Decompiled source of LethalEscapeUpdated v0.9.5

LethalEscape.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("LethalEscape")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalEscape")]
[assembly: AssemblyTitle("LethalEscape")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UpdatedEscape
{
	internal class LETimerFunctions : MonoBehaviour
	{
		public static float MinuteEscapeTimerPuffer;

		public static float MinuteEscapeTimerBracken;

		public static float MinuteEscapeTimerHoardingBug;

		public static LETimerFunctions instance;

		private void Awake()
		{
			instance = this;
		}

		private void Update()
		{
			MinuteEscapeTimerBracken += Time.deltaTime;
			MinuteEscapeTimerHoardingBug += Time.deltaTime;
			MinuteEscapeTimerPuffer += Time.deltaTime;
		}
	}
	[BepInPlugin("xCeezy.LethalEscape", "Lethal Escape", "0.9.5")]
	public class Plugin : BaseUnityPlugin
	{
		public static GameObject ExtraValues;

		private const string modGUID = "xCeezy.LethalEscape";

		private const string modName = "Lethal Escape";

		private const string modVersion = "0.9.5";

		private Harmony _harmony = new Harmony("LethalEscape");

		public static ManualLogSource mls;

		public static float TimeStartTeleport;

		public static ConfigEntry<bool> CanThumperEscape;

		public static ConfigEntry<bool> CanCaveDwellerEscape;

		public static ConfigEntry<bool> CanBrackenEscape;

		public static ConfigEntry<bool> CanJesterEscape;

		public static ConfigEntry<bool> CanHoardingBugEscape;

		public static ConfigEntry<bool> CanCoilHeadEscape;

		public static ConfigEntry<bool> CanSpiderEscape;

		public static ConfigEntry<bool> CanNutCrackerEscape;

		public static ConfigEntry<bool> CanHygrodereEscape;

		public static ConfigEntry<bool> goofyahh;

		public static ConfigEntry<float> ClaySurgeonEscapeChance;

		public static ConfigEntry<bool> CanPufferEscape;

		public static ConfigEntry<bool> CanButlerEscape;

		public static ConfigEntry<float> ButlerChanceToSpawnOutside;

		public static ConfigEntry<float> CaveDwellerChanceToSpawnOutside;

		public static ConfigEntry<bool> CanClaySurgeonEscape;

		public static ConfigEntry<float> ClaySurgeonChanceToSpawnOutside;

		public static ConfigEntry<float> ButlerEscapeDelay;

		public static float JesterSpeedWindup;

		public static ConfigEntry<float> BrackenChanceToEscapeEveryMinute;

		public static ConfigEntry<float> PufferChanceToEscapeEveryMinute;

		public static ConfigEntry<float> HoardingBugChanceToEscapeEveryMinute;

		public static ConfigEntry<float> HoardingBugChanceToNestNearShip;

		public static ConfigEntry<float> HoardingBugChanceToSpawnOutside;

		public static ConfigEntry<float> BrackenChanceToSpawnOutside;

		public static ConfigEntry<float> PufferChanceToSpawnOutside;

		public static ConfigEntry<float> JesterChanceToSpawnOutside;

		public static ConfigEntry<float> HygrodereChanceToSpawnOutside;

		public static ConfigEntry<float> NutCrackerChanceToSpawnOutside;

		public static ConfigEntry<float> ThumperChanceToSpawnOutside;

		public static ConfigEntry<float> SpiderChanceToSpawnOutside;

		public static ConfigEntry<float> JesterSpeedIncreasePerSecond;

		public static ConfigEntry<float> MaxJesterOutsideSpeed;

		public static ConfigEntry<float> BrackenEscapeDelay;

		public static ConfigEntry<float> ThumperEscapeDelay;

		public static ConfigEntry<int> SpiderMinWebsOutside;

		public static ConfigEntry<int> SpiderMaxWebsOutside;

		private void Awake()
		{
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Expected O, but got Unknown
			CanThumperEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "ThumperEscape", true, "Whether or not the Thumper can escape");
			CanBrackenEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "BrackenEscape", true, "Whether or not the Bracken can escape");
			CanJesterEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "JesterEscape", true, "Whether or not the Jester can escape");
			CanHoardingBugEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "HoardingBugEscape", true, "Whether or not the Hoarding Bugs can escape");
			CanCaveDwellerEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "CaveDwellerEscape", true, "Whether or not the Cave Dweller can escape");
			CaveDwellerChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "CaveDwellerSpawnOutsideChance", 10f, "The chance that the Cave Dweller will spawn outside");
			CanCoilHeadEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "CoilHeadEscape", true, "Whether or not Coil Head can escape");
			CanSpiderEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "SpiderEscape", true, "Whether or not the Spider can escape");
			CanClaySurgeonEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "ClaySurgeonEscape", true, "Whether or not the Clay Surgeon can escape");
			ClaySurgeonChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "ClaySurgeonSpawnOutsideChance", 10f, "The chance that the Clay Surgeon will spawn outside");
			CanNutCrackerEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "NutCrackerEscape", true, "Whether or not the Nut Cracker can escape");
			CanHygrodereEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "HygrodereEscape", false, "Whether or not the Hygrodere/Slime can escape");
			CanPufferEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "CanPufferEscape", true, "Whether or not the Puffer/Spore Lizard can escape");
			ThumperChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "ThumperSpawnOutsideChance", 5f, "The chance that the Thumper will spawn outside");
			BrackenChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "BrackenSpawnOutsideChance", 10f, "The chance that the Bracken will spawn outside");
			JesterChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "JesterSpawnOutsideChance", 0f, "The chance that the Jester will spawn outside");
			HoardingBugChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "HoardingBugSpawnOutsideChance", 30f, "The chance that the Hoarding Bug will spawn outside");
			SpiderChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "SpiderSpawnOutsideChance", 5f, "The chance that the Spider will spawn outside");
			NutCrackerChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "NutCrackerSpawnOutsideChance", 5f, "The chance that the NutCracker will spawn outside");
			HygrodereChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "HygrodereSpawnOutsideChance", 0f, "The chance that the Hygrodere will spawn outside");
			PufferChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "PufferSpawnOutsideChance", 5f, "The chance that the Puffer will spawn outside");
			CanButlerEscape = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Monster Escape", "ButlerEscape", true, "Whether or not the Butler can escape");
			ButlerChanceToSpawnOutside = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn Escape Settings", "ButlerSpawnOutsideChance", 5f, "The chance that the Butler will spawn outside");
			ButlerEscapeDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Butler Escape Delay", 7f, "Time it takes for the Butler to follow a player outside");
			ClaySurgeonEscapeChance = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "ClaySurgeonEscapeChance", 10f, "The chance that the Clay Surgeon will escape randomly every minute");
			PufferChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Puffer Escape Chance", 10f, "The chance that the Puffer/Spore Lizard will escape randomly every minute");
			BrackenChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Bracken Escape Chance", 10f, "The chance that the Bracken will escape randomly every minute");
			HoardingBugChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "HoardingBug Escape Chance", 15f, "The chance that the Hoarding Bug will escape randomly every minute");
			HoardingBugChanceToNestNearShip = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "HoardingBugShipNestChance", 50f, "The chance that the Hoarding Bug will make their nest at/near the ship");
			BrackenEscapeDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Bracken Escape Delay", 5f, "Time it takes for the Bracken to follow a player outside");
			ThumperEscapeDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Thumper Escape Delay", -5f, "Time it takes for the Thumper to follow a player outside which is based on how long the player was seen minus this value (Might break when under -15 and will force thumper outside when it sees someone when above 0)");
			SpiderMaxWebsOutside = ((BaseUnityPlugin)this).Config.Bind<int>("Escape Settings", "Max Spider Webs Outside", 28, "The maximum amount of spider webs the game will allow the spider to create webs outside (Vanilla game is 7 or 9 if update 47)");
			SpiderMinWebsOutside = ((BaseUnityPlugin)this).Config.Bind<int>("Escape Settings", "Min Spider Webs Outside", 20, "The minimum amount of spider webs the game will allow the spider to create webs outside (Vanilla game is 4 or 6 if update 47)");
			goofyahh = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Message Settings", true, "Enable or disable the message when the ship lands.");
			JesterSpeedIncreasePerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Jester Speed Increase", 1.35f, "How much speed the jester gets per second");
			MaxJesterOutsideSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Jester Outside Speed", 10f, "The max speed the Jester moves while outside (5 is the speed its at while in the box and 18 is jesters max speed inside the facility)");
			if ((Object)(object)ExtraValues == (Object)null)
			{
				ExtraValues = new GameObject();
				Object.DontDestroyOnLoad((Object)(object)ExtraValues);
				((Object)ExtraValues).hideFlags = (HideFlags)61;
				ExtraValues.AddComponent<LETimerFunctions>();
			}
			mls = Logger.CreateLogSource("GameMaster");
			mls.LogInfo((object)"Loaded xCeezy.LethalEscape. Patching.");
			_harmony.PatchAll(typeof(Plugin));
		}

		[HarmonyPatch(typeof(CrawlerAI), "Update")]
		[HarmonyPrefix]
		private static void CrawlerLEPrefixAI(CrawlerAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanThumperEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if (((EnemyAI)__instance).currentBehaviourStateIndex != 0 && __instance.noticePlayerTimer < ThumperEscapeDelay.Value && (Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(CrawlerAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void ThumperAILEOutsideAttack(CrawlerAI __instance, ref Collider other)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isEnemyDead && ((EnemyAI)__instance).isOutside && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !(Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>() <= 0.65f) && !(((EnemyAI)__instance).stunNormalizedTimer > 0f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
					component.DamagePlayer(40, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(40, Vector3.zero, -1);
					((EnemyAI)__instance).agent.speed = 0f;
					__instance.HitPlayerServerRpc((int)component.playerClientId);
					component.JumpToFearLevel(1f, true);
				}
			}
		}

		[HarmonyPatch(typeof(CrawlerAI), "Start")]
		[HarmonyPostfix]
		private static void CrawlerAILEPostfixStart(CrawlerAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ThumperChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= ThumperChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(JesterAI), "Update")]
		[HarmonyPrefix]
		private static void JesterLEPrefixAI(JesterAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanJesterEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if (((EnemyAI)__instance).currentBehaviourStateIndex == 2 && (Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					JesterSpeedWindup = 0f;
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(JesterAI), "Update")]
		[HarmonyPostfix]
		private static void JesterLEPostfixAI(JesterAI __instance)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			if (!CanJesterEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || !((EnemyAI)__instance).isOutside)
			{
				return;
			}
			if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
			bool flag = false;
			PlayerControllerB val = null;
			float num = float.MaxValue;
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val2 = StartOfRound.Instance.allPlayerScripts[i];
				if (val2.isPlayerControlled && !val2.isInsideFactory)
				{
					flag = true;
					float num2 = Vector3.Distance(((Component)__instance).transform.position, ((Component)val2).transform.position);
					if (num2 < num)
					{
						num = num2;
						val = val2;
					}
				}
			}
			NavMeshHit val3 = default(NavMeshHit);
			if (flag && (Object)(object)val != (Object)null)
			{
				((EnemyAI)__instance).SwitchToBehaviourState(2);
				((EnemyAI)__instance).agent.stoppingDistance = 0f;
				((EnemyAI)__instance).targetPlayer = val;
				((EnemyAI)__instance).SetMovingTowardsTargetPlayer(val);
				((EnemyAI)__instance).agent.isStopped = false;
			}
			else if ((((EnemyAI)__instance).agent.remainingDistance < 0.1f || !((EnemyAI)__instance).agent.hasPath) && NavMesh.SamplePosition(((Component)__instance).transform.position + Random.insideUnitSphere * 10f, ref val3, 10f, -1))
			{
				((EnemyAI)__instance).agent.SetDestination(((NavMeshHit)(ref val3)).position);
			}
			JesterSpeedWindup = Mathf.Clamp(JesterSpeedWindup + Time.deltaTime * JesterSpeedIncreasePerSecond.Value, 0f, MaxJesterOutsideSpeed.Value);
			((EnemyAI)__instance).agent.speed = JesterSpeedWindup;
		}

		[HarmonyPatch(typeof(JesterAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void JesterAILEOutsideAttack(JesterAI __instance, ref Collider other)
		{
			if (!((EnemyAI)__instance).isEnemyDead && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ((EnemyAI)__instance).isOutside)
			{
				if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
				{
					((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
				}
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && ((EnemyAI)__instance).currentBehaviourStateIndex == 2)
				{
					__instance.KillPlayerServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(JesterAI), "Start")]
		[HarmonyPostfix]
		private static void JesterAILEPostfixStart(JesterAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && JesterChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= JesterChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(HoarderBugAI), "Update")]
		[HarmonyPrefix]
		private static void HoardingBugAILEPrefixAI(HoarderBugAI __instance)
		{
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !CanHoardingBugEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory && __instance.searchForPlayer.inProgress)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
					return;
				}
				if (LETimerFunctions.MinuteEscapeTimerHoardingBug >= 60f && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
				{
					LETimerFunctions.MinuteEscapeTimerHoardingBug = 0f;
					if ((float)Random.Range(1, 100) <= HoardingBugChanceToEscapeEveryMinute.Value / (float)Object.FindObjectsOfType<HoarderBugAI>().Length)
					{
						SendEnemyOutside((EnemyAI)(object)__instance);
						if (HoardingBugChanceToNestNearShip.Value != 0f && (float)Random.Range(1, 100) <= HoardingBugChanceToNestNearShip.Value)
						{
							StartOfRound val = Object.FindObjectOfType<StartOfRound>();
							Transform val2 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(val.elevatorTransform.position, false, 0);
							__instance.nestPosition = val2.position;
							return;
						}
					}
				}
			}
			else if (__instance.heldItem != null)
			{
				if (__instance.nestPosition != Vector3.zero)
				{
					SendEnemyInside((EnemyAI)(object)__instance);
				}
				else
				{
					Transform val3 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(((Component)__instance).transform.position, false, 0);
					__instance.nestPosition = val3.position;
					SendEnemyInside((EnemyAI)(object)__instance);
				}
			}
			if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(HoarderBugAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void HoardingBugAILEOutsideAttack(HoarderBugAI __instance, ref Collider other)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				float value = Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>();
				bool value2 = Traverse.Create((object)__instance).Field("inChase").GetValue<bool>();
				if (!(value <= 0.5f) && !(((EnemyAI)__instance).stunNormalizedTimer > 0f) && value2)
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					component.DamagePlayer(30, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(30, Vector3.zero, -1);
					__instance.HitPlayerServerRpc();
				}
			}
		}

		[HarmonyPatch(typeof(HoarderBugAI), "Start")]
		[HarmonyPostfix]
		private static void HoardingBugAILEPostfixStart(HoarderBugAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && HoardingBugChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= HoardingBugChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(SpringManAI), "Update")]
		[HarmonyPrefix]
		private static void CoilHeadAILEPrefixAI(SpringManAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanCoilHeadEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(SpringManAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void CoilHeadAILEOutsideAttack(SpringManAI __instance, ref Collider other)
		{
			//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_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				bool value = Traverse.Create((object)__instance).Field("stoppingMovement").GetValue<bool>();
				float value2 = Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>();
				if (!value && ((EnemyAI)__instance).currentBehaviourStateIndex == 1 && !(value2 >= 0f) && !(((EnemyAI)__instance).stunNormalizedTimer > 0f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0.2f);
					component.DamagePlayer(90, true, true, (CauseOfDeath)6, 2, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(90, Vector3.zero, -1);
					component.JumpToFearLevel(1f, true);
				}
			}
		}

		[HarmonyPatch(typeof(SandSpiderAI), "Update")]
		[HarmonyPrefix]
		private static void SpiderAILEPrefixAI(SandSpiderAI __instance)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !CanSpiderEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
					__instance.meshContainerPosition = ((EnemyAI)__instance).serverPosition;
					__instance.meshContainerTarget = ((EnemyAI)__instance).serverPosition;
					__instance.maxWebTrapsToPlace += Random.Range(SpiderMinWebsOutside.Value, SpiderMaxWebsOutside.Value);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(SandSpiderAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void SpiderAILEOutsideAttack(SandSpiderAI __instance, ref Collider other)
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				bool value = Traverse.Create((object)__instance).Field("onWall").GetValue<bool>();
				float value2 = Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>();
				if (!value && !(value2 <= 1f) && !(((EnemyAI)__instance).stunNormalizedTimer > 0f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					component.DamagePlayer(90, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(90, Vector3.zero, -1);
					__instance.HitPlayerServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(SandSpiderAI), "Start")]
		[HarmonyPostfix]
		private static void SpiderAILEPostfixStart(SandSpiderAI __instance)
		{
			//IL_0040: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && SpiderChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= SpiderChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
				__instance.meshContainerPosition = ((EnemyAI)__instance).serverPosition;
				__instance.meshContainerTarget = ((EnemyAI)__instance).serverPosition;
				__instance.maxWebTrapsToPlace = Random.Range(SpiderMinWebsOutside.Value, SpiderMaxWebsOutside.Value);
			}
		}

		[HarmonyPatch(typeof(NutcrackerEnemyAI), "Update")]
		[HarmonyPrefix]
		private static void NutCrackerAILEPrefixAI(NutcrackerEnemyAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanNutCrackerEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(NutcrackerEnemyAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void NutCrackerAILEOutsideAttack(NutcrackerEnemyAI __instance, ref Collider other)
		{
			if (((EnemyAI)__instance).isEnemyDead || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				float value = Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>();
				if (!(((EnemyAI)__instance).stunNormalizedTimer >= 0f) && !(value < 1f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					__instance.LegKickPlayerServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(NutcrackerEnemyAI), "Start")]
		[HarmonyPostfix]
		private static void NutCrackerAILEPostfixStart(NutcrackerEnemyAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && NutCrackerChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= NutCrackerChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(ClaySurgeonAI), "Update")]
		[HarmonyPrefix]
		private static void ClaySurgeonLEPrefixAI(ClaySurgeonAI __instance)
		{
			Traverse val = Traverse.Create((object)__instance);
			if (val.Field("isEnemyDead").GetValue<bool>() || !CanClaySurgeonEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!val.Field("isOutside").GetValue<bool>())
			{
				PlayerControllerB value = val.Field("targetPlayer").GetValue<PlayerControllerB>();
				if ((Object)(object)value != (Object)null && !value.isInsideFactory && (float)Random.Range(1, 100) <= ClaySurgeonEscapeChance.Value)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				val.Method("ChangeOwnershipOfEnemy", new object[1] { GameNetworkManager.Instance.localPlayerController.actualClientId }).GetValue();
			}
		}

		[HarmonyPatch(typeof(ClaySurgeonAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void ClaySurgeonAILEOutsideAttack(ClaySurgeonAI __instance, ref Collider other)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			if (!val.Field("isEnemyDead").GetValue<bool>() && val.Field("isOutside").GetValue<bool>() && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !(val.Field("timeSinceHittingPlayer").GetValue<float>() < 0.4f))
				{
					val.Field("timeSinceHittingPlayer").SetValue((object)0f);
					component.DamagePlayer(50, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(50, Vector3.zero, -1);
					val.Method("HitPlayerServerRpc", new object[1] { (int)component.playerClientId }).GetValue();
				}
			}
		}

		[HarmonyPatch(typeof(ClaySurgeonAI), "Start")]
		[HarmonyPostfix]
		private static void ClaySurgeonAILEPostfixStart(ClaySurgeonAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ClaySurgeonChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= ClaySurgeonChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(BlobAI), "Update")]
		[HarmonyPrefix]
		private static void BlobAILEPrefixAI(BlobAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanHygrodereEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance, SpawnOnDoor: false);
					__instance.centerPoint = ((Component)__instance).transform;
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(BlobAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void BlobAILEOutsideAttack(BlobAI __instance, ref Collider other)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if (!((Object)(object)component != (Object)null) || component.isPlayerDead || !component.isPlayerControlled || !((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController))
			{
				return;
			}
			float value = Traverse.Create((object)__instance).Field("timeSinceHittingLocalPlayer").GetValue<float>();
			float value2 = Traverse.Create((object)__instance).Field("tamedTimer").GetValue<float>();
			float value3 = Traverse.Create((object)__instance).Field("angeredTimer").GetValue<float>();
			if (!(value < 0.25f) && (!(value2 > 0f) || !(value3 < 0f)))
			{
				Traverse.Create((object)__instance).Field("timeSinceHittingLocalPlayer").SetValue((object)0f);
				component.DamagePlayerFromOtherClientServerRpc(35, Vector3.zero, -1);
				component.DamagePlayer(35, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				if (component.isPlayerDead)
				{
					__instance.SlimeKillPlayerEffectServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(BlobAI), "Start")]
		[HarmonyPostfix]
		private static void HygrodereAILEPostfixStart(BlobAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && HygrodereChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= HygrodereChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
				__instance.centerPoint = ((Component)__instance).transform;
			}
		}

		[HarmonyPatch(typeof(FlowermanAI), "Update")]
		[HarmonyPrefix]
		private static void FlowermanAILEPrefixAI(FlowermanAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanBrackenEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				int value = Traverse.Create((object)__instance).Field("currentBehaviourStateIndex").GetValue<int>();
				float value2 = Traverse.Create((object)__instance).Field("evadeStealthTimer").GetValue<float>();
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory && (value == 1 || value2 > 0f) && Time.time - TimeStartTeleport >= BrackenEscapeDelay.Value + 5f)
				{
					TimeStartTeleport = Time.time;
				}
				if (Time.time - TimeStartTeleport > BrackenEscapeDelay.Value && Time.time - TimeStartTeleport < BrackenEscapeDelay.Value + 5f)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
				else if (LETimerFunctions.MinuteEscapeTimerBracken >= 60f && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
				{
					LETimerFunctions.MinuteEscapeTimerBracken = 0f;
					if (BrackenChanceToEscapeEveryMinute.Value != 0f && (float)Random.Range(1, 100) <= BrackenChanceToEscapeEveryMinute.Value)
					{
						SendEnemyOutside((EnemyAI)(object)__instance);
					}
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(FlowermanAI), "Update")]
		[HarmonyPostfix]
		private static void FlowermanAILEPostfixAI(FlowermanAI __instance)
		{
			if (!((EnemyAI)__instance).isEnemyDead && CanBrackenEscape.Value && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ((EnemyAI)__instance).isOutside && ((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(FlowermanAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void FlowerManAILEOutsideAttack(FlowermanAI __instance, ref Collider other, bool ___startingKillAnimationLocalClient)
		{
			if (!((EnemyAI)__instance).isEnemyDead && ((EnemyAI)__instance).isOutside && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !Traverse.Create((object)__instance).Field("inKillAnimation").GetValue<bool>() && !___startingKillAnimationLocalClient)
				{
					__instance.KillPlayerAnimationServerRpc((int)component.playerClientId);
					___startingKillAnimationLocalClient = true;
				}
			}
		}

		[HarmonyPatch(typeof(FlowermanAI), "Start")]
		[HarmonyPostfix]
		private static void FlowermanAILEPostfixStart(FlowermanAI __instance)
		{
			TimeStartTeleport = 0f;
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && BrackenChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= BrackenChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(ButlerEnemyAI), "Update")]
		[HarmonyPrefix]
		private static void ButlerLEPrefixAI(ButlerEnemyAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanButlerEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			if (!val.Field("isOutside").GetValue<bool>())
			{
				if (val.Field("currentBehaviourStateIndex").GetValue<int>() != 0 && val.Field("noticePlayerTimer").GetValue<float>() < ButlerEscapeDelay.Value && (Object)(object)val.Field("targetPlayer").GetValue<PlayerControllerB>() != (Object)null && !val.Field("targetPlayer").GetValue<PlayerControllerB>().isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(ButlerEnemyAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void ButlerAILEOutsideAttack(ButlerEnemyAI __instance, ref Collider other)
		{
			//IL_00e8: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			if (val.Field("isOutside").GetValue<bool>() && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !(val.Field("timeSinceHittingPlayer").GetValue<float>() <= 0.65f) && !(val.Field("stunNormalizedTimer").GetValue<float>() > 0f))
				{
					val.Field("timeSinceHittingPlayer").SetValue((object)0f);
					((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
					component.DamagePlayer(50, true, true, (CauseOfDeath)14, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(50, Vector3.zero, -1);
					val.Field("agent").Field("speed").SetValue((object)0f);
					__instance.StabPlayerServerRpc((int)component.playerClientId, true);
				}
			}
		}

		[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
		[HarmonyPostfix]
		private static void ButlerAILEPostfixStart(ButlerEnemyAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ButlerChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= ButlerChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool LoadNewLevel(SelectableLevel newLevel)
		{
			if (!goofyahh.Value)
			{
				return true;
			}
			if (!((NetworkBehaviour)StartOfRound.Instance.localPlayerController).IsHost)
			{
				return true;
			}
			HUDManager.Instance.AddTextToChatOnServer("<color=red>Lethal Escape 0.9.5 is active, monsters can escape the facility now!</color>", -1);
			return true;
		}

		[HarmonyPatch(typeof(CaveDwellerAI), "Update")]
		[HarmonyPrefix]
		private static void CaveDwellerLEPrefixAI(CaveDwellerAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanCaveDwellerEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance);
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(CaveDwellerAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void CaveDwellerAILEOutsideAttack(CaveDwellerAI __instance, ref Collider other)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isEnemyDead && ((EnemyAI)__instance).isOutside && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !(Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>() <= 1f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					component.DamagePlayer(30, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(30, Vector3.zero, -1);
					__instance.KillPlayerAnimationServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(CaveDwellerAI), "Start")]
		[HarmonyPostfix]
		private static void CaveDwellerAILEPostfixStart(CaveDwellerAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && CaveDwellerChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= CaveDwellerChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		[HarmonyPatch(typeof(PufferAI), "Update")]
		[HarmonyPrefix]
		private static void PufferAILEPrefixAI(PufferAI __instance)
		{
			if (((EnemyAI)__instance).isEnemyDead || !CanPufferEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory)
				{
					SendEnemyOutside((EnemyAI)(object)__instance, SpawnOnDoor: false);
				}
				else if (LETimerFunctions.MinuteEscapeTimerPuffer >= 60f && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
				{
					LETimerFunctions.MinuteEscapeTimerPuffer = 0f;
					if (PufferChanceToEscapeEveryMinute.Value != 0f && (float)Random.Range(1, 100) <= PufferChanceToEscapeEveryMinute.Value)
					{
						SendEnemyOutside((EnemyAI)(object)__instance, SpawnOnDoor: false);
					}
				}
			}
			else if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
		}

		[HarmonyPatch(typeof(PufferAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void PufferAILEOutsideAttack(PufferAI __instance, ref Collider other)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isEnemyDead && ((EnemyAI)__instance).isOutside && ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && component.isPlayerControlled && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController && !(Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").GetValue<float>() <= 1f))
				{
					Traverse.Create((object)__instance).Field("timeSinceHittingPlayer").SetValue((object)0f);
					component.DamagePlayer(20, true, true, (CauseOfDeath)6, 0, false, default(Vector3));
					component.DamagePlayerFromOtherClientServerRpc(20, Vector3.zero, -1);
					__instance.BitePlayerServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(PufferAI), "Start")]
		[HarmonyPostfix]
		private static void PufferAILEPostfixStart(PufferAI __instance)
		{
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && PufferChanceToSpawnOutside.Value != 0f && (float)Random.Range(1, 100) <= PufferChanceToSpawnOutside.Value)
			{
				SendEnemyOutside((EnemyAI)(object)__instance);
			}
		}

		public static void SendEnemyInside(EnemyAI instance)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			instance.isOutside = false;
			instance.allAINodes = GameObject.FindGameObjectsWithTag("AINode");
			EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>(false);
			EntranceTeleport val = null;
			float num = float.PositiveInfinity;
			EntranceTeleport[] array2 = array;
			foreach (EntranceTeleport val2 in array2)
			{
				if (!val2.isEntranceToBuilding)
				{
					continue;
				}
				NavMeshPath val3 = new NavMeshPath();
				NavMesh.CalculatePath(((Component)instance).transform.position, val2.entrancePoint.position, instance.agent.areaMask, val3);
				if ((int)val3.status == 0)
				{
					float num2 = 0f;
					Vector3[] corners = val3.corners;
					for (int j = 1; j < corners.Length; j++)
					{
						num2 += Vector3.Distance(corners[j - 1], corners[j]);
					}
					if (num2 < num)
					{
						num = num2;
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				Vector3 forward = val.entrancePoint.forward;
				Vector3 val4 = val.entrancePoint.position - forward * 2f;
				instance.agent.Warp(val4);
				instance.serverPosition = val4;
				((Component)instance).transform.position = instance.serverPosition;
			}
			array2 = array;
			foreach (EntranceTeleport val5 in array2)
			{
				if (val5.isEntranceToBuilding)
				{
					continue;
				}
				NavMeshPath val6 = new NavMeshPath();
				NavMesh.CalculatePath(((Component)instance).transform.position, val5.entrancePoint.position, instance.agent.areaMask, val6);
				if ((int)val6.status == 0)
				{
					float num3 = 0f;
					Vector3[] corners2 = val6.corners;
					for (int k = 1; k < corners2.Length; k++)
					{
						num3 += Vector3.Distance(corners2[k - 1], corners2[k]);
					}
					if (num3 < num)
					{
						num = num3;
						val = val5;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				Vector3 forward2 = val.entrancePoint.forward;
				Vector3 val7 = val.entrancePoint.position - forward2 * 2f;
				instance.agent.Warp(val7);
				instance.serverPosition = val7;
				((Component)instance).transform.position = instance.serverPosition;
			}
			else
			{
				Transform val8 = instance.ChooseClosestNodeToPosition(((Component)instance).transform.position, false, 0);
				instance.serverPosition = val8.position;
				((Component)instance).transform.position = instance.serverPosition;
				instance.agent.Warp(instance.serverPosition);
			}
			instance.SyncPositionToClients();
			instance.StartSearch(((Component)instance).transform.position, (AISearchRoutine)null);
		}

		public static void SendEnemyOutside(EnemyAI instance, bool SpawnOnDoor = true)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0057: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			instance.isOutside = true;
			instance.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
			EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>(false);
			EntranceTeleport val = null;
			EntranceTeleport val2 = null;
			float num = float.MaxValue;
			float num2 = float.MaxValue;
			EntranceTeleport[] array2 = array;
			foreach (EntranceTeleport val3 in array2)
			{
				if (!val3.isEntranceToBuilding)
				{
					continue;
				}
				NavMeshPath val4 = new NavMeshPath();
				if (NavMesh.CalculatePath(((Component)instance).transform.position, val3.entrancePoint.position, instance.agent.areaMask, val4))
				{
					float num3 = 0f;
					Vector3[] corners = val4.corners;
					for (int j = 1; j < corners.Length; j++)
					{
						num3 += Vector3.Distance(corners[j - 1], corners[j]);
					}
					if (num3 < num)
					{
						num2 = num;
						val2 = val;
						num = num3;
						val = val3;
					}
					else if (num3 < num2)
					{
						num2 = num3;
						val2 = val3;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				Vector3 forward = val.entrancePoint.forward;
				Vector3 val5 = val.entrancePoint.position + forward * 2f;
				NavMeshHit val6 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val5, ref val6, 5f, instance.agent.areaMask))
				{
					val5 = ((NavMeshHit)(ref val6)).position;
				}
				instance.agent.Warp(val5);
				instance.serverPosition = val5;
				((Component)instance).transform.position = val5;
			}
			else if ((Object)(object)val2 != (Object)null)
			{
				Vector3 forward2 = val2.entrancePoint.forward;
				Vector3 val7 = val2.entrancePoint.position + forward2 * 2f;
				NavMeshHit val8 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val7, ref val8, 5f, instance.agent.areaMask))
				{
					val7 = ((NavMeshHit)(ref val8)).position;
				}
				instance.agent.Warp(val7);
				instance.serverPosition = val7;
				((Component)instance).transform.position = val7;
			}
			else
			{
				Transform val9 = instance.ChooseClosestNodeToPosition(((Component)instance).transform.position, false, 0);
				Vector3 val10 = (((Object)(object)val9 != (Object)null) ? val9.position : ((Component)instance).transform.position);
				instance.agent.Warp(val10);
				instance.serverPosition = val10;
				((Component)instance).transform.position = val10;
			}
			instance.SyncPositionToClients();
			instance.StartSearch(((Component)instance).transform.position, (AISearchRoutine)null);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int A_1)
		{
			Version = A_1;
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}