D:\ValheimDev\Dumps\Old\assembly_valheim\WearNTear.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\WearNTear.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
   
public class WearNTear : MonoBehaviour, IDestructible public class WearNTear : MonoBehaviour, IDestructible
{ {
    private void Awake()     private void Awake()
    {     {
        int? num = WearNTear.s_terrainLayer;         int? num = WearNTear.s_terrainLayer;
        int num2 = 0;         int num2 = 0;
        if ((num.GetValueOrDefault() < num2) & (num != null))         if ((num.GetValueOrDefault() < num2) & (num != null))
        {         {
            WearNTear.s_terrainLayer = new int?(LayerMask.NameToLayer("terrain"));             WearNTear.s_terrainLayer = new int?(LayerMask.NameToLayer("terrain"));
        }         }
        this.m_nview = base.GetComponent<ZNetView>();         this.m_nview = base.GetComponent<ZNetView>();
        this.m_piece = base.GetComponent<Piece>();         this.m_piece = base.GetComponent<Piece>();
        if (this.m_nview.GetZDO() == null)         if (this.m_nview.GetZDO() == null)
        {         {
            return;             return;
        }         }
.        this.m_nview.Register<HitData>("WNTDamage", new Action<long, HitData>(this.RPC_Damage));         this.m_nview.Register<HitData>("RPC_Damage", new Action<long, HitData>(this.RPC_Damage));
        this.m_nview.Register("WNTRemove", new Action<long>(this.RPC_Remove));         this.m_nview.Register("RPC_Remove", new Action<long>(this.RPC_Remove));
        this.m_nview.Register("WNTRepair", new Action<long>(this.RPC_Repair));         this.m_nview.Register("RPC_Repair", new Action<long>(this.RPC_Repair));
        this.m_nview.Register<float>("WNTHealthChanged", new Action<long, float>(this.RPC_HealthChanged));         this.m_nview.Register<float>("RPC_HealthChanged", new Action<long, float>(this.RPC_HealthChanged));
          this.m_nview.Register("RPC_ClearCachedSupport", new Action<long>(this.RPC_ClearCachedSupport)); 
        if (this.m_autoCreateFragments)         if (this.m_autoCreateFragments)
        {         {
.            this.m_nview.Register("WNTCreateFragments", new Action<long>(this.RPC_CreateFragments));             this.m_nview.Register("RPC_CreateFragments", new Action<long>(this.RPC_CreateFragments));
        }         }
        if (WearNTear.s_rayMask == 0)         if (WearNTear.s_rayMask == 0)
        {         {
            WearNTear.s_rayMask = LayerMask.GetMask(new string[] { "piece", "Default", "static_solid", "Default_small", "terrain" });             WearNTear.s_rayMask = LayerMask.GetMask(new string[] { "piece", "Default", "static_solid", "Default_small", "terrain" });
        }         }
        WearNTear.s_allInstances.Add(this);         WearNTear.s_allInstances.Add(this);
        this.m_myIndex = WearNTear.s_allInstances.Count - 1;         this.m_myIndex = WearNTear.s_allInstances.Count - 1;
        this.m_createTime = Time.time;         this.m_createTime = Time.time;
        this.m_support = this.GetMaxSupport();         this.m_support = this.GetMaxSupport();
        float num3 = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);         float num3 = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);
        if (num3.Equals(this.m_health) && WearNTear.m_randomInitialDamage)         if (num3.Equals(this.m_health) && WearNTear.m_randomInitialDamage)
        {         {
            num3 = UnityEngine.Random.Range(0.1f * this.m_health, this.m_health * 0.6f);             num3 = UnityEngine.Random.Range(0.1f * this.m_health, this.m_health * 0.6f);
            this.m_nview.GetZDO().Set(ZDOVars.s_health, num3);             this.m_nview.GetZDO().Set(ZDOVars.s_health, num3);
        }         }
        if (Game.m_worldLevel > 0)         if (Game.m_worldLevel > 0)
        {         {
            this.m_health += (float)Game.m_worldLevel * Game.instance.m_worldLevelPieceHPMultiplier * this.m_health;             this.m_health += (float)Game.m_worldLevel * Game.instance.m_worldLevelPieceHPMultiplier * this.m_health;
        }         }
        this.UpdateCover(5f);         this.UpdateCover(5f);
        this.m_updateCoverTimer = UnityEngine.Random.Range(0f, 4f);         this.m_updateCoverTimer = UnityEngine.Random.Range(0f, 4f);
        this.m_healthPercentage = Mathf.Clamp01(num3 / this.m_health);         this.m_healthPercentage = Mathf.Clamp01(num3 / this.m_health);
.          this.m_propertyBlock = new MaterialPropertyBlock();
          this.m_renderers = this.GetHighlightRenderers();
          this.SetAshlandsMaterialValue(0f);
        this.UpdateVisual(false);         this.UpdateVisual(false);
.          base.InvokeRepeating("UpdateAshlandsMaterialValues", 0.5f, 0.5f);
    }     }
   
    private void Start()     private void Start()
    {     {
        this.m_connectedHeightMap = Heightmap.FindHeightmap(base.transform.position);         this.m_connectedHeightMap = Heightmap.FindHeightmap(base.transform.position);
.        this.m_connectedHeightMap.m_clearConnectedWearNTearCache += this.ClearCachedSupport;         if (this.m_connectedHeightMap != null) 
          { 
              this.m_connectedHeightMap.m_clearConnectedWearNTearCache += this.ClearCachedSupport;
          } 
      } 
   
      private void UpdateAshlandsMaterialValues() 
      { 
          this.SetAshlandsMaterialValue(Mathf.Max(this.m_lavaTimer, Mathf.Max(this.m_ashDamageTime, this.m_burnDamageTime))); 
          float num = Time.time - this.m_lastMaterialValueTimeCheck; 
          this.m_lastMaterialValueTimeCheck = Time.time; 
          if (this.m_ashDamageTime > 0f) 
          { 
              this.m_ashDamageTime -= num; 
          } 
          if (this.m_burnDamageTime > 0f) 
          { 
              this.m_burnDamageTime -= num; 
          } 
    }     }
   
    private void OnDestroy()     private void OnDestroy()
    {     {
        if (this.m_myIndex != -1)         if (this.m_myIndex != -1)
        {         {
            WearNTear.s_allInstances[this.m_myIndex] = WearNTear.s_allInstances[WearNTear.s_allInstances.Count - 1];             WearNTear.s_allInstances[this.m_myIndex] = WearNTear.s_allInstances[WearNTear.s_allInstances.Count - 1];
            WearNTear.s_allInstances[this.m_myIndex].m_myIndex = this.m_myIndex;             WearNTear.s_allInstances[this.m_myIndex].m_myIndex = this.m_myIndex;
            WearNTear.s_allInstances.RemoveAt(WearNTear.s_allInstances.Count - 1);             WearNTear.s_allInstances.RemoveAt(WearNTear.s_allInstances.Count - 1);
        }         }
        if (this.m_connectedHeightMap != null)         if (this.m_connectedHeightMap != null)
        {         {
            this.m_connectedHeightMap.m_clearConnectedWearNTearCache -= this.ClearCachedSupport;             this.m_connectedHeightMap.m_clearConnectedWearNTearCache -= this.ClearCachedSupport;
        }         }
    }     }
   
.      private void SetAshlandsMaterialValue(float v)
      {
          if (this.m_ashMaterialValue == v)
          {
              return;
          }
          this.m_ashMaterialValue = v;
          this.m_propertyBlock.SetFloat(WearNTear.s_AshlandsDamageShaderID, v);
          foreach (Renderer renderer in this.m_renderers)
          {
              renderer.SetPropertyBlock(this.m_propertyBlock);
          }
      }
   
    public bool Repair()     public bool Repair()
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return false;             return false;
        }         }
        if (this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health) >= this.m_health)         if (this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health) >= this.m_health)
        {         {
            return false;             return false;
        }         }
        if (Time.time - this.m_lastRepair < 1f)         if (Time.time - this.m_lastRepair < 1f)
        {         {
            return false;             return false;
        }         }
        this.m_lastRepair = Time.time;         this.m_lastRepair = Time.time;
