D:\ValheimDev\Dumps\Old\assembly_valheim\Heightmap.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\Heightmap.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
   
[ExecuteInEditMode] [ExecuteInEditMode]
.public class Heightmap : MonoBehaviour  public class Heightmap : MonoBehaviour, IMonoUpdater 
{ {
    private void Awake()     private void Awake()
    {     {
        if (!this.m_isDistantLod)         if (!this.m_isDistantLod)
        {         {
            Heightmap.s_heightmaps.Add(this);             Heightmap.s_heightmaps.Add(this);
        }         }
        if (Heightmap.s_shaderPropertyClearedMaskTex == 0)         if (Heightmap.s_shaderPropertyClearedMaskTex == 0)
        {         {
            Heightmap.s_shaderPropertyClearedMaskTex = Shader.PropertyToID("_ClearedMaskTex");             Heightmap.s_shaderPropertyClearedMaskTex = Shader.PropertyToID("_ClearedMaskTex");
        }         }
        this.m_collider = base.GetComponent<MeshCollider>();         this.m_collider = base.GetComponent<MeshCollider>();
        this.m_meshFilter = base.GetComponent<MeshFilter>();         this.m_meshFilter = base.GetComponent<MeshFilter>();
        if (!this.m_meshFilter)         if (!this.m_meshFilter)
        {         {
            this.m_meshFilter = base.gameObject.AddComponent<MeshFilter>();             this.m_meshFilter = base.gameObject.AddComponent<MeshFilter>();
        }         }
        this.m_meshRenderer = base.GetComponent<MeshRenderer>();         this.m_meshRenderer = base.GetComponent<MeshRenderer>();
        if (!this.m_meshRenderer)         if (!this.m_meshRenderer)
        {         {
            this.m_meshRenderer = base.gameObject.AddComponent<MeshRenderer>();             this.m_meshRenderer = base.gameObject.AddComponent<MeshRenderer>();
        }         }
        this.m_meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.Camera;         this.m_meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.Camera;
        this.m_renderGroupSubscriber = base.GetComponent<RenderGroupSubscriber>();         this.m_renderGroupSubscriber = base.GetComponent<RenderGroupSubscriber>();
        if (!this.m_renderGroupSubscriber)         if (!this.m_renderGroupSubscriber)
        {         {
            this.m_renderGroupSubscriber = base.gameObject.AddComponent<RenderGroupSubscriber>();             this.m_renderGroupSubscriber = base.gameObject.AddComponent<RenderGroupSubscriber>();
        }         }
        this.m_renderGroupSubscriber.Group = RenderGroup.Overworld;         this.m_renderGroupSubscriber.Group = RenderGroup.Overworld;
        if (this.m_material == null)         if (this.m_material == null)
        {         {
            base.enabled = false;             base.enabled = false;
        }         }
        this.UpdateShadowSettings();         this.UpdateShadowSettings();
    }     }
   
    private void OnDestroy()     private void OnDestroy()
    {     {
        if (!this.m_isDistantLod)         if (!this.m_isDistantLod)
        {         {
            Heightmap.s_heightmaps.Remove(this);             Heightmap.s_heightmaps.Remove(this);
        }         }
        if (this.m_materialInstance)         if (this.m_materialInstance)
        {         {
            UnityEngine.Object.DestroyImmediate(this.m_materialInstance);             UnityEngine.Object.DestroyImmediate(this.m_materialInstance);
        }         }
        if (this.m_collisionMesh)         if (this.m_collisionMesh)
        {         {
            UnityEngine.Object.DestroyImmediate(this.m_collisionMesh);             UnityEngine.Object.DestroyImmediate(this.m_collisionMesh);
        }         }
        if (this.m_renderMesh)         if (this.m_renderMesh)
        {         {
            UnityEngine.Object.DestroyImmediate(this.m_renderMesh);             UnityEngine.Object.DestroyImmediate(this.m_renderMesh);
        }         }
        if (this.m_paintMask)         if (this.m_paintMask)
        {         {
            UnityEngine.Object.DestroyImmediate(this.m_paintMask);             UnityEngine.Object.DestroyImmediate(this.m_paintMask);
        }         }
    }     }
   
    private void OnEnable()     private void OnEnable()
    {     {
        Heightmap.Instances.Add(this);         Heightmap.Instances.Add(this);
        this.UpdateShadowSettings();         this.UpdateShadowSettings();
        if (this.m_isDistantLod && Application.isPlaying && !this.m_distantLodEditorHax)         if (this.m_isDistantLod && Application.isPlaying && !this.m_distantLodEditorHax)
        {         {
            return;             return;
        }         }
        this.Regenerate();         this.Regenerate();
    }     }
   
    private void OnDisable()     private void OnDisable()
    {     {
        Heightmap.Instances.Remove(this);         Heightmap.Instances.Remove(this);
    }     }
   
.    public void CustomLateUpdate()     public void CustomLateUpdate(float deltaTime)
    {     {
        if (!this.m_doLateUpdate)         if (!this.m_doLateUpdate)
        {         {
            return;             return;
        }         }
        this.m_doLateUpdate = false;         this.m_doLateUpdate = false;
        this.Regenerate();         this.Regenerate();
    }     }
   
    private void UpdateShadowSettings()     private void UpdateShadowSettings()
    {     {
        if (this.m_isDistantLod)         if (this.m_isDistantLod)
        {         {
            this.m_meshRenderer.shadowCastingMode = (Heightmap.EnableDistantTerrainShadows ? ShadowCastingMode.On : ShadowCastingMode.Off);             this.m_meshRenderer.shadowCastingMode = (Heightmap.EnableDistantTerrainShadows ? ShadowCastingMode.On : ShadowCastingMode.Off);
            this.m_meshRenderer.receiveShadows = false;             this.m_meshRenderer.receiveShadows = false;
            return;             return;
        }         }
        this.m_meshRenderer.shadowCastingMode = (Heightmap.EnableDistantTerrainShadows ? ShadowCastingMode.On : ShadowCastingMode.TwoSided);         this.m_meshRenderer.shadowCastingMode = (Heightmap.EnableDistantTerrainShadows ? ShadowCastingMode.On : ShadowCastingMode.TwoSided);
        this.m_meshRenderer.receiveShadows = true;         this.m_meshRenderer.receiveShadows = true;
    }     }
   
    public static void ForceGenerateAll()     public static void ForceGenerateAll()
    {     {
        foreach (Heightmap heightmap in Heightmap.s_heightmaps)         foreach (Heightmap heightmap in Heightmap.s_heightmaps)
        {         {
            if (heightmap.HaveQueuedRebuild())             if (heightmap.HaveQueuedRebuild())
            {             {
                ZLog.Log("Force generating hmap " + heightmap.transform.position.ToString());                 ZLog.Log("Force generating hmap " + heightmap.transform.position.ToString());
                heightmap.Regenerate();                 heightmap.Regenerate();
            }             }
        }         }
    }     }
   
    public void Poke(bool delayed)     public void Poke(bool delayed)
    {     {
        if (delayed)         if (delayed)
        {         {
            this.m_doLateUpdate = true;             this.m_doLateUpdate = true;
            return;             return;
        }         }
        this.Regenerate();         this.Regenerate();
    }     }
   
    public bool HaveQueuedRebuild()     public bool HaveQueuedRebuild()
    {     {
        return this.m_doLateUpdate;         return this.m_doLateUpdate;
    }     }
   
    public void Regenerate()     public void Regenerate()
    {     {
        this.m_doLateUpdate = false;         this.m_doLateUpdate = false;
        if (!this.Generate())         if (!this.Generate())
        {         {
            return;             return;
        }         }
        this.RebuildCollisionMesh();         this.RebuildCollisionMesh();
        this.UpdateCornerDepths();         this.UpdateCornerDepths();
        this.m_materialInstance.SetTexture(Heightmap.s_shaderPropertyClearedMaskTex, this.m_paintMask);         this.m_materialInstance.SetTexture(Heightmap.s_shaderPropertyClearedMaskTex, this.m_paintMask);
        this.RebuildRenderMesh();         this.RebuildRenderMesh();
        Action clearConnectedWearNTearCache = this.m_clearConnectedWearNTearCache;         Action clearConnectedWearNTearCache = this.m_clearConnectedWearNTearCache;
        if (clearConnectedWearNTearCache == null)         if (clearConnectedWearNTearCache == null)
        {         {
            return;             return;
        }         }
        clearConnectedWearNTearCache();         clearConnectedWearNTearCache();
    }     }
   
    private void UpdateCornerDepths()     private void UpdateCornerDepths()
    {     {
.        float num = (ZoneSystem.instance ? ZoneSystem.instance.m_waterLevel : 30f);         float num = 30f;
        this.m_oceanDepth[0] = this.GetHeight(0, this.m_width);         this.m_oceanDepth[0] = this.GetHeight(0, this.m_width);
        this.m_oceanDepth[1] = this.GetHeight(this.m_width, this.m_width);         this.m_oceanDepth[1] = this.GetHeight(this.m_width, this.m_width);
        this.m_oceanDepth[2] = this.GetHeight(this.m_width, 0);         this.m_oceanDepth[2] = this.GetHeight(this.m_width, 0);
        this.m_oceanDepth[3] = this.GetHeight(0, 0);         this.m_oceanDepth[3] = this.GetHeight(0, 0);
        this.m_oceanDepth[0] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[0]));         this.m_oceanDepth[0] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[0]));
        this.m_oceanDepth[1] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[1]));         this.m_oceanDepth[1] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[1]));
        this.m_oceanDepth[2] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[2]));         this.m_oceanDepth[2] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[2]));
        this.m_oceanDepth[3] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[3]));         this.m_oceanDepth[3] = Mathf.Max(0f, (float)((double)num - (double)this.m_oceanDepth[3]));
        this.m_materialInstance.SetFloatArray("_depth", this.m_oceanDepth);         this.m_materialInstance.SetFloatArray("_depth", this.m_oceanDepth);
    }     }
   
    public float[] GetOceanDepth()     public float[] GetOceanDepth()
    {     {
        return this.m_oceanDepth;         return this.m_oceanDepth;
    }     }
   
    public float GetOceanDepth(Vector3 worldPos)     public float GetOceanDepth(Vector3 worldPos)
    {     {
        int num;         int num;
        int num2;         int num2;
        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertex(worldPos, out num, out num2);
        float num3 = (float)((double)num / (double)((float)this.m_width));         float num3 = (float)((double)num / (double)((float)this.m_width));
        float num4 = (float)num2 / (float)this.m_width;         float num4 = (float)num2 / (float)this.m_width;
        float num5 = DUtils.Lerp(this.m_oceanDepth[3], this.m_oceanDepth[2], num3);         float num5 = DUtils.Lerp(this.m_oceanDepth[3], this.m_oceanDepth[2], num3);
        float num6 = DUtils.Lerp(this.m_oceanDepth[0], this.m_oceanDepth[1], num3);         float num6 = DUtils.Lerp(this.m_oceanDepth[0], this.m_oceanDepth[1], num3);
        return DUtils.Lerp(num5, num6, num4);         return DUtils.Lerp(num5, num6, num4);
    }     }
   
    private void Initialize()     private void Initialize()
    {     {
        int num = this.m_width + 1;         int num = this.m_width + 1;
        int num2 = num * num;         int num2 = num * num;
        if (this.m_heights.Count == num2)         if (this.m_heights.Count == num2)
        {         {
            return;             return;
        }         }
        this.m_heights.Clear();         this.m_heights.Clear();
        for (int i = 0; i < num2; i++)         for (int i = 0; i < num2; i++)
        {         {
            this.m_heights.Add(0f);             this.m_heights.Add(0f);
        }         }
.        this.m_paintMask = new Texture2D(this.m_width, this.m_width);         this.m_paintMask = new Texture2D(num, num);
        this.m_paintMask.name = "_Heightmap m_paintMask";         this.m_paintMask.name = "_Heightmap m_paintMask";
        this.m_paintMask.wrapMode = TextureWrapMode.Clamp;         this.m_paintMask.wrapMode = TextureWrapMode.Clamp;
        this.m_materialInstance = new Material(this.m_material);         this.m_materialInstance = new Material(this.m_material);
        this.m_materialInstance.SetTexture(Heightmap.s_shaderPropertyClearedMaskTex, this.m_paintMask);         this.m_materialInstance.SetTexture(Heightmap.s_shaderPropertyClearedMaskTex, this.m_paintMask);
        this.m_meshRenderer.sharedMaterial = this.m_materialInstance;         this.m_meshRenderer.sharedMaterial = this.m_materialInstance;
    }     }
   
    private bool Generate()     private bool Generate()
    {     {
        if (HeightmapBuilder.instance == null)         if (HeightmapBuilder.instance == null)
        {         {
            return false;             return false;
        }         }
        if (WorldGenerator.instance == null)         if (WorldGenerator.instance == null)
        {         {
            ZLog.LogError("The WorldGenerator instance was null");             ZLog.LogError("The WorldGenerator instance was null");
            throw new NullReferenceException("The WorldGenerator instance was null");             throw new NullReferenceException("The WorldGenerator instance was null");
        }         }
        this.Initialize();         this.Initialize();
        int num = this.m_width + 1;         int num = this.m_width + 1;
        int num2 = num * num;         int num2 = num * num;
        Vector3 position = base.transform.position;         Vector3 position = base.transform.position;
        if (this.m_buildData == null || this.m_buildData.m_baseHeights.Count != num2 || this.m_buildData.m_center != position || this.m_buildData.m_scale != this.m_scale || this.m_buildData.m_worldGen != WorldGenerator.instance)         if (this.m_buildData == null || this.m_buildData.m_baseHeights.Count != num2 || this.m_buildData.m_center != position || this.m_buildData.m_scale != this.m_scale || this.m_buildData.m_worldGen != WorldGenerator.instance)
        {         {
            this.m_buildData = HeightmapBuilder.instance.RequestTerrainSync(position, this.m_width, this.m_scale, this.m_isDistantLod, WorldGenerator.instance);             this.m_buildData = HeightmapBuilder.instance.RequestTerrainSync(position, this.m_width, this.m_scale, this.m_isDistantLod, WorldGenerator.instance);
            this.m_cornerBiomes = this.m_buildData.m_cornerBiomes;             this.m_cornerBiomes = this.m_buildData.m_cornerBiomes;
        }         }
        for (int i = 0; i < num2; i++)         for (int i = 0; i < num2; i++)
        {         {
            this.m_heights[i] = this.m_buildData.m_baseHeights[i];             this.m_heights[i] = this.m_buildData.m_baseHeights[i];
        }         }
        this.m_paintMask.SetPixels(this.m_buildData.m_baseMask);         this.m_paintMask.SetPixels(this.m_buildData.m_baseMask);
        this.ApplyModifiers();         this.ApplyModifiers();
        return true;         return true;
    }     }
   
    private static float Distance(float x, float y, float rx, float ry)     private static float Distance(float x, float y, float rx, float ry)
    {     {
        float num = (float)((double)x - (double)rx);         float num = (float)((double)x - (double)rx);
        float num2 = (float)((double)y - (double)ry);         float num2 = (float)((double)y - (double)ry);
        float num3 = Mathf.Sqrt((float)((double)num * (double)num + (double)num2 * (double)num2));         float num3 = Mathf.Sqrt((float)((double)num * (double)num + (double)num2 * (double)num2));
        float num4 = (float)(1.4140000343322754 - (double)num3);         float num4 = (float)(1.4140000343322754 - (double)num3);
        return (float)((double)num4 * (double)num4 * (double)num4);         return (float)((double)num4 * (double)num4 * (double)num4);
    }     }
   
    public bool HaveBiome(Heightmap.Biome biome)     public bool HaveBiome(Heightmap.Biome biome)
    {     {
        return (this.m_cornerBiomes[0] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[1] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[2] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[3] & biome) > Heightmap.Biome.None;         return (this.m_cornerBiomes[0] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[1] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[2] & biome) != Heightmap.Biome.None || (this.m_cornerBiomes[3] & biome) > Heightmap.Biome.None;
    }     }
   
