Decompiled source of LethalEscapeUpdated v1.0.6

LethalEscape.dll

Decompiled 2 days ago
using System;
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 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.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace UpdatedEscape
{
	internal class LETimerFunctions : MonoBehaviour
	{
		public static float MinuteEscapeTimerPuffer;

		public static float MinuteEscapeTimerBracken;

		public static float MinuteEscapeTimerHoardingBug;

		public static float MinuteEscapeTimerCoilHead;

		public static LETimerFunctions instance;

		private void Awake()
		{
			instance = this;
		}

		private void Update()
		{
			MinuteEscapeTimerBracken += Time.deltaTime;
			MinuteEscapeTimerHoardingBug += Time.deltaTime;
			MinuteEscapeTimerPuffer += Time.deltaTime;
			MinuteEscapeTimerCoilHead += Time.deltaTime;
		}
	}
	[BepInPlugin("xCeezy.LethalEscape", "Lethal Escape", "1.0.6")]
	public class Plugin : BaseUnityPlugin
	{
		private static Dictionary<BaboonBirdAI, bool> baboonsPathingToDoor = new Dictionary<BaboonBirdAI, bool>();

		private static Dictionary<ButlerEnemyAI, float> butlerPendingLeaveFacilityInfo = new Dictionary<ButlerEnemyAI, float>();

		private static Dictionary<BaboonBirdAI, float> baboonPathingCooldowns = new Dictionary<BaboonBirdAI, float>();

		private static Dictionary<BaboonBirdAI, float> baboonDecisionTimers = new Dictionary<BaboonBirdAI, float>();

		private static Dictionary<FlowermanAI, Transform> brackenOriginalNests = new Dictionary<FlowermanAI, Transform>();

		private static Dictionary<FlowermanAI, float> brackenPathingCooldowns = new Dictionary<FlowermanAI, float>();

		private static Dictionary<FlowermanAI, float> brackenDecisionTimers = new Dictionary<FlowermanAI, float>();

		public static Vector3 LastButlerDeathPositionOutside;

		public static float LastButlerDeathTimeOutside = -1f;

		public static bool ButlerRecentlyDiedOutside = false;

		public static GameObject ExtraValues;

		private const string modGUID = "xCeezy.LethalEscape";

		private const string modName = "Lethal Escape";

		private const string modVersion = "1.0.6";

		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> CanButlerReturnInside;

		public static ConfigEntry<bool> CanBrackenReturnInside;

		public static ConfigEntry<bool> CanNutCrackerEscape;

		public static ConfigEntry<bool> CanHygrodereEscape;

		public static ConfigEntry<bool> goofyahh;

		public static ConfigEntry<float> BrackenChanceToGoInside;

		public static ConfigEntry<int> BrackenInteriorPathRange;

		public static ConfigEntry<int> BrackenExteriorPathRange;

		public static ConfigEntry<float> BrackenPathCooldown;

		public static ConfigEntry<bool> CanKiwiEnterFacility;

		public static ConfigEntry<float> KiwiChanceToEnterFacilityPerMinute;

		public static ConfigEntry<float> KiwiChanceToExitFacilityPerMinute;

		public static ConfigEntry<float> KiwiPathingCooldownConfig;

		public static ConfigEntry<int> KiwiInteriorPathRangeConfig;

		public static ConfigEntry<int> KiwiExteriorPathRangeConfig;

		public static ConfigEntry<bool> KiwiCanCarryEggsInOut;

		public static ConfigEntry<bool> KiwiCanMakeNestInside;

		public static ConfigEntry<float> KiwiNestInsideChance;

		public static ConfigEntry<float> ThumperChanceToEscapeEveryMinute;

		public static ConfigEntry<float> JesterChanceToEscapeEveryMinute;

		public static ConfigEntry<float> CaveDwellerChanceToEscapeEveryMinute;

		public static ConfigEntry<float> CoilHeadChanceToEscapeEveryMinute;

		public static ConfigEntry<float> SpiderChanceToEscapeEveryMinute;

		public static ConfigEntry<float> NutCrackerChanceToEscapeEveryMinute;

		public static ConfigEntry<float> HygrodereChanceToEscapeEveryMinute;

		public static ConfigEntry<float> ButlerChanceToEscapeEveryMinute;

		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;

		private static Dictionary<GiantKiwiAI, float> kiwiPathingCooldowns = new Dictionary<GiantKiwiAI, float>();

		private static Dictionary<GiantKiwiAI, float> kiwiDecisionTimers = new Dictionary<GiantKiwiAI, float>();

		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<bool> CanBaboonEnterFacility;

		public static ConfigEntry<float> BaboonChanceToEnterFacilityPerMinute;

		public static ConfigEntry<float> BaboonChanceToExitFacilityPerMinute;

		public static ConfigEntry<float> BaboonPathingCooldownConfig;

		public static ConfigEntry<int> BaboonInteriorPathRangeConfig;

		public static ConfigEntry<int> BaboonExteriorPathRangeConfig;

		public static ConfigEntry<bool> BaboonCanCarryScrapInOut;

		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_08f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fa: 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");
			CanBrackenReturnInside = ((BaseUnityPlugin)this).Config.Bind<bool>("Escape Settings", "BrackenCanReturnInside", true, "Whether or not the Bracken can return inside the facility after escaping");
			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");
			CanButlerReturnInside = ((BaseUnityPlugin)this).Config.Bind<bool>("Escape Settings", "ButlerCanReturnInside", true, "Whether or not the Butler can return inside the facility after escaping to follow its target.");
			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)");
			BrackenChanceToGoInside = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Bracken Chance To Go Inside", 10f, "The chance that the Bracken will go back inside randomly every minute");
			BrackenInteriorPathRange = ((BaseUnityPlugin)this).Config.Bind<int>("Escape Settings", "Bracken Interior Path Range", 20, "Range at which Bracken can detect entrances while inside");
			BrackenExteriorPathRange = ((BaseUnityPlugin)this).Config.Bind<int>("Escape Settings", "Bracken Exterior Path Range", 200, "Range at which Bracken can detect entrances while outside");
			BrackenPathCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Bracken Path Cooldown", 30f, "Cooldown between Bracken pathing attempts");
			CanKiwiEnterFacility = ((BaseUnityPlugin)this).Config.Bind<bool>("Giant Kiwi Settings", "KiwiCanEnterFacility", true, "Whether or not the Giant Kiwi can enter the facility.");
			KiwiChanceToEnterFacilityPerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Giant Kiwi Settings", "KiwiChanceToEnterFacilityPerMinute", 5f, "Chance per minute for a Kiwi (with no other objective) to try and enter the facility.");
			KiwiChanceToExitFacilityPerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Giant Kiwi Settings", "KiwiChanceToExitFacilityPerMinute", 15f, "Chance per minute for a Kiwi inside (with no other objective) to try and exit the facility.");
			KiwiPathingCooldownConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Giant Kiwi Settings", "KiwiPathingCooldown", 25f, "Cooldown in seconds between a Kiwi attempting to find an entrance/exit.");
			KiwiInteriorPathRangeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Giant Kiwi Settings", "KiwiInteriorPathRange", 40, "Max NavMesh path distance (in units) a Kiwi can be from an exit to path to it while inside.");
			KiwiExteriorPathRangeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Giant Kiwi Settings", "KiwiExteriorPathRange", 70, "Max NavMesh path distance (in units) a Kiwi can be from an entrance to path to it while outside.");
			KiwiCanCarryEggsInOut = ((BaseUnityPlugin)this).Config.Bind<bool>("Giant Kiwi Settings", "KiwiCanCarryEggsInOut", true, "If true, Kiwis will attempt to carry eggs into/out of the facility to return them to their nest (if nest is outside).");
			KiwiCanMakeNestInside = ((BaseUnityPlugin)this).Config.Bind<bool>("Giant Kiwi Settings", "KiwiCanMakeNestInside (Future)", false, "[Experimental] Whether the Giant Kiwi can make its primary nest inside the facility.");
			KiwiNestInsideChance = ((BaseUnityPlugin)this).Config.Bind<float>("Giant Kiwi Settings", "KiwiNestInsideChance (Future)", 0f, "If KiwiCanMakeNestInside is true, this is the chance it will choose to do so at the start of a round.");
			CanBaboonEnterFacility = ((BaseUnityPlugin)this).Config.Bind<bool>("Baboon Hawk Settings", "BaboonCanEnterFacility", true, "Whether or not the Baboon Hawk can enter the facility.");
			BaboonChanceToEnterFacilityPerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Baboon Hawk Settings", "BaboonChanceToEnterFacilityPerMinute", 3f, "Chance per minute for a Baboon Hawk (with no other objective) to try and enter the facility.");
			BaboonChanceToExitFacilityPerMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Baboon Hawk Settings", "BaboonChanceToExitFacilityPerMinute", 10f, "Chance per minute for a Baboon Hawk inside (with no other objective) to try and exit the facility.");
			BaboonPathingCooldownConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Baboon Hawk Settings", "BaboonPathingCooldown", 30f, "Cooldown in seconds between a Baboon Hawk attempting to find an entrance/exit.");
			BaboonInteriorPathRangeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Baboon Hawk Settings", "BaboonInteriorPathRange", 50, "Max NavMesh path distance (in units) a Baboon Hawk can be from an exit to path to it while inside.");
			BaboonExteriorPathRangeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Baboon Hawk Settings", "BaboonExteriorPathRange", 80, "Max NavMesh path distance (in units) a Baboon Hawk can be from an entrance to path to it while outside.");
			BaboonCanCarryScrapInOut = ((BaseUnityPlugin)this).Config.Bind<bool>("Baboon Hawk Settings", "BaboonCanCarryScrapInOut", true, "If true, Baboon Hawks will attempt to carry scrap into/out of the facility to return them to their camp (if camp is outside).");
			ThumperChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Thumper Escape Chance", 10f, "The chance that the Thumper will escape randomly every minute");
			JesterChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Jester Escape Chance", 0f, "The chance that the Jester will escape randomly every minute.");
			CaveDwellerChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Cave Dweller Escape Chance", 5f, "The chance that the Cave Dweller will escape randomly every minute");
			CoilHeadChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Coil Head Escape Chance", 5f, "The chance that the Coil Head will escape randomly every minute");
			SpiderChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Spider Escape Chance", 10f, "The chance that the Spider will escape randomly every minute");
			NutCrackerChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "NutCracker Escape Chance", 10f, "The chance that the Nutcracker will escape randomly every minute");
			HygrodereChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Hygrodere Escape Chance", 0f, "The chance that the Hygrodere/Slime will escape randomly every minute");
			ButlerChanceToEscapeEveryMinute = ((BaseUnityPlugin)this).Config.Bind<float>("Escape Settings", "Butler Escape Chance", 5f, "The chance that the Butler will escape randomly every minute");
			if ((Object)(object)ExtraValues == (Object)null)
			{
				ExtraValues = new GameObject();
				Object.DontDestroyOnLoad((Object)(object)ExtraValues);
				((Object)ExtraValues).hideFlags = (HideFlags)61;
				ExtraValues.AddComponent<LETimerFunctions>();
			}
			mls = ((BaseUnityPlugin)this).Logger;
			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, spawnOnDoor: false);
				}
			}
			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_00cd: 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_011b: 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_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_0146: 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;
			}
			if (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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			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);
					Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)false);
				}
				else
				{
					if (!(LETimerFunctions.MinuteEscapeTimerHoardingBug >= 60f) || !((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null))
					{
						return;
					}
					LETimerFunctions.MinuteEscapeTimerHoardingBug = 0f;
					Object[] array = Object.FindObjectsOfType(typeof(HoarderBugAI));
					float num = ((array.Length != 0) ? ((float)array.Length) : 1f);
					if (num == 0f)
					{
						num = 1f;
					}
					if (!((float)Random.Range(1, 100) <= HoardingBugChanceToEscapeEveryMinute.Value / num))
					{
						return;
					}
					SendEnemyOutside((EnemyAI)(object)__instance);
					if (HoardingBugChanceToNestNearShip.Value != 0f && (float)Random.Range(1, 100) <= HoardingBugChanceToNestNearShip.Value)
					{
						Vector3 val = RoundManager.FindMainEntrancePosition(true, true);
						if (val == Vector3.zero)
						{
							if ((Object)(object)StartOfRound.Instance.shipDoorNode != (Object)null)
							{
								val = ((Component)StartOfRound.Instance.shipDoorNode).transform.position;
							}
							else
							{
								val = StartOfRound.Instance.elevatorTransform.position;
								mls.LogWarning((object)"HoardingBugAILEPrefixAI: shipDoorNode is null, using elevatorTransform as fallback for ship reference.");
							}
						}
						Transform val2 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(val, true, 2);
						if ((Object)(object)val2 != (Object)null)
						{
							__instance.nestPosition = val2.position;
							Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)true);
							Traverse.Create((object)__instance).Method("SyncNestPositionServerRpc", new object[1] { __instance.nestPosition }).GetValue();
							mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (escaped) set OUTSIDE nest near ship at: {__instance.nestPosition}");
						}
						else
						{
							mls.LogWarning((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (escaped) failed to find OUTSIDE nest node near ship. `choseNestPosition` set to false.");
							Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)false);
						}
					}
					else
					{
						Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)false);
					}
				}
			}
			else 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_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)
			{
				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(EnemyAI), "ChooseFarthestNodeFromPosition")]
		[HarmonyPrefix]
		private static bool ChooseFarthestNodeFromPosition_Prefix(EnemyAI __instance, ref Transform __result, Vector3 pos, bool avoidLineOfSight = false, int offset = 0, bool doAsync = false, int maxAsyncIterations = 50, bool capDistance = false)
		{
			if (__instance.allAINodes.Any((GameObject node) => (Object)(object)node == (Object)null))
			{
				__instance.allAINodes = __instance.allAINodes.Where((GameObject node) => (Object)(object)node != (Object)null).ToArray();
				mls.LogWarning((object)("LethalEscape: Cleaned null entries from AINode array for " + ((object)__instance).GetType().Name + ". This prevented a crash."));
			}
			return true;
		}

		[HarmonyPatch(typeof(EnemyAI), "ChooseClosestNodeToPosition")]
		[HarmonyPrefix]
		private static bool ChooseClosestNodeToPosition_Prefix(EnemyAI __instance, ref Transform __result, Vector3 pos, bool avoidLineOfSight = false, int offset = 0)
		{
			if (__instance.allAINodes.Any((GameObject node) => (Object)(object)node == (Object)null))
			{
				__instance.allAINodes = __instance.allAINodes.Where((GameObject node) => (Object)(object)node != (Object)null).ToArray();
				mls.LogWarning((object)("LethalEscape: Cleaned null entries from AINode array for " + ((object)__instance).GetType().Name + ". This prevented a crash."));
			}
			return true;
		}

		[HarmonyPatch(typeof(HoarderBugAI), "Start")]
		[HarmonyPostfix]
		private static void HoardingBugAILEPostfixStart(HoarderBugAI __instance)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || HoardingBugChanceToSpawnOutside.Value == 0f || !((float)Random.Range(1, 100) <= HoardingBugChanceToSpawnOutside.Value))
			{
				return;
			}
			SendEnemyOutside((EnemyAI)(object)__instance);
			if (((EnemyAI)__instance).isOutside && HoardingBugChanceToNestNearShip.Value != 0f && (float)Random.Range(1, 100) <= HoardingBugChanceToNestNearShip.Value)
			{
				Vector3 val = RoundManager.FindMainEntrancePosition(true, true);
				if (val == Vector3.zero)
				{
					if ((Object)(object)StartOfRound.Instance.shipDoorNode != (Object)null)
					{
						val = ((Component)StartOfRound.Instance.shipDoorNode).transform.position;
					}
					else
					{
						val = StartOfRound.Instance.elevatorTransform.position;
						mls.LogWarning((object)"HoardingBugAILEPostfixStart: shipDoorNode is null, using elevatorTransform as fallback for ship reference.");
					}
				}
				Transform val2 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(val, true, 2);
				if ((Object)(object)val2 != (Object)null)
				{
					__instance.nestPosition = val2.position;
					Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)true);
					Traverse.Create((object)__instance).Method("SyncNestPositionServerRpc", new object[1] { __instance.nestPosition }).GetValue();
					mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (spawned outside) set OUTSIDE nest near ship at: {__instance.nestPosition}");
				}
				else
				{
					mls.LogWarning((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (spawned outside) failed to set OUTSIDE nest near ship. `choseNestPosition` = false.");
					Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)false);
				}
			}
			else if (((EnemyAI)__instance).isOutside)
			{
				Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)false);
			}
		}

		[HarmonyPatch(typeof(HoarderBugAI), "ChooseNestPosition")]
		[HarmonyPostfix]
		private static void HoarderBugAI_ChooseNestPosition_Postfix(HoarderBugAI __instance)
		{
			//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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: 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_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: 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_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Invalid comparison between Unknown and I4
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || !((EnemyAI)__instance).isOutside || ((EnemyAI)__instance).isEnemyDead)
			{
				return;
			}
			bool flag = false;
			int areaFromName = NavMesh.GetAreaFromName("Terrain");
			int num = ((areaFromName != -1) ? (1 << areaFromName) : (-1));
			if (__instance.nestPosition == Vector3.zero)
			{
				flag = true;
				mls.LogWarning((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside): Nest position is zero after vanilla ChooseNestPosition. Forcing new outside nest choice.");
			}
			else
			{
				NavMeshPath val = new NavMeshPath();
				int areaMask = ((EnemyAI)__instance).agent.areaMask;
				if (num != -1)
				{
					((EnemyAI)__instance).agent.areaMask = num;
				}
				bool num2 = ((EnemyAI)__instance).agent.CalculatePath(__instance.nestPosition, val);
				((EnemyAI)__instance).agent.areaMask = areaMask;
				if (!num2 || (int)val.status != 0)
				{
					flag = true;
					mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside): Current nest at {__instance.nestPosition} is not pathable on OUTSIDE NavMesh (Path status: {val.status}). Choosing new outside nest.");
				}
				else
				{
					mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside): Current nest at {__instance.nestPosition} is pathable on OUTSIDE NavMesh. Postfix deems it valid.");
				}
			}
			if (!flag)
			{
				return;
			}
			mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) needs a new OUTSIDE nest.");
			Vector3 val2 = Vector3.zero;
			HoarderBugAI[] array = Object.FindObjectsOfType<HoarderBugAI>();
			float num3 = float.MaxValue;
			Vector3 val3 = Vector3.zero;
			HoarderBugAI[] array2 = array;
			foreach (HoarderBugAI val4 in array2)
			{
				if (!((Object)(object)val4 != (Object)(object)__instance) || !((EnemyAI)val4).isOutside || !Traverse.Create((object)val4).Field("choseNestPosition").GetValue<bool>() || !(val4.nestPosition != Vector3.zero))
				{
					continue;
				}
				NavMeshPath val5 = new NavMeshPath();
				int areaMask2 = ((EnemyAI)__instance).agent.areaMask;
				if (num != -1)
				{
					((EnemyAI)__instance).agent.areaMask = num;
				}
				bool num4 = ((EnemyAI)__instance).agent.CalculatePath(val4.nestPosition, val5) && (int)val5.status == 0;
				((EnemyAI)__instance).agent.areaMask = areaMask2;
				if (num4)
				{
					float num5 = Vector3.Distance(((Component)__instance).transform.position, val4.nestPosition);
					if (num5 < num3)
					{
						num3 = num5;
						val3 = val4.nestPosition;
					}
				}
			}
			if (val3 != Vector3.zero)
			{
				val2 = val3;
				mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) will share OUTSIDE nest at {val2}.");
			}
			else
			{
				Transform val6 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(((Component)__instance).transform.position, true, Random.Range(0, 3));
				if ((Object)(object)val6 != (Object)null)
				{
					val2 = val6.position;
					mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) chose new personal OUTSIDE nest at {val2}.");
				}
				else
				{
					mls.LogError((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) FAILED to find any suitable outside node for its nest! This is problematic.");
					Vector3 val7 = RoundManager.FindMainEntrancePosition(true, true);
					if (val7 == Vector3.zero)
					{
						val7 = ((!((Object)(object)StartOfRound.Instance.shipDoorNode != (Object)null)) ? StartOfRound.Instance.elevatorTransform.position : ((Component)StartOfRound.Instance.shipDoorNode).transform.position);
					}
					val6 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(val7, true, 0);
					if ((Object)(object)val6 != (Object)null)
					{
						val2 = val6.position;
					}
					else
					{
						mls.LogError((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) FAILED even fallback nest selection.");
					}
					if (val2 == Vector3.zero)
					{
						return;
					}
				}
			}
			if (val2 != Vector3.zero && Vector3.Distance(__instance.nestPosition, val2) > 0.1f)
			{
				__instance.nestPosition = val2;
				Traverse.Create((object)__instance).Method("SyncNestPositionServerRpc", new object[1] { __instance.nestPosition }).GetValue();
				Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)true);
				mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) nest updated by postfix to: {__instance.nestPosition}");
			}
			else if (val2 != Vector3.zero && !Traverse.Create((object)__instance).Field<bool>("choseNestPosition").Value)
			{
				Traverse.Create((object)__instance).Field("choseNestPosition").SetValue((object)true);
				mls.LogInfo((object)$"Hoarding bug {((Object)__instance).GetInstanceID()} (outside) nest position {__instance.nestPosition} confirmed and flagged as chosen by postfix.");
			}
		}

		[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, spawnOnDoor: false);
				}
			}
			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, spawnOnDoor: false);
					__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), "DoAIInterval")]
		[HarmonyPrefix]
		private static bool DoAIInterval_BrackenCarryBodyFix(FlowermanAI __instance)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isOutside || !__instance.carryingPlayerBody || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return true;
			}
			if (((EnemyAI)__instance).agent.hasPath)
			{
				EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>();
				foreach (EntranceTeleport val in array)
				{
					if (val.isEntranceToBuilding && Vector3.Distance(((EnemyAI)__instance).agent.destination, val.entrancePoint.position) < 1f)
					{
						mls.LogInfo((object)$"Bracken {((Object)__instance).GetInstanceID()} is carrying body towards an entrance. Overriding vanilla AI to prevent body drop.");
						return false;
					}
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(FlowermanAI), "Update")]
		[HarmonyPrefix]
		private static bool FlowermanAILEPrefixAI(FlowermanAI __instance)
		{
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead)
			{
				if (brackenOriginalNests.ContainsKey(__instance))
				{
					brackenOriginalNests.Remove(__instance);
				}
				if (brackenPathingCooldowns.ContainsKey(__instance))
				{
					brackenPathingCooldowns.Remove(__instance);
				}
				if (brackenDecisionTimers.ContainsKey(__instance))
				{
					brackenDecisionTimers.Remove(__instance);
				}
				return true;
			}
			if (!CanBrackenEscape.Value || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return true;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if ((Object)(object)((EnemyAI)__instance).favoriteSpot != (Object)null && !brackenOriginalNests.ContainsKey(__instance))
				{
					brackenOriginalNests[__instance] = ((EnemyAI)__instance).favoriteSpot;
					mls.LogInfo((object)$"LethalEscape: Stored Bracken nest for {((Object)__instance).GetInstanceID()}");
				}
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && !((EnemyAI)__instance).targetPlayer.isInsideFactory && (((EnemyAI)__instance).currentBehaviourStateIndex == 1 || __instance.evadeStealthTimer > 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);
					brackenPathingCooldowns[__instance] = BrackenPathCooldown.Value;
				}
				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, spawnOnDoor: false);
						brackenPathingCooldowns[__instance] = BrackenPathCooldown.Value;
					}
				}
				return true;
			}
			if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
			if (brackenOriginalNests.ContainsKey(__instance))
			{
				((EnemyAI)__instance).favoriteSpot = brackenOriginalNests[__instance];
			}
			if (((EnemyAI)__instance).agent.hasPath)
			{
				EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>();
				foreach (EntranceTeleport val in array)
				{
					if (val.isEntranceToBuilding && Vector3.Distance(((EnemyAI)__instance).agent.destination, val.entrancePoint.position) < 1f)
					{
						if (Vector3.Distance(((Component)__instance).transform.position, val.entrancePoint.position) < 3.5f)
						{
							mls.LogInfo((object)$"Bracken {((Object)__instance).GetInstanceID()} reached entrance {((Object)val).name}. Sending inside.");
							SendEnemyInside((EnemyAI)(object)__instance);
							brackenPathingCooldowns[__instance] = BrackenPathCooldown.Value;
							return true;
						}
						return false;
					}
				}
			}
			if (brackenPathingCooldowns.TryGetValue(__instance, out var value) && value > 0f)
			{
				brackenPathingCooldowns[__instance] -= Time.deltaTime;
				return true;
			}
			if (brackenPathingCooldowns.ContainsKey(__instance) && brackenPathingCooldowns[__instance] <= 0f)
			{
				brackenPathingCooldowns.Remove(__instance);
			}
			bool flag = false;
			string arg = "";
			if (CanBrackenReturnInside.Value && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
			{
				if ((Object)(object)((EnemyAI)__instance).favoriteSpot != (Object)null && (Object)(object)((EnemyAI)__instance).targetNode == (Object)(object)((EnemyAI)__instance).favoriteSpot)
				{
					flag = true;
					arg = "returning to its nest";
				}
				if (!brackenDecisionTimers.ContainsKey(__instance))
				{
					brackenDecisionTimers[__instance] = 60f;
				}
				brackenDecisionTimers[__instance] -= Time.deltaTime;
				if (!flag && brackenDecisionTimers[__instance] <= 0f)
				{
					if (BrackenChanceToGoInside.Value > 0f && Random.Range(0f, 100f) < BrackenChanceToGoInside.Value)
					{
						flag = true;
						arg = "randomly deciding to go back inside";
					}
					brackenDecisionTimers[__instance] = 60f;
				}
			}
			if (flag)
			{
				EntranceTeleport val2 = FindClosestReachableEntrance(((Component)__instance).transform.position, findEntranceToBuilding: true, BrackenExteriorPathRange.Value, ((EnemyAI)__instance).agent);
				if ((Object)(object)val2 != (Object)null)
				{
					mls.LogInfo((object)$"Bracken {((Object)__instance).GetInstanceID()} is {arg}. Pathing to entrance {((Object)val2).name}.");
					((EnemyAI)__instance).SetDestinationToPosition(val2.entrancePoint.position, false);
					return false;
				}
				mls.LogInfo((object)$"Bracken {((Object)__instance).GetInstanceID()} wants to {arg}, but no reachable entrance found. Starting cooldown.");
				brackenPathingCooldowns[__instance] = BrackenPathCooldown.Value;
				return true;
			}
			return true;
		}

		[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)
			{
				if (((EnemyAI)__instance).isEnemyDead && butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
				{
					butlerPendingLeaveFacilityInfo.Remove(__instance);
				}
				return;
			}
			PlayerControllerB targetPlayer = ((EnemyAI)__instance).targetPlayer;
			int value = Traverse.Create((object)__instance).Field("currentBehaviourStateIndex").GetValue<int>();
			if ((Object)(object)targetPlayer == (Object)null || targetPlayer.isPlayerDead || (value != 1 && value != 2))
			{
				if (butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
				{
					mls.LogInfo((object)string.Format("Butler {0} no longer meets criteria for following (Target: {1}, State: {2}). Clearing pending leave timer.", ((Object)__instance).GetInstanceID(), ((Object)(object)targetPlayer == (Object)null) ? "null" : (targetPlayer.isPlayerDead ? (targetPlayer.playerUsername + "(Dead)") : targetPlayer.playerUsername), value));
					butlerPendingLeaveFacilityInfo.Remove(__instance);
				}
				return;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				if (!targetPlayer.isInsideFactory)
				{
					if (!butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
					{
						butlerPendingLeaveFacilityInfo[__instance] = Time.time;
						mls.LogInfo((object)$"Butler {((Object)__instance).GetInstanceID()} (State: {value}) target {targetPlayer.playerUsername} is outside. Initiating escape timer with delay: {ButlerEscapeDelay.Value}s.");
					}
					if (Time.time - butlerPendingLeaveFacilityInfo[__instance] >= ButlerEscapeDelay.Value)
					{
						mls.LogInfo((object)$"Butler {((Object)__instance).GetInstanceID()} escape delay ({ButlerEscapeDelay.Value}s) met. Sending Butler outside to follow {targetPlayer.playerUsername}.");
						SendEnemyOutside((EnemyAI)(object)__instance);
						butlerPendingLeaveFacilityInfo.Remove(__instance);
					}
				}
				else if (butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
				{
					mls.LogInfo((object)$"Butler {((Object)__instance).GetInstanceID()} target {targetPlayer.playerUsername} is back inside. Cancelling Butler's pending leave.");
					butlerPendingLeaveFacilityInfo.Remove(__instance);
				}
				return;
			}
			if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
			{
				((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
			}
			if (!targetPlayer.isInsideFactory)
			{
				return;
			}
			if (CanButlerReturnInside.Value)
			{
				mls.LogInfo((object)$"Butler {((Object)__instance).GetInstanceID()} (State: {value}) is outside, its target {targetPlayer.playerUsername} is inside. Config allows return. Sending Butler back inside immediately.");
				SendEnemyInside((EnemyAI)(object)__instance);
				if (butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
				{
					butlerPendingLeaveFacilityInfo.Remove(__instance);
				}
			}
			else
			{
				mls.LogInfo((object)$"Butler {((Object)__instance).GetInstanceID()} (State: {value}) is outside, target {targetPlayer.playerUsername} is inside, but CanButlerReturnInside is false. Butler will not return.");
				if (butlerPendingLeaveFacilityInfo.ContainsKey(__instance))
				{
					butlerPendingLeaveFacilityInfo.Remove(__instance);
				}
			}
		}

		[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(ButlerEnemyAI), "KillEnemy", new Type[] { typeof(bool) })]
		[HarmonyPrefix]
		private static void PrefixButlerKillEnemy(ButlerEnemyAI __instance)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost && ((EnemyAI)__instance).isOutside && !((EnemyAI)__instance).isEnemyDead)
			{
				LastButlerDeathPositionOutside = ((Component)__instance).transform.position;
				LastButlerDeathTimeOutside = Time.realtimeSinceStartup;
				ButlerRecentlyDiedOutside = true;
				mls.LogInfo((object)$"Butler flagged as dying outside at {LastButlerDeathPositionOutside}. Timestamp: {LastButlerDeathTimeOutside}");
			}
		}

		[HarmonyPatch(typeof(ButlerBeesEnemyAI), "Start")]
		[HarmonyPostfix]
		private static void PostfixBeeStart(ButlerBeesEnemyAI __instance)
		{
			//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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_00f1: 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_0147: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || ((EnemyAI)__instance).isOutside)
			{
				return;
			}
			float num = Time.realtimeSinceStartup - LastButlerDeathTimeOutside;
			if (ButlerRecentlyDiedOutside && num < 2f && Vector3.Distance(((Component)__instance).transform.position, LastButlerDeathPositionOutside) < 5f)
			{
				mls.LogInfo((object)$"ButlerBee at {((Component)__instance).transform.position} spawned by Butler that recently died outside. Configuring for outside environment.");
				((EnemyAI)__instance).isOutside = true;
				bool flag = true;
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					flag = !StartOfRound.Instance.hangarDoorsClosed || !GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom;
				}
				((EnemyAI)__instance).EnableEnemyMesh(flag, false);
				Vector3 position = ((Component)__instance).transform.position;
				NavMeshHit val = default(NavMeshHit);
				if (NavMesh.SamplePosition(position, ref val, 2f, ((EnemyAI)__instance).agent.areaMask))
				{
					position = ((NavMeshHit)(ref val)).position;
				}
				else
				{
					mls.LogWarning((object)$"ButlerBee (Outside): Failed to sample NavMesh at initial spawn {((Component)__instance).transform.position}. Attempting to find closest outside AI node.");
					Transform val2 = ((EnemyAI)__instance).ChooseClosestNodeToPosition(position, true, 0);
					if ((Object)(object)val2 != (Object)null)
					{
						position = val2.position;
					}
					else
					{
						mls.LogWarning((object)"ButlerBee (Outside): No close outside AINode found. Bee might be stuck or out of NavMesh bounds.");
					}
				}
				((EnemyAI)__instance).serverPosition = position;
				((Component)__instance).transform.position = position;
				if (!((Behaviour)((EnemyAI)__instance).agent).enabled)
				{
					((Behaviour)((EnemyAI)__instance).agent).enabled = true;
				}
				if (!((EnemyAI)__instance).agent.Warp(position))
				{
					mls.LogWarning((object)$"ButlerBee (Outside): NavMeshAgent failed to warp to {position}. The NavMesh might not be baked correctly for this area, or the agent is in an invalid state.");
				}
				((EnemyAI)__instance).SyncPositionToClients();
				if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
				{
					((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
				}
				mls.LogInfo((object)"ButlerBee successfully configured for outside.");
			}
			if (ButlerRecentlyDiedOutside && num >= 2f)
			{
				ButlerRecentlyDiedOutside = false;
			}
		}

		[HarmonyPatch(typeof(ButlerBeesEnemyAI), "OnCollideWithPlayer")]
		[HarmonyPrefix]
		public static bool ButlerBeesAILEOutsideAttackPrefix(ButlerBeesEnemyAI __instance, Collider other)
		{
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isEnemyDead)
			{
				return true;
			}
			if (!((EnemyAI)__instance).isOutside)
			{
				return true;
			}
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return false;
			}
			Traverse val = Traverse.Create((object)__instance);
			float value = val.Field("timeAtSpawning").GetValue<float>();
			float value2 = val.Field("timeAtLastHurtingPlayer").GetValue<float>();
			if (Time.realtimeSinceStartup - value < 1.7f)
			{
				return false;
			}
			if (Time.realtimeSinceStartup - value2 < 0.5f)
			{
				return false;
			}
			PlayerControllerB val2 = ((EnemyAI)__instance).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val2 != (Object)null)
			{
				val.Field("timeAtLastHurtingPlayer").SetValue((object)Time.realtimeSinceStartup);
				if (((NetworkBehaviour)__instance).OwnerClientId != GameNetworkManager.Instance.localPlayerController.actualClientId)
				{
					((EnemyAI)__instance).ChangeOwnershipOfEnemy(GameNetworkManager.Instance.localPlayerController.actualClientId);
				}
				mls.LogInfo((object)("Host: Outside Butler Bee attacking player " + val2.playerUsername + "."));
				val2.DamagePlayer(10, true, true, (CauseOfDeath)14, 0, false, default(Vector3));
				if ((Object)(object)val2 != (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					val2.DamagePlayerFromOtherClientServerRpc(10, Vector3.zero, -1);
				}
				return false;
			}
			return false;
		}

		[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 1.0.6 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);
			}
		}

		[HarmonyPatch(typeof(BaboonBirdAI), "Update")]
		[HarmonyPrefix]
		public static bool BaboonBirdAI_Update_Prefix(BaboonBirdAI __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Invalid comparison between Unknown and I4
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || ((EnemyAI)__instance).isEnemyDead || ((EnemyAI)__instance).inSpecialAnimation || ((EnemyAI)__instance).stunNormalizedTimer > 0f)
			{
				if (baboonsPathingToDoor.ContainsKey(__instance))
				{
					baboonsPathingToDoor.Remove(__instance);
				}
				return true;
			}
			if (!baboonsPathingToDoor.ContainsKey(__instance))
			{
				baboonsPathingToDoor[__instance] = false;
			}
			if (baboonsPathingToDoor.TryGetValue(__instance, out var value) && value)
			{
				if (!((EnemyAI)__instance).agent.hasPath || (int)((EnemyAI)__instance).agent.pathStatus == 2)
				{
					mls.LogInfo((object)$"Baboon ({((Object)__instance).GetInstanceID()}) lost its path to the door. Resetting state.");
					baboonsPathingToDoor.Remove(__instance);
					baboonPathingCooldowns[__instance] = BaboonPathingCooldownConfig.Value;
					return true;
				}
				if (((EnemyAI)__instance).agent.remainingDistance < 3.5f)
				{
					bool flag = (Object)(object)__instance.heldScrap != (Object)null;
					if (((EnemyAI)__instance).isOutside)
					{
						mls.LogInfo((object)$"Baboon ({((Object)__instance).GetInstanceID()}) has arrived at entrance, sending inside.");
						if (flag && BaboonCanCarryScrapInOut.Value && (Object)(object)__instance.heldScrap != (Object)null)
						{
							__instance.heldScrap.isInFactory = true;
						}
						SendEnemyInside((EnemyAI)(object)__instance);
					}
					else
					{
						mls.LogInfo((object)$"Baboon ({((Object)__instance).GetInstanceID()}) has arrived at exit, sending outside.");
						if (flag && BaboonCanCarryScrapInOut.Value && (Object)(object)__instance.heldScrap != (Object)null)
						{
							__instance.heldScrap.isInFactory = false;
						}
						SendEnemyOutside((EnemyAI)(object)__instance);
					}
					baboonsPathingToDoor.Remove(__instance);
					baboonPathingCooldowns[__instance] = BaboonPathingCooldownConfig.Value;
					return true;
				}
				return false;
			}
			if (!baboonDecisionTimers.ContainsKey(__instance))
			{
				baboonDecisionTimers[__instance] = 60f;
			}
			if (!baboonPathingCooldowns.ContainsKey(__instance))
			{
				baboonPathingCooldowns[__instance] = 0f;
			}
			if (baboonPathingCooldowns[__instance] > 0f)
			{
				baboonPathingCooldowns[__instance] -= Time.deltaTime;
				return true;
			}
			bool flag2 = false;
			Traverse obj = Traverse.Create((object)__instance);
			PlayerControllerB val = null;
			Threat value2 = obj.Field<Threat>("focusedThreat").Value;
			if (value2 != null && value2.threatScript != null && (int)value2.threatScript.type == 0)
			{
				Transform threatTransform = value2.threatScript.GetThreatTransform();
				val = ((threatTransform != null) ? ((Component)threatTransform).GetComponent<PlayerControllerB>() : null);
				flag2 = true;
			}
			baboonDecisionTimers[__instance] -= Time.deltaTime;
			if (baboonDecisionTimers[__instance] <= 0f)
			{
				flag2 = true;
				baboonDecisionTimers[__instance] = 60f;
			}
			if (!flag2)
			{
				return true;
			}
			bool flag3 = (Object)(object)__instance.heldScrap != (Object)null;
			bool flag4 = false;
			string arg = "";
			bool flag5 = false;
			string arg2 = "";
			if (((EnemyAI)__instance).isOutside)
			{
				if (CanBaboonEnterFacility.Value && (Object)(object)val != (Object)null && val.isInsideFactory && !val.isPlayerDead)
				{
					flag4 = true;
					arg = "Target player " + val.playerUsername + " is inside.";
				}
				else if (CanBaboonEnterFacility.Value && baboonDecisionTimers[__instance] <= 0f && Random.Range(0f, 100f) < BaboonChanceToEnterFacilityPerMinute.Value)
				{
					flag4 = true;
					arg = "Random decision to explore inside.";
				}
			}
			else if ((Object)(object)val != (Object)null && !val.isInsideFactory && !val.isPlayerDead)
			{
				flag5 = true;
				arg2 = "Target player " + val.playerUsername + " is outside.";
			}
			else if (flag3 && BaboonCanCarryScrapInOut.Value)
			{
				flag5 = true;
				arg2 = "Carrying scrap '" + ((Object)__instance.heldScrap).name + "' and its camp is outside.";
			}
			else if (baboonDecisionTimers[__instance] <= 0f && Random.Range(0f, 100f) < BaboonChanceToExitFacilityPerMinute.Value)
			{
				flag5 = true;
				arg2 = "Random decision to explore outside.";
			}
			if (flag4)
			{
				EntranceTeleport val2 = FindClosestReachableEntrance(((Component)__instance).transform.position, findEntranceToBuilding: true, BaboonExteriorPathRangeConfig.Value, ((EnemyAI)__instance).agent);
				if ((Object)(object)val2 != (Object)null)
				{
					((EnemyAI)__instance).StopSearch(__instance.scoutingSearchRoutine, true);
					((EnemyAI)__instance).StopSearch(((EnemyAI)__instance).currentSearch, true);
					((EnemyAI)__instance).SetDestinationToPosition(val2.entrancePoint.position, false);
					mls.LogInfo((object)$"Baboon ({((Object)__instance).GetInstanceID()}) decided to enter ({arg}). Pathing to {((Object)val2).name}.");
					baboonsPathingToDoor[__instance] = true;
					return false;
				}
			}
			else if (flag5)
			{
				EntranceTeleport val3 = FindClosestReachableEntrance(((Component)__instance).transform.position, findEntranceToBuilding: false, BaboonInteriorPathRangeConfig.Value, ((EnemyAI)__instance).agent);
				if ((Object)(object)val3 != (Object)null)
				{
					((EnemyAI)__instance).StopSearch(__instance.scoutingSearchRoutine, true);
					((EnemyAI)__instance).StopSearch(((EnemyAI)__instance).currentSearch, true);
					((EnemyAI)__instance).SetDestinationToPosition(val3.entrancePoint.position, false);
					mls.LogInfo((object)$"Baboon ({((Object)__instance).GetInstanceID()}) decided to exit ({arg2}). Pathing to {((Object)val3).name}.");
					baboonsPathingToDoor[__instance] = true;
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch(typeof(BaboonBirdAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void BaboonBirdAI_OnCollideWithPlayer_Postfix(BaboonBirdAI __instance, Collider other)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost || ((EnemyAI)__instance).isEnemyDead || ((EnemyAI)__instance).stunNormalizedTimer > 0f || ((EnemyAI)__instance).isOutside)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if (!((Object)(object)component != (Object)null) || !((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController) || component.isPlayerDead || !component.isPlayerControlled)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			if (val.Field<float>("timeSinceHitting").Value < 0.5f)
			{
				return;
			}
			Vector3 val2 = Vector3.Normalize(((Component)__instance).transform.position + Vector3.up * 0.7f - (((Component)other).transform.position + Vector3.up * 0.4f)) * 0.5f;
			if (!Physics.Linecast(((Component)__instance).transform.position + Vector3.up * 0.7f + val2, ((Component)other).transform.position + Vector3.up * 0.4f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				mls.LogInfo((object)("Host-controlled Baboon (inside) attacking non-host player " + component.playerUsername + "."));
				val.Field("timeSinceHitting").SetValue((object)0f);
				component.DamagePlayer(20, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				component.DamagePlayerFromOtherClientServerRpc(20, Vector3.zero, -1);
				if (component.isPlayerDead)
				{
					__instance.StabPlayerDeathAnimServerRpc((int)component.playerClientId);
				}
			}
		}

		[HarmonyPatch(typeof(GiantKiwiAI), "OnCollideWithPlayer")]
		[HarmonyPostfix]
		public static void GiantKiwiAILEOutsideAttack(GiantKiwiAI __instance, Collider other)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			if (((EnemyAI)__instance).isEnemyDead || __instance.inKillAnimation || !((EnemyAI)__instance).isOutside || !((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost)
			{
				return;
			}
			PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)component != (Object)null && component.isPlayerControlled && !component.isPlayerDead && (Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				Traverse obj = Traverse.Create((object)__instance);
				bool value = obj.Field<bool>("attacking").Value;
				float value2 = obj.Field<float>("timeSinceHittingGround").Value;
				if (value && value2 < 0.2f)
				{
					mls.LogInfo((object)("LethalEscape: Host-controlled Kiwi (outside) attacking non-host player " + component.playerUsername + " based o