.        this.m_nview.InvokeRPC("WNTRepair", Array.Empty<object>());         this.m_nview.InvokeRPC("RPC_Repair", Array.Empty<object>());
        return true;         return true;
    }     }
   
    private void RPC_Repair(long sender)     private void RPC_Repair(long sender)
    {     {
        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        this.m_nview.GetZDO().Set(ZDOVars.s_health, this.m_health);         this.m_nview.GetZDO().Set(ZDOVars.s_health, this.m_health);
.        this.m_nview.InvokeRPC(ZNetView.Everybody, "WNTHealthChanged", new object[] { this.m_health });         this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_HealthChanged", new object[] { this.m_health });
    }     }
   
    private float GetSupport()     private float GetSupport()
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return this.GetMaxSupport();             return this.GetMaxSupport();
        }         }
        if (!this.m_nview.HasOwner())         if (!this.m_nview.HasOwner())
        {         {
            return this.GetMaxSupport();             return this.GetMaxSupport();
        }         }
        if (this.m_nview.IsOwner())         if (this.m_nview.IsOwner())
        {         {
            return this.m_support;             return this.m_support;
        }         }
        return this.m_nview.GetZDO().GetFloat(ZDOVars.s_support, this.GetMaxSupport());         return this.m_nview.GetZDO().GetFloat(ZDOVars.s_support, this.GetMaxSupport());
    }     }
   
    private float GetSupportColorValue()     private float GetSupportColorValue()
    {     {
        float num = this.GetSupport();         float num = this.GetSupport();
        float num2;         float num2;
        float num3;         float num3;
        float num4;         float num4;
        float num5;         float num5;
        this.GetMaterialProperties(out num2, out num3, out num4, out num5);         this.GetMaterialProperties(out num2, out num3, out num4, out num5);
        if (num >= num2)         if (num >= num2)
        {         {
            return -1f;             return -1f;
        }         }
        num -= num3;         num -= num3;
        return Mathf.Clamp01(num / (num2 * 0.5f - num3));         return Mathf.Clamp01(num / (num2 * 0.5f - num3));
    }     }
   
    public void OnPlaced()     public void OnPlaced()
    {     {
        this.m_createTime = -1f;         this.m_createTime = -1f;
        this.m_clearCachedSupport = true;         this.m_clearCachedSupport = true;
    }     }
   
    private List<Renderer> GetHighlightRenderers()     private List<Renderer> GetHighlightRenderers()
    {     {
        MeshRenderer[] componentsInChildren = base.GetComponentsInChildren<MeshRenderer>(true);         MeshRenderer[] componentsInChildren = base.GetComponentsInChildren<MeshRenderer>(true);
        SkinnedMeshRenderer[] componentsInChildren2 = base.GetComponentsInChildren<SkinnedMeshRenderer>(true);         SkinnedMeshRenderer[] componentsInChildren2 = base.GetComponentsInChildren<SkinnedMeshRenderer>(true);
        List<Renderer> list = new List<Renderer>();         List<Renderer> list = new List<Renderer>();
        list.AddRange(componentsInChildren);         list.AddRange(componentsInChildren);
        list.AddRange(componentsInChildren2);         list.AddRange(componentsInChildren2);
        return list;         return list;
    }     }
   
    public void Highlight()     public void Highlight()
    {     {
        if (this.m_oldMaterials == null)         if (this.m_oldMaterials == null)
        {         {
            this.m_oldMaterials = new List<WearNTear.OldMeshData>();             this.m_oldMaterials = new List<WearNTear.OldMeshData>();
            foreach (Renderer renderer in this.GetHighlightRenderers())             foreach (Renderer renderer in this.GetHighlightRenderers())
            {             {
                WearNTear.OldMeshData oldMeshData = default(WearNTear.OldMeshData);                 WearNTear.OldMeshData oldMeshData = default(WearNTear.OldMeshData);
                oldMeshData.m_materials = renderer.sharedMaterials;                 oldMeshData.m_materials = renderer.sharedMaterials;
                oldMeshData.m_color = new Color[oldMeshData.m_materials.Length];                 oldMeshData.m_color = new Color[oldMeshData.m_materials.Length];
                oldMeshData.m_emissiveColor = new Color[oldMeshData.m_materials.Length];                 oldMeshData.m_emissiveColor = new Color[oldMeshData.m_materials.Length];
                for (int i = 0; i < oldMeshData.m_materials.Length; i++)                 for (int i = 0; i < oldMeshData.m_materials.Length; i++)
                {                 {
                    if (oldMeshData.m_materials[i].HasProperty("_Color"))                     if (oldMeshData.m_materials[i].HasProperty("_Color"))
                    {                     {
                        oldMeshData.m_color[i] = oldMeshData.m_materials[i].GetColor("_Color");                         oldMeshData.m_color[i] = oldMeshData.m_materials[i].GetColor("_Color");
                    }                     }
                    if (oldMeshData.m_materials[i].HasProperty("_EmissionColor"))                     if (oldMeshData.m_materials[i].HasProperty("_EmissionColor"))
                    {                     {
                        oldMeshData.m_emissiveColor[i] = oldMeshData.m_materials[i].GetColor("_EmissionColor");                         oldMeshData.m_emissiveColor[i] = oldMeshData.m_materials[i].GetColor("_EmissionColor");
                    }                     }
                }                 }
                oldMeshData.m_renderer = renderer;                 oldMeshData.m_renderer = renderer;
                this.m_oldMaterials.Add(oldMeshData);                 this.m_oldMaterials.Add(oldMeshData);
            }             }
        }         }
        float supportColorValue = this.GetSupportColorValue();         float supportColorValue = this.GetSupportColorValue();
        Color color = new Color(0.6f, 0.8f, 1f);         Color color = new Color(0.6f, 0.8f, 1f);
        if (supportColorValue >= 0f)         if (supportColorValue >= 0f)
        {         {
            color = Color.Lerp(new Color(1f, 0f, 0f), new Color(0f, 1f, 0f), supportColorValue);             color = Color.Lerp(new Color(1f, 0f, 0f), new Color(0f, 1f, 0f), supportColorValue);
            float num;             float num;
            float num2;             float num2;
            float num3;             float num3;
            Color.RGBToHSV(color, out num, out num2, out num3);             Color.RGBToHSV(color, out num, out num2, out num3);
            num2 = Mathf.Lerp(1f, 0.5f, supportColorValue);             num2 = Mathf.Lerp(1f, 0.5f, supportColorValue);
            num3 = Mathf.Lerp(1.2f, 0.9f, supportColorValue);             num3 = Mathf.Lerp(1.2f, 0.9f, supportColorValue);
            color = Color.HSVToRGB(num, num2, num3);             color = Color.HSVToRGB(num, num2, num3);
        }         }
        foreach (WearNTear.OldMeshData oldMeshData2 in this.m_oldMaterials)         foreach (WearNTear.OldMeshData oldMeshData2 in this.m_oldMaterials)
        {         {
            if (oldMeshData2.m_renderer)             if (oldMeshData2.m_renderer)
            {             {
                foreach (Material material in oldMeshData2.m_renderer.materials)                 foreach (Material material in oldMeshData2.m_renderer.materials)
                {                 {
                    material.SetColor("_EmissionColor", color * 0.4f);                     material.SetColor("_EmissionColor", color * 0.4f);
                    material.color = color;                     material.color = color;
                }                 }
            }             }
        }         }
        base.CancelInvoke("ResetHighlight");         base.CancelInvoke("ResetHighlight");
        base.Invoke("ResetHighlight", 0.2f);         base.Invoke("ResetHighlight", 0.2f);
    }     }
   
    private void ResetHighlight()     private void ResetHighlight()
    {     {
        if (this.m_oldMaterials == null)         if (this.m_oldMaterials == null)
        {         {
            return;             return;
        }         }
        foreach (WearNTear.OldMeshData oldMeshData in this.m_oldMaterials)         foreach (WearNTear.OldMeshData oldMeshData in this.m_oldMaterials)
        {         {
            if (oldMeshData.m_renderer)             if (oldMeshData.m_renderer)
            {             {
                Material[] materials = oldMeshData.m_renderer.materials;                 Material[] materials = oldMeshData.m_renderer.materials;
                if (materials.Length != 0)                 if (materials.Length != 0)
                {                 {
                    if (materials[0] == oldMeshData.m_materials[0])                     if (materials[0] == oldMeshData.m_materials[0])
                    {                     {
                        if (materials.Length == oldMeshData.m_color.Length)                         if (materials.Length == oldMeshData.m_color.Length)
                        {                         {
                            for (int i = 0; i < materials.Length; i++)                             for (int i = 0; i < materials.Length; i++)
                            {                             {
                                if (materials[i].HasProperty("_Color"))                                 if (materials[i].HasProperty("_Color"))
                                {                                 {
                                    materials[i].SetColor("_Color", oldMeshData.m_color[i]);                                     materials[i].SetColor("_Color", oldMeshData.m_color[i]);
                                }                                 }
                                if (materials[i].HasProperty("_EmissionColor"))                                 if (materials[i].HasProperty("_EmissionColor"))
                                {                                 {
                                    materials[i].SetColor("_EmissionColor", oldMeshData.m_emissiveColor[i]);                                     materials[i].SetColor("_EmissionColor", oldMeshData.m_emissiveColor[i]);
                                }                                 }
                            }                             }
                        }                         }
                    }                     }
                    else if (materials.Length == oldMeshData.m_materials.Length)                     else if (materials.Length == oldMeshData.m_materials.Length)
                    {                     {
                        for (int j = 0; j < oldMeshData.m_renderer.materials.Length; j++)                         for (int j = 0; j < oldMeshData.m_renderer.materials.Length; j++)
                        {                         {
                            UnityEngine.Object.Destroy(oldMeshData.m_renderer.materials[j]);                             UnityEngine.Object.Destroy(oldMeshData.m_renderer.materials[j]);
                        }                         }
                        oldMeshData.m_renderer.materials = oldMeshData.m_materials;                         oldMeshData.m_renderer.materials = oldMeshData.m_materials;
                    }                     }
                }                 }
            }             }
        }         }
        this.m_oldMaterials = null;         this.m_oldMaterials = null;
    }     }
   
    private void SetupColliders()     private void SetupColliders()
    {     {
        this.m_colliders = base.GetComponentsInChildren<Collider>(true);         this.m_colliders = base.GetComponentsInChildren<Collider>(true);
        this.m_bounds = new List<WearNTear.BoundData>();         this.m_bounds = new List<WearNTear.BoundData>();
        foreach (Collider collider in this.m_colliders)         foreach (Collider collider in this.m_colliders)
        {         {
            if (!collider.isTrigger && !(collider.attachedRigidbody != null))             if (!collider.isTrigger && !(collider.attachedRigidbody != null))
            {             {
                WearNTear.BoundData boundData = default(WearNTear.BoundData);                 WearNTear.BoundData boundData = default(WearNTear.BoundData);
                if (collider is BoxCollider)                 if (collider is BoxCollider)
                {                 {
                    BoxCollider boxCollider = collider as BoxCollider;                     BoxCollider boxCollider = collider as BoxCollider;
                    boundData.m_rot = boxCollider.transform.rotation;                     boundData.m_rot = boxCollider.transform.rotation;
                    boundData.m_pos = boxCollider.transform.position + boxCollider.transform.TransformVector(boxCollider.center);                     boundData.m_pos = boxCollider.transform.position + boxCollider.transform.TransformVector(boxCollider.center);
                    boundData.m_size = new Vector3(boxCollider.transform.lossyScale.x * boxCollider.size.x, boxCollider.transform.lossyScale.y * boxCollider.size.y, boxCollider.transform.lossyScale.z * boxCollider.size.z);                     boundData.m_size = new Vector3(boxCollider.transform.lossyScale.x * boxCollider.size.x, boxCollider.transform.lossyScale.y * boxCollider.size.y, boxCollider.transform.lossyScale.z * boxCollider.size.z);
                }                 }
                else                 else
                {                 {
                    boundData.m_rot = Quaternion.identity;                     boundData.m_rot = Quaternion.identity;
                    boundData.m_pos = collider.bounds.center;                     boundData.m_pos = collider.bounds.center;
                    boundData.m_size = collider.bounds.size;                     boundData.m_size = collider.bounds.size;
                }                 }
                boundData.m_size.x = boundData.m_size.x + 0.3f;                 boundData.m_size.x = boundData.m_size.x + 0.3f;
                boundData.m_size.y = boundData.m_size.y + 0.3f;                 boundData.m_size.y = boundData.m_size.y + 0.3f;
                boundData.m_size.z = boundData.m_size.z + 0.3f;                 boundData.m_size.z = boundData.m_size.z + 0.3f;
                boundData.m_size *= 0.5f;                 boundData.m_size *= 0.5f;
                this.m_bounds.Add(boundData);                 this.m_bounds.Add(boundData);
            }             }
        }         }
    }     }
   
    private bool ShouldUpdate()     private bool ShouldUpdate()
    {     {
        return this.m_createTime < 0f || Time.time - this.m_createTime > 30f;         return this.m_createTime < 0f || Time.time - this.m_createTime > 30f;
    }     }
   
    public void UpdateWear(float time)     public void UpdateWear(float time)
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return;             return;
        }         }
        if (this.m_nview.IsOwner() && this.ShouldUpdate())         if (this.m_nview.IsOwner() && this.ShouldUpdate())
        {         {
            if (ZNetScene.instance.OutsideActiveArea(base.transform.position))             if (ZNetScene.instance.OutsideActiveArea(base.transform.position))
            {             {
                this.m_support = this.GetMaxSupport();                 this.m_support = this.GetMaxSupport();
                this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);                 this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);
                return;                 return;
            }             }
