Иконка ресурса

FREE MapGenerator : 0.0.1 0.0.1

Нет прав для скачивания
C#:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Oxide.Core;
using UnityEngine;
using Color = UnityEngine.Color;
namespace Oxide.Plugins {
    [Info("MapGenerator", "Aliluya", "0.0.1")]
    public class MapGenerator : RustPlugin {
        public static MapGenerator Instance;
        private bool Wipe = false;
        public void OnServerInitialized() {
            if (Wipe) GenerateImages();
            Instance = this;
        }
        void OnNewSave(string filename) {
            Wipe = true;
        }
        private void GenerateImages() {
            byte[] array = GenerateImage(1024);
            if (array == null) return;
            Stream stream = new MemoryStream(array);
            var Images = Image.FromStream(stream);
            Images.Save(Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + Path.DirectorySeparatorChar + $"{World.Seed}.{World.Size}.png", ImageFormat.Png);
        }
        [ConsoleCommand("save.map")]
        private void cmdGenerate(ConsoleSystem.Arg arg) {
            bool flag = arg.Connection != null;
            if (!flag) {
                PrintWarning("Start generation image.Please wait!");
                GenerateImages();
            }
        }
        private Dictionary<int, byte[]> Images = new Dictionary<int, byte[]>();
        public static ColorDB gstruct1_1 = new ColorDB  //sand
        {
            color1 = new Color(0.675f, 0.655f, 0.596f, 1.000f), color2 = new Color(0.612f, 0.463f, 0.373f, 1.000f), color3 = new Color(0.812f, 0.647f, 0.553f, 1.000f), color4 = new Color(1.000f, 0.663f, 0.514f, 1.000f), color5 = new Color(0.502f, 0.494f, 0.302f, 1.000f), color6 = new Color(0.812f, 0.647f, 0.553f, 1.000f),
        }
        ;
        public static ColorDB gstruct1_2 = new ColorDB  //c
        {
            color1 = new Color(0.439f, 0.565f, 0.290f, 1.000f), color2 = new Color(0.780f, 0.714f, 0.635f, 1.000f), color3 = new Color(0.608f, 0.502f, 0.427f, 1.000f), color4 = new Color(1.000f, 0.831f, 0.761f, 1.000f), color5 = new Color(0.490f, 0.525f, 0.278f, 1.000f), color6 = new Color(0.490f, 0.525f, 0.278f, 1.000f),
        }
        ;
        public static ColorDB gstruct1_3 = new ColorDB {
            color1 = new Color(0.490f, 0.525f, 0.278f, 1.000f), color2 = new Color(0.780f, 0.714f, 0.635f, 1.000f), color3 = new Color(0.259f, 0.259f, 0.259f, 1.000f), color4 = new Color(0.722f, 0.584f, 0.475f, 1.000f), color5 = new Color(0.722f, 0.522f, 0.267f, 1.000f), color6 = new Color(0.396f, 0.388f, 0.357f, 1.000f),
        }
        ;
        public static ColorDB gstruct1_4 = new ColorDB {
            color1 = new Color(0.247f, 0.247f, 0.247f, 1.000f), color2 = new Color(1.000f, 1.000f, 1.000f, 1.000f), color3 = new Color(0.259f, 0.259f, 0.259f, 1.000f), color4 = new Color(0.376f, 0.376f, 0.376f, 1.000f), color5 = new Color(0.780f, 0.714f, 0.635f, 1.000f), color6 = new Color(0.396f, 0.380f, 0.357f, 1.000f),
        }
        ;
        public struct ColorDB {
            public Color color1;
            public Color color2;
            public Color color3;
            public Color color4;
            public Color color5;
            public Color color6;
        }
        public struct GenerationResult<T> {
            public GenerationResult<U> method_1<U>(U gparam_1) {
                return new GenerationResult<U> {
                    gparam_0 = gparam_1,
                }
                ;
            }
            public T gparam_0;
        }
        internal class ImageGeneration {
            static ImageGeneration() {
                Vector3 vector = new Vector3(-1f, 1.5f, 1f);
                leftUpVectorNormalized = vector.normalized;
                color_9 = new Color[][] {
                    Get8Colors(gstruct1_1), Get8Colors(gstruct1_2), Get8Colors(gstruct1_3), Get8Colors(gstruct1_4)
                }
                ;
                for (int i = 0; i < 4; i++) {
                    if (color_9[i] == null) {
                        color_9[i] = new Color[8];
                    }
                }
                float_0 = World.Size / 2f;
                MaskTerrainWorld = LayerMask.GetMask("Terrain", "World");
                MaskWorld = LayerMask.GetMask("World");
            }
            internal GenerationResult<Texture2D> Generate1(int width, int height, Action<int> action_0 = null) {
                GenerationResult<Texture2D> result = default(GenerationResult<Texture2D>);
                Color[][] colorArray = new Color[height][];
                float[][] singleArray = new float[height][];
                for (int i = 0; i < height; i++) {
                    colorArray[i] = new Color[width];
                    singleArray[i] = new float[width];
                }
                Texture2D texture2D;
                texture2D = new Texture2D(width, height, (TextureFormat) 3, false);
                float size = World.Size / (float) height;
                for (int pixel = 0; pixel < height; pixel++) {
                    try {
                        method_2(float_0 - (pixel + 0.5f) * size, TerrainMeta.NormalizeZ(float_0 - (pixel + 0.5f) * size), pixel, width, colorArray[pixel], singleArray[pixel], false);
                    }
                    catch (Exception) {
                        // ignored
                    }
                    if (action_0 != null) {
                        if ((int) (100 * float_0 - (pixel + 0.5f) * size / height) > 0) {
                            action_0((int) (100 * float_0 - (pixel + 0.5f) * size / height));
                        }
                    }
                }
                for (int j = 0; j < height; j++) {
                    texture2D.SetPixels(0, height - 1 - j, width, 1, colorArray[j]);
                }
                texture2D.Apply();
                ImgHelper.smethod_4(texture2D, 1f);
                result.gparam_0 = texture2D;
                return result;
            }
            internal GenerationResult<byte[]> Generate2(int width, int height) {
                GenerationResult<Texture2D> generationResult = this.Generate1(width, height);
                byte[] gparam = generationResult.gparam_0.EncodeToJPG();
                return generationResult.method_1<byte[]>(gparam);
            }
            private void method_2(float float_5, float float_6, int int_0, int int_1, Color[] color_10, float[] float_7, bool bool_0) {
                Vector3 vector = default(Vector3);
                for (int i = 0; i < int_1; i++) {
                    Color color = color_8;
                    Vector3 vector3_ = Vector3.up;
                    float num2 = 0f;
                    float num6 = bool_0 ? 0f : TerrainMeta.WaterMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6);
                    float num7 = bool_0 ? 0f : TerrainMeta.WaterMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) - float_3;
                    float num8 = bool_0 ? 0f : TerrainMeta.WaterMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) - float_2;
                    float num9 = bool_0 ? 0f : TerrainMeta.WaterMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) - float_4;
                    int num12 = 0;
                    int num13 = 0;
                    float num14 = 0f;
                    float num15 = 0f;
                    for (int j = 0; j < 4; j++) {
                        float biome = TerrainMeta.BiomeMap.GetBiome(TerrainMeta.BiomeMap.Index(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0)), TerrainMeta.BiomeMap.Index(float_6), 1 << j);
                        if (biome > num14) {
                            num13 = num12;
                            num15 = num14;
                            num12 = j;
                            num14 = biome;
                        }
                        else if (biome > num15) {
                            num13 = j;
                            num15 = biome;
                        }
                    }
                    if (bool_0) {
                        vector.Set((i + 0.5f) * World.Size / (float) int_1 - float_0, TerrainMeta.HeightMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) - 3f, float_5);
                    }
                    else {
                        vector.Set((i + 0.5f) * World.Size / (float) int_1 - float_0, num6 + 1000f, float_5);
                    }
                    RaycastHit raycastHit;
                    if (!Physics.Raycast(vector, vectorDown, out raycastHit, 1000f + float_3, bool_0 ? MaskWorld : MaskTerrainWorld, (QueryTriggerInteraction) 1)) {
                        color = color_1;
                    }
                    else {
                        num2 = raycastHit.point.y;
                        vector3_ = raycastHit.normal;
                        if (num2 > num8 && TerrainMeta.HeightMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) < num9) {
                            color = color_9[num12][1];
                        }
                        else {
                            if (num2 < num7) {
                                color = color_1;
                                goto IL_5DD;
                            }
                            if (raycastHit.collider is TerrainCollider) {
                                vector.y = num2 - Mathf.Epsilon;
                                if (!Physics.Raycast(vector, vectorDown, out raycastHit, 0.5f, MaskTerrainWorld, (QueryTriggerInteraction) 1)) {
                                    goto IL_24A;
                                }
                                try {
                                    if (raycastHit.collider.gameObject.name.Contains("road")) {
                                        color = color_2;
                                        goto IL_572;
                                    }
                                    goto IL_24A;
                                }
                                catch {
                                    goto IL_24A;
                                }
                                IL_231 : int k;
                                float num16;
                                while (k < 8) {
                                    float splat = TerrainMeta.SplatMap.GetSplat(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6, 1 << k);
                                    color += (color_9[num12][k] * splat * num14 + color_9[num13][k] * splat * num15) / (num14 + num15);
                                    num16 += splat;
                                    k++;
                                }
                                color *= 1f / num16;
                                goto IL_572;
                                IL_24A : num16 = 0f;
                                color = Color.black;
                                k = 0;
                                goto IL_231;
                            }
                            string text = null;
                            try {
                                Collider collider = raycastHit.collider;
                                string text2;
                                if (collider == null) {
                                    text2 = null;
                                }
                                else {
                                    GameObject gameObject = collider.gameObject;
                                    if (gameObject == null) {
                                        text2 = null;
                                    }
                                    else {
                                        string name = gameObject.name;
                                        text2 = ((name != null) ? name.ToLower() : null);
                                    }
                                }
                                text = text2;
                            }
                            catch {
                            }
                            if (text != null) {
                                if (text.Contains("road")) {
                                    color = color_2;
                                    goto IL_572;
                                }
                                if (text.Contains("office")) {
                                    color = color_6;
                                    goto IL_572;
                                }
                                if (text.Contains("ice_lake")) {
                                    color = color_7;
                                    goto IL_572;
                                }
                            }
                            string text3 = null;
                            try {
                                Collider collider2 = raycastHit.collider;
                                string text4;
                                if (collider2 == null) {
                                    text4 = null;
                                }
                                else {
                                    PhysicMaterial material = collider2.material;
                                    if (material == null) {
                                        text4 = null;
                                    }
                                    else {
                                        string name2 = material.name;
                                        text4 = ((name2 != null) ? name2.ToLower() : null);
                                    }
                                }
                                text3 = text4;
                            }
                            catch {
                            }
                            if (text3 != null) {
                                int length;
                                if ((length = text3.IndexOf(' ')) > -1) {
                                    text3 = text3.Substring(0, length);
                                }
                                uint num17 = smethod_0(text3);
                                if (num17 > 2226448744u) {
                                    if (num17 > 3000956154u) {
                                        if (num17 != 3189014883u) {
                                            if (num17 != 3612782300u) {
                                                if (num17 != 3775286339u) {
                                                    goto IL_55E;
                                                }
                                                if (text3 != "sandbag") {
                                                    goto IL_55E;
                                                }
                                            }
                                            else {
                                                if (text3 == "metal") {
                                                    goto IL_4AE;
                                                }
                                                goto IL_55E;
                                            }
                                        }
                                        else if (text3 != "sand") {
                                            goto IL_55E;
                                        }
                                        color = color_9[num12][2];
                                        goto IL_572;
                                    }
                                    if (num17 != 2419790668u) {
                                        if (num17 == 3000956154u && text3 == "gravel") {
                                            goto IL_54D;
                                        }
                                        goto IL_55E;
                                    }
                                    else if (text3 != "metalore") {
                                        goto IL_55E;
                                    }
                                    IL_4AE : color = color_3;
                                    goto IL_572;
                                }
                                if (num17 <= 1180566432u) {
                                    if (num17 != 974867124u) {
                                        if (num17 != 1180566432u) {
                                            goto IL_55E;
                                        }
                                        if (text3 != "dirt") {
                                            goto IL_55E;
                                        }
                                    }
                                    else {
                                        if (text3 == "rock") {
                                            color = color_9[num12][3];
                                            goto IL_572;
                                        }
                                        goto IL_55E;
                                    }
                                }
                                else if (num17 != 2223183858u) {
                                    if (num17 == 2226448744u && text3 == "wood") {
                                        color = color_5;
                                        goto IL_572;
                                    }
                                    goto IL_55E;
                                }
                                else {
                                    if (text3 == "snow") {
                                        color = color_9[num12][1];
                                        goto IL_572;
                                    }
                                    goto IL_55E;
                                }
                                IL_54D : color = color_9[num12][0];
                                goto IL_572;
                            }
                            IL_55E : if (num2 < TerrainMeta.HeightMap.GetHeight(TerrainMeta.NormalizeX((i + 0.5f) * World.Size / (float) int_1 - float_0), float_6) + 0.5f) {
                                color = color_2;
                            }
                            else {
                                color = color_4;
                            }
                        }
                        IL_572 : if (num2 < num8) {
                            color = Color.Lerp(color_0, color_1, (num2 - num8) / (num7 - num8));
                        }
                        else {
                            color = ImgHelper.smethod_7(color, vector3_, leftUpVectorNormalized);
                            if (num2 < num6) {
                                color = Color.Lerp(color, color_0, 0.5f + (num2 - num6) / (num8 - num6) * 0.5f);
                            }
                            else {
                                float_7[i] = num2;
                                color_10[i] = color;
                            }
                        }
                    }
                    IL_5DD : color_10[i] = color;
                    float_7[i] = num6;
                }
            }
            internal static uint smethod_0(string string_0) {
                uint num = 0u;
                if (string_0 != null) {
                    num = 2166136261u;
                    for (int i = 0; i < string_0.Length; i++) {
                        num = ((uint) string_0[i] ^ num) * 16777619u;
                    }
                }
                return num;
            }
            private static Color[] Get8Colors(ColorDB colorDB) {
                return new Color[] {
                    colorDB.color1, colorDB.color2, colorDB.color3, colorDB.color4, colorDB.color5, colorDB.color6, colorDB.color4, colorDB.color4
                }
                ;
            }
            private static Color color_0 = new Color(0.078f, 0.212f, 0.275f, 1.000f);
            private static Color color_1 = new Color(0.055f, 0.157f, 0.204f, 1.000f);
            private static Color color_2 = new Color(0.43f, 0.39f, 0.38f, 1.000f);
            private static Color color_3 = new Color(0.424f, 0.231f, 0.173f, 1.000f);
            private static Color color_4 = new Color(0.780f, 0.714f, 0.635f, 1.000f);
            private static Color color_5 = new Color(0.46f, 0.43f, 0.36f, 1.000f);
            private static Color color_6 = new Color(1.000f, 1.000f, 1.000f, 1.000f);
            private static Color color_7 = new Color(0.800f, 0.929f, 1.000f, 1.000f);
            private static Color color_8 = new Color(1.000f, 0.000f, 1.000f, 1.000f);
            private static Color[][] color_9;
            private static float float_0;
            private static Vector3 vectorDown = new Vector3(0f, -2f, 0f);
            private static LayerMask MaskTerrainWorld;
            private static LayerMask MaskWorld;
            private static float float_2 = 2f;
            private static float float_3 = 5f;
            private static float float_4 = 25f;
            private static Vector3 leftUpVectorNormalized;
        }
        public static class ImgHelper {
            public static void smethod_4(Texture2D texture2D_0, float float_0 = 8f) {
                Vector2 vector2 = new Vector2(float_0, float_0);
                Vector2 vector21 = new Vector2(-float_0, -float_0);
                float[, ] singleArray = new float[texture2D_0.width, texture2D_0.height];
                for (int int_2 = 0; int_2 < texture2D_0.height; int_2++) {
                    for (int k = 0; k < texture2D_0.width; k++) {
                        Color pixel = texture2D_0.GetPixel(k, int_2);
                        singleArray[k, int_2] = pixel.r * 0.299f + pixel.g * 0.587f + pixel.b * 0.114f;
                    }
                }
                Color[][] pixels = new Color[texture2D_0.height][];
                pixels[0] = texture2D_0.GetPixels(0, 0, texture2D_0.width, 1);
                pixels[texture2D_0.height - 1] = texture2D_0.GetPixels(0, texture2D_0.height - 1, texture2D_0.width, 1);
                for (int i = 1; i < texture2D_0.height - 1; i++) {
                    pixels[i] = new Color[texture2D_0.width];
                    pixels[i][0] = texture2D_0.GetPixel(0, i);
                    pixels[i][texture2D_0.width - 1] = texture2D_0.GetPixel(texture2D_0.width - 1, i);
                }
                for (int int_2 = 1; int_2 < texture2D_0.height - 1; int_2++) {
                    Color[] array = pixels[int_2];
                    Vector2 vector = new Vector2();
                    for (int k = 1; k < texture2D_0.width - 1; k++) {
                        vector.x = -(singleArray[k - 1, int_2 - 1] + singleArray[k + 1, int_2 - 1] - (singleArray[k - 1, int_2 + 1] + singleArray[k + 1, int_2 + 1]));
                        vector.y = singleArray[k - 1, int_2 - 1] + singleArray[k - 1, int_2 + 1] - (singleArray[k + 1, int_2 - 1] + singleArray[k + 1, int_2 + 1]);
                        vector = Vector2.Min(vector, Vector2.Max(vector21, vector * 1f / (Mathf.Min(Mathf.Abs(vector.x), Mathf.Abs(vector.y)) + Mathf.Max((singleArray[k - 1, int_2 - 1] + singleArray[k + 1, int_2 - 1] + singleArray[k - 1, int_2 + 1] + singleArray[k + 1, int_2 + 1]) * 0.03125f, 0.0078125f))));
                        vector.x *= 1f / texture2D_0.width;
                        vector.y *= 1f / texture2D_0.height;
                        vector2 = vector * -0.166666672f;
                        Vector2 vector3 = vector * 0.166666672f;
                        Vector2 vector4 = vector * -0.5f;
                        Vector2 vector5 = vector * 0.5f;
                        Color color = 0.5f * (texture2D_0.GetPixelBilinear(k * 1f/texture2D_0.width + vector2.x, int_2 * 1f/texture2D_0.height + vector2.y) + texture2D_0.GetPixelBilinear(k * 1f/texture2D_0.width + vector3.x, int_2 * 1f/texture2D_0.height + vector3.y));
                        Color color2 = color * 0.5f + 0.25f * (texture2D_0.GetPixelBilinear(k * 1f/texture2D_0.width + vector4.x, int_2 * 1f/texture2D_0.height + vector4.y) + texture2D_0.GetPixelBilinear(k * 1f/texture2D_0.width + vector5.x, int_2 * 1f/texture2D_0.height + vector5.y));
                        if (color2.r * 0.299f + color2.g * 0.587f + color2.b * 0.114f < Mathf.Min(singleArray[k, int_2], singleArray[k - 1, int_2 - 1], singleArray[k + 1, int_2 - 1], singleArray[k - 1, int_2 + 1], singleArray[k + 1, int_2 + 1]) || color2.r * 0.299f + color2.g * 0.587f + color2.b * 0.114f > Mathf.Max(singleArray[k, int_2], singleArray[k - 1, int_2 - 1], singleArray[k + 1, int_2 - 1], singleArray[k - 1, int_2 + 1], singleArray[k + 1, int_2 + 1])) array[k] = color;
                        else array[k] = color2;
                    }
                }
                for (int j = 0; j < texture2D_0.height; j++) {
                    texture2D_0.SetPixels(0, j, texture2D_0.width, 1, pixels[j]);
                }
                texture2D_0.Apply();
            }
            private static float smethod_5(float float_0) {
                return Mathf.Sqrt(1f - float_0 * float_0);
            }
            private static float smethod_6(float float_0, float float_1 = 0f) {
                float_0 = Mathf.Abs(float_0);
                float_0 = float_1 + (float_0 - float_1);
                return (1f + -1f * Mathf.Sqrt(1f - float_0 * float_0)) * 1f / smethod_5(float_1);
            }
            public static Color smethod_7(Color color_0, Vector3 vector3_0, Vector3 vector3_1) {
                Color color = Color.Lerp(color_0, Color.black, 0.75f);
                if (Vector3.Dot(vector3_0, vector3_1) < 0f) {
                    return color;
                }
                return Color.Lerp(color, color_0, smethod_6(Vector3.Dot(vector3_0, vector3_1), 0.85f));
            }
            private delegate void Delegate1(int int_0, int int_1, ref float float_0);
        }
        public static byte[] GenerateImage(int size = 2048) {
            GenerationResult<byte[]> generationResult = new ImageGeneration().Generate2(size, size);
            return generationResult.gparam_0;
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху