D:\ValheimDev\Dumps\Old\assembly_valheim\Floating.cs D:\ValheimDev\Dumps\Latest\assembly_valheim\Floating.cs
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
   
.public class Floating : MonoBehaviour, IWaterInteractable  public class Floating : MonoBehaviour, IWaterInteractable, IMonoUpdater 
{ {
    private void Awake()     private void Awake()
    {     {
        this.m_nview = base.GetComponent<ZNetView>();         this.m_nview = base.GetComponent<ZNetView>();
        this.m_body = base.GetComponent<Rigidbody>();         this.m_body = base.GetComponent<Rigidbody>();
        this.m_collider = base.GetComponentInChildren<Collider>();         this.m_collider = base.GetComponentInChildren<Collider>();
        this.SetSurfaceEffect(false);         this.SetSurfaceEffect(false);
        Floating.s_waterVolumeMask = LayerMask.GetMask(new string[] { "WaterVolume" });         Floating.s_waterVolumeMask = LayerMask.GetMask(new string[] { "WaterVolume" });
        base.InvokeRepeating("TerrainCheck", UnityEngine.Random.Range(10f, 30f), 30f);         base.InvokeRepeating("TerrainCheck", UnityEngine.Random.Range(10f, 30f), 30f);
    }     }
   
    private void OnEnable()     private void OnEnable()
    {     {
        Floating.Instances.Add(this);         Floating.Instances.Add(this);
    }     }
   
    private void OnDisable()     private void OnDisable()
    {     {
        Floating.Instances.Remove(this);         Floating.Instances.Remove(this);
    }     }
   
    public Transform GetTransform()     public Transform GetTransform()
    {     {
        if (this == null)         if (this == null)
        {         {
            return null;             return null;
        }         }
        return base.transform;         return base.transform;
    }     }
   
    private void TerrainCheck()     private void TerrainCheck()
    {     {
        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        float groundHeight = ZoneSystem.instance.GetGroundHeight(base.transform.position);         float groundHeight = ZoneSystem.instance.GetGroundHeight(base.transform.position);
        if (base.transform.position.y - groundHeight < -1f)         if (base.transform.position.y - groundHeight < -1f)
        {         {
            Vector3 position = base.transform.position;             Vector3 position = base.transform.position;
            position.y = groundHeight + 1f;             position.y = groundHeight + 1f;
            base.transform.position = position;             base.transform.position = position;
            Rigidbody component = base.GetComponent<Rigidbody>();             Rigidbody component = base.GetComponent<Rigidbody>();
            if (component)             if (component)
            {             {
                component.velocity = Vector3.zero;                 component.velocity = Vector3.zero;
            }             }
            ZLog.Log("Moved up item " + base.gameObject.name);             ZLog.Log("Moved up item " + base.gameObject.name);
        }         }
    }     }
   
    public void CustomFixedUpdate(float fixedDeltaTime)     public void CustomFixedUpdate(float fixedDeltaTime)
    {     {
.        if (!this.m_nview.IsValid() || !this.m_nview.IsOwner())         this.CheckBody(); 
          if (!this.m_body || !this.m_nview.IsValid() || !this.m_nview.IsOwner())
        {         {
            return;             return;
        }         }
        if (!this.HaveLiquidLevel())         if (!this.HaveLiquidLevel())
        {         {
            this.SetSurfaceEffect(false);             this.SetSurfaceEffect(false);
            return;             return;
        }         }
        this.UpdateImpactEffect();         this.UpdateImpactEffect();
        float floatDepth = this.GetFloatDepth();         float floatDepth = this.GetFloatDepth();
        if (floatDepth > 0f)         if (floatDepth > 0f)
        {         {
            this.SetSurfaceEffect(false);             this.SetSurfaceEffect(false);
            return;             return;
        }         }
        this.SetSurfaceEffect(true);         this.SetSurfaceEffect(true);
        Vector3 vector = this.m_collider.ClosestPoint(base.transform.position + Vector3.down * 1000f);         Vector3 vector = this.m_collider.ClosestPoint(base.transform.position + Vector3.down * 1000f);
        Vector3 worldCenterOfMass = this.m_body.worldCenterOfMass;         Vector3 worldCenterOfMass = this.m_body.worldCenterOfMass;
        float num = Mathf.Clamp01(Mathf.Abs(floatDepth) / this.m_forceDistance);         float num = Mathf.Clamp01(Mathf.Abs(floatDepth) / this.m_forceDistance);
        Vector3 vector2 = this.m_force * num * (fixedDeltaTime * 50f) * Vector3.up;         Vector3 vector2 = this.m_force * num * (fixedDeltaTime * 50f) * Vector3.up;
        this.m_body.WakeUp();         this.m_body.WakeUp();
        this.m_body.AddForceAtPosition(vector2 * this.m_balanceForceFraction, vector, ForceMode.VelocityChange);         this.m_body.AddForceAtPosition(vector2 * this.m_balanceForceFraction, vector, ForceMode.VelocityChange);
        this.m_body.AddForceAtPosition(vector2, worldCenterOfMass, ForceMode.VelocityChange);         this.m_body.AddForceAtPosition(vector2, worldCenterOfMass, ForceMode.VelocityChange);
        this.m_body.velocity = this.m_body.velocity - this.m_damping * num * this.m_body.velocity;         this.m_body.velocity = this.m_body.velocity - this.m_damping * num * this.m_body.velocity;
        this.m_body.angularVelocity = this.m_body.angularVelocity - this.m_damping * num * this.m_body.angularVelocity;         this.m_body.angularVelocity = this.m_body.angularVelocity - this.m_damping * num * this.m_body.angularVelocity;
    }     }
   
    public bool HaveLiquidLevel()     public bool HaveLiquidLevel()
    {     {
        return this.m_waterLevel > -10000f || this.m_tarLevel > -10000f;         return this.m_waterLevel > -10000f || this.m_tarLevel > -10000f;
    }     }
   
    private void SetSurfaceEffect(bool enabled)     private void SetSurfaceEffect(bool enabled)
    {     {
        if (this.m_surfaceEffects != null)         if (this.m_surfaceEffects != null)
        {         {
            this.m_surfaceEffects.SetActive(enabled);             this.m_surfaceEffects.SetActive(enabled);
        }         }
    }     }
   
    private void UpdateImpactEffect()     private void UpdateImpactEffect()
    {     {
.        if (this.m_body.IsSleeping() || !this.m_impactEffects.HasEffects())         this.CheckBody(); 
          if (!this.m_body || this.m_body.IsSleeping() || !this.m_impactEffects.HasEffects())
        {         {
            return;             return;
        }         }
        Vector3 vector = this.m_collider.ClosestPoint(base.transform.position + Vector3.down * 1000f);         Vector3 vector = this.m_collider.ClosestPoint(base.transform.position + Vector3.down * 1000f);
        float num = Mathf.Max(this.m_waterLevel, this.m_tarLevel);         float num = Mathf.Max(this.m_waterLevel, this.m_tarLevel);
        if (vector.y < num)         if (vector.y < num)
        {         {
            if (!this.m_wasInWater)             if (!this.m_wasInWater)
            {             {
                this.m_wasInWater = true;                 this.m_wasInWater = true;
                Vector3 vector2 = vector;                 Vector3 vector2 = vector;
                vector2.y = num;                 vector2.y = num;
                if (this.m_body.GetPointVelocity(vector).magnitude > 0.5f)                 if (this.m_body.GetPointVelocity(vector).magnitude > 0.5f)
                {                 {
                    this.m_impactEffects.Create(vector2, Quaternion.identity, null, 1f, -1);                     this.m_impactEffects.Create(vector2, Quaternion.identity, null, 1f, -1);
                    return;                     return;
                }                 }
            }             }
        }         }
        else         else
        {         {
            this.m_wasInWater = false;             this.m_wasInWater = false;
        }         }
    }     }
   
    private float GetFloatDepth()     private float GetFloatDepth()
    {     {
.          this.CheckBody();
          if (!this.m_body)
          {
              return 0f;
          }
        ref Vector3 worldCenterOfMass = this.m_body.worldCenterOfMass;         ref Vector3 worldCenterOfMass = this.m_body.worldCenterOfMass;
        float num = Mathf.Max(this.m_waterLevel, this.m_tarLevel);         float num = Mathf.Max(this.m_waterLevel, this.m_tarLevel);
        return worldCenterOfMass.y - num - this.m_waterLevelOffset;         return worldCenterOfMass.y - num - this.m_waterLevelOffset;
    }     }
   
    public bool IsInTar()     public bool IsInTar()
    {     {
.          this.CheckBody();
        return this.m_tarLevel > -10000f && this.m_body.worldCenterOfMass.y - this.m_tarLevel - this.m_waterLevelOffset < -0.2f;         return this.m_tarLevel > -10000f && this.m_body.worldCenterOfMass.y - this.m_tarLevel - this.m_waterLevelOffset < -0.2f;
    }     }
   
    public void SetLiquidLevel(float level, LiquidType type, Component liquidObj)     public void SetLiquidLevel(float level, LiquidType type, Component liquidObj)
    {     {
        if (type != LiquidType.Water && type != LiquidType.Tar)         if (type != LiquidType.Water && type != LiquidType.Tar)
        {         {
            return;             return;
        }         }
        if (type == LiquidType.Water)         if (type == LiquidType.Water)
        {         {
            this.m_waterLevel = level;             this.m_waterLevel = level;
        }         }
        else         else
        {         {
            this.m_tarLevel = level;             this.m_tarLevel = level;
        }         }
        if (!this.m_beenFloating && level > -10000f && this.GetFloatDepth() < 0f)         if (!this.m_beenFloating && level > -10000f && this.GetFloatDepth() < 0f)
        {         {
            this.m_beenFloating = true;             this.m_beenFloating = true;
        }         }
    }     }
   
.      private void CheckBody()
      {
          if (!this.m_body)
          {
              this.m_body = FloatingTerrain.GetBody(base.gameObject);
          }
      }
   
    public bool BeenFloating()     public bool BeenFloating()
    {     {
        return this.m_beenFloating;         return this.m_beenFloating;
    }     }
   
    private void OnDrawGizmosSelected()     private void OnDrawGizmosSelected()
    {     {
        Gizmos.color = Color.blue;         Gizmos.color = Color.blue;
        Gizmos.DrawWireCube(base.transform.position + Vector3.down * this.m_waterLevelOffset, new Vector3(1f, 0.05f, 1f));         Gizmos.DrawWireCube(base.transform.position + Vector3.down * this.m_waterLevelOffset, new Vector3(1f, 0.05f, 1f));
    }     }
   
    public static float GetLiquidLevel(Vector3 p, float waveFactor = 1f, LiquidType type = LiquidType.All)     public static float GetLiquidLevel(Vector3 p, float waveFactor = 1f, LiquidType type = LiquidType.All)
    {     {
        if (Floating.s_waterVolumeMask == 0)         if (Floating.s_waterVolumeMask == 0)
        {         {
            Floating.s_waterVolumeMask = LayerMask.GetMask(new string[] { "WaterVolume" });             Floating.s_waterVolumeMask = LayerMask.GetMask(new string[] { "WaterVolume" });
        }         }
        float num = -10000f;         float num = -10000f;
        int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);         int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);
        for (int i = 0; i < num2; i++)         for (int i = 0; i < num2; i++)
        {         {
            Collider collider = Floating.s_tempColliderArray[i];             Collider collider = Floating.s_tempColliderArray[i];
            int instanceID = collider.GetInstanceID();             int instanceID = collider.GetInstanceID();
            WaterVolume component;             WaterVolume component;
            if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))             if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))
            {             {
                component = collider.GetComponent<WaterVolume>();                 component = collider.GetComponent<WaterVolume>();
                Floating.s_waterVolumeCache[instanceID] = component;                 Floating.s_waterVolumeCache[instanceID] = component;
            }             }
            if (component)             if (component)
            {             {
                if (type == LiquidType.All || component.GetLiquidType() == type)                 if (type == LiquidType.All || component.GetLiquidType() == type)
                {                 {
                    num = Mathf.Max(num, component.GetWaterSurface(p, waveFactor));                     num = Mathf.Max(num, component.GetWaterSurface(p, waveFactor));
                }                 }
            }             }
            else             else
            {             {
                LiquidSurface component2;                 LiquidSurface component2;
                if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))                 if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))
                {                 {
                    component2 = collider.GetComponent<LiquidSurface>();                     component2 = collider.GetComponent<LiquidSurface>();
                    Floating.s_liquidSurfaceCache[instanceID] = component2;                     Floating.s_liquidSurfaceCache[instanceID] = component2;
                }                 }
                if (component2 && (type == LiquidType.All || component2.GetLiquidType() == type))                 if (component2 && (type == LiquidType.All || component2.GetLiquidType() == type))
                {                 {
                    num = Mathf.Max(num, component2.GetSurface(p));                     num = Mathf.Max(num, component2.GetSurface(p));
                }                 }
            }             }
        }         }
        return num;         return num;
    }     }
   
    public static float GetWaterLevel(Vector3 p, ref WaterVolume previousAndOut)     public static float GetWaterLevel(Vector3 p, ref WaterVolume previousAndOut)
    {     {
        if (previousAndOut != null && previousAndOut.gameObject.GetComponent<Collider>().bounds.Contains(p))         if (previousAndOut != null && previousAndOut.gameObject.GetComponent<Collider>().bounds.Contains(p))
        {         {
            return previousAndOut.GetWaterSurface(p, 1f);             return previousAndOut.GetWaterSurface(p, 1f);
        }         }
        float num = -10000f;         float num = -10000f;
        int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);         int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);
        for (int i = 0; i < num2; i++)         for (int i = 0; i < num2; i++)
        {         {
            Collider collider = Floating.s_tempColliderArray[i];             Collider collider = Floating.s_tempColliderArray[i];
            int instanceID = collider.GetInstanceID();             int instanceID = collider.GetInstanceID();
            WaterVolume component;             WaterVolume component;
            if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))             if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))
            {             {
                component = collider.GetComponent<WaterVolume>();                 component = collider.GetComponent<WaterVolume>();
                Floating.s_waterVolumeCache[instanceID] = component;                 Floating.s_waterVolumeCache[instanceID] = component;
            }             }
            if (component)             if (component)
            {             {
                if (component.GetLiquidType() == LiquidType.Water)                 if (component.GetLiquidType() == LiquidType.Water)
                {                 {
                    float waterSurface = component.GetWaterSurface(p, 1f);                     float waterSurface = component.GetWaterSurface(p, 1f);
                    if (waterSurface > num)                     if (waterSurface > num)
                    {                     {
                        num = waterSurface;                         num = waterSurface;
                        previousAndOut = component;                         previousAndOut = component;
                    }                     }
                }                 }
            }             }
            else             else
            {             {
                LiquidSurface component2;                 LiquidSurface component2;
                if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))                 if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))
                {                 {
                    component2 = collider.GetComponent<LiquidSurface>();                     component2 = collider.GetComponent<LiquidSurface>();
                    Floating.s_liquidSurfaceCache[instanceID] = component2;                     Floating.s_liquidSurfaceCache[instanceID] = component2;
                }                 }
                if (component2 && component2.GetLiquidType() == LiquidType.Water)                 if (component2 && component2.GetLiquidType() == LiquidType.Water)
                {                 {
                    num = Mathf.Max(num, component2.GetSurface(p));                     num = Mathf.Max(num, component2.GetSurface(p));
                }                 }
            }             }
        }         }
        return num;         return num;
    }     }
   
    public static bool IsUnderWater(Vector3 p, ref WaterVolume previousAndOut)     public static bool IsUnderWater(Vector3 p, ref WaterVolume previousAndOut)
    {     {
        if (previousAndOut != null && previousAndOut.gameObject.GetComponent<Collider>().bounds.Contains(p))         if (previousAndOut != null && previousAndOut.gameObject.GetComponent<Collider>().bounds.Contains(p))
        {         {
            return previousAndOut.GetWaterSurface(p, 1f) > p.y;             return previousAndOut.GetWaterSurface(p, 1f) > p.y;
        }         }
        float num = -10000f;         float num = -10000f;
        previousAndOut = null;         previousAndOut = null;
        int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);         int num2 = Physics.OverlapSphereNonAlloc(p, 0f, Floating.s_tempColliderArray, Floating.s_waterVolumeMask);
        for (int i = 0; i < num2; i++)         for (int i = 0; i < num2; i++)
        {         {
            Collider collider = Floating.s_tempColliderArray[i];             Collider collider = Floating.s_tempColliderArray[i];
            int instanceID = collider.GetInstanceID();             int instanceID = collider.GetInstanceID();
            WaterVolume component;             WaterVolume component;
            if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))             if (!Floating.s_waterVolumeCache.TryGetValue(instanceID, out component))
            {             {
                component = collider.GetComponent<WaterVolume>();                 component = collider.GetComponent<WaterVolume>();
                Floating.s_waterVolumeCache[instanceID] = component;                 Floating.s_waterVolumeCache[instanceID] = component;
            }             }
            if (component)             if (component)
            {             {
                if (component.GetLiquidType() == LiquidType.Water)                 if (component.GetLiquidType() == LiquidType.Water)
                {                 {
                    float waterSurface = component.GetWaterSurface(p, 1f);                     float waterSurface = component.GetWaterSurface(p, 1f);
                    if (waterSurface > num)                     if (waterSurface > num)
                    {                     {
                        num = waterSurface;                         num = waterSurface;
                        previousAndOut = component;                         previousAndOut = component;
                    }                     }
                }                 }
            }             }
            else             else
            {             {
                LiquidSurface component2;                 LiquidSurface component2;
                if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))                 if (!Floating.s_liquidSurfaceCache.TryGetValue(instanceID, out component2))
                {                 {
                    component2 = collider.GetComponent<LiquidSurface>();                     component2 = collider.GetComponent<LiquidSurface>();
                    Floating.s_liquidSurfaceCache[instanceID] = component2;                     Floating.s_liquidSurfaceCache[instanceID] = component2;
                }                 }
                if (component2 && component2.GetLiquidType() == LiquidType.Water)                 if (component2 && component2.GetLiquidType() == LiquidType.Water)
                {                 {
                    num = Mathf.Max(num, component2.GetSurface(p));                     num = Mathf.Max(num, component2.GetSurface(p));
                }                 }
            }             }
        }         }
        return num > p.y;         return num > p.y;
    }     }
   
    public int Increment(LiquidType type)     public int Increment(LiquidType type)
    {     {
        int[] liquids = this.m_liquids;         int[] liquids = this.m_liquids;
        int num = liquids[(int)type] + 1;         int num = liquids[(int)type] + 1;
        liquids[(int)type] = num;         liquids[(int)type] = num;
        return num;         return num;
    }     }
   
    public int Decrement(LiquidType type)     public int Decrement(LiquidType type)
    {     {
        int[] liquids = this.m_liquids;         int[] liquids = this.m_liquids;
        int num = liquids[(int)type] - 1;         int num = liquids[(int)type] - 1;
        liquids[(int)type] = num;         liquids[(int)type] = num;
        return num;         return num;
    }     }
   