.              bool flag = ShieldGenerator.IsInsideShieldCached(base.transform.position, ref this.m_shieldChangeID);
            float num = 0f;             float num = 0f;
.            bool flag = !this.m_haveRoof && EnvMan.instance.IsWet();             this.m_rainWet = !flag && !this.m_haveRoof && EnvMan.IsWet();
            if (this.m_wet)             if (this.m_wet)
            {             {
.                this.m_wet.SetActive(flag);                 this.m_wet.SetActive(this.m_rainWet);
            }             }
.            if (this.m_noRoofWear && this.GetHealthPercentage() > 0.5f)             if (this.m_noRoofWear && !flag && this.GetHealthPercentage() > 0.5f)
            {             {
.                if (flag || this.IsUnderWater())                 if (this.IsWet())
                {                 {
                    if (this.m_rainTimer == 0f)                     if (this.m_rainTimer == 0f)
                    {                     {
                        this.m_rainTimer = time;                         this.m_rainTimer = time;
                    }                     }
                    else if (time - this.m_rainTimer > 60f)                     else if (time - this.m_rainTimer > 60f)
                    {                     {
                        this.m_rainTimer = time;                         this.m_rainTimer = time;
                        num += 5f;                         num += 5f;
                    }                     }
                }                 }
                else                 else
                {                 {
                    this.m_rainTimer = 0f;                     this.m_rainTimer = 0f;
                }                 }
            }             }
            if (this.m_noSupportWear)             if (this.m_noSupportWear)
            {             {
                this.UpdateSupport();                 this.UpdateSupport();
                if (!this.HaveSupport())                 if (!this.HaveSupport())
                {                 {
                    num = 100f;                     num = 100f;
                }                 }
            }             }
