Decompiled source of FairAI v1.4.1

FairAI.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using FairAI.Component;
using FairAI.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalThings;
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: AssemblyTitle("FairAI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FairAI")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("42deea12-f73e-4d63-81e9-5359e98c8d53")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace FairAI
{
	internal class FAIR_AI : NetworkBehaviour
	{
		public EnemyAI targetWithRotation;

		public Dictionary<int, GameObject> targets;

		private void Awake()
		{
			targetWithRotation = null;
		}

		[ClientRpc]
		public void SwitchedTargetedEnemyClientRpc(Turret turret, EnemyAI enemy, bool setModeToCharging = false)
		{
			targetWithRotation = enemy;
			if (setModeToCharging)
			{
				Type typeFromHandle = typeof(Turret);
				MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic);
				method.Invoke(turret, new object[1] { 1 });
			}
		}

		[ClientRpc]
		public void RemoveTargetedEnemyClientRpc()
		{
			targetWithRotation = null;
		}
	}
	[BepInPlugin("GoldenKitten.FairAI", "Fair AI", "1.3.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "GoldenKitten.FairAI";

		private const string modName = "Fair AI";

		private const string modVersion = "1.3.8";

		private Harmony harmony = new Harmony("GoldenKitten.FairAI");

		public static Plugin Instance;

		public static ManualLogSource logger;

		public static List<EnemyType> enemies;

		public static List<Item> items;

		public static Assembly surfacedAssembly;

		public const string ltModID = "evaisa.lethalthings";

		public const string surfacedModID = "Surfaced";

		public static bool playersEnteredInside = false;

		public static bool surfacedEnabled = false;

		public static bool lethalThingsEnabled = false;

		public static int wallsAndEnemyLayerMask = 524288;

		public static int enemyMask = 524288;

		public static int allHittablesMask;

		private static float onMeshThreshold = 3f;

		private async void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			surfacedAssembly = null;
			harmony = new Harmony("GoldenKitten.FairAI");
			logger = Logger.CreateLogSource("GoldenKitten.FairAI");
			harmony.PatchAll(typeof(Plugin));
			CreateHarmonyPatch(harmony, typeof(RoundManager), "Start", null, typeof(RoundManagerPatch), "PatchStart", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(StartOfRound), "Start", null, typeof(StartOfRoundPatch), "PatchStart", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(StartOfRound), "Update", null, typeof(StartOfRoundPatch), "PatchUpdate", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(Turret), "Update", null, typeof(TurretAIPatch), "PatchUpdate", isPrefix: true);
			CreateHarmonyPatch(harmony, typeof(Turret), "CheckForPlayersInLineOfSight", new Type[2]
			{
				typeof(float),
				typeof(bool)
			}, typeof(TurretAIPatch), "CheckForTargetsInLOS", isPrefix: true);
			CreateHarmonyPatch(harmony, typeof(Turret), "SetTargetToPlayerBody", null, typeof(TurretAIPatch), "SetTargetToEnemyBody", isPrefix: true);
			CreateHarmonyPatch(harmony, typeof(Turret), "TurnTowardsTargetIfHasLOS", null, typeof(TurretAIPatch), "TurnTowardsTargetEnemyIfHasLOS", isPrefix: true);
			CreateHarmonyPatch(harmony, typeof(Landmine), "SpawnExplosion", new Type[8]
			{
				typeof(Vector3),
				typeof(bool),
				typeof(float),
				typeof(float),
				typeof(int),
				typeof(float),
				typeof(GameObject),
				typeof(bool)
			}, typeof(MineAIPatch), "PatchSpawnExplosion", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(Landmine), "OnTriggerEnter", null, typeof(MineAIPatch), "PatchOnTriggerEnter", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(Landmine), "OnTriggerExit", null, typeof(MineAIPatch), "PatchOnTriggerExit", isPrefix: false);
			CreateHarmonyPatch(harmony, typeof(Landmine), "Detonate", null, typeof(MineAIPatch), "DetonatePatch", isPrefix: false);
			await WaitForProcess(1);
			logger.LogInfo((object)"Fair AI initiated!");
		}

		public static async Task<IEnumerable<int>> WaitForProcess(int waitTime)
		{
			await Task.Delay(waitTime);
			bool done = false;
			while (!done)
			{
				await Instance.DelayedInitialization();
				done = true;
			}
			return new List<int>();
		}

		private async Task DelayedInitialization()
		{
			await Task.Run(delegate
			{
				TryLoadLethalThings();
				TryLoadSurfaced();
				logger.LogInfo((object)"Optional Components initiated!");
			});
		}

		private void TryLoadLethalThings()
		{
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				Assembly assembly = null;
				Assembly[] array = assemblies;
				foreach (Assembly assembly2 in array)
				{
					if (assembly2.GetName().Name == "LethalThings")
					{
						assembly = assembly2;
						break;
					}
				}
				if (assembly != null)
				{
					Type type = assembly.GetType("LethalThings.RoombaAI");
					if (type != null && BoombaPatch.enabled)
					{
						CreateHarmonyPatch(harmony, type, "Start", null, typeof(BoombaPatch), "PatchStart", isPrefix: false);
						CreateHarmonyPatch(harmony, type, "DoAIInterval", null, typeof(BoombaPatch), "PatchDoAIInterval", isPrefix: false);
						lethalThingsEnabled = true;
						logger.LogInfo((object)"LethalThings Component Initiated!");
					}
				}
				else
				{
					logger.LogWarning((object)"LethalThings assembly not found. Skipping optional patch.");
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)("An error occurred while trying to apply patches for LethalThings: " + ex.Message));
			}
		}

		private void TryLoadSurfaced()
		{
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				Assembly[] array = assemblies;
				foreach (Assembly assembly in array)
				{
					if (assembly.GetName().Name == "Surfaced")
					{
						surfacedAssembly = assembly;
						break;
					}
				}
				if (surfacedAssembly != null)
				{
					Type type = surfacedAssembly.GetType("Seamine");
					if (type != null)
					{
						if (SurfacedMinePatch.enabled)
						{
							CreateHarmonyPatch(harmony, type, "OnTriggerEnter", new Type[1] { typeof(Collider) }, typeof(SurfacedMinePatch), "PatchOnTriggerEnter", isPrefix: false);
							surfacedEnabled = true;
							logger.LogInfo((object)"Surfaced Component Initiated!");
						}
					}
					else
					{
						logger.LogInfo((object)"Surfaced Component Not Found!");
					}
				}
				else
				{
					logger.LogWarning((object)"Surfaced assembly not found. Skipping optional patch.");
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)("An error occurred while trying to apply patches for Surfaced: " + ex.Message));
			}
		}

		public static List<PlayerControllerB> GetActivePlayers()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] array = allPlayerScripts;
			foreach (PlayerControllerB val in array)
			{
				if ((Object)val != (Object)null && !val.isPlayerDead && ((Behaviour)val).isActiveAndEnabled && val.isPlayerControlled)
				{
					list.Add(val);
				}
			}
			return list;
		}

		public static bool AllowFairness(Vector3 position)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance != (Object)null && Can("CheckForPlayersInside"))
			{
				if (IsAPlayersOutside())
				{
					if (!(position.y > -80f))
					{
						Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
						if (!((Bounds)(ref bounds)).Contains(position))
						{
							goto IL_005c;
						}
					}
					return true;
				}
				goto IL_005c;
			}
			return true;
			IL_005c:
			return playersEnteredInside;
		}

		public static bool IsAPlayersOutside()
		{
			List<PlayerControllerB> activePlayers = GetActivePlayers();
			for (int i = 0; i < activePlayers.Count; i++)
			{
				PlayerControllerB val = activePlayers[i];
				if (!val.isInsideFactory)
				{
					return true;
				}
			}
			return false;
		}

		public static bool IsAPlayerInsideShip()
		{
			List<PlayerControllerB> activePlayers = GetActivePlayers();
			for (int i = 0; i < activePlayers.Count; i++)
			{
				PlayerControllerB val = activePlayers[i];
				if (val.isInHangarShipRoom)
				{
					return true;
				}
			}
			return false;
		}

		public static bool IsAPlayerInsideDungeon()
		{
			List<PlayerControllerB> activePlayers = GetActivePlayers();
			for (int i = 0; i < activePlayers.Count; i++)
			{
				PlayerControllerB val = activePlayers[i];
				if (val.isInsideFactory)
				{
					return true;
				}
			}
			return false;
		}

		public static bool CanMob(string parentIdentifier, string identifier, string mobName)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			string text = RemoveInvalidCharacters(mobName).ToUpper();
			if (((BaseUnityPlugin)Instance).Config[new ConfigDefinition("Mobs", parentIdentifier)].BoxedValue.ToString().ToUpper().Equals("TRUE"))
			{
				foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys)
				{
					if (RemoveInvalidCharacters(key.Key.ToUpper()).Equals(RemoveInvalidCharacters(text + identifier).ToUpper()))
					{
						return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Equals("TRUE");
					}
				}
				return false;
			}
			return false;
		}

		public static bool Can(string identifier)
		{
			foreach (ConfigDefinition key in ((BaseUnityPlugin)Instance).Config.Keys)
			{
				if (RemoveInvalidCharacters(key.Key.ToUpper()).Equals(RemoveInvalidCharacters(identifier.ToUpper())))
				{
					return ((BaseUnityPlugin)Instance).Config[key].BoxedValue.ToString().ToUpper().Equals("TRUE");
				}
			}
			return false;
		}

		public static string RemoveWhitespaces(string source)
		{
			return string.Join("", source.Split((string[]?)null, StringSplitOptions.RemoveEmptyEntries));
		}

		public static string RemoveSpecialCharacters(string source)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in source)
			{
				if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		public static string RemoveInvalidCharacters(string source)
		{
			return RemoveWhitespaces(RemoveSpecialCharacters(source));
		}

		public static Type FindType(string fullName)
		{
			try
			{
				if ((from a in AppDomain.CurrentDomain.GetAssemblies()
					where !a.IsDynamic
					select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName)) != null)
				{
					return (from a in AppDomain.CurrentDomain.GetAssemblies()
						where !a.IsDynamic
						select a).SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName.Equals(fullName));
				}
			}
			catch
			{
				return null;
			}
			return null;
		}

		public static void CreateHarmonyPatch(Harmony harmony, Type typeToPatch, string methodToPatch, Type[] parameters, Type patchType, string patchMethod, bool isPrefix, bool isTranspiler = false)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			if (typeToPatch == null || patchType == null)
			{
				logger.LogInfo((object)"Type is either incorrect or does not exist!");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(typeToPatch, methodToPatch, parameters, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(patchType, patchMethod, (Type[])null, (Type[])null);
			if (isTranspiler)
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else if (isPrefix)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static bool IsAgentOnNavMesh(GameObject agentObject)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = agentObject.transform.position;
			NavMeshHit val = default(NavMeshHit);
			if (NavMesh.SamplePosition(position, ref val, onMeshThreshold, -1) && Mathf.Approximately(position.x, ((NavMeshHit)(ref val)).position.x) && Mathf.Approximately(position.z, ((NavMeshHit)(ref val)).position.z))
			{
				return position.y >= ((NavMeshHit)(ref val)).position.y;
			}
			return false;
		}

		public static bool AttackTargets(Vector3 aimPoint, Vector3 forward, float range)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return HitTargets(GetTargets(aimPoint, forward, range), forward);
		}

		public static List<GameObject> GetTargets(Vector3 aimPoint, Vector3 forward, float range)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0153: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			List<GameObject> list = new List<GameObject>();
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(aimPoint, forward);
			RaycastHit[] array = Physics.RaycastAll(val, range, -5, (QueryTriggerInteraction)2);
			Array.Sort(array, (RaycastHit x, RaycastHit y) => ((RaycastHit)(ref x)).distance.CompareTo(((RaycastHit)(ref y)).distance));
			Vector3 val2 = aimPoint + forward * range;
			IHittable val3 = default(IHittable);
			EnemyAI val6 = default(EnemyAI);
			for (int i = 0; i < array.Length; i++)
			{
				GameObject gameObject = ((Component)((RaycastHit)(ref array[i])).transform).gameObject;
				Transform transform = ((RaycastHit)(ref array[i])).transform;
				if (((Component)transform).TryGetComponent<IHittable>(ref val3))
				{
					EnemyAI val4 = null;
					EnemyAICollisionDetect val5 = (EnemyAICollisionDetect)(object)((val3 is EnemyAICollisionDetect) ? val3 : null);
					if (val5 != null)
					{
						val4 = val5.mainScript;
					}
					if ((Object)(object)val4 != (Object)null && !val4.isEnemyDead && val4.enemyHP > 0)
					{
						list.Add(((Component)transform).gameObject);
					}
					val2 = ((RaycastHit)(ref array[i])).point;
				}
				else
				{
					if (((Component)transform).TryGetComponent<EnemyAI>(ref val6) && !val6.isEnemyDead && val6.enemyHP > 0)
					{
						list.Add(((Component)val6).gameObject);
						val2 = ((RaycastHit)(ref array[i])).point;
					}
					val2 = ((RaycastHit)(ref array[i])).point;
				}
			}
			return list;
		}

		public static List<EnemyAICollisionDetect> GetEnemyTargets(List<GameObject> originalTargets)
		{
			List<EnemyAICollisionDetect> hits = new List<EnemyAICollisionDetect>();
			originalTargets.ForEach(delegate(GameObject t)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				if ((Object)(object)t != (Object)null && t.GetComponent<IHittable>() != null)
				{
					IHittable component = t.GetComponent<IHittable>();
					if (component is EnemyAICollisionDetect)
					{
						EnemyAICollisionDetect item = (EnemyAICollisionDetect)component;
						hits.Add(item);
					}
				}
			});
			return hits;
		}

		public static bool HitTargets(List<GameObject> targets, Vector3 forward)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			bool hits = false;
			if (!targets.Any())
			{
				return hits;
			}
			targets.ForEach(delegate(GameObject t)
			{
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Expected O, but got Unknown
				//IL_0098: 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_005f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_017e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: 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_015c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)t != (Object)null)
				{
					if ((Object)(object)t.GetComponent<EnemyAI>() != (Object)null)
					{
						EnemyAI component = t.GetComponent<EnemyAI>();
						int num = 1;
						if (CanMob("TurretDamageAllMobs", ".Turret Damage", component.enemyType.enemyName))
						{
							if (component is NutcrackerEnemyAI)
							{
								if (((EnemyAI)(NutcrackerEnemyAI)component).currentBehaviourStateIndex > 0)
								{
									component.HitEnemyOnLocalClient(num, default(Vector3), (PlayerControllerB)null, false, -1);
									hits = true;
								}
							}
							else
							{
								component.HitEnemyOnLocalClient(num, default(Vector3), (PlayerControllerB)null, false, -1);
								hits = true;
							}
						}
					}
					else if (t.GetComponent<IHittable>() != null)
					{
						IHittable component2 = t.GetComponent<IHittable>();
						if (component2 is EnemyAICollisionDetect)
						{
							EnemyAICollisionDetect val = (EnemyAICollisionDetect)component2;
							int num2 = 1;
							if (CanMob("TurretDamageAllMobs", ".Turret Damage", val.mainScript.enemyType.enemyName))
							{
								if (val.mainScript is NutcrackerEnemyAI)
								{
									if (((EnemyAI)(NutcrackerEnemyAI)val.mainScript).currentBehaviourStateIndex > 0)
									{
										val.mainScript.HitEnemyOnLocalClient(num2, default(Vector3), (PlayerControllerB)null, false, -1);
										hits = true;
									}
								}
								else
								{
									val.mainScript.HitEnemyOnLocalClient(num2, default(Vector3), (PlayerControllerB)null, false, -1);
									hits = true;
								}
							}
						}
						else if (!(component2 is PlayerControllerB))
						{
							component2.Hit(1, forward, (PlayerControllerB)null, true, -1);
							hits = true;
						}
					}
				}
			});
			return hits;
		}
	}
}
namespace FairAI.Patches
{
	public static class BoombaPatch
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("evaisa.lethalthings");
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PatchStart(ref RoombaAI __instance)
		{
			((Component)__instance).gameObject.AddComponent<BoombaTimer>();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PatchDoAIInterval(ref RoombaAI __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.AllowFairness(((Component)__instance).transform.position) || !Plugin.IsAgentOnNavMesh(((Component)__instance).gameObject) || (((EnemyAI)__instance).currentSearch == null && !((EnemyAI)__instance).movingTowardsTargetPlayer) || (!__instance.mineAudio.isPlaying && !__instance.mineFarAudio.isPlaying) || !((Component)__instance).GetComponent<BoombaTimer>().IsActiveBomb())
			{
				return;
			}
			Vector3 val = ((Component)__instance).transform.position + Vector3.up;
			Collider[] array = Physics.OverlapSphere(val, 6f, 2621448, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				float num = Vector3.Distance(val, ((Component)array[i]).transform.position);
				if ((num > 4f && Physics.Linecast(val, ((Component)array[i]).transform.position + Vector3.up * 0.3f, 256, (QueryTriggerInteraction)1)) || !((Object)(object)((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>() != (Object)null))
				{
					continue;
				}
				EnemyAICollisionDetect component = ((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>();
				if (!((Object)(object)((Component)component.mainScript).gameObject != (Object)(object)((Component)__instance).gameObject) || !Plugin.CanMob("BoombaAllMobs", ".Boomba", component.mainScript.enemyType.enemyName))
				{
					continue;
				}
				if ((Object)(object)component != (Object)null && ((NetworkBehaviour)component.mainScript).IsOwner && !component.mainScript.isEnemyDead)
				{
					Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab, val, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
					if (num < 3f)
					{
						component.mainScript.KillEnemyOnOwnerClient(true);
					}
					else if (num < 6f)
					{
						component.mainScript.HitEnemyOnLocalClient(2, default(Vector3), (PlayerControllerB)null, false, -1);
					}
				}
				if (((NetworkBehaviour)__instance).IsServer)
				{
					((EnemyAI)__instance).KillEnemy(true);
				}
				else
				{
					((EnemyAI)__instance).KillEnemyServerRpc(true);
				}
			}
		}
	}
	internal class EnemyAIPatch
	{
	}
	internal class MineAIPatch
	{
		public static void PatchOnTriggerEnter(ref Landmine __instance, Collider other, ref float ___pressMineDebounceTimer)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.AllowFairness(((Component)__instance).transform.position))
			{
				EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper()))
				{
					___pressMineDebounceTimer = 0.5f;
					__instance.PressMineServerRpc();
				}
			}
		}

