Decompiled source of DarknessOfSouls v1.0.0

plugins/DarknessOfSouls.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items;
using Peak;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("Zorro.Core.Runtime")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 DarknessOfSouls
{
	internal class OrbItem : Item
	{
		public override bool CanUsePrimary()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)((Item)this).itemState == 1 && !VoidDirector.IsAwake)
			{
				return ((Item)this).CanUsePrimary();
			}
			return false;
		}

		public override bool CanUseSecondary()
		{
			return false;
		}
	}
	internal static class OrbBuilder
	{
		public const float CommuneSeconds = 2f;

		private static bool s_adopted;

		public static Texture2D Icon;

		public static Item Build()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_002a: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0189: 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_01a3: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: 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_024d: Expected O, but got Unknown
			VoidFx.BuildAssets();
			GameObject val = new GameObject("DarknessOfSouls");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)61;
			Transform transform = new GameObject("Visual").transform;
			transform.SetParent(val.transform, false);
			((Component)VoidFx.MeshObj("Orb", transform, VoidFx.Sphere, VoidFx.Black())).transform.localScale = Vector3.one * 0.16f;
			((Component)VoidFx.MeshObj("Band", transform, VoidFx.Sphere, VoidFx.Black())).transform.localScale = new Vector3(0.2f, 0.2f, 0.025f);
			val.AddComponent<SphereCollider>().radius = 0.09f;
			Transform transform2 = new GameObject("Hand_R").transform;
			transform2.SetParent(val.transform, false);
			transform2.localPosition = new Vector3(0.03f, -0.07f, 0f);
			Transform transform3 = new GameObject("Hand_L").transform;
			transform3.SetParent(val.transform, false);
			transform3.localPosition = new Vector3(-0.03f, -0.07f, 0f);
			PhotonView obj = val.AddComponent<PhotonView>();
			ItemPhysicsSyncer item = val.AddComponent<ItemPhysicsSyncer>();
			obj.ObservedComponents = new List<Component> { (Component)(object)item };
			obj.Synchronization = (ViewSynchronization)3;
			val.AddComponent<ItemCooking>().disableCooking = true;
			OrbItem orbItem = val.AddComponent<OrbItem>();
			((Item)orbItem).mass = 0.6f;
			((Item)orbItem).carryWeight = 1;
			((Item)orbItem).totalUses = -1;
			((Item)orbItem).rightHandOnly = false;
			((Item)orbItem).defaultPos = new Vector3(0f, -0.15f, 0.55f);
			((Item)orbItem).defaultForward = new Vector3(0f, 0f, 1f);
			((Item)orbItem).usingTimePrimary = 2f;
			((Item)orbItem).showUseProgress = true;
			((Item)orbItem).itemTags = (ItemTags)2048;
			Icon = MakeFallbackIcon();
			((Item)orbItem).UIData = new ItemUIData
			{
				itemName = "Darkness Of Souls",
				icon = Icon,
				mainInteractPrompt = "COMMUNE",
				secondaryInteractPrompt = "CHANGE DARKNESS",
				scrollInteractPrompt = "HOLE SIZE",
				hasScrollingInteract = true,
				hasMainInteract = true,
				hasSecondInteract = true,
				canDrop = true,
				canPocket = true,
				canBackpack = true,
				canThrow = true,
				iconScaleOffset = 1f
			};
			((Item)orbItem).addtlRenderers = val.GetComponentsInChildren<Renderer>(true);
			val.AddComponent<OrbCommune>();
			return (Item)(object)orbItem;
		}

		public static void TryAdopt()
		{
			if (s_adopted)
			{
				return;
			}
			ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
			if ((Object)(object)instance == (Object)null || instance.itemLookup == null || instance.itemLookup.Count < 10)
			{
				return;
			}
			s_adopted = true;
			Item val = null;
			foreach (Item value in instance.itemLookup.Values)
			{
				if ((Object)(object)value != (Object)null && (Object)(object)((Component)value).GetComponent<ScoutsHonor>() != (Object)null)
				{
					val = value;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				foreach (Item value2 in instance.itemLookup.Values)
				{
					if ((Object)(object)value2 != (Object)null && ((Object)((Component)value2).gameObject).name.ToLowerInvariant().Contains("honor"))
					{
						val = value2;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Scout's Honor not found in the item database - keeping the built-in orb look.");
				return;
			}
			try
			{
				Adopt(Plugin.OrbPrefab, val);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Adopting Scout's Honor look failed: " + ex));
			}
		}

		private static void Adopt(Item mine, Item tpl)
		{
			//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_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_00af: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01bd: 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_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: 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_01fa: 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_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: 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_0220: 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_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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_049d: 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_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: 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_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: 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)
			mine.defaultPos = tpl.defaultPos;
			mine.defaultForward = tpl.defaultForward;
			mine.rightHandOnly = tpl.rightHandOnly;
			mine.mass = tpl.mass;
			mine.UIData.iconScaleOffset = ((tpl.UIData != null) ? tpl.UIData.iconScaleOffset : 1f);
			string[] array = new string[2] { "Hand_R", "Hand_L" };
			foreach (string text in array)
			{
				Transform val = tpl.transform.Find(text);
				Transform val2 = mine.transform.Find(text);
				if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
				{
					val2.localPosition = val.localPosition;
					val2.localRotation = val.localRotation;
				}
			}
			Transform val3 = mine.transform.Find("Visual");
			for (int num = val3.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val3.GetChild(num)).gameObject);
			}
			Transform transform = tpl.transform;
			Bounds val4 = default(Bounds);
			bool flag = false;
			int num2 = 0;
			MeshFilter[] componentsInChildren = ((Component)tpl).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val5 in componentsInChildren)
			{
				MeshRenderer component = ((Component)val5).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null || (Object)(object)val5.sharedMesh == (Object)null || (Object)(object)((Component)val5).GetComponentInParent<ParticleSystem>(true) != (Object)null || UnderHandPoint(((Component)val5).transform, transform))
				{
					continue;
				}
				GameObject val6 = new GameObject("Part_" + ((Object)val5).name);
				val6.transform.SetParent(val3, false);
				val6.transform.localPosition = transform.InverseTransformPoint(((Component)val5).transform.position);
				val6.transform.localRotation = Quaternion.Inverse(transform.rotation) * ((Component)val5).transform.rotation;
				Vector3 lossyScale = transform.lossyScale;
				Vector3 lossyScale2 = ((Component)val5).transform.lossyScale;
				val6.transform.localScale = new Vector3(lossyScale2.x / lossyScale.x, lossyScale2.y / lossyScale.y, lossyScale2.z / lossyScale.z);
				val6.AddComponent<MeshFilter>().sharedMesh = val5.sharedMesh;
				Plugin.Log.LogInfo((object)("  copying Scout's Honor mesh '" + ((Object)val5.sharedMesh).name + "' (from '" + ((Object)val5).name + "')"));
				MeshRenderer val7 = val6.AddComponent<MeshRenderer>();
				Material[] array2 = (Material[])(object)new Material[Mathf.Max(1, ((Renderer)component).sharedMaterials.Length)];
				for (int j = 0; j < array2.Length; j++)
				{
					array2[j] = VoidFx.Black();
				}
				((Renderer)val7).sharedMaterials = array2;
				((Renderer)val7).shadowCastingMode = (ShadowCastingMode)1;
				foreach (Vector3 item in Corners(val5.sharedMesh.bounds))
				{
					Vector3 val8 = val6.transform.localPosition + val6.transform.localRotation * Vector3.Scale(item, val6.transform.localScale);
					if (!flag)
					{
						val4 = new Bounds(val8, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val4)).Encapsulate(val8);
					}
				}
				num2++;
			}
			if (num2 == 0)
			{
				Plugin.Log.LogWarning((object)"Scout's Honor has no mesh renderers we can copy - keeping the built-in orb.");
				((Component)VoidFx.MeshObj("Orb", val3, VoidFx.Sphere, VoidFx.Black())).transform.localScale = Vector3.one * 0.16f;
			}
			else
			{
				SphereCollider component2 = ((Component)mine).GetComponent<SphereCollider>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component2);
				}
				BoxCollider obj = ((Component)mine).gameObject.AddComponent<BoxCollider>();
				obj.center = ((Bounds)(ref val4)).center;
				obj.size = Vector3.Max(((Bounds)(ref val4)).size, Vector3.one * 0.05f);
			}
			mine.addtlRenderers = ((Component)mine).GetComponentsInChildren<Renderer>(true);
			Texture2D val9 = ((tpl.UIData != null) ? tpl.UIData.icon : null);
			Texture2D val10 = (((Object)(object)val9 != (Object)null) ? DarkenIcon((Texture)(object)val9) : null);
			if ((Object)(object)val10 != (Object)null)
			{
				Icon = val10;
				mine.UIData.icon = val10;
			}
			Plugin.Log.LogInfo((object)$"Darkness Of Souls now looks like a vantablack '{((Object)((Component)tpl).gameObject).name}' ({num2} meshes, held at {mine.defaultPos}).");
		}

		private static bool UnderHandPoint(Transform t, Transform root)
		{
			while ((Object)(object)t != (Object)null && (Object)(object)t != (Object)(object)root)
			{
				if (((Object)t).name == "Hand_L" || ((Object)t).name == "Hand_R" || (Object)(object)((Component)t).GetComponent<HandVisual>() != (Object)null)
				{
					return true;
				}
				t = t.parent;
			}
			return false;
		}

		private static IEnumerable<Vector3> Corners(Bounds b)
		{
			//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)
			for (int i = 0; i < 8; i++)
			{
				yield return ((Bounds)(ref b)).center + Vector3.Scale(((Bounds)(ref b)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
			}
		}

		private static Texture2D DarkenIcon(Texture src)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: 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_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: 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_0234: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: 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)
			try
			{
				int num = Mathf.Min(256, src.width);
				int num2 = Mathf.Min(256, src.height);
				RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0);
				RenderTexture active = RenderTexture.active;
				Graphics.Blit(src, temporary);
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
				val.Apply();
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				Color[] pixels = val.GetPixels();
				Color[] array = (Color[])(object)new Color[pixels.Length];
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.62f, 0.32f, 1f);
				int num3 = Mathf.Max(2, num / 40);
				for (int i = 0; i < num2; i++)
				{
					for (int j = 0; j < num; j++)
					{
						float a = pixels[i * num + j].a;
						float num4 = 0f;
						if (a < 0.5f)
						{
							for (int k = -num3; k <= num3; k++)
							{
								for (int l = -num3; l <= num3; l++)
								{
									int num5 = j + l;
									int num6 = i + k;
									if (num5 >= 0 && num6 >= 0 && num5 < num && num6 < num2 && pixels[num6 * num + num5].a > 0.5f)
									{
										num4 = Mathf.Max(num4, 1f - Mathf.Sqrt((float)(l * l + k * k)) / ((float)num3 + 1f));
									}
								}
							}
						}
						if (a >= 0.5f)
						{
							float grayscale = ((Color)(ref pixels[i * num + j])).grayscale;
							Color val3 = Color.Lerp(new Color(0.01f, 0.005f, 0.02f), new Color(0.12f, 0.05f, 0.2f), Mathf.Pow(grayscale, 3f) * 0.6f);
							array[i * num + j] = new Color(val3.r, val3.g, val3.b, a);
						}
						else
						{
							array[i * num + j] = new Color(val2.r, val2.g, val2.b, Mathf.Max(a, num4 * num4 * 0.9f));
						}
					}
				}
				Texture2D val4 = new Texture2D(num, num2, (TextureFormat)4, false)
				{
					name = "DoS_Icon"
				};
				val4.SetPixels(array);
				val4.Apply(false, false);
				Object.Destroy((Object)(object)val);
				return val4;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Icon recolour failed: " + ex.Message));
				return null;
			}
		}

		private static Texture2D MakeFallbackIcon()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				name = "DoS_IconFallback"
			};
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j + 0.5f) / 128f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 128f * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					if (num3 < 0.62f)
					{
						array[i * 128 + j] = new Color(0.01f, 0.005f, 0.02f, 1f);
						continue;
					}
					float num4 = Mathf.Exp((0f - (num3 - 0.62f)) * 9f);
					array[i * 128 + j] = new Color(0.62f, 0.32f, 1f, num4 * 0.95f);
				}
			}
			val.SetPixels(array);
			val.Apply(false, false);
			return val;
		}
	}
	internal class OrbCommune : MonoBehaviour
	{
		public static VoidMode LocalMode;

		public static float LocalRadius = 1.45f;

		public const float MinRadius = 0.1f;

		public const float MaxRadius = 100000f;

		public static float LocalStalkSpeed = 0.3f;

		public const float MinStalk = 0.05f;

		public const float MaxStalk = 50f;

		private static bool s_modeInit;

		private float lastScrollSfx;

		public static OrbCommune HeldLocal;

		private Item item;

		private float progress;

		private bool communed;

		private AudioSource hum;

		private AudioSource charge;

		private ParticleSystem wisps;

		private Transform halo;

		private float nextHint;

		private readonly float[] keyDownAt = new float[4];

		private readonly float[] keyNextAt = new float[4];

		public static bool Charging
		{
			get
			{
				if ((Object)(object)HeldLocal != (Object)null && HeldLocal.progress > 0f)
				{
					return !HeldLocal.communed;
				}
				return false;
			}
		}

		private void Awake()
		{
			item = ((Component)this).GetComponent<Item>();
			if (!s_modeInit)
			{
				s_modeInit = true;
				LocalMode = Plugin.DefaultMode.Value;
				LocalRadius = Mathf.Clamp(Plugin.SpawnRadius.Value, 0.1f, 100000f);
				LocalStalkSpeed = Mathf.Clamp(Plugin.StalkerSpeed.Value, 0.05f, 50f);
			}
			Item obj = item;
			obj.OnPrimaryFinishedCast = (Action)Delegate.Combine(obj.OnPrimaryFinishedCast, new Action(Commune));
			Item obj2 = item;
			obj2.OnScrolled = (Action<float>)Delegate.Combine(obj2.OnScrolled, new Action<float>(ScrollSize));
		}

		private void Start()
		{
			//IL_0033: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a6: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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)
			//IL_011b: 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_014f: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			MeshRenderer val = VoidFx.Billboard("Rim", ((Component)this).transform, VoidFx.Shared("OrbRim", (Texture)(object)VoidFx.PhotonRing, additive: true));
			halo = ((Component)val).transform;
			halo.localScale = Vector3.one * 0.42f;
			VoidFx.Tint(((Renderer)val).sharedMaterial, new Color(0.6f, 0.3f, 1f, 0.9f));
			wisps = VoidFx.Particles("Wisps", ((Component)this).transform, VoidFx.Shared("Mote", (Texture)(object)VoidFx.SoftDot, additive: false), 60);
			MainModule main = wisps.main;
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(1.2f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.015f, 0.05f);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0f, 0f, 0f, 0.9f), new Color(0.35f, 0.1f, 0.6f, 0.9f));
			ShapeModule shape = wisps.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.25f;
			((ShapeModule)(ref shape)).radiusThickness = 0f;
			VelocityOverLifetimeModule velocityOverLifetime = wisps.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = MinMaxCurve.op_Implicit(-0.2f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
			ColorOverLifetimeModule colorOverLifetime = wisps.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val2 = new Gradient();
			val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.4f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val2);
			EmissionModule emission = wisps.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(14f);
			wisps.Play();
			hum = VoidAudio.Loop(((Component)this).transform, VoidAudio.Hum, 8f);
		}

		private void OnDisable()
		{
			if ((Object)(object)HeldLocal == (Object)(object)this)
			{
				HeldLocal = null;
			}
		}

		private void ScrollSize(float v)
		{
			if (v != 0f && !communed && !VoidDirector.IsAwake && !(progress > 0f) && !((Object)(object)item.holderCharacter == (Object)null) && item.holderCharacter.IsLocal)
			{
				Keyboard current = Keyboard.current;
				bool fast = current != null && (((ButtonControl)current.leftShiftKey).isPressed || ((ButtonControl)current.rightShiftKey).isPressed);
				if (current != null && (((ButtonControl)current.leftCtrlKey).isPressed || ((ButtonControl)current.rightCtrlKey).isPressed || ((ButtonControl)current.leftAltKey).isPressed || ((ButtonControl)current.rightAltKey).isPressed))
				{
					ScrollSpeed(v, fast);
				}
				else
				{
					StepSize(v, fast);
				}
			}
		}

		private void StepSize(float v, bool fast)
		{
			float num = (fast ? 1.6f : 1.12f);
			float localRadius = LocalRadius;
			LocalRadius = Mathf.Clamp((v > 0f) ? (LocalRadius * num) : (LocalRadius / num), 0.1f, 100000f);
			if ((localRadius - 1.45f) * (LocalRadius - 1.45f) < 0f)
			{
				LocalRadius = 1.45f;
			}
			if (!Mathf.Approximately(localRadius, LocalRadius))
			{
				Plugin.SpawnRadius.Value = LocalRadius;
				if (Time.time - lastScrollSfx > 0.05f)
				{
					lastScrollSfx = Time.time;
					float num2 = Mathf.InverseLerp(Mathf.Log(0.1f), Mathf.Log(100000f), Mathf.Log(LocalRadius));
					VoidAudio.Play2D(VoidAudio.Thud, 0.25f, Mathf.Lerp(2.2f, 0.45f, num2));
				}
			}
		}

		private void StepKeys()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected I4, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected I4, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected I4, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected I4, but got Unknown
			Keyboard current = Keyboard.current;
			if (current == null || ((Object)(object)GUIManager.instance != (Object)null && GUIManager.instance.windowBlockingInput))
			{
				return;
			}
			bool fast = ((ButtonControl)current.leftShiftKey).isPressed || ((ButtonControl)current.rightShiftKey).isPressed;
			Key[] array = (Key[])(object)new Key[4]
			{
				(Key)(int)Plugin.SizeDownKey.Value,
				(Key)(int)Plugin.SizeUpKey.Value,
				(Key)(int)Plugin.SpeedDownKey.Value,
				(Key)(int)Plugin.SpeedUpKey.Value
			};
			for (int i = 0; i < 4; i++)
			{
				if ((int)array[i] == 0)
				{
					continue;
				}
				KeyControl val = current[array[i]];
				bool flag = false;
				if (((ButtonControl)val).wasPressedThisFrame)
				{
					flag = true;
					keyDownAt[i] = Time.time;
					keyNextAt[i] = Time.time + 0.35f;
				}
				else if (((ButtonControl)val).isPressed && Time.time >= keyNextAt[i])
				{
					flag = true;
					keyNextAt[i] = Time.time + 0.07f;
				}
				if (flag)
				{
					float v = ((i % 2 == 0) ? (-1f) : 1f);
					if (i < 2)
					{
						StepSize(v, fast);
					}
					else
					{
						ScrollSpeed(v, fast);
					}
				}
			}
		}

		private void ScrollSpeed(float v, bool fast)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			float num = (fast ? 1.6f : 1.15f);
			float localStalkSpeed = LocalStalkSpeed;
			LocalStalkSpeed = Mathf.Clamp((v > 0f) ? (LocalStalkSpeed * num) : (LocalStalkSpeed / num), 0.05f, 50f);
			if ((localStalkSpeed - 0.3f) * (LocalStalkSpeed - 0.3f) < 0f)
			{
				LocalStalkSpeed = 0.3f;
			}
			if (LocalMode != VoidMode.Stalker)
			{
				LocalMode = VoidMode.Stalker;
				VoidHud.Toast("<color=#" + ColorUtility.ToHtmlStringRGB(Modes.Tint(LocalMode)) + ">STALKER</color>\n<size=70%>" + Modes.Blurb(LocalMode) + "</size>", 2.5f);
			}
			if (!Mathf.Approximately(localStalkSpeed, LocalStalkSpeed))
			{
				Plugin.StalkerSpeed.Value = LocalStalkSpeed;
				if (Time.time - lastScrollSfx > 0.05f)
				{
					lastScrollSfx = Time.time;
					float num2 = Mathf.InverseLerp(Mathf.Log(0.05f), Mathf.Log(50f), Mathf.Log(LocalStalkSpeed));
					VoidAudio.Play2D(VoidAudio.Crack, 0.2f, Mathf.Lerp(0.6f, 2.4f, num2));
				}
			}
		}

		public static string SpeedText(float s)
		{
			string arg = ((s < 0.2f) ? "snail" : ((s < 0.6f) ? "creep" : ((s < 2f) ? "stroll" : ((s < 4f) ? "walk" : ((s < 7f) ? "run" : ((s < 15f) ? "sprint" : ((s < 30f) ? "car" : "rocket")))))));
			return $"{s:0.##} m/s <alpha=#99>({arg})";
		}

		public static string SizeText(float r)
		{
			string obj = ((r < 10f) ? $"{r:0.##} m" : ((r < 1000f) ? $"{r:0} m" : $"{r / 1000f:0.##} km"));
			string text = ((r < 1f) ? "pebble" : ((r < 2.5f) ? "campfire" : ((r < 8f) ? "boulder" : ((r < 25f) ? "camp-eater" : ((r < 120f) ? "slope-eater" : ((r < 600f) ? "biome-eater" : ((r < 3000f) ? "mountain-eater" : "world-ender")))))));
			return obj + " <alpha=#99>(" + text + ")";
		}

		private void CycleMode()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item.holderCharacter == (Object)null) && item.holderCharacter.IsLocal)
			{
				LocalMode = (VoidMode)((int)(LocalMode + 1) % 6);
				VoidAudio.Play2D(VoidAudio.Crack, 0.35f, 1.6f);
				VoidHud.Toast("<color=#" + ColorUtility.ToHtmlStringRGB(Modes.Tint(LocalMode)) + ">" + Modes.Title(LocalMode).ToUpperInvariant() + "</color>\n<size=70%>" + Modes.Blurb(LocalMode) + "</size>", 3f);
			}
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (int)item.itemState == 1 && (Object)(object)item.holderCharacter != (Object)null;
			bool flag2 = flag && item.holderCharacter.IsLocal;
			if ((Object)(object)hum != (Object)null)
			{
				hum.volume = (flag ? 0.35f : 0.18f) * Plugin.Volume.Value + progress * 0.4f;
			}
			if ((Object)(object)halo != (Object)null)
			{
				float num = (flag2 ? Mathf.Clamp(1f + Mathf.Log10(LocalRadius / 1.45f) * 0.3f, 0.6f, 2.6f) : 1f);
				float num2 = (0.42f + Mathf.Sin(Time.time * 2.3f) * 0.03f) * num + progress * 0.3f;
				halo.localScale = Vector3.one * num2;
			}
			if (!flag2)
			{
				if ((Object)(object)HeldLocal == (Object)(object)this)
				{
					HeldLocal = null;
				}
				SetProgress(0f);
				return;
			}
			HeldLocal = this;
			if (communed)
			{
				return;
			}
			CharacterInput input = item.holderCharacter.input;
			if (!VoidDirector.IsAwake && progress <= 0f)
			{
				StepKeys();
			}
			if ((Object)(object)input != (Object)null && input.useSecondaryWasPressed && !VoidDirector.IsAwake && progress <= 0f && !item.isUsingPrimary)
			{
				CycleMode();
			}
			bool flag3 = (Object)(object)Interaction.instance != (Object)null && Interaction.instance.currentHovered != null;
			bool flag4 = (Object)(object)input != (Object)null && input.interactIsPressed && (progress > 0f || !flag3);
			if (flag4 && !VoidDirector.IsAwake)
			{
				if (progress <= 0f)
				{
					StartCharge();
				}
				SetProgress(progress + Time.deltaTime / 2f);
				Tremble(progress);
				if (progress >= 1f)
				{
					Commune();
				}
				return;
			}
			if (flag4 && VoidDirector.IsAwake && Time.time > nextHint)
			{
				nextHint = Time.time + 2f;
				VoidHud.Toast("The Darkness is already awake.", 2f);
			}
			if (!item.isUsingPrimary)
			{
				SetProgress(0f);
				StopCharge();
				return;
			}
			if ((Object)(object)charge == (Object)null)
			{
				StartCharge();
			}
			Tremble(item.castProgress);
		}

		private void SetProgress(float p)
		{
			progress = Mathf.Clamp01(p);
			item.overrideForceProgress = progress > 0f;
			item.overrideProgress = progress;
		}

		private void Tremble(float p)
		{
			//IL_001c: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0052: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)this).transform.Find("Visual");
			if (!((Object)(object)val == (Object)null))
			{
				val.localPosition = Random.insideUnitSphere * 0.006f * p * p;
				EmissionModule val2 = (EmissionModule)(((Object)(object)wisps != (Object)null) ? wisps.emission : default(EmissionModule));
				if ((Object)(object)wisps != (Object)null)
				{
					((EmissionModule)(ref val2)).rateOverTime = MinMaxCurve.op_Implicit(14f + 90f * p);
				}
			}
		}

		private void StartCharge()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			StopCharge();
			charge = VoidAudio.Play3D(VoidAudio.Charge, ((Component)this).transform.position, 0.8f, 30f);
		}

		private void StopCharge()
		{
			//IL_0040: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)charge != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)charge).gameObject);
				charge = null;
			}
			Transform val = ((Component)this).transform.Find("Visual");
			if ((Object)(object)val != (Object)null)
			{
				val.localPosition = Vector3.zero;
			}
			if ((Object)(object)wisps != (Object)null)
			{
				EmissionModule emission = wisps.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(14f);
			}
		}

		private void Commune()
		{
			//IL_009e: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!communed && !((Object)(object)item.holderCharacter == (Object)null) && item.holderCharacter.IsLocal)
			{
				if (VoidDirector.IsAwake)
				{
					VoidHud.Toast("The Darkness is already awake.", 2f);
					SetProgress(0f);
					return;
				}
				if (!VoidNet.EveryoneHasMod(out var missing))
				{
					VoidHud.Toast("<color=#ff7070>" + missing + " can't see the Darkness</color>\n<size=70%>Everyone needs Darkness Of Souls installed.</size>", 4f);
					SetProgress(0f);
					return;
				}
				communed = true;
				SetProgress(0f);
				charge = null;
				Vector3 position = ((Component)this).transform.position;
				VoidNet.RequestCommune(position, LocalMode, ((MonoBehaviourPun)item.holderCharacter).photonView.ViewID, LocalRadius, LocalStalkSpeed);
				((MonoBehaviour)item).StartCoroutine(item.ConsumeDelayed(false));
				Plugin.Log.LogInfo((object)$"Communed with the Darkness ({Modes.Title(LocalMode)}) at {position}.");
			}
		}
	}
	internal class OrbSpawner : MonoBehaviour
	{
		private static OrbSpawner I;

		private float sceneAt;

		private float next;

		private bool placedThisScene;

		private void Awake()
		{
			I = this;
			SceneManager.activeSceneChanged += delegate
			{
				sceneAt = Time.time;
				placedThisScene = false;
				Patch_CampfireLit.LastLitAt = -1f;
			};
		}

		private void Update()
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected I4, but got Unknown
			if (Time.time < next)
			{
				return;
			}
			next = Time.time + 1f;
			OrbBuilder.TryAdopt();
			VoidFx.EnsureShaders();
			if (placedThisScene || !Plugin.OrbAtStart.Value || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient || Plugin.OrbPrefabName == null)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).name.StartsWith("Level_") || Time.time - sceneAt < 8f || (Object)(object)Character.localCharacter == (Object)null || !MapHandler.ExistsAndInitialized)
			{
				return;
			}
			placedThisScene = true;
			Vector3 val = Vector3.zero;
			int num = 0;
			int num2 = 0;
			try
			{
				num2 = (int)MapHandler.CurrentSegmentNumber;
			}
			catch
			{
			}
			if (num2 == 0)
			{
				foreach (SpawnPoint allSpawnPoint in SpawnPoint.allSpawnPoints)
				{
					if ((Object)(object)allSpawnPoint != (Object)null)
					{
						val += ((Component)allSpawnPoint).transform.position;
						num++;
					}
				}
			}
			val = ((num <= 0) ? Character.localCharacter.Center : (val / (float)num));
			Place(val, (num2 == 0) ? "the crash site" : "the host");
		}

		public static void OnBiomeArrived()
		{
			//IL_0099: 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_009f: 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_0092: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)I == (Object)null || !Plugin.OrbEveryCamp.Value || VoidDirector.IsAwake || !PhotonNetwork.IsMasterClient)
			{
				return;
			}
			foreach (Item aLL_ITEM in Item.ALL_ITEMS)
			{
				if (aLL_ITEM is OrbItem && ((Component)aLL_ITEM).gameObject.activeInHierarchy)
				{
					return;
				}
			}
			Vector3 val = ((Patch_CampfireLit.LastLitAt > 0f) ? Patch_CampfireLit.LastLit : (((Object)(object)Character.localCharacter != (Object)null) ? Character.localCharacter.Center : Vector3.zero));
			if (val != Vector3.zero)
			{
				I.Place(val, "the campfire");
			}
		}

		private void Place(Vector3 around, string where)
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			Campfire[] array = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0);
			RaycastHit val2 = default(RaycastHit);
			for (float num = 2.5f; num <= 7f; num += 0.75f)
			{
				float num2 = Random.Range(0f, 360f);
				for (int i = 0; i < 12; i++)
				{
					Vector3 val = Quaternion.Euler(0f, num2 + (float)i * 30f, 0f) * Vector3.forward;
					if (!Physics.Raycast(around + val * num + Vector3.up * 3f, Vector3.down, ref val2, 8f, LayerMask.op_Implicit(HelperFunctions.terrainMapMask), (QueryTriggerInteraction)1) || ((RaycastHit)(ref val2)).normal.y < 0.75f || Mathf.Abs(((RaycastHit)(ref val2)).point.y - around.y) > 3f)
					{
						continue;
					}
					bool flag = false;
					Campfire[] array2 = array;
					foreach (Campfire val3 in array2)
					{
						if ((Object)(object)val3 != (Object)null && Vector3.Distance(((Component)val3).transform.position, ((RaycastHit)(ref val2)).point) < 2f)
						{
							flag = true;
						}
					}
					if (!flag)
					{
						Spawn(((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.15f, where);
						return;
					}
				}
			}
			Spawn(around + Vector3.up * 0.5f, where);
		}

		private static void Spawn(Vector3 pos, string where)
		{
			//IL_0019: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
			GameObject val2 = PhotonNetwork.InstantiateItemRoom(Plugin.OrbPrefabName, pos, val, true);
			PhotonView val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<PhotonView>() : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.RPC("SetKinematicRPC", (RpcTarget)3, new object[3] { true, pos, val });
			}
			Plugin.Log.LogInfo((object)$"A Darkness Of Souls orb waits at {where} ({pos}).");
		}
	}
	[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
	internal static class Patch_CampfireLit
	{
		public static Vector3 LastLit;

		public static float LastLitAt = -1f;

		private static void Postfix(Campfire __instance, bool updateSegment)
		{
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			if (updateSegment && !((Object)(object)__instance == (Object)null))
			{
				LastLit = ((Component)__instance).transform.position;
				LastLitAt = Time.time;
				Plugin.D($"Campfire lit at {LastLit}");
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ReviveCharacter")]
	internal static class Patch_Revive
	{
		private static void Postfix(Character __instance)
		{
			if ((Object)(object)__instance != (Object)null && __instance.IsLocal)
			{
				VoidDirector.OnLocalRevived(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Interaction), "DoInteraction")]
	internal static class Patch_NoInteractWhileCommuning
	{
		private static bool Prefix(Interaction __instance)
		{
			if (!OrbCommune.Charging)
			{
				return true;
			}
			__instance.readyToInteract = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(LocalizedText), "GetText", new Type[]
	{
		typeof(string),
		typeof(bool)
	})]
	internal static class Patch_Text
	{
		private static readonly Dictionary<string, string> Ours = new Dictionary<string, string>
		{
			{ "NAME_DARKNESS OF SOULS", "Darkness Of Souls" },
			{ "DESC_DARKNESS OF SOULS", "A vantablack Scout's Honor. Hold E to commune... if you dare." },
			{ "CHANGE DARKNESS", "Change mode" },
			{ "HOLE SIZE", "Hole size" },
			{ "COMMUNE", "Commune" }
		};

		private static void Postfix(string id, ref string __result)
		{
			if (id != null && (__result == null || __result.StartsWith("LOC: ") || __result.Length <= 0) && Ours.TryGetValue(id.ToUpperInvariant(), out var value))
			{
				__result = value;
			}
		}
	}
	[BepInPlugin("com.attackstudioyt.darknessofsouls", "DarknessOfSouls", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.attackstudioyt.darknessofsouls";

		public const string Name = "DarknessOfSouls";

		public const string Version = "1.0.0";

		public const int Protocol = 1;

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<VoidMode> DefaultMode;

		internal static ConfigEntry<Difficulty> Diff;

		internal static ConfigEntry<bool> OrbAtStart;

		internal static ConfigEntry<bool> OrbEveryCamp;

		internal static ConfigEntry<float> ReturnDelay;

		internal static ConfigEntry<float> ContactSeconds;

		internal static ConfigEntry<float> PullStrength;

		internal static ConfigEntry<float> GrowthSpeed;

		internal static ConfigEntry<bool> RipScenery;

		internal static ConfigEntry<bool> EatItems;

		internal static ConfigEntry<bool> ProtectCamps;

		internal static ConfigEntry<float> SpawnRadius;

		internal static ConfigEntry<float> StalkerSpeed;

		internal static ConfigEntry<Key> ReclaimKey;

		internal static ConfigEntry<Key> SizeDownKey;

		internal static ConfigEntry<Key> SizeUpKey;

		internal static ConfigEntry<Key> SpeedDownKey;

		internal static ConfigEntry<Key> SpeedUpKey;

		internal static ConfigEntry<bool> AnyoneCanReclaim;

		internal static ConfigEntry<bool> DebrisHits;

		internal static ConfigEntry<float> DebrisDamage;

		internal static ConfigEntry<float> Volume;

		internal static ConfigEntry<bool> ScreenEffects;

		internal static ConfigEntry<int> MaxDebris;

		internal static ConfigEntry<bool> DebugLogging;

		internal static Item OrbPrefab;

		internal static string OrbPrefabName
		{
			get
			{
				if (!((Object)(object)OrbPrefab != (Object)null))
				{
					return null;
				}
				return ((Object)((Component)OrbPrefab).gameObject).name;
			}
		}

		private void Awake()
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Expected O, but got Unknown
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Expected O, but got Unknown
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Expected O, but got Unknown
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Expected O, but got Unknown
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Expected O, but got Unknown
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			DefaultMode = ((BaseUnityPlugin)this).Config.Bind<VoidMode>("Challenge", "DefaultMode", VoidMode.Classic, "Mode the orb starts on (right-click while holding it to change). Classic: stays put. Stalker: creeps after the nearest scout. Ravenous: grows and pulls much harder. Binary: two smaller holes orbit each other. Wanderer: drifts around the camp in long loops. Apocalypse: scenery and items fold in instantly while scouts are barely pulled.");
			Diff = ((BaseUnityPlugin)this).Config.Bind<Difficulty>("Challenge", "Difficulty", Difficulty.Normal, "Host's value is used. Chill = gentler pull/growth and slower curse. Brutal = for veterans. Solo runs are automatically a little kinder.");
			OrbAtStart = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge", "OrbAtCrashSite", true, "Host: a Darkness Of Souls orb waits by the crashed plane at the start of every run.");
			OrbEveryCamp = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge", "OrbAtEveryCamp", false, "Host: also leave a fresh orb at each new biome's campfire while no Darkness is awake.");
			ReturnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "ReturnDelaySeconds", 15f, new ConfigDescription("Seconds after the next biome appears before the Darkness reforms on the campfire you lit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 120f), Array.Empty<object>()));
			ContactSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "ContactSecondsToPassOut", 5f, new ConfigDescription("Roughly how many seconds a healthy scout survives inside the hole (at Normal).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			PullStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "PullStrength", 1f, new ConfigDescription("Multiplier on gravity pull for scouts and items.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			GrowthSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Tuning", "GrowthSpeed", 1f, new ConfigDescription("Multiplier on how fast the hole grows.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			RipScenery = ((BaseUnityPlugin)this).Config.Bind<bool>("World", "RipOutScenery", true, "Bushes, trees, rocks and props near the hole shake loose and get dragged in.");
			EatItems = ((BaseUnityPlugin)this).Config.Bind<bool>("World", "FizzleItems", true, "Loose items get pulled in and fizzle when they touch the hole.");
			ProtectCamps = ((BaseUnityPlugin)this).Config.Bind<bool>("World", "ProtectCamps", true, "Scenery within 8 m of a campfire or scout statue is never ripped out.");
			SpawnRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "SpawnRadius", 1.45f, new ConfigDescription("Host: radius in metres the black hole opens to (and resets to at each campfire). 1.45 = campfire size. Go as big as you dare: 10 swallows a camp, 100 a whole slope, 1000+ the mountain. It still grows from there.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100000f), Array.Empty<object>()));
			StalkerSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Challenge", "StalkerSpeed", 0.3f, new ConfigDescription("Stalker mode: how fast (m/s) it creeps after the nearest scout. Set in-game with Ctrl+Scroll while holding the orb. A scout walks about 3 m/s; it gets ~20% faster after each campfire.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 50f), Array.Empty<object>()));
			ReclaimKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ReclaimKey", (Key)22, "Hold this while the Darkness is awake to reclaim it: the black hole implodes and the orb returns to your hands.");
			SizeDownKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "HoleSizeDownKey", (Key)11, "Holding the orb: make the hole smaller (hold to repeat, Shift = big jumps). Scroll wheel works too.");
			SizeUpKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "HoleSizeUpKey", (Key)12, "Holding the orb: make the hole bigger (hold to repeat, Shift = big jumps).");
			SpeedDownKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "StalkerSpeedDownKey", (Key)13, "Holding the orb: slower Stalker (switches the orb to Stalker).");
			SpeedUpKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "StalkerSpeedUpKey", (Key)14, "Holding the orb: faster Stalker (switches the orb to Stalker).");
			AnyoneCanReclaim = ((BaseUnityPlugin)this).Config.Bind<bool>("Challenge", "AnyoneCanReclaim", true, "Host: anyone may reclaim the Darkness. Off = only the scout who communed with it (and the host).");
			DebrisHits = ((BaseUnityPlugin)this).Config.Bind<bool>("World", "DebrisHitsScouts", true, "Scenery and items flying round the hole are solid: a fast hit knocks you over and injures you (bigger and faster = worse), a slow one shoves you.");
			DebrisDamage = ((BaseUnityPlugin)this).Config.Bind<float>("World", "DebrisDamage", 1f, new ConfigDescription("Multiplier on the injury from being hit by flying debris (0 = knockdown only).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			MaxDebris = ((BaseUnityPlugin)this).Config.Bind<int>("World", "MaxFlyingDebris", 45, new ConfigDescription("Most pieces of scenery flying at once (lower if your PC struggles).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 200), Array.Empty<object>()));
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 0.9f, new ConfigDescription("Darkness sound volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ScreenEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("Visual", "ScreenEffects", true, "Dark vignette, flashes and camera shake near the hole.");
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogging", false, "Verbose logs.");
			VoidAudio.Build();
			OrbPrefab = OrbBuilder.Build();
			ModDefinition orCreate = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info.Metadata);
			new ItemContent(OrbPrefab).Register(orCreate);
			Log.LogInfo((object)("Registered item prefab '" + ((Object)((Component)OrbPrefab).gameObject).name + "'."));
			new Harmony("com.attackstudioyt.darknessofsouls").PatchAll(typeof(Plugin).Assembly);
			GameObject val = new GameObject("DarknessOfSouls.Host");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<VoidNet>();
			val.AddComponent<VoidDirector>();
			val.AddComponent<Uprooter>();
			val.AddComponent<VoidHud>();
			val.AddComponent<OrbSpawner>();
			Log.LogInfo((object)"DarknessOfSouls 1.0.0 loaded.");
		}

		internal static void D(string msg)
		{
			if (DebugLogging.Value)
			{
				Log.LogInfo((object)("[dbg] " + msg));
			}
		}
	}
	public enum VoidMode
	{
		Classic,
		Stalker,
		Ravenous,
		Binary,
		Wanderer,
		Apocalypse
	}
	public enum Difficulty
	{
		Chill,
		Normal,
		Brutal
	}
	internal static class Modes
	{
		public const int Count = 6;

		public static bool Apocalypse(VoidMode m)
		{
			return m == VoidMode.Apocalypse;
		}

		public static string Title(VoidMode m)
		{
			return m switch
			{
				VoidMode.Stalker => "Stalker", 
				VoidMode.Ravenous => "Ravenous", 
				VoidMode.Binary => "Binary", 
				VoidMode.Wanderer => "Wanderer", 
				VoidMode.Apocalypse => "Apocalypse", 
				_ => "Classic", 
			};
		}

		public static string Blurb(VoidMode m)
		{
			return m switch
			{
				VoidMode.Stalker => "It creeps after the nearest scout. Keep moving.", 
				VoidMode.Ravenous => "Grows twice as fast and pulls much harder.", 
				VoidMode.Binary => "Two smaller holes orbit each other.", 
				VoidMode.Wanderer => "Drifts around the camp in long, slow loops.", 
				VoidMode.Apocalypse => "The world folds in at once. It barely tugs at scouts.", 
				_ => "Stays where it was born, growing and pulling.", 
			};
		}

		public static Color Tint(VoidMode m)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0072: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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)
			return (Color)(m switch
			{
				VoidMode.Stalker => new Color(1f, 0.22f, 0.32f), 
				VoidMode.Ravenous => new Color(1f, 0.5f, 0.12f), 
				VoidMode.Binary => new Color(0.3f, 0.8f, 1f), 
				VoidMode.Wanderer => new Color(0.45f, 1f, 0.6f), 
				VoidMode.Apocalypse => new Color(1f, 0.85f, 0.45f), 
				_ => new Color(0.68f, 0.4f, 1f), 
			});
		}
	}
	internal class Uprooter : MonoBehaviour
	{
		private struct Entry
		{
			public Renderer r;

			public Bounds b;

			public bool map;
		}

		private class MeshCache
		{
			public Vector3[] v;

			public Vector3[] n;

			public Vector2[] uv;

			public Color[] c;
		}

		private class Debris
		{
			public Transform t;

			public Vector3 basePos;

			public Vector3 vel;

			public Vector3 spinAxis;

			public float spin;

			public float timer;

			public float shakeFor;

			public float size;

			public float scale0 = 1f;

			public bool flying;

			public Bounds local;

			public float hitCd;

			public int groundHits;
		}

		public static Uprooter Instance;

		private const float Cell = 16f;

		private readonly Dictionary<long, List<Entry>> grid = new Dictionary<long, List<Entry>>();

		private readonly HashSet<int> gone = new HashSet<int>();

		private readonly List<Vector3> camps = new List<Vector3>();

		private readonly List<Debris> debris = new List<Debris>();

		private readonly Dictionary<Mesh, MeshCache> batchCache = new Dictionary<Mesh, MeshCache>();

		private const string DebrisName = "DoS_Debris";

		private int followups;

		private bool scanning;

		private bool scanned;

		private int scannedSeg = -2;

		private float rescanAt;

		private float tick;

		private float lastCrack;

		private int maskSkipLayers;

		private static readonly Collider[] s_hits = (Collider[])(object)new Collider[16];

		private void Awake()
		{
			Instance = this;
			string[] array = new string[7] { "Terrain", "Character", "UI", "Water", "Ignore Raycast", "TransparentFX", "Rope" };
			for (int i = 0; i < array.Length; i++)
			{
				int num = LayerMask.NameToLayer(array[i]);
				if (num >= 0)
				{
					maskSkipLayers |= 1 << num;
				}
			}
		}

		public void Clear()
		{
			((MonoBehaviour)this).StopAllCoroutines();
			scanning = false;
			scanned = false;
			scannedSeg = -2;
			grid.Clear();
			gone.Clear();
			camps.Clear();
			batchCache.Clear();
			foreach (Debris debri in debris)
			{
				Kill(debri);
			}
			debris.Clear();
		}

		private void Update()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected I4, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			bool num = VoidDirector.HoleCount > 0 && Plugin.RipScenery.Value;
			UpdateDebris(Time.deltaTime);
			if (!num)
			{
				return;
			}
			int num2 = -1;
			try
			{
				if (MapHandler.ExistsAndInitialized)
				{
					num2 = (int)MapHandler.CurrentSegmentNumber;
				}
			}
			catch
			{
			}
			if (!scanning && (!scanned || num2 != scannedSeg || Time.time > rescanAt))
			{
				((MonoBehaviour)this).StartCoroutine(Scan(num2));
			}
			tick -= Time.deltaTime;
			if (!(tick > 0f) && scanned && (VoidDirector.State.phase == 3 || VoidDirector.State.phase == 4))
			{
				tick = 0.2f;
				for (int i = 0; i < VoidDirector.HoleCount; i++)
				{
					Consider(VoidDirector.HolePos(i), VoidDirector.HoleRadius(i));
				}
			}
		}

		private IEnumerator Scan(int seg)
		{
			scanning = true;
			if (seg != scannedSeg)
			{
				followups = 0;
			}
			scannedSeg = seg;
			followups++;
			rescanAt = ((followups == 1) ? (Time.time + 10f) : ((followups == 2) ? (Time.time + 30f) : float.MaxValue));
			MeshRenderer[] all = Object.FindObjectsByType<MeshRenderer>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			Dictionary<long, List<Entry>> fresh = new Dictionary<long, List<Entry>>();
			int mapLayer = LayerMask.NameToLayer("Map");
			int n = 0;
			int kept = 0;
			MeshRenderer[] array = all;
			foreach (MeshRenderer r in array)
			{
				int num = n + 1;
				n = num;
				if (num % 2000 == 0)
				{
					yield return null;
				}
				if ((Object)(object)r == (Object)null || !((Renderer)r).enabled || gone.Contains(((Object)r).GetInstanceID()) || ((1 << ((Component)r).gameObject.layer) & maskSkipLayers) != 0)
				{
					continue;
				}
				Material sharedMaterial = ((Renderer)r).sharedMaterial;
				if ((Object)(object)sharedMaterial != (Object)null && ((Object)sharedMaterial).name.StartsWith("DoS_"))
				{
					continue;
				}
				Transform parent = ((Component)r).transform.parent;
				if ((Object)(object)parent != (Object)null && ((Object)parent).name == "DoS_Debris")
				{
					continue;
				}
				Bounds bounds = ((Renderer)r).bounds;
				float num2 = Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z));
				if (!(num2 < 0.3f) && !(num2 > 30f) && (!(((Bounds)(ref bounds)).size.y < 0.22f * Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z)) || !(Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) > 5f)))
				{
					long key = Key(((Bounds)(ref bounds)).center);
					if (!fresh.TryGetValue(key, out var value))
					{
						value = (fresh[key] = new List<Entry>());
					}
					value.Add(new Entry
					{
						r = (Renderer)(object)r,
						b = bounds,
						map = (((Component)r).gameObject.layer == mapLayer && (Object)(object)((Component)r).GetComponentInParent<LODGroup>() == (Object)null)
					});
					kept++;
				}
			}
			camps.Clear();
			Campfire[] array2 = Object.FindObjectsByType<Campfire>((FindObjectsSortMode)0);
			foreach (Campfire val in array2)
			{
				camps.Add(((Component)val).transform.position);
			}
			RespawnChest[] array3 = Object.FindObjectsByType<RespawnChest>((FindObjectsSortMode)0);
			foreach (RespawnChest val2 in array3)
			{
				camps.Add(((Component)val2).transform.position);
			}
			grid.Clear();
			foreach (KeyValuePair<long, List<Entry>> item in fresh)
			{
				grid[item.Key] = item.Value;
			}
			scanned = true;
			scanning = false;
			Plugin.D($"Uprooter indexed {kept}/{all.Length} renderers, {camps.Count} camp spots protected.");
		}

		private static long Key(Vector3 p)
		{
			//IL_0000: 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)
			return ((long)Mathf.FloorToInt(p.x / 16f) << 32) ^ (uint)Mathf.FloorToInt(p.z / 16f);
		}

		private void Consider(Vector3 p, float r)
		{
			//IL_0047: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			if (r <= 0.05f)
			{
				return;
			}
			float num = VoidDirector.PullRange(r);
			float reach = num - r;
			float num2 = ((VoidDirector.State.ripMul <= 0f) ? 1f : VoidDirector.State.ripMul);
			float maxRip = (2.5f + r * 1.6f) * num2;
			int num3 = Mathf.FloorToInt((p.x - num - 15f) / 16f);
			int num4 = Mathf.FloorToInt((p.x + num + 15f) / 16f);
			int num5 = Mathf.FloorToInt((p.z - num - 15f) / 16f);
			int num6 = Mathf.FloorToInt((p.z + num + 15f) / 16f);
			int budget = (Modes.Apocalypse(VoidDirector.State.mode) ? 30 : ((r > 50f) ? 12 : 4));
			if ((long)(num4 - num3 + 1) * (long)(num6 - num5 + 1) > grid.Count)
			{
				foreach (List<Entry> value2 in grid.Values)
				{
					if (ConsiderList(value2, p, r, reach, maxRip, ref budget))
					{
						break;
					}
				}
				return;
			}
			for (int i = num3; i <= num4; i++)
			{
				for (int j = num5; j <= num6; j++)
				{
					long key = ((long)i << 32) ^ (uint)j;
					if (grid.TryGetValue(key, out var value) && ConsiderList(value, p, r, reach, maxRip, ref budget))
					{
						return;
					}
				}
			}
		}

		private bool ConsiderList(List<Entry> list, Vector3 p, float r, float reach, float maxRip, ref int budget)
		{
			//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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			for (int num = list.Count - 1; num >= 0; num--)
			{
				Entry entry = list[num];
				Renderer r2 = entry.r;
				if ((Object)(object)r2 == (Object)null || gone.Contains(((Object)r2).GetInstanceID()) || !r2.enabled)
				{
					list.RemoveAt(num);
				}
				else if (((Component)r2).gameObject.activeInHierarchy)
				{
					Bounds b = entry.b;
					float num2 = Mathf.Sqrt(((Bounds)(ref b)).SqrDistance(p)) - r;
					if (!(num2 > reach))
					{
						float num3 = Mathf.Max(((Bounds)(ref b)).size.x, Mathf.Max(((Bounds)(ref b)).size.y, ((Bounds)(ref b)).size.z));
						bool flag = Modes.Apocalypse(VoidDirector.State.mode);
						if (!(num3 > ((!entry.map) ? (flag ? 30f : 11f) : (flag ? 6f : 4.5f))))
						{
							bool flag2 = num2 < 0.25f && num3 < maxRip * 2.5f;
							float num4 = (flag ? reach : (reach * Mathf.Clamp(0.9f - num3 / maxRip * 0.6f, 0.15f, 0.9f)));
							if (flag2 || ((flag || !(num3 > maxRip)) && !(num2 > num4)))
							{
								list.RemoveAt(num);
								if (Rip(r2, flag2, debris.Count >= Plugin.MaxDebris.Value))
								{
									budget--;
								}
								if (budget <= 0)
								{
									return true;
								}
							}
						}
					}
				}
			}
			return false;
		}

		private bool Rip(Renderer seed, bool instant, bool dissolve)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)seed).transform;
			List<Renderer> list = new List<Renderer>();
			LODGroup componentInParent = ((Component)seed).GetComponentInParent<LODGroup>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				transform = ((Component)componentInParent).transform;
				LOD[] lODs = componentInParent.GetLODs();
				if (lODs.Length != 0)
				{
					Renderer[] renderers = lODs[0].renderers;
					foreach (Renderer val in renderers)
					{
						if ((Object)(object)val != (Object)null)
						{
							list.Add(val);
						}
					}
				}
				LOD[] array = lODs;
				for (int i = 0; i < array.Length; i++)
				{
					Renderer[] renderers = array[i].renderers;
					foreach (Renderer val2 in renderers)
					{
						if ((Object)(object)val2 != (Object)null)
						{
							gone.Add(((Object)val2).GetInstanceID());
						}
					}
				}
			}
			if (list.Count == 0)
			{
				list.Add(seed);
			}
			gone.Add(((Object)seed).GetInstanceID());
			if (Protected(transform))
			{
				return false;
			}
			Bounds bounds = list[0].bounds;
			foreach (Renderer item2 in list)
			{
				((Bounds)(ref bounds)).Encapsulate(item2.bounds);
			}
			float num = Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z));
			if (Plugin.ProtectCamps.Value)
			{
				foreach (Vector3 camp in camps)
				{
					Vector3 val3 = camp - ((Bounds)(ref bounds)).center;
					if (((Vector3)(ref val3)).sqrMagnitude < 64f)
					{
						return false;
					}
				}
			}
			Bounds local = default(Bounds);
			Transform val4 = (dissolve ? null : MakeProxy(list, ((Bounds)(ref bounds)).center, out local));
			if ((Object)(object)componentInParent != (Object)null)
			{
				LOD[] array = componentInParent.GetLODs();
				for (int i = 0; i < array.Length; i++)
				{
					Renderer[] renderers = array[i].renderers;
					foreach (Renderer val5 in renderers)
					{
						if ((Object)(object)val5 != (Object)null)
						{
							val5.enabled = false;
						}
					}
				}
				componentInParent.enabled = false;
			}
			foreach (Renderer item3 in list)
			{
				item3.enabled = false;
			}
			Collider[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			Transform parent = transform.parent;
			if ((Object)(object)parent != (Object)null && (Object)(object)componentInParent == (Object)null && (Object)(object)((Component)parent).GetComponent<Collider>() != (Object)null && ((Component)parent).GetComponentsInChildren<Renderer>().Length <= 2)
			{
				componentsInChildren = ((Component)parent).GetComponents<Collider>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].enabled = false;
				}
			}
			if ((Object)(object)val4 == (Object)null)
			{
				VoidDirector.FizzleFx(((Bounds)(ref bounds)).center, Mathf.Min(3f, num * 0.4f), sound: true);
				return true;
			}
			Debris item = new Debris
			{
				t = val4,
				basePos = val4.position,
				size = num,
				local = local,
				shakeFor = (instant ? 0f : (Modes.Apocalypse(VoidDirector.State.mode) ? 0.12f : (0.5f + Mathf.Min(2f, num * 0.15f)))),
				spinAxis = Random.onUnitSphere,
				spin = Random.Range(30f, 140f) / Mathf.Max(1f, num * 0.4f)
			};
			debris.Add(item);
			Plugin.D($"Ripping '{((Object)transform).name}' ({num:0.0} m)");
			return true;
		}

		private static bool Protected(Transform t)
		{
			if (((Object)t.root).name == "DoS_Debris")
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<Item>() != (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<Character>() != (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<Campfire>() != (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<RespawnChest>() != (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<Luggage>() != (Object)null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<PhotonView>() != (Object)null)
			{
				return true;
			}
			if (((Component)t).GetComponentInParent<IInteractible>() != null)
			{
				return true;
			}
			if ((Object)(object)((Component)t).GetComponentInParent<VoidHole>() != (Object)null || (Object)(object)((Component)t).GetComponentInParent<Shockwave>() != (Object)null || (Object)(object)((Component)t).GetComponentInParent<RisingOrb>() != (Object)null)
			{
				return true;
			}
			return false;
		}

		private Transform MakeProxy(List<Renderer> rends, Vector3 center, out Bounds local)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = new GameObject("DoS_Debris").transform;
			transform.position = center;
			int num = 0;
			local = new Bounds(Vector3.zero, Vector3.zero);
			bool flag = false;
			foreach (Renderer rend in rends)
			{
				MeshFilter component = ((Component)rend).GetComponent<MeshFilter>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
				{
					continue;
				}
				GameObject val = new GameObject("Piece");
				Mesh val2 = component.sharedMesh;
				if (rend.isPartOfStaticBatch)
				{
					val2 = CutFromBatch(component.sharedMesh, (MeshRenderer)rend);
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					val.transform.position = Vector3.zero;
					val.transform.rotation = Quaternion.identity;
					val.transform.localScale = Vector3.one;
				}
				else
				{
					val.transform.position = ((Component)rend).transform.position;
					val.transform.rotation = ((Component)rend).transform.rotation;
					val.transform.localScale = ((Component)rend).transform.lossyScale;
				}
				val.transform.SetParent(transform, true);
				val.AddComponent<MeshFilter>().sharedMesh = val2;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterials = rend.sharedMaterials;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1;
				num++;
				Bounds bounds = val2.bounds;
				for (int i = 0; i < 8; i++)
				{
					Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
					Vector3 val4 = transform.InverseTransformPoint(val.transform.TransformPoint(val3));
					if (!flag)
					{
						local = new Bounds(val4, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref local)).Encapsulate(val4);
					}
				}
			}
			if (num == 0)
			{
				Object.Destroy((Object)(object)((Component)transform).gameObject);
				return null;
			}
			return transform;
		}

		private Mesh CutFromBatch(Mesh batch, MeshRenderer r)
		{
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			if (!batch.isReadable)
			{
				return null;
			}
			if (!batchCache.TryGetValue(batch, out var value))
			{
				value = new MeshCache
				{
					v = batch.vertices,
					n = batch.normals,
					uv = batch.uv,
					c = batch.colors
				};
				batchCache[batch] = value;
			}
			int subMeshStartIndex = r.subMeshStartIndex;
			int num = ((Renderer)r).sharedMaterials.Length;
			if (subMeshStartIndex < 0 || subMeshStartIndex + num > batch.subMeshCount)
			{
				return null;
			}
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<Color> list4 = new List<Color>();
			List<int[]> list5 = new List<int[]>();
			for (int i = 0; i < num; i++)
			{
				int[] indices = batch.GetIndices(subMeshStartIndex + i);
				int[] array = new int[indices.Length];
				for (int j = 0; j < indices.Length; j++)
				{
					int num2 = indices[j];
					if (!dictionary.TryGetValue(num2, out var value2))
					{
						value2 = (dictionary[num2] = list.Count);
						list.Add(value.v[num2]);
						if (value.n != null && value.n.Length == value.v.Length)
						{
							list2.Add(value.n[num2]);
						}
						if (value.uv != null && value.uv.Length == value.v.Length)
						{
							list3.Add(value.uv[num2]);
						}
						if (value.c != null && value.c.Length == value.v.Length)
						{
							list4.Add(value.c[num2]);
						}
					}
					array[j] = value2;
				}
				list5.Add(array);
			}
			if (list.Count == 0)
			{
				return null;
			}
			Mesh val = new Mesh
			{
				name = "DoS_Cut"
			};
			if (list.Count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(list);
			if (list2.Count == list.Count)
			{
				val.SetNormals(list2);
			}
			if (list3.Count == list.Count)
			{
				val.SetUVs(0, list3);
			}
			if (list4.Count == list.Count)
			{
				val.SetColors(list4);
			}
			val.subMeshCount = list5.Count;
			for (int k = 0; k < list5.Count; k++)
			{
				val.SetTriangles(list5[k], k);
			}
			val.RecalculateBounds();
			if (list2.Count != list.Count)
			{
				val.RecalculateNormals();
			}
			return val;
		}

		private static void Kill(Debris d)
		{
			if ((Object)(object)d.t == (Object)null)
			{
				return;
			}
			MeshFilter[] componentsInChildren = ((Component)d.t).GetComponentsInChildren<MeshFilter>();
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val.sharedMesh != (Object)null && ((Object)val.sharedMesh).name == "DoS_Cut")
				{
					Object.Destroy((Object)(object)val.sharedMesh);
				}
			}
			Object.Destroy((Object)(object)((Component)d.t).gameObject);
		}

		private void MoveWithCollision(Debris d, float dt, float distToHole, float r)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01c9: 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_006a: 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_0074: 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_0091: 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_00ac: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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)
			Vector3 position = d.t.position;
			Vector3 val = d.vel * dt;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude > 0.0001f && d.groundHits < 8 && distToHole > r * 2f + 2f)
			{
				float num = Mathf.Clamp(d.size * 0.2f, 0.15f, 1.2f);
				RaycastHit val2 = default(RaycastHit);
				if (Physics.SphereCast(position, num, val / magnitude, ref val2, magnitude, LayerMask.op_Implicit(HelperFunctions.terrainMapMask), (QueryTriggerInteraction)1))
				{
					float num2 = Vector3.Dot(d.vel, ((RaycastHit)(ref val2)).normal);
					d.t.position = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * (num + 0.02f);
					if (num2 < 0f)
					{
						d.vel = (d.vel - 1.35f * num2 * ((RaycastHit)(ref val2)).normal) * 0.7f;
					}
					d.groundHits++;
					if (0f - num2 > 4f && Time.time - lastCrack > 0.12f)
					{
						lastCrack = Time.time;
						VoidAudio.Play3D(VoidAudio.Thud, ((RaycastHit)(ref val2)).point, Mathf.Clamp(0.25f + d.size * 0.06f - num2 * 0.02f, 0.25f, 1f), 60f, Mathf.Clamp(1.3f - d.size * 0.05f, 0.6f, 1.3f));
						VoidDirector.FizzleFx(((RaycastHit)(ref val2)).point, Mathf.Min(1f, d.size * 0.12f), sound: false);
					}
					return;
				}
			}
			d.t.position = position + val;
		}

		private void HitScouts(Debris d, float dt)
		{
			//IL_0052: 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_0063: 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_0073: 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_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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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)
			//IL_012f: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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)
			if (!Plugin.DebrisHits.Value)
			{
				return;
			}
			d.hitCd -= dt;
			if (d.hitCd > 0f)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || localCharacter.data.dead)
			{
				return;
			}
			Vector3 val = d.t.TransformPoint(((Bounds)(ref d.local)).center);
			Vector3 val2 = Vector3.Scale(((Bounds)(ref d.local)).extents, d.t.lossyScale);
			float num = ((Vector3)(ref val2)).magnitude + 1.2f;
			Vector3 val3 = localCharacter.Center - val;
			if (((Vector3)(ref val3)).sqrMagnitude > num * num)
			{
				return;
			}
			int num2 = Physics.OverlapBoxNonAlloc(val, val2, s_hits, d.t.rotation, LayerMask.op_Implicit(HelperFunctions.CharacterMask), (QueryTriggerInteraction)1);
			for (int i = 0; i < num2; i++)
			{
				if (!((Object)(object)s_hits[i] == (Object)null) && !((Object)(object)((Component)s_hits[i]).GetComponentInParent<Character>() != (Object)(object)localCharacter))
				{
					float sizeK = Mathf.Clamp(d.size * 0.25f * d.t.localScale.x, 0.3f, 2f);
					Vector3 at = s_hits[i].ClosestPoint(val);
					VoidDirector.Instance?.DebrisHit(localCharacter, d.vel, sizeK, at);
					d.hitCd = 1.2f;
					Vector3 val4 = d.vel * 0.35f;
					val3 = val - localCharacter.Center;
					d.vel = val4 + ((Vector3)(ref val3)).normalized * 2f;
					break;
				}
			}
		}

		private void UpdateDebris(float dt)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e7: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: 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_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_01a3: Unknown result type (might be due to invalid