Decompiled source of MageAPI v1.0.0

BepInEx/plugins/MageAPI/MageAPI.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using FishNet.Connection;
using FishNet.Managing;
using FishNet.Managing.Logging;
using FishNet.Managing.Server;
using FishNet.Object;
using FishNet.Transporting;
using HarmonyLib;
using MageAPI.Attributes;
using MageAPI.Enums;
using MageAPI.Helpers.Extensions;
using MageAPI.Interfaces;
using MageAPI.Managers;
using MageAPI.Modules;
using MageAPI.Modules.Events.Client;
using MageAPI.Modules.Events.Core;
using MageAPI.Modules.Events.Game;
using MageAPI.Modules.Events.Misc;
using MageAPI.Modules.Events.Player;
using MageAPI.Mono;
using MageAPI.Mono.Instance;
using MageAPI.Mono.Instance.Core;
using MageAPI.Patches.Client;
using Microsoft.CodeAnalysis;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("BepInEx")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MageAPI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9ffc80c2a008e24077abbdf15cc370b64a60b436")]
[assembly: AssemblyProduct("MageAPI")]
[assembly: AssemblyTitle("MageAPI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BlackMagicAPI
{
	internal static class ModMetaData
	{
		internal const string GUID = "com.d1gq.mage.api";

		internal const string PLUGIN_NAME = "MageAPI";

		internal const string VERSION = "1.0.0";
	}
}
namespace MageAPI
{
	[BepInProcess("MageArena")]
	[BepInPlugin("com.d1gq.mage.api", "MageAPI", "1.0.0")]
	public class MagePlugin : BaseUnityPlugin
	{
		internal static Harmony? Harmony;

		private ManualLogSource? _log;

		public static string modsync = "all";

		internal static MagePlugin Instance { get; private set; }

		internal static ManualLogSource Log => Instance._log;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			_log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Harmony = new Harmony("com.d1gq.mage.api");
			Harmony.PatchAll();
			MageAPI.Mono.Debugger.Create();
			CustomLayers.Init();
			((MonoBehaviour)this).StartCoroutine(CoAwake());
			Log.LogInfo((object)"MageAPI v1.0.0 loaded!");
		}

		private static IEnumerator CoAwake()
		{
			while (!Chainloader._loaded)
			{
				yield return null;
			}
			RpcHarmonyPatch.PatchAll();
			InstanceModulePatch.ItemInstancePatch.Patch();
			while (true)
			{
				NetworkManager? obj = NetworkManager.Instances.FirstOrDefault();
				if (!((Object)(object)((obj != null) ? obj.ClientManager : null) == (Object)null))
				{
					break;
				}
				yield return null;
			}
			NetworkManager.Instances.First().ClientManager.OnRemoteConnectionState += delegate(RemoteConnectionStateArgs args)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				if ((int)args.ConnectionState == 0)
				{
					IReadOnlyList<NetworkManager> instances = NetworkManager.Instances;
					if (instances != null)
					{
						NetworkManager? obj2 = instances.FirstOrDefault();
						NetworkConnection value = default(NetworkConnection);
						if (((obj2 == null) ? null : obj2.ServerManager?.Clients?.TryGetValue(args.ConnectionId, out value)) == true)
						{
							Events.Client.ClientDisconnectEvent.After.InvokeEvent((value, null));
						}
					}
				}
			};
		}

		internal static void Patch(MethodBase[] methods, HarmonyMethod? prefix = null, HarmonyMethod? postfix = null)
		{
			if (Harmony == null)
			{
				return;
			}
			try
			{
				foreach (MethodBase methodBase in methods)
				{
					if (methodBase != null)
					{
						Harmony.Patch(methodBase, prefix, postfix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to patch: {arg}");
			}
		}
	}
}
namespace MageAPI.Patches.Unity
{
	[HarmonyPatch(typeof(LayerMask))]
	internal static class LayerMaskPatch
	{
		[HarmonyPatch("NameToLayer")]
		[HarmonyPrefix]
		private static bool NameToLayer_Prefix(string layerName, ref int __result)
		{
			if (CustomLayers.NameToLayer(layerName, out var layer))
			{
				__result = layer;
				return false;
			}
			return true;
		}

		[HarmonyPatch("LayerToName")]
		[HarmonyPrefix]
		private static bool LayerToName_Prefix(int layer, ref string __result)
		{
			if (CustomLayers.LayerToName(layer, out string layerName))
			{
				__result = layerName;
				return false;
			}
			return true;
		}
	}
}
namespace MageAPI.Patches.Gameplay
{
	[HarmonyPatch]
	internal static class HealthModulePatch
	{
		[HarmonyPatch(typeof(PlayerMovement), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(PlayerMovement __instance)
		{
			HealthModule healthModule = AddHealthModule((MonoBehaviour)(object)__instance, "playerHealth");
			healthModule.EntityType = EntityType.Player;
			healthModule.HitCollider = __instance.hitboxcols.First();
			healthModule.RecreateHitColliders();
		}

		[HarmonyPatch(typeof(ShadowWizardAI), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(ShadowWizardAI __instance)
		{
			HealthModule healthModule = AddHealthModule((MonoBehaviour)(object)__instance, "hp");
			healthModule.EntityType = EntityType.ShadowWizard;
			healthModule.HitCollider = __instance.swizcols.First();
			healthModule.RecreateHitColliders();
		}

		[HarmonyPatch(typeof(SkelemageController), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(SkelemageController __instance)
		{
			HealthModule healthModule = AddHealthModule((MonoBehaviour)(object)__instance, "hp");
			healthModule.EntityType = EntityType.Skelemage;
			healthModule.HitCollider = healthModule.AllColliders.ElementAt(1);
			healthModule.RecreateHitColliders();
		}

		[HarmonyPatch(typeof(CastleWraithController), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(CastleWraithController __instance)
		{
			AddHealthModule((MonoBehaviour)(object)__instance, "Health").EntityType = EntityType.ShadowWizard;
		}

		[HarmonyPatch(typeof(DuendeManager), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(DuendeManager __instance)
		{
			DuendeController[] duende = __instance.Duende;
			foreach (DuendeController val in duende)
			{
				HealthModule healthModule = AddHealthModule((MonoBehaviour)(object)val, 25f, (Action)val.KillDuende);
				healthModule.EntityType = EntityType.Duende;
				healthModule.HitCollider = healthModule.AllColliders.ElementAt(1);
				healthModule.RecreateHitColliders();
			}
		}

		[HarmonyPatch(typeof(DuendeController), "RespawnDuende")]
		[HarmonyPostfix]
		private static void HealthModulePatch_RespawnDuende_Postfix(DuendeController __instance)
		{
			HealthModule.GetHealthModuleFromMono((MonoBehaviour)(object)__instance)?.ResetDeath();
		}

		[HarmonyPatch(typeof(BogFrogController), "Awake")]
		[HarmonyPostfix]
		private static void HealthModulePatch_Awake_Postfix(BogFrogController __instance)
		{
			BogFrogSingleController[] bogFrogs = __instance.BogFrogs;
			foreach (BogFrogSingleController val in bogFrogs)
			{
				HealthModule healthModule = AddHealthModule((MonoBehaviour)(object)val, (Action)val.hitbyspell);
				healthModule.EntityType = EntityType.BogFrog;
				healthModule.HitCollider = healthModule.AllColliders.ElementAt(1);
				healthModule.RecreateHitColliders();
			}
		}

		private static HealthModule AddHealthModule(MonoBehaviour mono, string name)
		{
			//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)
			HealthModule healthModule = new GameObject("HealthModule(" + ((object)mono).GetType().Name + ")")
			{
				layer = CustomLayers.Damageable
			}.AddComponent<HealthModule>();
			healthModule.Setup(mono, name);
			return healthModule;
		}

		private static HealthModule AddHealthModule(MonoBehaviour mono, float maxHP, Action kill)
		{
			//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)
			HealthModule healthModule = new GameObject("HealthModule(" + ((object)mono).GetType().Name + ")")
			{
				layer = CustomLayers.Damageable
			}.AddComponent<HealthModule>();
			healthModule.Setup(mono, maxHP, kill);
			return healthModule;
		}

		private static HealthModule AddHealthModule(MonoBehaviour mono, Action kill)
		{
			//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)
			HealthModule healthModule = new GameObject("HealthModule(" + ((object)mono).GetType().Name + ")")
			{
				layer = CustomLayers.Damageable
			}.AddComponent<HealthModule>();
			healthModule.Setup(mono, kill);
			return healthModule;
		}
	}
}
namespace MageAPI.Patches.Gameplay.Event
{
	[HarmonyPatch]
	internal static class EventPatch
	{
		[HarmonyPatch(typeof(PlayerMovement))]
		internal static class PlayerMovementPatch
		{
			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			private static void Update_Prefix(PlayerMovement __instance, ref bool __state)
			{
				__state = false;
				if (__instance.playerHealth <= 0f && !__instance.isDead)
				{
					if (Events.Player.PlayerDeathEvent.Before.InvokeEvent((__instance.GetPlayerInstance(), null)))
					{
						__state = true;
					}
					else if (__instance.playerHealth < 0.1f)
					{
						__instance.playerHealth = 0.1f;
					}
				}
			}

			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void Update_Postfix(PlayerMovement __instance, bool __state)
			{
				if (__state)
				{
					Events.Player.PlayerDeathEvent.After.InvokeEvent((__instance.GetPlayerInstance(), null));
				}
			}

			[HarmonyPatch("RespawnPlayer")]
			[HarmonyPostfix]
			private static void RespawnPlayer_Postfix(PlayerMovement __instance)
			{
				Events.Player.PlayerSpawnEvent.After.InvokeEvent((__instance.GetPlayerInstance(), null));
			}
		}

		[HarmonyPatch(typeof(PlayerInventory))]
		internal static class PlayerInventoryPatch
		{
			[HarmonyPatch("Pickup")]
			[HarmonyPostfix]
			private static void Pickup_Postfix(PlayerInventory __instance, GameObject itemObject)
			{
				IItemInteraction itemInteraction = default(IItemInteraction);
				if (itemObject.TryGetComponent<IItemInteraction>(ref itemInteraction))
				{
					Events.Player.PlayerPickupItemEvent.After.InvokeEvent((__instance.GetPlayerInstance(), itemInteraction.GetItemInstance()));
				}
			}

			[HarmonyPatch("Drop")]
			[HarmonyPrefix]
			private static void Pickup_Prefix(PlayerInventory __instance)
			{
				ItemInstance equippedItem = __instance.GetEquippedItem();
				if ((Object)(object)equippedItem != (Object)null)
				{
					Events.Player.PlayerPickupItemEvent.After.InvokeEvent((__instance.GetPlayerInstance(), equippedItem));
				}
			}
		}

		[HarmonyPatch(typeof(MainMenuManagerNetworked))]
		internal static class MainMenuManagerNetworkedPatch
		{
			[RpcHarmonyPatch("RpcLogic___ObsActuallyStart_2166136261")]
			[RpcHarmonyPostfix]
			private static void ObsActuallyStart_Postfix()
			{
				Events.Game.GameStartEvent.After.InvokeEvent();
			}
		}

		[HarmonyPatch(typeof(PlayerRespawnManager))]
		internal static class PlayerRespawnManagerPatch
		{
			[RpcHarmonyPatch("RpcLogic___ObsEndGame_3316948804")]
			[RpcHarmonyPostfix]
			private static void ObsEndGame_Postfix(int losingteam)
			{
				Events.Game.GameEndEvent.After.InvokeEvent((losingteam, null));
			}
		}

		[HarmonyPatch(typeof(VoiceControlListener))]
		internal static class VoiceControlListenerPatch
		{
			[HarmonyPatch("tryresult")]
			[HarmonyPrefix]
			private static bool tryresult_Prefix(VoiceControlListener __instance, ref string res, ref bool __state)
			{
				__state = false;
				ValueRef<string> valueRef = new ValueRef<string>(res);
				if (Events.Misc.VoiceControlListenerResultEvent.Before.InvokeEvent((valueRef, __instance)))
				{
					res = valueRef.Value;
					__state = true;
					return true;
				}
				return false;
			}

			[HarmonyPatch("tryresult")]
			[HarmonyPostfix]
			private static void tryresult_Postfix(VoiceControlListener __instance, string res, bool __state)
			{
				if (__state)
				{
					Events.Misc.VoiceControlListenerResultEvent.After.InvokeEvent((res, __instance));
				}
			}
		}

		[HarmonyPatch(typeof(BootstrapManager))]
		internal static class BootstrapManagerPatch
		{
			[HarmonyPatch("WaitForPotentialDelay")]
			[HarmonyPostfix]
			private static void WaitForPotentialDelay_Postfix(BootstrapManager __instance, [HarmonyArgument(0)] NetworkConnection conn, [HarmonyArgument(2)] string steamid, ref IEnumerator __result)
			{
				NetworkConnection conn2 = conn;
				BootstrapManager __instance2 = __instance;
				string steamid2 = steamid;
				IEnumerator waitForPotentialDelay = __result;
				__result = CoConnection();
				IEnumerator CoConnection()
				{
					if (!Events.Client.ClientConnectEvent.Before.InvokeEvent((conn2, null)) && __instance2._networkManager.IsHostStarted)
					{
						BootstrapNetworkManager.KickPlayer(steamid2);
						yield return (object)new WaitForSeconds(2f);
						conn2.Kick((KickReason)0, (LoggingType)3, "");
					}
					else
					{
						yield return waitForPotentialDelay;
						Events.Client.ClientConnectEvent.After.InvokeEvent((conn2, null));
					}
				}
			}
		}
	}
}
namespace MageAPI.Patches.Client
{
	[HarmonyPatch]
	internal static class InstanceModulePatch
	{
		internal static class ItemInstancePatch
		{
			private static bool _isPatched;

			public static void Patch()
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (!_isPatched)
				{
					_isPatched = true;
					MagePlugin.Patch(GetMethods(), null, new HarmonyMethod(typeof(ItemInstancePatch).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic)));
				}
			}

			private static MethodBase[] GetMethods()
			{
				List<MethodBase> list = new List<MethodBase>();
				Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly asm) => asm.GetName().Name == "Assembly-CSharp");
				int num;
				MethodBase[] array;
				if (assembly == null)
				{
					Debug.LogError((object)"Game assembly not found!");
					num = 0;
					array = new MethodBase[list.Count];
					{
						foreach (MethodBase item in list)
						{
							array[num] = item;
							num++;
						}
						return array;
					}
				}
				try
				{
					Type[] types = assembly.GetTypes();
					foreach (Type type in types)
					{
						if (!type.IsAbstract && !type.IsInterface && typeof(IItemInteraction).IsAssignableFrom(type))
						{
							MethodInfo method = type.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
							if (method != null && !method.IsAbstract)
							{
								list.Add(method);
							}
						}
					}
				}
				catch (Exception arg)
				{
					MagePlugin.Log.LogError((object)$"Error processing game assembly: {arg}");
				}
				num = 0;
				array = new MethodBase[list.Count];
				foreach (MethodBase item2 in list)
				{
					array[num] = item2;
					num++;
				}
				return array;
			}

			private static void Postfix(MonoBehaviour __instance)
			{
				if (__instance is IItemInteraction)
				{
					ComponentHolderProtocol.AddComponent<ItemInstance>((Object)(object)__instance);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerMovement), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(PlayerMovement __instance)
		{
			ComponentHolderProtocol.AddComponent<PlayerInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(ShadowWizardAI), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(ShadowWizardAI __instance)
		{
			ComponentHolderProtocol.AddComponent<ShadowWizardInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(SoupManController), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(SoupManController __instance)
		{
			ComponentHolderProtocol.AddComponent<SoupManInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(SkelemageController), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(SkelemageController __instance)
		{
			ComponentHolderProtocol.AddComponent<SkelemageInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(FallenKnightNet), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(FallenKnightNet __instance)
		{
			ComponentHolderProtocol.AddComponent<FallenKnightInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(BoneDogController), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(BoneDogController __instance)
		{
			ComponentHolderProtocol.AddComponent<BoneDogInstance>((Object)(object)__instance);
		}

		[HarmonyPatch(typeof(DuendeManager), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(DuendeManager __instance)
		{
			DuendeController[] duende = __instance.Duende;
			for (int i = 0; i < duende.Length; i++)
			{
				ComponentHolderProtocol.AddComponent<DuendeInstance>((Object)(object)duende[i]);
			}
		}

		[HarmonyPatch(typeof(BogFrogController), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(BogFrogController __instance)
		{
			BogFrogSingleController[] bogFrogs = __instance.BogFrogs;
			for (int i = 0; i < bogFrogs.Length; i++)
			{
				ComponentHolderProtocol.AddComponent<BogFrogInstance>((Object)(object)bogFrogs[i]);
			}
		}

		[HarmonyPatch(typeof(FlagController), "Awake")]
		[HarmonyPostfix]
		private static void InstanceModulePatch_Awake_Postfix(FlagController __instance)
		{
			ComponentHolderProtocol.AddComponent<FlagInstance>((Object)(object)__instance);
		}
	}
	[HarmonyPatch]
	internal static class MonoSingletonPatch
	{
		[HarmonyPatch(typeof(BootstrapNetworkManager), "Awake")]
		[HarmonyPostfix]
		private static void MonoInstancePatch_Awake_Postfix(BootstrapNetworkManager __instance)
		{
			MonoSingleton<BootstrapNetworkManager>.Instance = __instance;
		}

		[HarmonyPatch(typeof(ColoseumManager), "Awake")]
		[HarmonyPostfix]
		private static void MonoInstancePatch_Awake_Postfix(ColoseumManager __instance)
		{
			MonoSingleton<ColoseumManager>.Instance = __instance;
		}

		[HarmonyPatch(typeof(PlayerRespawnManager), "Awake")]
		[HarmonyPostfix]
		private static void MonoInstancePatch_Awake_Postfix(PlayerRespawnManager __instance)
		{
			MonoSingleton<PlayerRespawnManager>.Instance = __instance;
		}

		[HarmonyPatch(typeof(BogFrogController), "Awake")]
		[HarmonyPostfix]
		private static void MonoInstancePatch_Awake_Postfix(BogFrogController __instance)
		{
			MonoSingleton<BogFrogController>.Instance = __instance;
		}

		[HarmonyPatch(typeof(NightAudioSwap), "Start")]
		[HarmonyPostfix]
		private static void MonoInstancePatch_Start_Postfix(NightAudioSwap __instance)
		{
			MonoSingleton<NightAudioSwap>.Instance = __instance;
		}
	}
}
namespace MageAPI.Mono
{
	public class ColliderDebugger : MonoBehaviour
	{
		private static GameObject? LineRenderers;

		private Dictionary<Collider, LineRenderer[]> _colliderLineRenderers = new Dictionary<Collider, LineRenderer[]>();

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)LineRenderers == (Object)null)
			{
				LineRenderers = new GameObject("LineRenderers");
				Object.DontDestroyOnLoad((Object)(object)LineRenderers);
			}
			InitializeAllColliderRenderers();
		}

		private void InitializeAllColliderRenderers()
		{
			Collider[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Collider>();
			foreach (Collider collider in componentsInChildren)
			{
				CreateLineRenderersForCollider(collider);
			}
		}

		private void CreateLineRenderersForCollider(Collider collider)
		{
			if (_colliderLineRenderers.ContainsKey(collider))
			{
				return;
			}
			BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
			if (val != null)
			{
				_colliderLineRenderers[collider] = CreateBoxLineRenderers(val);
				return;
			}
			SphereCollider val2 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null);
			if (val2 != null)
			{
				_colliderLineRenderers[collider] = CreateSphereLineRenderers(val2);
				return;
			}
			CapsuleCollider val3 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null);
			if (val3 != null)
			{
				_colliderLineRenderers[collider] = CreateCapsuleLineRenderers(val3);
				return;
			}
			MeshCollider val4 = (MeshCollider)(object)((collider is MeshCollider) ? collider : null);
			if (val4 != null)
			{
				_colliderLineRenderers[collider] = CreateMeshLineRenderers(val4);
			}
		}

		private LineRenderer[] CreateBoxLineRenderers(BoxCollider boxCol)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[12];
			for (int i = 0; i < 12; i++)
			{
				array[i] = CreateLineRenderer("BoxEdge_" + i, Color.green);
			}
			return array;
		}

		private LineRenderer[] CreateSphereLineRenderers(SphereCollider sphereCol)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[3];
			for (int i = 0; i < 3; i++)
			{
				array[i] = CreateLineRenderer("SphereCircle_" + i, Color.cyan);
			}
			return array;
		}

		private LineRenderer[] CreateCapsuleLineRenderers(CapsuleCollider capsuleCol)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			int num = 16;
			int num2 = num * 3 * 2 + num;
			LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[num2];
			for (int i = 0; i < num2; i++)
			{
				array[i] = CreateLineRenderer("CapsulePart_" + i, Color.yellow);
			}
			return array;
		}

		private LineRenderer[] CreateMeshLineRenderers(MeshCollider meshCol)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)meshCol.sharedMesh == (Object)null)
			{
				return (LineRenderer[])(object)new LineRenderer[0];
			}
			HashSet<(int, int)> uniqueEdges = GetUniqueEdges(meshCol.sharedMesh);
			LineRenderer[] array = (LineRenderer[])(object)new LineRenderer[uniqueEdges.Count];
			for (int i = 0; i < uniqueEdges.Count; i++)
			{
				array[i] = CreateLineRenderer("MeshEdge_" + i, Color.magenta);
			}
			return array;
		}

		private HashSet<(int, int)> GetUniqueEdges(Mesh mesh)
		{
			HashSet<(int, int)> hashSet = new HashSet<(int, int)>();
			int[] triangles = mesh.triangles;
			for (int i = 0; i < triangles.Length; i += 3)
			{
				int num = triangles[i];
				int num2 = triangles[i + 1];
				int num3 = triangles[i + 2];
				hashSet.Add((Mathf.Min(num, num2), Mathf.Max(num, num2)));
				hashSet.Add((Mathf.Min(num2, num3), Mathf.Max(num2, num3)));
				hashSet.Add((Mathf.Min(num3, num), Mathf.Max(num3, num)));
			}
			return hashSet;
		}

		private LineRenderer CreateLineRenderer(string name, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			Transform transform = val.transform;
			GameObject? lineRenderers = LineRenderers;
			transform.SetParent((lineRenderers != null) ? lineRenderers.transform : null);
			val.transform.localPosition = Vector3.zero;
			LineRenderer obj = val.AddComponent<LineRenderer>();
			Shader val2 = Shader.Find("HDRP/Unlit");
			((Renderer)obj).material = new Material(val2)
			{
				color = color
			};
			float startWidth = (obj.endWidth = 0.005f);
			obj.startWidth = startWidth;
			obj.useWorldSpace = false;
			obj.positionCount = 2;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			return obj;
		}

		private void Update()
		{
			//IL_0051: 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)
			foreach (KeyValuePair<Collider, LineRenderer[]> colliderLineRenderer in _colliderLineRenderers)
			{
				Collider key = colliderLineRenderer.Key;
				LineRenderer[] value = colliderLineRenderer.Value;
				if ((Object)(object)key == (Object)null)
				{
					CleanupLineRenderers(value);
					continue;
				}
				LineRenderer[] array = value;
				foreach (LineRenderer obj in array)
				{
					((Component)obj).transform.position = ((Component)key).transform.position;
					((Component)obj).transform.rotation = ((Component)key).transform.rotation;
				}
				UpdateLineRendererPositions(key, value);
			}
			_colliderLineRenderers = _colliderLineRenderers.Where<KeyValuePair<Collider, LineRenderer[]>>((KeyValuePair<Collider, LineRenderer[]> kvp) => (Object)(object)kvp.Key != (Object)null).ToDictionary((KeyValuePair<Collider, LineRenderer[]> kvp) => kvp.Key, (KeyValuePair<Collider, LineRenderer[]> kvp) => kvp.Value);
		}

		private void UpdateLineRendererPositions(Collider collider, LineRenderer[] lineRenderers)
		{
			//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_0019: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Vector3 lossyScale = ((Component)collider).transform.lossyScale;
			BoxCollider val = (BoxCollider)(object)((collider is BoxCollider) ? collider : null);
			if (val != null)
			{
				UpdateBoxLineRenderers(val, lineRenderers, lossyScale);
				return;
			}
			SphereCollider val2 = (SphereCollider)(object)((collider is SphereCollider) ? collider : null);
			if (val2 != null)
			{
				UpdateSphereLineRenderers(val2, lineRenderers, lossyScale);
				return;
			}
			CapsuleCollider val3 = (CapsuleCollider)(object)((collider is CapsuleCollider) ? collider : null);
			if (val3 != null)
			{
				UpdateCapsuleLineRenderers(val3, lineRenderers, lossyScale);
				return;
			}
			MeshCollider val4 = (MeshCollider)(object)((collider is MeshCollider) ? collider : null);
			if (val4 != null)
			{
				UpdateMeshLineRenderers(val4, lineRenderers, lossyScale);
			}
		}

		private void UpdateBoxLineRenderers(BoxCollider boxCol, LineRenderer[] lineRenderers, Vector3 scale)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_000e: 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_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_0027: 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_0041: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0092: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00c5: 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_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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00f2: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_010a: 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_0116: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_012f: 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_013b: 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_0146: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			Vector3 center = boxCol.center;
			Vector3 val = Vector3.Scale(boxCol.size, scale) * 0.5f;
			Vector3[] array = (Vector3[])(object)new Vector3[8]
			{
				center + new Vector3(0f - val.x, 0f - val.y, 0f - 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(0f - val.x, val.y, 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(val.x, val.y, 0f - val.z),
				center + new Vector3(val.x, val.y, val.z)
			};
			int num = 0;
			(int, int)[] array2 = new(int, int)[12]
			{
				(0, 1),
				(0, 2),
				(0, 4),
				(1, 3),
				(1, 5),
				(2, 3),
				(2, 6),
				(3, 7),
				(4, 5),
				(4, 6),
				(5, 7),
				(6, 7)
			};
			for (int i = 0; i < array2.Length; i++)
			{
				var (num2, num3) = array2[i];
				if (num < lineRenderers.Length)
				{
					lineRenderers[num].SetPosition(0, array[num2]);
					lineRenderers[num].SetPosition(1, array[num3]);
					num++;
				}
			}
		}

		private void UpdateSphereLineRenderers(SphereCollider sphereCol, LineRenderer[] lineRenderers, Vector3 scale)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_005f: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(new float[3] { scale.x, scale.y, scale.z });
			float scaledRadius = sphereCol.radius * num;
			Vector3 center = Vector3.Scale(sphereCol.center, scale);
			int num2 = 24;
			float anglePerSegment = (float)Math.PI * 2f / (float)num2;
			if (lineRenderers.Length >= 3)
			{
				UpdateCircleLineRenderer(lineRenderers[0], center, scaledRadius, num2, anglePerSegment, (float angle) => new Vector3(Mathf.Cos(angle) * scaledRadius, Mathf.Sin(angle) * scaledRadius, 0f));
				UpdateCircleLineRenderer(lineRenderers[1], center, scaledRadius, num2, anglePerSegment, (float angle) => new Vector3(Mathf.Cos(angle) * scaledRadius, 0f, Mathf.Sin(angle) * scaledRadius));
				UpdateCircleLineRenderer(lineRenderers[2], center, scaledRadius, num2, anglePerSegment, (float angle) => new Vector3(0f, Mathf.Cos(angle) * scaledRadius, Mathf.Sin(angle) * scaledRadius));
			}
		}

		private void UpdateCircleLineRenderer(LineRenderer lr, Vector3 center, float radius, int segments, float anglePerSegment, Func<float, Vector3> positionCalculator)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)lr == (Object)null))
			{
				lr.positionCount = segments + 1;
				for (int i = 0; i <= segments; i++)
				{
					float arg = (float)i * anglePerSegment;
					Vector3 val = center + positionCalculator(arg);
					lr.SetPosition(i, val);
				}
			}
		}

		private void UpdateCapsuleLineRenderers(CapsuleCollider capsuleCol, LineRenderer[] lineRenderers, Vector3 scale)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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_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_015e: 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_01a3: 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_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_00cd: 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_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: 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_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: 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_02ba: 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_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Scale(capsuleCol.center, scale);
			int direction = capsuleCol.direction;
			float scaledRadius;
			float num;
			switch (direction)
			{
			case 0:
				scaledRadius = capsuleCol.radius * Mathf.Max(scale.y, scale.z);
				num = capsuleCol.height * scale.x;
				break;
			case 2:
				scaledRadius = capsuleCol.radius * Mathf.Max(scale.x, scale.y);
				num = capsuleCol.height * scale.z;
				break;
			default:
				scaledRadius = capsuleCol.radius * Mathf.Max(scale.x, scale.z);
				num = capsuleCol.height * scale.y;
				break;
			}
			Vector3 axisDirection = (Vector3)(direction switch
			{
				0 => Vector3.right, 
				2 => Vector3.forward, 
				_ => Vector3.up, 
			});
			float num2 = Mathf.Max(num - 2f * scaledRadius, 0f);
			Vector3 val2 = val + axisDirection * (num2 / 2f);
			Vector3 val3 = val - axisDirection * (num2 / 2f);
			Vector3 val4 = val2 + axisDirection * scaledRadius;
			Vector3 val5 = val3 - axisDirection * scaledRadius;
			int num3 = 16;
			float num4 = (float)Math.PI * 2f / (float)num3;
			int num5 = 0;
			UpdateCircleLineRenderer(lineRenderers[num5++], val2, scaledRadius, num3, num4, (float angle) => CalculatePerpendicular(axisDirection, angle) * scaledRadius);
			UpdateCircleLineRenderer(lineRenderers[num5++], val, scaledRadius, num3, num4, (float angle) => CalculatePerpendicular(axisDirection, angle) * scaledRadius);
			UpdateCircleLineRenderer(lineRenderers[num5++], val3, scaledRadius, num3, num4, (float angle) => CalculatePerpendicular(axisDirection, angle) * scaledRadius);
			for (int i = 0; i < num3; i++)
			{
				if (num5 >= lineRenderers.Length)
				{
					break;
				}
				float angle2 = (float)i * num4;
				Vector3 val6 = CalculatePerpendicular(axisDirection, angle2) * scaledRadius;
				lineRenderers[num5].positionCount = 2;
				lineRenderers[num5].SetPosition(0, val3 + val6);
				lineRenderers[num5].SetPosition(1, val2 + val6);
				num5++;
			}
			for (int j = 1; j <= 3; j++)
			{
				if (num5 >= lineRenderers.Length)
				{
					break;
				}
				float num6 = (float)Math.PI / 2f * ((float)j / 3f);
				float ringRadius = Mathf.Sin(num6) * scaledRadius;
				float num7 = Mathf.Cos(num6) * scaledRadius;
				UpdateCircleLineRenderer(lineRenderers[num5++], val4 - axisDirection * num7, ringRadius, num3, num4, (float angle) => CalculatePerpendicular(axisDirection, angle) * ringRadius);
				if (num5 < lineRenderers.Length)
				{
					UpdateCircleLineRenderer(lineRenderers[num5++], val5 + axisDirection * num7, ringRadius, num3, num4, (float angle) => CalculatePerpendicular(axisDirection, angle) * ringRadius);
				}
			}
			for (int k = num5; k < lineRenderers.Length; k++)
			{
				if ((Object)(object)lineRenderers[k] != (Object)null)
				{
					((Renderer)lineRenderers[k]).enabled = false;
				}
			}
		}

		private Vector3 CalculatePerpendicular(Vector3 axis, float angle)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_005b: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0084: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Mathf.Abs(Vector3.Dot(axis, Vector3.up)) < 0.9f) ? Vector3.up : ((!(Mathf.Abs(Vector3.Dot(axis, Vector3.forward)) < 0.9f)) ? Vector3.right : Vector3.forward));
			Vector3 val2 = Vector3.Cross(axis, val);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			val2 = Vector3.Cross(axis, normalized);
			Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
			val2 = Mathf.Cos(angle) * normalized + Mathf.Sin(angle) * normalized2;
			return ((Vector3)(ref val2)).normalized;
		}

		private void UpdateMeshLineRenderers(MeshCollider meshCol, LineRenderer[] lineRenderers, Vector3 scale)
		{
			//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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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)
			if ((Object)(object)meshCol.sharedMesh == (Object)null)
			{
				return;
			}
			HashSet<(int, int)> uniqueEdges = GetUniqueEdges(meshCol.sharedMesh);
			Vector3[] vertices = meshCol.sharedMesh.vertices;
			int num = 0;
			foreach (var (num2, num3) in uniqueEdges)
			{
				if (num >= lineRenderers.Length)
				{
					break;
				}
				if ((Object)(object)lineRenderers[num] != (Object)null)
				{
					Vector3 val = Vector3.Scale(vertices[num2], scale);
					Vector3 val2 = Vector3.Scale(vertices[num3], scale);
					lineRenderers[num].positionCount = 2;
					lineRenderers[num].SetPosition(0, val);
					lineRenderers[num].SetPosition(1, val2);
					((Renderer)lineRenderers[num]).enabled = true;
				}
				num++;
			}
			for (int i = num; i < lineRenderers.Length; i++)
			{
				if ((Object)(object)lineRenderers[i] != (Object)null)
				{
					((Renderer)lineRenderers[i]).enabled = false;
				}
			}
		}

		private void CleanupLineRenderers(LineRenderer[] lineRenderers)
		{
			foreach (LineRenderer val in lineRenderers)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private void OnDestroy()
		{
			foreach (LineRenderer[] value in _colliderLineRenderers.Values)
			{
				CleanupLineRenderers(value);
			}
			_colliderLineRenderers.Clear();
		}
	}
	[RequireComponent(typeof(Collider))]
	public class DamageCollisionCheck : MonoBehaviour
	{
		private readonly HashSet<Collider> _ignoredColliders = new HashSet<Collider>();

		public event Action<Collider, HealthModule>? OnEnterHealthCollider;

		public event Action<Collider, HealthModule>? OnExitHealthCollider;

		public event Action<Collision>? OnEnterCollision;

		public event Action<Collision>? OnExitCollision;

		private void Awake()
		{
			if (((Component)this).gameObject.layer != CustomLayers.CheckDamageable)
			{
				MagePlugin.Log.LogWarning((object)("DamageCollisionCheck on '" + ((Object)((Component)this).gameObject).name + "' must be on layer " + LayerMask.LayerToName(CustomLayers.CheckDamageable) + ". Current layer: " + LayerMask.LayerToName(((Component)this).gameObject.layer) + ". Component will be disabled."));
				((Behaviour)this).enabled = false;
			}
			Rigidbody val = default(Rigidbody);
			if (!((Component)this).TryGetComponent<Rigidbody>(ref val))
			{
				MagePlugin.Log.LogWarning((object)("DamageCollisionCheck on '" + ((Object)((Component)this).gameObject).name + "' may not receive collision events without a Rigidbody component."));
			}
		}

		public void IgnoreCollider(Collider collider)
		{
			if ((Object)(object)collider == (Object)null)
			{
				throw new ArgumentNullException("collider");
			}
			_ignoredColliders.Add(collider);
		}

		private void OnTriggerEnter(Collider other)
		{
			HealthModule arg = default(HealthModule);
			if (!_ignoredColliders.Contains(other) && ((Component)other).gameObject.layer == CustomLayers.Damageable && ((Component)other).gameObject.TryGetComponent<HealthModule>(ref arg))
			{
				this.OnEnterHealthCollider?.Invoke(other, arg);
			}
		}

		private void OnTriggerExit(Collider other)
		{
			HealthModule arg = default(HealthModule);
			if (!_ignoredColliders.Contains(other) && ((Component)other).gameObject.layer == CustomLayers.Damageable && ((Component)other).gameObject.TryGetComponent<HealthModule>(ref arg))
			{
				this.OnExitHealthCollider?.Invoke(other, arg);
			}
		}

		private void OnCollisionEnter(Collision other)
		{
			if (!_ignoredColliders.Contains(other.collider))
			{
				this.OnEnterCollision?.Invoke(other);
			}
		}

		private void OnCollisionExit(Collision other)
		{
			if (!_ignoredColliders.Contains(other.collider))
			{
				this.OnExitCollision?.Invoke(other);
			}
		}
	}
	internal class Debugger : MonoBehaviour
	{
		internal static Debugger? Instance;

		internal static void Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			GameObject val = new GameObject("MageAPIDebugger");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<Debugger>();
		}

		private void Awake()
		{
			Instance = this;
		}
	}
	public class HealthModule : MonoBehaviour, IHealth
	{
		private bool _hasSetup;

		private bool _hasCustomHealth;

		private bool _isInstantRespawn;

		private Action? _onKill;

		private bool _dead;

		private float _maxHealth;

		private float _health;

		internal static List<HealthModule> AllHealthModules = new List<HealthModule>();

		private float _hitCooldown;

		internal Vector3 OffsetPos { get; set; } = Vector3.zero;


		private Func<float> GetHealth { get; set; } = () => 0f;


		private Action<float> SetHealth { get; set; } = delegate
		{
		};


		public float Health
		{
			get
			{
				return GetHealth();
			}
			set
			{
				SetHealth(value);
			}
		}

		public MonoBehaviour AssociatedMonoBehaviour { get; private set; }

		public Collider[] AllColliders { get; private set; }

		public Collider HitCollider { get; internal set; }

		public EntityType EntityType { get; internal set; }

		public HealthModule GetHealthModule()
		{
			return this;
		}

		internal static HealthModule? GetHealthModuleFromMono(MonoBehaviour mono)
		{
			MonoBehaviour mono2 = mono;
			return AllHealthModules.FirstOrDefault((HealthModule mod) => (Object)(object)mod.AssociatedMonoBehaviour == (Object)(object)mono2);
		}

		internal void Setup(MonoBehaviour target, string fieldName)
		{
			MonoBehaviour target2 = target;
			AssociatedMonoBehaviour = target2;
			AllColliders = ((Component)target2).GetComponentsInChildren<Collider>();
			HitCollider = AllColliders.First();
			try
			{
				FieldInfo field = ((object)target2).GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && field.FieldType == typeof(float))
				{
					GetHealth = () => (float)field.GetValue(target2);
					SetHealth = delegate(float value)
					{
						ValueRef<float> valueRef = new ValueRef<float>(value);
						if (Events.Misc.HealthModuleEvent.Before.InvokeEvent((valueRef, this)))
						{
							value = valueRef.Value;
							field.SetValue(target2, value);
							Events.Misc.HealthModuleEvent.After.InvokeEvent((this, null));
						}
					};
				}
				_hasSetup = true;
			}
			catch
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		internal void Setup(MonoBehaviour target, float maxHealth, Action kill)
		{
			AssociatedMonoBehaviour = target;
			AllColliders = ((Component)target).GetComponentsInChildren<Collider>();
			HitCollider = AllColliders.First();
			_hasCustomHealth = true;
			_onKill = kill;
			_maxHealth = maxHealth;
			_health = maxHealth;
			GetHealth = () => _health;
			SetHealth = delegate(float value)
			{
				ValueRef<float> valueRef = new ValueRef<float>(value);
				if (Events.Misc.HealthModuleEvent.Before.InvokeEvent((valueRef, this)))
				{
					value = valueRef.Value;
					_health = value;
					Events.Misc.HealthModuleEvent.After.InvokeEvent((this, null));
				}
			};
			_hasSetup = true;
		}

		internal void Setup(MonoBehaviour target, Action kill)
		{
			AssociatedMonoBehaviour = target;
			AllColliders = ((Component)target).GetComponentsInChildren<Collider>();
			HitCollider = AllColliders.First();
			_hasCustomHealth = true;
			_isInstantRespawn = true;
			_onKill = kill;
			_maxHealth = 0.1f;
			_health = 0.1f;
			GetHealth = () => _health;
			SetHealth = delegate(float value)
			{
				ValueRef<float> valueRef = new ValueRef<float>(value);
				if (Events.Misc.HealthModuleEvent.Before.InvokeEvent((valueRef, this)))
				{
					value = valueRef.Value;
					_health = value;
					Events.Misc.HealthModuleEvent.After.InvokeEvent((this, null));
				}
			};
			_hasSetup = true;
		}

		internal void RecreateHitColliders()
		{
			CopyColliderProperties(HitCollider, ((Component)this).gameObject);
		}

		private void CopyColliderProperties(Collider? source, GameObject target)
		{
			//IL_004f: 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_007f: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null)
			{
				return;
			}
			Component obj = target.AddComponent(((object)source).GetType());
			Collider val = (Collider)(object)((obj is Collider) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			val.isTrigger = true;
			val.contactOffset = source.contactOffset;
			BoxCollider val2 = (BoxCollider)(object)((source is BoxCollider) ? source : null);
			if (val2 != null)
			{
				BoxCollider val3 = (BoxCollider)(object)((val is BoxCollider) ? val : null);
				if (val3 != null)
				{
					val3.center = val2.center;
					val3.size = val2.size;
					return;
				}
			}
			SphereCollider val4 = (SphereCollider)(object)((source is SphereCollider) ? source : null);
			if (val4 != null)
			{
				SphereCollider val5 = (SphereCollider)(object)((val is SphereCollider) ? val : null);
				if (val5 != null)
				{
					val5.center = val4.center;
					val5.radius = val4.radius;
					return;
				}
			}
			CapsuleCollider val6 = (CapsuleCollider)(object)((source is CapsuleCollider) ? source : null);
			if (val6 != null)
			{
				CapsuleCollider val7 = (CapsuleCollider)(object)((val is CapsuleCollider) ? val : null);
				if (val7 != null)
				{
					val7.center = val6.center;
					val7.radius = val6.radius;
					val7.height = val6.height;
					val7.direction = val6.direction;
					return;
				}
			}
			MeshCollider val8 = (MeshCollider)(object)((source is MeshCollider) ? source : null);
			if (val8 != null)
			{
				MeshCollider val9 = (MeshCollider)(object)((val is MeshCollider) ? val : null);
				if (val9 != null)
				{
					val9.sharedMesh = val8.sharedMesh;
					val9.convex = val8.convex;
					val9.cookingOptions = val8.cookingOptions;
				}
			}
		}

		private void Update()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (!_hasSetup)
			{
				return;
			}
			if ((Object)(object)AssociatedMonoBehaviour == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			((Component)this).transform.position = ((Component)AssociatedMonoBehaviour).transform.position + OffsetPos;
			((Component)this).transform.rotation = ((Component)AssociatedMonoBehaviour).transform.rotation;
			SetGlobalScale(((Component)this).transform, ((Component)HitCollider).transform.lossyScale);
			if (_hitCooldown > 0f)
			{
				_hitCooldown -= Time.deltaTime;
				_hitCooldown = Mathf.Clamp(_hitCooldown, 0f, 1f);
				_health = _maxHealth;
			}
			else
			{
				if (!((Behaviour)AssociatedMonoBehaviour).enabled || !_hasCustomHealth)
				{
					return;
				}
				if (!_dead && _health <= 0f)
				{
					_onKill?.Invoke();
					if (!_isInstantRespawn)
					{
						_dead = true;
					}
					else
					{
						_hitCooldown = 1f;
					}
				}
				else if (_health > _maxHealth)
				{
					_health = _maxHealth;
				}
			}
		}

		private void SetGlobalScale(Transform transform, Vector3 globalScale)
		{
			//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_0024: 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_0031: 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_0052: 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_0073: 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_008c: 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_0099: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)transform.parent == (Object)null)
			{
				transform.localScale = globalScale;
				return;
			}
			Vector3 lossyScale = transform.parent.lossyScale;
			lossyScale.x = ((lossyScale.x == 0f) ? 0.0001f : lossyScale.x);
			lossyScale.y = ((lossyScale.y == 0f) ? 0.0001f : lossyScale.y);
			lossyScale.z = ((lossyScale.z == 0f) ? 0.0001f : lossyScale.z);
			transform.localScale = new Vector3(globalScale.x / lossyScale.x, globalScale.y / lossyScale.y, globalScale.z / lossyScale.z);
		}

		internal void ResetDeath()
		{
			_health = _maxHealth;
			_dead = false;
		}

		private void Awake()
		{
			AllHealthModules.Add(this);
		}

		private void OnDestroy()
		{
			AllHealthModules.Remove(this);
		}
	}
}
namespace MageAPI.Mono.Instance
{
	public sealed class BogFrogInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(2)
		{
			typeof(BogFrogSingleController),
			typeof(BogFrogInteractor)
		};

		public BogFrogSingleController BogFrogSingleController => GetMonoInstance<BogFrogSingleController>(0);

		public BogFrogInteractor BogFrogInteractor => GetMonoInstance<BogFrogInteractor>(1);
	}
	public sealed class BoneDogInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(2)
		{
			typeof(BoneDogController),
			typeof(BoneDogTargets)
		};

		public BoneDogController BoneDogController => GetMonoInstance<BoneDogController>(0);

		public BoneDogTargets BoneDogTargets => GetMonoInstance<BoneDogTargets>(1);
	}
	public sealed class DuendeInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(2)
		{
			typeof(DuendeController),
			typeof(DuendeInteractor)
		};

		public DuendeController DuendeController => GetMonoInstance<DuendeController>(0);

		public DuendeInteractor DuendeInteractor => GetMonoInstance<DuendeInteractor>(1);
	}
	public sealed class FallenKnightInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(3)
		{
			typeof(FallenKnight),
			typeof(FallenKnightNet),
			typeof(KnightDong)
		};

		public FallenKnight FallenKnight => GetMonoInstance<FallenKnight>(0);

		public FallenKnightNet FallenKnightNet => GetMonoInstance<FallenKnightNet>(1);

		public KnightDong FallenKnightDong => GetMonoInstance<KnightDong>(2);
	}
	public sealed class FlagInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(1) { typeof(FlagController) };

		public FlagController FlagController => GetMonoInstance<FlagController>(0);
	}
	public sealed class ItemInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(1) { typeof(IItemInteraction) };

		public IItemInteraction Item => (IItemInteraction)GetMonoInstance<MonoBehaviour>(0);

		public GameObject GameObject => ((Component)GetMonoInstance<MonoBehaviour>(0)).gameObject;
	}
	public sealed class PlayerInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(2)
		{
			typeof(PlayerMovement),
			typeof(PlayerInventory)
		};

		public PlayerMovement PlayerMovement => GetMonoInstance<PlayerMovement>(0);

		public PlayerInventory PlayerInventory => GetMonoInstance<PlayerInventory>(1);

		public HealthModule HealthModule => GetMonoInstance<HealthModule>(2);

		protected override void GetNonTypeInstances()
		{
			AddMonoInstance((MonoBehaviour?)(object)MageAPI.Mono.HealthModule.GetHealthModuleFromMono((MonoBehaviour)(object)PlayerMovement));
		}
	}
	public sealed class ShadowWizardInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(1) { typeof(ShadowWizardAI) };

		public ShadowWizardAI ShadowWizardAI => GetMonoInstance<ShadowWizardAI>(0);
	}
	public sealed class SkelemageInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(2)
		{
			typeof(SkelemageController),
			typeof(SkelemageAniController)
		};

		public SkelemageController SkelemageController => GetMonoInstance<SkelemageController>(0);

		public SkelemageAniController SkelemageAniController => GetMonoInstance<SkelemageAniController>(1);
	}
	public sealed class SoupManInstance : InstanceModule
	{
		protected override List<Type> MonoTypes => new List<Type>(3)
		{
			typeof(SoupManController),
			typeof(SoupManInteractor),
			typeof(GetSoupFromGuy)
		};

		public SoupManController SoupManController => GetMonoInstance<SoupManController>(0);

		public SoupManInteractor SoupManInteractor => GetMonoInstance<SoupManInteractor>(1);

		public GetSoupFromGuy GetSoupFromGuy => GetMonoInstance<GetSoupFromGuy>(2);
	}
}
namespace MageAPI.Mono.Instance.Core
{
	public abstract class InstanceModule : MonoBehaviour
	{
		private static Dictionary<Type, List<InstanceModule>> _instances { get; } = new Dictionary<Type, List<InstanceModule>>();


