Decompiled source of StarlancerAIFix v3.8.4

StarlancerAI.dll

Decompiled 2 months 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StarlancerAIFix.Patches;
using Unity.Netcode;
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("StarlancerAI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+12f4ae1b05090c6c0566b8652090f6a4581f0bc0")]
[assembly: AssemblyProduct("StarlancerAI")]
[assembly: AssemblyTitle("StarlancerAI")]
[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 StarlancerAIFix
{
	[BepInPlugin("AudioKnight.StarlancerAIFix", "Starlancer AI Fix", "3.8.4")]
	public class StarlancerAIFixBase : BaseUnityPlugin
	{
		private const string modGUID = "AudioKnight.StarlancerAIFix";

		private const string modName = "Starlancer AI Fix";

		private const string modVersion = "3.8.4";

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

		public static StarlancerAIFixBase Instance;

		internal static ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"Starlancer AI Fix Online.");
			harmony.PatchAll(typeof(StarlancerAIFixBase));
			harmony.PatchAll(typeof(AIFix));
		}
	}
}
namespace StarlancerAIFix.Patches
{
	public class AIFix
	{
		internal class ThreatComponent : MonoBehaviour, IVisibleThreat
		{
			public EnemyAI thisEnemy;

			public Transform eye;

			public float visibility;

			public int threatLevel;

			public int interestLevel;

			public Transform enemyTransform;

			public NavMeshAgent agent;

			public Vector3 agentLocalVelocity;

			public ThreatType Generic;

			ThreatType IVisibleThreat.type => Generic;

			int IVisibleThreat.SendSpecialBehaviour(int id)
			{
				return 0;
			}

			int IVisibleThreat.GetThreatLevel(Vector3 seenByPosition)
			{
				return threatLevel;
			}

			int IVisibleThreat.GetInterestLevel()
			{
				return interestLevel;
			}

			Transform IVisibleThreat.GetThreatLookTransform()
			{
				return eye;
			}

			Transform IVisibleThreat.GetThreatTransform()
			{
				return enemyTransform;
			}

			Vector3 IVisibleThreat.GetThreatVelocity()
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				if (((NetworkBehaviour)thisEnemy).IsOwner)
				{
					return agent.velocity;
				}
				return Vector3.zero;
			}