.    public Heightmap.Biome GetBiome(Vector3 point)     public Heightmap.Biome GetBiome(Vector3 point, float oceanLevel = 0.02f, bool waterAlwaysOcean = false)
    {     {
.        if (this.m_isDistantLod)         if (this.m_isDistantLod || waterAlwaysOcean)
        {         {
.            return WorldGenerator.instance.GetBiome(point.x, point.z);             return WorldGenerator.instance.GetBiome(point.x, point.z, oceanLevel, waterAlwaysOcean);
        }         }
        if (this.m_cornerBiomes[0] == this.m_cornerBiomes[1] && this.m_cornerBiomes[0] == this.m_cornerBiomes[2] && this.m_cornerBiomes[0] == this.m_cornerBiomes[3])         if (this.m_cornerBiomes[0] == this.m_cornerBiomes[1] && this.m_cornerBiomes[0] == this.m_cornerBiomes[2] && this.m_cornerBiomes[0] == this.m_cornerBiomes[3])
        {         {
            return this.m_cornerBiomes[0];             return this.m_cornerBiomes[0];
        }         }
        float x = point.x;         float x = point.x;
        float z = point.z;         float z = point.z;
        this.WorldToNormalizedHM(point, out x, out z);         this.WorldToNormalizedHM(point, out x, out z);
        for (int i = 1; i < Heightmap.s_tempBiomeWeights.Length; i++)         for (int i = 1; i < Heightmap.s_tempBiomeWeights.Length; i++)
        {         {
            Heightmap.s_tempBiomeWeights[i] = 0f;             Heightmap.s_tempBiomeWeights[i] = 0f;
        }         }
        Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[0]]] += Heightmap.Distance(x, z, 0f, 0f);         Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[0]]] += Heightmap.Distance(x, z, 0f, 0f);
        Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[1]]] += Heightmap.Distance(x, z, 1f, 0f);         Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[1]]] += Heightmap.Distance(x, z, 1f, 0f);
        Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[2]]] += Heightmap.Distance(x, z, 0f, 1f);         Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[2]]] += Heightmap.Distance(x, z, 0f, 1f);
        Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[3]]] += Heightmap.Distance(x, z, 1f, 1f);         Heightmap.s_tempBiomeWeights[Heightmap.s_biomeToIndex[this.m_cornerBiomes[3]]] += Heightmap.Distance(x, z, 1f, 1f);
        int num = Heightmap.s_biomeToIndex[Heightmap.Biome.None];         int num = Heightmap.s_biomeToIndex[Heightmap.Biome.None];
        float num2 = -99999f;         float num2 = -99999f;
        for (int j = 1; j < Heightmap.s_tempBiomeWeights.Length; j++)         for (int j = 1; j < Heightmap.s_tempBiomeWeights.Length; j++)
        {         {
            if (Heightmap.s_tempBiomeWeights[j] > num2)             if (Heightmap.s_tempBiomeWeights[j] > num2)
            {             {
                num = j;                 num = j;
                num2 = Heightmap.s_tempBiomeWeights[j];                 num2 = Heightmap.s_tempBiomeWeights[j];
            }             }
        }         }
        return Heightmap.s_indexToBiome[num];         return Heightmap.s_indexToBiome[num];
    }     }
   
    public Heightmap.BiomeArea GetBiomeArea()     public Heightmap.BiomeArea GetBiomeArea()
    {     {
        if (!this.IsBiomeEdge())         if (!this.IsBiomeEdge())
        {         {
            return Heightmap.BiomeArea.Median;             return Heightmap.BiomeArea.Median;
        }         }
        return Heightmap.BiomeArea.Edge;         return Heightmap.BiomeArea.Edge;
    }     }
   
    public bool IsBiomeEdge()     public bool IsBiomeEdge()
    {     {
        return this.m_cornerBiomes[0] != this.m_cornerBiomes[1] || this.m_cornerBiomes[0] != this.m_cornerBiomes[2] || this.m_cornerBiomes[0] != this.m_cornerBiomes[3];         return this.m_cornerBiomes[0] != this.m_cornerBiomes[1] || this.m_cornerBiomes[0] != this.m_cornerBiomes[2] || this.m_cornerBiomes[0] != this.m_cornerBiomes[3];
    }     }
   
    private void ApplyModifiers()     private void ApplyModifiers()
    {     {
        List<TerrainModifier> allInstances = TerrainModifier.GetAllInstances();         List<TerrainModifier> allInstances = TerrainModifier.GetAllInstances();
        float[] array = null;         float[] array = null;
        float[] array2 = null;         float[] array2 = null;
        foreach (TerrainModifier terrainModifier in allInstances)         foreach (TerrainModifier terrainModifier in allInstances)
        {         {
            if (terrainModifier.enabled && this.TerrainVSModifier(terrainModifier))             if (terrainModifier.enabled && this.TerrainVSModifier(terrainModifier))
            {             {
                if (terrainModifier.m_playerModifiction && array == null)                 if (terrainModifier.m_playerModifiction && array == null)
                {                 {
                    array = this.m_heights.ToArray();                     array = this.m_heights.ToArray();
                    array2 = this.m_heights.ToArray();                     array2 = this.m_heights.ToArray();
                }                 }
                this.ApplyModifier(terrainModifier, array, array2);                 this.ApplyModifier(terrainModifier, array, array2);
            }             }
        }         }
        TerrainComp terrainComp = (this.m_isDistantLod ? null : TerrainComp.FindTerrainCompiler(base.transform.position));         TerrainComp terrainComp = (this.m_isDistantLod ? null : TerrainComp.FindTerrainCompiler(base.transform.position));
        if (terrainComp)         if (terrainComp)
        {         {
            if (array == null)             if (array == null)
            {             {
                array = this.m_heights.ToArray();                 array = this.m_heights.ToArray();
                array2 = this.m_heights.ToArray();                 array2 = this.m_heights.ToArray();
            }             }
            terrainComp.ApplyToHeightmap(this.m_paintMask, this.m_heights, array, array2, this);             terrainComp.ApplyToHeightmap(this.m_paintMask, this.m_heights, array, array2, this);
        }         }
        this.m_paintMask.Apply();         this.m_paintMask.Apply();
    }     }
   
    private void ApplyModifier(TerrainModifier modifier, float[] baseHeights, float[] levelOnly)     private void ApplyModifier(TerrainModifier modifier, float[] baseHeights, float[] levelOnly)
    {     {
        if (modifier.m_level)         if (modifier.m_level)
        {         {
            this.LevelTerrain(modifier.transform.position + Vector3.up * modifier.m_levelOffset, modifier.m_levelRadius, modifier.m_square, baseHeights, levelOnly, modifier.m_playerModifiction);             this.LevelTerrain(modifier.transform.position + Vector3.up * modifier.m_levelOffset, modifier.m_levelRadius, modifier.m_square, baseHeights, levelOnly, modifier.m_playerModifiction);
        }         }
        if (modifier.m_smooth)         if (modifier.m_smooth)
        {         {
            this.SmoothTerrain2(modifier.transform.position + Vector3.up * modifier.m_levelOffset, modifier.m_smoothRadius, modifier.m_square, levelOnly, modifier.m_smoothPower, modifier.m_playerModifiction);             this.SmoothTerrain2(modifier.transform.position + Vector3.up * modifier.m_levelOffset, modifier.m_smoothRadius, modifier.m_square, levelOnly, modifier.m_smoothPower, modifier.m_playerModifiction);
        }         }
        if (modifier.m_paintCleared)         if (modifier.m_paintCleared)
        {         {
            this.PaintCleared(modifier.transform.position, modifier.m_paintRadius, modifier.m_paintType, modifier.m_paintHeightCheck, false);             this.PaintCleared(modifier.transform.position, modifier.m_paintRadius, modifier.m_paintType, modifier.m_paintHeightCheck, false);
        }         }
    }     }
   
    public bool CheckTerrainModIsContained(TerrainModifier modifier)     public bool CheckTerrainModIsContained(TerrainModifier modifier)
    {     {
        Vector3 position = modifier.transform.position;         Vector3 position = modifier.transform.position;
        float num = modifier.GetRadius() + 0.1f;         float num = modifier.GetRadius() + 0.1f;
        Vector3 position2 = base.transform.position;         Vector3 position2 = base.transform.position;
        float num2 = (float)this.m_width * this.m_scale * 0.5f;         float num2 = (float)this.m_width * this.m_scale * 0.5f;
        return position.x + num <= position2.x + num2 && position.x - num >= position2.x - num2 && position.z + num <= position2.z + num2 && position.z - num >= position2.z - num2;         return position.x + num <= position2.x + num2 && position.x - num >= position2.x - num2 && position.z + num <= position2.z + num2 && position.z - num >= position2.z - num2;
    }     }
   
    public bool TerrainVSModifier(TerrainModifier modifier)     public bool TerrainVSModifier(TerrainModifier modifier)
    {     {
        Vector3 position = modifier.transform.position;         Vector3 position = modifier.transform.position;
        float num = modifier.GetRadius() + 4f;         float num = modifier.GetRadius() + 4f;
        Vector3 position2 = base.transform.position;         Vector3 position2 = base.transform.position;
        float num2 = (float)this.m_width * this.m_scale * 0.5f;         float num2 = (float)this.m_width * this.m_scale * 0.5f;
        return position.x + num >= position2.x - num2 && position.x - num <= position2.x + num2 && position.z + num >= position2.z - num2 && position.z - num <= position2.z + num2;         return position.x + num >= position2.x - num2 && position.x - num <= position2.x + num2 && position.z + num >= position2.z - num2 && position.z - num <= position2.z + num2;
    }     }
   
    private Vector3 CalcVertex(int x, int y)     private Vector3 CalcVertex(int x, int y)
    {     {
        int num = this.m_width + 1;         int num = this.m_width + 1;
        Vector3 vector = new Vector3((float)((double)this.m_width * (double)this.m_scale * -0.5), 0f, (float)((double)this.m_width * (double)this.m_scale * -0.5));         Vector3 vector = new Vector3((float)((double)this.m_width * (double)this.m_scale * -0.5), 0f, (float)((double)this.m_width * (double)this.m_scale * -0.5));
        float num2 = this.m_heights[y * num + x];         float num2 = this.m_heights[y * num + x];
        return vector + new Vector3((float)((double)x * (double)this.m_scale), num2, (float)((double)y * (double)this.m_scale));         return vector + new Vector3((float)((double)x * (double)this.m_scale), num2, (float)((double)y * (double)this.m_scale));
    }     }
   
    private Color GetBiomeColor(float ix, float iy)     private Color GetBiomeColor(float ix, float iy)
    {     {
        if (this.m_cornerBiomes[0] == this.m_cornerBiomes[1] && this.m_cornerBiomes[0] == this.m_cornerBiomes[2] && this.m_cornerBiomes[0] == this.m_cornerBiomes[3])         if (this.m_cornerBiomes[0] == this.m_cornerBiomes[1] && this.m_cornerBiomes[0] == this.m_cornerBiomes[2] && this.m_cornerBiomes[0] == this.m_cornerBiomes[3])
        {         {
            return Heightmap.GetBiomeColor(this.m_cornerBiomes[0]);             return Heightmap.GetBiomeColor(this.m_cornerBiomes[0]);
        }         }
        Color32 biomeColor = Heightmap.GetBiomeColor(this.m_cornerBiomes[0]);         Color32 biomeColor = Heightmap.GetBiomeColor(this.m_cornerBiomes[0]);
        Color32 biomeColor2 = Heightmap.GetBiomeColor(this.m_cornerBiomes[1]);         Color32 biomeColor2 = Heightmap.GetBiomeColor(this.m_cornerBiomes[1]);
        Color32 biomeColor3 = Heightmap.GetBiomeColor(this.m_cornerBiomes[2]);         Color32 biomeColor3 = Heightmap.GetBiomeColor(this.m_cornerBiomes[2]);
        Color32 biomeColor4 = Heightmap.GetBiomeColor(this.m_cornerBiomes[3]);         Color32 biomeColor4 = Heightmap.GetBiomeColor(this.m_cornerBiomes[3]);
        Color32 color = Color32.Lerp(biomeColor, biomeColor2, ix);         Color32 color = Color32.Lerp(biomeColor, biomeColor2, ix);
        Color32 color2 = Color32.Lerp(biomeColor3, biomeColor4, ix);         Color32 color2 = Color32.Lerp(biomeColor3, biomeColor4, ix);
        return Color32.Lerp(color, color2, iy);         return Color32.Lerp(color, color2, iy);
    }     }
   
    public static Color32 GetBiomeColor(Heightmap.Biome biome)     public static Color32 GetBiomeColor(Heightmap.Biome biome)
    {     {
        if (biome <= Heightmap.Biome.Plains)         if (biome <= Heightmap.Biome.Plains)
        {         {
            switch (biome)             switch (biome)
            {             {
            case Heightmap.Biome.Meadows:             case Heightmap.Biome.Meadows:
            case Heightmap.Biome.Meadows | Heightmap.Biome.Swamp:             case Heightmap.Biome.Meadows | Heightmap.Biome.Swamp:
                break;                 break;
            case Heightmap.Biome.Swamp:             case Heightmap.Biome.Swamp:
                return new Color32(byte.MaxValue, 0, 0, 0);                 return new Color32(byte.MaxValue, 0, 0, 0);
            case Heightmap.Biome.Mountain:             case Heightmap.Biome.Mountain:
                return new Color32(0, byte.MaxValue, 0, 0);                 return new Color32(0, byte.MaxValue, 0, 0);
            default:             default:
                if (biome == Heightmap.Biome.BlackForest)                 if (biome == Heightmap.Biome.BlackForest)
                {                 {
                    return new Color32(0, 0, byte.MaxValue, 0);                     return new Color32(0, 0, byte.MaxValue, 0);
                }                 }
                if (biome == Heightmap.Biome.Plains)                 if (biome == Heightmap.Biome.Plains)
                {                 {
                    return new Color32(0, 0, 0, byte.MaxValue);                     return new Color32(0, 0, 0, byte.MaxValue);
                }                 }
                break;                 break;
            }             }
        }         }
        else         else
        {         {
            if (biome == Heightmap.Biome.AshLands)             if (biome == Heightmap.Biome.AshLands)
            {             {
                return new Color32(byte.MaxValue, 0, 0, byte.MaxValue);                 return new Color32(byte.MaxValue, 0, 0, byte.MaxValue);
            }             }
            if (biome == Heightmap.Biome.DeepNorth)             if (biome == Heightmap.Biome.DeepNorth)
            {             {
                return new Color32(0, byte.MaxValue, 0, 0);                 return new Color32(0, byte.MaxValue, 0, 0);
            }             }
            if (biome == Heightmap.Biome.Mistlands)             if (biome == Heightmap.Biome.Mistlands)
            {             {
                return new Color32(0, 0, byte.MaxValue, byte.MaxValue);                 return new Color32(0, 0, byte.MaxValue, byte.MaxValue);
            }             }
        }         }
        return new Color32(0, 0, 0, 0);         return new Color32(0, 0, 0, 0);
    }     }
   
    private void RebuildCollisionMesh()     private void RebuildCollisionMesh()
    {     {
        if (this.m_collisionMesh == null)         if (this.m_collisionMesh == null)
        {         {
            this.m_collisionMesh = new Mesh();             this.m_collisionMesh = new Mesh();
            this.m_collisionMesh.name = "___Heightmap m_collisionMesh";             this.m_collisionMesh.name = "___Heightmap m_collisionMesh";
        }         }
        int num = this.m_width + 1;         int num = this.m_width + 1;
        float num2 = -999999f;         float num2 = -999999f;
        float num3 = 999999f;         float num3 = 999999f;
        Heightmap.s_tempVertices.Clear();         Heightmap.s_tempVertices.Clear();
        for (int i = 0; i < num; i++)         for (int i = 0; i < num; i++)
        {         {
            for (int j = 0; j < num; j++)             for (int j = 0; j < num; j++)
            {             {
                Vector3 vector = this.CalcVertex(j, i);                 Vector3 vector = this.CalcVertex(j, i);
                Heightmap.s_tempVertices.Add(vector);                 Heightmap.s_tempVertices.Add(vector);
                if (vector.y > num2)                 if (vector.y > num2)
                {                 {
                    num2 = vector.y;                     num2 = vector.y;
                }                 }
                if (vector.y < num3)                 if (vector.y < num3)
                {                 {
                    num3 = vector.y;                     num3 = vector.y;
                }                 }
            }             }
        }         }
        this.m_collisionMesh.SetVertices(Heightmap.s_tempVertices);         this.m_collisionMesh.SetVertices(Heightmap.s_tempVertices);
        int num4 = (num - 1) * (num - 1) * 6;         int num4 = (num - 1) * (num - 1) * 6;
        if ((ulong)this.m_collisionMesh.GetIndexCount(0) != (ulong)((long)num4))         if ((ulong)this.m_collisionMesh.GetIndexCount(0) != (ulong)((long)num4))
        {         {
            Heightmap.s_tempIndices.Clear();             Heightmap.s_tempIndices.Clear();
            for (int k = 0; k < num - 1; k++)             for (int k = 0; k < num - 1; k++)
            {             {
                for (int l = 0; l < num - 1; l++)                 for (int l = 0; l < num - 1; l++)
                {                 {
                    int num5 = k * num + l;                     int num5 = k * num + l;
                    int num6 = k * num + l + 1;                     int num6 = k * num + l + 1;
                    int num7 = (k + 1) * num + l + 1;                     int num7 = (k + 1) * num + l + 1;
                    int num8 = (k + 1) * num + l;                     int num8 = (k + 1) * num + l;
                    Heightmap.s_tempIndices.Add(num5);                     Heightmap.s_tempIndices.Add(num5);
                    Heightmap.s_tempIndices.Add(num8);                     Heightmap.s_tempIndices.Add(num8);
                    Heightmap.s_tempIndices.Add(num6);                     Heightmap.s_tempIndices.Add(num6);
                    Heightmap.s_tempIndices.Add(num6);                     Heightmap.s_tempIndices.Add(num6);
                    Heightmap.s_tempIndices.Add(num8);                     Heightmap.s_tempIndices.Add(num8);
                    Heightmap.s_tempIndices.Add(num7);                     Heightmap.s_tempIndices.Add(num7);
                }                 }
            }             }
            this.m_collisionMesh.SetIndices(Heightmap.s_tempIndices.ToArray(), MeshTopology.Triangles, 0);             this.m_collisionMesh.SetIndices(Heightmap.s_tempIndices.ToArray(), MeshTopology.Triangles, 0);
        }         }
        if (this.m_collider)         if (this.m_collider)
        {         {
            this.m_collider.sharedMesh = this.m_collisionMesh;             this.m_collider.sharedMesh = this.m_collisionMesh;
        }         }
        float num9 = (float)this.m_width * this.m_scale * 0.5f;         float num9 = (float)this.m_width * this.m_scale * 0.5f;
        this.m_bounds.SetMinMax(base.transform.position + new Vector3(-num9, num3, -num9), base.transform.position + new Vector3(num9, num2, num9));         this.m_bounds.SetMinMax(base.transform.position + new Vector3(-num9, num3, -num9), base.transform.position + new Vector3(num9, num2, num9));
        this.m_boundingSphere.position = this.m_bounds.center;         this.m_boundingSphere.position = this.m_bounds.center;
        this.m_boundingSphere.radius = Vector3.Distance(this.m_boundingSphere.position, this.m_bounds.max);         this.m_boundingSphere.radius = Vector3.Distance(this.m_boundingSphere.position, this.m_bounds.max);
    }     }
   
    private void RebuildRenderMesh()     private void RebuildRenderMesh()
    {     {
        if (this.m_renderMesh == null)         if (this.m_renderMesh == null)
        {         {
            this.m_renderMesh = new Mesh();             this.m_renderMesh = new Mesh();
            this.m_renderMesh.name = "___Heightmap m_renderMesh";             this.m_renderMesh.name = "___Heightmap m_renderMesh";
        }         }
        WorldGenerator instance = WorldGenerator.instance;         WorldGenerator instance = WorldGenerator.instance;
        int num = this.m_width + 1;         int num = this.m_width + 1;
        Vector3 vector = base.transform.position + new Vector3((float)((double)this.m_width * (double)this.m_scale * -0.5), 0f, (float)((double)this.m_width * (double)this.m_scale * -0.5));         Vector3 vector = base.transform.position + new Vector3((float)((double)this.m_width * (double)this.m_scale * -0.5), 0f, (float)((double)this.m_width * (double)this.m_scale * -0.5));
        Heightmap.s_tempVertices.Clear();         Heightmap.s_tempVertices.Clear();
        Heightmap.s_tempUVs.Clear();         Heightmap.s_tempUVs.Clear();
        Heightmap.s_tempIndices.Clear();         Heightmap.s_tempIndices.Clear();
        Heightmap.s_tempColors.Clear();         Heightmap.s_tempColors.Clear();
        for (int i = 0; i < num; i++)         for (int i = 0; i < num; i++)
        {         {
            float num2 = DUtils.SmoothStep(0f, 1f, (float)((double)i / (double)this.m_width));             float num2 = DUtils.SmoothStep(0f, 1f, (float)((double)i / (double)this.m_width));
            for (int j = 0; j < num; j++)             for (int j = 0; j < num; j++)
            {             {
                float num3 = DUtils.SmoothStep(0f, 1f, (float)((double)j / (double)this.m_width));                 float num3 = DUtils.SmoothStep(0f, 1f, (float)((double)j / (double)this.m_width));
                Heightmap.s_tempUVs.Add(new Vector2((float)((double)j / (double)this.m_width), (float)((double)i / (double)this.m_width)));                 Heightmap.s_tempUVs.Add(new Vector2((float)((double)j / (double)this.m_width), (float)((double)i / (double)this.m_width)));
                if (this.m_isDistantLod)                 if (this.m_isDistantLod)
                {                 {
                    float num4 = (float)((double)vector.x + (double)j * (double)this.m_scale);                     float num4 = (float)((double)vector.x + (double)j * (double)this.m_scale);
                    float num5 = (float)((double)vector.z + (double)i * (double)this.m_scale);                     float num5 = (float)((double)vector.z + (double)i * (double)this.m_scale);
.                    Heightmap.Biome biome = instance.GetBiome(num4, num5);                     Heightmap.Biome biome = instance.GetBiome(num4, num5, 0.02f, false);
                    Heightmap.s_tempColors.Add(Heightmap.GetBiomeColor(biome));                     Heightmap.s_tempColors.Add(Heightmap.GetBiomeColor(biome));
                }                 }
                else                 else
                {                 {
                    Heightmap.s_tempColors.Add(this.GetBiomeColor(num3, num2));                     Heightmap.s_tempColors.Add(this.GetBiomeColor(num3, num2));
                }                 }
            }             }
        }         }
        this.m_collisionMesh.GetVertices(Heightmap.s_tempVertices);         this.m_collisionMesh.GetVertices(Heightmap.s_tempVertices);
        this.m_collisionMesh.GetIndices(Heightmap.s_tempIndices, 0);         this.m_collisionMesh.GetIndices(Heightmap.s_tempIndices, 0);
        this.m_renderMesh.Clear();         this.m_renderMesh.Clear();
        this.m_renderMesh.SetVertices(Heightmap.s_tempVertices);         this.m_renderMesh.SetVertices(Heightmap.s_tempVertices);
        this.m_renderMesh.SetColors(Heightmap.s_tempColors);         this.m_renderMesh.SetColors(Heightmap.s_tempColors);
        this.m_renderMesh.SetUVs(0, Heightmap.s_tempUVs);         this.m_renderMesh.SetUVs(0, Heightmap.s_tempUVs);
        this.m_renderMesh.SetIndices(Heightmap.s_tempIndices, MeshTopology.Triangles, 0, true, 0);         this.m_renderMesh.SetIndices(Heightmap.s_tempIndices, MeshTopology.Triangles, 0, true, 0);
        this.m_renderMesh.RecalculateNormals();         this.m_renderMesh.RecalculateNormals();
        this.m_renderMesh.RecalculateTangents();         this.m_renderMesh.RecalculateTangents();
        this.m_renderMesh.RecalculateBounds();         this.m_renderMesh.RecalculateBounds();
        this.m_meshFilter.mesh = this.m_renderMesh;         this.m_meshFilter.mesh = this.m_renderMesh;
    }     }
   
    private void SmoothTerrain2(Vector3 worldPos, float radius, bool square, float[] levelOnlyHeights, float power, bool playerModifiction)     private void SmoothTerrain2(Vector3 worldPos, float radius, bool square, float[] levelOnlyHeights, float power, bool playerModifiction)
    {     {
        int num;         int num;
        int num2;         int num2;
        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertex(worldPos, out num, out num2);
        float num3 = (float)((double)(worldPos.y - base.transform.position.y));         float num3 = (float)((double)(worldPos.y - base.transform.position.y));
        float num4 = (float)((double)(radius / this.m_scale));         float num4 = (float)((double)(radius / this.m_scale));
        int num5 = Mathf.CeilToInt(num4);         int num5 = Mathf.CeilToInt(num4);
        Vector2 vector = new Vector2((float)num, (float)num2);         Vector2 vector = new Vector2((float)num, (float)num2);
        int num6 = this.m_width + 1;         int num6 = this.m_width + 1;
        for (int i = num2 - num5; i <= num2 + num5; i++)         for (int i = num2 - num5; i <= num2 + num5; i++)
        {         {
            for (int j = num - num5; j <= num + num5; j++)             for (int j = num - num5; j <= num + num5; j++)
            {             {
                float num7 = Vector2.Distance(vector, new Vector2((float)j, (float)i));                 float num7 = Vector2.Distance(vector, new Vector2((float)j, (float)i));
                if (num7 <= num4)                 if (num7 <= num4)
                {                 {
                    float num8 = num7 / num4;                     float num8 = num7 / num4;
                    if (j >= 0 && i >= 0 && j < num6 && i < num6)                     if (j >= 0 && i >= 0 && j < num6 && i < num6)
                    {                     {
                        if (power == 3f)                         if (power == 3f)
                        {                         {
                            num8 = (float)((double)num8 * (double)num8 * (double)num8);                             num8 = (float)((double)num8 * (double)num8 * (double)num8);
                        }                         }
                        else                         else
                        {                         {
                            num8 = Mathf.Pow(num8, power);                             num8 = Mathf.Pow(num8, power);
                        }                         }
                        float height = this.GetHeight(j, i);                         float height = this.GetHeight(j, i);
                        float num9 = (float)(1.0 - (double)num8);                         float num9 = (float)(1.0 - (double)num8);
                        float num10 = DUtils.Lerp(height, num3, num9);                         float num10 = DUtils.Lerp(height, num3, num9);
                        if (playerModifiction)                         if (playerModifiction)
                        {                         {
                            float num11 = levelOnlyHeights[i * num6 + j];                             float num11 = levelOnlyHeights[i * num6 + j];
                            num10 = Mathf.Clamp(num10, (float)((double)num11 - 1.0), (float)((double)num11 + 1.0));                             num10 = Mathf.Clamp(num10, (float)((double)num11 - 1.0), (float)((double)num11 + 1.0));
                        }                         }
                        this.SetHeight(j, i, num10);                         this.SetHeight(j, i, num10);
                    }                     }
                }                 }
            }             }
        }         }
    }     }
   
    private bool AtMaxWorldLevelDepth(Vector3 worldPos)     private bool AtMaxWorldLevelDepth(Vector3 worldPos)
    {     {
        float num;         float num;
        this.GetWorldHeight(worldPos, out num);         this.GetWorldHeight(worldPos, out num);
        float num2;         float num2;
        this.GetWorldBaseHeight(worldPos, out num2);         this.GetWorldBaseHeight(worldPos, out num2);
        return Mathf.Max(-(float)((double)num - (double)num2), 0f) >= 7.95f;         return Mathf.Max(-(float)((double)num - (double)num2), 0f) >= 7.95f;
    }     }
   
    private bool GetWorldBaseHeight(Vector3 worldPos, out float height)     private bool GetWorldBaseHeight(Vector3 worldPos, out float height)
    {     {
        int num;         int num;
        int num2;         int num2;
        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertex(worldPos, out num, out num2);
        int num3 = this.m_width + 1;         int num3 = this.m_width + 1;
        if (num < 0 || num2 < 0 || num >= num3 || num2 >= num3)         if (num < 0 || num2 < 0 || num >= num3 || num2 >= num3)
        {         {
            height = 0f;             height = 0f;
            return false;             return false;
        }         }
        height = (float)((double)this.m_buildData.m_baseHeights[num2 * num3 + num] + (double)base.transform.position.y);         height = (float)((double)this.m_buildData.m_baseHeights[num2 * num3 + num] + (double)base.transform.position.y);
        return true;         return true;
    }     }
   
    private bool GetWorldHeight(Vector3 worldPos, out float height)     private bool GetWorldHeight(Vector3 worldPos, out float height)
    {     {
        int num;         int num;
        int num2;         int num2;
        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertex(worldPos, out num, out num2);
        int num3 = this.m_width + 1;         int num3 = this.m_width + 1;
        if (num < 0 || num2 < 0 || num >= num3 || num2 >= num3)         if (num < 0 || num2 < 0 || num >= num3 || num2 >= num3)
        {         {
            height = 0f;             height = 0f;
            return false;             return false;
        }         }
        height = (float)((double)this.m_heights[num2 * num3 + num] + (double)base.transform.position.y);         height = (float)((double)this.m_heights[num2 * num3 + num] + (double)base.transform.position.y);
        return true;         return true;
    }     }
   
    public static bool AtMaxLevelDepth(Vector3 worldPos)     public static bool AtMaxLevelDepth(Vector3 worldPos)
    {     {
        Heightmap heightmap = Heightmap.FindHeightmap(worldPos);         Heightmap heightmap = Heightmap.FindHeightmap(worldPos);
        return heightmap && heightmap.AtMaxWorldLevelDepth(worldPos);         return heightmap && heightmap.AtMaxWorldLevelDepth(worldPos);
    }     }
   
    public static bool GetHeight(Vector3 worldPos, out float height)     public static bool GetHeight(Vector3 worldPos, out float height)
    {     {
        Heightmap heightmap = Heightmap.FindHeightmap(worldPos);         Heightmap heightmap = Heightmap.FindHeightmap(worldPos);
        if (heightmap && heightmap.GetWorldHeight(worldPos, out height))         if (heightmap && heightmap.GetWorldHeight(worldPos, out height))
        {         {
            return true;             return true;
        }         }
        height = 0f;         height = 0f;
        return false;         return false;
    }     }
   
    private void PaintCleared(Vector3 worldPos, float radius, TerrainModifier.PaintType paintType, bool heightCheck, bool apply)     private void PaintCleared(Vector3 worldPos, float radius, TerrainModifier.PaintType paintType, bool heightCheck, bool apply)
    {     {
        worldPos.x -= 0.5f;         worldPos.x -= 0.5f;
        worldPos.z -= 0.5f;         worldPos.z -= 0.5f;
        float num = worldPos.y - base.transform.position.y;         float num = worldPos.y - base.transform.position.y;
        int num2;         int num2;
        int num3;         int num3;
.        this.WorldToVertex(worldPos, out num2, out num3);         this.WorldToVertexMask(worldPos, out num2, out num3);
        float num4 = radius / this.m_scale;         float num4 = radius / this.m_scale;
        int num5 = Mathf.CeilToInt(num4);         int num5 = Mathf.CeilToInt(num4);
        Vector2 vector = new Vector2((float)num2, (float)num3);         Vector2 vector = new Vector2((float)num2, (float)num3);
        for (int i = num3 - num5; i <= num3 + num5; i++)         for (int i = num3 - num5; i <= num3 + num5; i++)
        {         {
            for (int j = num2 - num5; j <= num2 + num5; j++)             for (int j = num2 - num5; j <= num2 + num5; j++)
            {             {
.                if (j >= 0 && i >= 0 && j < this.m_paintMask.width && i < this.m_paintMask.height && (!heightCheck || this.GetHeight(j, i) <= num))                 if (j >= 0 && i >= 0 && j < this.m_paintMask.width + 1 && i < this.m_paintMask.height + 1 && (!heightCheck || this.GetHeight(j, i) <= num))
                {                 {
                    float num6 = Vector2.Distance(vector, new Vector2((float)j, (float)i));                     float num6 = Vector2.Distance(vector, new Vector2((float)j, (float)i));
                    float num7 = 1f - Mathf.Clamp01(num6 / num4);                     float num7 = 1f - Mathf.Clamp01(num6 / num4);
                    num7 = Mathf.Pow(num7, 0.1f);                     num7 = Mathf.Pow(num7, 0.1f);
                    Color color = this.m_paintMask.GetPixel(j, i);                     Color color = this.m_paintMask.GetPixel(j, i);
                    float a = color.a;                     float a = color.a;
                    switch (paintType)                     switch (paintType)
                    {                     {
                    case TerrainModifier.PaintType.Dirt:                     case TerrainModifier.PaintType.Dirt:
                        color = Color.Lerp(color, Heightmap.m_paintMaskDirt, num7);                         color = Color.Lerp(color, Heightmap.m_paintMaskDirt, num7);
                        break;                         break;
                    case TerrainModifier.PaintType.Cultivate:                     case TerrainModifier.PaintType.Cultivate:
                        color = Color.Lerp(color, Heightmap.m_paintMaskCultivated, num7);                         color = Color.Lerp(color, Heightmap.m_paintMaskCultivated, num7);
                        break;                         break;
                    case TerrainModifier.PaintType.Paved:                     case TerrainModifier.PaintType.Paved:
                        color = Color.Lerp(color, Heightmap.m_paintMaskPaved, num7);                         color = Color.Lerp(color, Heightmap.m_paintMaskPaved, num7);
                        break;                         break;
                    case TerrainModifier.PaintType.Reset:                     case TerrainModifier.PaintType.Reset:
                        color = Color.Lerp(color, Heightmap.m_paintMaskNothing, num7);                         color = Color.Lerp(color, Heightmap.m_paintMaskNothing, num7);
                        break;                         break;
.                      case TerrainModifier.PaintType.ClearVegetation:
                          color = Color.Lerp(color, Heightmap.m_paintMaskClearVegetation, num7);
                          break;
                      }
                      if (paintType != TerrainModifier.PaintType.ClearVegetation)
                      {
                          color.a = a;
                    }                     }
.                    color.a = a;  
                    this.m_paintMask.SetPixel(j, i, color);                     this.m_paintMask.SetPixel(j, i, color);
                }                 }
            }             }
        }         }
        if (apply)         if (apply)
        {         {
            this.m_paintMask.Apply();             this.m_paintMask.Apply();
        }         }
    }     }
   
    public float GetVegetationMask(Vector3 worldPos)     public float GetVegetationMask(Vector3 worldPos)
    {     {
        worldPos.x -= 0.5f;         worldPos.x -= 0.5f;
        worldPos.z -= 0.5f;         worldPos.z -= 0.5f;
        int num;         int num;
        int num2;         int num2;
.        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertexMask(worldPos, out num, out num2);
        return this.m_paintMask.GetPixel(num, num2).a;         return this.m_paintMask.GetPixel(num, num2).a;
    }     }
   
    public bool IsCleared(Vector3 worldPos)     public bool IsCleared(Vector3 worldPos)
    {     {
        worldPos.x = (float)((double)worldPos.x - 0.5);         worldPos.x = (float)((double)worldPos.x - 0.5);
        worldPos.z = (float)((double)worldPos.z - 0.5);         worldPos.z = (float)((double)worldPos.z - 0.5);
        int num;         int num;
        int num2;         int num2;
.        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertexMask(worldPos, out num, out num2);
        Color pixel = this.m_paintMask.GetPixel(num, num2);         Color pixel = this.m_paintMask.GetPixel(num, num2);
        return pixel.r > 0.5f || pixel.g > 0.5f || pixel.b > 0.5f;         return pixel.r > 0.5f || pixel.g > 0.5f || pixel.b > 0.5f;
    }     }
   
    public bool IsCultivated(Vector3 worldPos)     public bool IsCultivated(Vector3 worldPos)
    {     {
        int num;         int num;
        int num2;         int num2;
.        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertexMask(worldPos, out num, out num2);
        return this.m_paintMask.GetPixel(num, num2).g > 0.5f;         return this.m_paintMask.GetPixel(num, num2).g > 0.5f;
    }     }
   