		protected abstract List<Type> MonoTypes { get; }

		private List<MonoBehaviour> MonoInstances { get; } = new List<MonoBehaviour>();


		internal static T GetModuleInstanceFromMono<T>(MonoBehaviour mono) where T : InstanceModule
		{
			T[] moduleInstances = GetModuleInstances<T>();
			foreach (T val in moduleInstances)
			{
				foreach (MonoBehaviour monoInstance in val.MonoInstances)
				{
					if ((Object)(object)monoInstance == (Object)(object)mono)
					{
						return val;
					}
				}
			}
			return null;
		}

		internal static T[] GetModuleInstances<T>() where T : InstanceModule
		{
			return GetModuleInstances(typeof(T)).Cast<T>().ToArray();
		}

		private static InstanceModule[] GetModuleInstances(Type moduleType)
		{
			if (_instances.TryGetValue(moduleType, out List<InstanceModule> value))
			{
				List<InstanceModule> list = value;
				int num = 0;
				InstanceModule[] array = new InstanceModule[list.Count];
				{
					foreach (InstanceModule item in list)
					{
						array[num] = item;
						num++;
					}
					return array;
				}
			}
			return Array.Empty<InstanceModule>();
		}

		protected T GetMonoInstance<T>(int index) where T : MonoBehaviour
		{
			return (T)(object)MonoInstances[index];
		}

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			Type type = ((object)this).GetType();
			if (!_instances.TryGetValue(type, out List<InstanceModule> value))
			{
				value = new List<InstanceModule>();
				_instances[type] = value;
			}
			value.Add(this);
			foreach (Type monoType in MonoTypes)
			{
				MonoBehaviour item = (MonoBehaviour)((Component)this).GetComponentInChildren(monoType, true);
				MonoInstances.Add(item);
			}
			GetNonTypeInstances();
		}

