Decompiled source of Hide And Seek Nightly v10.13.24

HideAndSeek.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Debugger;
using GameNetcodeStuff;
using HarmonyLib;
using HideAndSeek;
using HideAndSeek.AbilityScripts;
using HideAndSeek.AbilityScripts.Extra;
using HideAndSeek.AudioScripts;
using HideAndSeek.Patches;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HideAndSeek")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9600259795c574d47c48152b705049febe1026c6")]
[assembly: AssemblyProduct("HideAndSeek")]
[assembly: AssemblyTitle("HideAndSeek")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Debugger
{
	public static class Debug
	{
		private static bool warned = false;

		private static readonly string WARNmESSAGE = "DebugEnabled is false! (Make sure to turn this on when trying to read Debug.Log()'s messages)";

		public static void Log(object m)
		{
			if (Config.debugEnabled.Value)
			{
				Plugin._Logger.LogInfo(m);
			}
			else if (!warned)
			{
				warned = true;
				Plugin._Logger.LogWarning((object)WARNmESSAGE);
			}
		}

		public static void LogMessage(object m)
		{
			if (Config.debugEnabled.Value)
			{
				Plugin._Logger.LogMessage(m);
			}
			else if (!warned)
			{
				warned = true;
				Plugin._Logger.LogWarning((object)WARNmESSAGE);
			}
		}

		public static void LogWarning(object m)
		{
			if (Config.debugEnabled.Value)
			{
				Plugin._Logger.LogWarning(m);
			}
			else if (!warned)
			{
				warned = true;
				Plugin._Logger.LogWarning((object)WARNmESSAGE);
			}
		}

		public static void LogError(object m)
		{
			if (Config.debugEnabled.Value)
			{
				Plugin._Logger.LogError(m);
			}
			else if (!warned)
			{
				warned = true;
				Plugin._Logger.LogWarning((object)WARNmESSAGE);
			}
		}
	}
}
namespace HideAndSeek
{
	public class AbilityConfig
	{
		public bool syncedWithHost = false;

		public string abilityName = "genericNull";

		public int abilityCost = 10;

		public bool seekerAbility = true;

		public bool hiderAbility = true;

		public bool requiresRoundActive = true;

		public bool requiresSeekerActive = true;

		public float abilityDelay = 10f;

		public bool oneTimeUse = false;

		public AbilityConfig(string _abilityName = "genericNull", int _abilityCost = 10, float _abilityDelay = 10f, bool _oneTimeUse = false, bool _seekerAbility = true, bool _hiderAbility = true, bool _requriesRoundActive = true, bool _requiresSeekerActive = true)
		{
			abilityName = _abilityName;
			abilityCost = _abilityCost;
			seekerAbility = _seekerAbility;
			hiderAbility = _hiderAbility;
			requiresRoundActive = _requriesRoundActive;
			requiresSeekerActive = _requiresSeekerActive;
			abilityDelay = _abilityDelay;
			oneTimeUse = _oneTimeUse;
		}
	}
	public class Config
	{
		public static ConfigEntry<bool> debugEnabled;

		public static ConfigEntry<bool> abilitiesEnabled;

		public static ConfigEntry<bool> creditsResetOnNewRound;

		public static ConfigEntry<string> sellKeyBind;

		public static ConfigEntry<string> abilityMenuKeyBind;

		public static ConfigEntry<int> deadBodySellValue;

		public static ConfigEntry<bool> disableAllDaytimeEntities;

		public static ConfigEntry<bool> circuitBeeEnabled;

		public static ConfigEntry<bool> manticoilEnabled;

		public static ConfigEntry<bool> roamingLocustEnabled;

		public static ConfigEntry<bool> disableAllOutsideEntities;

		public static ConfigEntry<bool> baboonHawkEnabled;

		public static ConfigEntry<bool> earthLeviathanEnabled;

		public static ConfigEntry<bool> eyelessDogEnabled;

		public static ConfigEntry<bool> forestKeeperEnabled;

		public static ConfigEntry<bool> tulipSnakeEnabled;

		public static ConfigEntry<bool> mechEnabled;

		public static ConfigEntry<bool> kidnapperFoxEnabled;

		public static ConfigEntry<bool> disableAllIndoorEntities;

		public static ConfigEntry<bool> brackenEnabled;

		public static ConfigEntry<bool> bunkerSpiderEnabled;

		public static ConfigEntry<bool> coilHeadEnabled;

		public static ConfigEntry<bool> ghostGirlEnabled;

		public static ConfigEntry<bool> hoardingBugEnabled;

		public static ConfigEntry<bool> hygrodereEnabled;

		public static ConfigEntry<bool> jesterEnabled;

		public static ConfigEntry<bool> maskedEnabled;

		public static ConfigEntry<bool> nutcrackerEnabled;

		public static ConfigEntry<bool> snareFleaEnabled;

		public static ConfigEntry<bool> sporeLizardEnabled;

		public static ConfigEntry<bool> thumperEnabled;

		public static ConfigEntry<bool> butlerEnabled;

		public static ConfigEntry<bool> barberEnabled;

		public static ConfigEntry<bool> turretsEnabled;

		public static ConfigEntry<bool> landminesEnabled;

		public static ConfigEntry<bool> spikeTrapEnabled;

		public static ConfigEntry<bool> maneaterEnabled;

		public static ConfigEntry<Color> seekerNameColor;

		public static ConfigEntry<string> seekerChooseBehavior;

		public static ConfigEntry<string> numberOfSeekers;

		public static ConfigEntry<string> extraSeekerChooseBehavior;

		public static ConfigEntry<bool> isSeekerImmune;

		public static ConfigEntry<bool> hostilesIgnoreSeeker;

		public static ConfigEntry<bool> shotgunInfiniteAmmo;

		public static ConfigEntry<bool> shotgunAutoReload;

		public static ConfigEntry<bool> teleportSeekerToEntrance;

		public static ConfigEntry<bool> forceSeekerInside;

		public static ConfigEntry<bool> shipLeaveEarly;

		public static ConfigEntry<float> timeWhenLastHider;

		public static ConfigEntry<float> timeSeekerIsReleased;

		public static ConfigEntry<string> seekerItemSlot1;

		public static ConfigEntry<string> seekerItemSlot2;

		public static ConfigEntry<string> seekerItemSlot3;

		public static ConfigEntry<string> seekerItemSlot4;

		public static ConfigEntry<Color> hiderNameColor;

		public static ConfigEntry<bool> teleportHidersToEntrance;

		public static ConfigEntry<bool> forceHidersInside;

		public static ConfigEntry<bool> lockHidersInside;

		public static ConfigEntry<bool> infiniteFlashlightBattery;

		public static ConfigEntry<string> hiderItemSlot1;

		public static ConfigEntry<string> hiderItemSlot2;

		public static ConfigEntry<string> hiderItemSlot3;

		public static ConfigEntry<string> hiderItemSlot4;

		public static ConfigEntry<Color> zombieNameColor;

		public static ConfigEntry<bool> deadHidersRespawn;

		public static ConfigEntry<bool> deadZombiesRespawn;

		public static ConfigEntry<bool> zombiesCanUseAbilities;

		public static ConfigEntry<float> zombieSpawnDelay;

		public static ConfigEntry<string> zombieSpawnLocation;

		public static ConfigEntry<string> zombieItemSlot1;

		public static ConfigEntry<string> zombieItemSlot2;

		public static ConfigEntry<string> zombieItemSlot3;

		public static ConfigEntry<string> zombieItemSlot4;

		public Config(ConfigFile cfg)
		{
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0614: Unknown result type (might be due to invalid IL or missing references)
			//IL_072a: Unknown result type (might be due to invalid IL or missing references)
			debugEnabled = cfg.Bind<bool>("0:Debug/Other", "DebugEnabled", false, "Used for random feature testing and debug logging. (Should be disabled for end user)");
			abilitiesEnabled = cfg.Bind<bool>("0:Gamemode.Abilities", "Abilities Enabled", true, "Enables Abilities! Hold 'c' to sell scrap and press 't' to open the abilities menu to spend your credits on.");
			creditsResetOnNewRound = cfg.Bind<bool>("0:Gamemode.Abilities", "Credits Reset On New Round", false, "Makes everyone's credits go back to 0 when a new round starts");
			abilityMenuKeyBind = cfg.Bind<string>("0:Gamemode.Abilities", "Ability Menu keybind", "<Keyboard>/t", "Press this to open a menu with a wide range of fun abilities!");
			sellKeyBind = cfg.Bind<string>("0:Gamemode.Abilities", "Sell keybind", "<Keyboard>/c", "Hold this for 3 seconds, and you got your self some cash!");
			deadBodySellValue = cfg.Bind<int>("0:Gamemode.Abilities", "Dead Body Value", 100, "How much a dead body is worth when selling");
			disableAllDaytimeEntities = cfg.Bind<bool>("1:Entities.Daytime", "Disable All Daytime Entities", false, "Determines if daytime spawning should be disabled. (Usefull for modded maps with unique enemies)");
			circuitBeeEnabled = cfg.Bind<bool>("1:Entities.Daytime", "Spawn Circut Bees", false, "Determines if Circuit Bees should spawn.");
			manticoilEnabled = cfg.Bind<bool>("1:Entities.Daytime", "Spawn Manticoils", true, "Determines if Manticoils should spawn.");
			roamingLocustEnabled = cfg.Bind<bool>("1:Entities.Daytime", "Spawn Roaming Locusts", true, "Determines if Roaming Locusts should spawn.");
			disableAllOutsideEntities = cfg.Bind<bool>("1:Entities.Outside", "Disable All Outside Entities", false, "Determines if outside spawning should be disabled. (Usefull for modded maps with unique enemies)");
			eyelessDogEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Eyeless Dogs", false, "Determines if Eyeless Dogs should spawn.");
			forestKeeperEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Forest Keepers", false, "Determines if Forest Keepers should spawn.");
			earthLeviathanEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Earth Leviathans", false, "Determines if Earth Leviathans should spawn.");
			baboonHawkEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Baboon Hawks", false, "Determines if Baboon Hawks should spawn.");
			tulipSnakeEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Tulip Snakes", false, "Determines if Tulip Snakes should spawn.");
			mechEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Old Bird", false, "Determines if Old Birds should spawn.");
			kidnapperFoxEnabled = cfg.Bind<bool>("1:Entities.Outside", "Spawn Foxes", false, "Determines if Foxes should spawn.");
			disableAllIndoorEntities = cfg.Bind<bool>("1:Entities.Indoor", "Disable All Indoor Entities", false, "Determines if indoor spawning should be disabled. (Usefull for modded maps with unique enemies)");
			brackenEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Brackens", false, "Determines if Brackens should spawn.");
			bunkerSpiderEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Bunker Spiders", false, "Determines if Bunker Spiders should spawn.");
			coilHeadEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Coil Heads", false, "Determines if Coil Heads should spawn.");
			ghostGirlEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Ghost Girls", false, "Determines if Ghost Girls should spawn.");
			hoardingBugEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Hoarding Bugs", false, "Determines if Hoarding Bugs should spawn.");
			hygrodereEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Hygroderes (Slimes)", false, "Determines if Hygroderes (Slimes) should spawn.");
			jesterEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Jesters", false, "Determines if Jesters should spawn.");
			maskedEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Masked (Player Mimics)", false, "Determines if Masked (Player Mimics) should spawn.");
			nutcrackerEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Nutcrackers", false, "Determines if Nutcrackers should spawn.");
			snareFleaEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Snare Fleas", false, "Determines if Snare Fleas should spawn.");
			sporeLizardEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Spore Lizards", false, "Determines if Spore Lizards should spawn.");
			thumperEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Thumpers", false, "Determines if Thumpers should spawn.");
			butlerEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Butlers", false, "Determines if Butlers should spawn.");
			barberEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Barbers", false, "Determines if Barbers should spawn.");
			maneaterEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Maneaters", false, "Determines if Maneaters should spawn.");
			turretsEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Turrets", false, "Determines if Turrets should spawn.");
			landminesEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Land Mines", false, "Determines if Land Mines should spawn.");
			spikeTrapEnabled = cfg.Bind<bool>("1:Entities.Indoor", "Spawn Spike Traps", false, "Determines if Spike Traps should spawn.");
			seekerNameColor = cfg.Bind<Color>("2:Players.Seeker", "Seeker Name Color", new Color(1f, 0f, 0f), "The color the player's name tag will be.");
			seekerChooseBehavior = cfg.Bind<string>("2:Players.Seeker", "Seeker Choose Behavior", "Turns", "'None' (Just a random range generator), 'No Double' (Next Seeker can't be last seeker), 'Turns' (Will not pick someone that was already seeker, resets when everyone got a chance), 'Lever' (The seeker is the lever puller)");
			numberOfSeekers = cfg.Bind<string>("2:Players.Seeker", "Number of Seekers", "20%", "'1'-[connected players] (Example '3') OR '1%'-'100%' (Example 25%): No matter what this is set to, (Example '0' or '100%') there will ALWAYS be at least 1 hider and 1 seeker (Unless there is only one connected player, then they would just be seeker)");
			extraSeekerChooseBehavior = cfg.Bind<string>("2:Players.Seeker", "Extra Seeker Choose Behavior", "Turns", "'None' (Just a random range generator), 'Turns' (Will not pick someone that was already seeker, resets when everyone got a chance), 'Lever' (!WIP! Players nearest to the lever will be the seeker)");
			isSeekerImmune = cfg.Bind<bool>("2:Players.Seeker", "Is Seeker Immune", false, "Determines if the seeker could be harmed or not (not recommended while abilites are enabled)");
			hostilesIgnoreSeeker = cfg.Bind<bool>("2:Players.Seeker", "Is Seeker Ignored", true, "(To be implemented!) Determines if the seeker should be ignored by hostiles or not.");
			shotgunInfiniteAmmo = cfg.Bind<bool>("2:Players.Seeker", "Shotgun Infinite Ammo", true, "Disables the need for ammo for the shotgun.");
			shotgunAutoReload = cfg.Bind<bool>("2:Players.Seeker", "Shotgun Auto Reload", false, "(Only works if 'shotgunInfiniteAmmo' is enabled) Disables the need to reload a new shell, and lets you shoot like normal again.");
			shipLeaveEarly = cfg.Bind<bool>("2:Players.Seeker", "Make Ship Leave Early", true, "Skips the time when there is one hider left (Time defined by 'timeWhenLastHider')");
			timeWhenLastHider = cfg.Bind<float>("2:Players.Seeker", "Last Hider Time", 900f, "The time the clock is set to when there is one hider left. 900 = 9:00 PM, 960 = 10:00 PM, +60 = +1 hour (Requires makeShipLeaveEarly = true, to be enabled!)");
			timeSeekerIsReleased = cfg.Bind<float>("2:Players.Seeker", "Seeking Time", 195f, "The time the seeker is released to wreak havoc in the land. 180 = 9:00 PM, 240 = 10:00 PM, +60 = +1 hour");
			teleportSeekerToEntrance = cfg.Bind<bool>("2:Players.Seeker", "Teleport Seeker To Entrance", true, "Determines if the seeker should be teleported to the entrance on landing.");
			forceSeekerInside = cfg.Bind<bool>("2:Players.Seeker", "Teleport Seeker Inside", true, "Determines if the seeker should be teleported into the building on landing. (teleportSeekerToEntrance Should Be Enabled!)");
			seekerItemSlot1 = cfg.Bind<string>("2:Players.Seeker", "Seeker Item Slot 1", "Shotgun", "The id of the item that will spawn in the first slot of the seeker. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			seekerItemSlot2 = cfg.Bind<string>("2:Players.Seeker", "Seeker Item Slot 2", "Pro-flashlight", "The id of the item that will spawn in the second slot of the seeker. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			seekerItemSlot3 = cfg.Bind<string>("2:Players.Seeker", "Seeker Item Slot 3", "", "The id of the item that will spawn in the third slot of the seeker. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			seekerItemSlot4 = cfg.Bind<string>("2:Players.Seeker", "Seeker Item Slot 4", "", "The id of the item that will spawn in the fourth slot of the seeker. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			hiderNameColor = cfg.Bind<Color>("2:Players.Hider", "Hider Name Color", new Color(1f, 1f, 1f), "The color the player's name tag will be.");
			teleportHidersToEntrance = cfg.Bind<bool>("2:Players.Hider", "Teleport Hiders To Entrance", true, "Determines if all the hiders should be teleported to the entrance on landing.");
			forceHidersInside = cfg.Bind<bool>("2:Players.Hider", "Teleport Hiders Inside", true, "Determines if all the hiders should be teleported into the building on landing. (teleportHidersToEntrance Should Be Enabled!)");
			lockHidersInside = cfg.Bind<bool>("2:Players.Hider", "Lock Hiders Inside", true, "Determines if all the hiders should be locked inside the building. (forceHidersInside Should Be Enabled!)");
			infiniteFlashlightBattery = cfg.Bind<bool>("2:Players.Hider", "Infinite Flashlight Battery", true, "Makes the flashlight never run out of battery.");
			hiderItemSlot1 = cfg.Bind<string>("2:Players.Hider", "Hider Item Slot 1", "flashlight", "The id of the item that will spawn in the first slot of the hider. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			hiderItemSlot2 = cfg.Bind<string>("2:Players.Hider", "Hider Item Slot 2", "", "The id of the item that will spawn in the second slot of the hider. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			hiderItemSlot3 = cfg.Bind<string>("2:Players.Hider", "Hider Item Slot 3", "", "The id of the item that will spawn in the third slot of the hider. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			hiderItemSlot4 = cfg.Bind<string>("2:Players.Hider", "Hider Item Slot 4", "", "The id of the item that will spawn in the fourth slot of the hider. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			zombieNameColor = cfg.Bind<Color>("2:Players.Zombie", "Zombie Name Color", new Color(0f, 1f, 0f), "The color the player's name tag will be.");
			deadHidersRespawn = cfg.Bind<bool>("2:Players.Zombie", "Dead Hiders Respawn", true, "(If true) : When a hider is killed, they will turn into a zombie, assisting the seeker.");
			deadZombiesRespawn = cfg.Bind<bool>("2:Players.Zombie", "Dead Zombies Respawn", false, "(If true) : When a zombie dies, they will respawn again.");
			zombiesCanUseAbilities = cfg.Bind<bool>("2:Players.Zombie", "Zombies Can Use Abilities", false, "(If true) : The zombies will be able to use seeker abilities.");
			zombieSpawnDelay = cfg.Bind<float>("2:Players.Zombie", "Zombie Spawn Delay", 5f, "When a player dies, the thread will yield for the spesified amount of seconds before attempting to respawn them as a zombie.");
			zombieSpawnLocation = cfg.Bind<string>("2:Players.Zombie", "Lock Hiders Inside", "Seeker", "'Inside' : Teleports Zombies inside when spawning, 'Entrance' : Teleports Zombies to the main entrance when spawning, 'Ship' : Spawns Zombies in the ship, 'Seeker' : Teleports Zombies near the seeker");
			zombieItemSlot1 = cfg.Bind<string>("2:Players.Zombie", "Hider Item Slot 1", "Stop sign, Yield sign, Shovel", "The id of the item that will spawn in the first slot of the zombie. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			zombieItemSlot2 = cfg.Bind<string>("2:Players.Zombie", "Hider Item Slot 2", "", "The id of the item that will spawn in the second slot of the zombie. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			zombieItemSlot3 = cfg.Bind<string>("2:Players.Zombie", "Hider Item Slot 3", "", "The id of the item that will spawn in the third slot of the zombie. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
			zombieItemSlot4 = cfg.Bind<string>("2:Players.Zombie", "Hider Item Slot 4", "", "The id of the item that will spawn in the fourth slot of the zombie. 'item1, item2' will randomly choose between the items listed (See README.md for list of Item IDs)");
		}
	}
	public class NetworkHandler : NetworkBehaviour
	{
		public LethalClientMessage<string> NetworkMessage = new LethalClientMessage<string>("HASMessage", (Action<string>)null, (Action<string, ulong>)null);

		public static NetworkHandler Instance { get; private set; }

		public event Action<string, MessageProperties> NetworkEvent;

		public override void OnNetworkSpawn()
		{
			this.NetworkEvent = null;
			NetworkMessage = new LethalClientMessage<string>("HASMessage", (Action<string>)null, (Action<string, ulong>)null);
			if (Object.op_Implicit((Object)(object)Instance) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				NetworkHandler instance = Instance;
				if (instance != null)
				{
					NetworkObject component = ((Component)instance).gameObject.GetComponent<NetworkObject>();
					if (component != null)
					{
						component.Despawn(true);
					}
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
			Debugger.Debug.LogMessage("NetworkHandler OnNetworkSpawn(): Connecting Events....");
			NetworkEvent += SyncingPatch.LevelLoading;
			NetworkEvent += SyncingPatch.LevelLoaded;
			NetworkEvent += SyncingPatch.PlayerChosen;
			NetworkEvent += SyncingPatch.SeekersChosen;
			NetworkEvent += SyncingPatch.LockDoor;
			NetworkEvent += SyncingPatch.OpenDoor;
			NetworkEvent += SyncingPatch.PlayerTeleported;
			NetworkEvent += SyncingPatch.DisplayTip;
			NetworkEvent += SyncingPatch.LeverFlipped;
			NetworkEvent += SyncingPatch.SellCurrentItem;
			NetworkEvent += SyncingPatch.MoneyChanged;
			NetworkEvent += SyncingPatch.DestroyItem;
			NetworkEvent += SyncingPatch.BuyAbility;
			NetworkEvent += SyncingPatch.ActivateAbility;
			NetworkEvent += SyncingPatch.SetDayTime;
			NetworkEvent += SyncingPatch.GrabItem;
			NetworkEvent += SyncingPatch.RequestAbilityConfig;
			NetworkEvent += SyncingPatch.ReceiveAbilityConfig;
			NetworkMessage.OnReceivedFromClient += EventRecivedRpc;
		}

		public override void OnDestroy()
		{
			Debugger.Debug.LogMessage("NetworkHandler OnDestroy(): Disconnecting Events....");
			NetworkEvent -= SyncingPatch.LevelLoading;
			NetworkEvent -= SyncingPatch.LevelLoaded;
			NetworkEvent -= SyncingPatch.PlayerChosen;
			NetworkEvent -= SyncingPatch.SeekersChosen;
			NetworkEvent -= SyncingPatch.LockDoor;
			NetworkEvent -= SyncingPatch.OpenDoor;
			NetworkEvent -= SyncingPatch.PlayerTeleported;
			NetworkEvent -= SyncingPatch.DisplayTip;
			NetworkEvent -= SyncingPatch.LeverFlipped;
			NetworkEvent -= SyncingPatch.SellCurrentItem;
			NetworkEvent -= SyncingPatch.MoneyChanged;
			NetworkEvent -= SyncingPatch.DestroyItem;
			NetworkEvent -= SyncingPatch.BuyAbility;
			NetworkEvent -= SyncingPatch.ActivateAbility;
			NetworkEvent -= SyncingPatch.SetDayTime;
			NetworkEvent -= SyncingPatch.GrabItem;
			NetworkEvent -= SyncingPatch.RequestAbilityConfig;
			NetworkEvent += SyncingPatch.ReceiveAbilityConfig;
			((NetworkBehaviour)this).OnDestroy();
		}

		public void EventSendRpc(string eventName, MessageProperties message = null)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (message != null)
			{
				this.NetworkEvent?.Invoke(eventName, message);
			}
			else
			{
				this.NetworkEvent?.Invoke(eventName, new MessageProperties(__bool: false, "", 0, 0f, 0uL, default(Vector3), __null: true));
			}
			Debugger.Debug.LogMessage("[Server] Event! + " + eventName + " Info: " + message);
			string text = eventName + "|" + JsonUtility.ToJson((object)message);
			NetworkMessage.SendAllClients(text, false, false);
		}

		public void EventRecivedRpc(string data, ulong playerID)
		{
			//IL_0073: 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)
			string arg = data.Split("|")[0];
			string text = data.Split("|")[1];
			MessageProperties messageProperties = (MessageProperties)JsonUtility.FromJson(text, typeof(MessageProperties));
			if (messageProperties != null)
			{
				this.NetworkEvent?.Invoke(arg, messageProperties);
			}
			else
			{
				this.NetworkEvent?.Invoke(arg, new MessageProperties(__bool: false, "", 0, 0f, 0uL, default(Vector3), __null: true));
			}
		}
	}
	[BepInPlugin("gogozooom.HideAndSeek", "Hide And Seek", "1.4.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "gogozooom.HideAndSeek";

		public const string PLUGIN_NAME = "Hide And Seek";

		public const string PLUGIN_VERSION = "1.4.0.1";

		public static ManualLogSource _Logger;

		public static Plugin instance;

		public static Config _Config;

		public static List<PlayerControllerB> seekers = new List<PlayerControllerB>();

		public static List<PlayerControllerB> zombies = new List<PlayerControllerB>();

		public static AssetBundle networkHandlerBundle;

		public static AssetBundle abilityRadialMenuBundle;

		private readonly Harmony harmony = new Harmony("gogozooom.HideAndSeek");

		private void Awake()
		{
			instance = this;
			_Logger = ((BaseUnityPlugin)this).Logger;
			_Config = new Config(((BaseUnityPlugin)this).Config);
			Debugger.Debug.Log("Patching .RoundManagerPatch");
			harmony.PatchAll(typeof(RoundManagerPatch));
			Debugger.Debug.Log("Patching .TurretPatch");
			harmony.PatchAll(typeof(TurretPatch));
			Debugger.Debug.Log("Patching .LandminePatch");
			harmony.PatchAll(typeof(LandminePatch));
			Debugger.Debug.Log("Patching .SpikeRoofTrapPatch");
			harmony.PatchAll(typeof(SpikeRoofTrapPatch));
			Debugger.Debug.Log("Patching .ShotgunPatch");
			harmony.PatchAll(typeof(ShotgunPatch));
			Debugger.Debug.Log("Patching .PlayerControllerBPatch");
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			Debugger.Debug.Log("Patching .EntranceTeleportPatch");
			harmony.PatchAll(typeof(EntranceTeleportPatch));
			Debugger.Debug.Log("Patching .TerminalPatch");
			harmony.PatchAll(typeof(TerminalPatch));
			Debugger.Debug.Log("Patching .TimeOfDayPatch");
			harmony.PatchAll(typeof(TimeOfDayPatch));
			Debugger.Debug.Log("Patching .HUDManagerPatch");
			harmony.PatchAll(typeof(HUDManagerPatch));
			Debugger.Debug.Log("Patching .GameNetworkManagerPatch");
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			Debugger.Debug.Log("Patching .StartOfRoundPatch");
			harmony.PatchAll(typeof(StartOfRoundPatch));
			Debugger.Debug.Log("Patching .InteractTriggerPatch");
			harmony.PatchAll(typeof(InteractTriggerPatch));
			Debugger.Debug.Log("Patching .GrabbableObjectPatch");
			harmony.PatchAll(typeof(GrabbableObjectPatch));
			Debugger.Debug.Log("Patching .DeadBodyInfoPatch");
			harmony.PatchAll(typeof(DeadBodyInfoPatch));
			Debugger.Debug.Log("Patching .HoarderBugAIPatch");
			harmony.PatchAll(typeof(HoarderBugAIPatch));
			Debugger.Debug.Log("Patching .CrawlerAIPatch");
			harmony.PatchAll(typeof(CrawlerAIPatch));
			Debugger.Debug.Log("Patching .FlowermanAIPatch");
			harmony.PatchAll(typeof(FlowermanAIPatch));
			Debugger.Debug.Log("Patching .MaskedPlayerEnemyPatch");
			harmony.PatchAll(typeof(MaskedPlayerEnemyPatch));
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "networkhandler");
			networkHandlerBundle = AssetBundle.LoadFromFile(text);
			string text2 = Path.Combine(directoryName, "abilityradialmenu");
			abilityRadialMenuBundle = AssetBundle.LoadFromFile(text2);
			AbilitySpriteManager.LoadSprites();
			((MonoBehaviour)this).StartCoroutine(AudioManager.LoadAudioCoroutine());
			_Logger.LogInfo((object)"Plugin gogozooom.HideAndSeek is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HideAndSeek";

		public const string PLUGIN_NAME = "HideAndSeek";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace HideAndSeek.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	public class RoundManagerPatch
	{
		public static RoundManager instance;

		public static int playersTeleported;

		public static int playersAlive;

		public static ulong leverLastFlippedBy = 999uL;

		public static List<(ulong playerId, Vector3 position)> itemSpawnPositions = new List<(ulong, Vector3)>();

		private static bool shipLeaving = false;

		public static bool levelLoading = false;

		public static SelectableLevel currentLevel;

		public static ulong lastSeekerId = 10001uL;

		public static List<ulong> pastSeekers = new List<ulong>();

		private static bool rewardedPlayersD = false;

		private static bool seekersWon = false;

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void AwakePatch()
		{
			Debugger.Debug.LogMessage("RoundManager Awake started with variables..:");
			Debugger.Debug.LogMessage($"instance = {instance}");
			Debugger.Debug.LogMessage($"playersTeleported = {playersTeleported}");
			Debugger.Debug.LogMessage($"playersAlive = {playersAlive}");
			Debugger.Debug.LogMessage($"leverLastFlippedBy = {leverLastFlippedBy}");
			Debugger.Debug.LogMessage($"itemSpawnPositions = {itemSpawnPositions}");
			if (leverLastFlippedBy != 999)
			{
				Debugger.Debug.LogError("Player left half way through! Fixing variables");
				playersTeleported = 0;
				playersAlive = 0;
				leverLastFlippedBy = 999uL;
				levelLoading = false;
				lastSeekerId = 10001uL;
				pastSeekers.Clear();
				itemSpawnPositions.Clear();
				Plugin.seekers.Clear();
				Plugin.zombies.Clear();
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch(ref RoundManager __instance)
		{
			if (!AudioManager.LoadedAudio)
			{
				Debugger.Debug.LogWarning("Loading AudioManager Audio!");
				((MonoBehaviour)__instance).StartCoroutine(AudioManager.LoadAudioCoroutine());
			}
			Debugger.Debug.Log($"StartPatch, AbilityManager: Enabled = {Config.abilitiesEnabled.Value}");
			if (Config.abilitiesEnabled.Value)
			{
				((MonoBehaviour)Object.FindObjectOfType<RoundManager>()).StartCoroutine(AbilityManager.ConnectStart());
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch()
		{
			//IL_0197: 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_01cb: 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)
			if (!Object.op_Implicit((Object)(object)GameNetworkManager.Instance.localPlayerController) || !((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsServer)
			{
				return;
			}
			int livingPlayers = StartOfRound.Instance.livingPlayers;
			if (playersAlive < livingPlayers)
			{
				Debugger.Debug.LogWarning("Player count reset to: " + livingPlayers);
				playersAlive = livingPlayers;
			}
			else if (playersAlive > livingPlayers)
			{
				Debugger.Debug.LogWarning("Player died! New Count: " + livingPlayers);
				playersAlive = livingPlayers;
				if (TimeOfDay.Instance.currentDayTime != 0f)
				{
					PlayerDied("Player Died!");
				}
			}
			if (StartOfRound.Instance.shipIsLeaving && !shipLeaving)
			{
				shipLeaving = true;
			}
			else
			{
				if (!StartOfRound.Instance.inShipPhase || !shipLeaving)
				{
					return;
				}
				shipLeaving = false;
				if (Plugin.seekers.Count <= 0 || seekersWon)
				{
					return;
				}
				PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
				foreach (PlayerControllerB val in array)
				{
					if (!Plugin.seekers.Contains(val) && ((Component)val).gameObject.activeSelf)
					{
						NetworkHandler.Instance.EventSendRpc(".moneyChanged", new MessageProperties(__bool: false, "silent", 250, 0f, val.actualClientId));
						NetworkHandler.Instance.EventSendRpc(".tip", new MessageProperties(__bool: false, "You won, and got a reward!", -1, 0f, val.actualClientId));
					}
				}
			}
		}

		[HarmonyPatch("LoadNewLevel")]
		[HarmonyPrefix]
		private static bool LoadLevelPatch(ref int randomSeed, ref SelectableLevel newLevel)
		{
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d31: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d37: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca7: Unknown result type (might be due to invalid IL or missing references)
			Debugger.Debug.LogMessage("[LoadLevelPatch] LoadLevel Start!");
			if (levelLoading)
			{
				Debugger.Debug.LogError("levelLoading is true! This should be abnormal!");
				return false;
			}
			levelLoading = true;
			instance = Object.FindFirstObjectByType<RoundManager>();
			Plugin.seekers.Clear();
			Plugin.zombies.Clear();
			playersTeleported = 0;
			SyncingPatch.TeleportPlayer();
			seekersWon = false;
			currentLevel = newLevel;
			rewardedPlayersD = false;
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				return true;
			}
			if (!Object.op_Implicit((Object)(object)Abilities.turretPrefab) || !Object.op_Implicit((Object)(object)Abilities.landminePrefab))
			{
				SpawnableMapObject[] spawnableMapObjects = currentLevel.spawnableMapObjects;
				foreach (SpawnableMapObject val in spawnableMapObjects)
				{
					if ((Object)(object)val.prefabToSpawn.GetComponentInChildren<Turret>() != (Object)null)
					{
						Abilities.turretPrefab = val.prefabToSpawn;
					}
					if ((Object)(object)val.prefabToSpawn.GetComponentInChildren<Landmine>() != (Object)null)
					{
						Abilities.landminePrefab = val.prefabToSpawn;
					}
				}
			}
			foreach (NetworkObject item in Abilities.objectsToDespawnNextRound)
			{
				if (item.IsSpawned)
				{
					item.Despawn(true);
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
			}
			Abilities.objectsToDespawnNextRound = new List<NetworkObject>();
			NetworkHandler.Instance.EventSendRpc(".levelLoading");
			if (Config.abilitiesEnabled.Value && Config.creditsResetOnNewRound.Value)
			{
				NetworkHandler.Instance.EventSendRpc(".moneyChanged", new MessageProperties(__bool: true, "", 0, 0f, 0uL, default(Vector3), __null: true));
			}
			foreach (SpawnableEnemyWithRarity daytimeEnemy in newLevel.DaytimeEnemies)
			{
				Debugger.Debug.Log("Checking DaytimeEnemey: " + daytimeEnemy.enemyType.enemyName);
				if (Config.disableAllDaytimeEntities.Value)
				{
					Debugger.Debug.Log("DisableAllDaytimeEntities is true! " + daytimeEnemy.enemyType.enemyName);
					daytimeEnemy.rarity = 0;
					continue;
				}
				switch (daytimeEnemy.enemyType.enemyName)
				{
				case "Red Locust Bees":
					if (!Config.circuitBeeEnabled.Value)
					{
						daytimeEnemy.rarity = 0;
					}
					break;
				case "Manticoil":
					if (!Config.manticoilEnabled.Value)
					{
						daytimeEnemy.rarity = 0;
					}
					break;
				case "Docile Locust Bees":
					if (!Config.roamingLocustEnabled.Value)
					{
						daytimeEnemy.rarity = 0;
					}
					break;
				}
				Debugger.Debug.Log(daytimeEnemy.enemyType.enemyName + ".Rarity = " + daytimeEnemy.rarity);
			}
			foreach (SpawnableEnemyWithRarity outsideEnemy in newLevel.OutsideEnemies)
			{
				Debugger.Debug.Log("Checking OutsideEnemey: " + outsideEnemy.enemyType.enemyName);
				if (Config.disableAllOutsideEntities.Value)
				{
					Debugger.Debug.Log("DisableAllOutsideEntities is true! " + outsideEnemy.enemyType.enemyName);
					outsideEnemy.rarity = 0;
					continue;
				}
				switch (outsideEnemy.enemyType.enemyName)
				{
				case "MouthDog":
					if (!Config.eyelessDogEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "ForestGiant":
					if (!Config.forestKeeperEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "Baboon hawk":
					if (!Config.baboonHawkEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "Earth Leviathan":
					if (!Config.earthLeviathanEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "RadMech":
					if (!Config.mechEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "Tulip Snake":
					if (!Config.tulipSnakeEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				case "BushWolf":
					if (!Config.kidnapperFoxEnabled.Value)
					{
						outsideEnemy.rarity = 0;
					}
					break;
				}
				Debugger.Debug.Log(outsideEnemy.enemyType.enemyName + ".Rarity = " + outsideEnemy.rarity);
			}
			foreach (SpawnableEnemyWithRarity enemy in newLevel.Enemies)
			{
				Debugger.Debug.Log("Checking Enemey: " + enemy.enemyType.enemyName);
				if (Config.disableAllIndoorEntities.Value)
				{
					Debugger.Debug.Log("DisableAllIndoorEntities is true! " + enemy.enemyType.enemyName);
					enemy.rarity = 0;
					continue;
				}
				switch (enemy.enemyType.enemyName)
				{
				case "Centipede":
					if (!Config.snareFleaEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Bunker Spider":
					if (!Config.bunkerSpiderEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Hoarding bug":
					if (!Config.hoardingBugEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Flowerman":
					if (!Config.brackenEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Crawler":
					if (!Config.thumperEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Blob":
					if (!Config.hygrodereEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Girl":
					if (!Config.ghostGirlEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Puffer":
					if (!Config.sporeLizardEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Nutcracker":
					if (!Config.nutcrackerEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Jester":
					if (!Config.jesterEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Spring":
					if (!Config.coilHeadEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Masked":
					if (!Config.maskedEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Butler":
					if (!Config.butlerEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "Clay Surgeon":
					if (!Config.barberEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				case "CaveDweller":
					if (!Config.maneaterEnabled.Value)
					{
						enemy.rarity = 0;
					}
					break;
				}
				Debugger.Debug.Log(enemy.enemyType.enemyName + ".Rarity = " + enemy.rarity);
			}
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB val2 in array)
			{
				if (val2.isPlayerControlled)
				{
					Debugger.Debug.LogMessage("Found " + ((Object)val2).name + "! Adding to active list.");
					list.Add(val2);
				}
			}
			int num = 1;
			num = ((!Config.numberOfSeekers.Value.Contains("%")) ? int.Parse(Config.numberOfSeekers.Value.Split("%")[0]) : Mathf.RoundToInt(float.Parse(Config.numberOfSeekers.Value.Replace("%", "")) / 100f * (float)list.Count));
			if (num >= list.Count)
			{
				num = list.Count - 1;
			}
			if (num <= 0)
			{
				num = 1;
			}
			Debugger.Debug.LogWarning($"Number of seekers this round! = '{num}'");
			string text = "";
			for (int k = 0; k < num; k++)
			{
				PlayerControllerB val3 = PickRandomSeeker();
				Plugin.seekers.Add(val3);
				if (text != "")
				{
					text += ", ";
				}
				text += val3.playerUsername;
				NetworkHandler.Instance.EventSendRpc(".playerChosen", new MessageProperties(__bool: false, "", 0, 0f, ((NetworkBehaviour)val3).NetworkObjectId));
			}
			NetworkHandler.Instance.EventSendRpc(".seekersChosen", new MessageProperties(__bool: false, text, 0, 0f, 0uL));
			itemSpawnPositions.Clear();
			((MonoBehaviour)instance).StartCoroutine(GivePlayersItems());
			levelLoading = false;
			NetworkHandler.Instance.EventSendRpc(".levelLoaded", new MessageProperties(__bool: false, "", 0, 0f, 0uL));
			return true;
		}

		public static PlayerControllerB PickRandomSeeker()
		{
			string text = Config.seekerChooseBehavior.Value.ToLower().Trim().Replace(" ", "");
			if (Plugin.seekers.Count > 0)
			{
				text = Config.extraSeekerChooseBehavior.Value.ToLower().Trim().Replace(" ", "");
			}
			ulong num = 10001uL;
			Debugger.Debug.Log("Random Type ['" + text + "']");
			switch (text)
			{
			case "nodouble":
			{
				List<ulong> list = new List<ulong>();
				PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
				foreach (PlayerControllerB val in array)
				{
					Debugger.Debug.Log($"Searching {val}, {val.isPlayerControlled}, {val.actualClientId}");
					if (val.isPlayerControlled && val.actualClientId != lastSeekerId && !Plugin.seekers.Contains(val))
					{
						Debugger.Debug.Log($"Added {val}!");
						list.Add(val.actualClientId);
					}
				}
				if (list.Count > 0)
				{
					int index = Random.Range(0, list.Count);
					Debugger.Debug.Log("[NoDouble] RandomPlayerNumber = " + index);
					num = list[index];
				}
				else
				{
					num = GameNetworkManager.Instance.localPlayerController.actualClientId;
				}
				break;
			}
			case "turns":
			{
				List<ulong> list3 = new List<ulong>();
				PlayerControllerB[] array3 = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
				foreach (PlayerControllerB val3 in array3)
				{
					if (val3.isPlayerControlled && !pastSeekers.Contains(val3.actualClientId) && !Plugin.seekers.Contains(val3))
					{
						list3.Add(val3.actualClientId);
					}
				}
				if (list3.Count <= 0)
				{
					pastSeekers.Clear();
					PlayerControllerB[] array4 = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
					foreach (PlayerControllerB val4 in array4)
					{
						if (val4.isPlayerControlled && !Plugin.seekers.Contains(val4))
						{
							list3.Add(val4.actualClientId);
						}
					}
				}
				int num2 = Random.Range(0, list3.Count);
				Debugger.Debug.Log($"[Turns] RandomPlayerNumber = '{num2}' Number In Current Pool '{list3.Count}'");
				num = list3[num2];
				if (list3.Contains(num))
				{
					list3.Remove(num);
					pastSeekers.Add(num);
				}
				Debugger.Debug.LogWarning("---- New Pools! ----");
				Debugger.Debug.LogWarning("CurrentPool = ");
				Debugger.Debug.Log(list3.ToArray());
				Debugger.Debug.LogWarning("PastSeekers = ");
				Debugger.Debug.Log(pastSeekers.ToArray());
				break;
			}
			case "lever":
				if (leverLastFlippedBy != 999)
				{
					Debugger.Debug.Log($"It using new lever thingy hehehe; Player id ({leverLastFlippedBy})");
					num = leverLastFlippedBy;
					break;
				}
				goto default;
			default:
			{
				List<ulong> list2 = new List<ulong>();
				PlayerControllerB[] array2 = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
				foreach (PlayerControllerB val2 in array2)
				{
					if (val2.isPlayerControlled && !Plugin.seekers.Contains(val2))
					{
						list2.Add(val2.actualClientId);
					}
				}
				int index2 = Random.Range(0, list2.Count);
				Debugger.Debug.Log("[Random] RandomPlayerNumber = " + index2);
				num = list2[index2];
				break;
			}
			}
			PlayerControllerB playerWithClientId = GetPlayerWithClientId(num);
			if ((Object)(object)playerWithClientId == (Object)null)
			{
				Debugger.Debug.LogWarning($"Could not find player with id: '{num}' using id: '0' instead");
				playerWithClientId = GetPlayerWithClientId(0uL);
			}
			lastSeekerId = num;
			return playerWithClientId;
		}

		public static PlayerControllerB GetPlayerWithClientId(ulong playerId)
		{
			PlayerControllerB val = null;
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB val2 in array)
			{
				Debugger.Debug.Log($"Looped through {((Object)val2).name}; Client id {val2.actualClientId}; Is controlled; {val2.isPlayerControlled}");
				if (playerId == 0)
				{
					if (GetFRFRId(val2) == playerId)
					{
						val = val2;
						break;
					}
				}
				else if (val2.actualClientId == playerId)
				{
					val = val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				bool flag = false;
				PlayerControllerB[] array2 = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
				foreach (PlayerControllerB val3 in array2)
				{
					if (((NetworkBehaviour)val3).OwnerClientId != val3.actualClientId)
					{
						flag = true;
						val3.actualClientId = ((NetworkBehaviour)val3).OwnerClientId;
						Debugger.Debug.LogWarning("'" + val3.playerUsername + "' found with an incorrect actualClientId!");
					}
				}
				if (flag)
				{
					return GetPlayerWithClientId(playerId);
				}
			}
			Debugger.Debug.Log($"GetPlayerWithClientId({playerId}) Got player '{val}' with '{playerId}'");
			return val;
		}

		private static ulong GetFRFRId(PlayerControllerB player)
		{
			string text = ((Object)player).name.Replace("Player", "").Replace(" ", "").Replace("(", "")
				.Replace(")", "");
			if (text == "")
			{
				return 0uL;
			}
			return ulong.Parse(text);
		}

		public static void PlayerDied(string reason = "", bool checking = false)
		{
			//IL_0197: 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_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB val in array)
			{
				if (Plugin.seekers.Contains(val) && !val.isPlayerDead)
				{
					num2++;
				}
				else if (!val.isPlayerDead)
				{
					num++;
				}
			}
			if (checking)
			{
				Debugger.Debug.Log($"Checking dead people... Seekers dead: {num2 <= 0} Alive hider count: {num} Is ship leaving: {StartOfRound.Instance.shipIsLeaving}");
			}
			if (StartOfRound.Instance.shipIsLeaving)
			{
				return;
			}
			StartMatchLever val2 = Object.FindAnyObjectByType<StartMatchLever>();
			if (num2 <= 0)
			{
				if (!rewardedPlayersD)
				{
					rewardedPlayersD = true;
					PlayerControllerB[] array2 = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
					foreach (PlayerControllerB val3 in array2)
					{
						if (!Plugin.seekers.Contains(val3) && ((Component)val3).gameObject.activeSelf && !val3.isPlayerDead)
						{
							NetworkHandler.Instance.EventSendRpc(".moneyChanged", new MessageProperties(__bool: false, "silent", 250, 0f, val3.actualClientId));
						}
					}
				}
				if (!checking)
				{
					NetworkHandler.Instance.EventSendRpc(".tip", new MessageProperties(__bool: false, "", 0, 0f, 0uL)
					{
						_string = "Seeker Died; Hiders Win!",
						_bool = true
					});
				}
				Debugger.Debug.LogMessage("_________ SEEKER DIED! _________");
				val2.EndGame();
				val2.LeverAnimation();
				return;
			}
			if (!checking)
			{
				Debugger.Debug.LogMessage("_________ PLAYER DIED! _________");
			}
			if (num <= 0 && GameNetworkManager.Instance.connectedPlayers != 1)
			{
				if (!rewardedPlayersD)
				{
					rewardedPlayersD = true;
					seekersWon = true;
					foreach (PlayerControllerB seeker in Plugin.seekers)
					{
						NetworkHandler.Instance.EventSendRpc(".moneyChanged", new MessageProperties(__bool: false, "silent", 500, 0f, seeker.actualClientId));
					}
				}
				if (!checking)
				{
					NetworkHandler.Instance.EventSendRpc(".tip", new MessageProperties(__bool: false, "", 0, 0f, 0uL)
					{
						_string = "Seeker Won!",
						_bool = true
					});
				}
				Debugger.Debug.LogMessage($"_________ SEEKER WON! _________ {GameNetworkManager.Instance.connectedPlayers} Connected player amount. != 1?: {StartOfRound.Instance.connectedPlayersAmount != 1} ");
				val2.EndGame();
				val2.LeverAnimation();
			}
			else if (num >= 1 && !checking)
			{
				if (num == 1)
				{
					if (Config.shipLeaveEarly.Value && Config.timeWhenLastHider.Value > TimeOfDay.Instance.currentDayTime)
					{
						NetworkHandler.Instance.EventSendRpc(".setDayTime", new MessageProperties(__bool: false, "", 0, Config.timeWhenLastHider.Value, 0uL));
					}
					NetworkHandler.Instance.EventSendRpc(".tip", new MessageProperties(__bool: false, "1 Hider Remains...", 0, 0f, 0uL));
				}
				else
				{
					NetworkHandler.Instance.EventSendRpc(".tip", new MessageProperties(__bool: false, $"{num} Hiders Remain...", 0, 0f, 0uL));
				}
			}
			if (!checking)
			{
				Debugger.Debug.LogMessage($"_________ ({num + num2}) Players Left! _________");
			}
		}

		public static IEnumerator GivePlayersItems()
		{
			List<PlayerControllerB> players = new List<PlayerControllerB>();
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB player in array)
			{
				if (player.isPlayerControlled)
				{
					players.Add(player);
				}
			}
			Debugger.Debug.LogMessage("Game Has Started = " + GameNetworkManager.Instance.gameHasStarted);
			while (true)
			{
				if (itemSpawnPositions.Count == 0 || playersTeleported == 0 || !StartOfRound.Instance.shipHasLanded)
				{
					if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
					{
						PlayerDied("Before Item Give", checking: true);
					}
					if (!StartOfRound.Instance.shipIsLeaving)
					{
						Debugger.Debug.Log($"[Progress] Players Teleported: {playersTeleported}, item Spawn Positions: {itemSpawnPositions.Count}");
						yield return (object)new WaitForSeconds(1f);
						continue;
					}
					break;
				}
				int tries = 5;
				while ((itemSpawnPositions.Count < players.Count || playersTeleported < players.Count || !StartOfRound.Instance.shipHasLanded) && tries > 0)
				{
					Debugger.Debug.Log($"[Progress Inter] Not fully there! We have: {tries} left before ending automatically! {playersTeleported}, {itemSpawnPositions.Count}");
					yield return (object)new WaitForSeconds(1f);
					tries--;
				}
				Debugger.Debug.Log($"[Final] Players Teleported: {playersTeleported}, item Spawn Positions: {itemSpawnPositions.Count}");
				foreach (PlayerControllerB player2 in players)
				{
					if (Plugin.seekers.Contains(player2))
					{
						if (!string.IsNullOrEmpty(Config.seekerItemSlot1.Value))
						{
							yield return SpawnNewItemCoroutine(Config.seekerItemSlot1.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.seekerItemSlot2.Value))
						{
							yield return SpawnNewItemCoroutine(Config.seekerItemSlot2.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.seekerItemSlot3.Value))
						{
							yield return SpawnNewItemCoroutine(Config.seekerItemSlot3.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.seekerItemSlot4.Value))
						{
							yield return SpawnNewItemCoroutine(Config.seekerItemSlot4.Value, player2);
						}
					}
					else
					{
						if (!string.IsNullOrEmpty(Config.hiderItemSlot1.Value))
						{
							yield return SpawnNewItemCoroutine(Config.hiderItemSlot1.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.hiderItemSlot2.Value))
						{
							yield return SpawnNewItemCoroutine(Config.hiderItemSlot2.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.hiderItemSlot3.Value))
						{
							yield return SpawnNewItemCoroutine(Config.hiderItemSlot3.Value, player2);
						}
						if (!string.IsNullOrEmpty(Config.hiderItemSlot4.Value))
						{
							yield return SpawnNewItemCoroutine(Config.hiderItemSlot4.Value, player2);
						}
					}
				}
				break;
			}
		}

		public static void SpawnNewItem(string itemName, PlayerControllerB player, bool forceSamePosition = false)
		{
			((MonoBehaviour)RoundManager.Instance).StartCoroutine(SpawnNewItemCoroutine(itemName, player, forceSamePosition));
		}

		private static IEnumerator SpawnNewItemCoroutine(string itemName, PlayerControllerB player, bool forceSamePosition = false)
		{
			Debugger.Debug.LogMessage("SpawnNewItem()!");
			Item[] items = Resources.FindObjectsOfTypeAll<Item>();
			string targetItem = itemName;
			if (itemName.Contains(","))
			{
				string[] itemNames = itemName.Split(",");
				int r = Random.Range(0, itemNames.Length);
				targetItem = itemNames[r];
			}
			int i = 0;
			Item[] array = items;
			foreach (Item item2 in array)
			{
				if (item2.itemName.ToLower().Trim() == targetItem.ToLower().Trim())
				{
					break;
				}
				i++;
			}
			if (i == items.Length)
			{
				Debugger.Debug.LogWarning("Could not find " + targetItem + " in items id list! (Look at README.md to see item IDs)");
				yield break;
			}
			Vector3 itemSpawnPosition2 = ((Component)player).transform.position;
			bool newPositionFound = false;
			Debugger.Debug.Log($"Spawing Item with spawn positions: {itemSpawnPositions.Count}");
			foreach (var idVector in itemSpawnPositions)
			{
				Debugger.Debug.Log($"Scanning {idVector.playerId} with position {idVector.position}");
				if (idVector.playerId == player.actualClientId)
				{
					newPositionFound = true;
					itemSpawnPosition2 = idVector.position;
					Debugger.Debug.Log($"New Item Spawn Position! {itemSpawnPosition2}");
				}
			}
			if (!newPositionFound)
			{
				Debugger.Debug.LogError("Could not find Spawn Position for player");
			}
			if (forceSamePosition)
			{
				itemSpawnPosition2 = ((Component)player).transform.position;
			}
			itemSpawnPosition2 += Vector3.up * 0.3f;
			GrabbableObject newItem = Object.Instantiate<GameObject>(items[i].spawnPrefab, itemSpawnPosition2, Quaternion.identity).GetComponent<GrabbableObject>();
			newItem.fallTime = 0f;
			((Component)newItem).GetComponent<NetworkObject>().Spawn(false);
			((NetworkBehaviour)newItem).NetworkObject.ChangeOwnership(player.actualClientId);
			Debugger.Debug.LogMessage($"Spawning {((Object)newItem).name} for {player.playerUsername} at position {((Component)newItem).transform.position}");
			yield return (object)new WaitForEndOfFrame();
			int totalItems = 0;
			GrabbableObject[] itemSlots = player.ItemSlots;
			foreach (GrabbableObject item in itemSlots)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					totalItems++;
				}
			}
			if (totalItems < 4)
			{
				NetworkHandler networkHandler = NetworkHandler.Instance;
				ulong actualClientId = player.actualClientId;
				string _extraMessage = ((NetworkBehaviour)newItem).NetworkObjectId.ToString();
				networkHandler.EventSendRpc(".grabItem", new MessageProperties(__bool: false, "", 0, 0f, actualClientId, default(Vector3), __null: false, _extraMessage));
			}
			yield return (object)new WaitForEndOfFrame();
		}

		public static bool IsRoundActive()
		{
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			PlayerControllerB[] array = Object.FindObjectsByType<PlayerControllerB>((FindObjectsSortMode)0);
			foreach (PlayerControllerB val in array)
			{
				if (val.isPlayerControlled)
				{
					list.Add(val);
				}
			}
			return playersTeleported >= list.Count && StartOfRound.Instance.shipHasLanded;
		}
	}
	[HarmonyPatch(typeof(Turret))]
	public class TurretPatch
	{
		[HarmonyPatch("CheckForPlayersInLineOfSight")]
		[HarmonyPrefix]
		private static bool CheckForPlayersInLineOfSightPatch(ref Turret __instance, ref PlayerControllerB __result, ref float radius, ref bool angleRangeCheck)
		{
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Invalid comparison between Unknown and I4
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Invalid comparison between Unknown and I4
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			if (Config.abilitiesEnabled.Value)
			{
				NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
				SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Component)networkObject).gameObject.GetComponent<SpawnAbilityInfo>() : null);
				if (Object.op_Implicit((Object)(object)spawnAbilityInfo))
				{
					Vector3 val = __instance.aimPoint.forward;
					val = Quaternion.Euler(0f, (float)(-(int)__instance.rotationRange) / radius, 0f) * val;
					float num = __instance.rotationRange / radius * 2f;
					Ray val2 = default(Ray);
					RaycastHit val3 = default(RaycastHit);
					for (int i = 0; i <= 6; i++)
					{
						((Ray)(ref val2))..ctor(__instance.centerPoint.position, val);
						bool flag = (bool)AccessTools.Field(typeof(Turret), "enteringBerserkMode").GetValue(__instance);
						if (Physics.Raycast(val2, ref val3, 30f, 1051400, (QueryTriggerInteraction)1))
						{
							AccessTools.Field(typeof(Turret), "shootRay").SetValue(__instance, val2);
							AccessTools.Field(typeof(Turret), "hit").SetValue(__instance, val3);
							if (((Component)((RaycastHit)(ref val3)).transform).CompareTag("Player"))
							{
								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 - __instance.centerPoint.position, __instance.forwardFacingPos.forward) > __instance.rotationRange)
									{
										__result = null;
										return false;
									}
									if ((Object)(object)component == (Object)(object)spawnAbilityInfo.creatorPlayer || spawnAbilityInfo.otherFriendlies.Contains(component))
									{
										Debugger.Debug.LogError("Turret: Canceled behavior because is friendly!");
										__result = null;
										return false;
									}
									__result = component;
									return false;
								}
								continue;
							}
							if (((int)__instance.turretMode == 2 || !((int)__instance.turretMode != 3 || flag)) && ((Component)((RaycastHit)(ref val3)).transform).tag.StartsWith("PlayerRagdoll"))
							{
								Rigidbody component2 = ((Component)((RaycastHit)(ref val3)).transform).GetComponent<Rigidbody>();
								if ((Object)(object)component2 != (Object)null)
								{
									component2.AddForce(((Vector3)(ref val)).normalized * 42f, (ForceMode)1);
								}
							}
						}
						val = Quaternion.Euler(0f, num / 6f, 0f) * val;
					}
					__result = null;
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPatch(Turret __instance)
		{
			if (!Config.turretsEnabled.Value && TimeOfDay.Instance.currentDayTime <= Config.timeSeekerIsReleased.Value)
			{
				Debugger.Debug.LogWarning("Turret Found! Deleteing...");
				((NetworkBehaviour)__instance).NetworkObject.Despawn(true);
				Debugger.Debug.Log("Deleteing...");
			}
		}
	}
	[HarmonyPatch(typeof(Landmine))]
	public class LandminePatch
	{
		[HarmonyPatch("OnTriggerEnter")]
		[HarmonyPrefix]
		private static bool OnTriggerEnterPatch(ref Landmine __instance, ref Collider other)
		{
			if (Config.abilitiesEnabled.Value)
			{
				NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
				SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Component)networkObject).gameObject.GetComponent<SpawnAbilityInfo>() : null);
				if (Object.op_Implicit((Object)(object)spawnAbilityInfo))
				{
					float num = (float)AccessTools.Field(typeof(Landmine), "pressMineDebounceTimer").GetValue(__instance);
					if (__instance.hasExploded)
					{
						return false;
					}
					if (num > 0f)
					{
						return false;
					}
					if (((Component)other).CompareTag("Player"))
					{
						PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
						if ((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
						{
							return false;
						}
						if ((Object)(object)component != (Object)null && !component.isPlayerDead)
						{
							if ((Object)(object)component == (Object)(object)spawnAbilityInfo.creatorPlayer || spawnAbilityInfo.otherFriendlies.Contains(component))
							{
								Debugger.Debug.LogError("Landmine: Canceled behavior because is friendly!");
								return false;
							}
							AccessTools.Field(typeof(Landmine), "localPlayerOnMine").SetValue(__instance, true);
							AccessTools.Field(typeof(Landmine), "pressMineDebounceTimer").SetValue(__instance, 0.5f);
							__instance.PressMineServerRpc();
							return false;
						}
					}
					else if (((Component)other).CompareTag("PhysicsProp") || ((Component)other).tag.StartsWith("PlayerRagdoll"))
					{
						if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<DeadBodyInfo>()))
						{
							if ((Object)(object)((Component)other).GetComponent<DeadBodyInfo>().playerScript != (Object)(object)GameNetworkManager.Instance.localPlayerController)
							{
								return false;
							}
						}
						else if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<GrabbableObject>()) && !((NetworkBehaviour)((Component)other).GetComponent<GrabbableObject>()).NetworkObject.IsOwner)
						{
							return false;
						}
						AccessTools.Field(typeof(Landmine), "pressMineDebounceTimer").SetValue(__instance, 0.5f);
						__instance.PressMineServerRpc();
					}
				}
			}
			return true;
		}

		[HarmonyPatch("OnTriggerExit")]
		[HarmonyPrefix]
		private static bool OnTriggerExitPatch(ref Landmine __instance, ref Collider other)
		{
			if (Config.abilitiesEnabled.Value)
			{
				NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
				SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Component)networkObject).gameObject.GetComponent<SpawnAbilityInfo>() : null);
				if (Object.op_Implicit((Object)(object)spawnAbilityInfo))
				{
					if (__instance.hasExploded)
					{
						return false;
					}
					if (!(bool)AccessTools.Field(typeof(Landmine), "mineActivated").GetValue(__instance))
					{
						return false;
					}
					if (((Component)other).CompareTag("Player"))
					{
						PlayerControllerB component = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
						if ((Object)(object)component != (Object)null && !component.isPlayerDead)
						{
							if ((Object)(object)component != (Object)(object)GameNetworkManager.Instance.localPlayerController)
							{
								return false;
							}
							if ((Object)(object)component == (Object)(object)spawnAbilityInfo.creatorPlayer || spawnAbilityInfo.otherFriendlies.Contains(component))
							{
								Debugger.Debug.LogError("Landmine: Canceled behavior because is friendly!");
								return false;
							}
							AccessTools.Field(typeof(Landmine), "localPlayerOnMine").SetValue(__instance, false);
							AccessTools.Method(typeof(Landmine), "TriggerMineOnLocalClientByExiting", (Type[])null, (Type[])null).Invoke(__instance, null);
							return false;
						}
					}
					else if (((Component)other).tag.StartsWith("PlayerRagdoll") || ((Component)other).CompareTag("PhysicsProp"))
					{
						if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<DeadBodyInfo>()))
						{
							if ((Object)(object)((Component)other).GetComponent<DeadBodyInfo>().playerScript != (Object)(object)GameNetworkManager.Instance.localPlayerController)
							{
								return false;
							}
						}
						else if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<GrabbableObject>()) && !((NetworkBehaviour)((Component)other).GetComponent<GrabbableObject>()).NetworkObject.IsOwner)
						{
							return false;
						}
						AccessTools.Method(typeof(Landmine), "TriggerMineOnLocalClientByExiting", (Type[])null, (Type[])null).Invoke(__instance, null);
					}
				}
			}
			return true;
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPatch(Landmine __instance)
		{
			if (!Config.landminesEnabled.Value && TimeOfDay.Instance.currentDayTime <= Config.timeSeekerIsReleased.Value)
			{
				Debugger.Debug.LogWarning("Landmine Found!");
				((NetworkBehaviour)__instance).NetworkObject.Despawn(true);
				Debugger.Debug.Log("Deleteing...");
			}
		}
	}
	public class EnemyAIPatch
	{
		public static void UpdatePatch(EnemyAI _this)
		{
			//IL_0121: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: 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_0339: 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_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_060f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)_this);
			if (_this.enemyType.isDaytimeEnemy && !_this.daytimeEnemyLeaving)
			{
				AccessTools.Method(typeof(CrawlerAI), "CheckTimeOfDayToLeave", (Type[])null, (Type[])null).Invoke(_this, null);
			}
			if (_this.stunnedIndefinitely <= 0)
			{
				if (_this.stunNormalizedTimer >= 0f)
				{
					_this.stunNormalizedTimer -= Time.deltaTime / _this.enemyType.stunTimeMultiplier;
				}
				else
				{
					_this.stunnedByPlayer = null;
					if (_this.postStunInvincibilityTimer >= 0f)
					{
						_this.postStunInvincibilityTimer -= Time.deltaTime * 5f;
					}
				}
			}
			if (!_this.ventAnimationFinished && _this.timeSinceSpawn < _this.exitVentAnimationTime + 0.005f * (float)RoundManager.Instance.numberOfEnemiesInScene)
			{
				_this.timeSinceSpawn += Time.deltaTime;
				if (!((NetworkBehaviour)_this).IsOwner)
				{
					Vector3 serverPosition = _this.serverPosition;
					if (_this.serverPosition != Vector3.zero)
					{
						((Component)_this).transform.position = _this.serverPosition;
						((Component)_this).transform.eulerAngles = new Vector3(((Component)_this).transform.eulerAngles.x, (float)val.Field("targetYRotation").GetValue(), ((Component)_this).transform.eulerAngles.z);
					}
					return;
				}
				float num = (float)val.Field("updateDestinationInterval").GetValue();
				if (num >= 0f)
				{
					num -= Time.deltaTime;
					return;
				}
				_this.SyncPositionToClients();
				num = 0.1f;
				val.Field("updateDestinationInterval").SetValue((object)num);
				return;
			}
			if (!_this.inSpecialAnimation && !_this.ventAnimationFinished)
			{
				_this.ventAnimationFinished = true;
				if ((Object)(object)_this.creatureAnimator != (Object)null)
				{
					_this.creatureAnimator.SetBool("inSpawningAnimation", false);
				}
			}
			if (!((NetworkBehaviour)_this).IsOwner)
			{
				if (_this.currentSearch.inProgress)
				{
					_this.StopSearch(_this.currentSearch, true);
				}
				_this.SetClientCalculatingAI(false);
				if (!_this.inSpecialAnimation)
				{
					Vector3 val2 = (Vector3)val.Field("tempVelocity").GetValue();
					((Component)_this).transform.position = Vector3.SmoothDamp(((Component)_this).transform.position, _this.serverPosition, ref val2, _this.syncMovementSpeed);
					((Component)_this).transform.eulerAngles = new Vector3(((Component)_this).transform.eulerAngles.x, Mathf.LerpAngle(((Component)_this).transform.eulerAngles.y, (float)val.Field("targetYRotation").GetValue(), 15f * Time.deltaTime), ((Component)_this).transform.eulerAngles.z);
					val.Field("tempVelocity").SetValue((object)val2);
				}
				_this.timeSinceSpawn += Time.deltaTime;
				return;
			}
			if (_this.isEnemyDead)
			{
				_this.SetClientCalculatingAI(false);
				return;
			}
			if (!_this.inSpecialAnimation)
			{
				_this.SetClientCalculatingAI(true);
			}
			if (_this.movingTowardsTargetPlayer && (Object)(object)_this.targetPlayer != (Object)null)
			{
				float num2 = (float)val.Field("setDestinationToPlayerInterval").GetValue();
				if (num2 <= 0f)
				{
					num2 = 0.25f;
					_this.destination = RoundManager.Instance.GetNavMeshPosition(((Component)_this.targetPlayer).transform.position, RoundManager.Instance.navHit, 2.7f, -1);
				}
				else
				{
					_this.destination = new Vector3(((Component)_this.targetPlayer).transform.position.x, _this.destination.y, ((Component)_this.targetPlayer).transform.position.z);
					num2 -= Time.deltaTime;
				}
				if (_this.addPlayerVelocityToDestination > 0f)
				{
					if ((Object)(object)_this.targetPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController)
					{
						_this.destination += Vector3.Normalize(_this.targetPlayer.thisController.velocity * 100f) * _this.addPlayerVelocityToDestination;
					}
					else if (_this.targetPlayer.timeSincePlayerMoving < 0.25f)
					{
						_this.destination += Vector3.Normalize((_this.targetPlayer.serverPlayerPosition - _this.targetPlayer.oldPlayerPosition) * 100f) * _this.addPlayerVelocityToDestination;
					}
				}
				val.Field("setDestinationToPlayerInterval").SetValue((object)num2);
			}
			if (_this.inSpecialAnimation)
			{
				return;
			}
			float num3 = (float)val.Field("updateDestinationInterval").GetValue();
			if (num3 >= 0f)
			{
				num3 -= Time.deltaTime;
			}
			else
			{
				_this.DoAIInterval();
				num3 = _this.AIIntervalTime;
			}
			float num4 = (float)val.Field("previousYRotation").GetValue();
			if (Mathf.Abs(num4 - ((Component)_this).transform.eulerAngles.y) > 6f)
			{
				val.Field("previousYRotation").SetValue((object)((Component)_this).transform.eulerAngles.y);
				val.Field("targetYRotation").SetValue((object)((Component)_this).transform.eulerAngles.y);
				if (((NetworkBehaviour)_this).IsServer)
				{
					AccessTools.Method(typeof(CrawlerAI), "UpdateEnemyRotationClientRpc", (Type[])null, (Type[])null).Invoke(_this, new object[1] { (short)num4 });
					return;
				}
				AccessTools.Method(typeof(CrawlerAI), "UpdateEnemyRotationServerRpc", (Type[])null, (Type[])null).Invoke(_this, new object[1] { (short)num4 });
			}
			val.Field("updateDestinationInterval").SetValue((object)num3);
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI))]
	public class HoarderBugAIPatch
	{
		private static bool GrabTargetItemIfClose(HoarderBugAI _this, SpawnAbilityInfo sInfo)
		{
			//IL_001d: 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_0055: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_this.targetItem != (Object)null && _this.heldItem == null && Vector3.Distance(((Component)_this).transform.position, ((Component)_this.targetItem).transform.position) < 1f)
			{
				_this.nestPosition = ((Component)sInfo.creatorPlayer).transform.position;
				if (!((EnemyAI)_this).SetDestinationToPosition(_this.nestPosition, true))
				{
					_this.nestPosition = ((EnemyAI)_this).ChooseClosestNodeToPosition(((Component)_this).transform.position, false, 0).position;
					((EnemyAI)_this).SetDestinationToPosition(_this.nestPosition, false);
				}
				Debugger.Debug.LogMessage($"FOUDN ITEM! '{_this.targetItem}' setting nest position to player...");
				NetworkObject component = ((Component)_this.targetItem).GetComponent<NetworkObject>();
				((EnemyAI)_this).SwitchToBehaviourStateOnLocalClient(1);
				AccessTools.Method(typeof(HoarderBugAI), "GrabItem", (Type[])null, (Type[])null).Invoke(_this, new object[1] { component });
				Traverse.Create((object)_this).Field("sendingGrabOrDropRPC").SetValue((object)true);
				_this.GrabItemServerRpc(NetworkObjectReference.op_Implicit(component));
				return true;
			}
			return false;
		}

		private static bool IsHoarderBugAngry(HoarderBugAI _this)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Invalid comparison between Unknown and I4
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Invalid comparison between Unknown and I4
			if (((EnemyAI)_this).stunNormalizedTimer > 0f)
			{
				_this.angryTimer = 4f;
				if (Object.op_Implicit((Object)(object)((EnemyAI)_this).stunnedByPlayer))
				{
					_this.angryAtPlayer = ((EnemyAI)_this).stunnedByPlayer;
				}
				return true;
			}
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < HoarderBugAI.HoarderBugItems.Count; i++)
			{
				if ((int)HoarderBugAI.HoarderBugItems[i].status == 1)
				{
					num2++;
				}
				else if ((int)HoarderBugAI.HoarderBugItems[i].status == 2)
				{
					num++;
				}
			}
			if (_this.angryTimer > 0f || num2 > 0)
			{
			}
			return _this.angryTimer > 0f || num2 > 0;
		}

		[HarmonyPatch("IsHoarderBugAngry")]
		[HarmonyPrefix]
		private static bool IsHoarderBugAngryPatch(ref HoarderBugAI __instance, ref bool __result)
		{
			__result = IsHoarderBugAngry(__instance);
			return false;
		}

		[HarmonyPatch("DoAIInterval")]
		[HarmonyPrefix]
		private static bool DoAIIntervalPatch(ref HoarderBugAI __instance)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0859: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_0750: Unknown result type (might be due to invalid IL or missing references)
			//IL_0770: Unknown result type (might be due to invalid IL or missing references)
			//IL_077c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_078a: Unknown result type (might be due to invalid IL or missing references)
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Unknown result type (might be due to invalid IL or missing references)
			if (Config.abilitiesEnabled.Value)
			{
				NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
				SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Component)networkObject).gameObject.GetComponent<SpawnAbilityInfo>() : null);
				Traverse val = Traverse.Create((object)__instance);
				if (Object.op_Implicit((Object)(object)spawnAbilityInfo))
				{
					if (((EnemyAI)__instance).moveTowardsDestination)
					{
						((EnemyAI)__instance).agent.SetDestination(((EnemyAI)__instance).destination);
					}
					((EnemyAI)__instance).SyncPositionToClients();
					if (((EnemyAI)__instance).isEnemyDead || StartOfRound.Instance.allPlayersDead)
					{
						return false;
					}
					if (!(bool)AccessTools.Field(typeof(HoarderBugAI), "choseNestPosition").GetValue(__instance))
					{
						AccessTools.Field(typeof(HoarderBugAI), "choseNestPosition").SetValue(__instance, true);
						AccessTools.Method(typeof(HoarderBugAI), "ChooseNestPosition", (Type[])null, (Type[])null).Invoke(__instance, Array.Empty<object>());
						return false;
					}
					if (((EnemyAI)__instance).CheckLineOfSightForPosition(__instance.nestPosition, 60f, 40, 0.5f, (Transform)null))
					{
						for (int i = 0; i < HoarderBugAI.HoarderBugItems.Count; i++)
						{
							if (HoarderBugAI.HoarderBugItems[i].itemGrabbableObject.isHeld && HoarderBugAI.HoarderBugItems[i].itemNestPosition == __instance.nestPosition)
							{
								HoarderBugAI.HoarderBugItems[i].status = (HoarderBugItemStatus)1;
							}
						}
					}
					HoarderBugItem val2 = __instance.CheckLineOfSightForItem((HoarderBugItemStatus)1, 60f, 30, 3f);
					if (val2 != null && !val2.itemGrabbableObject.isHeld)
					{
						val2.status = (HoarderBugItemStatus)2;
						if (!HoarderBugAI.grabbableObjectsInMap.Contains(((Component)val2.itemGrabbableObject).gameObject))
						{
							HoarderBugAI.grabbableObjectsInMap.Add(((Component)val2.itemGrabbableObject).gameObject);
						}
					}
					switch (((EnemyAI)__instance).currentBehaviourStateIndex)
					{
					case 0:
					{
						val.Field("inReturnToNestMode").SetValue((object)false);
						AccessTools.Method(typeof(HoarderBugAI), "ExitChaseMode", (Type[])null, (Type[])null).Invoke(__instance, null);
						if (GrabTargetItemIfClose(__instance, spawnAbilityInfo))
						{
							break;
						}
						if ((Object)(object)__instance.targetItem == (Object)null && !__instance.searchForItems.inProgress)
						{
							((EnemyAI)__instance).StartSearch(__instance.nestPosition, __instance.searchForItems);
							return false;
						}
						if ((Object)(object)__instance.targetItem != (Object)null)
						{
							Debugger.Debug.Log($"Found target item! {((Component)__instance.targetItem).gameObject}");
							AccessTools.Method(typeof(HoarderBugAI), "SetGoTowardsTargetObject", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { ((Component)__instance.targetItem).gameObject });
							return false;
						}
						GameObject val4 = ((EnemyAI)__instance).CheckLineOfSight(HoarderBugAI.grabbableObjectsInMap, 60f, 40, 5f, (Transform)null, (int[])null);
						if (Object.op_Implicit((Object)(object)val4))
						{
							GrabbableObject component = val4.GetComponent<GrabbableObject>();
							if (Object.op_Implicit((Object)(object)component) && (!component.isHeld || (Random.Range(0, 100) < 4 && !component.isPocketed)))
							{
								Debugger.Debug.Log($"Found target item! {val4}");
								AccessTools.Method(typeof(HoarderBugAI), "SetGoTowardsTargetObject", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { val4 });
								return false;
							}
						}
						break;
					}
					case 1:
						AccessTools.Method(typeof(HoarderBugAI), "ExitChaseMode", (Type[])null, (Type[])null).Invoke(__instance, null);
						if (!(bool)val.Field("inReturnToNestMode").GetValue())
						{
							val.Field("inReturnToNestMode").SetValue((object)true);
							AccessTools.Method(typeof(HoarderBugAI), "SetReturningToNest", (Type[])null, (Type[])null).Invoke(__instance, null);
							Debugger.Debug.Log(((Object)((Component)__instance).gameObject).name + ": Abandoned current search and returning to nest empty-handed");
						}
						GrabTargetItemIfClose(__instance, spawnAbilityInfo);
						if ((bool)val.Field("waitingAtNest").GetValue())
						{
							if (Vector3.Distance(((Component)__instance).transform.position, ((Component)spawnAbilityInfo.creatorPlayer).transform.position) > 2.2f)
							{
								Debugger.Debug.LogMessage("Master running away!");
								val.Field("waitingAtNest").SetValue((object)false);
								((EnemyAI)__instance).SwitchToBehaviourState(0);
								return false;
							}
							if (__instance.heldItem != null)
							{
								AccessTools.Method(typeof(HoarderBugAI), "DropItemAndCallDropRPC", (Type[])null, (Type[])null).Invoke(__instance, new object[2]
								{
									((Component)__instance.heldItem.itemGrabbableObject).GetComponent<NetworkObject>(),
									true
								});
							}
							else
							{
								GameObject val3 = ((EnemyAI)__instance).CheckLineOfSight(HoarderBugAI.grabbableObjectsInMap, 60f, 40, 5f, (Transform)null, (int[])null);
								if (Object.op_Implicit((Object)(object)val3) && Vector3.Distance(((EnemyAI)__instance).eye.position, val3.transform.position) < 6f)
								{
									__instance.targetItem = val3.GetComponent<GrabbableObject>();
									if ((Object)(object)__instance.targetItem != (Object)null && !__instance.targetItem.isHeld)
									{
										val.Field("waitingAtNest").SetValue((object)false);
										((EnemyAI)__instance).SwitchToBehaviourState(0);
										return false;
									}
								}
							}
							if ((float)val.Field("waitingAtNestTimer").GetValue() <= 0f)
							{
								if (!__instance.watchingPlayerNearPosition || (Object)(object)__instance.watchingPlayer == (Object)(object)spawnAbilityInfo.creatorPlayer)
								{
									Debugger.Debug.Log("Gave item! Will return to search");
									val.Field("waitingAtNest").SetValue((object)false);
									((EnemyAI)__instance).SwitchToBehaviourStateOnLocalClient(0);
								}
								return false;
							}
							return false;
						}
						if (Vector3.Distance(((Component)__instance).transform.position, ((EnemyAI)__instance).agent.destination) < 1.25f)
						{
							if (Vector3.Distance(((Component)__instance).transform.position, ((Component)spawnAbilityInfo.creatorPlayer).transform.position) < 1.25f)
							{
								val.Field("waitingAtNest").SetValue((object)true);
								val.Field("waitingAtNestTimer").SetValue((object)5f);
								return false;
							}
							__instance.nestPosition = ((Component)spawnAbilityInfo.creatorPlayer).transform.position;
							if (!((EnemyAI)__instance).SetDestinationToPosition(__instance.nestPosition, true))
							{
								__instance.nestPosition = ((EnemyAI)__instance).ChooseClosestNodeToPosition(((Component)__instance).transform.position, false, 0).position;
								((EnemyAI)__instance).SetDestinationToPosition(__instance.nestPosition, false);
							}
						}
						break;
					case 2:
						val.Field("inReturnToNestMode").SetValue((object)false);
						if (__instance.heldItem != null)
						{
							AccessTools.Method(typeof(HoarderBugAI), "DropItemAndCallDropRPC", (Type[])null, (Type[])null).Invoke(__instance, new object[2]
							{
								((Component)__instance.heldItem.itemGrabbableObject).GetComponent<NetworkObject>(),
								false
							});
						}
						if ((bool)val.Field("lostPlayerInChase").GetValue())
						{
							if (!__instance.searchForPlayer.inProgress)
							{
								__instance.searchForPlayer.searchWidth = 30f;
								((EnemyAI)__instance).StartSearch(((Component)((EnemyAI)__instance).targetPlayer).transform.position, __instance.searchForPlayer);
								Debugger.Debug.Log(((Object)((Component)__instance).gameObject).name + ": Lost player in chase; beginning search where the player was last seen");
								return false;
							}
							break;
						}
						if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
						{
							Debugger.Debug.LogError("TargetPlayer is null even though bug is in chase; setting targetPlayer to watchingPlayer");
							if ((Object)(object)__instance.watchingPlayer != (Object)null)
							{
								((EnemyAI)__instance).targetPlayer = __instance.watchingPlayer;
							}
						}
						if (__instance.searchForPlayer.inProgress)
						{
							((EnemyAI)__instance).StopSearch(__instance.searchForPlayer, true);
							Debugger.Debug.Log(((Object)((Component)__instance).gameObject).name + ": Found player during chase; stopping search coroutine and moving after target player");
						}
						((EnemyAI)__instance).movingTowardsTargetPlayer = true;
						break;
					default:
						return false;
					case 3:
						break;
					}
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("DetectAndLookAtPlayers")]
		[HarmonyPrefix]
		private static bool DetectAndLookAtPlayersPatch(ref HoarderBugAI __instance)
		{
			//IL_0078: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			if (!Config.abilitiesEnabled.Value)
			{
				return true;
			}
			NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
			SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Component)networkObject).gameObject.GetComponent<SpawnAbilityInfo>() : null);
			Traverse val = Traverse.Create((object)__instance);
			if (!Object.op_Implicit((Object)(object)spawnAbilityInfo))
			{
				return true;
			}
			Vector3 val2 = ((((EnemyAI)__instance).currentBehaviourStateIndex != 1) ? ((Component)__instance).transform.position : __instance.nestPosition);
			PlayerControllerB[] allPlayersInLineOfSight = ((EnemyAI)__instance).GetAllPlayersInLineOfSight(70f, 30, ((EnemyAI)__instance).eye, 1.2f, -1);
			if (allPlayersInLineOfSight != null)
			{
				PlayerControllerB watchingPlayer = __instance.watchingPlayer;
				Traverse.Create((object)__instance).Field("timeSinceSeeingAPlayer").SetValue((object)0f);
				float num = 500f;
				bool flag = false;
				if ((Object)(object)((EnemyAI)__instance).stunnedByPlayer != (Object)null && (Object)(object)((EnemyAI)__instance).stunnedByPlayer != (Object)(object)spawnAbilityInfo.creatorPlayer)
				{
					flag = true;
					__instance.angryAtPlayer = ((EnemyAI)__instance).stunnedByPlayer;
				}
				for (int i = 0; i < allPlayersInLineOfSight.Length; i++)
				{
					bool flag2 = spawnAbilityInfo.otherFriendlies.Contains(allPlayersInLineOfSight[i]) || (Object)(object)spawnAbilityInfo.creatorPlayer == (Object)(object)allPlayersInLineOfSight[i];
					if (!flag && (Object)(object)allPlayersInLineOfSight[i].currentlyHeldObjectServer != (Object)null)
					{
						HoarderBugItem[] array = HoarderBugAI.HoarderBugItems.ToArray();
						foreach (HoarderBugItem val3 in array)
						{
							if ((Object)(object)val3.itemGrabbableObject == (Object)(object)allPlayersInLineOfSight[i].currentlyHeldObjectServer)
							{
								if (!flag2)
								{
									Debugger.Debug.LogWarning("Bug angy because you stol his stuff!");
									val3.status = (HoarderBugItemStatus)1;
									__instance.angryAtPlayer = allPlayersInLineOfSight[i];
									flag = true;
								}
								else
								{
									((EnemyAI)__instance).SwitchToBehaviourState(0);
									HoarderBugAI.HoarderBugItems.Remove(val3);
								}
							}
						}
					}
					if (IsHoarderBugAngry(__instance) && (Object)(object)allPlayersInLineOfSight[i] == (Object)(object)__instance.angryAtPlayer)
					{
						__instance.watchingPlayer = __instance.angryAtPlayer;
					}
					else
					{
						float num2 = Vector3.Distance(((Component)allPlayersInLineOfSight[i]).transform.position, val2);
						if (num2 < num)
						{
							num = num2;
							__instance.watchingPlayer = allPlayersInLineOfSight[i];
						}
					}
					float num3 = Vector3.Distance(((Component)allPlayersInLineOfSight[i]).transform.position, __instance.nestPosition);
					if (HoarderBugAI.HoarderBugItems.Count > 0)
					{
						if ((num3 < 4f || ((bool)Traverse.Create((object)__instance).Field("inChase").GetValue() && num3 < 8f)) && __instance.angryTimer < 3.25f)
						{
							if (!flag2)
							{
								Debugger.Debug.LogWarning("Bug angy because you close to nest!");
								__instance.angryAtPlayer = allPlayersInLineOfSight[i];
								__instance.watchingPlayer = allPlayersInLineOfSight[i];
								__instance.angryTimer = 3.25f;
								break;
							}
							if (Vector3.Distance(((Component)__instance).transform.position, ((Component)spawnAbilityInfo.creatorPlayer).transform.position) <= 1.25f && __instance.heldItem != null)
							{
								AccessTools.Method(typeof(HoarderBugAI), "DropItemAndCallDropRPC", (Type[])null, (Type[])null).Invoke(__instance, new object[2]
								{
									((Component)__instance.heldItem.itemGrabbableObject).GetComponent<NetworkObject>(),
									true
								});
								val.Field("waitingAtNest").SetValue((object)true);
								val.Field("waitingAtNestTimer").SetValue((object)5f);
							}
							float num4 = Vector3.Distance(((Component)HoarderBugAI.HoarderBugItems[0].itemGrabbableObject).transform.position, ((Component)spawnAbilityInfo.creatorPlayer).transform.position);
							if (__instance.heldItem == null && num4 > 5f)
							{
								((EnemyAI)__instance).SetDestinationToPosition(((Component)HoarderBugAI.HoarderBugItems[0].itemGrabbableObject).transform.position, false);
								__instance.targetItem = HoarderBugAI.HoarderBugItems[0].itemGrabbableObject;
							}
						}
						if (!(bool)Traverse.Create((object)__instance).Field("isAngry").GetValue() && ((EnemyAI)__instance).currentBehaviourStateIndex == 0 && num3 < 8f && ((Object)(object)__instance.targetItem == (Object)null || Vector3.Distance(((Component)__instance.targetItem).transform.position, ((Component)__instance).transform.position) > 7.5f) && ((NetworkBehaviour)__instance).IsOwner)
						{
							Debugger.Debug.Log("Switching state to 1, Guarding Items!");
							((EnemyAI)__instance).SwitchToBehaviourState(1);
						}
					}
					if (((EnemyAI)__instance).currentBehaviourStateIndex != 2 && Vector3.Distance(((Component)__instance).transform.position, ((Component)allPlayersInLineOfSight[i]).transform.position) < 2.5f && !flag2)
					{
						Debugger.Debug.LogWarning("Bug angy because you touch him!");
						float num5 = (float)Traverse.Create((object)__instance).Field("annoyanceMeter").GetValue();
						num5 += 0.2f;
						if (num5 > 2.5f)
						{
							__instance.angryAtPlayer = allPlayersInLineOfSight[i];
							__instance.watchingPlayer = allPlayersInLineOfSight[i];
							__instance.angryTimer = 3.25f;
						}
						Traverse.Create((object)__instance).Field("annoyanceMeter").SetValue((object)num5);
					}
				}
				__instance.watchingPlayerNearPosition = num < 6f;
				if ((Object)(object)__instance.watchingPlayer != (Object)(object)watchingPlayer)
				{
					RoundManager.PlayRandomClip(((EnemyAI)__instance).creatureVoice, __instance.chitterSFX, true, 1f, 0, 1000);
				}
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					return false;
				}
				bool flag3 = (bool)Traverse.Create((object)__instance).Field("lostPlayerInChase").GetValue();
				if (((EnemyAI)__instance).currentBehaviourStateIndex != 2)
				{
					if (IsHoarderBugAngry(__instance))
					{
						flag3 = false;
						((EnemyAI)__instance).targetPlayer = __instance.watchingPlayer;
						((EnemyAI)__instance).SwitchToBehaviourState(2);
						return false;
					}
				}
				else
				{
					((EnemyAI)__instance).targetPlayer = __instance.watchingPlayer;
					if (flag3)
					{
						flag3 = false;
						return false;
					}
				}
				Traverse.Create((object)__instance).Field("lostPlayerInChase").SetValue((object)flag3);
			}
			else
			{
				float num6 = (float)Traverse.Create((object)__instance).Field("timeSinceSeeingAPlayer").GetValue();
				num6 += 0.2f;
				Traverse.Create((object)__instance).Field("timeSinceSeeingAPlayer").SetValue((object)num6);
				__instance.watchingPlayerNearPosition = false;
				if (((EnemyAI)__instance).currentBehaviourStateIndex != 2)
				{
					if (num6 > 1.5f)
					{
						__instance.watchingPlayer = null;
						return false;
					}
				}
				else
				{
					if (num6 > 1.25f)
					{
						__instance.watchingPlayer = null;
					}
					if (!((NetworkBehaviour)__instance).IsOwner)
					{
						return false;
					}
					if (num6 > 15f)
					{
						((EnemyAI)__instance).SwitchToBehaviourState(1);
						return false;
					}
					if (num6 > 2.5f)
					{
						Traverse.Create((object)__instance).Field("lostPlayerInChase").SetValue((object)true);
					}
				}
			}
			return false;
		}

		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool OnCollideWithPlayerPatch(ref HoarderBugAI __instance, Collider other)
		{
			if (!Config.abilitiesEnabled.Value)
			{
				return true;
			}
			NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject;
			SpawnAbilityInfo spawnAbilityInfo = ((networkObject != null) ? ((Componen