.      public bool IsLava(Vector3 worldPos, float lavaValue = 0.6f)
      {
          return this.GetBiome(worldPos, 0.02f, false) == Heightmap.Biome.AshLands && !this.IsBiomeEdge() && this.GetVegetationMask(worldPos) > lavaValue;
      }
   
      public float GetLava(Vector3 worldPos)
      {
          if (this.GetBiome(worldPos, 0.02f, false) != Heightmap.Biome.AshLands || this.IsBiomeEdge())
          {
              return 0f;
          }
          return this.GetVegetationMask(worldPos);
      }
   
      public float GetHeightOffset(Vector3 worldPos)
      {
          if (this.GetBiome(worldPos, 0.02f, false) != Heightmap.Biome.AshLands)
          {
              return 0f;
          }
          if (this.IsBiomeEdge())
          {
              return Heightmap.GetGroundMaterialOffset(FootStep.GroundMaterial.Ashlands);
          }
          float vegetationMask = this.GetVegetationMask(worldPos);
          return Mathf.Lerp(Heightmap.GetGroundMaterialOffset(FootStep.GroundMaterial.Ashlands), Heightmap.GetGroundMaterialOffset(FootStep.GroundMaterial.Lava), vegetationMask);
      }
   
    public void WorldToVertex(Vector3 worldPos, out int x, out int y)     public void WorldToVertex(Vector3 worldPos, out int x, out int y)
    {     {
        Vector3 vector = worldPos - base.transform.position;         Vector3 vector = worldPos - base.transform.position;
.        x = Mathf.FloorToInt(vector.x / this.m_scale + 0.5f) + this.m_width / 2;         int num = this.m_width / 2; 
        y = Mathf.FloorToInt(vector.z / this.m_scale + 0.5f) + this.m_width / 2;         x = Mathf.FloorToInt(vector.x / this.m_scale + 0.5f) + num; 
          y = Mathf.FloorToInt(vector.z / this.m_scale + 0.5f) + num; 
      } 
   
      public void WorldToVertexMask(Vector3 worldPos, out int x, out int y) 
      { 
          Vector3 vector = worldPos - base.transform.position; 
          int num = (this.m_width + 1) / 2;
          x = Mathf.FloorToInt(vector.x / this.m_scale + 0.5f) + num; 
          y = Mathf.FloorToInt(vector.z / this.m_scale + 0.5f) + num;
    }     }
   
    private void WorldToNormalizedHM(Vector3 worldPos, out float x, out float y)     private void WorldToNormalizedHM(Vector3 worldPos, out float x, out float y)
    {     {
        float num = (float)this.m_width * this.m_scale;         float num = (float)this.m_width * this.m_scale;
        Vector3 vector = worldPos - base.transform.position;         Vector3 vector = worldPos - base.transform.position;
        x = vector.x / num + 0.5f;         x = vector.x / num + 0.5f;
        y = vector.z / num + 0.5f;         y = vector.z / num + 0.5f;
    }     }
   
    private void LevelTerrain(Vector3 worldPos, float radius, bool square, float[] baseHeights, float[] levelOnly, bool playerModifiction)     private void LevelTerrain(Vector3 worldPos, float radius, bool square, float[] baseHeights, float[] levelOnly, bool playerModifiction)
    {     {
        int num;         int num;
        int num2;         int num2;
.        this.WorldToVertex(worldPos, out num, out num2);         this.WorldToVertexMask(worldPos, out num, out num2);
        Vector3 vector = worldPos - base.transform.position;         Vector3 vector = worldPos - base.transform.position;
        float num3 = (float)((double)radius / (double)this.m_scale);         float num3 = (float)((double)radius / (double)this.m_scale);
        int num4 = Mathf.CeilToInt(num3);         int num4 = Mathf.CeilToInt(num3);
        int num5 = this.m_width + 1;         int num5 = this.m_width + 1;
        Vector2 vector2 = new Vector2((float)num, (float)num2);         Vector2 vector2 = new Vector2((float)num, (float)num2);
        for (int i = num2 - num4; i <= num2 + num4; i++)         for (int i = num2 - num4; i <= num2 + num4; i++)
        {         {
            for (int j = num - num4; j <= num + num4; j++)             for (int j = num - num4; j <= num + num4; j++)
            {             {
                if ((square || Vector2.Distance(vector2, new Vector2((float)j, (float)i)) <= num3) && j >= 0 && i >= 0 && j < num5 && i < num5)                 if ((square || Vector2.Distance(vector2, new Vector2((float)j, (float)i)) <= num3) && j >= 0 && i >= 0 && j < num5 && i < num5)
                {                 {
                    float num6 = vector.y;                     float num6 = vector.y;
                    if (playerModifiction)                     if (playerModifiction)
                    {                     {
                        float num7 = baseHeights[i * num5 + j];                         float num7 = baseHeights[i * num5 + j];
                        num6 = Mathf.Clamp(num6, (float)((double)num7 - 8.0), (float)((double)num7 + 8.0));                         num6 = Mathf.Clamp(num6, (float)((double)num7 - 8.0), (float)((double)num7 + 8.0));
                        levelOnly[i * num5 + j] = num6;                         levelOnly[i * num5 + j] = num6;
                    }                     }
                    this.SetHeight(j, i, num6);                     this.SetHeight(j, i, num6);
                }                 }
            }             }
        }         }
    }     }
   
    public Color GetPaintMask(int x, int y)     public Color GetPaintMask(int x, int y)
    {     {
.        if (x < 0 || y < 0 || x >= this.m_width || y >= this.m_width)         if (x < 0 || y < 0 || x >= this.m_paintMask.width || y >= this.m_paintMask.height)
        {         {
            return Color.black;             return Color.black;
        }         }
        return this.m_paintMask.GetPixel(x, y);         return this.m_paintMask.GetPixel(x, y);
    }     }
   