		protected virtual void GetNonTypeInstances()
		{
		}

		protected void AddMonoInstance(MonoBehaviour? mono)
		{
			if (!((Object)(object)mono == (Object)null))
			{
				MonoInstances.Add(mono);
			}
		}

		private void OnDestroy()
		{
			Type type = ((object)this).GetType();
			if (_instances.TryGetValue(type, out List<InstanceModule> value))
			{
				value.Remove(this);
				if (value.Count == 0)
				{
					_instances.Remove(type);
				}
			}
			MonoInstances.Clear();
		}
	}
}
namespace MageAPI.Modules
{
	public static class CustomLayers
	{
		private static readonly Dictionary<string, int> NameToLayerMap = new Dictionary<string, int>();

		private static readonly Dictionary<int, string> LayerToNameMap = new Dictionary<int, string>();

		private static readonly HashSet<int> UsedLayers = new HashSet<int>();

		public static int IgnorePlayer { get; private set; }

		public static int Damageable { get; private set; }

		public static int CheckDamageable { get; private set; }

		internal static void Init()
		{
			IgnorePlayer = GetOrCreateLayer("IgnorePlayer");
			Damageable = GetOrCreateLayer("Damageable");
			CheckDamageable = GetOrCreateLayer("CheckDamageable");
			Physics.IgnoreLayerCollision(IgnorePlayer, 6, true);
			SetLayerCollisions(Damageable, new int[1] { CheckDamageable });
			SetLayerCollisions(CheckDamageable, new int[3] { Damageable, 3, 8 });
		}