.    public static List<Floating> Instances { get; } = new List<Floating>();     public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>();
   
    public float m_waterLevelOffset;     public float m_waterLevelOffset;
   
    public float m_forceDistance = 1f;     public float m_forceDistance = 1f;
   
    public float m_force = 0.5f;     public float m_force = 0.5f;
   
    public float m_balanceForceFraction = 0.02f;     public float m_balanceForceFraction = 0.02f;
   
    public float m_damping = 0.05f;     public float m_damping = 0.05f;
   
    public EffectList m_impactEffects = new EffectList();     public EffectList m_impactEffects = new EffectList();
   
    public GameObject m_surfaceEffects;     public GameObject m_surfaceEffects;
   
    private static int s_waterVolumeMask = 0;     private static int s_waterVolumeMask = 0;
   
    private static readonly Collider[] s_tempColliderArray = new Collider[256];     private static readonly Collider[] s_tempColliderArray = new Collider[256];
   
    private static readonly Dictionary<int, WaterVolume> s_waterVolumeCache = new Dictionary<int, WaterVolume>();     private static readonly Dictionary<int, WaterVolume> s_waterVolumeCache = new Dictionary<int, WaterVolume>();
   
    private static readonly Dictionary<int, LiquidSurface> s_liquidSurfaceCache = new Dictionary<int, LiquidSurface>();     private static readonly Dictionary<int, LiquidSurface> s_liquidSurfaceCache = new Dictionary<int, LiquidSurface>();
   
    private float m_waterLevel = -10000f;     private float m_waterLevel = -10000f;
   
    private float m_tarLevel = -10000f;     private float m_tarLevel = -10000f;
   
    private bool m_beenFloating;     private bool m_beenFloating;
   
    private bool m_wasInWater = true;     private bool m_wasInWater = true;
   
    private const float c_MinImpactEffectVelocity = 0.5f;     private const float c_MinImpactEffectVelocity = 0.5f;
   
    private Rigidbody m_body;     private Rigidbody m_body;
   
    private Collider m_collider;     private Collider m_collider;
   
    private ZNetView m_nview;     private ZNetView m_nview;
   
    private readonly int[] m_liquids = new int[2];     private readonly int[] m_liquids = new int[2];
} }