.      public Texture2D GetPaintMask()
      {
          return this.m_paintMask;
      }
   
    private void SetPaintMask(int x, int y, Color paint)     private void SetPaintMask(int x, int y, Color paint)
    {     {
        if (x < 0 || y < 0 || x >= this.m_width || y >= this.m_width)         if (x < 0 || y < 0 || x >= this.m_width || y >= this.m_width)
        {         {
            return;             return;
        }         }
        this.m_paintMask.SetPixel(x, y, paint);         this.m_paintMask.SetPixel(x, y, paint);
    }     }
   
    public float GetHeight(int x, int y)     public float GetHeight(int x, int y)
    {     {
        int num = this.m_width + 1;         int num = this.m_width + 1;
        if (x < 0 || y < 0 || x >= num || y >= num)         if (x < 0 || y < 0 || x >= num || y >= num)
        {         {
            return 0f;             return 0f;
        }         }
        return this.m_heights[y * num + x];         return this.m_heights[y * num + x];
    }     }
   
    public void SetHeight(int x, int y, float h)     public void SetHeight(int x, int y, float h)
    {     {
        int num = this.m_width + 1;         int num = this.m_width + 1;
        if (x < 0 || y < 0 || x >= num || y >= num)         if (x < 0 || y < 0 || x >= num || y >= num)
        {         {
            return;             return;
        }         }
        this.m_heights[y * num + x] = h;         this.m_heights[y * num + x] = h;
    }     }
   
    public bool IsPointInside(Vector3 point, float radius = 0f)     public bool IsPointInside(Vector3 point, float radius = 0f)
    {     {
        float num = (float)((double)this.m_width * (double)this.m_scale * 0.5);         float num = (float)((double)this.m_width * (double)this.m_scale * 0.5);
        Vector3 position = base.transform.position;         Vector3 position = base.transform.position;
        return (float)((double)point.x + (double)radius) >= (float)((double)position.x - (double)num) && (float)((double)point.x - (double)radius) <= (float)((double)position.x + (double)num) && (float)((double)point.z + (double)radius) >= (float)((double)position.z - (double)num) && (float)((double)point.z - (double)radius) <= (float)((double)position.z + (double)num);         return (float)((double)point.x + (double)radius) >= (float)((double)position.x - (double)num) && (float)((double)point.x - (double)radius) <= (float)((double)position.x + (double)num) && (float)((double)point.z + (double)radius) >= (float)((double)position.z - (double)num) && (float)((double)point.z - (double)radius) <= (float)((double)position.z + (double)num);
    }     }
   
    public static List<Heightmap> GetAllHeightmaps()     public static List<Heightmap> GetAllHeightmaps()
    {     {
        return Heightmap.s_heightmaps;         return Heightmap.s_heightmaps;
    }     }
   
    public static Heightmap FindHeightmap(Vector3 point)     public static Heightmap FindHeightmap(Vector3 point)
    {     {
        foreach (Heightmap heightmap in Heightmap.s_heightmaps)         foreach (Heightmap heightmap in Heightmap.s_heightmaps)
        {         {
            if (heightmap.IsPointInside(point, 0f))             if (heightmap.IsPointInside(point, 0f))
            {             {
                return heightmap;                 return heightmap;
            }             }
        }         }
        return null;         return null;
    }     }
   
    public static void FindHeightmap(Vector3 point, float radius, List<Heightmap> heightmaps)     public static void FindHeightmap(Vector3 point, float radius, List<Heightmap> heightmaps)
    {     {
        foreach (Heightmap heightmap in Heightmap.s_heightmaps)         foreach (Heightmap heightmap in Heightmap.s_heightmaps)
        {         {
            if (heightmap.IsPointInside(point, radius))             if (heightmap.IsPointInside(point, radius))
            {             {
                heightmaps.Add(heightmap);                 heightmaps.Add(heightmap);
            }             }
        }         }
    }     }
   
    public static Heightmap.Biome FindBiome(Vector3 point)     public static Heightmap.Biome FindBiome(Vector3 point)
    {     {
        Heightmap heightmap = Heightmap.FindHeightmap(point);         Heightmap heightmap = Heightmap.FindHeightmap(point);
        if (!heightmap)         if (!heightmap)
        {         {
            return Heightmap.Biome.None;             return Heightmap.Biome.None;
        }         }
.        return heightmap.GetBiome(point);         return heightmap.GetBiome(point, 0.02f, false);
    }     }
   
    public static bool HaveQueuedRebuild(Vector3 point, float radius)     public static bool HaveQueuedRebuild(Vector3 point, float radius)
    {     {
        Heightmap.s_tempHmaps.Clear();         Heightmap.s_tempHmaps.Clear();
        Heightmap.FindHeightmap(point, radius, Heightmap.s_tempHmaps);         Heightmap.FindHeightmap(point, radius, Heightmap.s_tempHmaps);
        using (List<Heightmap>.Enumerator enumerator = Heightmap.s_tempHmaps.GetEnumerator())         using (List<Heightmap>.Enumerator enumerator = Heightmap.s_tempHmaps.GetEnumerator())
        {         {
            while (enumerator.MoveNext())             while (enumerator.MoveNext())
            {             {
                if (enumerator.Current.HaveQueuedRebuild())                 if (enumerator.Current.HaveQueuedRebuild())
                {                 {
                    return true;                     return true;
                }                 }
            }             }
        }         }
        return false;         return false;
    }     }
   
    public static void UpdateTerrainAlpha()     public static void UpdateTerrainAlpha()
    {     {
        if (Player.m_localPlayer == null)         if (Player.m_localPlayer == null)
        {         {
            return;             return;
        }         }
        List<Heightmap> list = new List<Heightmap>();         List<Heightmap> list = new List<Heightmap>();
        Heightmap.FindHeightmap(Player.m_localPlayer.transform.position, 150f, list);         Heightmap.FindHeightmap(Player.m_localPlayer.transform.position, 150f, list);
        bool flag = false;         bool flag = false;
        using (List<Heightmap>.Enumerator enumerator = list.GetEnumerator())         using (List<Heightmap>.Enumerator enumerator = list.GetEnumerator())
        {         {
            while (enumerator.MoveNext())             while (enumerator.MoveNext())
            {             {
                if (Heightmap.UpdateTerrainAlpha(enumerator.Current))                 if (Heightmap.UpdateTerrainAlpha(enumerator.Current))
                {                 {
                    flag = true;                     flag = true;
                }                 }
            }             }
        }         }
        if (!flag)         if (!flag)
        {         {
            global::Console.instance.Print("Nothing to update");             global::Console.instance.Print("Nothing to update");
            return;             return;
        }         }
        global::Console.instance.Print("Updated terrain alpha");         global::Console.instance.Print("Updated terrain alpha");
    }     }
   
    public static bool UpdateTerrainAlpha(Heightmap hmap)     public static bool UpdateTerrainAlpha(Heightmap hmap)
    {     {
        HeightmapBuilder.HMBuildData hmbuildData = HeightmapBuilder.instance.RequestTerrainSync(hmap.transform.position, hmap.m_width, hmap.m_scale, hmap.IsDistantLod, WorldGenerator.instance);         HeightmapBuilder.HMBuildData hmbuildData = HeightmapBuilder.instance.RequestTerrainSync(hmap.transform.position, hmap.m_width, hmap.m_scale, hmap.IsDistantLod, WorldGenerator.instance);
        int num = 0;         int num = 0;
        for (int i = 0; i < hmap.m_width; i++)         for (int i = 0; i < hmap.m_width; i++)
        {         {
            for (int j = 0; j < hmap.m_width; j++)             for (int j = 0; j < hmap.m_width; j++)
            {             {
                int num2 = i * hmap.m_width + j;                 int num2 = i * hmap.m_width + j;
                float a = hmbuildData.m_baseMask[num2].a;                 float a = hmbuildData.m_baseMask[num2].a;
                Color paintMask = hmap.GetPaintMask(j, i);                 Color paintMask = hmap.GetPaintMask(j, i);
                if (a != paintMask.a)                 if (a != paintMask.a)
                {                 {
                    paintMask.a = a;                     paintMask.a = a;
                    hmap.SetPaintMask(j, i, paintMask);                     hmap.SetPaintMask(j, i, paintMask);
                    num++;                     num++;
                }                 }
            }             }
        }         }
        if (num > 0)         if (num > 0)
        {         {
            hmap.GetAndCreateTerrainCompiler().UpdatePaintMask(hmap);             hmap.GetAndCreateTerrainCompiler().UpdatePaintMask(hmap);
        }         }
        return num > 0;         return num > 0;
    }     }
   