		private static void SetLayerCollisions(int targetLayer, int[]? exceptionLayers = null, bool areExceptionsIgnored = false)
		{
			for (int i = 0; i < 32; i++)
			{
				if (i != targetLayer && (exceptionLayers == null || exceptionLayers.Contains(i) != !areExceptionsIgnored))
				{
					Physics.IgnoreLayerCollision(i, targetLayer, true);
				}
			}
		}

		internal static bool NameToLayer(string layerName, out int layer)
		{
			layerName = "MageAPI_" + layerName;
			return NameToLayerMap.TryGetValue(layerName, out layer);
		}

		internal static bool LayerToName(int layer, out string layerName)
		{
			bool num = LayerToNameMap.TryGetValue(layer, out layerName);
			if (num)
			{
				layerName = layerName.Replace("MageAPI_", "");
			}
			return num;
		}

		internal static int GetOrCreateLayer(string layerName)
		{
			if (NameToLayerMap.TryGetValue(layerName, out var value))
			{
				return value;
			}
			for (int i = 0; i < 32; i++)
			{
				if (string.IsNullOrEmpty(LayerMask.LayerToName(i)) && !UsedLayers.Contains(i))
				{
					RegisterLayer(i, layerName);
					return i;
				}
			}
			Debug.LogError((object)("[CustomLayer] No available layers found for '" + layerName + "'!"));
			return -1;
		}

