Decompiled source of ColliderPlugin v2.0.1

ColliderPlugin.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.Singletons;
using HarmonyLib;
using ModdingTales;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ColliderExPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("ColliderExPlugin")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("ColliderExPlugin")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("2.0.1.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.collider", "Collider Plugin", "2.0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ColliderExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(CreatureBoardAsset), "OnBaseLoaded")]
	public class PatchOnBaseLoaded
	{
		public static void Postfix(CreatureBoardAsset __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			string name = __instance.Name;
			CreatureGuid creatureId = __instance.CreatureId;
			LoggingPlugin.LogDebug(name + " (" + ((object)(CreatureGuid)(ref creatureId)).ToString() + "): Checking For Collider");
			string[] obj = new string[5] { __instance.Name, " (", null, null, null };
			creatureId = __instance.CreatureId;
			obj[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
			obj[3] = "): Not ANGEL Asset? ";
			obj[4] = (__instance.Link == null || !__instance.Link.Contains("ANGEL")).ToString();
			LoggingPlugin.LogDebug(string.Concat(obj));
			if (__instance.Link == null || !__instance.Link.Contains("ANGEL"))
			{
				((MonoBehaviour)_self).StartCoroutine(AddColliderIfNone(__instance, 0.01f));
			}
			else
			{
				((MonoBehaviour)_self).StartCoroutine(AddColliderIfNone(__instance));
			}
		}

		public static IEnumerator AddColliderIfNone(CreatureBoardAsset __instance, float delay = 1f)
		{
			yield return (object)new WaitForSeconds(delay);
			if ((Object)(object)((Component)__instance).gameObject.GetComponentInChildren<BoxCollider>() == (Object)null)
			{
				string name = __instance.Name;
				CreatureGuid creatureId = __instance.CreatureId;
				LoggingPlugin.LogDebug(name + " (" + ((object)(CreatureGuid)(ref creatureId)).ToString() + "): Adding New Box Collider");
				BuildBoxCollider(__instance);
			}
		}
	}

	[HarmonyPatch(typeof(CreatureBoardAsset), "Pickup")]
	public class PatchPickedUp
	{
		public static void Postfix(CreatureBoardAsset __instance)
		{
			((Component)__instance).transform.SetParent((Transform)null, true);
			if (viewColliders)
			{
				DestroyColliders();
			}
		}
	}

	[HarmonyPatch(typeof(CreatureBoardAsset), "DropCommon")]
	public static class PatchDropCommon
	{
		public static bool Prefix(CreatureBoardAsset __instance, ref Vector3 dropDestination, float height)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: 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_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			string[] obj = new string[7] { __instance.Name, " (", null, null, null, null, null };
			CreatureGuid creatureId = __instance.CreatureId;
			obj[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
			obj[3] = "): Is Being Dropped To ";
			obj[4] = ((object)(Vector3)(ref dropDestination)).ToString();
			obj[5] = " From Height ";
			obj[6] = height.ToString();
			LoggingPlugin.LogDebug(string.Concat(obj));
			BoxCollider componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<BoxCollider>();
			if ((Object)(object)componentInChildren == (Object)null)
			{
				string name = __instance.Name;
				creatureId = __instance.CreatureId;
				LoggingPlugin.LogDebug(name + " (" + ((object)(CreatureGuid)(ref creatureId)).ToString() + "): Dropping Object Without Collider");
			}
			else
			{
				float y = dropDestination.y;
				float y2 = ((Component)((MovableBoardAsset)__instance).Rotator).transform.position.y;
				CreatureBoardAsset val = null;
				foreach (CreatureBoardAsset item in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
				{
					if (!(__instance.CreatureId != item.CreatureId))
					{
						continue;
					}
					if (((Component)((MovableBoardAsset)item).Rotator).transform.position.y < ((Component)((MovableBoardAsset)__instance).Rotator).transform.position.y)
					{
						string[] obj2 = new string[8] { __instance.Name, " (", null, null, null, null, null, null };
						creatureId = __instance.CreatureId;
						obj2[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
						obj2[3] = "): Getting ";
						obj2[4] = item.Name;
						obj2[5] = " (";
						creatureId = item.CreatureId;
						obj2[6] = ((object)(CreatureGuid)(ref creatureId)).ToString();
						obj2[7] = ") Colliders";
						LoggingPlugin.LogDebug(string.Concat(obj2));
						BoxCollider[] componentsInChildren = ((Component)item).GetComponentsInChildren<BoxCollider>();
						foreach (BoxCollider val2 in componentsInChildren)
						{
							string[] obj3 = new string[11]
							{
								__instance.Name, " (", null, null, null, null, null, null, null, null,
								null
							};
							creatureId = __instance.CreatureId;
							obj3[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
							obj3[3] = "): ";
							obj3[4] = item.Name;
							obj3[5] = " (";
							creatureId = item.CreatureId;
							obj3[6] = ((object)(CreatureGuid)(ref creatureId)).ToString();
							obj3[7] = ") Collider ";
							obj3[8] = ((Object)val2).name;
							obj3[9] = " Intersects? ";
							Bounds bounds = ((Collider)componentInChildren).bounds;
							obj3[10] = ((Bounds)(ref bounds)).Intersects(((Collider)val2).bounds).ToString();
							LoggingPlugin.LogTrace(string.Concat(obj3));
							if (!DropsThrough(((Component)((MovableBoardAsset)__instance).Rotator).transform.position, val2))
							{
								continue;
							}
							string[] obj4 = new string[9] { __instance.Name, " (", null, null, null, null, null, null, null };
							creatureId = __instance.CreatureId;
							obj4[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
							obj4[3] = "): Intersects With Asset ";
							obj4[4] = ((Object)((Component)val2).gameObject).name;
							obj4[5] = " (";
							obj4[6] = ((Object)val2).name;
							obj4[7] = ") With Top At ";
							bounds = ((Collider)val2).bounds;
							obj4[8] = ((Bounds)(ref bounds)).max.y.ToString();
							LoggingPlugin.LogTrace(string.Concat(obj4));
							bounds = ((Collider)val2).bounds;
							if (((Bounds)(ref bounds)).max.y > y)
							{
								bounds = ((Collider)val2).bounds;
								if (((Bounds)(ref bounds)).max.y < y2)
								{
									bounds = ((Collider)val2).bounds;
									y = ((Bounds)(ref bounds)).max.y;
									val = item;
								}
							}
						}
					}
					else
					{
						string[] obj5 = new string[8] { __instance.Name, " (", null, null, null, null, null, null };
						creatureId = __instance.CreatureId;
						obj5[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
						obj5[3] = "): Ignoring Child ";
						obj5[4] = item.Name;
						obj5[5] = " (";
						creatureId = item.CreatureId;
						obj5[6] = ((object)(CreatureGuid)(ref creatureId)).ToString();
						obj5[7] = ")";
						LoggingPlugin.LogDebug(string.Concat(obj5));
					}
				}
				dropDestination = new Vector3(dropDestination.x, y, dropDestination.z);
				if ((Object)(object)val != (Object)null)
				{
					((Component)__instance).transform.SetParent(((Component)((MovableBoardAsset)val).Rotator).transform, true);
				}
				if (viewColliders)
				{
					((MonoBehaviour)_self).StartCoroutine(DrawColliders());
				}
				_ = LocalClient.SelectedCreatureId;
				if (LocalClient.SelectedCreatureId == __instance.CreatureId)
				{
					DropInfo dropInfo = new DropInfo();
					creatureId = __instance.CreatureId;
					dropInfo.asset = ((object)(CreatureGuid)(ref creatureId)).ToString();
					dropInfo.dropDestinationX = dropDestination.x;
					dropInfo.dropDestinationY = dropDestination.y;
					dropInfo.dropDestinationZ = dropDestination.z;
					dropInfo.height = height;
					DropInfo dropInfo2 = dropInfo;
					creatureId = __instance.CreatureId;
					AssetDataPlugin.SetInfo(((object)(CreatureGuid)(ref creatureId)).ToString(), "org.lordashes.plugins.collider", JsonConvert.SerializeObject((object)dropInfo2), false);
				}
			}
			return true;
		}
	}

	private class DropInfo
	{
		public string asset { get; set; } = "";


		public float dropDestinationX { get; set; }

		public float dropDestinationY { get; set; }

		public float dropDestinationZ { get; set; }

		public float height { get; set; }
	}

	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static GameObject FindInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject FindInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done, partial: true);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static GameObject[] FindAllInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done, partial: true);
			return results.ToArray();
		}

		public static GameObject FindWithComponentInHierarchy(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllWithComponentInHierarchy<T>(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static void Traverse(Transform root, string seekName, string seekType, bool single, ref List<GameObject> results, ref bool done, bool partial = false)
		{
			try
			{
				if ((seekName == null || seekName == ((Object)((Component)root).gameObject).name || (partial && ((Object)((Component)root).gameObject).name.Contains(seekName))) && (seekType == null || (Object)(object)((Component)root).GetComponent(seekType) != (Object)null))
				{
					LoggingPlugin.LogTrace("Matched '" + ((Object)((Component)root).gameObject).name + "'");
					results.Add(((Component)root).gameObject);
					if (single)
					{
						done = true;
						return;
					}
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (!done)
					{
						Traverse(item, seekName, seekType, single, ref results, ref done, partial);
					}
				}
			}
			catch
			{
			}
		}

		public static object LookUp(in Dictionary<string, object> dictionary, string key)
		{
			foreach (KeyValuePair<string, object> item in dictionary)
			{
				if (item.Key.ToUpper() == key.ToUpper())
				{
					return item.Value;
				}
			}
			return null;
		}

		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.Initialize(plugin, new ManualLogSource("Collider Plugin"), text, false);
		}
	}

	public const string Name = "Collider Plugin";

	public const string Guid = "org.lordashes.plugins.collider";

	public const string Version = "2.0.1.0";

	public const string Author = "Lord Ashes";

	public static ColliderExPlugin _self;

	private ConfigEntry<KeyboardShortcut> toggleColliderView;

	private static bool viewColliders;

	private void ColliderLocationUpdate(DatumChange change)
	{
		//IL_0030: 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_004e: 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)
		LoggingPlugin.LogDebug(change.source + ": Repositioning");
		DropInfo dropInfo = JsonConvert.DeserializeObject<DropInfo>(change.value.ToString());
		CreatureBoardAsset val = null;
		CreaturePresenter.TryGetAsset(new CreatureGuid(dropInfo.asset), ref val);
		string name = val.Name;
		CreatureGuid creatureId = val.CreatureId;
		LoggingPlugin.LogDebug(name + " (" + ((object)(CreatureGuid)(ref creatureId)).ToString() + "): Dropping");
		((Component)val).gameObject.transform.position = new Vector3(dropInfo.dropDestinationX, dropInfo.dropDestinationY, dropInfo.dropDestinationZ);
	}

	public static bool DropsThrough(Vector3 droppingObjectPos, BoxCollider collider)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		Tuple<Vector3, Vector3> worldBounds = GetWorldBounds(collider);
		if (droppingObjectPos.x < worldBounds.Item1.x)
		{
			return false;
		}
		if (droppingObjectPos.x > worldBounds.Item2.x)
		{
			return false;
		}
		if (droppingObjectPos.z < worldBounds.Item1.z)
		{
			return false;
		}
		if (droppingObjectPos.z > worldBounds.Item2.z)
		{
			return false;
		}
		return true;
	}

	private static void BuildBoxCollider(CreatureBoardAsset __instance)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: 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_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_00e1: 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_00d4: 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_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		string name = __instance.Name;
		CreatureGuid creatureId = __instance.CreatureId;
		LoggingPlugin.LogDebug(name + " (" + ((object)(CreatureGuid)(ref creatureId)).ToString() + "): Adding Mesh Sized BoxCollider");
		BoxCollider val = ((Component)__instance).gameObject.AddComponent<BoxCollider>();
		Vector3 zero = Vector3.zero;
		Vector3 zero2 = Vector3.zero;
		Renderer[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<Renderer>();
		foreach (Renderer val2 in componentsInChildren)
		{
			Bounds bounds = val2.bounds;
			Vector3 val3 = ((Component)__instance).transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
			Vector3 val4 = ((Component)__instance).transform.InverseTransformVector(((Bounds)(ref bounds)).size);
			if (val4.x > zero.x)
			{
				zero.x = val4.x;
			}
			if (val4.y > zero.y)
			{
				zero.y = val4.y;
			}
			if (val4.z > zero.z)
			{
				zero.z = val4.z;
			}
			if (val3.x > zero2.x)
			{
				zero2.x = val3.x;
			}
			if (val3.y > zero2.y)
			{
				zero2.y = val3.y;
			}
			if (val3.z > zero2.z)
			{
				zero2.z = val3.z;
			}
		}
		val.center = zero2;
		val.size = zero;
		((Object)val).name = "ColliderExPlugin:" + __instance.Name;
		string[] obj = new string[5] { __instance.Name, " (", null, null, null };
		creatureId = __instance.CreatureId;
		obj[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj[3] = "): Size = ";
		Vector3 val5 = val.size;
		obj[4] = ((object)(Vector3)(ref val5)).ToString();
		LoggingPlugin.LogTrace(string.Concat(obj));
		string[] obj2 = new string[5] { __instance.Name, " (", null, null, null };
		creatureId = __instance.CreatureId;
		obj2[2] = ((object)(CreatureGuid)(ref creatureId)).ToString();
		obj2[3] = "): Center = ";
		val5 = val.center;
		obj2[4] = ((object)(Vector3)(ref val5)).ToString();
		LoggingPlugin.LogTrace(string.Concat(obj2));
	}

	public static void DestroyColliders()
	{
		LoggingPlugin.LogDebug("Destroying Collider Traces");
		while ((Object)(object)GameObject.Find("DebugLine") != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)GameObject.Find("DebugLine"));
		}
	}

	public static IEnumerator DrawColliders(float delay = 1f)
	{
		yield return (object)new WaitForSeconds(delay);
		DestroyColliders();
		LoggingPlugin.LogDebug("Creating Collider Traces");
		foreach (CreatureBoardAsset asset in (IEnumerable<CreatureBoardAsset>)CreaturePresenter.GetTempReadOnlyViewOfAllCreatureAssets())
		{
			BoxCollider[] componentsInChildren = ((Component)asset).GetComponentsInChildren<BoxCollider>();
			foreach (BoxCollider collider in componentsInChildren)
			{
				DrawBoxCollider(collider, Color.red);
			}
		}
	}

	public static void DrawBoxCollider(BoxCollider box, Color color)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0056: 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_005e: 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_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_007f: 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_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_0122: 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_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: 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_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: 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_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_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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: 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_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: 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_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)box).transform;
		Vector3 center = box.center;
		Vector3 size = box.size;
		Vector3[] array = (Vector3[])(object)new Vector3[8];
		Vector3 val = size * 0.5f;
		array[0] = center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z);
		array[1] = center + new Vector3(val.x, 0f - val.y, 0f - val.z);
		array[2] = center + new Vector3(val.x, 0f - val.y, val.z);
		array[3] = center + new Vector3(0f - val.x, 0f - val.y, val.z);
		array[4] = center + new Vector3(0f - val.x, val.y, 0f - val.z);
		array[5] = center + new Vector3(val.x, val.y, 0f - val.z);
		array[6] = center + new Vector3(val.x, val.y, val.z);
		array[7] = center + new Vector3(0f - val.x, val.y, val.z);
		for (int i = 0; i < 8; i++)
		{
			array[i] = transform.TransformPoint(array[i]);
		}
		DrawLine(array[0], array[1], color);
		DrawLine(array[1], array[2], color);
		DrawLine(array[2], array[3], color);
		DrawLine(array[3], array[0], color);
		DrawLine(array[4], array[5], color);
		DrawLine(array[5], array[6], color);
		DrawLine(array[6], array[7], color);
		DrawLine(array[7], array[4], color);
		DrawLine(array[0], array[4], color);
		DrawLine(array[1], array[5], color);
		DrawLine(array[2], array[6], color);
		DrawLine(array[3], array[7], color);
	}

	public static GameObject DrawLine(Vector3 start, Vector3 end, Color color, float duration = 0.1f)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_001d: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("DebugLine");
		LineRenderer val2 = val.AddComponent<LineRenderer>();
		val2.positionCount = 2;
		val2.SetPosition(0, start);
		val2.SetPosition(1, end);
		((Renderer)val2).material = new Material(Shader.Find("Sprites/Default"));
		Color startColor = (val2.endColor = color);
		val2.startColor = startColor;
		float startWidth = (val2.endWidth = 0.02f);
		val2.startWidth = startWidth;
		((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val2).receiveShadows = false;
		return val;
	}

	private static Tuple<Vector3, Vector3> GetWorldBounds(BoxCollider box)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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_007c: 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_0083: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: 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_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: 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_0159: 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_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: 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_01bf: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: 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)
		Transform transform = ((Component)box).transform;
		Vector3 center = box.center;
		Vector3 size = box.size;
		Vector3 val = size * 0.5f;
		Vector3[] array = (Vector3[])(object)new Vector3[8]
		{
			center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z),
			center + new Vector3(val.x, 0f - val.y, 0f - val.z),
			center + new Vector3(val.x, 0f - val.y, val.z),
			center + new Vector3(0f - val.x, 0f - val.y, val.z),
			center + new Vector3(0f - val.x, val.y, 0f - val.z),
			center + new Vector3(val.x, val.y, 0f - val.z),
			center + new Vector3(val.x, val.y, val.z),
			center + new Vector3(0f - val.x, val.y, val.z)
		};
		for (int i = 0; i < 8; i++)
		{
			array[i] = transform.TransformPoint(array[i]);
		}
		Vector3 val2 = array[0];
		Vector3 val3 = array[0];
		Vector3[] array2 = array;
		foreach (Vector3 val4 in array2)
		{
			val2 = Vector3.Min(val2, val4);
			val3 = Vector3.Max(val3, val4);
		}
		return new Tuple<Vector3, Vector3>(val2, val3);
	}

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		Debug.Log((object)(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		toggleColliderView = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Settings", "Toggle Collider View", new KeyboardShortcut((KeyCode)56, (KeyCode[])(object)new KeyCode[1] { (KeyCode)305 }), (ConfigDescription)null);
		Harmony val = new Harmony("org.lordashes.plugins.collider");
		val.PatchAll();
		AssetDataPlugin.Subscribe("org.lordashes.plugins.collider", (Action<DatumChange>)ColliderLocationUpdate, (Func<DatumChange, bool>)Checker.CheckSourceAsCreature);
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void Update()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = toggleColliderView.Value;
		if (((KeyboardShortcut)(ref value)).IsUp())
		{
			viewColliders = !viewColliders;
			if (viewColliders)
			{
				((MonoBehaviour)_self).StartCoroutine(DrawColliders(0.01f));
			}
			else
			{
				DestroyColliders();
			}
		}
	}
}