.      public FootStep.GroundMaterial GetGroundMaterial(Vector3 groundNormal, Vector3 point, float lavaValue = 0.6f)
      {
          float num = Mathf.Acos(Mathf.Clamp01(groundNormal.y)) * 57.29578f;
          Heightmap.Biome biome = this.GetBiome(point, 0.02f, false);
          if (biome == Heightmap.Biome.Mountain || biome == Heightmap.Biome.DeepNorth)
          {
              if (num < 40f && !this.IsCleared(point))
              {
                  return FootStep.GroundMaterial.Snow;
              }
          }
          else if (biome == Heightmap.Biome.Swamp)
          {
              if (num < 40f)
              {
                  return FootStep.GroundMaterial.Mud;
              }
          }
          else if (biome == Heightmap.Biome.Meadows || biome == Heightmap.Biome.BlackForest)
          {
              if (num < 25f)
              {
                  return FootStep.GroundMaterial.Grass;
              }
          }
          else if (biome == Heightmap.Biome.AshLands)
          {
              if (this.IsLava(point, lavaValue))
              {
                  return FootStep.GroundMaterial.Lava;
              }
              return FootStep.GroundMaterial.Ashlands;
          }
          return FootStep.GroundMaterial.GenericGround;
      }
   
      public static float GetGroundMaterialOffset(FootStep.GroundMaterial material)
      {
          if (material == FootStep.GroundMaterial.Snow)
          {
              return 0.1f;
          }
          if (material == FootStep.GroundMaterial.Ashlands)
          {
              return 0.1f;
          }
          if (material != FootStep.GroundMaterial.Lava)
          {
              return 0f;
          }
          return 0.8f;
      }
   
    public static Heightmap.Biome FindBiomeClutter(Vector3 point)     public static Heightmap.Biome FindBiomeClutter(Vector3 point)
    {     {
        if (ZoneSystem.instance && !ZoneSystem.instance.IsZoneLoaded(point))         if (ZoneSystem.instance && !ZoneSystem.instance.IsZoneLoaded(point))
        {         {
            return Heightmap.Biome.None;             return Heightmap.Biome.None;
        }         }
        Heightmap heightmap = Heightmap.FindHeightmap(point);         Heightmap heightmap = Heightmap.FindHeightmap(point);
        if (heightmap)         if (heightmap)
        {         {
.            return heightmap.GetBiome(point);             return heightmap.GetBiome(point, 0.02f, false);
        }         }
        return Heightmap.Biome.None;         return Heightmap.Biome.None;
    }     }
   
    public void Clear()     public void Clear()
    {     {
        this.m_heights.Clear();         this.m_heights.Clear();
        this.m_paintMask = null;         this.m_paintMask = null;
        this.m_materialInstance = null;         this.m_materialInstance = null;
        this.m_buildData = null;         this.m_buildData = null;
        if (this.m_collisionMesh)         if (this.m_collisionMesh)
        {         {
            this.m_collisionMesh.Clear();             this.m_collisionMesh.Clear();
        }         }
        if (this.m_renderMesh)         if (this.m_renderMesh)
        {         {
            this.m_renderMesh.Clear();             this.m_renderMesh.Clear();
        }         }
        if (this.m_collider)         if (this.m_collider)
        {         {
            this.m_collider.sharedMesh = null;             this.m_collider.sharedMesh = null;
        }         }
    }     }
   
    public TerrainComp GetAndCreateTerrainCompiler()     public TerrainComp GetAndCreateTerrainCompiler()
    {     {
        TerrainComp terrainComp = TerrainComp.FindTerrainCompiler(base.transform.position);         TerrainComp terrainComp = TerrainComp.FindTerrainCompiler(base.transform.position);
        if (terrainComp)         if (terrainComp)
        {         {
            return terrainComp;             return terrainComp;
        }         }
        return UnityEngine.Object.Instantiate<GameObject>(this.m_terrainCompilerPrefab, base.transform.position, Quaternion.identity).GetComponent<TerrainComp>();         return UnityEngine.Object.Instantiate<GameObject>(this.m_terrainCompilerPrefab, base.transform.position, Quaternion.identity).GetComponent<TerrainComp>();
    }     }
   
    public bool IsDistantLod     public bool IsDistantLod
    {     {
        get         get
        {         {
            return this.m_isDistantLod;             return this.m_isDistantLod;
        }         }
        set         set
        {         {
            if (this.m_isDistantLod == value)             if (this.m_isDistantLod == value)
            {             {
                return;                 return;
            }             }
            if (value)             if (value)
            {             {
                Heightmap.s_heightmaps.Remove(this);                 Heightmap.s_heightmaps.Remove(this);
            }             }
            else             else
            {             {
                Heightmap.s_heightmaps.Add(this);                 Heightmap.s_heightmaps.Add(this);
            }             }
            this.m_isDistantLod = value;             this.m_isDistantLod = value;
            this.UpdateShadowSettings();             this.UpdateShadowSettings();
        }         }
    }     }
   
    public event Action m_clearConnectedWearNTearCache;     public event Action m_clearConnectedWearNTearCache;
   
    public static bool EnableDistantTerrainShadows     public static bool EnableDistantTerrainShadows
    {     {
        get         get
        {         {
            return Heightmap.s_enableDistantTerrainShadows;             return Heightmap.s_enableDistantTerrainShadows;
        }         }
        set         set
        {         {
            if (Heightmap.s_enableDistantTerrainShadows == value)             if (Heightmap.s_enableDistantTerrainShadows == value)
            {             {
                return;                 return;
            }             }
            Heightmap.s_enableDistantTerrainShadows = value;             Heightmap.s_enableDistantTerrainShadows = value;
.            foreach (Heightmap heightmap in Heightmap.Instances)             foreach (IMonoUpdater monoUpdater in Heightmap.Instances)
            {             {
.                heightmap.UpdateShadowSettings();                 ((Heightmap)monoUpdater).UpdateShadowSettings();
            }             }
        }         }
    }     }
   