		private static void RegisterLayer(int layer, string name)
		{
			name = "MageAPI_" + name;
			NameToLayerMap[name] = layer;
			LayerToNameMap[layer] = name;
			UsedLayers.Add(layer);
			Debug.Log((object)$"[CustomLayer] Registered layer {layer} as '{name}'");
		}

		private static void DebugLogAllLayers()
		{
			for (int i = 0; i < 32; i++)
			{
				string text = LayerMask.LayerToName(i);
				if (!string.IsNullOrEmpty(text))
				{
					MagePlugin.Log.LogInfo((object)$"{i}, {text}");
				}
			}
		}
	}
	internal class MonoSingleton<T> where T : MonoBehaviour
	{
		internal static T? Instance { get; set; }
	}
	public class ValueRef<T>
	{
		public T Value { get; set; }

		public ValueRef(T value)
		{
			Value = value;
			base..ctor();
		}
	}
}
namespace MageAPI.Modules.Events.Player
{
	public class PlayerDeathEvent : StaticEvent<PlayerDeathEvent.AfterEvent, PlayerDeathEvent.BeforeEvent>
	{
		public class AfterEvent : EventBase<(PlayerInstance player, object?)>
		{
		}

		public class BeforeEvent : EventBase<(PlayerInstance player, object?), bool>
		{
			protected override bool DefaultValue => true;
		}
	}
	public class PlayerDropItemEvent : StaticBeforeEvent<PlayerDropItemEvent.BeforeEvent>
	{
		public class BeforeEvent : EventBase<(PlayerInstance player, ItemInstance itemInstance)>
		{
		}
	}
	public class PlayerPickupItemEvent : StaticAfterEvent<PlayerPickupItemEvent.AfterEvent>
	{
		public class AfterEvent : EventBase<(PlayerInstance player, ItemInstance itemInstance)>
		{
		}
	}
	public class PlayerSpawnEvent : StaticAfterEvent<PlayerSpawnEvent.AfterEvent>
	{
		public class AfterEvent : EventBase<(PlayerInstance player, object?)>
		{
		}
	}
}
namespace MageAPI.Modules.Events.Misc
{
	public class HealthModuleEvent : StaticEvent<HealthModuleEvent.AfterEvent, HealthModuleEvent.BeforeEvent>
	{
		public class AfterEvent : EventBase<(HealthModule healthModule, object?)>
		{
		}