.            if (num > 0f && this.CanBeRemoved())              bool flag2 = false; 
              if (this.m_biome == Heightmap.Biome.None || !this.m_heightmap) 
              { 
                  Vector3 position = base.transform.position; 
                  Vector3 vector; 
                  Heightmap.Biome biome; 
                  Heightmap.BiomeArea biomeArea; 
                  ZoneSystem.instance.GetGroundData(ref position, out vector, out biome, out biomeArea, out this.m_heightmap); 
                  if (this.m_heightmap != null) 
                  { 
                      this.m_biome = this.m_heightmap.GetBiome(base.transform.position, 0.02f, false); 
                      float num2 = 9999f; 
                      foreach (Renderer renderer in this.m_renderers) 
                      { 
                          float y = renderer.bounds.min.y; 
                          if (y < num2) 
                          { 
                              num2 = y; 
                          } 
                      } 
                      this.m_groundDist = num2 - position.y; 
                  } 
              } 
              if (this.m_biome == Heightmap.Biome.AshLands) 
              { 
                  this.m_inAshlands = true; 
                  if (Game.instance.m_ashDamage > 0f && !flag && !this.m_ashDamageImmune) 
                  { 
                      flag2 = !this.m_haveAshRoof && (!this.m_ashDamageResist || this.GetHealthPercentage() > 0.1f); 
                      if (flag2) 
                      { 
                          if (this.m_ashTimer == 0f) 
                          { 
                              this.m_ashTimer = time; 
                          } 
                          else if (time - this.m_ashTimer > 5f) 
                          { 
                              this.m_ashTimer = time; 
                              num += Game.instance.m_ashDamage; 
                          } 
                      } 
                      else 
                      { 
                          this.m_ashTimer = 0f; 
                      } 
                  } 
                  float lava = this.m_heightmap.GetLava(base.transform.position); 
                  if (lava > 0.2f && this.m_groundDist < 1.5f && !this.m_ashDamageImmune) 
                  { 
                      if (this.m_lavaTimer == 0f) 
                      { 
                          this.m_lavaTimer = time; 
                      } 
                      else if (time - this.m_lavaTimer > 2f) 
                      { 
                          this.m_lavaTimer = time; 
                          float num3 = (flag ? 30f : 70f) * lava; 
                          num += num3 * (this.m_ashDamageResist ? 0.33f : 1f); 
                      } 
                  } 
                  else 
                  { 
                      this.m_lavaTimer = 0f; 
                  } 
              } 
              this.m_ashDamageTime = (float)(flag2 ? 5 : 0); 
              if (num > 0f && !this.CanBeRemoved()) 
            {             {
.                float num2 = num / 100f * this.m_health;                 num = 0f; 
                this.ApplyDamage(num2);             } 
              if (num > 0f) 
              { 
                  float num4 = num / 100f * this.m_health;
                  this.ApplyDamage(num4, null);
            }             }
        }         }
        this.UpdateVisual(true);         this.UpdateVisual(true);
    }     }
   
    private Vector3 GetCOM()     private Vector3 GetCOM()
    {     {
        return base.transform.position + base.transform.rotation * this.m_comOffset;         return base.transform.position + base.transform.rotation * this.m_comOffset;
    }     }
   
.      public bool IsWet()
      {
          return this.m_rainWet || this.IsUnderWater();
      }
   
    private void ClearCachedSupport()     private void ClearCachedSupport()
    {     {
        this.m_supportColliders.Clear();         this.m_supportColliders.Clear();
        this.m_supportPositions.Clear();         this.m_supportPositions.Clear();
        this.m_supportValue.Clear();         this.m_supportValue.Clear();
    }     }
   