.    public static List<Heightmap> Instances { get; } = new List<Heightmap>();     public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>();
   
    private static readonly Dictionary<Heightmap.Biome, int> s_biomeToIndex = new Dictionary<Heightmap.Biome, int>     private static readonly Dictionary<Heightmap.Biome, int> s_biomeToIndex = new Dictionary<Heightmap.Biome, int>
    {     {
        {         {
            Heightmap.Biome.None,             Heightmap.Biome.None,
            0             0
        },         },
        {         {
            Heightmap.Biome.Meadows,             Heightmap.Biome.Meadows,
            1             1
        },         },
        {         {
            Heightmap.Biome.Swamp,             Heightmap.Biome.Swamp,
            2             2
        },         },
        {         {
            Heightmap.Biome.Mountain,             Heightmap.Biome.Mountain,
            3             3
        },         },
        {         {
            Heightmap.Biome.BlackForest,             Heightmap.Biome.BlackForest,
            4             4
        },         },
        {         {
            Heightmap.Biome.Plains,             Heightmap.Biome.Plains,
            5             5
        },         },
        {         {
            Heightmap.Biome.AshLands,             Heightmap.Biome.AshLands,
            6             6
        },         },
        {         {
            Heightmap.Biome.DeepNorth,             Heightmap.Biome.DeepNorth,
            7             7
        },         },
        {         {
            Heightmap.Biome.Ocean,             Heightmap.Biome.Ocean,
            8             8
        },         },
        {         {
            Heightmap.Biome.Mistlands,             Heightmap.Biome.Mistlands,
            9             9
        }         }
    };     };
   
    private static readonly Heightmap.Biome[] s_indexToBiome = new Heightmap.Biome[]     private static readonly Heightmap.Biome[] s_indexToBiome = new Heightmap.Biome[]
    {     {
        Heightmap.Biome.None,         Heightmap.Biome.None,
        Heightmap.Biome.Meadows,         Heightmap.Biome.Meadows,
        Heightmap.Biome.Swamp,         Heightmap.Biome.Swamp,
        Heightmap.Biome.Mountain,         Heightmap.Biome.Mountain,
        Heightmap.Biome.BlackForest,         Heightmap.Biome.BlackForest,
        Heightmap.Biome.Plains,         Heightmap.Biome.Plains,
        Heightmap.Biome.AshLands,         Heightmap.Biome.AshLands,
        Heightmap.Biome.DeepNorth,         Heightmap.Biome.DeepNorth,
        Heightmap.Biome.Ocean,         Heightmap.Biome.Ocean,
        Heightmap.Biome.Mistlands         Heightmap.Biome.Mistlands
    };     };
   
    private static readonly float[] s_tempBiomeWeights = new float[Enum.GetValues(typeof(Heightmap.Biome)).Length];     private static readonly float[] s_tempBiomeWeights = new float[Enum.GetValues(typeof(Heightmap.Biome)).Length];
   
    public GameObject m_terrainCompilerPrefab;     public GameObject m_terrainCompilerPrefab;
   
    public int m_width = 32;     public int m_width = 32;
   
    public float m_scale = 1f;     public float m_scale = 1f;
   
    public Material m_material;     public Material m_material;
   
    public const float c_LevelMaxDelta = 8f;     public const float c_LevelMaxDelta = 8f;
   
    public const float c_SmoothMaxDelta = 1f;     public const float c_SmoothMaxDelta = 1f;
   
    [SerializeField]     [SerializeField]
    private bool m_isDistantLod;     private bool m_isDistantLod;
   
    private ShadowCastingMode m_shadowMode = ShadowCastingMode.ShadowsOnly;     private ShadowCastingMode m_shadowMode = ShadowCastingMode.ShadowsOnly;
   
    private bool m_receiveShadows;     private bool m_receiveShadows;
   
    public bool m_distantLodEditorHax;     public bool m_distantLodEditorHax;
   
    private static readonly List<Heightmap> s_tempHmaps = new List<Heightmap>();     private static readonly List<Heightmap> s_tempHmaps = new List<Heightmap>();
   
    private readonly List<float> m_heights = new List<float>();     private readonly List<float> m_heights = new List<float>();
   
    private HeightmapBuilder.HMBuildData m_buildData;     private HeightmapBuilder.HMBuildData m_buildData;
   
    private Texture2D m_paintMask;     private Texture2D m_paintMask;
   
    private Material m_materialInstance;     private Material m_materialInstance;
   
    private MeshCollider m_collider;     private MeshCollider m_collider;
   
    private MeshFilter m_meshFilter;     private MeshFilter m_meshFilter;
   
    private MeshRenderer m_meshRenderer;     private MeshRenderer m_meshRenderer;
   
    private RenderGroupSubscriber m_renderGroupSubscriber;     private RenderGroupSubscriber m_renderGroupSubscriber;
   
    private readonly float[] m_oceanDepth = new float[4];     private readonly float[] m_oceanDepth = new float[4];
   
    private Heightmap.Biome[] m_cornerBiomes = new Heightmap.Biome[]     private Heightmap.Biome[] m_cornerBiomes = new Heightmap.Biome[]
    {     {
        Heightmap.Biome.Meadows,         Heightmap.Biome.Meadows,
        Heightmap.Biome.Meadows,         Heightmap.Biome.Meadows,
        Heightmap.Biome.Meadows,         Heightmap.Biome.Meadows,
        Heightmap.Biome.Meadows         Heightmap.Biome.Meadows
    };     };
   
    private Bounds m_bounds;     private Bounds m_bounds;
   
    private BoundingSphere m_boundingSphere;     private BoundingSphere m_boundingSphere;
   
    private Mesh m_collisionMesh;     private Mesh m_collisionMesh;
   
    private Mesh m_renderMesh;     private Mesh m_renderMesh;
   
    private bool m_doLateUpdate;     private bool m_doLateUpdate;
   
    private static readonly List<Heightmap> s_heightmaps = new List<Heightmap>();     private static readonly List<Heightmap> s_heightmaps = new List<Heightmap>();
   
    private static readonly List<Vector3> s_tempVertices = new List<Vector3>();     private static readonly List<Vector3> s_tempVertices = new List<Vector3>();
   
    private static readonly List<Vector2> s_tempUVs = new List<Vector2>();     private static readonly List<Vector2> s_tempUVs = new List<Vector2>();
   
    private static readonly List<int> s_tempIndices = new List<int>();     private static readonly List<int> s_tempIndices = new List<int>();
   
    private static readonly List<Color32> s_tempColors = new List<Color32>();     private static readonly List<Color32> s_tempColors = new List<Color32>();
   
    public static Color m_paintMaskDirt = new Color(1f, 0f, 0f, 1f);     public static Color m_paintMaskDirt = new Color(1f, 0f, 0f, 1f);
   
    public static Color m_paintMaskCultivated = new Color(0f, 1f, 0f, 1f);     public static Color m_paintMaskCultivated = new Color(0f, 1f, 0f, 1f);
   
    public static Color m_paintMaskPaved = new Color(0f, 0f, 1f, 1f);     public static Color m_paintMaskPaved = new Color(0f, 0f, 1f, 1f);
   
    public static Color m_paintMaskNothing = new Color(0f, 0f, 0f, 1f);     public static Color m_paintMaskNothing = new Color(0f, 0f, 0f, 1f);
   