		public static void PatchOnTriggerExit(ref Landmine __instance, Collider other, ref bool ___sendingExplosionRPC)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.AllowFairness(((Component)__instance).transform.position))
			{
				EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper()) && !__instance.hasExploded)
				{
					__instance.SetOffMineAnimation();
					___sendingExplosionRPC = true;
					__instance.ExplodeMineServerRpc();
				}
			}
		}

		public static void DetonatePatch(ref Landmine __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				((MonoBehaviour)__instance).StartCoroutine(WaitForUpdate(1.5f, __instance));
			}
		}

		public static IEnumerator WaitForUpdate(float waitTime, Landmine mine)
		{
			yield return (object)new WaitForSeconds(waitTime);
			if (!((Object)(object)mine == (Object)null))
			{
				if ((Object)(object)((Component)mine).GetComponent<NetworkObject>() != (Object)null)
				{
					((Component)mine).GetComponent<NetworkObject>().Despawn(true);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)mine).gameObject);
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PatchSpawnExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f, int nonLethalDamage = 50, float physicsForce = 0f, GameObject overridePrefab = null, bool goThroughCar = false)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			bool flag = true;
			Collider[] array = Physics.OverlapSphere(explosionPosition, 6f, 2621448, (QueryTriggerInteraction)2);
			for (int i = 0; i < array.Length; i++)
			{
				float num = Vector3.Distance(explosionPosition, ((Component)array[i]).transform.position);
				if (num > 4f && Physics.Linecast(explosionPosition, ((Component)array[i]).transform.position + Vector3.up * 0.3f, 256, (QueryTriggerInteraction)1))
				{
					continue;
				}
				if (Plugin.surfacedEnabled && Plugin.surfacedAssembly != null)
				{
					Type type = Plugin.surfacedAssembly.GetType("Seamine");
					if (type != null && (Object)(object)((Component)array[i]).gameObject.GetComponent(type) != (Object)null)
					{
						Component component = ((Component)array[i]).gameObject.GetComponent(type);
						FieldInfo field = type.GetField("mineActivated", BindingFlags.Instance | BindingFlags.NonPublic);
						FieldInfo field2 = type.GetField("hasExploded", BindingFlags.Instance | BindingFlags.Public);
						if (!(bool)field2.GetValue(component) || !(bool)field.GetValue(component))
						{
							break;
						}
						if (Plugin.AllowFairness(component.transform.position))
						{
							MethodInfo method = type.GetMethod("TriggerMineOnLocalClientByExiting", BindingFlags.Instance | BindingFlags.NonPublic);
							method.Invoke(component, new object[0]);
						}
					}
				}
				if (!((Object)(object)((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>() != (Object)null))
				{
					continue;
				}
				EnemyAICollisionDetect component2 = ((Component)array[i]).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component2 != (Object)null && ((NetworkBehaviour)component2.mainScript).IsOwner && !component2.mainScript.isEnemyDead)
				{
					if (num < killRange)
					{
						component2.mainScript.HitEnemyOnLocalClient(component2.mainScript.enemyHP, default(Vector3), (PlayerControllerB)null, false, -1);
					}
					else if (num < damageRange)
					{
						component2.mainScript.HitEnemyOnLocalClient(Mathf.RoundToInt((float)(component2.mainScript.enemyHP / 2)), default(Vector3), (PlayerControllerB)null, false, -1);
					}
				}
			}
		}
	}
	internal class RoundManagerPatch
	{
		public static void PatchStart(ref RoundManager __instance)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			Plugin.enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType))
				where (Object)(object)e != (Object)null
				select e).ToList();
			Plugin.items = (from Item i in Resources.FindObjectsOfTypeAll(typeof(Item))
				where (Object)(object)i != (Object)null
				select i).ToList();
			Plugin.allHittablesMask = StartOfRound.Instance.collidersRoomMaskDefaultAndPlayers | 0x280008 | Plugin.enemyMask;
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "ExplodeAllMobs")))
			{
				ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "ExplodeAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Set Off Mines.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "BoombaAllMobs")))
			{
				ConfigEntry<bool> val2 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "BoombaAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Set Off Boombas.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "TurretTargetAllMobs")))
			{
				ConfigEntry<bool> val3 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "TurretTargetAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Be Targeted By Turrets.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "TurretDamageAllMobs")))
			{
				ConfigEntry<bool> val4 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "TurretDamageAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Be Killed By Turrets.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "CheckForPlayersInside")))
			{
				ConfigEntry<bool> val5 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "CheckForPlayersInside", false, "Whether to check for players inside the dungeon before anything else occurs.");
			}
			foreach (EnemyType enemy in Plugin.enemies)
			{
				string text = Plugin.RemoveInvalidCharacters(enemy.enemyName);
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Mine")))
				{
					ConfigEntry<bool> val6 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Mine", true, "Does it set off the landmine or not?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Boomba")))
				{
					ConfigEntry<bool> val7 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Boomba", true, "Does it set off the boomba or not?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Turret Target")))
				{
					ConfigEntry<bool> val8 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Turret Target", true, "Is it targetable by turrets?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Turret Damage")))
				{
					ConfigEntry<bool> val9 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Turret Damage", true, "Is it damageable by turrets?");
				}
			}
		}
	}
	internal class StartOfRoundPatch
	{
		public static void PatchStart(ref StartOfRound __instance)
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Expected O, but got Unknown
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			Plugin.enemies = (from EnemyType e in Resources.FindObjectsOfTypeAll(typeof(EnemyType))
				where (Object)(object)e != (Object)null
				select e).ToList();
			Plugin.items = (from Item i in Resources.FindObjectsOfTypeAll(typeof(Item))
				where (Object)(object)i != (Object)null
				select i).ToList();
			Plugin.allHittablesMask = StartOfRound.Instance.collidersRoomMaskDefaultAndPlayers | 0x280008 | Plugin.enemyMask;
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "ExplodeAllMobs")))
			{
				ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "ExplodeAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Set Off Mines.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "BoombaAllMobs")))
			{
				ConfigEntry<bool> val2 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "BoombaAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Set Off Boombas.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "TurretTargetAllMobs")))
			{
				ConfigEntry<bool> val3 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "TurretTargetAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Be Targeted By Turrets.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "TurretDamageAllMobs")))
			{
				ConfigEntry<bool> val4 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "TurretDamageAllMobs", true, "Leave On To Customise Mobs Below Or Turn Off To Make All Mobs Unable To Be Killed By Turrets.");
			}
			if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", "CheckForPlayersInside")))
			{
				ConfigEntry<bool> val5 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", "CheckForPlayersInside", false, "Whether to check for players inside the dungeon before anything else occurs.");
			}
			foreach (EnemyType enemy in Plugin.enemies)
			{
				string text = Plugin.RemoveInvalidCharacters(enemy.enemyName);
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Mine")))
				{
					ConfigEntry<bool> val6 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Mine", true, "Does it set off the landmine or not?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Boomba")))
				{
					ConfigEntry<bool> val7 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Boomba", true, "Does it set off the boomba or not?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Turret Target")))
				{
					ConfigEntry<bool> val8 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Turret Target", true, "Is it targetable by turrets?");
				}
				if (!((BaseUnityPlugin)Plugin.Instance).Config.ContainsKey(new ConfigDefinition("Mobs", text + ".Turret Damage")))
				{
					ConfigEntry<bool> val9 = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Mobs", text + ".Turret Damage", true, "Is it damageable by turrets?");
				}
			}
		}

		public static void PatchUpdate(ref StartOfRound __instance)
		{
			if (Plugin.Can("CheckForPlayersInside"))
			{
				if (__instance.shipIsLeaving)
				{
					Plugin.playersEnteredInside = false;
				}
				else
				{
					Plugin.playersEnteredInside = Plugin.IsAPlayerInsideDungeon();
				}
			}
		}
	}
	public static class SurfacedMinePatch
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("Surfaced");
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PatchBerthaOnTriggerEnter(ref Bertha __instance, Collider other)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(Bertha);
			if (!__instance.hasExploded && Plugin.AllowFairness(((Component)__instance).transform.position))
			{
				EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper()))
				{
					MethodInfo method = typeFromHandle.GetMethod("TriggerMineOnLocalClientByExiting", BindingFlags.Instance | BindingFlags.NonPublic);
					method.Invoke(__instance, new object[1] { -1 });
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void PatchOnTriggerEnter(ref Seamine __instance, Collider other)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(Seamine);
			FieldInfo field = typeFromHandle.GetField("mineActivated", BindingFlags.Instance | BindingFlags.NonPublic);
			if (!__instance.hasExploded && (bool)field.GetValue(__instance) && Plugin.AllowFairness(((Component)__instance).transform.position))
			{
				EnemyAICollisionDetect component = ((Component)other).gameObject.GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null && !component.mainScript.isEnemyDead && Plugin.CanMob("ExplodeAllMobs", ".Mine", component.mainScript.enemyType.enemyName.ToUpper()))
				{
					MethodInfo method = typeFromHandle.GetMethod("TriggerMineOnLocalClientByExiting", BindingFlags.Instance | BindingFlags.NonPublic);
					method.Invoke(__instance, new object[0]);
				}
			}
		}
	}
	internal class TurretAIPatch
	{
		public static float viewRadius = 16f;

		public static float viewAngle = 90f;

		public static bool PatchUpdate(ref Turret __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: 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_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected I4, but got Unknown
			//IL_0195: 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_012b: Invalid comparison between Unknown and I4
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null) && Plugin.AllowFairness(((Component)__instance).transform.position))
			{
				FAIR_AI fAIR_AI = ((Component)__instance).gameObject.GetComponent<FAIR_AI>() ?? ((Component)__instance).gameObject.AddComponent<FAIR_AI>();
				Type typeFromHandle = typeof(Turret);
				FieldInfo field = typeFromHandle.GetField("wasTargetingPlayerLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field2 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field3 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic);
				MethodInfo method = typeFromHandle.GetMethod("SetTargetToPlayerBody", BindingFlags.Instance | BindingFlags.NonPublic);
				MethodInfo method2 = typeFromHandle.GetMethod("TurnTowardsTargetIfHasLOS", BindingFlags.Instance | BindingFlags.NonPublic);
				if (!__instance.turretActive)
				{
					field.SetValue(__instance, false);
					__instance.turretMode = (TurretMode)0;
					__instance.targetPlayerWithRotation = null;
					fAIR_AI.targetWithRotation = null;
					return false;
				}
				if ((Object)(object)fAIR_AI.targetWithRotation != (Object)null || (Object)(object)__instance.targetPlayerWithRotation != (Object)null)
				{
					if (!(bool)field.GetValue(__instance))
					{
						field.SetValue(__instance, true);
						if ((int)__instance.turretMode == 0)
						{
							if ((Object)(object)fAIR_AI.targetWithRotation != (Object)null)
							{
								__instance.turretMode = (TurretMode)2;
							}
							else
							{
								__instance.turretMode = (TurretMode)1;
							}
						}
					}
					SetTargetToEnemyBody(ref __instance);
					TurnTowardsTargetEnemyIfHasLOS(ref __instance);
				}
				else if ((bool)field.GetValue(__instance))
				{
					field.SetValue(__instance, false);
					__instance.turretMode = (TurretMode)0;
				}
				TurretMode turretMode = __instance.turretMode;
				TurretMode val = turretMode;
				switch ((int)val)
				{
				case 0:
					DetectionFunction(__instance, fAIR_AI);
					break;
				case 1:
					ChargingFunction(__instance, fAIR_AI);
					break;
				case 2:
					FiringFunction(__instance);
					break;
				case 3:
					BerserkFunction(__instance);
					break;
				}
				if ((bool)field2.GetValue(__instance))
				{
					__instance.turnTowardsObjectCompass.localEulerAngles = new Vector3(-180f, __instance.turretRod.localEulerAngles.y - Time.deltaTime * 20f, 180f);
					__instance.turretRod.rotation = Quaternion.RotateTowards(__instance.turretRod.rotation, __instance.turnTowardsObjectCompass.rotation, __instance.rotationSpeed * Time.deltaTime);
					return false;
				}
				if ((bool)field3.GetValue(__instance))
				{
					__instance.turnTowardsObjectCompass.localEulerAngles = new Vector3(-180f, Mathf.Clamp(__instance.targetRotation, 0f - __instance.rotationRange, __instance.rotationRange), 180f);
				}
				__instance.turretRod.rotation = Quaternion.RotateTowards(__instance.turretRod.rotation, __instance.turnTowardsObjectCompass.rotation, __instance.rotationSpeed * Time.deltaTime);
				return false;
			}
			return false;
		}

		public static void DetectionFunction(Turret turret, FAIR_AI turret_ai)
		{
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(Turret);
			FieldInfo field = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field4 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field5 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field6 = typeFromHandle.GetField("switchRotationTimer", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field7 = typeFromHandle.GetField("rotatingRight", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method2 = typeFromHandle.GetMethod("FadeBulletAudio", BindingFlags.Instance | BindingFlags.NonPublic);
			if ((int)field.GetValue(turret) != 0)
			{
				field.SetValue(turret, (object)(TurretMode)0);
				field2.SetValue(turret, false);
				turret.mainAudio.Stop();
				turret.farAudio.Stop();
				turret.berserkAudio.Stop();
				if (field3.GetValue(turret) != null)
				{
					((MonoBehaviour)turret).StopCoroutine((Coroutine)field3.GetValue(turret));
				}
				field3.SetValue(turret, ((MonoBehaviour)turret).StartCoroutine((IEnumerator)method2.Invoke(turret, new object[0])));
				turret.bulletParticles.Stop(true, (ParticleSystemStopBehavior)1);
				turret.rotationSpeed = 28f;
				field4.SetValue(turret, true);
				turret.turretAnimator.SetInteger("TurretMode", 0);
				field5.SetValue(turret, Random.Range(0f, 0.15f));
			}
			if (!((NetworkBehaviour)turret).IsServer)
			{
				return;
			}
			if ((float)field6.GetValue(turret) >= 7f)
			{
				field6.SetValue(turret, 0f);
				bool flag = !(bool)field7.GetValue(turret);
				turret.SwitchRotationClientRpc(flag);
				turret.SwitchRotationOnInterval(flag);
			}
			else
			{
				field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime);
			}
			if ((float)field5.GetValue(turret) >= 0.25f)
			{
				field5.SetValue(turret, 0f);
				EnemyAICollisionDetect val = CheckForEnemiesInLineOfSight(turret, 15f);
				if ((Object)(object)val != (Object)null && !val.mainScript.isEnemyDead && Plugin.CanMob("TurretTargetAllMobs", ".Turret Target", val.mainScript.enemyType.enemyName))
				{
					turret_ai.targetWithRotation = val.mainScript;
					turret.turretMode = (TurretMode)2;
					turret.SetToModeClientRpc(2);
					method.Invoke(turret, new object[1] { (object)(TurretMode)2 });
					turret_ai.SwitchedTargetedEnemyClientRpc(turret, val.mainScript);
					Plugin.logger.LogInfo((object)"Detected Enemy!");
					return;
				}
				field5.SetValue(turret, 0f);
				PlayerControllerB val2 = CheckForPlayersInLOS(turret, 1.35f, angleRangeCheck: true);
				if ((Object)(object)val2 != (Object)null && !val2.isPlayerDead)
				{
					turret.targetPlayerWithRotation = val2;
					method.Invoke(turret, new object[1] { 1 });
					turret.SwitchTargetedPlayerClientRpc((int)val2.playerClientId, true);
					Plugin.logger.LogInfo((object)"Detected Player!");
				}
			}
			else
			{
				field5.SetValue(turret, (float)field5.GetValue(turret) + Time.deltaTime);
			}
		}

		public static void ChargingFunction(Turret turret, FAIR_AI turret_ai)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			Type typeFromHandle = typeof(Turret);
			FieldInfo field = typeFromHandle.GetField("hasLineOfSight", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field4 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field5 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field6 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic);
			if ((int)(TurretMode)field2.GetValue(turret) != 1)
			{
				field2.SetValue(turret, (object)(TurretMode)1);
				field3.SetValue(turret, false);
				turret.mainAudio.PlayOneShot(turret.detectPlayerSFX);
				turret.berserkAudio.Stop();
				WalkieTalkie.TransmitOneShotAudio(turret.mainAudio, turret.detectPlayerSFX, 1f);
				turret.rotationSpeed = 95f;
				field4.SetValue(turret, false);
				field6.SetValue(turret, 0f);
				turret.turretAnimator.SetInteger("TurretMode", 1);
			}
			if (!((NetworkBehaviour)turret).IsServer)
			{
				return;
			}
			if ((float)field5.GetValue(turret) >= 1.5f)
			{
				field5.SetValue(turret, 0f);
				Plugin.logger.LogInfo((object)"Charging timer is up, setting to firing mode");
				if (!(bool)field.GetValue(turret))
				{
					Plugin.logger.LogInfo((object)"hasLineOfSight is false");
					turret.targetPlayerWithRotation = null;
					turret.RemoveTargetedPlayerClientRpc();
					turret_ai.targetWithRotation = null;
					turret_ai.RemoveTargetedEnemyClientRpc();
				}
				else
				{
					method.Invoke(turret, new object[1] { 2 });
					turret.SetToModeClientRpc(2);
				}
			}
			else
			{
				field5.SetValue(turret, (float)field5.GetValue(turret) + Time.deltaTime);
			}
		}

		public static void FiringFunction(Turret turret)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: 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_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			Type typeFromHandle = typeof(Turret);
			FieldInfo field = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field4 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field5 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field6 = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field7 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic);
			if ((int)(TurretMode)field.GetValue(turret) != 2)
			{
				field.SetValue(turret, (object)(TurretMode)2);
				turret.berserkAudio.Stop();
				RoundManager.Instance.PlayAudibleNoise(((Component)turret.berserkAudio).transform.position, 15f, 0.9f, 0, false, 0);
				turret.mainAudio.clip = turret.firingSFX;
				turret.mainAudio.Play();
				turret.farAudio.clip = turret.firingFarSFX;
				turret.farAudio.Play();
				turret.bulletParticles.Play(true);
				turret.bulletCollisionAudio.Play();
				if (field2 != null && field2.GetValue(turret) != null)
				{
					((MonoBehaviour)turret).StopCoroutine((Coroutine)field2.GetValue(turret));
				}
				turret.bulletCollisionAudio.volume = 1f;
				field3.SetValue(turret, false);
				field5.SetValue(turret, 0f);
				turret.turretAnimator.SetInteger("TurretMode", 2);
			}
			if ((float)field4.GetValue(turret) >= 0.21f)
			{
				Plugin.logger.LogInfo((object)"Attacking Target");
				field4.SetValue(turret, 0f);
				if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					if (GameNetworkManager.Instance.localPlayerController.health > 50)
					{
						GameNetworkManager.Instance.localPlayerController.DamagePlayer(50, true, true, (CauseOfDeath)7, 0, false, default(Vector3));
					}
					else
					{
						GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3));
					}
				}
				field6.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward));
				RaycastHit val = default(RaycastHit);
				if (Physics.Raycast((Ray)field6.GetValue(turret), ref val, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
				{
					field7.SetValue(turret, val);
					Transform transform = ((Component)turret.bulletCollisionAudio).transform;
					Ray val2 = (Ray)field6.GetValue(turret);
					RaycastHit val3 = (RaycastHit)field7.GetValue(turret);
					Ray val4 = val2;
					transform.position = ((Ray)(ref val4)).GetPoint(((RaycastHit)(ref val3)).distance - 0.5f);
				}
				Vector3 forward = turret.aimPoint.forward;
				forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward;
				Plugin.AttackTargets(turret.aimPoint.position, forward, 30f);
			}
			else
			{
				field4.SetValue(turret, (float)field4.GetValue(turret) + Time.deltaTime);
			}
		}

		public static void BerserkFunction(Turret turret)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Invalid comparison between Unknown and I4
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Expected O, but got Unknown
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			Type typeFromHandle = typeof(Turret);
			FieldInfo field = typeFromHandle.GetField("wasTargetingPlayerLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("turretModeLastFrame", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeFromHandle.GetField("rotatingClockwise", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field4 = typeFromHandle.GetField("fadeBulletAudioCoroutine", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field5 = typeFromHandle.GetField("rotatingSmoothly", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field6 = typeFromHandle.GetField("turretInterval", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field7 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field8 = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field9 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field10 = typeFromHandle.GetField("berserkTimer", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field11 = typeFromHandle.GetField("enteringBerserkMode", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method = typeFromHandle.GetMethod("SwitchTurretMode", BindingFlags.Instance | BindingFlags.NonPublic);
			if ((int)(TurretMode)field2.GetValue(turret) != 3)
			{
				field2.SetValue(turret, (object)(TurretMode)3);
				turret.turretAnimator.SetInteger("TurretMode", 1);
				field10.SetValue(turret, 1.3f);
				turret.berserkAudio.Play();
				turret.rotationSpeed = 77f;
				field11.SetValue(turret, true);
				field5.SetValue(turret, true);
				field7.SetValue(turret, 0f);
				field.SetValue(turret, false);
				turret.targetPlayerWithRotation = null;
			}
			if ((bool)field11.GetValue(turret))
			{
				field10.SetValue(turret, (float)field10.GetValue(turret) - Time.deltaTime);
				if ((float)field10.GetValue(turret) <= 0f)
				{
					field11.SetValue(turret, false);
					field3.SetValue(turret, true);
					field10.SetValue(turret, 9f);
					turret.turretAnimator.SetInteger("TurretMode", 2);
					turret.mainAudio.clip = turret.firingSFX;
					turret.mainAudio.Play();
					turret.farAudio.clip = turret.firingFarSFX;
					turret.farAudio.Play();
					turret.bulletParticles.Play(true);
					turret.bulletCollisionAudio.Play();
					if (field4 != null)
					{
						((MonoBehaviour)turret).StopCoroutine((Coroutine)field4.GetValue(turret));
					}
					turret.bulletCollisionAudio.volume = 1f;
				}
				return;
			}
			if ((float)field6.GetValue(turret) >= 0.21f)
			{
				field6.SetValue(turret, 0f);
				if ((Object)(object)CheckForPlayersInLOS(turret, 3f) == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					if (GameNetworkManager.Instance.localPlayerController.health > 50)
					{
						GameNetworkManager.Instance.localPlayerController.DamagePlayer(50, true, true, (CauseOfDeath)7, 0, false, default(Vector3));
					}
					else
					{
						GameNetworkManager.Instance.localPlayerController.KillPlayer(turret.aimPoint.forward * 40f, true, (CauseOfDeath)7, 0, default(Vector3));
					}
				}
				field8.SetValue(turret, (object)new Ray(turret.aimPoint.position, turret.aimPoint.forward));
				RaycastHit val = default(RaycastHit);
				if (Physics.Raycast((Ray)field8.GetValue(turret), ref val, 30f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
				{
					field9.SetValue(turret, val);
					Transform transform = ((Component)turret.bulletCollisionAudio).transform;
					Ray val2 = (Ray)field8.GetValue(turret);
					RaycastHit val3 = (RaycastHit)field9.GetValue(turret);
					transform.position = ((Ray)(ref val2)).GetPoint(((RaycastHit)(ref val3)).distance - 0.5f);
				}
				Vector3 forward = turret.aimPoint.forward;
				forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward;
				Plugin.AttackTargets(turret.centerPoint.position, forward, 30f);
			}
			else
			{
				field6.SetValue(turret, (float)field6.GetValue(turret) + Time.deltaTime);
			}
			if (((NetworkBehaviour)turret).IsServer)
			{
				field10.SetValue(turret, (float)field10.GetValue(turret) - Time.deltaTime);
				if ((float)field10.GetValue(turret) <= 0f)
				{
					method.Invoke(turret, new object[1] { 0 });
					turret.SetToModeClientRpc(0);
				}
			}
		}

		public static bool CheckForTargetsInLOS(ref Turret __instance, float radius = 2f, bool angleRangeCheck = false)
		{
			FAIR_AI component = ((Component)__instance).gameObject.GetComponent<FAIR_AI>();
			PlayerControllerB val = CheckForPlayersInLOS(__instance, radius, angleRangeCheck);
			EnemyAICollisionDetect val2 = CheckForEnemiesInLineOfSight(__instance, radius, angleRangeCheck);
			if ((Object)(object)val != (Object)null)
			{
				component.targets = new Dictionary<int, GameObject> { 
				{
					0,
					((Component)val).gameObject
				} };
				return true;
			}
			if ((Object)(object)val2 != (Object)null)
			{
				component.targets = new Dictionary<int, GameObject> { 
				{
					1,
					((Component)val2).gameObject
				} };
				return true;
			}
			return false;
		}

		public static PlayerControllerB CheckForPlayersInLOS(Turret turret, float radius = 2f, bool angleRangeCheck = false)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Invalid comparison between Unknown and I4
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_0229: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = turret.aimPoint.forward;
			val = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / radius, 0f) * val;
			float num = turret.rotationRange / radius * 2f;
			Type typeFromHandle = typeof(Turret);
			FieldInfo field = typeFromHandle.GetField("shootRay", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeFromHandle.GetField("hit", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field3 = typeFromHandle.GetField("enteringBerserkMode", BindingFlags.Instance | BindingFlags.NonPublic);
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i <= 6; i++)
			{
				field.SetValue(turret, (object)new Ray(turret.centerPoint.position, val));
				RaycastHit val3;
				if (Physics.Raycast((Ray)field.GetValue(turret), ref val2, 30f, 1051400, (QueryTriggerInteraction)1))
				{
					field2.SetValue(turret, val2);
					val3 = (RaycastHit)field2.GetValue(turret);
					if (((Component)((RaycastHit)(ref val3)).transform).CompareTag("Player"))
					{
						val3 = (RaycastHit)field2.GetValue(turret);
						PlayerControllerB component = ((Component)((RaycastHit)(ref val3)).transform).GetComponent<PlayerControllerB>();
						if (!((Object)(object)component == (Object)null))
						{
							if (angleRangeCheck && Vector3.Angle(((Component)component).transform.position + Vector3.up * 1.75f - turret.centerPoint.position, turret.forwardFacingPos.forward) > turret.rotationRange)
							{
								return null;
							}
							return component;
						}
						continue;
					}
					if ((int)turret.turretMode == 2)
					{
						goto IL_01ee;
					}
					if ((int)turret.turretMode == 3 && !(bool)field3.GetValue(turret))
					{
						val3 = (RaycastHit)field2.GetValue(turret);
						if (((Component)((RaycastHit)(ref val3)).transform).tag.StartsWith("PlayerRagdoll"))
						{
							goto IL_01ee;
						}
					}
				}
				goto IL_0238;
				IL_01ee:
				val3 = (RaycastHit)field2.GetValue(turret);
				Rigidbody component2 = ((Component)((RaycastHit)(ref val3)).transform).GetComponent<Rigidbody>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.AddForce(((Vector3)(ref val)).normalized * 42f, (ForceMode)1);
				}
				goto IL_0238;
				IL_0238:
				val = Quaternion.Euler(0f, num / 6f, 0f) * val;
			}
			return null;
		}

		public static EnemyAICollisionDetect CheckForEnemiesInLineOfSight(Turret turret, float radius = 2f, bool angleRangeCheck = false)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Vector3 forward = turret.aimPoint.forward;
			forward = Quaternion.Euler(0f, (float)(int)(0f - turret.rotationRange) / 3f, 0f) * forward;
			List<EnemyAICollisionDetect> enemyTargets = Plugin.GetEnemyTargets(Plugin.GetTargets(turret.aimPoint.position, forward, radius));
			if (enemyTargets == null || !enemyTargets.Any())
			{
				return null;
			}
			return enemyTargets[0];
		}

		public static bool SetTargetToEnemyBody(ref Turret __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				Type typeFromHandle = typeof(Turret);
				FieldInfo field = typeFromHandle.GetField("targetingDeadPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
				FAIR_AI component = ((Component)__instance).gameObject.GetComponent<FAIR_AI>();
				if ((Object)(object)component.targetWithRotation != (Object)null)
				{
					if (!((Object)(object)((Component)component.targetWithRotation).GetComponent<EnemyAICollisionDetect>() != (Object)null))
					{
						if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null)
						{
							if (__instance.targetPlayerWithRotation.isPlayerDead)
							{
								if (!(bool)field.GetValue(__instance))
								{
									field.SetValue(__instance, true);
								}
								if ((Object)(object)__instance.targetPlayerWithRotation.deadBody != (Object)null)
								{
									__instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.deadBody.bodyParts[5]).transform;
								}
							}
							else
							{
								field.SetValue(__instance, false);
								__instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.gameplayCamera).transform;
							}
						}
						return false;
					}
					EnemyAICollisionDetect component2 = ((Component)component.targetWithRotation).GetComponent<EnemyAICollisionDetect>();
					if (component2.mainScript.isEnemyDead)
					{
						if (!(bool)field.GetValue(__instance))
						{
							field.SetValue(__instance, true);
						}
					}
					else if ((Object)(object)__instance.targetPlayerWithRotation == (Object)null)
					{
						field.SetValue(__instance, false);
						__instance.targetTransform = ((Component)component.targetWithRotation).transform;
					}
				}
				else if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null)
				{
					if (__instance.targetPlayerWithRotation.isPlayerDead)
					{
						if (!(bool)field.GetValue(__instance))
						{
							field.SetValue(__instance, true);
						}
						if ((Object)(object)__instance.targetPlayerWithRotation.deadBody != (Object)null)
						{
							__instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.deadBody.bodyParts[5]).transform;
						}
					}
					else
					{
						field.SetValue(__instance, false);
						__instance.targetTransform = ((Component)__instance.targetPlayerWithRotation.gameplayCamera).transform;
					}
				}
			}
			return false;
		}

		public static bool TurnTowardsTargetEnemyIfHasLOS(ref Turret __instance)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				FAIR_AI component = ((Component)__instance).GetComponent<FAIR_AI>();
				Type typeFromHandle = typeof(Turret);
				FieldInfo field = typeFromHandle.GetField("targetingDeadPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field2 = typeFromHandle.GetField("hasLineOfSight", BindingFlags.Instance | BindingFlags.NonPublic);
				FieldInfo field3 = typeFromHandle.GetField("lostLOSTimer", BindingFlags.Instance | BindingFlags.NonPublic);
				bool flag = true;
				if ((Object)(object)__instance.targetTransform != (Object)null && (Object)(object)__instance.centerPoint != (Object)null && (Object)(object)__instance.forwardFacingPos != (Object)null)
				{
					Vector3 val = __instance.targetTransform.position - __instance.centerPoint.position;
					float num = Vector3.Angle(val, __instance.forwardFacingPos.forward);
					if (num > __instance.rotationRange)
					{
						flag = false;
					}
				}
				EnemyAICollisionDetect val2 = CheckForEnemiesInLineOfSight(__instance, 15f);
				if ((Object)(object)val2 == (Object)null)
				{
					flag = false;
				}
				if (flag)
				{
					__instance.targetTransform = ((Component)val2.mainScript).transform;
					field2.SetValue(__instance, true);
					field3.SetValue(__instance, 0f);
					__instance.tempTransform.position = __instance.targetTransform.position;
					Transform tempTransform = __instance.tempTransform;
					tempTransform.position -= Vector3.up * 0.15f;
					__instance.turnTowardsObjectCompass.LookAt(__instance.tempTransform);
					return false;
				}
				bool flag2 = true;
				if ((bool)field.GetValue(__instance) || Vector3.Angle(__instance.targetTransform.position - __instance.centerPoint.position, __instance.forwardFacingPos.forward) > __instance.rotationRange)
				{
					flag2 = false;
				}
				if (Physics.Linecast(__instance.aimPoint.position, __instance.targetTransform.position, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
				{
					flag2 = false;
				}
				if (flag2)
				{
					field2.SetValue(__instance, true);
					field3.SetValue(__instance, 0f);
					__instance.tempTransform.position = __instance.targetTransform.position;
					Transform tempTransform2 = __instance.tempTransform;
					tempTransform2.position -= Vector3.up * 0.15f;
					__instance.turnTowardsObjectCompass.LookAt(__instance.tempTransform);
					return false;
				}
				if ((bool)field2.GetValue(__instance))
				{
					field2.SetValue(__instance, false);
					field3.SetValue(__instance, 0f);
				}
				if (!((NetworkBehaviour)__instance).IsServer)
				{
					return false;
				}
				field3.SetValue(__instance, (float)field3.GetValue(__instance) + Time.deltaTime);
				if ((float)field3.GetValue(__instance) >= 2f)
				{
					field3.SetValue(__instance, 0f);
					Plugin.logger.LogInfo((object)"Turret: LOS timer ended on server. checking for new player target");
					PlayerControllerB val3 = CheckForPlayersInLOS(__instance);
					if ((Object)(object)val3 != (Object)null)
					{
						__instance.targetPlayerWithRotation = val3;
						__instance.SwitchTargetedPlayerClientRpc((int)val3.playerClientId, false);
						Plugin.logger.LogInfo((object)"Turret: Got new player target");
					}
					else
					{
						Plugin.logger.LogInfo((object)"Turret: No new player to target; returning to detection mode.");
						__instance.targetPlayerWithRotation = null;
						__instance.RemoveTargetedPlayerClientRpc();
					}
				}
				if ((Object)(object)__instance.targetPlayerWithRotation != (Object)null)
				{
					return false;
				}
				if ((bool)field2.GetValue(__instance))
				{
					field2.SetValue(__instance, false);
					field3.SetValue(__instance, 0f);
				}
				if (!((NetworkBehaviour)__instance).IsServer)
				{
					return false;
				}
				field3.SetValue(__instance, (float)field3.GetValue(__instance) + Time.deltaTime);
				if ((float)field3.GetValue(__instance) >= 2f)
				{
					field3.SetValue(__instance, 0f);
					Plugin.logger.LogInfo((object)"Turret: LOS timer ended on server. checking for new enemy target");
					EnemyAICollisionDetect val4 = CheckForEnemiesInLineOfSight(__instance, 15f);
					if ((Object)(object)val4 != (Object)null)
					{
						component.targetWithRotation = val4.mainScript;
						component.SwitchedTargetedEnemyClientRpc(__instance, val4.mainScript);
						Plugin.logger.LogInfo((object)"Turret: Got new enemy target");
					}
					else
					{
						Plugin.logger.LogInfo((object)"Turret: No new enemy to target; returning to detection mode.");
						component.targetWithRotation = null;
						component.RemoveTargetedEnemyClientRpc();
					}
				}
			}
			return false;
		}
	}
}
namespace FairAI.Component
{
	internal class BoombaTimer : MonoBehaviour
	{
		private bool isActiveBomb = false;

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(StartBombTimer());
			Plugin.logger.LogInfo((object)"Boomba has been set active.");
		}

		public IEnumerator StartBombTimer()
		{
			SetActiveBomb(isActive: false);
			yield return (object)new WaitForSeconds(3f);
			SetActiveBomb(isActive: true);
		}

		public void SetActiveBomb(bool isActive)
		{
			isActiveBomb = isActive;
		}

		public bool IsActiveBomb()
		{
			return isActiveBomb;
		}
	}
}