.      private void RPC_ClearCachedSupport(long sender)
      {
          this.ClearCachedSupport();
      }
   
    private void UpdateSupport()     private void UpdateSupport()
    {     {
        int count = this.m_supportColliders.Count;         int count = this.m_supportColliders.Count;
        if (count > 0)         if (count > 0)
        {         {
            int num = 0;             int num = 0;
            float num2 = 0f;             float num2 = 0f;
            for (int i = 0; i < count; i++)             for (int i = 0; i < count; i++)
            {             {
                Collider collider = this.m_supportColliders[i];                 Collider collider = this.m_supportColliders[i];
                if (collider == null)                 if (collider == null)
                {                 {
                    break;                     break;
                }                 }
                WearNTear componentInParent = collider.GetComponentInParent<WearNTear>();                 WearNTear componentInParent = collider.GetComponentInParent<WearNTear>();
                if (componentInParent == null || !componentInParent.m_supports)                 if (componentInParent == null || !componentInParent.m_supports)
                {                 {
                    break;                     break;
                }                 }
                if (collider != null && collider.transform.position == this.m_supportPositions[i])                 if (collider != null && collider.transform.position == this.m_supportPositions[i])
                {                 {
                    float support = componentInParent.GetSupport();                     float support = componentInParent.GetSupport();
                    if (support > num2)                     if (support > num2)
                    {                     {
                        num2 = support;                         num2 = support;
                    }                     }
                    if (support.Equals(this.m_supportValue[i]))                     if (support.Equals(this.m_supportValue[i]))
                    {                     {
                        num++;                         num++;
                    }                     }
                }                 }
            }             }
            if (num == this.m_supportPositions.Count && num2 > this.m_support)             if (num == this.m_supportPositions.Count && num2 > this.m_support)
            {             {
                return;                 return;
            }             }
            this.ClearCachedSupport();             this.ClearCachedSupport();
        }         }
        if (this.m_colliders == null)         if (this.m_colliders == null)
        {         {
            this.SetupColliders();             this.SetupColliders();
        }         }
        float num3;         float num3;
        float num4;         float num4;
        float num5;         float num5;
        float num6;         float num6;
        this.GetMaterialProperties(out num3, out num4, out num5, out num6);         this.GetMaterialProperties(out num3, out num4, out num5, out num6);
        WearNTear.s_tempSupportPoints.Clear();         WearNTear.s_tempSupportPoints.Clear();
        WearNTear.s_tempSupportPointValues.Clear();         WearNTear.s_tempSupportPointValues.Clear();
        Vector3 com = this.GetCOM();         Vector3 com = this.GetCOM();
        bool flag = false;         bool flag = false;
        float num7 = 0f;         float num7 = 0f;
        foreach (WearNTear.BoundData boundData in this.m_bounds)         foreach (WearNTear.BoundData boundData in this.m_bounds)
        {         {
            int num8 = Physics.OverlapBoxNonAlloc(boundData.m_pos, boundData.m_size, WearNTear.s_tempColliders, boundData.m_rot, WearNTear.s_rayMask);             int num8 = Physics.OverlapBoxNonAlloc(boundData.m_pos, boundData.m_size, WearNTear.s_tempColliders, boundData.m_rot, WearNTear.s_rayMask);
            if (this.m_clearCachedSupport)             if (this.m_clearCachedSupport)
            {             {
                for (int j = 0; j < num8; j++)                 for (int j = 0; j < num8; j++)
                {                 {
                    Collider collider2 = WearNTear.s_tempColliders[j];                     Collider collider2 = WearNTear.s_tempColliders[j];
                    if (!(collider2.attachedRigidbody != null) && !collider2.isTrigger && !this.m_colliders.Contains(collider2))                     if (!(collider2.attachedRigidbody != null) && !collider2.isTrigger && !this.m_colliders.Contains(collider2))
                    {                     {
                        WearNTear componentInParent2 = collider2.GetComponentInParent<WearNTear>();                         WearNTear componentInParent2 = collider2.GetComponentInParent<WearNTear>();
                        if (!(componentInParent2 == null))                         if (!(componentInParent2 == null))
                        {                         {
.                            componentInParent2.ClearCachedSupport();                             if (componentInParent2.m_nview.IsOwner()) 
                              { 
                                  componentInParent2.ClearCachedSupport();
                              } 
                              else 
                              { 
                                  componentInParent2.m_nview.InvokeRPC(componentInParent2.m_nview.GetZDO().GetOwner(), "RPC_ClearCachedSupport", Array.Empty<object>()); 
                              } 
                        }                         }
                    }                     }
                }                 }
                this.m_clearCachedSupport = false;                 this.m_clearCachedSupport = false;
            }             }
            for (int k = 0; k < num8; k++)             for (int k = 0; k < num8; k++)
            {             {
                Collider collider3 = WearNTear.s_tempColliders[k];                 Collider collider3 = WearNTear.s_tempColliders[k];
                if (!(collider3.attachedRigidbody != null) && !collider3.isTrigger && !this.m_colliders.Contains(collider3))                 if (!(collider3.attachedRigidbody != null) && !collider3.isTrigger && !this.m_colliders.Contains(collider3))
                {                 {
                    int layer = collider3.gameObject.layer;                     int layer = collider3.gameObject.layer;
                    int? num9 = WearNTear.s_terrainLayer;                     int? num9 = WearNTear.s_terrainLayer;
                    if ((layer == num9.GetValueOrDefault()) & (num9 != null))                     if ((layer == num9.GetValueOrDefault()) & (num9 != null))
                    {                     {
                        flag = true;                         flag = true;
                    }                     }
                    else                     else
                    {                     {
                        WearNTear componentInParent3 = collider3.GetComponentInParent<WearNTear>();                         WearNTear componentInParent3 = collider3.GetComponentInParent<WearNTear>();
                        if (componentInParent3 == null)                         if (componentInParent3 == null)
                        {                         {
                            this.m_support = num3;                             this.m_support = num3;
                            this.ClearCachedSupport();                             this.ClearCachedSupport();
                            this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);                             this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);
                            return;                             return;
                        }                         }
                        if (componentInParent3.m_supports)                         if (componentInParent3.m_supports)
                        {                         {
                            float num10 = Vector3.Distance(com, componentInParent3.GetCOM()) + 0.1f;                             float num10 = Vector3.Distance(com, componentInParent3.GetCOM()) + 0.1f;
.                            if (!this.m_useCorrectCOMDistanceCalculation)                             float num11 = Vector3.Distance(com, componentInParent3.transform.position) + 0.1f; 
                              if (num11 < num10 && !this.m_forceCorrectCOMCalculation)
                            {                             {
.                                num10 = Vector3.Distance(com, componentInParent3.transform.position) + 0.1f;                                 num10 = num11;
                            }                             }
                            float support2 = componentInParent3.GetSupport();                             float support2 = componentInParent3.GetSupport();
                            num7 = Mathf.Max(num7, support2 - num5 * num10 * support2);                             num7 = Mathf.Max(num7, support2 - num5 * num10 * support2);
                            Vector3 vector = WearNTear.FindSupportPoint(com, componentInParent3, collider3);                             Vector3 vector = WearNTear.FindSupportPoint(com, componentInParent3, collider3);
                            if (vector.y < com.y + 0.05f)                             if (vector.y < com.y + 0.05f)
                            {                             {
                                Vector3 normalized = (vector - com).normalized;                                 Vector3 normalized = (vector - com).normalized;
                                if (normalized.y < 0f)                                 if (normalized.y < 0f)
                                {                                 {
.                                    float num11 = Mathf.Acos(1f - Mathf.Abs(normalized.y)) / 1.5707964f;                                     float num12 = Mathf.Acos(1f - Mathf.Abs(normalized.y)) / 1.5707964f;
                                    float num12 = Mathf.Lerp(num5, num6, num11);                                     float num13 = Mathf.Lerp(num5, num6, num12);
                                    float num13 = support2 - num12 * num10 * support2;                                     float num14 = support2 - num13 * num10 * support2;
                                    num7 = Mathf.Max(num7, num13);                                     num7 = Mathf.Max(num7, num14);
                                }                                 }
.                                float num14 = support2 - num6 * num10 * support2;                                 float num15 = support2 - num6 * num10 * support2;
                                WearNTear.s_tempSupportPoints.Add(vector);                                 WearNTear.s_tempSupportPoints.Add(vector);
.                                WearNTear.s_tempSupportPointValues.Add(num14);                                 WearNTear.s_tempSupportPointValues.Add(num15);
                                this.m_supportColliders.Add(collider3);                                 this.m_supportColliders.Add(collider3);
                                this.m_supportPositions.Add(collider3.transform.position);                                 this.m_supportPositions.Add(collider3.transform.position);
                                this.m_supportValue.Add(componentInParent3.GetSupport());                                 this.m_supportValue.Add(componentInParent3.GetSupport());
                            }                             }
                        }                         }
                    }                     }
                }                 }
            }             }
        }         }
        if (flag)         if (flag)
        {         {
            this.m_support = num3;             this.m_support = num3;
            this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);             this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);
            return;             return;
        }         }
        if (WearNTear.s_tempSupportPoints.Count > 0)         if (WearNTear.s_tempSupportPoints.Count > 0)
        {         {
            int count2 = WearNTear.s_tempSupportPoints.Count;             int count2 = WearNTear.s_tempSupportPoints.Count;
            for (int l = 0; l < count2 - 1; l++)             for (int l = 0; l < count2 - 1; l++)
            {             {
                Vector3 vector2 = WearNTear.s_tempSupportPoints[l] - com;                 Vector3 vector2 = WearNTear.s_tempSupportPoints[l] - com;
                vector2.y = 0f;                 vector2.y = 0f;
                for (int m = l + 1; m < count2; m++)                 for (int m = l + 1; m < count2; m++)
                {                 {
.                    float num15 = (WearNTear.s_tempSupportPointValues[l] + WearNTear.s_tempSupportPointValues[m]) * 0.5f;                     float num16 = (WearNTear.s_tempSupportPointValues[l] + WearNTear.s_tempSupportPointValues[m]) * 0.5f;
                    if (num15 > num7)                     if (num16 > num7)
                    {                     {
                        Vector3 vector3 = WearNTear.s_tempSupportPoints[m] - com;                         Vector3 vector3 = WearNTear.s_tempSupportPoints[m] - com;
                        vector3.y = 0f;                         vector3.y = 0f;
                        if (Vector3.Angle(vector2, vector3) >= 100f)                         if (Vector3.Angle(vector2, vector3) >= 100f)
                        {                         {
.                            num7 = num15;                             num7 = num16;
                        }                         }
                    }                     }
                }                 }
            }             }
        }         }
        this.m_support = Mathf.Min(num7, num3);         this.m_support = Mathf.Min(num7, num3);
        this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);         this.m_nview.GetZDO().Set(ZDOVars.s_support, this.m_support);
        if (!this.HaveSupport())         if (!this.HaveSupport())
        {         {
            this.ClearCachedSupport();             this.ClearCachedSupport();
        }         }
    }     }
   
    private static Vector3 FindSupportPoint(Vector3 com, WearNTear wnt, Collider otherCollider)     private static Vector3 FindSupportPoint(Vector3 com, WearNTear wnt, Collider otherCollider)
    {     {
        MeshCollider meshCollider = otherCollider as MeshCollider;         MeshCollider meshCollider = otherCollider as MeshCollider;
        if (!(meshCollider != null) || meshCollider.convex)         if (!(meshCollider != null) || meshCollider.convex)
        {         {
            return otherCollider.ClosestPoint(com);             return otherCollider.ClosestPoint(com);
        }         }
        RaycastHit raycastHit;         RaycastHit raycastHit;
        if (meshCollider.Raycast(new Ray(com, Vector3.down), out raycastHit, 10f))         if (meshCollider.Raycast(new Ray(com, Vector3.down), out raycastHit, 10f))
        {         {
            return raycastHit.point;             return raycastHit.point;
        }         }
        return (com + wnt.GetCOM()) * 0.5f;         return (com + wnt.GetCOM()) * 0.5f;
    }     }
   
    private bool HaveSupport()     private bool HaveSupport()
    {     {
        return this.m_support >= this.GetMinSupport();         return this.m_support >= this.GetMinSupport();
    }     }
   
    private bool IsUnderWater()     private bool IsUnderWater()
    {     {
        return Floating.IsUnderWater(base.transform.position, ref this.m_previousWaterVolume);         return Floating.IsUnderWater(base.transform.position, ref this.m_previousWaterVolume);
    }     }
   
    public void UpdateCover(float dt)     public void UpdateCover(float dt)
    {     {
        this.m_updateCoverTimer += dt;         this.m_updateCoverTimer += dt;
        if (this.m_updateCoverTimer <= 4f)         if (this.m_updateCoverTimer <= 4f)
        {         {
            return;             return;
        }         }
.        if (EnvMan.instance.IsWet())         if (EnvMan.IsWet())
        {         {
            this.m_haveRoof = this.HaveRoof();             this.m_haveRoof = this.HaveRoof();
        }         }
.          if (this.m_inAshlands)
          {
              this.m_haveAshRoof = this.HaveAshRoof();
          }
        this.m_updateCoverTimer = 0f;         this.m_updateCoverTimer = 0f;
    }     }
   
    private bool HaveRoof()     private bool HaveRoof()
    {     {
.        if (this.m_roof)          return this.m_roof || WearNTear.RoofCheck(base.transform.position, out this.m_roof); 
      } 
   
      public static bool RoofCheck(Vector3 position, out GameObject roofObject) 
      { 
          int num = Physics.SphereCastNonAlloc(position, 0.1f, Vector3.up, WearNTear.s_raycastHits, 100f, WearNTear.s_rayMask); 
          for (int i = 0; i < num; i++) 
          { 
              RaycastHit raycastHit = WearNTear.s_raycastHits[i]; 
              if (!raycastHit.collider.gameObject.CompareTag("leaky")) 
              { 
                  roofObject = raycastHit.collider.gameObject; 
                  return true; 
              } 
          } 
          roofObject = null; 
          return false; 
      } 
   
      private bool HaveAshRoof() 
      { 
          if (this.m_ashroof) 
        {         {
            return true;             return true;
        }         }
        int num = Physics.SphereCastNonAlloc(base.transform.position, 0.1f, Vector3.up, WearNTear.s_raycastHits, 100f, WearNTear.s_rayMask);         int num = Physics.SphereCastNonAlloc(base.transform.position, 0.1f, Vector3.up, WearNTear.s_raycastHits, 100f, WearNTear.s_rayMask);
        for (int i = 0; i < num; i++)         for (int i = 0; i < num; i++)
        {         {
            RaycastHit raycastHit = WearNTear.s_raycastHits[i];             RaycastHit raycastHit = WearNTear.s_raycastHits[i];
.            if (!raycastHit.collider.gameObject.CompareTag("leaky"))             if (raycastHit.collider.gameObject != base.gameObject && (raycastHit.collider.transform.parent == null || raycastHit.collider.transform.parent.gameObject != base.gameObject))
            {             {
.                this.m_roof = raycastHit.collider.gameObject;                 this.m_ashroof = raycastHit.collider.gameObject;
                return true;                 return true;
            }             }
        }         }
        return false;         return false;
    }     }
   
    private void RPC_HealthChanged(long peer, float health)     private void RPC_HealthChanged(long peer, float health)
    {     {
        float num = health / this.m_health;         float num = health / this.m_health;
        this.m_healthPercentage = Mathf.Clamp01(health / this.m_health);         this.m_healthPercentage = Mathf.Clamp01(health / this.m_health);
        this.ClearCachedSupport();         this.ClearCachedSupport();
        this.SetHealthVisual(num, true);         this.SetHealthVisual(num, true);
    }     }
   
    private void UpdateVisual(bool triggerEffects)     private void UpdateVisual(bool triggerEffects)
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return;             return;
        }         }
        this.SetHealthVisual(this.GetHealthPercentage(), triggerEffects);         this.SetHealthVisual(this.GetHealthPercentage(), triggerEffects);
    }     }
   
    private void SetHealthVisual(float health, bool triggerEffects)     private void SetHealthVisual(float health, bool triggerEffects)
    {     {
        if (this.m_worn == null && this.m_broken == null && this.m_new == null)         if (this.m_worn == null && this.m_broken == null && this.m_new == null)
        {         {
            return;             return;
        }         }
        if (health > 0.75f)         if (health > 0.75f)
        {         {
            if (this.m_worn != this.m_new)             if (this.m_worn != this.m_new)
            {             {
                this.m_worn.SetActive(false);                 this.m_worn.SetActive(false);
            }             }
            if (this.m_broken != this.m_new)             if (this.m_broken != this.m_new)
            {             {
                this.m_broken.SetActive(false);                 this.m_broken.SetActive(false);
            }             }
            this.m_new.SetActive(true);             this.m_new.SetActive(true);
            return;             return;
        }         }
        if (health > 0.25f)         if (health > 0.25f)
        {         {
            if (triggerEffects && !this.m_worn.activeSelf)             if (triggerEffects && !this.m_worn.activeSelf)
            {             {
                this.m_switchEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);                 this.m_switchEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);
            }             }
            if (this.m_new != this.m_worn)             if (this.m_new != this.m_worn)
            {             {
                this.m_new.SetActive(false);                 this.m_new.SetActive(false);
            }             }
            if (this.m_broken != this.m_worn)             if (this.m_broken != this.m_worn)
            {             {
                this.m_broken.SetActive(false);                 this.m_broken.SetActive(false);
            }             }
            this.m_worn.SetActive(true);             this.m_worn.SetActive(true);
            return;             return;
        }         }
        if (triggerEffects && !this.m_broken.activeSelf)         if (triggerEffects && !this.m_broken.activeSelf)
        {         {
            this.m_switchEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);             this.m_switchEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);
        }         }
        if (this.m_new != this.m_broken)         if (this.m_new != this.m_broken)
        {         {
            this.m_new.SetActive(false);             this.m_new.SetActive(false);
        }         }
        if (this.m_worn != this.m_broken)         if (this.m_worn != this.m_broken)
        {         {
            this.m_worn.SetActive(false);             this.m_worn.SetActive(false);
        }         }
        this.m_broken.SetActive(true);         this.m_broken.SetActive(true);
    }     }
   
    public float GetHealthPercentage()     public float GetHealthPercentage()
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return 1f;             return 1f;
        }         }
        return this.m_healthPercentage;         return this.m_healthPercentage;
    }     }
   
    public DestructibleType GetDestructibleType()     public DestructibleType GetDestructibleType()
    {     {
        return DestructibleType.Default;         return DestructibleType.Default;
    }     }
   
    public void Damage(HitData hit)     public void Damage(HitData hit)
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return;             return;
        }         }