.      public static Color m_paintMaskClearVegetation = new Color(0f, 0f, 0f, 0f);
   
    private static bool s_enableDistantTerrainShadows = false;     private static bool s_enableDistantTerrainShadows = false;
   
    private static int s_shaderPropertyClearedMaskTex = 0;     private static int s_shaderPropertyClearedMaskTex = 0;
   
    public const RenderGroup c_RenderGroup = RenderGroup.Overworld;     public const RenderGroup c_RenderGroup = RenderGroup.Overworld;
   
    [Flags]     [Flags]
    public enum Biome     public enum Biome
    {     {
        None = 0,         None = 0,
        Meadows = 1,         Meadows = 1,
        Swamp = 2,         Swamp = 2,
        Mountain = 4,         Mountain = 4,
        BlackForest = 8,         BlackForest = 8,
        Plains = 16,         Plains = 16,
        AshLands = 32,         AshLands = 32,
        DeepNorth = 64,         DeepNorth = 64,
        Ocean = 256,         Ocean = 256,
.        Mistlands = 512          Mistlands = 512, 
          All = 895 
    }     }
   
    [Flags]     [Flags]
    public enum BiomeArea     public enum BiomeArea
    {     {
        Edge = 1,         Edge = 1,
        Median = 2,         Median = 2,
        Everything = 3         Everything = 3
    }     }
} }