Decompiled source of StarlancerEnemyEscape v2.4.1

StarlancerEnemyEscape.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 EnemyEscape;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StarlancerAIFix.Patches;
using StarlancerEnemyEscape;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("StarlancerEnemyEscape")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+59295cca759c482e1cb3a7e3cce1b058dec3b59b")]
[assembly: AssemblyProduct("StarlancerEnemyEscape")]
[assembly: AssemblyTitle("StarlancerEnemyEscape")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StarlancerEnemyEscape
{
	[BepInPlugin("AudioKnight.StarlancerEnemyEscape", "Starlancer EnemyEscape", "2.4.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class StarlancerEnemyEscapeBase : BaseUnityPlugin
	{
		public enum ConfigPreset
		{
			Disabled,
			ReasonableDefaults,
			Minimal,
			Chaos
		}

		private const string modGUID = "AudioKnight.StarlancerEnemyEscape";

		private const string modName = "Starlancer EnemyEscape";

		private const string modVersion = "2.4.1";

		private readonly Harmony harmony = new Harmony("AudioKnight.StarlancerEnemyEscape");

		public static StarlancerEnemyEscapeBase Instance;

		internal static ManualLogSource logger;

		internal static ConfigFile EnemyEscapeConfig = new ConfigFile(Path.Combine(Paths.ConfigPath, "AudioKnight.StarlancerEnemyEscape.cfg"), true);

		public static ConfigEntry<ConfigPreset> configEscapePreset;

		internal static Dictionary<string, ConfigEntry<int>> EnemyEscapeConfigDictionary = new Dictionary<string, ConfigEntry<int>>();

		internal static Dictionary<string, ConfigEntry<int>> configEscapeInteriorRange = new Dictionary<string, ConfigEntry<int>>();

		internal static Dictionary<string, ConfigEntry<int>> configEscapeExteriorRange = new Dictionary<string, ConfigEntry<int>>();

		internal static Dictionary<string, ConfigEntry<int>> configEscapeCooldownTime = new Dictionary<string, ConfigEntry<int>>();

		internal static Dictionary<string, string> EnemyBlacklist = new Dictionary<string, string>
		{
			{ "Girl", "Unneeded" },
			{ "Masked", "Unneeded" },
			{ "Tulip Snake", "Unneeded" },
			{ "Docile Locust Bees", "Unneeded" },
			{ "Manticoil", "Unneeded" },
			{ "Lasso", "Unimplemented" },
			{ "Red pill", "Unimplemented" }
		};

		internal static Dictionary<string, string> VanillaEnemyList = new Dictionary<string, string>
		{
			{ "Blob", "" },
			{ "Bunker Spider", "" },
			{ "Butler", "" },
			{ "Butler Bees", "" },
			{ "Centipede", "" },
			{ "Crawler", "" },
			{ "Flowerman", "" },
			{ "Hoarding bug", "" },
			{ "Jester", "" },
			{ "Nutcracker", "" },
			{ "Puffer", "" },
			{ "Spring", "" },
			{ "Baboon hawk", "" },
			{ "Earth Leviathan", "" },
			{ "ForestGiant", "" },
			{ "MouthDog", "" },
			{ "RadMech", "" },
			{ "Red Locust Bees", "" }
		};

		internal static Dictionary<string, int> DefaultPresetValues = new Dictionary<string, int>
		{
			{ "Blob", 0 },
			{ "Bunker Spider", 10 },
			{ "Butler", 5 },
			{ "Butler Bees", 5 },
			{ "Centipede", 0 },
			{ "Crawler", 10 },
			{ "Flowerman", 10 },
			{ "Hoarding bug", 10 },
			{ "Jester", 1 },
			{ "Nutcracker", 5 },
			{ "Puffer", 10 },
			{ "Spring", 5 },
			{ "Baboon hawk", 15 },
			{ "Earth Leviathan", 0 },
			{ "ForestGiant", 0 },
			{ "MouthDog", 0 },
			{ "RadMech", 0 },
			{ "Red Locust Bees", 5 }
		};

		internal static Dictionary<string, int> DisabledPresetValues = new Dictionary<string, int>
		{
			{ "Blob", 0 },
			{ "Bunker Spider", 0 },
			{ "Butler", 0 },
			{ "Butler Bees", 0 },
			{ "Centipede", 0 },
			{ "Crawler", 0 },
			{ "Flowerman", 0 },
			{ "Hoarding bug", 0 },
			{ "Jester", 0 },
			{ "Nutcracker", 0 },
			{ "Puffer", 0 },
			{ "Spring", 0 },
			{ "Baboon hawk", 0 },
			{ "Earth Leviathan", 0 },
			{ "ForestGiant", 0 },
			{ "MouthDog", 0 },
			{ "RadMech", 0 },
			{ "Red Locust Bees", 0 }
		};

		internal static Dictionary<string, int> MinimalPresetValues = new Dictionary<string, int>
		{
			{ "Blob", 1 },
			{ "Bunker Spider", 1 },
			{ "Butler", 1 },
			{ "Butler Bees", 1 },
			{ "Centipede", 1 },
			{ "Crawler", 1 },
			{ "Flowerman", 1 },
			{ "Hoarding bug", 1 },
			{ "Jester", 1 },
			{ "Nutcracker", 1 },
			{ "Puffer", 1 },
			{ "Spring", 1 },
			{ "Baboon hawk", 1 },
			{ "Earth Leviathan", 1 },
			{ "ForestGiant", 1 },
			{ "MouthDog", 1 },
			{ "RadMech", 1 },
			{ "Red Locust Bees", 1 }
		};

		internal static Dictionary<string, int> ChaosPresetValues = new Dictionary<string, int>
		{
			{ "Blob", 100 },
			{ "Bunker Spider", 100 },
			{ "Butler", 100 },
			{ "Butler Bees", 100 },
			{ "Centipede", 100 },
			{ "Crawler", 100 },
			{ "Flowerman", 100 },
			{ "Hoarding bug", 100 },
			{ "Jester", 100 },
			{ "Nutcracker", 100 },
			{ "Puffer", 100 },
			{ "Spring", 100 },
			{ "Baboon hawk", 100 },
			{ "Earth Leviathan", 100 },
			{ "ForestGiant", 100 },
			{ "MouthDog", 100 },
			{ "RadMech", 100 },
			{ "Red Locust Bees", 100 }
		};

		private void Awake()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			EnemyEscapeConfig = ((BaseUnityPlugin)this).Config;
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"Starlancer is allowing enemies to roam.");
			configEscapePreset = ((BaseUnityPlugin)this).Config.Bind<ConfigPreset>("EnemyEscape", "EscapePreset", ConfigPreset.ReasonableDefaults, new ConfigDescription("Which preset to use. If an enemy has a value manually set below, it will take priority.\nReasonableDefaults: Blob:0, Bunker Spider:10, Butler:5, Butler Bees:5, Centipede:0, Crawler:10, Flowerman:10, Hoarding bug:10, Jester:1, Nutcracker:5, Puffer:10, Spring:5, Baboon hawk:15, Earth Leviathan:0, ForestGiant:0, MouthDog:0, RadMech:0, Red Locust Bees:5\nDisabled: All 0s, Minimal: All 1s, Chaos: All 100s (Use at your own risk)", (AcceptableValueBase)null, Array.Empty<object>()));
			harmony.PatchAll(typeof(StarlancerEnemyEscapeBase));
			harmony.PatchAll(typeof(StarlancerEscapeComponent));
		}

		internal static Dictionary<string, int> GetPresetValues(ConfigPreset preset)
		{
			return preset switch
			{
				ConfigPreset.Disabled => DisabledPresetValues, 
				ConfigPreset.ReasonableDefaults => DefaultPresetValues, 
				ConfigPreset.Minimal => MinimalPresetValues, 
				ConfigPreset.Chaos => ChaosPresetValues, 
				_ => DefaultPresetValues, 
			};
		}

		internal static Dictionary<string, int> GetCurrentlySelectedPreset()
		{
			return GetPresetValues(configEscapePreset.Value);
		}
	}
}
namespace EnemyEscape
{
	internal class StarlancerEscapeComponent : MonoBehaviour
	{
		private const int UpdateInterval = 1;

		private const float TeleportCooldownTime = 5f;

		private const float TeleportRange = 1f;

		private const int intPathRangeDefault = 20;

		private const int extPathRangeDefault = 200;

		private const int cooldownTimeDefault = 30;

		internal static EntranceTeleport[] entranceTeleports;

		internal static EntranceTeleport[] outsideTeleports;

		internal static EntranceTeleport[] insideTeleports;

		internal int chanceToEscape;

		internal int interiorPathRange;

		internal int exteriorPathRange;

		internal int pathCooldownTime;

		private bool ignoreStateCheck;

		private bool pathingToTeleport;

		private bool teleportFound;

		private bool closeToTeleport;

		private int pathRange;

		private float lastTeleportCheck;

		private float lastTeleportTime;

		private float lastPathAttempt;

		private float prevPathDistance;

		private Vector3 closestTeleportPosition;

		private Vector3 randomEnemyDestination;

		private Random random;

		private EnemyAI enemy;

		private NavMeshPath pathToTeleport;

		private EntranceTeleport closestTeleport;

		private Transform insideFavoriteSpot;

		private Transform outsideFavoriteSpot;

		private void Awake()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			enemy = ((Component)this).GetComponent<EnemyAI>();
			pathToTeleport = new NavMeshPath();
			lastTeleportCheck = Time.time;
			lastTeleportTime = Time.time;
			lastPathAttempt = Time.time;
			closestTeleportPosition = Vector3.negativeInfinity;
			prevPathDistance = float.PositiveInfinity;
			random = new Random(StartOfRound.Instance.randomMapSeed);
			interiorPathRange = StarlancerEnemyEscapeBase.configEscapeInteriorRange[enemy.enemyType.enemyName].Value;
			exteriorPathRange = StarlancerEnemyEscapeBase.configEscapeExteriorRange[enemy.enemyType.enemyName].Value;
			pathCooldownTime = StarlancerEnemyEscapeBase.configEscapeCooldownTime[enemy.enemyType.enemyName].Value;
			StarlancerEnemyEscapeBase.logger.LogInfo((object)("Adding EscapeComponent to " + ((Object)((Component)enemy).gameObject).name + ". It may now roam freely."));
			if (StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[enemy.enemyType.enemyName].Value == -1)
			{
				chanceToEscape = StarlancerEnemyEscapeBase.GetCurrentlySelectedPreset().GetValueOrDefault(enemy.enemyType.enemyName, 0);
			}
			else
			{
				chanceToEscape = StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[enemy.enemyType.enemyName].Value;
			}
			if (chanceToEscape == 0)
			{
				StarlancerEnemyEscapeBase.logger.LogInfo((object)("ChanceToEscape is 0, removing EscapeComponent from " + ((Object)((Component)this).gameObject).name));
				Object.Destroy((Object)(object)((Component)enemy).GetComponent<StarlancerEscapeComponent>());
			}
			if (enemy.isOutside)
			{
				outsideFavoriteSpot = enemy.favoriteSpot;
				insideFavoriteSpot = AIFix.insideAINodes[random.Next(0, AIFix.insideAINodes.Length - 1)].transform;
				pathRange = exteriorPathRange;
			}
			else
			{
				insideFavoriteSpot = enemy.favoriteSpot;
				outsideFavoriteSpot = AIFix.outsideAINodes[random.Next(0, AIFix.outsideAINodes.Length - 1)].transform;
				pathRange = interiorPathRange;
			}
			if (((object)enemy).GetType() == typeof(RedLocustBees))
			{
				ignoreStateCheck = true;
			}
		}

		private void Update()
		{
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Invalid comparison between Unknown and I4
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_083b: Unknown result type (might be due to invalid IL or missing references)
			//IL_084b: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0886: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_096c: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_077b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ada: Unknown result type (might be due to invalid IL or missing references)
			if (enemy.isEnemyDead)
			{
				Object.Destroy((Object)(object)((Component)enemy).GetComponent<StarlancerEscapeComponent>());
			}
			if (Time.time - lastTeleportCheck <= 1f)
			{
				return;
			}
			lastTeleportCheck = Time.time;
			if (!ignoreStateCheck && enemy.currentBehaviourStateIndex != 0)
			{
				lastPathAttempt += Time.deltaTime;
			}
			if (Time.time - lastPathAttempt > (float)pathCooldownTime || pathingToTeleport)
			{
				if (((object)enemy).GetType() == typeof(FlowermanAI))
				{
					return;
				}
				if (((object)enemy).GetType() == typeof(HoarderBugAI))
				{
					if (((Component)enemy).GetComponent<HoarderBugAI>().heldItem != null)
					{
						enemy.SetDestinationToPosition(((Component)enemy).GetComponent<HoarderBugAI>().nestPosition, false);
						lastPathAttempt += Time.deltaTime;
						return;
					}
				}
				else if (((object)enemy).GetType() == typeof(RedLocustBees) && !((Component)enemy).GetComponent<RedLocustBees>().searchForHive.inProgress)
				{
					lastPathAttempt = Time.time;
					return;
				}
				if (pathingToTeleport)
				{
					enemy.SetDestinationToPosition(closestTeleportPosition, false);
					enemy.agent.SetDestination(closestTeleportPosition);
				}
				else if (random.Next(0, 100) <= chanceToEscape)
				{
					EntranceTeleport[] array = entranceTeleports;
					foreach (EntranceTeleport val in array)
					{
						NavMesh.CalculatePath(((Component)enemy).transform.position, ((Component)val.entrancePoint).transform.position, enemy.agent.areaMask, pathToTeleport);
						if ((int)pathToTeleport.status <= 0)
						{
							Vector3[] corners = pathToTeleport.corners;
							float num = 0f;
							for (int j = 1; j < corners.Length; j++)
							{
								num += Vector3.Distance(corners[j - 1], corners[j]);
							}
							if (!(num > (float)pathRange) && num < prevPathDistance)
							{
								teleportFound = true;
								prevPathDistance = num;
								closestTeleport = val;
								closestTeleportPosition = ((Component)val.entrancePoint).transform.position;
							}
						}
					}
					if (teleportFound)
					{
						pathingToTeleport = true;
						enemy.SetDestinationToPosition(closestTeleportPosition, false);
						enemy.agent.SetDestination(closestTeleportPosition);
					}
				}
				lastPathAttempt = Time.time;
			}
			if (Time.time - lastTeleportTime < 5f)
			{
				return;
			}
			if (!pathingToTeleport)
			{
				if (enemy.isOutside)
				{
					EntranceTeleport[] array2 = outsideTeleports;
					foreach (EntranceTeleport val2 in array2)
					{
						if (Vector3.Distance(((Component)enemy).transform.position, ((Component)val2.entrancePoint).transform.position) < 1f)
						{
							closeToTeleport = true;
						}
					}
				}
				if (!enemy.isOutside)
				{
					EntranceTeleport[] array3 = insideTeleports;
					foreach (EntranceTeleport val3 in array3)
					{
						if (Vector3.Distance(((Component)enemy).transform.position, ((Component)val3.entrancePoint).transform.position) < 1f)
						{
							closeToTeleport = true;
						}
					}
				}
			}
			if (enemy.isOutside && (Vector3.Distance(((Component)enemy).transform.position, closestTeleportPosition) <= 1f || closeToTeleport))
			{
				for (int m = 0; m < outsideTeleports.Length; m++)
				{
					if (Vector3.Distance(((Component)outsideTeleports[m].entrancePoint).transform.position, ((Component)enemy).transform.position) <= 1f)
					{
						TeleportAndRefresh();
						enemy.agent.Warp(((Component)insideTeleports[m].entrancePoint).transform.position);
						enemy.SetEnemyOutside(false);
						pathRange = interiorPathRange;
						enemy.favoriteSpot = insideFavoriteSpot;
						TeleportAndRefresh();
						if (((object)enemy).GetType() == typeof(BaboonBirdAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<BaboonBirdAI>().scoutingSearchRoutine);
							((Component)enemy).GetComponent<BaboonBirdAI>().scoutingSearchRoutine.unsearchedNodes = enemy.allAINodes.ToList();
						}
						else if (((object)enemy).GetType() == typeof(HoarderBugAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<HoarderBugAI>().searchForItems);
							((Component)enemy).GetComponent<HoarderBugAI>().searchForItems.unsearchedNodes = enemy.allAINodes.ToList();
						}
						else if (((object)enemy).GetType() == typeof(CrawlerAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<CrawlerAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(SpringManAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<SpringManAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(BlobAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<BlobAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(RedLocustBees))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<RedLocustBees>().searchForHive);
						}
						else
						{
							enemy.StartSearch(((Component)enemy).transform.position, (AISearchRoutine)null);
						}
						break;
					}
				}
			}
			else
			{
				if ((enemy.isOutside || !(Vector3.Distance(((Component)enemy).transform.position, closestTeleportPosition) <= 1f)) && !closeToTeleport)
				{
					return;
				}
				for (int n = 0; n < insideTeleports.Length; n++)
				{
					if (Vector3.Distance(((Component)insideTeleports[n].entrancePoint).transform.position, ((Component)enemy).transform.position) <= 1f)
					{
						enemy.agent.Warp(((Component)outsideTeleports[n].entrancePoint).transform.position);
						enemy.SetEnemyOutside(true);
						pathRange = exteriorPathRange;
						enemy.favoriteSpot = outsideFavoriteSpot;
						TeleportAndRefresh();
						if (((object)enemy).GetType() == typeof(BaboonBirdAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<BaboonBirdAI>().scoutingSearchRoutine);
							((Component)enemy).GetComponent<BaboonBirdAI>().scoutingSearchRoutine.unsearchedNodes = enemy.allAINodes.ToList();
						}
						else if (((object)enemy).GetType() == typeof(HoarderBugAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<HoarderBugAI>().searchForItems);
							((Component)enemy).GetComponent<HoarderBugAI>().searchForItems.unsearchedNodes = enemy.allAINodes.ToList();
						}
						else if (((object)enemy).GetType() == typeof(CrawlerAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<CrawlerAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(SpringManAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<SpringManAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(BlobAI))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<BlobAI>().searchForPlayers);
						}
						else if (((object)enemy).GetType() == typeof(RedLocustBees))
						{
							enemy.StartSearch(((Component)enemy).transform.position, ((Component)enemy).GetComponent<RedLocustBees>().searchForHive);
						}
						else
						{
							enemy.StartSearch(((Component)enemy).transform.position, (AISearchRoutine)null);
						}
						break;
					}
				}
			}
		}

		private void TeleportAndRefresh()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			closeToTeleport = false;
			lastTeleportTime = Time.time;
			prevPathDistance = float.PositiveInfinity;
			pathingToTeleport = false;
			teleportFound = false;
			randomEnemyDestination = enemy.allAINodes[random.Next(0, enemy.allAINodes.Length - 1)].transform.position;
			enemy.SetDestinationToPosition(randomEnemyDestination, false);
			enemy.agent.SetDestination(randomEnemyDestination);
			enemy.DoAIInterval();
		}

		[HarmonyPatch(typeof(EnemyAI), "Start")]
		[HarmonyPostfix]
		private static void EscapeSetup(EnemyAI __instance)
		{
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Expected O, but got Unknown
			//IL_0616: Unknown result type (might be due to invalid IL or missing references)
			//IL_0620: Expected O, but got Unknown
			//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Expected O, but got Unknown
			//IL_07de: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e8: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Expected O, but got Unknown
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Expected O, but got Unknown
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Expected O, but got Unknown
			if (StarlancerEnemyEscapeBase.EnemyBlacklist.ContainsKey(__instance.enemyType.enemyName))
			{
				return;
			}
			if (!StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary.ContainsKey(__instance.enemyType.enemyName))
			{
				if (StarlancerEnemyEscapeBase.VanillaEnemyList.ContainsKey(__instance.enemyType.enemyName))
				{
					StarlancerEnemyEscapeBase.logger.LogInfo((object)("Adding " + __instance.enemyType.enemyName + " to the StarlancerEnemyEscape config."));
					StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") ?? "", -1, new ConfigDescription("Chance for " + __instance.enemyType.enemyName + " to go into or out of the facility. Set to -1 to use the value from the chosen preset.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 100), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.logger.LogInfo((object)("Adding " + __instance.enemyType.enemyName + " to the StarlancerEnemyEscape config."));
					StarlancerEnemyEscapeBase.configEscapeExteriorRange[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Exterior Range", 200, new ConfigDescription("Range at which " + __instance.enemyType.enemyName + " can detect a teleport while outside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 9999), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.configEscapeInteriorRange[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Interior Range", 20, new ConfigDescription("Range at which " + __instance.enemyType.enemyName + " can detect a teleport while inside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.configEscapeCooldownTime[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Cooldown Time", 30, new ConfigDescription("Length of the cooldown between attempts at pathing to a nearby EntranceTeleport for " + __instance.enemyType.enemyName + ".", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
				}
				else
				{
					StarlancerEnemyEscapeBase.logger.LogInfo((object)("Adding " + __instance.enemyType.enemyName + " to the StarlancerEnemyEscape config."));
					StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") ?? "", -1, new ConfigDescription("Chance for " + __instance.enemyType.enemyName + " to go into or out of the facility. Set to -1 to use the value from the chosen preset.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 100), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.configEscapeExteriorRange[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Exterior Range", 200, new ConfigDescription("Range at which " + __instance.enemyType.enemyName + " can detect a teleport while outside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 9999), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.configEscapeInteriorRange[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Interior Range", 20, new ConfigDescription("Range at which " + __instance.enemyType.enemyName + " can detect a teleport while inside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
					StarlancerEnemyEscapeBase.configEscapeCooldownTime[__instance.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", __instance.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
						.Replace("\\", "")
						.Replace("\"", "")
						.Replace("'", "")
						.Replace("[", "")
						.Replace("]", "") + " Cooldown Time", 30, new ConfigDescription("Length of the cooldown between attempts at pathing to a nearby EntranceTeleport for " + __instance.enemyType.enemyName + ".", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
				}
			}
			if (AIFix.insideAINodes.Length != 0 && (Object)(object)((Component)__instance).gameObject.GetComponent<StarlancerEscapeComponent>() == (Object)null)
			{
				StarlancerEscapeComponent starlancerEscapeComponent = ((Component)__instance).gameObject.AddComponent<StarlancerEscapeComponent>();
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void BindRegisteredEnemies()
		{
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0515: Expected O, but got Unknown
			//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Expected O, but got Unknown
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Expected O, but got Unknown
			//IL_07ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c4: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Expected O, but got Unknown
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Expected O, but got Unknown
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Expected O, but got Unknown
			EnemyAI[] array = Resources.FindObjectsOfTypeAll<EnemyAI>();
			EnemyAI[] array2 = array;
			foreach (EnemyAI val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.enemyType == (Object)null) && val.enemyType.enemyName != null && !StarlancerEnemyEscapeBase.EnemyBlacklist.ContainsKey(val.enemyType.enemyName) && !StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary.ContainsKey(val.enemyType.enemyName))
				{
					if (StarlancerEnemyEscapeBase.VanillaEnemyList.ContainsKey(val.enemyType.enemyName))
					{
						StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") ?? "", -1, new ConfigDescription("Chance for " + val.enemyType.enemyName + " to go into or out of the facility. Set to -1 to use the value from the chosen preset.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 100), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeExteriorRange[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Exterior Range", 200, new ConfigDescription("Range at which " + val.enemyType.enemyName + " can detect a teleport while outside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 9999), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeInteriorRange[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Interior Range", 20, new ConfigDescription("Range at which " + val.enemyType.enemyName + " can detect a teleport while inside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeCooldownTime[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Vanilla Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Cooldown Time", 30, new ConfigDescription("Length of the cooldown between attempts at pathing to a nearby EntranceTeleport for " + val.enemyType.enemyName + ".", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
					}
					else
					{
						StarlancerEnemyEscapeBase.EnemyEscapeConfigDictionary[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") ?? "", -1, new ConfigDescription("Chance for " + val.enemyType.enemyName + " to go into or out of the facility. Set to -1 to use the value from the chosen preset.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 100), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeExteriorRange[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Exterior Range", 200, new ConfigDescription("Range at which " + val.enemyType.enemyName + " can detect a teleport while outside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 9999), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeInteriorRange[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Interior Range", 20, new ConfigDescription("Range at which " + val.enemyType.enemyName + " can detect a teleport while inside.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
						StarlancerEnemyEscapeBase.configEscapeCooldownTime[val.enemyType.enemyName] = StarlancerEnemyEscapeBase.EnemyEscapeConfig.Bind<int>("Mod Enemies", val.enemyType.enemyName.Replace("=", "").Replace("\n", "").Replace("\t", "")
							.Replace("\\", "")
							.Replace("\"", "")
							.Replace("'", "")
							.Replace("[", "")
							.Replace("]", "") + " Cooldown Time", 30, new ConfigDescription("Length of the cooldown between attempts at pathing to a nearby EntranceTeleport for " + val.enemyType.enemyName + ".", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 9999), Array.Empty<object>()));
					}
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "SetLevelObjectVariables")]
		[HarmonyPostfix]
		private static void EntranceTeleportsAndAINodes()
		{
			if (entranceTeleports != null && entranceTeleports.Length != 0 && !((Object)(object)entranceTeleports[0] == (Object)null))
			{
				return;
			}
			entranceTeleports = Object.FindObjectsOfType<EntranceTeleport>();
			outsideTeleports = (EntranceTeleport[])(object)new EntranceTeleport[entranceTeleports.Length / 2];
			insideTeleports = (EntranceTeleport[])(object)new EntranceTeleport[entranceTeleports.Length / 2];
			for (int i = 0; i < entranceTeleports.Length; i++)
			{
				int entranceId = entranceTeleports[i].entranceId;
				if (entranceTeleports[i].isEntranceToBuilding)
				{
					outsideTeleports[entranceId] = entranceTeleports[i];
					StarlancerEnemyEscapeBase.logger.LogInfo((object)"Finding exterior EntranceTeleports.");
				}
				else
				{
					insideTeleports[entranceId] = entranceTeleports[i];
					StarlancerEnemyEscapeBase.logger.LogInfo((object)"Finding interior EntranceTeleports.");
				}
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "SetDestinationToPosition")]
		[HarmonyPrefix]
		private static void SetDestinationToPositionPrefix(EnemyAI __instance, ref Vector3 position, ref bool checkForPath)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Invalid comparison between Unknown and I4
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Invalid comparison between Unknown and I4
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: 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_014c: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<StarlancerEscapeComponent>()))
			{
				return;
			}
			bool flag = false;
			NavMeshPath val = new NavMeshPath();
			float num = float.PositiveInfinity;
			if (__instance.isOutside)
			{
				Vector3[] outsideNodePositions = AIFix.outsideNodePositions;
				foreach (Vector3 val2 in outsideNodePositions)
				{
					if (Vector3.Distance(val2, position) < 10f)
					{
						flag = false;
						break;
					}
					flag = true;
				}
				if (flag)
				{
					EntranceTeleport[] array = outsideTeleports;
					foreach (EntranceTeleport val3 in array)
					{
						NavMesh.CalculatePath(((Component)__instance).transform.position, ((Component)val3.entrancePoint).transform.position, __instance.agent.areaMask, val);
						if ((int)val.status <= 0)
						{
							Vector3[] corners = val.corners;
							float num2 = 0f;
							for (int k = 1; k < corners.Length; k++)
							{
								num2 += Vector3.Distance(corners[k - 1], corners[k]);
							}
							if (num2 < num)
							{
								num = num2;
								checkForPath = false;
								position = ((Component)val3.entrancePoint).transform.position;
								__instance.destination = position;
							}
						}
					}
				}
			}
			if (__instance.isOutside)
			{
				return;
			}
			Vector3[] insideNodePositions = AIFix.insideNodePositions;
			foreach (Vector3 val4 in insideNodePositions)
			{
				if (Vector3.Distance(val4, position) < 10f)
				{
					flag = false;
					break;
				}
				flag = true;
			}
			if (!flag)
			{
				return;
			}
			EntranceTeleport[] array2 = insideTeleports;
			foreach (EntranceTeleport val5 in array2)
			{
				NavMesh.CalculatePath(((Component)__instance).transform.position, ((Component)val5.entrancePoint).transform.position, __instance.agent.areaMask, val);
				if ((int)val.status <= 0)
				{
					Vector3[] corners2 = val.corners;
					float num3 = 0f;
					for (int n = 1; n < corners2.Length; n++)
					{
						num3 += Vector3.Distance(corners2[n - 1], corners2[n]);
					}
					if (num3 < num)
					{
						num = num3;
						checkForPath = false;
						position = ((Component)val5.entrancePoint).transform.position;
						__instance.destination = position;
					}
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}