.        this.m_nview.InvokeRPC("WNTDamage", new object[] { hit });         this.m_nview.InvokeRPC("RPC_Damage", new object[] { hit });
    }     }
   
    private bool CanBeRemoved()     private bool CanBeRemoved()
    {     {
        return !this.m_piece || this.m_piece.CanBeRemoved();         return !this.m_piece || this.m_piece.CanBeRemoved();
    }     }
   
    private void RPC_Damage(long sender, HitData hit)     private void RPC_Damage(long sender, HitData hit)
    {     {
        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        if (this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health) <= 0f)         if (this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health) <= 0f)
        {         {
            return;             return;
        }         }
        HitData.DamageModifier damageModifier;         HitData.DamageModifier damageModifier;
        hit.ApplyResistance(this.m_damages, out damageModifier);         hit.ApplyResistance(this.m_damages, out damageModifier);
        float totalDamage = hit.GetTotalDamage();         float totalDamage = hit.GetTotalDamage();
        DamageText.instance.ShowText(damageModifier, hit.m_point, totalDamage, false);         DamageText.instance.ShowText(damageModifier, hit.m_point, totalDamage, false);
        if (totalDamage <= 0f)         if (totalDamage <= 0f)
        {         {
            return;             return;
        }         }
        if (this.m_triggerPrivateArea)         if (this.m_triggerPrivateArea)
        {         {
            Character attacker = hit.GetAttacker();             Character attacker = hit.GetAttacker();
            if (attacker)             if (attacker)
            {             {
                bool flag = totalDamage >= this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);                 bool flag = totalDamage >= this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);
                PrivateArea.OnObjectDamaged(base.transform.position, attacker, flag);                 PrivateArea.OnObjectDamaged(base.transform.position, attacker, flag);
            }             }
        }         }
.        this.ApplyDamage(totalDamage);         if (!hit.CheckToolTier(this.m_minToolTier, true)) 
        this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1);         { 
        if (this.m_hitNoise > 0f)             DamageText.instance.ShowText(DamageText.TextType.TooHard, hit.m_point, 0f, false); 
              return; 
          } 
          this.ApplyDamage(totalDamage, hit);
          if (hit.m_hitType != HitData.HitType.CinderFire && hit.m_hitType != HitData.HitType.AshlandsOcean) 
          { 
              this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1);
              if (hit.GetTotalPhysicalDamage() > 0f) 
              { 
                  this.m_hitEffect.Create(hit.m_point, Quaternion.identity, base.transform, 1f, -1); 
              } 
          } 
          if (this.m_hitNoise > 0f && hit.m_hitType != HitData.HitType.CinderFire)
        {         {
            Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);             Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
            if (closestPlayer)             if (closestPlayer)
            {             {
                closestPlayer.AddNoise(this.m_hitNoise);                 closestPlayer.AddNoise(this.m_hitNoise);
            }             }
        }         }
        if (this.m_onDamaged != null)         if (this.m_onDamaged != null)
        {         {
            this.m_onDamaged();             this.m_onDamaged();
        }         }
.          if (hit.m_damage.m_fire > 3f && !this.IsWet())
          {
              this.m_burnDamageTime = 3f;
          }
    }     }
   