		public class BeforeEvent : EventBase<(ValueRef<float> healthToSet, HealthModule healthModule), bool>
		{
			protected override bool DefaultValue => true;
		}
	}
	public class VoiceControlListenerResultEvent : StaticEvent<VoiceControlListenerResultEvent.AfterEvent, VoiceControlListenerResultEvent.BeforeEvent>
	{
		public class AfterEvent : EventBase<(string result, VoiceControlListener voiceControlListener)>
		{
		}

		public class BeforeEvent : EventBase<(ValueRef<string> result, VoiceControlListener voiceControlListener), bool>
		{
			protected override bool DefaultValue => true;
		}
	}
}
namespace MageAPI.Modules.Events.Game
{
	public class GameEndEvent : StaticAfterEvent<GameEndEvent.AfterEvent>
	{
		public class AfterEvent : EventBase<(int losingTeam, object?)>
		{
		}
	}
	public class GameStartEvent : StaticAfterEvent<GameStartEvent.AfterEvent>
	{
		public class AfterEvent : EventBase
		{
		}
	}
}
namespace MageAPI.Modules.Events.Core
{
	public abstract class CustomEvent
	{
	}
	public abstract class EventBase : CustomEvent
	{
		private event Action? EventInvoked;

		public void Subscribe(Action action)
		{
			EventInvoked += action;
		}

		public void Unsubscribe(Action action)
		{
			EventInvoked -= action;
		}

		internal void InvokeEvent()
		{
			this.EventInvoked?.Invoke();
		}
	}
	public abstract class EventBase<Data> : CustomEvent
	{
		private event Action<Data>? EventInvoked;

		public void Subscribe(Action<Data> action)
		{
			EventInvoked += action;
		}

		public void Unsubscribe(Action<Data> action)
		{
			EventInvoked -= action;
		}

		internal void InvokeEvent(Data data)
		{
			this.EventInvoked?.Invoke(data);
		}
	}
	public abstract class EventBase<Data, Return> : CustomEvent
	{
		private class Subscription
		{
			internal Func<Data, Return> Handler { get; }

			internal int Priority { get; }

			public Subscription(Func<Data, Return> handler, int priority)
			{
				Handler = handler;
				Priority = priority;
				base..ctor();
			}
		}

		private readonly List<Subscription> _subscriptions = new List<Subscription>();

		protected virtual Return DefaultValue => default(Return);