			float IVisibleThreat.GetVisibility()
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				if (thisEnemy.isEnemyDead)
				{
					return 0f;
				}
				Vector3 velocity = agent.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude > 0f)
				{
					return 1f;
				}
				return visibility;
			}
		}

		public static GameObject[] outsideAINodes;

		public static GameObject[] insideAINodes;

		public static Vector3[] outsideNodePositions;

		public static Vector3[] insideNodePositions;

		public static string[] enemyWhitelist = new string[8] { "Blob", "Butler", "Centipede", "Crawler", "Flowerman", "HoarderBug", "Nutcracker", "SandSpider" };

		private static GameObject[] FindOutsideAINodes()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (outsideAINodes == null || outsideAINodes.Length == 0 || (Object)(object)outsideAINodes[0] == (Object)null)
			{
				outsideAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
				StarlancerAIFixBase.logger.LogInfo((object)"Finding outside AI nodes.");
				outsideNodePositions = (Vector3[])(object)new Vector3[outsideAINodes.Length];
				for (int i = 0; i < outsideAINodes.Length; i++)
				{
					outsideNodePositions[i] = outsideAINodes[i].transform.position;
				}
			}
			return outsideAINodes;
		}

		private static GameObject[] FindInsideAINodes()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (insideAINodes == null || insideAINodes.Length == 0 || (Object)(object)insideAINodes[0] == (Object)null)
			{
				insideAINodes = GameObject.FindGameObjectsWithTag("AINode");
				StarlancerAIFixBase.logger.LogInfo((object)"Finding inside AI nodes.");
				insideNodePositions = (Vector3[])(object)new Vector3[insideAINodes.Length];
				for (int i = 0; i < insideAINodes.Length; i++)
				{
					insideNodePositions[i] = insideAINodes[i].transform.position;
				}
			}
			return insideAINodes;
		}

		[HarmonyPatch(typeof(EnemyAI), "Start")]
		[HarmonyPostfix]
		private static void AIFixPatch(EnemyAI __instance)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00ce: 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_00d5: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			FindOutsideAINodes();
			FindInsideAINodes();
			__instance.removedPowerLevel = true;
			if (StartOfRound.Instance.currentLevelID == 3)
			{
				__instance.SetEnemyOutside(true);
				return;
			}
			Vector3 position = ((Component)__instance).transform.position;
			Vector3 val = Vector3.positiveInfinity;
			Vector3 val2 = Vector3.positiveInfinity;
			Vector3 val3;
			for (int i = 0; i < outsideNodePositions.Length; i++)
			{
				val3 = outsideNodePositions[i] - position;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				val3 = val - position;
				if (sqrMagnitude < ((Vector3)(ref val3)).sqrMagnitude)
				{
					val = outsideNodePositions[i];
				}
			}
			for (int j = 0; j < insideAINodes.Length; j++)
			{
				val3 = insideNodePositions[j] - position;
				float sqrMagnitude2 = ((Vector3)(ref val3)).sqrMagnitude;
				val3 = val2 - position;
				if (sqrMagnitude2 < ((Vector3)(ref val3)).sqrMagnitude)
				{
					val2 = insideNodePositions[j];
				}
			}
			if (!__instance.isOutside)
			{
				val3 = val - position;
				float sqrMagnitude3 = ((Vector3)(ref val3)).sqrMagnitude;
				val3 = val2 - position;
				if (sqrMagnitude3 < ((Vector3)(ref val3)).sqrMagnitude)
				{
					__instance.SetEnemyOutside(true);
					int num = Random.Range(0, __instance.allAINodes.Length - 1);
					__instance.favoriteSpot = __instance.allAINodes[num].transform;
					StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance).gameObject).name} spawned outside; Switching to exterior AI. Setting Favorite Spot to {__instance.favoriteSpot}.");
					return;
				}
			}
			if (__instance.isOutside)
			{
				val3 = val - position;
				float sqrMagnitude4 = ((Vector3)(ref val3)).sqrMagnitude;
				val3 = val2 - position;
				if (sqrMagnitude4 > ((Vector3)(ref val3)).sqrMagnitude)
				{
					__instance.SetEnemyOutside(false);
					int num2 = Random.Range(0, __instance.allAINodes.Length - 1);
					__instance.favoriteSpot = __instance.allAINodes[num2].transform;
					StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance).gameObject).name} spawned inside; Switching to interior AI. Setting Favorite Spot to {__instance.favoriteSpot}.");
				}
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "SubtractFromPowerLevel")]
		[HarmonyPostfix]
		private static void SubtractPowerLevelPatch(EnemyAI __instance)
		{
			EnemyAI __instance2 = __instance;
			if (RoundManager.Instance.currentLevel.OutsideEnemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType))
			{
				StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the exterior enemy list has died; \nPrevious exterior power level is {RoundManager.Instance.currentOutsideEnemyPower}");
				RoundManager.Instance.currentOutsideEnemyPower = Mathf.Max(RoundManager.Instance.currentOutsideEnemyPower - __instance2.enemyType.PowerLevel, 0f);
				StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent exterior power level is {RoundManager.Instance.currentOutsideEnemyPower}");
			}
			else if (RoundManager.Instance.currentLevel.Enemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType))
			{
				StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the interior enemy list has died; \nPrevious interior power level is {RoundManager.Instance.currentEnemyPower}");
				RoundManager.Instance.currentEnemyPower = Mathf.Max(RoundManager.Instance.currentEnemyPower - __instance2.enemyType.PowerLevel, 0f);
				RoundManager.Instance.cannotSpawnMoreInsideEnemies = false;
				StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent interior power level is {RoundManager.Instance.currentEnemyPower}");
			}
			else if (RoundManager.Instance.currentLevel.DaytimeEnemies.Any((SpawnableEnemyWithRarity enemy) => (Object)(object)enemy.enemyType == (Object)(object)__instance2.enemyType))
			{
				StarlancerAIFixBase.logger.LogInfo((object)$"{((Object)((Component)__instance2).gameObject).name} from the daytime enemy list has died; \nPrevious daytime power level is {RoundManager.Instance.currentDaytimeEnemyPower}");
				RoundManager.Instance.currentDaytimeEnemyPower = Mathf.Max(RoundManager.Instance.currentDaytimeEnemyPower - __instance2.enemyType.PowerLevel, 0f);
				StarlancerAIFixBase.logger.LogInfo((object)$"Removing {((Object)((Component)__instance2).gameObject).name}'s power ({__instance2.enemyType.PowerLevel}) from the RoundManager; \nCurrent daytime power level is {RoundManager.Instance.currentDaytimeEnemyPower}");
			}
		}

		[HarmonyPatch(typeof(JesterAI), "Update")]
		[HarmonyPostfix]
		private static void JesterAIPatch(JesterAI __instance, ref bool ___targetingPlayer, ref float ___noPlayersToChaseTimer, ref int ___previousState)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			switch (((EnemyAI)__instance).currentBehaviourStateIndex)
			{
			case 0:
				if (((EnemyAI)__instance).isOutside && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null && !__instance.roamMap.inProgress)
				{
					((EnemyAI)__instance).StartSearch(((Component)__instance).transform.position, __instance.roamMap);
					((EnemyAI)__instance).SwitchToBehaviourState(0);
				}
				break;
			case 2:
			{
				if ((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null && __instance.targetingPlayer && ((!((EnemyAI)__instance).isOutside && !((EnemyAI)__instance).targetPlayer.isInsideFactory) || (((EnemyAI)__instance).isOutside && ((EnemyAI)__instance).targetPlayer.isInsideFactory)))
				{
					((EnemyAI)__instance).targetPlayer = null;
				}
				if (!((EnemyAI)__instance).isOutside)
				{
					break;
				}
				if (___previousState != 2)
				{
					___previousState = 2;
					__instance.farAudio.Stop();
					((EnemyAI)__instance).creatureAnimator.SetBool("poppedOut", true);
					((EnemyAI)__instance).creatureAnimator.SetFloat("CrankSpeedMultiplier", 1f);
					((EnemyAI)__instance).creatureSFX.PlayOneShot(__instance.popUpSFX);
					WalkieTalkie.TransmitOneShotAudio(((EnemyAI)__instance).creatureSFX, __instance.popUpSFX, 1f);
					((EnemyAI)__instance).creatureVoice.clip = __instance.screamingSFX;
					((EnemyAI)__instance).creatureVoice.Play();
					((EnemyAI)__instance).agent.speed = 0f;
					__instance.mainCollider.isTrigger = true;
					((EnemyAI)__instance).agent.stoppingDistance = 0f;
				}
				___targetingPlayer = false;
				for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
				{
					if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && !StartOfRound.Instance.allPlayerScripts[i].isInsideFactory)
					{
						___targetingPlayer = true;
						break;
					}
				}
				if (!___targetingPlayer)
				{
					___noPlayersToChaseTimer -= Time.deltaTime;
					if (___noPlayersToChaseTimer <= 0f)
					{
						((EnemyAI)__instance).SwitchToBehaviourState(0);
					}
				}
				else
				{
					___noPlayersToChaseTimer = 5f;
				}
				break;
			}
			}
		}

		[HarmonyPatch(typeof(SandWormAI), "StartEmergeAnimation")]
		[HarmonyPostfix]
		private static void SandwormResetPatch(SandWormAI __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isOutside)
			{
				int num = Random.Range(0, ((EnemyAI)__instance).allAINodes.Length - 1);
				__instance.endOfFlightPathPosition = ((EnemyAI)__instance).allAINodes[num].transform.position;
			}
		}

		[HarmonyPatch(typeof(SandWormAI), "StartEmergeAnimation")]
		[HarmonyPostfix]
		private static void SandwormAttackPatch(SandWormAI __instance)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isOutside)
			{
				__instance.EmergeServerRpc((int)RoundManager.Instance.YRotationThatFacesTheFarthestFromPosition(((Component)__instance).transform.position + Vector3.up * 1.5f, 30f, 6));
			}
		}

		[HarmonyPatch(typeof(SpringManAI), "DoAIInterval")]
		[HarmonyPostfix]
		private static void SpringManAnimPatch(SpringManAI __instance)
		{
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 0 && ((EnemyAI)__instance).isOutside && __instance.searchForPlayers.inProgress && ((EnemyAI)__instance).agent.speed >= 1f)
			{
				((EnemyAI)__instance).creatureAnimator.SetFloat("walkSpeed", 1f);
			}
		}

		[HarmonyPatch(typeof(PufferAI), "Start")]
		[HarmonyPostfix]
		private static void PufferPrefabPatch(PufferAI __instance)
		{
			if (((EnemyAI)__instance).isOutside)
			{
				((EnemyAI)__instance).currentBehaviourStateIndex = 1;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")]
		[HarmonyPrefix]
		private static bool EnemyMeshPatch(EnemyAI __instance, bool enable, bool overrideDoNotSet = false)
		{
			int num = 0;
			int num2 = 0;
			int layer = ((!enable) ? 23 : 19);
			for (int i = 0; i < __instance.skinnedMeshRenderers.Length; i++)
			{
				if ((Object)(object)__instance.skinnedMeshRenderers[i] != (Object)null && (!((Component)__instance.skinnedMeshRenderers[i]).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)__instance.skinnedMeshRenderers[i]).gameObject.layer = layer;
				}
				else
				{
					if (!((Object)(object)__instance.skinnedMeshRenderers[i] == (Object)null))
					{
						continue;
					}
					List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(__instance.skinnedMeshRenderers);
					int num3 = 0;
					while (num3 < list.Count)
					{
						if ((Object)(object)list[num3] == (Object)null)
						{
							num++;
							list.RemoveAt(num3);
						}
						else
						{
							num3++;
						}
					}
					StarlancerAIFixBase.logger.LogWarning((object)$"Found and removed {num} null SkinnedMeshRenderers in {((Object)((Component)__instance).gameObject).name} ({__instance.thisEnemyIndex}) to prevent potential null reference exceptions.");
					__instance.skinnedMeshRenderers = list.ToArray();
				}
			}
			for (int j = 0; j < __instance.meshRenderers.Length; j++)
			{
				if ((Object)(object)__instance.meshRenderers[j] != (Object)null && (!((Component)__instance.meshRenderers[j]).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)__instance.meshRenderers[j]).gameObject.layer = layer;
				}
				else
				{
					if (!((Object)(object)__instance.meshRenderers[j] == (Object)null))
					{
						continue;
					}
					List<MeshRenderer> list2 = new List<MeshRenderer>(__instance.meshRenderers);
					int num4 = 0;
					while (num4 < list2.Count)
					{
						if ((Object)(object)list2[num4] == (Object)null)
						{
							num2++;
							list2.RemoveAt(num4);
						}
						else
						{
							num4++;
						}
					}
					StarlancerAIFixBase.logger.LogWarning((object)$"Found and removed {num2} null MeshRenderers in {((Object)((Component)__instance).gameObject).name} ({__instance.thisEnemyIndex}) to prevent potential null reference exceptions.");
					__instance.meshRenderers = list2.ToArray();
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
		[HarmonyPrefix]
		private static void PlayerIsTargetablePatch(ref bool overrideInsideFactoryCheck)
		{
			if (StartOfRound.Instance.currentLevelID == 3)
			{
				overrideInsideFactoryCheck = true;
			}
		}

		[HarmonyPatch(typeof(EnemyAI), "Start")]
		[HarmonyPostfix]
		private static void ThreatPatch(EnemyAI __instance)
		{
			if (Array.IndexOf(enemyWhitelist, ((Object)__instance.enemyType).name) != -1)
			{
				StarlancerAIFixBase.logger.LogInfo((object)("The Enemy Whitelist contains: " + string.Join(", ", enemyWhitelist) + "."));
				IVisibleThreat componentInChildren = ((Component)__instance).GetComponentInChildren<IVisibleThreat>();
				if (componentInChildren == null && componentInChildren == null)
				{
					StarlancerAIFixBase.logger.LogInfo((object)("Adding IVisibleThreat component to " + ((Object)((Component)__instance).gameObject).name + "."));
					ThreatComponent threatComponent = ((Component)__instance).gameObject.AddComponent<ThreatComponent>();
					threatComponent.thisEnemy = __instance;
					threatComponent.eye = __instance.eye;
					threatComponent.visibility = 0.5f;
					threatComponent.threatLevel = 3;
					threatComponent.interestLevel = 0;
					threatComponent.enemyTransform = ((Component)__instance).transform;
					threatComponent.agent = __instance.agent;
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}