.    public bool ApplyDamage(float damage)     public bool ApplyDamage(float damage, HitData hitData = null)
    {     {
        float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);         float num = this.m_nview.GetZDO().GetFloat(ZDOVars.s_health, this.m_health);
        if (num <= 0f)         if (num <= 0f)
        {         {
            return false;             return false;
        }         }
        num -= damage;         num -= damage;
        this.m_nview.GetZDO().Set(ZDOVars.s_health, num);         this.m_nview.GetZDO().Set(ZDOVars.s_health, num);
.          if (Terminal.m_showTests && Terminal.m_testList.ContainsKey("damage"))
          {
              Terminal.Log(string.Format("Damage WNT: {0} took {1} damage from {2}", base.gameObject.name, damage, (hitData == null) ? "UNKNOWN" : hitData));
          }
        if (num <= 0f)         if (num <= 0f)
        {         {
.            this.Destroy();             this.Destroy(hitData);
        }         }
        else         else
        {         {
.            this.m_nview.InvokeRPC(ZNetView.Everybody, "WNTHealthChanged", new object[] { num });             this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_HealthChanged", new object[] { num });
        }         }
        return true;         return true;
    }     }
   
    public void Remove()     public void Remove()
    {     {
        if (!this.m_nview.IsValid())         if (!this.m_nview.IsValid())
        {         {
            return;             return;
        }         }
.        this.m_nview.InvokeRPC("WNTRemove", Array.Empty<object>());         this.m_nview.InvokeRPC("RPC_Remove", Array.Empty<object>());
    }     }
   
    private void RPC_Remove(long sender)     private void RPC_Remove(long sender)
    {     {
        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
.        this.Destroy();         this.Destroy(null);
    }     }
   
.    private void Destroy()     private void Destroy(HitData hitData = null)
    {     {
        Bed component = base.GetComponent<Bed>();         Bed component = base.GetComponent<Bed>();
        if (component != null && this.m_nview.IsOwner() && Game.instance != null)         if (component != null && this.m_nview.IsOwner() && Game.instance != null)
        {         {
            Game.instance.RemoveCustomSpawnPoint(component.GetSpawnPoint());             Game.instance.RemoveCustomSpawnPoint(component.GetSpawnPoint());
        }         }
        this.m_nview.GetZDO().Set(ZDOVars.s_health, 0f);         this.m_nview.GetZDO().Set(ZDOVars.s_health, 0f);
        this.m_nview.GetZDO().Set(ZDOVars.s_support, 0f);         this.m_nview.GetZDO().Set(ZDOVars.s_support, 0f);
        this.m_support = 0f;         this.m_support = 0f;
        this.m_health = 0f;         this.m_health = 0f;
        this.ClearCachedSupport();         this.ClearCachedSupport();
        if (this.m_piece)         if (this.m_piece)
        {         {
.            this.m_piece.DropResources();             this.m_piece.DropResources(hitData);
        }         }
        if (this.m_onDestroyed != null)         if (this.m_onDestroyed != null)
        {         {
            this.m_onDestroyed();             this.m_onDestroyed();
        }         }
.        if (this.m_destroyNoise > 0f)          if (this.m_destroyNoise > 0f && (hitData == null || hitData.m_hitType != HitData.HitType.CinderFire)) 
        {         {
            Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f);             Player closestPlayer = Player.GetClosestPlayer(base.transform.position, 10f);
            if (closestPlayer)             if (closestPlayer)
            {             {
                closestPlayer.AddNoise(this.m_destroyNoise);                 closestPlayer.AddNoise(this.m_destroyNoise);
            }             }
        }         }
        this.m_destroyedEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);         this.m_destroyedEffect.Create(base.transform.position, base.transform.rotation, base.transform, 1f, -1);
        if (this.m_autoCreateFragments)         if (this.m_autoCreateFragments)
        {         {
.            this.m_nview.InvokeRPC(ZNetView.Everybody, "WNTCreateFragments", Array.Empty<object>());             this.m_nview.InvokeRPC(ZNetView.Everybody, "RPC_CreateFragments", Array.Empty<object>());
        }         }
        ZNetScene.instance.Destroy(base.gameObject);         ZNetScene.instance.Destroy(base.gameObject);
    }     }
   
    private void RPC_CreateFragments(long peer)     private void RPC_CreateFragments(long peer)
    {     {
        this.ResetHighlight();         this.ResetHighlight();
        if (this.m_fragmentRoots != null && this.m_fragmentRoots.Length != 0)         if (this.m_fragmentRoots != null && this.m_fragmentRoots.Length != 0)
        {         {
            foreach (GameObject gameObject in this.m_fragmentRoots)             foreach (GameObject gameObject in this.m_fragmentRoots)
            {             {
                gameObject.SetActive(true);                 gameObject.SetActive(true);
                Destructible.CreateFragments(gameObject, false);                 Destructible.CreateFragments(gameObject, false);
            }             }
            return;             return;
        }         }
        Destructible.CreateFragments(base.gameObject, true);         Destructible.CreateFragments(base.gameObject, true);
    }     }
   
    private float GetMaxSupport()     private float GetMaxSupport()
    {     {
        float num;         float num;
        float num2;         float num2;
        float num3;         float num3;
        float num4;         float num4;
        this.GetMaterialProperties(out num, out num2, out num3, out num4);         this.GetMaterialProperties(out num, out num2, out num3, out num4);
        return num;         return num;
    }     }
   
    private float GetMinSupport()     private float GetMinSupport()
    {     {
        float num;         float num;
        float num2;         float num2;
        float num3;         float num3;
        float num4;         float num4;
        this.GetMaterialProperties(out num, out num2, out num3, out num4);         this.GetMaterialProperties(out num, out num2, out num3, out num4);
        return num2;         return num2;
    }     }
   
    private void GetMaterialProperties(out float maxSupport, out float minSupport, out float horizontalLoss, out float verticalLoss)     private void GetMaterialProperties(out float maxSupport, out float minSupport, out float horizontalLoss, out float verticalLoss)
    {     {
        switch (this.m_materialType)         switch (this.m_materialType)
        {         {
        case WearNTear.MaterialType.Wood:         case WearNTear.MaterialType.Wood:
            maxSupport = 100f;             maxSupport = 100f;
            minSupport = 10f;             minSupport = 10f;
            verticalLoss = 0.125f;             verticalLoss = 0.125f;
            horizontalLoss = 0.2f;             horizontalLoss = 0.2f;
            return;             return;
        case WearNTear.MaterialType.Stone:         case WearNTear.MaterialType.Stone:
            maxSupport = 1000f;             maxSupport = 1000f;
            minSupport = 100f;             minSupport = 100f;
            verticalLoss = 0.125f;             verticalLoss = 0.125f;
            horizontalLoss = 1f;             horizontalLoss = 1f;
            return;             return;
        case WearNTear.MaterialType.Iron:         case WearNTear.MaterialType.Iron:
            maxSupport = 1500f;             maxSupport = 1500f;
            minSupport = 20f;             minSupport = 20f;
            verticalLoss = 0.07692308f;             verticalLoss = 0.07692308f;
            horizontalLoss = 0.07692308f;             horizontalLoss = 0.07692308f;
            return;             return;
        case WearNTear.MaterialType.HardWood:         case WearNTear.MaterialType.HardWood:
            maxSupport = 140f;             maxSupport = 140f;
            minSupport = 10f;             minSupport = 10f;
            verticalLoss = 0.1f;             verticalLoss = 0.1f;
            horizontalLoss = 0.16666667f;             horizontalLoss = 0.16666667f;
            return;             return;
        case WearNTear.MaterialType.Marble:         case WearNTear.MaterialType.Marble:
            maxSupport = 1500f;             maxSupport = 1500f;
            minSupport = 100f;             minSupport = 100f;
            verticalLoss = 0.125f;             verticalLoss = 0.125f;
            horizontalLoss = 0.5f;             horizontalLoss = 0.5f;
            return;             return;
.          case WearNTear.MaterialType.Ashstone:
              maxSupport = 2000f;
              minSupport = 100f;
              verticalLoss = 0.1f;
              horizontalLoss = 0.33333334f;
              return;
          case WearNTear.MaterialType.Ancient:
              maxSupport = 5000f;
              minSupport = 100f;
              verticalLoss = 0.06666667f;
              horizontalLoss = 0.25f;
              return;
        default:         default:
            maxSupport = 0f;             maxSupport = 0f;
            minSupport = 0f;             minSupport = 0f;
            verticalLoss = 0f;             verticalLoss = 0f;
            horizontalLoss = 0f;             horizontalLoss = 0f;
            return;             return;
        }         }
    }     }
   