		public void Subscribe(Func<Data, Return> action, int eventPriority = 3000)
		{
			Func<Data, Return> action2 = action;
			if (!_subscriptions.Any((Subscription s) => (Delegate?)s.Handler == (Delegate?)action2))
			{
				Subscription item = new Subscription(action2, eventPriority);
				_subscriptions.Add(item);
			}
		}

		public void Subscribe(Func<Data, Return> action, EventPriority eventPriority)
		{
			Subscribe(action, (int)eventPriority);
		}

		public void Unsubscribe(Func<Data, Return> action)
		{
			Func<Data, Return> action2 = action;
			Subscription subscription = _subscriptions.FirstOrDefault((Subscription s) => (Delegate?)s.Handler == (Delegate?)action2);
			if (subscription != null)
			{
				_subscriptions.Remove(subscription);
			}
		}

		internal Return InvokeEvent(Data data)
		{
			Return result = DefaultValue;
			foreach (Subscription item in _subscriptions.OrderBy((Subscription s) => s.Priority))
			{
				if (item != null && item.Handler != null)
				{
					result = item.Handler(data);
				}
			}
			return result;
		}
	}
	public static class Events
	{
		public static class Client
		{
			public static ClientConnectEvent ClientConnectEvent => Events<MageAPI.Modules.Events.Client.ClientConnectEvent>.Instance;

			public static ClientDisconnectEvent ClientDisconnectEvent => Events<MageAPI.Modules.Events.Client.ClientDisconnectEvent>.Instance;
		}

		public static class Player
		{
			public static PlayerDeathEvent PlayerDeathEvent => Events<MageAPI.Modules.Events.Player.PlayerDeathEvent>.Instance;

			public static PlayerSpawnEvent PlayerSpawnEvent => Events<MageAPI.Modules.Events.Player.PlayerSpawnEvent>.Instance;

			public static PlayerPickupItemEvent PlayerPickupItemEvent => Events<MageAPI.Modules.Events.Player.PlayerPickupItemEvent>.Instance;

			public static PlayerDropItemEvent PlayerDropItemEvent => Events<MageAPI.Modules.Events.Player.PlayerDropItemEvent>.Instance;
		}

		public static class Game
		{
			public static GameStartEvent GameStartEvent => Events<MageAPI.Modules.Events.Game.GameStartEvent>.Instance;

			public static GameEndEvent GameEndEvent => Events<MageAPI.Modules.Events.Game.GameEndEvent>.Instance;
		}

		public static class Misc
		{
			public static HealthModuleEvent HealthModuleEvent => Events<MageAPI.Modules.Events.Misc.HealthModuleEvent>.Instance;

			public static VoiceControlListenerResultEvent VoiceControlListenerResultEvent => Events<MageAPI.Modules.Events.Misc.VoiceControlListenerResultEvent>.Instance;
		}
	}
	public static class Events<T> where T : StaticEvent, new()
	{
		public static readonly T Instance = new T();
	}
	public abstract class StaticEvent
	{
	}
	public abstract class StaticEvent<AfterEvent, BeforeEvent> : StaticEvent where AfterEvent : CustomEvent, new() where BeforeEvent : CustomEvent, new()
	{
		public AfterEvent After { get; } = new AfterEvent();


		public BeforeEvent Before { get; } = new BeforeEvent();

	}
	public abstract class StaticAfterEvent<AfterEvent> : StaticEvent where AfterEvent : CustomEvent, new()
	{
		public AfterEvent After { get; } = new AfterEvent();

	}
	public abstract class StaticBeforeEvent<BeforeEvent> : StaticEvent where BeforeEvent : CustomEvent, new()
	{
		public BeforeEvent Before { get; } = new BeforeEvent();

	}
}
namespace MageAPI.Modules.Events.Client
{
	public class ClientConnectEvent : StaticEvent<ClientConnectEvent.AfterEvent, ClientConnectEvent.BeforeEvent>
	{
		public class AfterEvent : EventBase<(NetworkConnection networkConnection, object?)>
		{
		}

		public class BeforeEvent : EventBase<(NetworkConnection networkConnection, object?), bool>
		{
			protected override bool DefaultValue => true;
		}
	}
	public class ClientDisconnectEvent : StaticAfterEvent<ClientDisconnectEvent.AfterEvent>
	{
		public class AfterEvent : EventBase<(NetworkConnection networkConnection, object?)>
		{
		}
	}
}
namespace MageAPI.Managers
{
	public static class InstanceManager
	{
		public static class Singletons
		{
			public static MainMenuManager? MainMenuManager => MainMenuManager.instance;

			public static BootstrapManager? BootstrapManager => BootstrapManager.instance;

			public static BootstrapNetworkManager? BootstrapNetworkManager => MonoSingleton<BootstrapNetworkManager>.Instance;

			public static ColoseumManager? ColoseumManager => MonoSingleton<ColoseumManager>.Instance;

			public static PlayerRespawnManager? PlayerRespawnManager => MonoSingleton<PlayerRespawnManager>.Instance;

			public static BogFrogController? BogFrogManager => MonoSingleton<BogFrogController>.Instance;

			public static NightAudioSwap? NightAudioSwap => MonoSingleton<NightAudioSwap>.Instance;

			public static WeatherCycle? WeatherCycle => MonoSingleton<NightAudioSwap>.Instance?.nightday;
		}

		public static class ObjectPools
		{
			public static HealthModule[] HealthModules => HealthModule.AllHealthModules.ToArray();

			public static ItemInstance[] Items => InstanceModule.GetModuleInstances<ItemInstance>();

			public static PlayerInstance[] Players => InstanceModule.GetModuleInstances<PlayerInstance>();

			public static DuendeInstance[] Duendes => InstanceModule.GetModuleInstances<DuendeInstance>();

			public static BogFrogInstance[] BogFrogs => InstanceModule.GetModuleInstances<BogFrogInstance>();

			public static ShadowWizardInstance[] ShadowWizards => InstanceModule.GetModuleInstances<ShadowWizardInstance>();

			public static SoupManInstance[] SoupMans => InstanceModule.GetModuleInstances<SoupManInstance>();

			public static SkelemageInstance[] Skelemages => InstanceModule.GetModuleInstances<SkelemageInstance>();

			public static BoneDogInstance[] BoneDogs => InstanceModule.GetModuleInstances<BoneDogInstance>();

			public static FallenKnightInstance[] FallenKnights => InstanceModule.GetModuleInstances<FallenKnightInstance>();

			public static FlagInstance[] Flags => InstanceModule.GetModuleInstances<FlagInstance>();
		}
	}
}
namespace MageAPI.Interfaces
{
	public interface IHealth
	{
		float Health { get; set; }

		MonoBehaviour AssociatedMonoBehaviour { get; }

		HealthModule GetHealthModule();
	}
}
namespace MageAPI.Helpers
{
	public static class Layers
	{
		public const int Default = 0;

		public const int TransparentFX = 1;

		public const int IgnoreRaycast = 2;

		public const int Ground = 3;

		public const int Water = 4;

		public const int UI = 5;

		public const int Player = 6;

		public const int Item = 7;

		public const int Ground2 = 8;

		public const int IgnoreRaycastGround = 9;

		public const int AIAgent = 10;

		public const int FlagDrawer = 11;

		public const int InterableNet = 12;

		public const int FireballDetect = 13;

		public const int ReverbCollider = 14;

		public const int BaseForceField = 15;
	}
	public static class MageUtils
	{
		public static PlayerInstance? GetFurthestPlayer(Vector3 origin, Func<PlayerInstance, bool>? filter = null)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			PlayerInstance result = null;
			float num = float.NegativeInfinity;
			PlayerInstance[] players = InstanceManager.ObjectPools.Players;
			foreach (PlayerInstance playerInstance in players)
			{
				if (!((Object)(object)playerInstance == (Object)null) && (filter == null || filter(playerInstance)))
				{
					float num2 = Vector3.Distance(origin, ((Component)playerInstance).transform.position);
					if (num2 > num)
					{
						num = num2;
						result = playerInstance;
					}
				}
			}
			return result;
		}

