Decompiled source of Crumble v1.0.1

Mods/Crumble.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.MoveSystem;
using Il2CppSystem;
using Il2CppTMPro;
using Main;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RockUI;
using RumbleModdingAPI.RMAPI;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::Main.Main), "Crumble", "1.0.0", "Nano", null)]
[assembly: MelonColor(127, 52, 235, 131)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonAdditionalDependencies(new string[] { "RockUI" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Main
{
	public static class ChunkCache
	{
		private static readonly Dictionary<string, ChunkData[]> Cache = new Dictionary<string, ChunkData[]>();

		private static readonly Dictionary<int, (Mesh mesh, Bounds bounds)> Seen = new Dictionary<int, (Mesh, Bounds)>();

		private static string MakeKey(Mesh mesh, int count, bool minecraft)
		{
			return $"{((Object)mesh).GetInstanceID()}|{count}|{minecraft}";
		}

		public static bool TryGet(Mesh mesh, out ChunkData[] chunks)
		{
			int value = Preferences.ChunksPerBreak.Value;
			bool value2 = Preferences.ChunkStyleMinecraft.Value;
			return Cache.TryGetValue(MakeKey(mesh, value, value2), out chunks);
		}

		public static ChunkData[] Build(Mesh mesh, Bounds bounds)
		{
			//IL_000c: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			Seen[((Object)mesh).GetInstanceID()] = (mesh, bounds);
			int value = Preferences.ChunksPerBreak.Value;
			bool value2 = Preferences.ChunkStyleMinecraft.Value;
			string key = MakeKey(mesh, value, value2);
			if (Cache.TryGetValue(key, out var value3))
			{
				return value3;
			}
			float value4 = Preferences.SliceRandomness.Value;
			ChunkData[] chunks;
			if (value2)
			{
				chunks = ShardClusterBuilder.Build(bounds, value, value4);
				Preferences.Log($"Built {chunks.Length} shards (minecraft) for mesh {((Object)mesh).GetInstanceID()}.");
			}
			else
			{
				Mesh val = (mesh.isReadable ? mesh : null);
				bool flag = false;
				if ((Object)(object)val == (Object)null && MeshReadback.TryMakeReadable(mesh, out var readable))
				{
					val = readable;
					flag = true;
				}
				if ((Object)(object)val != (Object)null && MeshSlicer.TrySlice(val, value, value4, out chunks))
				{
					Preferences.Log($"Sliced mesh {((Object)mesh).GetInstanceID()} into {chunks.Length} ({(flag ? "GPU readback" : "readable")}).");
				}
				else
				{
					chunks = ShardClusterBuilder.Build(bounds, value, value4);
					Preferences.Log($"Mesh {((Object)mesh).GetInstanceID()} not sliceable; built {chunks.Length} shards.");
				}
			}
			Cache[key] = chunks;
			return chunks;
		}

		public static IEnumerator PreWarm()
		{
			HashSet<int> seen = new HashSet<int>();
			Il2CppArrayBase<Structure> val = Object.FindObjectsOfType<Structure>();
			foreach (Structure item in val)
			{
				MeshFilter componentInChildren = ((Component)item).GetComponentInChildren<MeshFilter>();
				if (!((Object)(object)componentInChildren == (Object)null) && !((Object)(object)componentInChildren.sharedMesh == (Object)null))
				{
					int instanceID = ((Object)componentInChildren.sharedMesh).GetInstanceID();
					if (seen.Add(instanceID))
					{
						Build(componentInChildren.sharedMesh, componentInChildren.sharedMesh.bounds);
						yield return null;
					}
				}
			}
			Preferences.Log($"Pre-warm complete: {seen.Count} structure meshes cached.");
		}

		public static IEnumerator PrewarmCurrent()
		{
			List<(Mesh mesh, Bounds bounds)> snapshot = new List<(Mesh, Bounds)>(Seen.Values);
			foreach (var item in snapshot)
			{
				if (!((Object)(object)item.mesh == (Object)null))
				{
					Build(item.mesh, item.bounds);
					yield return null;
				}
			}
			Preferences.Log($"Pre-warmed {snapshot.Count} meshes at current settings.");
		}

		public static void Clear()
		{
			foreach (ChunkData[] value in Cache.Values)
			{
				for (int i = 0; i < value.Length; i++)
				{
					if ((Object)(object)value[i].Mesh != (Object)null)
					{
						Object.Destroy((Object)(object)value[i].Mesh);
					}
				}
			}
			Cache.Clear();
			Seen.Clear();
		}
	}
	public struct ChunkData
	{
		public Mesh Mesh;

		public Vector3 LocalOffset;

		public ChunkData(Mesh mesh, Vector3 localOffset)
		{
			//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)
			Mesh = mesh;
			LocalOffset = localOffset;
		}
	}
	internal static class CrumbleUI
	{
		private const float PanelW = 13f;

		private const float PanelH = 23f;

		private const float TitleY = 10.5f;

		private const float ModeLabelY = 8f;

		private const float ModeStateY = 8.8f;

		private const float ModeLeverY = 7.2f;

		private const float ChunksLabelY = 5f;

		private const float ChunksValueY = 5.8f;

		private const float ChunksSliderY = 4.2f;

		private const float StyleLabelY = 2f;

		private const float StyleStateY = 2.8f;

		private const float StyleLeverY = 1.2f;

		private const float RockLabelY = -1f;

		private const float RockStateY = -0.2f;

		private const float RockLeverY = -1.8f;

		private const float SizeLabelY = -4f;

		private const float SizeValueY = -3.2f;

		private const float SizeSliderY = -4.8f;

		private const float TimeLabelY = -7f;

		private const float TimeValueY = -6.2f;

		private const float TimeSliderY = -7.8f;

		private const float LeftColX = -3.5f;

		private const float RightColX = 3.5f;

		private const float CentreX = 0f;

		private const float LimitPanelW = 10f;

		private const float LimitPanelH = 6f;

		private const float LimitTitleY = 1.8f;

		private const float LimitValueY = 0.1f;

		private const float LimitSliderY = -1.6f;

		private const float LimitYaw = 20f;

		private const float Distance = 3f;

		private const float HeightDrop = 0.3f;

		private static GameObject _panel;

		private static bool _suppress;

		private static TextMeshPro _modeTmp;

		private static TextMeshPro _styleTmp;

		private static TextMeshPro _chunksTmp;

		private static TextMeshPro _rockTmp;

		private static TextMeshPro _sizeTmp;

		private static TextMeshPro _timeTmp;

		private static InteractionLever _styleLever;

		private static bool _suppressStyle;

		private static int _styleSyncToken;

		private static int _lastStyleStep = -1;

		private static GameObject _limitPanel;

		private static TextMeshPro _limitTmp;

		private static int _lastLimit = -1;

		private const string ModeStateTag = "__MODE_STATE__";

		private const string StyleStateTag = "__STYLE_STATE__";

		private const string ChunksValueTag = "__CHUNKS_VALUE__";

		private const string RockCamStateTag = "__ROCKCAM_STATE__";

		private const string ChunkSizeValueTag = "__CHUNKSIZE_VALUE__";

		private const string TimeDespawnValueTag = "__TIMEDESPAWN_VALUE__";

		private const string ChunkLimitValueTag = "__CHUNKLIMIT_VALUE__";

		private static int _lastDespawn = -1;

		public static bool IsOpen => (Object)(object)_panel != (Object)null;

		public static void Toggle()
		{
			if (IsOpen)
			{
				Close();
			}
			else
			{
				Open();
			}
		}

		public static void Close()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
				_panel = null;
			}
			if ((Object)(object)_limitPanel != (Object)null)
			{
				Object.Destroy((Object)(object)_limitPanel);
				_limitPanel = null;
			}
			_limitTmp = null;
			_lastLimit = -1;
			_modeTmp = null;
			_styleTmp = null;
			_chunksTmp = null;
			_rockTmp = null;
			_sizeTmp = null;
			_timeTmp = null;
			_styleLever = null;
			_suppressStyle = false;
			_lastStyleStep = -1;
		}

		public static void Open()
		{
			if (IsOpen)
			{
				return;
			}
			try
			{
				BuildPanel();
			}
			catch (Exception value)
			{
				Main.Logger.Error($"CrumbleUI.Open failed: {value}");
			}
		}

		private static void BuildPanel()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00c3: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Expected O, but got Unknown
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Expected O, but got Unknown
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Expected O, but got Unknown
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Expected O, but got Unknown
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Expected O, but got Unknown
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Expected O, but got Unknown
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Expected O, but got Unknown
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Expected O, but got Unknown
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Expected O, but got Unknown
			//IL_0559: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Expected O, but got Unknown
			//IL_05a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Expected O, but got Unknown
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Unknown result type (might be due to invalid IL or missing references)
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Unknown result type (might be due to invalid IL or missing references)
			//IL_063f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Expected O, but got Unknown
			//IL_0663: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_0681: Unknown result type (might be due to invalid IL or missing references)
			//IL_0686: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_069b: Expected O, but got Unknown
			//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			_suppress = true;
			bool value = Preferences.PersistUntilSceneChange.Value;
			bool value2 = Preferences.ChunkStyleMinecraft.Value;
			int value3 = Preferences.ChunksPerBreak.Value;
			bool value4 = Preferences.RockCamVisibility.Value;
			int value5 = Preferences.ChunkSize.Value;
			int num = (int)Preferences.ChunkLifetime.Value;
			bool num2 = value2 || value3 == 1;
			string text = (value ? "Chaos" : "Default");
			string text2 = (num2 ? "Minecraft" : "Real slices");
			string text3 = value3.ToString();
			string text4 = (value4 ? "True" : "False");
			string text5 = value5.ToString();
			string text6 = num.ToString();
			RockPanel val = new RockPanel();
			val.size = new Vector2(13f, 23f);
			RockText val2 = new RockText();
			val2.text = "Crumble";
			val2.fontSize = 2;
			val2.fontColor = Color.white;
			((UIElement)val2).anchor = (AnchorType)8;
			((UIElement)val2).anchorOffset = new Vector2(0f, 10.5f);
			((UIElement)val).AddChildUI((UIElement)(object)val2);
			RockText val3 = new RockText();
			val3.text = "Mode:";
			val3.fontSize = 1;
			val3.fontColor = Color.white;
			((UIElement)val3).anchor = (AnchorType)8;
			((UIElement)val3).anchorOffset = new Vector2(-3.5f, 8f);
			((UIElement)val).AddChildUI((UIElement)(object)val3);
			RockText val4 = new RockText();
			val4.text = "__MODE_STATE__" + text;
			val4.fontSize = 1;
			val4.fontColor = Color.cyan;
			((UIElement)val4).anchor = (AnchorType)8;
			((UIElement)val4).anchorOffset = new Vector2(3.5f, 8.8f);
			((UIElement)val).AddChildUI((UIElement)(object)val4);
			RockLever val5 = new RockLever();
			((UIElement)val5).anchor = (AnchorType)8;
			((UIElement)val5).anchorOffset = new Vector2(3.5f, 7.2f);
			val5.leverToggledAction = OnModeLever;
			((UIElement)val).AddChildUI((UIElement)(object)val5);
			RockText val6 = new RockText();
			val6.text = "Slices Per Structure";
			val6.fontSize = 1;
			val6.fontColor = Color.white;
			((UIElement)val6).anchor = (AnchorType)8;
			((UIElement)val6).anchorOffset = new Vector2(-3.5f, 5f);
			((UIElement)val).AddChildUI((UIElement)(object)val6);
			RockText val7 = new RockText();
			val7.text = "__CHUNKS_VALUE__" + text3;
			val7.fontSize = 1;
			val7.fontColor = Color.yellow;
			((UIElement)val7).anchor = (AnchorType)8;
			((UIElement)val7).anchorOffset = new Vector2(3.5f, 5.8f);
			((UIElement)val).AddChildUI((UIElement)(object)val7);
			RockSlider val8 = new RockSlider();
			val8.useSteps = true;
			val8.stepCount = 10;
			((UIElement)val8).anchor = (AnchorType)8;
			((UIElement)val8).anchorOffset = new Vector2(0f, 4.2f);
			val8.stepReachedAction = OnChunksSlider;
			((UIElement)val).AddChildUI((UIElement)(object)val8);
			RockText val9 = new RockText();
			val9.text = "Chunk Style";
			val9.fontSize = 1;
			val9.fontColor = Color.white;
			((UIElement)val9).anchor = (AnchorType)8;
			((UIElement)val9).anchorOffset = new Vector2(-3.5f, 2f);
			((UIElement)val).AddChildUI((UIElement)(object)val9);
			RockText val10 = new RockText();
			val10.text = "__STYLE_STATE__" + text2;
			val10.fontSize = 1;
			val10.fontColor = Color.cyan;
			((UIElement)val10).anchor = (AnchorType)8;
			((UIElement)val10).anchorOffset = new Vector2(3.5f, 2.8f);
			((UIElement)val).AddChildUI((UIElement)(object)val10);
			RockLever val11 = new RockLever();
			((UIElement)val11).anchor = (AnchorType)8;
			((UIElement)val11).anchorOffset = new Vector2(3.5f, 1.2f);
			val11.leverToggledAction = OnStyleLever;
			((UIElement)val).AddChildUI((UIElement)(object)val11);
			RockText val12 = new RockText();
			val12.text = "Rock Cam Visibility";
			val12.fontSize = 1;
			val12.fontColor = Color.white;
			((UIElement)val12).anchor = (AnchorType)8;
			((UIElement)val12).anchorOffset = new Vector2(-3.5f, -1f);
			((UIElement)val).AddChildUI((UIElement)(object)val12);
			RockText val13 = new RockText();
			val13.text = "__ROCKCAM_STATE__" + text4;
			val13.fontSize = 1;
			val13.fontColor = Color.cyan;
			((UIElement)val13).anchor = (AnchorType)8;
			((UIElement)val13).anchorOffset = new Vector2(3.5f, -0.2f);
			((UIElement)val).AddChildUI((UIElement)(object)val13);
			RockLever val14 = new RockLever();
			((UIElement)val14).anchor = (AnchorType)8;
			((UIElement)val14).anchorOffset = new Vector2(3.5f, -1.8f);
			val14.leverToggledAction = OnRockCamLever;
			((UIElement)val).AddChildUI((UIElement)(object)val14);
			RockText val15 = new RockText();
			val15.text = "Chunk Size";
			val15.fontSize = 1;
			val15.fontColor = Color.white;
			((UIElement)val15).anchor = (AnchorType)8;
			((UIElement)val15).anchorOffset = new Vector2(-3.5f, -4f);
			((UIElement)val).AddChildUI((UIElement)(object)val15);
			RockText val16 = new RockText();
			val16.text = "__CHUNKSIZE_VALUE__" + text5;
			val16.fontSize = 1;
			val16.fontColor = Color.yellow;
			((UIElement)val16).anchor = (AnchorType)8;
			((UIElement)val16).anchorOffset = new Vector2(3.5f, -3.2f);
			((UIElement)val).AddChildUI((UIElement)(object)val16);
			RockSlider val17 = new RockSlider();
			val17.useSteps = true;
			val17.stepCount = 10;
			((UIElement)val17).anchor = (AnchorType)8;
			((UIElement)val17).anchorOffset = new Vector2(0f, -4.8f);
			val17.stepReachedAction = OnChunkSizeSlider;
			((UIElement)val).AddChildUI((UIElement)(object)val17);
			if (!value)
			{
				RockText val18 = new RockText();
				val18.text = "Time Till Despawn";
				val18.fontSize = 1;
				val18.fontColor = Color.white;
				((UIElement)val18).anchor = (AnchorType)8;
				((UIElement)val18).anchorOffset = new Vector2(-3.5f, -7f);
				((UIElement)val).AddChildUI((UIElement)(object)val18);
				RockText val19 = new RockText();
				val19.text = "__TIMEDESPAWN_VALUE__" + text6;
				val19.fontSize = 1;
				val19.fontColor = Color.yellow;
				((UIElement)val19).anchor = (AnchorType)8;
				((UIElement)val19).anchorOffset = new Vector2(3.5f, -6.2f);
				((UIElement)val).AddChildUI((UIElement)(object)val19);
				RockSlider val20 = new RockSlider();
				val20.useSteps = false;
				((UIElement)val20).anchor = (AnchorType)8;
				((UIElement)val20).anchorOffset = new Vector2(0f, -7.8f);
				val20.valueChangedAction = OnTimeDespawnValue;
				((UIElement)val).AddChildUI((UIElement)(object)val20);
			}
			_panel = RockUI.CreateFinalisedUI((UIElement)(object)val, false);
			Main.Logger.Msg("Settings panel built.");
			ResolveTMPRefs();
			ResolveControlRefs();
			SetText(_modeTmp, text);
			SetText(_styleTmp, text2);
			SetText(_chunksTmp, text3);
			SetText(_rockTmp, text4);
			SetText(_sizeTmp, text5);
			SetText(_timeTmp, text6);
			BuildLimitPanel();
			MelonCoroutines.Start(SyncControlStatesDeferred());
			PositionPanel();
		}

		private static void BuildLimitPanel()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0092: 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_009e: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_011c: Expected O, but got Unknown
			string text = Preferences.MaxConcurrentDebris.Value.ToString();
			RockPanel val = new RockPanel
			{
				size = new Vector2(10f, 6f)
			};
			RockText val2 = new RockText();
			val2.text = "Chunk Limit";
			val2.fontSize = 1;
			val2.fontColor = Color.white;
			((UIElement)val2).anchor = (AnchorType)8;
			((UIElement)val2).anchorOffset = new Vector2(0f, 1.8f);
			((UIElement)val).AddChildUI((UIElement)(object)val2);
			RockText val3 = new RockText();
			val3.text = "__CHUNKLIMIT_VALUE__" + text;
			val3.fontSize = 1;
			val3.fontColor = Color.yellow;
			((UIElement)val3).anchor = (AnchorType)8;
			((UIElement)val3).anchorOffset = new Vector2(0f, 0.1f);
			((UIElement)val).AddChildUI((UIElement)(object)val3);
			RockSlider val4 = new RockSlider();
			val4.useSteps = false;
			((UIElement)val4).anchor = (AnchorType)8;
			((UIElement)val4).anchorOffset = new Vector2(0f, -1.6f);
			val4.valueChangedAction = OnChunkLimitValue;
			((UIElement)val).AddChildUI((UIElement)(object)val4);
			_limitPanel = RockUI.CreateFinalisedUI((UIElement)val, false);
			Il2CppArrayBase<TextMeshPro> val5 = (((Object)(object)_limitPanel != (Object)null) ? _limitPanel.GetComponentsInChildren<TextMeshPro>(true) : null);
			if (val5 != null)
			{
				foreach (TextMeshPro item in val5)
				{
					if (!((Object)(object)item == (Object)null))
					{
						((TMP_Text)item).enableWordWrapping = false;
						((TMP_Text)item).overflowMode = (TextOverflowModes)0;
						if ((((TMP_Text)item).text ?? string.Empty).StartsWith("__CHUNKLIMIT_VALUE__"))
						{
							_limitTmp = item;
						}
					}
				}
			}
			if ((Object)(object)_limitTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find chunk-limit-value TMP.");
			}
			SetText(_limitTmp, text);
			int value = (((Object)(object)_limitPanel != (Object)null) ? _limitPanel.GetComponentsInChildren<Renderer>(true).Length : 0);
			Main.Logger.Msg($"Limit panel built: created={(Object)(object)_limitPanel != (Object)null}, tmp={(Object)(object)_limitTmp != (Object)null}, renderers={value}, value={text}.");
		}

		private static void ResolveTMPRefs()
		{
			if ((Object)(object)_panel == (Object)null)
			{
				return;
			}
			Il2CppArrayBase<TextMeshPro> componentsInChildren = _panel.GetComponentsInChildren<TextMeshPro>(true);
			if (componentsInChildren == null)
			{
				return;
			}
			foreach (TextMeshPro item in componentsInChildren)
			{
				if (!((Object)(object)item == (Object)null))
				{
					((TMP_Text)item).enableWordWrapping = false;
					((TMP_Text)item).overflowMode = (TextOverflowModes)0;
					string text = ((TMP_Text)item).text ?? string.Empty;
					if (text.StartsWith("__MODE_STATE__"))
					{
						_modeTmp = item;
					}
					else if (text.StartsWith("__STYLE_STATE__"))
					{
						_styleTmp = item;
					}
					else if (text.StartsWith("__CHUNKS_VALUE__"))
					{
						_chunksTmp = item;
					}
					else if (text.StartsWith("__ROCKCAM_STATE__"))
					{
						_rockTmp = item;
					}
					else if (text.StartsWith("__CHUNKSIZE_VALUE__"))
					{
						_sizeTmp = item;
					}
					else if (text.StartsWith("__TIMEDESPAWN_VALUE__"))
					{
						_timeTmp = item;
					}
				}
			}
			if ((Object)(object)_modeTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find mode-state TMP.");
			}
			if ((Object)(object)_styleTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find style-state TMP.");
			}
			if ((Object)(object)_chunksTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find chunks-value TMP.");
			}
			if ((Object)(object)_rockTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find rock-cam-state TMP.");
			}
			if ((Object)(object)_sizeTmp == (Object)null)
			{
				Main.Logger.Warning("Could not find chunk-size-value TMP.");
			}
		}

		private static void ResolveControlRefs()
		{
			if ((Object)(object)_panel == (Object)null)
			{
				return;
			}
			try
			{
				Il2CppArrayBase<InteractionLever> componentsInChildren = _panel.GetComponentsInChildren<InteractionLever>(true);
				_styleLever = ((componentsInChildren != null && componentsInChildren.Length > 1) ? componentsInChildren[1] : null);
				Preferences.Log($"ResolveControlRefs: styleLever={(Object)(object)_styleLever != (Object)null}.");
			}
			catch (Exception ex)
			{
				Main.Logger.Warning("ResolveControlRefs failed: " + ex.Message);
			}
		}

		private static bool EffectiveMinecraft()
		{
			if (!Preferences.ChunkStyleMinecraft.Value)
			{
				return Preferences.ChunksPerBreak.Value <= 1;
			}
			return true;
		}

		private static void RefreshStyleDisplay()
		{
			bool flag = EffectiveMinecraft();
			SetText(_styleTmp, flag ? "Minecraft" : "Real slices");
			MoveStyleLever(flag ? 1 : 0);
		}

		private static void MoveStyleLever(int step)
		{
			if (!((Object)(object)_styleLever == (Object)null) && step != _lastStyleStep)
			{
				_lastStyleStep = step;
				MelonCoroutines.Start(FlipStyleLeverDeferred(step));
			}
		}

		private static IEnumerator FlipStyleLeverDeferred(int step)
		{
			int token = ++_styleSyncToken;
			_suppressStyle = true;
			SetStepSafe((InteractionNumericalBase)(object)_styleLever, step);
			for (int i = 0; i < 30; i++)
			{
				yield return null;
				if (_styleSyncToken != token)
				{
					yield break;
				}
			}
			if (_styleSyncToken == token)
			{
				_suppressStyle = false;
			}
		}

		private static IEnumerator RebuildInPlace()
		{
			yield return null;
			if (!((Object)(object)_panel == (Object)null))
			{
				Vector3 position = _panel.transform.position;
				Quaternion rotation = _panel.transform.rotation;
				Close();
				Open();
				if ((Object)(object)_panel != (Object)null)
				{
					_panel.transform.position = position;
					_panel.transform.rotation = rotation;
					PositionLimitPanel();
				}
			}
		}

		private static void PositionPanel()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				Vector3 val = ((Component)main).transform.forward;
				val.y = 0f;
				val = ((((Vector3)(ref val)).sqrMagnitude < 0.001f) ? Vector3.forward : ((Vector3)(ref val)).normalized);
				Vector3 position = ((Component)main).transform.position + val * 3f;
				position.y -= 0.3f;
				_panel.transform.position = position;
				_panel.transform.rotation = Quaternion.LookRotation(val, Vector3.up);
				PositionLimitPanel();
			}
		}

		private static void PositionLimitPanel()
		{
			//IL_0026: 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)
			//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_0062: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_limitPanel == (Object)null || (Object)(object)_panel == (Object)null)
			{
				return;
			}
			try
			{
				Vector3 right = _panel.transform.right;
				float num = HalfWidthAlong(_panel, right);
				float num2 = HalfWidthAlong(_limitPanel, right);
				float num3 = num + 0.04f + num2;
				_limitPanel.transform.position = _panel.transform.position + right * num3;
				_limitPanel.transform.rotation = _panel.transform.rotation * Quaternion.Euler(0f, 20f, 0f);
				Main.Logger.Msg($"LimitPos: mainHalf={num:0.000} limitHalf={num2:0.000} offset={num3:0.000} lossyScale={_panel.transform.lossyScale.x:0.000} limitPos={_limitPanel.transform.position}");
			}
			catch (Exception ex)
			{
				Main.Logger.Warning("PositionLimitPanel failed: " + ex.Message);
			}
		}

		private static float HalfWidthAlong(GameObject go, Vector3 axis)
		{
			//IL_001f: 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_004e: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			Il2CppArrayBase<Renderer> componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			if (componentsInChildren == null || componentsInChildren.Length == 0)
			{
				return 0f;
			}
			Vector3 position = go.transform.position;
			float num = 0f;
			foreach (Renderer item in componentsInChildren)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Bounds bounds = item.bounds;
				Vector3 center = ((Bounds)(ref bounds)).center;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				for (int i = 0; i < 8; i++)
				{
					float num2 = Mathf.Abs(Vector3.Dot(center + new Vector3(((i & 1) == 0) ? (0f - extents.x) : extents.x, ((i & 2) == 0) ? (0f - extents.y) : extents.y, ((i & 4) == 0) ? (0f - extents.z) : extents.z) - position, axis));
					if (num2 > num)
					{
						num = num2;
					}
				}
			}
			return num;
		}

		private static void OnModeLever(int v)
		{
			if (!_suppress)
			{
				bool flag = v == 1;
				if (flag != Preferences.PersistUntilSceneChange.Value)
				{
					Preferences.PersistUntilSceneChange.Value = flag;
					SetText(_modeTmp, flag ? "Chaos" : "Default");
					MelonPreferences.Save();
					MelonCoroutines.Start(RebuildInPlace());
				}
			}
		}

		private static void OnChunksSlider(int step)
		{
			if (!_suppress)
			{
				int value = step + 1;
				Preferences.ChunksPerBreak.Value = value;
				SetText(_chunksTmp, value.ToString());
				RefreshStyleDisplay();
				MelonPreferences.Save();
				MelonCoroutines.Start(ChunkCache.PrewarmCurrent());
			}
		}

		private static void OnStyleLever(int v)
		{
			if (!_suppress && !_suppressStyle)
			{
				bool value = v == 1;
				Preferences.ChunkStyleMinecraft.Value = value;
				_lastStyleStep = v;
				RefreshStyleDisplay();
				MelonPreferences.Save();
				MelonCoroutines.Start(ChunkCache.PrewarmCurrent());
			}
		}

		private static void OnRockCamLever(int v)
		{
			if (!_suppress)
			{
				Preferences.RockCamVisibility.Value = v == 1;
				SetText(_rockTmp, (v == 1) ? "True" : "False");
				DebrisLayers.EnsureCamerasSeeDebris();
				MelonPreferences.Save();
			}
		}

		private static void OnChunkSizeSlider(int step)
		{
			if (!_suppress)
			{
				int value = step + 1;
				Preferences.ChunkSize.Value = value;
				SetText(_sizeTmp, value.ToString());
				MelonPreferences.Save();
			}
		}

		private static void OnTimeDespawnValue(float v)
		{
			if (!_suppress)
			{
				int num = Mathf.Clamp(Mathf.RoundToInt(1f + v * 19f), 1, 20);
				Preferences.ChunkLifetime.Value = num;
				SetText(_timeTmp, num.ToString());
				if (num != _lastDespawn)
				{
					_lastDespawn = num;
					MelonPreferences.Save();
				}
			}
		}

		private static void OnChunkLimitValue(float v)
		{
			if (!_suppress)
			{
				int num = Mathf.Clamp(Mathf.RoundToInt(1f + v * 499f), 1, 500);
				Preferences.MaxConcurrentDebris.Value = num;
				SetText(_limitTmp, num.ToString());
				if (num != _lastLimit)
				{
					_lastLimit = num;
					MelonPreferences.Save();
				}
			}
		}

		public static IEnumerator SyncControlStatesDeferred()
		{
			for (int i = 0; i < 15; i++)
			{
				yield return null;
			}
			if ((Object)(object)_panel == (Object)null)
			{
				_suppress = false;
				yield break;
			}
			SyncControlStates();
			ResolveControlRefs();
			RefreshStyleDisplay();
			_suppress = false;
		}

		private static void SyncControlStates()
		{
			try
			{
				Il2CppArrayBase<InteractionLever> componentsInChildren = _panel.GetComponentsInChildren<InteractionLever>(true);
				if (componentsInChildren != null)
				{
					if (componentsInChildren.Length > 0)
					{
						SetStepSafe((InteractionNumericalBase)(object)componentsInChildren[0], Preferences.PersistUntilSceneChange.Value ? 1 : 0);
					}
					if (componentsInChildren.Length > 2)
					{
						SetStepSafe((InteractionNumericalBase)(object)componentsInChildren[2], Preferences.RockCamVisibility.Value ? 1 : 0);
					}
				}
				Il2CppArrayBase<InteractionSlider> componentsInChildren2 = _panel.GetComponentsInChildren<InteractionSlider>(true);
				if (componentsInChildren2 != null)
				{
					if (componentsInChildren2.Length > 0)
					{
						SetStepSafe((InteractionNumericalBase)(object)componentsInChildren2[0], Mathf.Clamp(Preferences.ChunksPerBreak.Value - 1, 0, 9));
					}
					if (componentsInChildren2.Length > 1)
					{
						SetStepSafe((InteractionNumericalBase)(object)componentsInChildren2[1], Mathf.Clamp(Preferences.ChunkSize.Value - 1, 0, 9));
					}
				}
				int value = componentsInChildren?.Length ?? 0;
				int value2 = componentsInChildren2?.Length ?? 0;
				Preferences.Log($"Synced {value} levers / {value2} sliders to saved settings.");
			}
			catch (Exception ex)
			{
				Main.Logger.Warning("SyncControlStates failed: " + ex.Message);
			}
		}

		private static void SetStepSafe(InteractionNumericalBase ctrl, int step)
		{
			if ((Object)(object)ctrl == (Object)null)
			{
				return;
			}
			try
			{
				ctrl.SetStep(step, false, false);
			}
			catch (Exception ex)
			{
				Main.Logger.Warning("SetStep failed: " + ex.Message);
			}
		}

		private static void SetText(TextMeshPro tmp, string s)
		{
			if ((Object)(object)tmp == (Object)null)
			{
				return;
			}
			try
			{
				((TMP_Text)tmp).text = s;
			}
			catch (Exception ex)
			{
				Main.Logger.Error("SetText failed: " + ex.Message);
			}
		}
	}
	[RegisterTypeInIl2Cpp]
	public class DebrisChunk : MonoBehaviour
	{
		private static readonly LinkedList<DebrisChunk> Live = new LinkedList<DebrisChunk>();

		private LinkedListNode<DebrisChunk> _node;

		private float _age;

		private float _lifetime;

		private bool _dying;

		private float _initialScaleMax = 1f;

		private const float FadeDuration = 0.6f;

		private float _fadeAge;

		private bool _useAlphaFade;

		private Material _fadeMat;

		private string _fadeProp;

		private Color _startColor;

		public DebrisChunk(IntPtr ptr)
			: base(ptr)
		{
		}

		public void Init(float lifetime)
		{
			_lifetime = lifetime;
			_node = Live.AddLast(this);
			EnforceCap();
		}

		private static void EnforceCap()
		{
			int value = Preferences.MaxConcurrentDebris.Value;
			while (Live.First != null && (Object)(object)Live.First.Value == (Object)null)
			{
				Live.RemoveFirst();
			}
			while (Live.Count > value)
			{
				DebrisChunk debrisChunk = Live.First?.Value;
				if ((Object)(object)debrisChunk == (Object)null)
				{
					Live.RemoveFirst();
				}
				else
				{
					debrisChunk.Kill();
				}
			}
		}

		private void Update()
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if (Preferences.PersistUntilSceneChange.Value && !_dying)
			{
				return;
			}
			_age += Time.deltaTime;
			if (!_dying && _age >= _lifetime)
			{
				BeginFade();
			}
			if (!_dying)
			{
				return;
			}
			_fadeAge += Time.deltaTime;
			if (_useAlphaFade)
			{
				float num = _fadeAge / 0.6f;
				Color startColor = _startColor;
				startColor.a = Mathf.Lerp(_startColor.a, 0f, num);
				_fadeMat.SetColor(_fadeProp, startColor);
				if (num >= 1f)
				{
					Kill();
				}
			}
			else
			{
				Vector3 val = ((Component)this).transform.localScale - Vector3.one * (Time.deltaTime / 0.5f) * _initialScaleMax;
				if (Mathf.Max(val.x, Mathf.Max(val.y, val.z)) <= 0f)
				{
					Kill();
				}
				else
				{
					((Component)this).transform.localScale = val;
				}
			}
		}

		private void BeginFade()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			_dying = true;
			_fadeAge = 0f;
			MeshRenderer component = ((Component)this).GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				Material material = ((Renderer)component).material;
				string text = null;
				if (material.HasProperty("_BaseColor"))
				{
					text = "_BaseColor";
				}
				else if (material.HasProperty("_Color"))
				{
					text = "_Color";
				}
				if (text != null)
				{
					try
					{
						material.SetFloat("_Surface", 1f);
						material.SetFloat("_Mode", 3f);
						material.SetInt("_SrcBlend", 5);
						material.SetInt("_DstBlend", 10);
						material.SetInt("_ZWrite", 0);
						material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
						material.EnableKeyword("_ALPHABLEND_ON");
						material.DisableKeyword("_ALPHATEST_ON");
						material.renderQueue = 3000;
					}
					catch (Exception ex)
					{
						Main.Logger.Warning("Alpha-fade shader setup failed, falling back to shrink: " + ex.Message);
						goto IL_0111;
					}
					_useAlphaFade = true;
					_fadeMat = material;
					_fadeProp = text;
					_startColor = material.GetColor(text);
					return;
				}
			}
			goto IL_0111;
			IL_0111:
			_useAlphaFade = false;
			Vector3 localScale = ((Component)this).transform.localScale;
			_initialScaleMax = Mathf.Max(localScale.x, Mathf.Max(localScale.y, localScale.z));
		}

		public void Kill()
		{
			if (_node != null)
			{
				Live.Remove(_node);
				_node = null;
			}
			if ((Object)(object)this != (Object)null && (Object)(object)((Component)this).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void OnDestroy()
		{
			if (_node != null)
			{
				Live.Remove(_node);
				_node = null;
			}
		}
	}
	public static class DebrisLayers
	{
		public static int DebrisLayer = -1;

		private static readonly string[] CollideNames = new string[4] { "Floor", "CombatFloor", "Environment", "PedestalFloor" };

		private static bool _loggedCams;

		public static void DumpLayers()
		{
			for (int i = 0; i < 32; i++)
			{
				string value = LayerMask.LayerToName(i);
				if (!string.IsNullOrEmpty(value))
				{
					Preferences.Log($"Layer {i} = '{value}'");
				}
			}
		}

		public static void Setup()
		{
			DebrisLayer = FindUnusedLayer();
			if (DebrisLayer < 0)
			{
				DebrisLayer = 26;
			}
			for (int i = 0; i < 32; i++)
			{
				Physics.IgnoreLayerCollision(DebrisLayer, i, true);
			}
			string[] collideNames = CollideNames;
			for (int j = 0; j < collideNames.Length; j++)
			{
				int num = LayerMask.NameToLayer(collideNames[j]);
				if (num >= 0)
				{
					Physics.IgnoreLayerCollision(DebrisLayer, num, false);
				}
			}
			Physics.IgnoreLayerCollision(DebrisLayer, DebrisLayer, false);
			EnsureCamerasSeeDebris();
			Preferences.Log($"Debris layer = {DebrisLayer}");
		}

		public static void EnsureCamerasSeeDebris()
		{
			if (DebrisLayer < 0)
			{
				return;
			}
			int num = 1 << DebrisLayer;
			bool value = Preferences.RockCamVisibility.Value;
			Il2CppReferenceArray<Camera> allCameras = Camera.allCameras;
			if (allCameras == null)
			{
				return;
			}
			foreach (Camera item in (Il2CppArrayBase<Camera>)(object)allCameras)
			{
				if (!((Object)(object)item == (Object)null))
				{
					string text = ((Object)item).name ?? string.Empty;
					bool flag = text == "Headset" || text.ToLowerInvariant().Contains("headset");
					if (!_loggedCams)
					{
						Preferences.Log($"Camera '{((Object)item).name}' layer={((Component)item).gameObject.layer} headset={flag} show={flag || value}");
					}
					if (flag || value)
					{
						item.cullingMask |= num;
					}
					else
					{
						item.cullingMask &= ~num;
					}
				}
			}
			_loggedCams = true;
		}

		private static int FindUnusedLayer()
		{
			for (int num = 31; num >= 8; num--)
			{
				if (string.IsNullOrEmpty(LayerMask.LayerToName(num)))
				{
					return num;
				}
			}
			return -1;
		}
	}
	public static class DebrisSpawner
	{
		public static void Spawn(Transform structure)
		{
			//IL_0056: 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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				DebrisLayers.EnsureCamerasSeeDebris();
				MeshRenderer componentInChildren = ((Component)structure).GetComponentInChildren<MeshRenderer>();
				MeshFilter componentInChildren2 = ((Component)structure).GetComponentInChildren<MeshFilter>();
				if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren2 == (Object)null || (Object)(object)componentInChildren2.sharedMesh == (Object)null)
				{
					Preferences.Log("No renderer/mesh on structure; skipping debris.");
					return;
				}
				Transform transform = ((Component)componentInChildren2).transform;
				Material sharedMaterial = ((Renderer)componentInChildren).sharedMaterial;
				Bounds bounds = componentInChildren2.sharedMesh.bounds;
				ChunkData[] chunks;
				ChunkData[] array = (ChunkCache.TryGet(componentInChildren2.sharedMesh, out chunks) ? chunks : ChunkCache.Build(componentInChildren2.sharedMesh, bounds));
				ChunkData[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					SpawnOne(array2[i], transform, sharedMaterial);
				}
				Preferences.Log($"Spawned {array.Length} debris chunks.");
			}
			catch (Exception value)
			{
				Main.Logger.Error($"Spawn failed (gameplay unaffected): {value}");
			}
		}

		private static void SpawnOne(ChunkData c, Transform pivot, Material mat)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			//IL_0035: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_009d: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_0100: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			if (DebrisLayers.DebrisLayer >= 0)
			{
				GameObject val = new GameObject("CrumbleChunk")
				{
					layer = DebrisLayers.DebrisLayer
				};
				val.transform.position = pivot.TransformPoint(c.LocalOffset);
				val.transform.rotation = pivot.rotation * Quaternion.Euler((float)Random.Range(0, 360), (float)Random.Range(0, 360), (float)Random.Range(0, 360));
				float num = (float)Preferences.ChunkSize.Value / 5f;
				val.transform.localScale = pivot.lossyScale * num;
				val.AddComponent<MeshFilter>().sharedMesh = c.Mesh;
				MeshRenderer val2 = val.AddComponent<MeshRenderer>();
				if ((Object)(object)mat != (Object)null)
				{
					((Renderer)val2).sharedMaterial = mat;
				}
				MeshCollider obj = val.AddComponent<MeshCollider>();
				obj.sharedMesh = c.Mesh;
				obj.convex = true;
				Rigidbody obj2 = val.AddComponent<Rigidbody>();
				obj2.useGravity = true;
				obj2.angularDrag = Preferences.AngularDrag.Value;
				Vector3 lossyScale = pivot.lossyScale;
				Bounds bounds = c.Mesh.bounds;
				float x = ((Bounds)(ref bounds)).size.x;
				bounds = c.Mesh.bounds;
				float num2 = x * ((Bounds)(ref bounds)).size.y;
				bounds = c.Mesh.bounds;
				float num3 = num2 * ((Bounds)(ref bounds)).size.z * Mathf.Abs(lossyScale.x * lossyScale.y * lossyScale.z) * num * num * num;
				obj2.mass = Mathf.Max(0.05f, num3 * Preferences.MassScale.Value);
				val.AddComponent<DebrisChunk>().Init(Preferences.ChunkLifetime.Value);
			}
		}
	}
	public class Main : MelonMod
	{
		public static Instance Logger;

		private bool _layersReady;

		private bool _comboWasDown;

		private int _camFrame;

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			try
			{
				Preferences.Init();
				try
				{
					ClassInjector.RegisterTypeInIl2Cpp<DebrisChunk>();
				}
				catch (Exception ex)
				{
					Logger.Warning("DebrisChunk register: " + ex.Message);
				}
				((MelonBase)this).HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
				Logger.Msg("Initialized and patched Structure.Kill.");
				Actions.onMapInitialized += OnMapInitialized;
			}
			catch (Exception value)
			{
				Logger.Error($"Init failed: {value}");
			}
		}

		private void OnMapInitialized(string mapName)
		{
			try
			{
				CrumbleUI.Close();
				DebrisLayers.DumpLayers();
				if (!_layersReady)
				{
					DebrisLayers.Setup();
					_layersReady = true;
				}
				ChunkCache.Clear();
				MelonCoroutines.Start(ChunkCache.PreWarm());
			}
			catch (Exception value)
			{
				Logger.Error($"map-init failed: {value}");
			}
		}

		public override void OnUpdate()
		{
			try
			{
				if (++_camFrame >= 10)
				{
					_camFrame = 0;
					DebrisLayers.EnsureCamerasSeeDebris();
				}
				float trigger = LeftController.GetTrigger();
				float secondary = RightController.GetSecondary();
				bool flag = trigger > 0.5f && secondary > 0.5f;
				if (flag && !_comboWasDown)
				{
					string sceneName = Scene.GetSceneName();
					Logger.Msg("Menu combo pressed in scene '" + sceneName + "'.");
					if (sceneName == "Gym" || sceneName == "Park")
					{
						CrumbleUI.Toggle();
					}
					else
					{
						Logger.Msg("Settings menu only opens in Gym or Park (current: '" + sceneName + "').");
					}
				}
				_comboWasDown = flag;
			}
			catch (Exception value)
			{
				Logger.Error($"OnUpdate error: {value}");
			}
		}
	}
	public static class MeshReadback
	{
		public static bool TryMakeReadable(Mesh src, out Mesh readable)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			readable = null;
			GraphicsBuffer val = null;
			GraphicsBuffer val2 = null;
			try
			{
				if ((Object)(object)src == (Object)null)
				{
					return false;
				}
				if (!src.HasVertexAttribute((VertexAttribute)0))
				{
					return false;
				}
				if (src.vertexBufferCount < 1)
				{
					return false;
				}
				int vertexBufferStride = src.GetVertexBufferStride(0);
				int vertexAttributeOffset = src.GetVertexAttributeOffset((VertexAttribute)0);
				if (vertexBufferStride <= 0)
				{
					return false;
				}
				val = src.GetVertexBuffer(0);
				if (val == null)
				{
					return false;
				}
				int count = val.count;
				if (count == 0)
				{
					return false;
				}
				byte[] array = ReadBytes(val, count * vertexBufferStride);
				if (array == null)
				{
					return false;
				}
				Vector3[] array2 = (Vector3[])(object)new Vector3[count];
				for (int i = 0; i < count; i++)
				{
					int num = i * vertexBufferStride + vertexAttributeOffset;
					array2[i] = new Vector3(BitConverter.ToSingle(array, num), BitConverter.ToSingle(array, num + 4), BitConverter.ToSingle(array, num + 8));
				}
				val2 = src.GetIndexBuffer();
				if (val2 == null)
				{
					return false;
				}
				int count2 = val2.count;
				if (count2 < 3)
				{
					return false;
				}
				int[] array3 = new int[count2];
				if ((int)src.indexFormat == 0)
				{
					byte[] array4 = ReadBytes(val2, count2 * 2);
					if (array4 == null)
					{
						return false;
					}
					for (int j = 0; j < count2; j++)
					{
						int num2 = BitConverter.ToUInt16(array4, j * 2);
						if (num2 >= count)
						{
							return false;
						}
						array3[j] = num2;
					}
				}
				else
				{
					byte[] array5 = ReadBytes(val2, count2 * 4);
					if (array5 == null)
					{
						return false;
					}
					for (int k = 0; k < count2; k++)
					{
						uint num3 = BitConverter.ToUInt32(array5, k * 4);
						if (num3 >= (uint)count)
						{
							return false;
						}
						array3[k] = (int)num3;
					}
				}
				Mesh val3 = new Mesh();
				if (count > 65535)
				{
					val3.indexFormat = (IndexFormat)1;
				}
				val3.vertices = Il2CppStructArray<Vector3>.op_Implicit(array2);
				val3.triangles = Il2CppStructArray<int>.op_Implicit(array3);
				val3.RecalculateNormals();
				val3.RecalculateBounds();
				readable = val3;
				return true;
			}
			catch
			{
				readable = null;
				return false;
			}
			finally
			{
				if (val != null)
				{
					val.Dispose();
				}
				if (val2 != null)
				{
					val2.Dispose();
				}
			}
		}

		private static byte[] ReadBytes(GraphicsBuffer buf, int length)
		{
			if (length <= 0)
			{
				return null;
			}
			Il2CppStructArray<byte> val = new Il2CppStructArray<byte>((long)length);
			buf.GetData(((Il2CppObjectBase)val).Cast<Array>());
			byte[] array = new byte[length];
			for (int i = 0; i < length; i++)
			{
				array[i] = ((Il2CppArrayBase<byte>)(object)val)[i];
			}
			return array;
		}
	}
	public static class MeshSlicer
	{
		private struct Edge
		{
			public Vector3 a;

			public Vector3 b;
		}

		private struct Vec3Key
		{
			public float x;

			public float y;

			public float z;

			public Vec3Key(Vector3 v)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				x = Mathf.Round(v.x * 1000f) / 1000f;
				y = Mathf.Round(v.y * 1000f) / 1000f;
				z = Mathf.Round(v.z * 1000f) / 1000f;
			}

			public override bool Equals(object obj)
			{
				if (!(obj is Vec3Key vec3Key))
				{
					return false;
				}
				if (x == vec3Key.x && y == vec3Key.y)
				{
					return z == vec3Key.z;
				}
				return false;
			}

			public override int GetHashCode()
			{
				return x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() >> 2);
			}
		}

		private class SimpleMesh
		{
			public List<Vector3> vertices;

			public List<int> triangles;

			public Dictionary<Vec3Key, int> vertMap;

			public SimpleMesh()
			{
				vertices = new List<Vector3>();
				triangles = new List<int>();
				vertMap = new Dictionary<Vec3Key, int>();
			}

			public SimpleMesh(Mesh mesh)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				vertices = new List<Vector3>((IEnumerable<Vector3>)mesh.vertices);
				triangles = new List<int>((IEnumerable<int>)mesh.triangles);
				vertMap = new Dictionary<Vec3Key, int>();
				for (int i = 0; i < vertices.Count; i++)
				{
					Vec3Key key = new Vec3Key(vertices[i]);
					if (!vertMap.ContainsKey(key))
					{
						vertMap[key] = i;
					}
				}
			}

			public int AddVertex(Vector3 v)
			{
				//IL_0002: 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)
				Vec3Key key = new Vec3Key(v);
				if (vertMap.TryGetValue(key, out var value))
				{
					return value;
				}
				value = vertices.Count;
				vertices.Add(v);
				vertMap[key] = value;
				return value;
			}

			public void AddTriangle(Vector3 v0, Vector3 v1, Vector3 v2)
			{
				//IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references)
				int num = AddVertex(v0);
				int num2 = AddVertex(v1);
				int num3 = AddVertex(v2);
				if (num != num2 && num2 != num3 && num3 != num)
				{
					triangles.Add(num);
					triangles.Add(num2);
					triangles.Add(num3);
				}
			}
		}

		private static Bounds GetBounds(SimpleMesh m)
		{
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_003b: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0056: 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)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			if (m.vertices.Count == 0)
			{
				return new Bounds(Vector3.zero, Vector3.zero);
			}
			Vector3 val = m.vertices[0];
			Vector3 val2 = m.vertices[0];
			for (int i = 1; i < m.vertices.Count; i++)
			{
				val = Vector3.Min(val, m.vertices[i]);
				val2 = Vector3.Max(val2, m.vertices[i]);
			}
			return new Bounds((val + val2) * 0.5f, val2 - val);
		}

		private static float GetVolume(SimpleMesh m)
		{
			//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_0009: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = GetBounds(m);
			return ((Bounds)(ref bounds)).size.x * ((Bounds)(ref bounds)).size.y * ((Bounds)(ref bounds)).size.z;
		}

		private static Vector3 Intersect(Vector3 a, Vector3 b, float da, float db)
		{
			//IL_001e: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			float num = da - db;
			float num2 = ((num == 0f) ? 0.5f : (da / num));
			num2 = Mathf.Clamp01(num2);
			return a + (b - a) * num2;
		}

		private static void FillCap(SimpleMesh mesh, List<Edge> edges)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0022: 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_002c: 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_002f: 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)
			//IL_0039: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007c: 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)
			if (edges.Count == 0)
			{
				return;
			}
			Vector3 val = Vector3.zero;
			foreach (Edge edge in edges)
			{
				val += edge.a;
				val += edge.b;
			}
			val /= (float)(edges.Count * 2);
			foreach (Edge edge2 in edges)
			{
				mesh.AddTriangle(edge2.a, edge2.b, val);
			}
		}

		private static bool Split(SimpleMesh input, Vector3 planePoint, Vector3 planeNormal, out SimpleMesh posMesh, out SimpleMesh negMesh)
		{
			//IL_003a: 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_004c: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0110: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			posMesh = new SimpleMesh();
			negMesh = new SimpleMesh();
			List<Edge> list = new List<Edge>();
			List<Edge> list2 = new List<Edge>();
			List<Vector3> vertices = input.vertices;
			List<int> triangles = input.triangles;
			for (int i = 0; i < triangles.Count; i += 3)
			{
				Vector3 val = vertices[triangles[i]];
				Vector3 val2 = vertices[triangles[i + 1]];
				Vector3 val3 = vertices[triangles[i + 2]];
				float num = Vector3.Dot(val - planePoint, planeNormal);
				float num2 = Vector3.Dot(val2 - planePoint, planeNormal);
				float num3 = Vector3.Dot(val3 - planePoint, planeNormal);
				bool flag = num >= 0f;
				bool flag2 = num2 >= 0f;
				bool flag3 = num3 >= 0f;
				if (flag && flag2 && flag3)
				{
					posMesh.AddTriangle(val, val2, val3);
					continue;
				}
				if (!flag && !flag2 && !flag3)
				{
					negMesh.AddTriangle(val, val2, val3);
					continue;
				}
				Vector3 val4;
				Vector3 val5;
				Vector3 val6;
				float da;
				float db;
				float db2;
				bool flag4;
				if (flag != flag2 && flag != flag3)
				{
					val4 = val;
					val5 = val2;
					val6 = val3;
					da = num;
					db = num2;
					db2 = num3;
					flag4 = flag;
				}
				else if (flag2 != flag && flag2 != flag3)
				{
					val4 = val2;
					val5 = val3;
					val6 = val;
					da = num2;
					db = num3;
					db2 = num;
					flag4 = flag2;
				}
				else
				{
					val4 = val3;
					val5 = val;
					val6 = val2;
					da = num3;
					db = num;
					db2 = num2;
					flag4 = flag3;
				}
				Vector3 val7 = Intersect(val4, val5, da, db);
				Vector3 val8 = Intersect(val4, val6, da, db2);
				if (flag4)
				{
					posMesh.AddTriangle(val4, val7, val8);
					negMesh.AddTriangle(val5, val6, val7);
					negMesh.AddTriangle(val6, val8, val7);
					list.Add(new Edge
					{
						a = val8,
						b = val7
					});
					list2.Add(new Edge
					{
						a = val7,
						b = val8
					});
				}
				else
				{
					negMesh.AddTriangle(val4, val7, val8);
					posMesh.AddTriangle(val5, val6, val7);
					posMesh.AddTriangle(val6, val8, val7);
					list2.Add(new Edge
					{
						a = val8,
						b = val7
					});
					list.Add(new Edge
					{
						a = val7,
						b = val8
					});
				}
			}
			if (posMesh.triangles.Count == 0 || negMesh.triangles.Count == 0)
			{
				return false;
			}
			FillCap(posMesh, list);
			FillCap(negMesh, list2);
			return true;
		}

		private static ChunkData CreateChunkData(SimpleMesh m)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//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_004b: 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_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			Vector3 val = Vector3.zero;
			foreach (Vector3 vertex in m.vertices)
			{
				val += vertex;
			}
			if (m.vertices.Count > 0)
			{
				val /= (float)m.vertices.Count;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[m.vertices.Count];
			for (int i = 0; i < m.vertices.Count; i++)
			{
				array[i] = m.vertices[i] - val;
			}
			Mesh val2 = new Mesh
			{
				vertices = Il2CppStructArray<Vector3>.op_Implicit(array),
				triangles = Il2CppStructArray<int>.op_Implicit(m.triangles.ToArray())
			};
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			return new ChunkData(val2, val);
		}

		public static bool TrySlice(Mesh mesh, int count, float randomness, out ChunkData[] chunks)
		{
			//IL_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_005c: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_010f: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			chunks = null;
			try
			{
				if ((Object)(object)mesh == (Object)null || count < 2)
				{
					return false;
				}
				List<SimpleMesh> list = new List<SimpleMesh>();
				list.Add(new SimpleMesh(mesh));
				int num = 0;
				int num2 = count * 5;
				Vector3[] array = (Vector3[])(object)new Vector3[6]
				{
					Vector3.up,
					Vector3.down,
					Vector3.left,
					Vector3.right,
					Vector3.forward,
					Vector3.back
				};
				Vector3 planePoint = default(Vector3);
				while (list.Count < count && num < num2)
				{
					int num3 = -1;
					float num4 = -1f;
					for (int i = 0; i < list.Count; i++)
					{
						float volume = GetVolume(list[i]);
						if (volume > num4)
						{
							num4 = volume;
							num3 = i;
						}
					}
					if (num3 == -1)
					{
						break;
					}
					SimpleMesh simpleMesh = list[num3];
					Vector3 val = array[Random.Range(0, array.Length)];
					Vector3 onUnitSphere = Random.onUnitSphere;
					Vector3 val2 = Vector3.Lerp(val, onUnitSphere, randomness);
					Vector3 planeNormal = ((Vector3)(ref val2)).normalized;
					if (((Vector3)(ref planeNormal)).sqrMagnitude < 0.001f)
					{
						planeNormal = Vector3.up;
					}
					Bounds bounds = GetBounds(simpleMesh);
					((Vector3)(ref planePoint))..ctor(Random.Range(((Bounds)(ref bounds)).min.x, ((Bounds)(ref bounds)).max.x), Random.Range(((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).max.y), Random.Range(((Bounds)(ref bounds)).min.z, ((Bounds)(ref bounds)).max.z));
					if (Split(simpleMesh, planePoint, planeNormal, out var posMesh, out var negMesh))
					{
						list.RemoveAt(num3);
						list.Add(posMesh);
						list.Add(negMesh);
					}
					else
					{
						num++;
					}
				}
				if (list.Count < 2)
				{
					return false;
				}
				chunks = new ChunkData[list.Count];
				for (int j = 0; j < list.Count; j++)
				{
					chunks[j] = CreateChunkData(list[j]);
				}
				return true;
			}
			catch
			{
				chunks = null;
				return false;
			}
		}
	}
	public static class Preferences
	{
		private const string Dir = "UserData/Crumble/";

		private const string File = "config.cfg";

		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<bool> Enabled;

		public static MelonPreferences_Entry<int> ChunksPerBreak;

		public static MelonPreferences_Entry<bool> ChunkStyleMinecraft;

		public static MelonPreferences_Entry<float> ChunkLifetime;

		public static MelonPreferences_Entry<float> MassScale;

		public static MelonPreferences_Entry<float> AngularDrag;

		public static MelonPreferences_Entry<int> MaxConcurrentDebris;

		public static MelonPreferences_Entry<bool> PersistUntilSceneChange;

		public static MelonPreferences_Entry<float> SliceRandomness;

		public static MelonPreferences_Entry<bool> DebugLogging;

		public static MelonPreferences_Entry<bool> RockCamVisibility;

		public static MelonPreferences_Entry<int> ChunkSize;

		public static void Init()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			if (!Directory.Exists("UserData/Crumble/"))
			{
				Directory.CreateDirectory("UserData/Crumble/");
			}
			Category = MelonPreferences.CreateCategory("Crumble", "Settings");
			Category.SetFilePath(Path.Combine("UserData/Crumble/", "config.cfg"));
			Enabled = Category.CreateEntry<bool>("Enabled", true, "Enabled", "Toggle the whole mod on/off", false, false, (ValueValidator)null, (string)null);
			ChunksPerBreak = Category.CreateEntry<int>("ChunksPerBreak", 8, "Chunks Per Break", "Exact number of chunks spawned per destruction", false, false, (ValueValidator)new ValueRange<int>(1, 10), (string)null);
			ChunkStyleMinecraft = Category.CreateEntry<bool>("ChunkStyleMinecraft", false, "Chunk Style: Minecraft", "false = attempt real mesh slices, true = force box shards", false, false, (ValueValidator)null, (string)null);
			ChunkLifetime = Category.CreateEntry<float>("ChunkLifetime", 6f, "Chunk Lifetime (s)", "Seconds before a chunk despawns", false, false, (ValueValidator)new ValueRange<float>(0.5f, 60f), (string)null);
			MassScale = Category.CreateEntry<float>("MassScale", 1f, "Mass Scale", "Multiplier on chunk mass (scaled by size)", false, false, (ValueValidator)new ValueRange<float>(0.01f, 100f), (string)null);
			AngularDrag = Category.CreateEntry<float>("AngularDrag", 0.5f, "Angular Drag", "Higher = chunks stop spinning sooner", false, false, (ValueValidator)new ValueRange<float>(0f, 20f), (string)null);
			MaxConcurrentDebris = Category.CreateEntry<int>("MaxConcurrentDebris", 65, "Chunk Limit", "Hard cap on live chunks (VR safety). Applies in all modes, including Chaos", false, false, (ValueValidator)new ValueRange<int>(1, 500), (string)null);
			PersistUntilSceneChange = Category.CreateEntry<bool>("PersistUntilSceneChange", false, "Persist Until Scene Change", "If true, chunks never despawn on a timer and the concurrent cap is ignored; they clear only on map/scene change (VR perf risk if you spam destructions)", false, false, (ValueValidator)null, (string)null);
			SliceRandomness = Category.CreateEntry<float>("SliceRandomness", 0.5f, "Slice Randomness", "0 = uniform cuts, 1 = chaotic cuts", false, false, (ValueValidator)new ValueRange<float>(0f, 1f), (string)null);
			DebugLogging = Category.CreateEntry<bool>("DebugLogging", false, "Debug Logging", "Verbose Crumble logs", false, false, (ValueValidator)null, (string)null);
			RockCamVisibility = Category.CreateEntry<bool>("RockCamVisibility", true, "Rock Cam Visibility", "Show debris chunks in the in-game live/recording (Rock) camera", false, false, (ValueValidator)null, (string)null);
			ChunkSize = Category.CreateEntry<int>("ChunkSize", 5, "Chunk Size", "Chunk size multiplier (5 = normal)", false, false, (ValueValidator)new ValueRange<int>(1, 10), (string)null);
		}

		public static void Log(string msg)
		{
			if (DebugLogging != null && DebugLogging.Value)
			{
				Main.Logger.Msg(msg);
			}
		}
	}
	public static class ShardClusterBuilder
	{
		public static ChunkData[] Build(Bounds bounds, int count, float randomness)
		{
			//IL_0010: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_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_0089: 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_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			count = Mathf.Max(1, count);
			List<Bounds> list = new List<Bounds>(count) { bounds };
			while (list.Count < count)
			{
				int index = 0;
				float num = Volume(list[0]);
				for (int i = 1; i < list.Count; i++)
				{
					float num2 = Volume(list[i]);
					if (num2 > num)
					{
						num = num2;
						index = i;
					}
				}
				Bounds val = list[index];
				list.RemoveAt(index);
				Vector3 size = ((Bounds)(ref val)).size;
				float num3 = 1f + Random.Range(0f - randomness, randomness) * 0.4f;
				Bounds item;
				Bounds item2;
				if (size.x >= size.y && size.x >= size.z)
				{
					float num4 = ((Bounds)(ref val)).min.x + size.x * 0.5f * num3;
					num4 = Mathf.Clamp(num4, ((Bounds)(ref val)).min.x + size.x * 0.1f, ((Bounds)(ref val)).max.x - size.x * 0.1f);
					item = BoundsFromMinMax(((Bounds)(ref val)).min, new Vector3(num4, ((Bounds)(ref val)).max.y, ((Bounds)(ref val)).max.z));
					item2 = BoundsFromMinMax(new Vector3(num4, ((Bounds)(ref val)).min.y, ((Bounds)(ref val)).min.z), ((Bounds)(ref val)).max);
				}
				else if (size.y >= size.x && size.y >= size.z)
				{
					float num5 = ((Bounds)(ref val)).min.y + size.y * 0.5f * num3;
					num5 = Mathf.Clamp(num5, ((Bounds)(ref val)).min.y + size.y * 0.1f, ((Bounds)(ref val)).max.y - size.y * 0.1f);
					item = BoundsFromMinMax(((Bounds)(ref val)).min, new Vector3(((Bounds)(ref val)).max.x, num5, ((Bounds)(ref val)).max.z));
					item2 = BoundsFromMinMax(new Vector3(((Bounds)(ref val)).min.x, num5, ((Bounds)(ref val)).min.z), ((Bounds)(ref val)).max);
				}
				else
				{
					float num6 = ((Bounds)(ref val)).min.z + size.z * 0.5f * num3;
					num6 = Mathf.Clamp(num6, ((Bounds)(ref val)).min.z + size.z * 0.1f, ((Bounds)(ref val)).max.z - size.z * 0.1f);
					item = BoundsFromMinMax(((Bounds)(ref val)).min, new Vector3(((Bounds)(ref val)).max.x, ((Bounds)(ref val)).max.y, num6));
					item2 = BoundsFromMinMax(new Vector3(((Bounds)(ref val)).min.x, ((Bounds)(ref val)).min.y, num6), ((Bounds)(ref val)).max);
				}
				list.Add(item);
				list.Add(item2);
			}
			ChunkData[] array = new ChunkData[list.Count];
			for (int j = 0; j < list.Count; j++)
			{
				Bounds val2 = list[j];
				Mesh mesh = Box(((Bounds)(ref val2)).extents);
				int num7 = j;
				val2 = list[j];
				array[num7] = new ChunkData(mesh, ((Bounds)(ref val2)).center);
			}
			return array;
		}

		private static float Volume(Bounds b)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//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_000e: 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)
			V