.    public void UseCorrectCOMCalculation(bool correct = true)  
    {  
        this.m_useCorrectCOMDistanceCalculation = correct;  
    }  
   
    public static List<WearNTear> GetAllInstances()     public static List<WearNTear> GetAllInstances()
    {     {
        return WearNTear.s_allInstances;         return WearNTear.s_allInstances;
    }     }
   
    public static bool m_randomInitialDamage = false;     public static bool m_randomInitialDamage = false;
   
    public Action m_onDestroyed;     public Action m_onDestroyed;
   
    public Action m_onDamaged;     public Action m_onDamaged;
   
    [Header("Wear")]     [Header("Wear")]
    public GameObject m_new;     public GameObject m_new;
   
    public GameObject m_worn;     public GameObject m_worn;
   
    public GameObject m_broken;     public GameObject m_broken;
   
    public GameObject m_wet;     public GameObject m_wet;
   
    public bool m_noRoofWear = true;     public bool m_noRoofWear = true;
   
    public bool m_noSupportWear = true;     public bool m_noSupportWear = true;
   
.      [global::Tooltip("'Ash Damage' covers both lava and ambient ashlands damage (currently 0... but server modifiers??)")]
      public bool m_ashDamageImmune;
   
      public bool m_ashDamageResist;
   
      public bool m_burnable = true;
   
    public WearNTear.MaterialType m_materialType;     public WearNTear.MaterialType m_materialType;
   
    public bool m_supports = true;     public bool m_supports = true;
   
    public Vector3 m_comOffset = Vector3.zero;     public Vector3 m_comOffset = Vector3.zero;
   
.      public bool m_forceCorrectCOMCalculation;
   
    [Header("Destruction")]     [Header("Destruction")]
    public float m_health = 100f;     public float m_health = 100f;
   
    public HitData.DamageModifiers m_damages;     public HitData.DamageModifiers m_damages;
   
.      public int m_minToolTier;
   
    public float m_hitNoise;     public float m_hitNoise;
   
    public float m_destroyNoise;     public float m_destroyNoise;
   
    public bool m_triggerPrivateArea = true;     public bool m_triggerPrivateArea = true;
   
    [Header("Effects")]     [Header("Effects")]
    public EffectList m_destroyedEffect = new EffectList();     public EffectList m_destroyedEffect = new EffectList();
   
    public EffectList m_hitEffect = new EffectList();     public EffectList m_hitEffect = new EffectList();
   
    public EffectList m_switchEffect = new EffectList();     public EffectList m_switchEffect = new EffectList();
   
    public bool m_autoCreateFragments = true;     public bool m_autoCreateFragments = true;
   
    public GameObject[] m_fragmentRoots;     public GameObject[] m_fragmentRoots;
   
    private const float c_RainDamageTime = 60f;     private const float c_RainDamageTime = 60f;
   
    private const float c_RainDamage = 5f;     private const float c_RainDamage = 5f;
   
.      private const float c_RainDamageMax = 0.5f;
   
      private const float c_AshDamageTime = 5f;
   
      private const float c_AshDamageMaxResist = 0.1f;
   
      private const float c_LavaDamageTime = 2f;
   
      private const float c_LavaDamage = 70f;
   
      private const float c_LavaDamageShielded = 30f;
   
    private const float c_ComTestWidth = 0.2f;     private const float c_ComTestWidth = 0.2f;
   
    private const float c_ComMinAngle = 100f;     private const float c_ComMinAngle = 100f;
   
    private static readonly RaycastHit[] s_raycastHits = new RaycastHit[128];     private static readonly RaycastHit[] s_raycastHits = new RaycastHit[128];
   
    private static readonly Collider[] s_tempColliders = new Collider[128];     private static readonly Collider[] s_tempColliders = new Collider[128];
   
    private static int s_rayMask = 0;     private static int s_rayMask = 0;
   
    private static readonly List<WearNTear> s_allInstances = new List<WearNTear>();     private static readonly List<WearNTear> s_allInstances = new List<WearNTear>();
   
    private static readonly List<Vector3> s_tempSupportPoints = new List<Vector3>();     private static readonly List<Vector3> s_tempSupportPoints = new List<Vector3>();
   
    private static readonly List<float> s_tempSupportPointValues = new List<float>();     private static readonly List<float> s_tempSupportPointValues = new List<float>();
   
.      private static readonly int s_AshlandsDamageShaderID = Shader.PropertyToID("_TakingAshlandsDamage");
   
      private MaterialPropertyBlock m_propertyBlock;
   
      private List<Renderer> m_renderers;
   
    private ZNetView m_nview;     private ZNetView m_nview;
   
    private Collider[] m_colliders;     private Collider[] m_colliders;
   
    private float m_support = 1f;     private float m_support = 1f;
   
    private float m_createTime;     private float m_createTime;
   
    private int m_myIndex = -1;     private int m_myIndex = -1;
   
    private float m_rainTimer;     private float m_rainTimer;
   
    private float m_lastRepair;     private float m_lastRepair;
   
    private Piece m_piece;     private Piece m_piece;
   
    private GameObject m_roof;     private GameObject m_roof;
   
    private float m_healthPercentage = 100f;     private float m_healthPercentage = 100f;
   
    private bool m_clearCachedSupport;     private bool m_clearCachedSupport;
   
    private Heightmap m_connectedHeightMap;     private Heightmap m_connectedHeightMap;
   
.      private float m_burnDamageTime;
   
      private float m_ashDamageTime;
   
      private float m_ashMaterialValue;
   
      private float m_lastBurnDamageTime;
   
      private float m_lastMaterialValueTimeCheck;
   
    private readonly List<Collider> m_supportColliders = new List<Collider>();     private readonly List<Collider> m_supportColliders = new List<Collider>();
   
    private readonly List<Vector3> m_supportPositions = new List<Vector3>();     private readonly List<Vector3> m_supportPositions = new List<Vector3>();
   
    private readonly List<float> m_supportValue = new List<float>();     private readonly List<float> m_supportValue = new List<float>();
   
    private WaterVolume m_previousWaterVolume;     private WaterVolume m_previousWaterVolume;
   
.      private GameObject m_ashroof;
   
      private Heightmap.Biome m_biome;
   
      private Heightmap m_heightmap;
   
      private float m_groundDist;
   
      private float m_ashTimer;
   
      private bool m_inAshlands;
   
      private int m_shieldChangeID;
   
      private float m_lavaTimer;
   
      private bool m_rainWet;
   
    private List<WearNTear.BoundData> m_bounds;     private List<WearNTear.BoundData> m_bounds;
   
    private List<WearNTear.OldMeshData> m_oldMaterials;     private List<WearNTear.OldMeshData> m_oldMaterials;
   
    private float m_updateCoverTimer;     private float m_updateCoverTimer;
   
    private bool m_haveRoof = true;     private bool m_haveRoof = true;
   
.    private const float c_UpdateCoverFrequency = 4f;     private bool m_haveAshRoof = true;
   
.    private bool m_useCorrectCOMDistanceCalculation = true;     private const float c_UpdateCoverFrequency = 4f;
   
    private static int? s_terrainLayer = new int?(-1);     private static int? s_terrainLayer = new int?(-1);
   
    public enum MaterialType     public enum MaterialType
    {     {
        Wood,         Wood,
        Stone,         Stone,
        Iron,         Iron,
        HardWood,         HardWood,
.        Marble          Marble, 
          Ashstone, 
          Ancient 
    }     }
   
    private struct BoundData     private struct BoundData
    {     {
        public Vector3 m_pos;         public Vector3 m_pos;
   
        public Quaternion m_rot;         public Quaternion m_rot;
   
        public Vector3 m_size;         public Vector3 m_size;
    }     }
   
    private struct OldMeshData     private struct OldMeshData
    {     {
        public Renderer m_renderer;         public Renderer m_renderer;
   
        public Material[] m_materials;         public Material[] m_materials;
   
        public Color[] m_color;         public Color[] m_color;
   
        public Color[] m_emissiveColor;         public Color[] m_emissiveColor;
    }     }
} }