		public static PlayerInstance? GetClosestPlayer(Vector3 origin, Func<PlayerInstance, bool>? filter = null)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			PlayerInstance result = null;
			float num = float.PositiveInfinity;
			PlayerInstance[] players = InstanceManager.ObjectPools.Players;
			foreach (PlayerInstance playerInstance in players)
			{
				if (!((Object)(object)playerInstance == (Object)null) && (filter == null || filter(playerInstance)))
				{
					float num2 = Vector3.Distance(origin, ((Component)playerInstance).transform.position);
					if (num2 < num)
					{
						num = num2;
						result = playerInstance;
					}
				}
			}
			return result;
		}

		public static bool RaycastLineOfSight(Vector3 origin, Vector3 target, string[]? excludedLayerNames = null, float angleOffset = 5f, int testCount = 3)
		{
			//IL_000a: 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_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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (excludedLayerNames == null)
			{
				excludedLayerNames = Array.Empty<string>();
			}
			Vector3 val = target - origin;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num = Vector3.Distance(origin, target);
			if (num < Mathf.Epsilon)
			{
				return true;
			}
			int num2 = 0;
			string[] array = excludedLayerNames;
			for (int i = 0; i < array.Length; i++)
			{
				int num3 = LayerMask.NameToLayer(array[i]);
				if (num3 != -1)
				{
					num2 |= 1 << num3;
				}
			}
			num2 = ~num2;
			testCount = Mathf.Max(1, testCount);
			if (testCount % 2 == 0)
			{
				testCount++;
			}
			if (!Physics.Raycast(origin, normalized, num, num2))
			{
				return true;
			}
			if (testCount <= 1 || Mathf.Approximately(angleOffset, 0f))
			{
				return false;
			}
			float[] array2 = new float[testCount];
			for (int j = 0; j < testCount; j++)
			{
				array2[j] = 0f - angleOffset + (float)j * (2f * angleOffset / (float)(testCount - 1));
			}
			for (int k = 0; k < testCount; k++)
			{
				if (!Mathf.Approximately(array2[k], 0f))
				{
					Vector3 val2 = Quaternion.AngleAxis(array2[k], Vector3.up) * normalized;
					if (!Physics.Raycast(origin, val2, num, num2))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static IEnumerator CombineCoroutine(params IEnumerator[] enumerators)
		{
			foreach (IEnumerator enumerator in enumerators)
			{
				while (enumerator.MoveNext())
				{
					yield return enumerator.Current;
				}
			}
		}

		public static IEnumerator CombineCoroutine(IEnumerable<IEnumerator> enumerators)
		{
			foreach (IEnumerator enumerator in enumerators)
			{
				while (enumerator.MoveNext())
				{
					yield return enumerator.Current;
				}
			}
		}
	}
}
namespace MageAPI.Helpers.Extensions
{
	public static class ItemExtensions
	{
		public static ItemInstance GetItemInstance(this IItemInteraction itemInteraction)
		{
			IItemInteraction itemInteraction2 = itemInteraction;
			return InstanceModule.GetModuleInstances<ItemInstance>().FirstOrDefault((ItemInstance item) => item.Item == itemInteraction2);
		}
	}
	public static class PlayerExtensions
	{
		public static PlayerInstance? GetPlayerInstance(this NetworkConnection conn)
		{
			NetworkConnection conn2 = conn;
			return InstanceModule.GetModuleInstances<PlayerInstance>().FirstOrDefault((PlayerInstance player) => ((NetworkBehaviour)player.PlayerMovement).Owner == conn2);
		}

		public static PlayerInstance GetPlayerInstance(this PlayerMovement playerMovement)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerMovement);
		}

		public static PlayerInventory GetPlayerInventory(this PlayerMovement playerMovement)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerMovement).PlayerInventory;
		}

		public static HealthModule GetHealthModule(this PlayerMovement playerMovement)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerMovement).HealthModule;
		}

		public static PlayerInstance GetPlayerInstance(this PlayerInventory playerInventory)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerInventory);
		}

		public static PlayerMovement GetPlayerMovement(this PlayerInventory playerInventory)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerInventory).PlayerMovement;
		}

		public static HealthModule GetHealthModule(this PlayerInventory playerInventory)
		{
			return InstanceModule.GetModuleInstanceFromMono<PlayerInstance>((MonoBehaviour)(object)playerInventory).HealthModule;
		}

		public static ItemInstance[] GetInventoryItems(this PlayerInventory playerInventory)
		{
			return (from obj in playerInventory.equippedItems
				where (Object)(object)obj != (Object)null
				select obj.GetComponent<IItemInteraction>().GetItemInstance()).ToArray();
		}

		public static ItemInstance? GetEquippedItem(this PlayerInventory playerInventory)
		{
			GameObject obj = playerInventory.equippedItems[playerInventory.equippedIndex];
			return ((obj != null) ? obj.GetComponent<IItemInteraction>().GetItemInstance() : null) ?? null;
		}

		public static void DespawnItemInInventory(this PlayerInventory playerInventory, IItemInteraction item)
		{
			if (!((NetworkBehaviour)playerInventory).IsOwner)
			{
				return;
			}
			int equippedIndex = playerInventory.equippedIndex;
			for (int i = 0; i < playerInventory.equippedItems.Length; i++)
			{
				GameObject val = playerInventory.equippedItems[i];
				if ((Object)(object)val != (Object)null && val.GetComponent<IItemInteraction>() == item)
				{
					playerInventory.equippedIndex = i;
					playerInventory.destroyHandItem();
					break;
				}
			}
			playerInventory.equippedIndex = equippedIndex;
		}
	}
}
namespace MageAPI.Enums
{
	public enum EntityType
	{
		None,
		Player,
		ShadowWizard,
		Skelemage,
		CastleWraith,
		Duende,
		BogFrog
	}
	public enum EventPriority
	{
		First = 0,
		High = 1000,
		Medium = 2000,
		Low = 3000,
		Last = 4000
	}
}
namespace MageAPI.Attributes
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
	public class RpcHarmonyPatch : HarmonyPatch
	{
		public RpcHarmonyPatch(Type declaringType)
			: base(declaringType)
		{
		}

		public RpcHarmonyPatch(Type declaringType, string methodName)
			: base(declaringType, methodName)
		{
		}

		public RpcHarmonyPatch(Type declaringType, string methodName, params Type[] argumentTypes)
			: base(declaringType, methodName, argumentTypes)
		{
		}

		public RpcHarmonyPatch(string methodName)
			: base(methodName)
		{
		}

		public RpcHarmonyPatch(string methodName, params Type[] argumentTypes)
			: base(methodName, argumentTypes)
		{
		}

		internal static void PatchAll()
		{
			Harmony harmony = MagePlugin.Harmony;
			if (harmony == null)
			{
				return;
			}
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				try
				{
					Type[] types = ((object)value.Instance).GetType().Assembly.GetTypes();
					foreach (Type obj in types)
					{
						HarmonyPatch customAttribute = ((MemberInfo)obj).GetCustomAttribute<HarmonyPatch>();
						MethodInfo[] methods = obj.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (MethodInfo methodInfo in methods)
						{
							RpcHarmonyPatch customAttribute2 = ((MemberInfo)methodInfo).GetCustomAttribute<RpcHarmonyPatch>();
							if (customAttribute2 != null && methodInfo.IsStatic)
							{
								HarmonyMethod info = ((HarmonyAttribute)customAttribute2).info;
								if ((object)info.declaringType == null)
								{
									info.declaringType = ((HarmonyAttribute)(customAttribute?)).info?.declaringType;
								}
								PatchFromAttribute(harmony, customAttribute2, methodInfo);
							}
						}
					}
				}
				catch (Exception ex)
				{
					MagePlugin.Log.LogError((object)("Failed to process assembly " + value.Metadata.Name + ": " + ex.Message));
				}
			}
		}

		private static void PatchFromAttribute(Harmony harmony, RpcHarmonyPatch attribute, MethodInfo patchMethod)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = ResolveTargetMethod(((HarmonyAttribute)attribute).info);
				if (methodInfo == null)
				{
					MagePlugin.Log.LogWarning((object)$"Could not find target method for {((HarmonyAttribute)attribute).info.declaringType}.{((HarmonyAttribute)attribute).info.methodName}");
					return;
				}
				string text = DeterminePatchType(patchMethod);
				if (text == "Unknown")
				{
					MagePlugin.Log.LogWarning((object)("Method " + patchMethod.Name + " doesn't have Harmony attributes or follow prefix/postfix naming convention. Skipping."));
					return;
				}
				HarmonyMethod val = null;
				HarmonyMethod val2 = null;
				HarmonyMethod val3 = new HarmonyMethod(patchMethod);
				if (!(text == "Prefix"))
				{
					if (!(text == "Postfix"))
					{
						return;
					}
					val2 = val3;
				}
				else
				{
					val = val3;
				}
				harmony.Patch((MethodBase)methodInfo, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				MagePlugin.Log.LogInfo((object)("Successfully patched " + methodInfo.DeclaringType?.Name + "." + methodInfo.Name + " with " + text));
			}
			catch (Exception ex)
			{
				MagePlugin.Log.LogError((object)("Failed to patch from attribute: " + ex.Message));
			}
		}

		private static string DeterminePatchType(MethodInfo patchMethod)
		{
			if (((MemberInfo)patchMethod).GetCustomAttribute<RpcHarmonyPrefix>() != null)
			{
				return "Prefix";
			}
			if (((MemberInfo)patchMethod).GetCustomAttribute<RpcHarmonyPostfix>() != null)
			{
				return "Postfix";
			}
			return GetPatchTypeFromMethodName(patchMethod.Name);
		}

		private static MethodInfo? ResolveTargetMethod(HarmonyMethod info)
		{
			HarmonyMethod info2 = info;
			if (info2.declaringType == null || string.IsNullOrEmpty(info2.methodName))
			{
				return null;
			}
			BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
			string namePrefix = Regex.Replace(info2.methodName, "_\\d+$", "");
			List<MethodInfo> source = (from m in info2.declaringType.GetMethods(bindingAttr)
				where Regex.Replace(m.Name, "_\\d+$", "") == namePrefix
				select m).ToList();
			if (info2.argumentTypes != null && info2.argumentTypes.Length != 0)
			{
				source = source.Where(delegate(MethodInfo m)
				{
					ParameterInfo[] parameters = m.GetParameters();
					if (parameters.Length != info2.argumentTypes.Length)
					{
						return false;
					}
					for (int i = 0; i < parameters.Length; i++)
					{
						if (parameters[i].ParameterType != info2.argumentTypes[i])
						{
							return false;
						}
					}
					return true;
				}).ToList();
			}
			return source.FirstOrDefault();
		}

		private static string GetPatchTypeFromMethodName(string methodName)
		{
			if (methodName.EndsWith("Prefix", StringComparison.OrdinalIgnoreCase) || methodName.Equals("Prefix", StringComparison.OrdinalIgnoreCase))
			{
				return "Prefix";
			}
			if (methodName.EndsWith("Postfix", StringComparison.OrdinalIgnoreCase) || methodName.Equals("Postfix", StringComparison.OrdinalIgnoreCase))
			{
				return "Postfix";
			}
			return "Unknown";
		}
	}
	public class RpcHarmonyPrefix : HarmonyPrefix
	{
	}
	public class RpcHarmonyPostfix : HarmonyPostfix
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}