Decompiled source of FluidLab v1.0.1

Mods/FluidLab.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BoneLib;
using FluidLab;
using HarmonyLib;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Audio;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.SceneStreaming;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.VRMK;
using Il2CppSystem;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FluidLabMod), "Fluid Lab", "1.0.1", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("A BONELAB mod that adds simulated buoyancy and drag.")]
[assembly: AssemblyTitle("Fluid Lab")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace FluidLab
{
	public static class BarcodeReferences
	{
		public const string WaterSplashVFX = "Lakatrazz.FluidEffectsResource.Spawnable.WaterSplash";

		public const string LavaSplashVFX = "Lakatrazz.FluidEffectsResource.Spawnable.LavaSplash";

		public const string AcidSplashVFX = "Lakatrazz.FluidEffectsResource.Spawnable.AcidSplash";

		public const string WaterSplashSFX = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallSplash";

		public const string LavaSplashSFX = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallLavaSplash";

		public const string AcidSplashSFX = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallAcidSplash";

		public const string WaterAmbience = "Lakatrazz.FluidEffectsResource.MonoDisc.Underwater";

		public const string LavaAmbience = "Lakatrazz.FluidEffectsResource.MonoDisc.Underlava";
	}
	public static class CommonDensities
	{
		public const float Water = 1000f;

		public const float Lava = 3100f;

		public const float Acid = 1180f;
	}
	public static class AscentManager
	{
		public static void OnLevelLoaded()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (LevelChecker.IsLevel("13 - Ascent"))
			{
				LiquidVolume liquidVolume = LiquidCreator.CreateLiquid(new Vector3(-102.341f, 22.32f, -138.4774f), Quaternion.identity, new Vector3(22.93945f, 6.998039f, 16.99998f), 1180f);
				liquidVolume.SplashVFXBarcode = "Lakatrazz.FluidEffectsResource.Spawnable.AcidSplash";
				liquidVolume.SplashSFXBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallAcidSplash";
				liquidVolume.AmbienceBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.Underlava";
			}
		}
	}
	public static class DungeonWarriorManager
	{
		public static readonly LiquidDefinition[] Liquids = new LiquidDefinition[4]
		{
			new LiquidDefinition(new Vector3(4.916908f, -15.06f, -16.8f), Quaternion.identity, new Vector3(12.74802f, 21.90735f, 49.21357f), 3100f),
			new LiquidDefinition(new Vector3(31.74236f, -37.95f, -43.49785f), Quaternion.identity, new Vector3(41.24413f, 21.01563f, 30.99791f), 3100f),
			new LiquidDefinition(new Vector3(53.82556f, -41.3f, -92.16464f), Quaternion.identity, new Vector3(10.99997f, 10.99804f, 23.03027f), 3100f),
			new LiquidDefinition(new Vector3(53.82556f, -80.91f, -110.8805f), Quaternion.identity, new Vector3(13f, 10.99988f, 22.99988f), 3100f)
		};

		public static void OnLevelLoaded()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (LevelChecker.IsLevel("Dungeon Warrior"))
			{
				LiquidDefinition[] liquids = Liquids;
				for (int i = 0; i < liquids.Length; i++)
				{
					LiquidDefinition liquidDefinition = liquids[i];
					LiquidVolume liquidVolume = LiquidCreator.CreateLiquid(liquidDefinition.position, liquidDefinition.rotation, liquidDefinition.size, liquidDefinition.density);
					liquidVolume.SplashVFXBarcode = "Lakatrazz.FluidEffectsResource.Spawnable.LavaSplash";
					liquidVolume.SplashSFXBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallLavaSplash";
					liquidVolume.AmbienceBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.Underlava";
				}
			}
		}
	}
	public static class LevelChecker
	{
		public static bool IsLevel(string title)
		{
			return ((Scannable)SceneStreamer.Session.Level).Title == title;
		}

		public static bool IsLoading()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			return (int)SceneStreamer.Session.Status == 1;
		}
	}
	public struct LiquidDefinition
	{
		public Vector3 position;

		public Quaternion rotation;

		public Vector3 size;

		public float density;

		public LiquidDefinition(Vector3 position, Quaternion rotation, Vector3 size, float density = 1000f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			this.position = position;
			this.rotation = rotation;
			this.size = size;
			this.density = density;
		}
	}
	public static class LiquidCreator
	{
		public static LiquidVolume CreateLiquid(Vector3 position, Quaternion rotation, Vector3 size, float density = 1000f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Liquid Volume");
			val.transform.position = position;
			val.transform.rotation = rotation;
			BoxCollider obj = val.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.size = size;
			LiquidVolume liquidVolume = val.AddComponent<LiquidVolume>();
			liquidVolume.size.Set(size);
			liquidVolume.density.Set(density);
			return liquidVolume;
		}

		public static FlowVolume CreateFlow(Vector3 position, Quaternion rotation, Vector3 size, Vector3 flow)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Flow Volume");
			val.transform.position = position;
			val.transform.rotation = rotation;
			BoxCollider obj = val.AddComponent<BoxCollider>();
			((Collider)obj).isTrigger = true;
			obj.size = size;
			FlowVolume flowVolume = val.AddComponent<FlowVolume>();
			flowVolume.size.Set(size);
			flowVolume.flow.Set(flow);
			return flowVolume;
		}
	}
	public static class MagmaGateManager
	{
		public static void OnLevelLoaded()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (LevelChecker.IsLevel("08 - Magma Gate"))
			{
				LiquidVolume liquidVolume = LiquidCreator.CreateLiquid(new Vector3(1.8f, -28.1f, 23.2f), Quaternion.identity, new Vector3(360.3596f, 54.99212f, 213.0187f), 3100f);
				liquidVolume.SplashVFXBarcode = "Lakatrazz.FluidEffectsResource.Spawnable.LavaSplash";
				liquidVolume.SplashSFXBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallLavaSplash";
				liquidVolume.AmbienceBarcode = "Lakatrazz.FluidEffectsResource.MonoDisc.Underlava";
			}
		}
	}
	public static class TuscanyManager
	{
		public static void OnLevelLoaded()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			if (LevelChecker.IsLevel("Tuscany"))
			{
				LiquidCreator.CreateLiquid(new Vector3(-7.137532f, -215.7f, -224f), Quaternion.identity, new Vector3(889.0146f, 407.6404f, 669.338f));
				Vector3 flow = Vector3.down * 1f;
				LiquidCreator.CreateFlow(new Vector3(-58.7f, -39.8f, -4.2f), Quaternion.Euler(-90f, 0f, 25f), new Vector3(123.769f, 37.42f, 56f), flow);
				LiquidCreator.CreateFlow(new Vector3(18.9f, -39.8f, -28.5f), Quaternion.Euler(-90f, 0f, -8f), new Vector3(67f, 32.82f, 56f), flow);
				LiquidCreator.CreateFlow(new Vector3(122.3f, -39.8f, -50.6f), Quaternion.Euler(-90f, 0f, 17f), new Vector3(178.11f, 39.35f, 56f), flow);
				LiquidCreator.CreateFlow(new Vector3(-217.4f, -39.8f, -1f), Quaternion.Euler(-90f, 0f, -17f), new Vector3(78.3f, 27.23f, 56f), flow);
				MelonCoroutines.Start(CoWaitForDeathTrigger("UNDER WATER KILL VOLUME"));
			}
		}

		private static IEnumerator CoWaitForDeathTrigger(string name)
		{
			while (LevelChecker.IsLoading())
			{
				yield return null;
			}
			GameObject val;
			while ((Object)(object)(val = GameObject.Find(name)) == (Object)null)
			{
				yield return null;
			}
			val.SetActive(false);
		}
	}
	public static class MathUtilities
	{
		public const float Rad2Deg = 57.29578f;

		public static Vector3 NormalizeSafe(Vector3 vector)
		{
			if (vector.LengthSquared() <= 0.005f)
			{
				return Vector3.Zero;
			}
			return Vector3.Normalize(vector);
		}

		public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection)
		{
			return RotateTowards(LookRotation(fromDirection), LookRotation(toDirection), float.MaxValue);
		}

		public static Quaternion RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta)
		{
			float num = Angle(from, to);
			if (num == 0f)
			{
				return to;
			}
			float amount = Math.Min(1f, maxDegreesDelta / num);
			return Quaternion.Slerp(from, to, amount);
		}

		public static Quaternion LookRotation(Vector3 forward)
		{
			Vector3 unitY = Vector3.UnitY;
			forward = Vector3.Normalize(forward);
			Vector3 vector = Vector3.Normalize(Vector3.Cross(unitY, forward));
			Vector3 vector2 = Vector3.Cross(forward, vector);
			float x = vector.X;
			float y = vector.Y;
			float z = vector.Z;
			float x2 = vector2.X;
			float y2 = vector2.Y;
			float z2 = vector2.Z;
			float x3 = forward.X;
			float y3 = forward.Y;
			float z3 = forward.Z;
			float num = x + y2 + z3;
			Quaternion result = default(Quaternion);
			if (num > 0f)
			{
				float num2 = (float)Math.Sqrt(num + 1f);
				result.W = num2 * 0.5f;
				num2 = 0.5f / num2;
				result.X = (z2 - y3) * num2;
				result.Y = (x3 - z) * num2;
				result.Z = (y - x2) * num2;
				return result;
			}
			if (x >= y2 && x >= z3)
			{
				float num3 = (float)Math.Sqrt(1f + x - y2 - z3);
				float num4 = 0.5f / num3;
				result.X = 0.5f * num3;
				result.Y = (y + x2) * num4;
				result.Z = (z + x3) * num4;
				result.W = (z2 - y3) * num4;
				return result;
			}
			if (y2 > z3)
			{
				float num5 = (float)Math.Sqrt(1f + y2 - x - z3);
				float num6 = 0.5f / num5;
				result.X = (x2 + y) * num6;
				result.Y = 0.5f * num5;
				result.Z = (y3 + z2) * num6;
				result.W = (x3 - z) * num6;
				return result;
			}
			float num7 = (float)Math.Sqrt(1f + z3 - x - y2);
			float num8 = 0.5f / num7;
			result.X = (x3 + z) * num8;
			result.Y = (y3 + z2) * num8;
			result.Z = 0.5f * num7;
			result.W = (y - x2) * num8;
			return result;
		}

		public static float Angle(Quaternion a, Quaternion b)
		{
			return (float)Math.Acos(Math.Min(Math.Abs(Quaternion.Dot(a, b)), 1f)) * 2f * 57.29578f;
		}
	}
	public class FluidLabMod : MelonMod
	{
		public const string Version = "1.0.1";

		private VoxelBody[] _playerVoxelBodies;

		private VoxelBody _leftHandVoxelBody;

		private VoxelBody _rightHandVoxelBody;

		private VoxelBody _headVoxelBody;

		private AudioSource _headAmbience;

		private Vector3 _cumulativeHandVelocity = Vector3.zero;

		public override void OnInitializeMelon()
		{
			Hooking.OnLevelLoaded += OnLevelLoaded;
			Hooking.OnSwitchAvatarPostfix += OnSwitchAvatarPostfix;
		}

		private void OnLevelLoaded(LevelInfo level)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			TuscanyManager.OnLevelLoaded();
			MagmaGateManager.OnLevelLoaded();
			AscentManager.OnLevelLoaded();
			DungeonWarriorManager.OnLevelLoaded();
			PhysicsRig physicsRig = Player.PhysicsRig;
			_playerVoxelBodies = Il2CppArrayBase<VoxelBody>.op_Implicit(((Component)physicsRig).GetComponentsInChildren<VoxelBody>());
			_leftHandVoxelBody = ((Component)physicsRig.leftHand).GetComponent<VoxelBody>();
			_rightHandVoxelBody = ((Component)physicsRig.rightHand).GetComponent<VoxelBody>();
			_headVoxelBody = ((Component)((Rig)physicsRig).m_head).GetComponent<VoxelBody>();
			_headVoxelBody.OnEnterLiquid += OnPlayerEnterLiquid;
			_headVoxelBody.OnExitLiquid += OnPlayerExitLiquid;
			_headAmbience = ((Component)((Rig)physicsRig).m_head).gameObject.AddComponent<AudioSource>();
			_headAmbience.spatialBlend = 0f;
			_headAmbience.outputAudioMixerGroup = Audio3dManager.ambience;
			_headAmbience.playOnAwake = false;
			_headAmbience.loop = true;
			_headAmbience.volume = 0.2f;
			_cumulativeHandVelocity = Vector3.zero;
		}

		private void OnPlayerEnterLiquid()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Audio3dPlugin.Audio3dManager.SetLowPassFilter(1000f);
			if ((Object)(object)_headVoxelBody.SubmergedLiquid != (Object)null)
			{
				MonoDiscReference val = new MonoDiscReference(_headVoxelBody.SubmergedLiquid.AmbienceBarcode);
				if ((Object)(object)((DataCardReference<MonoDisc>)(object)val).DataCard != (Object)null)
				{
					((DataCardReference<MonoDisc>)(object)val).DataCard.AudioClip.LoadAsset(Action<AudioClip>.op_Implicit((Action<AudioClip>)OnAmbienceLoaded));
				}
			}
			void OnAmbienceLoaded(AudioClip clip)
			{
				if (!((Object)(object)_headAmbience == (Object)null))
				{
					_headAmbience.clip = clip;
					_headAmbience.Play();
				}
			}
		}

		private void OnPlayerExitLiquid()
		{
			Audio3dPlugin.Audio3dManager.SetLowPassFilter(22000f);
			if ((Object)(object)_headAmbience != (Object)null)
			{
				_headAmbience.Stop();
				_headAmbience.clip = null;
			}
		}

		private void OnSwitchAvatarPostfix(Avatar avatar)
		{
			VoxelBody[] playerVoxelBodies = _playerVoxelBodies;
			for (int i = 0; i < playerVoxelBodies.Length; i++)
			{
				playerVoxelBodies[i].RecalculateVoxels();
			}
		}

		public override void OnFixedUpdate()
		{
			VoxelBodyManager.OnFixedUpdate();
			if ((Object)(object)Player.RigManager != (Object)null && _playerVoxelBodies != null)
			{
				OnUpdatePlayer();
			}
		}

		private void OnUpdatePlayer()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			RigManager rigManager = Player.RigManager;
			float num = Mathf.Clamp01((rigManager.controllerRig.GetCrouch() + 1f) * 0.5f);
			num *= num;
			PhysicsRig physicsRig = rigManager.physicsRig;
			Vector3 val = Vector3.zero;
			Vector3 velocity = physicsRig.torso.rbHead.velocity;
			if (Object.op_Implicit((Object)(object)_leftHandVoxelBody.SubmergedLiquid))
			{
				val += physicsRig.leftHand.rb.velocity - velocity;
			}
			if (Object.op_Implicit((Object)(object)_rightHandVoxelBody.SubmergedLiquid))
			{
				val += physicsRig.rightHand.rb.velocity - velocity;
			}
			val *= ((Vector3)(ref val)).magnitude;
			Vector3 val2 = val * Time.deltaTime;
			float num2 = Vector3.Dot(((Vector3)(ref _cumulativeHandVelocity)).normalized, ((Vector3)(ref val)).normalized);
			num2 = Mathf.Clamp((num2 + 1f) * 0.5f, 0.1f, 1f);
			_cumulativeHandVelocity += Vector3.ClampMagnitude(val2 * num2, 2f);
			_cumulativeHandVelocity = Vector3.ClampMagnitude(_cumulativeHandVelocity, 10f);
			VoxelBody[] playerVoxelBodies = _playerVoxelBodies;
			foreach (VoxelBody obj in playerVoxelBodies)
			{
				obj.BuoyancyMultiplier = num;
				obj.ExtraVelocity = -_cumulativeHandVelocity;
			}
			_cumulativeHandVelocity = Vector3.Lerp(_cumulativeHandVelocity, Vector3.zero, 1f - Mathf.Exp(-4f * Time.deltaTime));
		}
	}
	[RegisterTypeInIl2Cpp]
	public class FlowVolume : MonoBehaviour
	{
		public Il2CppValueField<Vector3> center;

		public Il2CppValueField<Vector3> size;

		public Il2CppValueField<Vector3> flow;

		public Vector3 Velocity => ((Component)this).transform.rotation * Il2CppValueField<Vector3>.op_Implicit(flow);

		public FlowVolume(IntPtr intPtr)
			: base(intPtr)
		{
		}
	}
	[RegisterTypeInIl2Cpp]
	public class LiquidVolume : MonoBehaviour
	{
		public Il2CppValueField<float> density;

		public Il2CppValueField<Vector3> center;

		public Il2CppValueField<Vector3> size;

		public Il2CppValueField<Vector3> flow;

		private Vector3 _worldFlow = Vector3.zero;

		private Vector3 _worldCenter = Vector3.zero;

		private Vector3 _worldSize = Vector3.zero;

		private float _height;

		public float Density => Il2CppValueField<float>.op_Implicit(density);

		public Vector3 Velocity => _worldFlow;

		public Vector3 WorldCenter => _worldCenter;

		public Vector3 WorldSize => _worldSize;

		public float Height => _height;

		public string AmbienceBarcode { get; set; } = "Lakatrazz.FluidEffectsResource.MonoDisc.Underwater";


		public bool AmbienceEnabled { get; set; } = true;


		public string SplashVFXBarcode { get; set; } = "Lakatrazz.FluidEffectsResource.Spawnable.WaterSplash";


		public string SplashSFXBarcode { get; set; } = "Lakatrazz.FluidEffectsResource.MonoDisc.SmallSplash";


		public bool SplashEnabled { get; set; } = true;


		public LiquidVolume(IntPtr intPtr)
			: base(intPtr)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)


		[HideFromIl2Cpp]
		public void Splash(Vector3 position, float speed, float size)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			if (!SplashEnabled)
			{
				return;
			}
			position.y = Height;
			float num = speed / 10f;
			float num2 = Math.Clamp(size / 0.05f, 0f, 1f);
			float volume = Math.Clamp(num * num2, 0f, 1f);
			volume *= volume;
			if (!(volume < 0.05f))
			{
				SpawnSplashEffect(position, size * Mathf.Lerp(0.2f, 1f, volume));
				MonoDiscReference val = new MonoDiscReference(SplashSFXBarcode);
				if ((Object)(object)((DataCardReference<MonoDisc>)(object)val).DataCard != (Object)null)
				{
					((DataCardReference<MonoDisc>)(object)val).DataCard.AudioClip.LoadAsset(Action<AudioClip>.op_Implicit((Action<AudioClip>)OnLoadedSound));
				}
			}
			void OnLoadedSound(AudioClip clip)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				float num3 = Mathf.Pow(Random.Range(0.7f, 1.2f), volume);
				Audio3dManager.PlayAtPoint(clip, position, Audio3dManager.impact, volume, num3, new Nullable<float>(0f), new Nullable<float>(1f), new Nullable<float>(1f));
			}
		}

		private void SpawnSplashEffect(Vector3 position, float size)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			Spawnable val = new Spawnable
			{
				crateRef = new SpawnableCrateReference(SplashVFXBarcode),
				policyData = null
			};
			AssetSpawner.Register(val);
			AssetSpawner.Spawn(val, position, Quaternion.identity, new Nullable<Vector3>(Vector3.one * size), (Transform)null, true, new Nullable<int>(0), (Action<GameObject>)null, (Action<GameObject>)null);
		}

		private void LateUpdate()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 localToWorldMatrix = ((Component)this).transform.localToWorldMatrix;
			_worldCenter = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(Il2CppValueField<Vector3>.op_Implicit(center));
			_worldSize = Vector3.Scale(((Matrix4x4)(ref localToWorldMatrix)).lossyScale, Il2CppValueField<Vector3>.op_Implicit(size));
			_height = WorldCenter.y + WorldSize.y * 0.5f;
			_worldFlow = ((Component)this).transform.rotation * Il2CppValueField<Vector3>.op_Implicit(flow);
		}

		public void SetAmbience(string barcode)
		{
			AmbienceBarcode = barcode;
		}

		public void ToggleAmbience(bool enabled)
		{
			AmbienceEnabled = enabled;
		}

		public void SetSplashVFX(string barcode)
		{
			SplashVFXBarcode = barcode;
		}

		public void SetSplashSFX(string barcode)
		{
			SplashSFXBarcode = barcode;
		}

		public void ToggleSplash(bool enabled)
		{
			SplashEnabled = enabled;
		}
	}
	[Serializable]
	public class Voxel
	{
		public Vector3 position;

		public float submersion;
	}
	[RegisterTypeInIl2Cpp]
	public class VoxelBody : MonoBehaviour
	{
		[Serializable]
		public class VoxelLevel
		{
			public Voxel[] voxels;

			public Vector3 voxelSize;

			public AABB voxelAABB;
		}

		public struct AABB
		{
			public Vector3 c1;

			public Vector3 c2;

			public Vector3 c3;

			public Vector3 c4;

			public Vector3 c5;

			public Vector3 c6;

			public Vector3 c7;

			public Vector3 c8;

			public AABB(Vector3 size)
			{
				Vector3 vector = size * 0.5f;
				float x = vector.X;
				float y = vector.Y;
				float z = vector.Z;
				c1 = new Vector3(x, y, z);
				c2 = new Vector3(0f - x, y, z);
				c3 = new Vector3(x, 0f - y, z);
				c4 = new Vector3(x, y, 0f - z);
				c5 = new Vector3(0f - x, 0f - y, z);
				c6 = new Vector3(x, 0f - y, 0f - z);
				c7 = new Vector3(0f - x, y, 0f - z);
				c8 = new Vector3(0f - x, 0f - y, 0f - z);
			}

			public readonly Vector3 RotateAABB(Quaternion rotation)
			{
				Vector3 value = Vector3.Transform(c1, rotation);
				Vector3 value2 = Vector3.Transform(c2, rotation);
				Vector3 value3 = Vector3.Transform(c3, rotation);
				Vector3 value4 = Vector3.Transform(c4, rotation);
				Vector3 value5 = Vector3.Transform(c5, rotation);
				Vector3 value6 = Vector3.Transform(c6, rotation);
				Vector3 value7 = Vector3.Transform(c7, rotation);
				Vector3 value8 = Vector3.Transform(c8, rotation);
				Vector3 vector = Vector3.Min(Vector3.Min(Vector3.Min(Vector3.Min(Vector3.Min(Vector3.Min(Vector3.Min(value, value2), value3), value4), value5), value6), value7), value8);
				return Vector3.Max(Vector3.Max(Vector3.Max(Vector3.Max(Vector3.Max(Vector3.Max(Vector3.Max(value, value2), value3), value4), value5), value6), value7), value8) - vector;
			}
		}

		public class VoxelReference
		{
			public Voxel voxel;

			public Vector3 overridePosition;
		}

		private MarrowBody _marrowBody;

		private int _colliderCount;

		private VoxelLevel _voxelLevel;

		private int _liquidCount;

		private int _flowCount;

		private LiquidVolume _activeLiquid;

		private FlowVolume _activeFlow;

		private bool _validUpdate;

		private Vector3 _bodyPosition = Vector3.Zero;

		private Quaternion _bodyRotation = Quaternion.Identity;

		private Vector3 _bodyCenterOfMass = Vector3.Zero;

		private Vector3 _bodyVelocity = Vector3.Zero;

		private Vector3 _bodyAngularVelocity = Vector3.Zero;

		private float _liquidDensity = 1f;

		private float _liquidHeight;

		private Vector3 _liquidVelocity = Vector3.Zero;

		private Vector3 _flowVelocity = Vector3.Zero;

		private Vector3 _gravity = Vector3.Zero;

		private float _mass = 1f;

		private float _fixedDeltaTime = 1f;

		private Vector3 _totalForce = Vector3.Zero;

		private Vector3 _centerOfForce = Vector3.Zero;

		private int _forceCount;

		public Rigidbody Body => _marrowBody._rigidbody;

		public float BuoyancyMultiplier { get; set; } = 1f;


		public Vector3 ExtraVelocity { get; set; } = Vector3.zero;


		public LiquidVolume SubmergedLiquid => _activeLiquid;

		[HideFromIl2Cpp]
		public event Action OnEnterLiquid;

		[HideFromIl2Cpp]
		public event Action OnExitLiquid;

		public VoxelBody(IntPtr intPtr)
			: base(intPtr)
		{
		}//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)


		private void Awake()
		{
			_marrowBody = ((Component)this).GetComponent<MarrowBody>();
			_colliderCount = ((Il2CppArrayBase<Collider>)(object)_marrowBody.Colliders).Count;
			RecalculateVoxels();
		}

		[HideFromIl2Cpp]
		private Collider[] GetColliders()
		{
			return Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)_marrowBody.Colliders);
		}

		public void RecalculateVoxels()
		{
			_liquidCount = 0;
			_flowCount = 0;
			int voxelCount = 128 / ((Il2CppArrayBase<MarrowBody>)(object)_marrowBody.Entity.Bodies).Length;
			_voxelLevel = CutIntoVoxels(voxelCount);
		}

		private void OnTriggerEnter(Collider other)
		{
			CheckLiquidEnter(other);
			CheckFlowEnter(other);
		}

		private void CheckLiquidEnter(Collider other)
		{
			LiquidVolume component = ((Component)other).GetComponent<LiquidVolume>();
			if (((Object)(object)component == (Object)(object)_activeLiquid || (Object)(object)_activeLiquid == (Object)null) && (Object)(object)component != (Object)null)
			{
				_liquidCount++;
				_liquidCount = Math.Min(_liquidCount, _colliderCount);
				if (_liquidCount == 1)
				{
					RegisterLiquid(component);
				}
			}
		}

		private void CheckFlowEnter(Collider other)
		{
			FlowVolume component = ((Component)other).GetComponent<FlowVolume>();
			if (((Object)(object)component == (Object)(object)_activeFlow || (Object)(object)_activeFlow == (Object)null) && (Object)(object)component != (Object)null)
			{
				_flowCount++;
				_flowCount = Math.Min(_flowCount, _colliderCount);
				if (_flowCount == 1)
				{
					_activeFlow = component;
				}
			}
		}

		private void OnTriggerExit(Collider other)
		{
			CheckLiquidExit(other);
			CheckFlowExit(other);
		}

		private void CheckLiquidExit(Collider other)
		{
			if (Object.op_Implicit((Object)(object)_activeLiquid) && (Object)(object)((Component)other).gameObject == (Object)(object)((Component)_activeLiquid).gameObject)
			{
				_liquidCount--;
				if (_liquidCount <= 0)
				{
					UnregisterLiquid();
				}
			}
		}

		private void CheckFlowExit(Collider other)
		{
			if (Object.op_Implicit((Object)(object)_activeFlow) && (Object)(object)((Component)other).gameObject == (Object)(object)((Component)_activeFlow).gameObject)
			{
				_flowCount--;
				if (_flowCount <= 0)
				{
					_activeFlow = null;
					_flowCount = 0;
				}
			}
		}

		public void RegisterLiquid(LiquidVolume liquid)
		{
			_activeLiquid = liquid;
			this.OnEnterLiquid?.Invoke();
			if (_marrowBody.HasRigidbody)
			{
				Splash(liquid);
			}
		}

		private void Splash(LiquidVolume liquid)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = Body.velocity;
			float magnitude = ((Vector3)(ref velocity)).magnitude;
			if (!(magnitude < 2f))
			{
				Bounds bounds = _marrowBody.Bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				float size2 = (size.x + size.y + size.z) / 3f;
				Vector3 worldCenterOfMass = Body.worldCenterOfMass;
				liquid.Splash(worldCenterOfMass, magnitude, size2);
			}
		}

		public void UnregisterLiquid()
		{
			_activeLiquid = null;
			_liquidCount = 0;
			this.OnExitLiquid?.Invoke();
		}

		private void OnDisable()
		{
			UnregisterLiquid();
			_activeFlow = null;
			_flowCount = 0;
			VoxelBodyManager.VoxelBodies.Remove(this);
		}

		private void OnEnable()
		{
			UnregisterLiquid();
			_activeFlow = null;
			_flowCount = 0;
			VoxelBodyManager.VoxelBodies.Add(this);
		}

		public void OnPreFixedUpdate()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			_validUpdate = true;
			if (!_marrowBody.HasRigidbody)
			{
				_validUpdate = false;
				return;
			}
			if (!Object.op_Implicit((Object)(object)_activeLiquid))
			{
				_validUpdate = false;
				return;
			}
			if (Body.IsSleeping())
			{
				_validUpdate = false;
				return;
			}
			_fixedDeltaTime = Time.fixedDeltaTime;
			_mass = Body.mass;
			_gravity = ToSystemVector3(Physics.gravity);
			Quaternion rotation = ((Component)this).transform.rotation;
			_bodyPosition = ToSystemVector3(((Component)this).transform.position);
			_bodyRotation = new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w);
			_bodyCenterOfMass = ToSystemVector3(Body.worldCenterOfMass);
			_bodyVelocity = ToSystemVector3(Body.velocity);
			_bodyAngularVelocity = ToSystemVector3(Body.angularVelocity);
			_liquidDensity = _activeLiquid.Density;
			_liquidVelocity = ToSystemVector3(_activeLiquid.Velocity + ExtraVelocity);
			_liquidHeight = _activeLiquid.Height;
			if ((Object)(object)_activeFlow != (Object)null)
			{
				_flowVelocity = ToSystemVector3(_activeFlow.Velocity);
			}
			else
			{
				_flowVelocity = Vector3.Zero;
			}
		}

		[HideFromIl2Cpp]
		public void OnParallelFixedUpdate()
		{
			_totalForce = Vector3.Zero;
			_centerOfForce = Vector3.Zero;
			_forceCount = 0;
			if (!_validUpdate)
			{
				return;
			}
			VoxelLevel voxelLevel = _voxelLevel;
			Voxel[] voxels = voxelLevel.voxels;
			Vector3 voxelSize = voxelLevel.voxelSize;
			float y = voxelLevel.voxelAABB.RotateAABB(_bodyRotation).Y;
			float num = y * 0.5f;
			float num2 = voxelSize.X * voxelSize.Y * voxelSize.Z;
			float liquidDensity = _liquidDensity;
			Vector3 fluidVelocity = _liquidVelocity + _flowVelocity;
			Voxel[] array = voxels;
			foreach (Voxel obj in array)
			{
				Vector3 vector = Vector3.Transform(obj.position, _bodyRotation) + _bodyPosition;
				Vector3 pointVelocity = GetPointVelocity(_bodyCenterOfMass, _bodyVelocity, _bodyAngularVelocity, vector);
				vector += pointVelocity * _fixedDeltaTime;
				float num3 = vector.Y - num;
				float num4 = _liquidHeight - num3;
				num4 = (obj.submersion = Math.Clamp(num4 / y, 0f, 1f));
				if (num4 > 0f)
				{
					float num5 = num2 * num4;
					Vector3 vector2 = BuoyancyMultiplier * liquidDensity * num5 * -_gravity;
					_totalForce += vector2;
					_centerOfForce += vector;
					_forceCount++;
				}
			}
			SolveFluidDrag(fluidVelocity, liquidDensity, voxelLevel);
		}

		public void OnPostFixedUpdate()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (_forceCount > 0)
			{
				Body.AddForceAtPosition(ToUnityVector3(_totalForce), ToUnityVector3(_centerOfForce / _forceCount));
				Rigidbody body = Body;
				body.angularVelocity *= Math.Clamp(1f - _fixedDeltaTime * 6f, 0f, 1f);
			}
		}

		[HideFromIl2Cpp]
		private void SolveFluidDrag(Vector3 fluidVelocity, float fluidDensity, VoxelLevel voxelLevel)
		{
			Vector3 voxelSize = voxelLevel.voxelSize;
			Voxel[] projectedVoxels = GetProjectedVoxels(MathUtilities.NormalizeSafe(fluidVelocity - _bodyVelocity), voxelLevel);
			float voxelArea = GetVoxelArea(voxelSize);
			float num = 0.5f;
			Vector3 zero = Vector3.Zero;
			Vector3 zero2 = Vector3.Zero;
			int num2 = 0;
			Voxel[] array = projectedVoxels;
			foreach (Voxel obj in array)
			{
				float submersion = obj.submersion;
				Vector3 vector = Vector3.Transform(obj.position, _bodyRotation) + _bodyPosition;
				Vector3 pointVelocity = GetPointVelocity(_bodyCenterOfMass, _bodyVelocity, _bodyAngularVelocity, vector);
				Vector3 vector2 = fluidVelocity - pointVelocity;
				float num3 = fluidDensity * vector2.Length() * 0.5f;
				Vector3 vector3 = num * num3 * voxelArea * submersion * vector2;
				zero += vector3;
				zero2 += vector;
				num2++;
			}
			float val = _bodyVelocity.Length() / _fixedDeltaTime * _mass;
			zero = MathUtilities.NormalizeSafe(zero) * Math.Min(zero.Length(), val);
			_totalForce += zero;
			_centerOfForce += zero2;
			_forceCount += num2;
		}

		private static Vector3 ToSystemVector3(Vector3 vector)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(vector.x, vector.y, vector.z);
		}

		private static Vector3 ToUnityVector3(Vector3 vector)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(vector.X, vector.Y, vector.Z);
		}

		private static Vector3 GetPointVelocity(Vector3 worldCenterOfMass, Vector3 velocity, Vector3 angularVelocity, Vector3 point)
		{
			return Vector3.Cross(angularVelocity, point - worldCenterOfMass) + velocity;
		}

		[HideFromIl2Cpp]
		private Voxel[] GetProjectedVoxels(Vector3 direction, VoxelLevel voxelLevel)
		{
			Voxel[] voxels = voxelLevel.voxels;
			Vector3 voxelSize = voxelLevel.voxelSize;
			Quaternion quaternion = MathUtilities.FromToRotation(Vector3.UnitZ, direction);
			List<VoxelReference> list = new List<VoxelReference>();
			Vector3 directionInMatrix = Vector3.Transform(direction, Quaternion.Inverse(_bodyRotation)) * 1000f;
			foreach (Voxel item in voxels.OrderByDescending((Voxel voxel) => (voxel.position - directionInMatrix).LengthSquared()))
			{
				if (!(item.submersion <= 0f))
				{
					Vector3 value = Vector3.Transform(item.position, _bodyRotation) + _bodyPosition;
					value = Vector3.Transform(value, quaternion);
					value.Z = 0f;
					value = Vector3.Transform(value, Quaternion.Inverse(quaternion));
					list.Add(new VoxelReference
					{
						voxel = item,
						overridePosition = value
					});
				}
			}
			List<VoxelReference> list2 = new List<VoxelReference>();
			float maxDistanceSqr = voxelSize.LengthSquared() / 2f;
			foreach (VoxelReference voxel2 in list)
			{
				if (!list2.Exists((VoxelReference nonDupe) => (voxel2.overridePosition - nonDupe.overridePosition).LengthSquared() < maxDistanceSqr))
				{
					list2.Add(voxel2);
				}
			}
			Voxel[] array = new Voxel[list2.Count];
			for (int i = 0; i < list2.Count; i++)
			{
				array[i] = list2[i].voxel;
			}
			return array;
		}

		private static float GetVoxelArea(Vector3 voxelSize)
		{
			return Math.Abs(voxelSize.X * voxelSize.Y);
		}

		[HideFromIl2Cpp]
		private VoxelLevel CutIntoVoxels(int voxelCount)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			Quaternion rotation = ((Component)this).transform.rotation;
			voxelCount = Math.Max(voxelCount, 4);
			_marrowBody.CalculateBounds();
			Bounds bounds = _marrowBody.Bounds;
			Collider[] colliders = GetColliders();
			float num = 1f / (float)Math.Cbrt(voxelCount);
			Vector3 val = ((Bounds)(ref bounds)).size * num;
			int num2 = Mathf.RoundToInt(1f / num);
			List<Voxel> list = new List<Voxel>(num2 * num2 * num2);
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < num2; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					for (int k = 0; k < num2; k++)
					{
						Vector3 min = ((Bounds)(ref bounds)).min;
						float num3 = min.x + val.x * (0.5f + (float)i);
						float num4 = min.y + val.y * (0.5f + (float)j);
						float num5 = min.z + val.z * (0.5f + (float)k);
						((Vector3)(ref val2))..ctor(num3, num4, num5);
						Vector3 point = rotation * val2 + position;
						if (IsPointInsideCollider(colliders, point))
						{
							Voxel item = new Voxel
							{
								position = ToSystemVector3(val2)
							};
							list.Add(item);
						}
					}
				}
			}
			Vector3 vector = ToSystemVector3(val);
			return new VoxelLevel
			{
				voxels = list.ToArray(),
				voxelSize = vector,
				voxelAABB = new AABB(vector)
			};
		}

		private static bool IsPointInsideCollider(Collider[] colliders, Vector3 point)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < colliders.Length; i++)
			{
				if (colliders[i].ClosestPoint(point) == point)
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class VoxelBodyManager
	{
		public static HashSet<VoxelBody> VoxelBodies { get; } = new HashSet<VoxelBody>();


		public static void OnFixedUpdate()
		{
			foreach (VoxelBody voxelBody in VoxelBodies)
			{
				try
				{
					voxelBody.OnPreFixedUpdate();
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Error caught running OnPreFixedUpdate.", ex);
				}
			}
			Parallel.ForEach(VoxelBodies, OnParallelFixedUpdate);
			foreach (VoxelBody voxelBody2 in VoxelBodies)
			{
				try
				{
					voxelBody2.OnPostFixedUpdate();
				}
				catch (Exception ex2)
				{
					MelonLogger.Error("Error caught running OnPostFixedUpdate.", ex2);
				}
			}
		}

		private static void OnParallelFixedUpdate(VoxelBody body)
		{
			try
			{
				body.OnParallelFixedUpdate();
			}
			catch (Exception ex)
			{
				MelonLogger.Error("Error caught running OnParallelFixedUpdate.", ex);
			}
		}
	}
}
namespace FluidLab.Patching
{
	[HarmonyPatch(typeof(MarrowBody))]
	public static class MarrowBodyPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void Awake(MarrowBody __instance)
		{
			((Component)__instance).gameObject.AddComponent<VoxelBody>();
		}
	}
}