Decompiled source of ghostCodes v2.5.1

ghostCodes.dll

Decompiled 3 weeks 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.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using Microsoft.CodeAnalysis;
using OpenLib;
using OpenLib.Common;
using OpenLib.Compat;
using OpenLib.ConfigManager;
using OpenLib.CoreMethods;
using OpenLib.Events;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using com.github.zehsteam.ToilHead.MonoBehaviours;
using ghostCodes.Compatibility;
using ghostCodes.Configs;
using ghostCodes.Interactions;
using ghostCodes.NetcodePatcher;
using ghostCodes.Patches;
using ghostCodes.PluginStuff;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ghostcodes")]
[assembly: AssemblyDescription("https://github.com/darmuh/ghostcodes")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ghostcodes")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d54996ea-9c7b-47cf-b5cb-fdfe2c657f71")]
[assembly: AssemblyFileVersion("2.5.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.5.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace ghostCodes
{
	internal class Blastdoors
	{
		internal static void HandleHungryDoor(int randomObjectNum, StartOfRound instance)
		{
			if (CodeStuff.myTerminalObjects.Count != 0)
			{
				if (((Object)((Component)CodeStuff.myTerminalObjects[randomObjectNum]).gameObject).name.Contains("BigDoor"))
				{
					Plugin.MoreLogs("The door is hungy");
					((MonoBehaviour)instance).StartCoroutine(HungryDoor(randomObjectNum));
				}
				else
				{
					CodeStuff.myTerminalObjects[randomObjectNum].CallFunctionFromTerminal();
				}
			}
		}

		private static IEnumerator HungryDoor(int randomObjectNum)
		{
			float intervalTime = Random.Range(0.2f, 0.7f);
			int numBites = Random.Range(3, 9);
			if (((Object)((Component)CodeStuff.myTerminalObjects[randomObjectNum]).gameObject).name.Contains("BigDoor"))
			{
				int j;
				for (j = 0; j < numBites; j++)
				{
					CodeStuff.myTerminalObjects[randomObjectNum].CallFunctionFromTerminal();
					yield return (object)new WaitForSeconds(intervalTime);
					j++;
				}
			}
		}
	}
	internal class Teleporters
	{
		internal static void InteractWithAnyTP(int tpNum)
		{
			if (tpNum == 0 && (Object)(object)Teleporter.NormalTP != (Object)null)
			{
				Plugin.MoreLogs("Messing with NormalTP");
				Teleporter.NormalTP.PressTeleportButtonServerRpc();
				Plugin.MoreLogs("NormalTP button pressed via ServerRpc");
			}
			else if (tpNum == 1 && (Object)(object)Teleporter.InverseTP != (Object)null)
			{
				Plugin.MoreLogs("Messing with InverseTP");
				Teleporter.InverseTP.PressTeleportButtonServerRpc();
				Plugin.MoreLogs("InverseTP button pressed via ServerRpc");
			}
		}
	}
	internal class TerminalAdditions
	{
		internal static TerminalNode rebootNode;

		internal static bool rebootCommandExpired = false;

		internal static int rebootCount;

		internal static int rebootTime;

		internal static int deathNoteStrikes = 0;

		public static bool isTerminalRebooting = false;

		internal static bool spookyColors = false;

		internal static bool credsCorrupted = false;

		internal static int OriginalCreds = 0;

		internal static Color OriginalColor;

		internal static string rebootConfirmName = "ghostCodes_confirm_reboot";

		internal static string rebootDenyName = "ghostCodes_deny_reboot";

		internal static AudioClip Shock;

		internal static AudioClip Reboot;

		internal static AudioClip Success;

		internal static void ResetBools()
		{
			isTerminalRebooting = false;
			rebootCommandExpired = false;
			spookyColors = false;
			rebootCount = 0;
			deathNoteStrikes = 0;
		}

		internal static IEnumerator RebootTerminalSpooky()
		{
			if (isTerminalRebooting)
			{
				yield break;
			}
			Plugin.MoreLogs("Start of spooky terminal reboot coroutine.");
			SoundSystem.PlayTerminalSound(Reboot);
			yield return (object)new WaitForSeconds(1f);
			SetTerminalText(StringStuff.reboot_3);
			yield return (object)new WaitForSeconds(1f);
			SetTerminalText(StringStuff.reboot_2);
			yield return (object)new WaitForSeconds(1f);
			SetTerminalText(StringStuff.reboot_1);
			Plugin.instance.Terminal.QuitTerminal(true);
			yield return (object)new WaitForEndOfFrame();
			IsTerminalUsable(state: false);
			float originalAlpha = ((TMP_Text)Plugin.instance.Terminal.topRightText).alpha;
			((TMP_Text)Plugin.instance.Terminal.topRightText).alpha = 0f;
			((Component)Plugin.instance.Terminal.terminalUIScreen).gameObject.SetActive(true);
			Plugin.instance.Terminal.screenText.caretPosition = Plugin.instance.Terminal.screenText.text.Length;
			Bools.endAllCodes = true;
			isTerminalRebooting = true;
			yield return (object)new WaitForSeconds(1f);
			SetTerminalText(StringStuff.reboot_progress_1);
			((MonoBehaviour)StartOfRound.Instance).StartCoroutine(RebootLoadingTextLoop());
			yield return (object)new WaitForSeconds((float)rebootTime);
			isTerminalRebooting = false;
			DressGirl.StopGirlFromChasing();
			Bools.endAllCodes = false;
			((TMP_Text)Plugin.instance.Terminal.topRightText).alpha = originalAlpha;
			Plugin.instance.Terminal.terminalAudio.Stop();
			SoundSystem.PlayTerminalSound(Success);
			SetTerminalText("\n\n\n\n\n\n\n\n\n\t\t>>Reboot <color=#ebe334>Complete.</color><<\n\n\n\n");
			IsTerminalUsable(state: true);
			InitPlugin.RestartPlugin();
			if (InteractionsConfig.TerminalRebootUses.Value > 0)
			{
				if (rebootCount >= InteractionsConfig.TerminalRebootUses.Value)
				{
					rebootCommandExpired = true;
				}
				else
				{
					rebootCount++;
				}
			}
		}

		internal static IEnumerator RebootLoadingTextLoop()
		{
			while (isTerminalRebooting)
			{
				int @int = NumberStuff.GetInt(0, StringStuff.rebootProgress.Count);
				SetTerminalText("<color=#b81b1b>" + StringStuff.rebootProgress[@int] + "</color>");
				yield return (object)new WaitForSeconds(0.1f);
			}
		}

		internal static void SetTerminalText(string newText)
		{
			Plugin.instance.Terminal.currentText = newText;
			Plugin.instance.Terminal.screenText.text = newText;
		}

		internal static void IsTerminalUsable(bool state)
		{
			Plugin.instance.Terminal.terminalTrigger.interactable = state;
			Plugin.MoreLogs($"terminal interactable set to {state}");
		}

		internal static string PlayerNameNode()
		{
			if ((Object)(object)Plugin.instance.DressGirl == (Object)null)
			{
				Plugin.instance.Terminal.LoadNewNode(Plugin.instance.Terminal.terminalNodes.specialNodes[5]);
				return "";
			}
			if (!Plugin.instance.DressGirl.hauntingLocalPlayer)
			{
				Plugin.instance.Terminal.LoadNewNode(Plugin.instance.Terminal.terminalNodes.specialNodes[5]);
				return "";
			}
			Plugin.MoreLogs("handling player name node");
			if (InteractionsConfig.DeathNoteMaxStrikes.Value != -1 && deathNoteStrikes > InteractionsConfig.DeathNoteMaxStrikes.Value)
			{
				return "\n\n\n\n\n\n\t\tDeath note is out of space...\r\n";
			}
			string cleanedScreenText = CommonStringStuff.GetCleanedScreenText(Plugin.instance.Terminal);
			cleanedScreenText = StringStuff.TerminalFriendlyString(cleanedScreenText);
			return ValidPlayerNameInput(cleanedScreenText);
		}

		internal static string HandleRebootNode()
		{
			Plugin.MoreLogs("Handling reboot node");
			if (StartOfRound.Instance.inShipPhase)
			{
				return "\n\n\n\n\n\n\t\tTerminal reboot is not necessary... (in orbit)\r\n";
			}
			int @int = NumberStuff.GetInt(0, 100);
			if (InteractionsConfig.TerminalReboot.Value < @int || rebootCommandExpired)
			{
				string result = "\n\n\n\n\n\n\t\tTerminal reboot has failed...\r\n";
				rebootCommandExpired = true;
				return result;
			}
			((MonoBehaviour)StartOfRound.Instance).StartCoroutine(RebootTerminalSpooky());
			Plugin.MoreLogs("rebooting terminal");
			return "";
		}

		internal static string AskTerminalReboot()
		{
			rebootTime = NumberStuff.GetInt(30, 88);
			return $"You have requested to reboot the terminal.\nTotal time to reboot is {rebootTime} seconds...\n\nPlease CONFIRM or DENY.\n\n";
		}

		internal static void CreateAllNodes()
		{
			if (ModConfig.ModNetworking.Value)
			{
				CreateRebootNode();
				CreatePlayerNameNodes();
			}
		}

		private static void CreateRebootNode()
		{
			if (InteractionsConfig.TerminalReboot.Value >= 1)
			{
				rebootNode = AddingThings.AddNodeManual("ghostCodes_reboot", "reboot", (Func<string>)AskTerminalReboot, true, 1, ConfigSetup.defaultListing, 0, (Func<string>)HandleRebootNode, (Func<string>)null, "", "Terminal Reboot has been cancelled.\r\n\r\n", false, 1, "", false, "");
			}
		}

		private static void CreatePlayerNameNodes()
		{
			if (InteractionsConfig.DeathNote.Value < 1)
			{
				return;
			}
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if ((Object)(object)val != (Object)(object)StartOfRound.Instance.localPlayerController && val.isPlayerControlled)
				{
					string playerUsername = val.playerUsername;
					playerUsername = StringStuff.TerminalFriendlyString(playerUsername);
					AddingThings.AddNodeManual("ghostCodes_haunt_" + playerUsername, playerUsername, (Func<string>)PlayerNameNode, true, 0, ConfigSetup.defaultListing, 0, (Func<string>)null, (Func<string>)null, "", "", false, 1, "", true, "");
					Plugin.MoreLogs("Command created for haunting " + playerUsername);
				}
				else
				{
					Plugin.MoreLogs("skipping self and non-player controlled players");
				}
			}
		}

		private static void DeathNoteFail()
		{
			if (InteractionsConfig.DeathNoteFailChase.boolValue && !((Object)(object)Plugin.instance.DressGirl == (Object)null))
			{
				Plugin.MoreLogs("death note failed, beginning ghost girl chase");
				Plugin.instance.DressGirl.BeginChasing();
			}
		}

		private static string ValidPlayerNameInput(string s)
		{
			int @int = NumberStuff.GetInt(0, 100);
			PlayerControllerB val = default(PlayerControllerB);
			if (Misc.TryGetPlayerFromName(s, ref val))
			{
				if (InteractionsConfig.DeathNote.Value < @int)
				{
					string result = "\n\n\n\n\n\n<color=#b81b1b>You're not getting rid of me that easy! :3</color>\n\n";
					deathNoteStrikes++;
					DeathNoteFail();
					return result;
				}
				if (val.isPlayerControlled && !val.isPlayerDead)
				{
					string result2 = "\n\n\n\n\n\n<color=#b81b1b>Okay! I'll go play with " + s + " now! :3</color>\n\n";
					DressGirl.EndAllGirlStuff();
					NetHandler.Instance.ChangeDressGirlToPlayerServerRpc(s);
					deathNoteStrikes++;
					Plugin.MoreLogs("You should not be haunted anymore.");
					return result2;
				}
				string result3 = "\n\n\n\n\n\n<color=#b81b1b>I think i'll keep having fun with you! :3</color>\n\n";
				deathNoteStrikes++;
				Plugin.MoreLogs("picked player is likely dead, this is an else statement");
				DeathNoteFail();
				return result3;
			}
			string result4 = "\n\n\n\n\n\n<color=#b81b1b>I don't know anyone by that name! Guess you're stuck with me ^.^</color>\n\n";
			deathNoteStrikes++;
			DeathNoteFail();
			return result4;
		}

		internal static void CorruptedCredits(bool state)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (state)
			{
				Plugin.Spam("Credits corrupted!");
				OriginalCreds = Plugin.instance.Terminal.groupCredits;
				OriginalColor = ((Graphic)Plugin.instance.Terminal.topRightText).color;
				Plugin.instance.Terminal.SyncGroupCreditsServerRpc(0, Plugin.instance.Terminal.numberOfItemsInDropship);
				((Graphic)Plugin.instance.Terminal.topRightText).color = Color.red;
				credsCorrupted = true;
			}
			else
			{
				Plugin.Spam("Credits restored!");
				Plugin.instance.Terminal.SyncGroupCreditsServerRpc(OriginalCreds, Plugin.instance.Terminal.numberOfItemsInDropship);
				((Graphic)Plugin.instance.Terminal.topRightText).color = OriginalColor;
				credsCorrupted = false;
			}
		}

		internal static void RestoreCreds()
		{
			if (credsCorrupted)
			{
				CorruptedCredits(state: false);
			}
		}
	}
	internal class Bools
	{
		internal static bool lightsFlickering;

		internal static bool appPullInvoked;

		public static bool endAllCodes;

		internal static bool IsCodeSent()
		{
			return Plugin.instance.CodeSent;
		}

		internal static bool IsInsideFactory()
		{
			return StartOfRound.Instance.localPlayerController.isInsideFactory;
		}

		internal static bool IsHourInRange(int hour, int startHour, int endHour)
		{
			if (hour > startHour)
			{
				return hour <= endHour;
			}
			return false;
		}

		internal static bool ShouldRunCodeLooper()
		{
			if (SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings")
			{
				return true;
			}
			if (!ModConfig.ModNetworking.Value)
			{
				return true;
			}
			if ((Object)(object)Plugin.instance.Terminal == (Object)null)
			{
				Plugin.MoreLogs("Terminal instance null");
				return false;
			}
			return false;
		}

		internal static bool ShouldInitPlugin()
		{
			if ((Object)(object)Plugin.instance.Terminal == (Object)null)
			{
				Plugin.MoreLogs("Terminal instance null");
				return false;
			}
			return true;
		}

		public static bool GhostCodesShouldNotBePresentEver()
		{
			if (((Object)StartOfRound.Instance.currentLevel).name == "CompanyBuildingLevel" || StartOfRound.Instance.currentLevel.riskLevel == "Safe")
			{
				return true;
			}
			if (StartOfRound.Instance.inShipPhase)
			{
				return true;
			}
			if (Plugin.instance.CodeCount > Plugin.instance.RandCodeAmount)
			{
				return true;
			}
			return false;
		}

		public static bool CanSendCodes()
		{
			if (endAllCodes || GhostCodesShouldNotBePresentEver())
			{
				return false;
			}
			if (SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings")
			{
				return GameNetworkManager.Instance.gameHasStarted;
			}
			if ((Object)(object)Plugin.instance.DressGirl == (Object)null)
			{
				Plugin.MoreLogs("dressgirl instance is null");
				return false;
			}
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				return Plugin.instance.DressGirl.hauntingLocalPlayer == Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController);
			}
			return false;
		}

		internal static bool KeepSendingCodes()
		{
			if (endAllCodes || GhostCodesShouldNotBePresentEver())
			{
				return false;
			}
			if (StartOfRound.Instance.shipIsLeaving || StartOfRound.Instance.allPlayersDead)
			{
				return false;
			}
			if (SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings")
			{
				return true;
			}
			if ((Object)(object)Plugin.instance.DressGirl == (Object)null)
			{
				return false;
			}
			if (!Plugin.instance.DressGirl.hauntingLocalPlayer)
			{
				return false;
			}
			if (Plugin.instance.DressGirl.hauntingPlayer.isPlayerDead)
			{
				return false;
			}
			if (Coroutines.rapidFireStart && !DressGirl.girlIsChasing)
			{
				return false;
			}
			return true;
		}

		internal static bool DressGirlStartCodes()
		{
			if (endAllCodes || RapidFire.startRapidFire || GhostCodesShouldNotBePresentEver())
			{
				return false;
			}
			if (StartOfRound.Instance.shipIsLeaving || StartOfRound.Instance.allPlayersDead)
			{
				return false;
			}
			if (!Plugin.instance.DressGirl.staringInHaunt || Plugin.instance.DressGirl.hauntingPlayer.isPlayerDead)
			{
				return false;
			}
			return true;
		}

		internal static bool IsThisaBigDoor(int randomObjectNum)
		{
			if (randomObjectNum < 0)
			{
				return false;
			}
			if (CodeStuff.myTerminalObjects.Count == 0)
			{
				return false;
			}
			if ((Object)(object)CodeStuff.myTerminalObjects[randomObjectNum] == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)CodeStuff.myTerminalObjects[randomObjectNum]).gameObject == (Object)null)
			{
				return false;
			}
			if (((Object)((Component)CodeStuff.myTerminalObjects[randomObjectNum]).gameObject).name.Contains("BigDoor"))
			{
				return true;
			}
			return false;
		}

		internal static bool AreEnoughPlayersDancing(int totalPlayers, int playersDancing, int requiredPercentage)
		{
			if (playersDancing > totalPlayers * (requiredPercentage / 100))
			{
				return true;
			}
			return false;
		}

		internal static bool IsThisEffective(int percentChance)
		{
			int @int = NumberStuff.GetInt(0, 100);
			if (percentChance > @int)
			{
				return true;
			}
			return false;
		}

		internal static bool CheckForPlayerName(string playerName)
		{
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if (playerName.Contains(val.playerUsername))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool AreAnyPlayersInShip()
		{
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if (!val.isPlayerDead && val.isInHangarShipRoom)
				{
					return true;
				}
			}
			Plugin.MoreLogs("No players detected in ship");
			return false;
		}

		internal static bool AreAnyPlayersInFacility()
		{
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if (!val.isPlayerDead && val.isInsideFactory)
				{
					return true;
				}
			}
			Plugin.MoreLogs("No players detected in facility");
			return false;
		}

		internal static bool IsAnyPlayerUsingTerminal(out PlayerControllerB terminalUser)
		{
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if (!val.isPlayerDead && val.inTerminalMenu)
				{
					terminalUser = val;
					return true;
				}
			}
			terminalUser = null;
			return false;
		}
	}
	internal class CodeActions
	{
		internal static Random Rand = new Random();

		internal static void InitPossibleActions(StartOfRound instance, int randomObjectNum = -1)
		{
			CodeHandling.possibleActions.Clear();
			NetworkingRequiredActions();
			ExternalModCheck();
			CruiserStuff();
			ShipStuff();
			GhostGirlRequired();
			AddRegularDoorStuff();
			Maininteractions();
			if (randomObjectNum >= 0)
			{
				TerminalObjectActions(instance, randomObjectNum);
			}
		}

		private static void Maininteractions()
		{
			if (InteractionsConfig.AffectAllBatteries.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("AffectAllBatteries", delegate
				{
					Items.AdjustAllPlayersBattery();
				}, InteractionsConfig.AffectAllBatteries.Value));
			}
			if (InteractionsConfig.AffectRandomPlayerBatteries.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("AffectRandomPlayerBatteries", delegate
				{
					Items.AffectRandomPlayersBatterys();
				}, InteractionsConfig.AffectRandomPlayerBatteries.Value));
			}
			if (InteractionsConfig.HauntFactoryScrap.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("HauntFactoryScrap", delegate
				{
					Items.HauntItemUse(isHeld: false);
				}, InteractionsConfig.HauntFactoryScrap.Value));
			}
			if (InteractionsConfig.HauntHeldScrap.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("HauntHeldScrap", delegate
				{
					Items.HauntItemUse(isHeld: true);
				}, InteractionsConfig.HauntHeldScrap.Value));
			}
			if (InteractionsConfig.SignalTranslator.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("SignalTranslator", delegate
				{
					SignalTranslator.MessWithSignalTranslator();
				}, InteractionsConfig.SignalTranslator.Value));
			}
		}

		private static void MessWithWalkies()
		{
			if (WalkieTalkie.allWalkieTalkies.Count == 0 || !SetupConfig.GhostCodesSettings.HauntingsMode)
			{
				return;
			}
			Plugin.Spam("Adding enabled walkie stuff");
			if (InteractionsConfig.GarbleWalkies.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("GarbleWalkies", delegate
				{
					NetHandler.Instance.GarbleWalkiesServerRpc();
				}, InteractionsConfig.GarbleWalkies.Value));
			}
			if (InteractionsConfig.BreatheOnWalkies.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("BreatheOnWalkies", delegate
				{
					NetHandler.Instance.BreatheOnWalkiesServerRpc();
				}, InteractionsConfig.BreatheOnWalkies.Value));
			}
		}

		private static void GhostGirlRequired()
		{
			if (!SetupConfig.GhostCodesSettings.HauntingsMode)
			{
				return;
			}
			if (InteractionsConfig.PlayerLights.Value > 0 && !RapidFire.startRapidFire)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ggFlashlight", delegate
				{
					Lights.GGFlashlight();
				}, InteractionsConfig.PlayerLights.Value));
			}
			if (InteractionsConfig.AffectHauntedPlayerBatteries.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("AffectHauntedPlayerBatteries", delegate
				{
					Items.AffectHauntedPlayersBatterys();
				}, InteractionsConfig.AffectHauntedPlayerBatteries.Value));
			}
			MessWithWalkies();
		}

		private static void ShipStuff()
		{
			if (!Bools.AreAnyPlayersInShip())
			{
				return;
			}
			Plugin.Spam("players detected on ship");
			if (InteractionsConfig.LightsOnShip.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("MessWithShipLights", delegate
				{
					ghostCodes.ShipStuff.MessWithShipLights();
				}, InteractionsConfig.LightsOnShip.Value));
			}
			if (InteractionsConfig.DoorsOnShip.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("MessWithShipDoors", delegate
				{
					ghostCodes.ShipStuff.MessWithShipDoors();
				}, InteractionsConfig.DoorsOnShip.Value));
			}
			if (ModConfig.ModNetworking.Value && InteractionsConfig.ShockTerminalUser.Value > 0 && Bools.IsAnyPlayerUsingTerminal(out var terminalUser))
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("Shock Terminal User", delegate
				{
					ghostCodes.ShipStuff.ShockTerminal();
				}, InteractionsConfig.ShockTerminalUser.Value));
				Plugin.MoreLogs(terminalUser.playerUsername + " detected using terminal");
			}
			if (InteractionsConfig.MonitorsOnShip.Value > 0 && ModConfig.ModNetworking.Value)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("MessWithMonitors", delegate
				{
					NetHandler.Instance.MessWithMonitorsServerRpc();
				}, InteractionsConfig.MonitorsOnShip.Value));
			}
			if (InteractionsConfig.TeleportPlayer.Value > 0 && (Object)(object)Teleporter.NormalTP != (Object)null)
			{
				Plugin.MoreLogs("Added MessWithNormalTP");
				CodeHandling.possibleActions.Add(new ActionPercentage("MessWithNormalTP", delegate
				{
					Teleporters.InteractWithAnyTP(0);
				}, InteractionsConfig.TeleportPlayer.Value));
			}
			if (InteractionsConfig.InverseTeleporter.Value > 0 && (Object)(object)Teleporter.InverseTP != (Object)null)
			{
				Plugin.MoreLogs("Added MessWithInverseTP");
				CodeHandling.possibleActions.Add(new ActionPercentage("MessWithInverseTP", delegate
				{
					Teleporters.InteractWithAnyTP(1);
				}, InteractionsConfig.InverseTeleporter.Value));
			}
			if (InteractionsConfig.CorruptedCredits.Value > 0 && !TerminalAdditions.credsCorrupted)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CorruptedCredits", delegate
				{
					TerminalAdditions.CorruptedCredits(state: true);
				}, InteractionsConfig.CorruptedCredits.Value));
			}
			if (InteractionsConfig.HeavyLever.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("HeavyLever", delegate
				{
					ghostCodes.ShipStuff.HeavyLeverFunc();
				}, InteractionsConfig.HeavyLever.Value));
			}
			if (InteractionsConfig.HauntedOrder.Value > 0 && Plugin.instance.Terminal.orderedItemsFromTerminal.Count == 0 && Plugin.instance.Terminal.numberOfItemsInDropship == 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("HauntedOrder", delegate
				{
					ghostCodes.ShipStuff.HauntedOrderFunc();
				}, InteractionsConfig.HauntedOrder.Value));
			}
		}

		private static void AddRegularDoorStuff()
		{
			if (!Bools.AreAnyPlayersInFacility())
			{
				return;
			}
			if (InteractionsConfig.ToggleAllRegularDoors.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ToggleAllRegularDoors", delegate
				{
					Doors.OpenOrCloseALLDoors();
				}, InteractionsConfig.ToggleAllRegularDoors.Value));
			}
			if (InteractionsConfig.ToggleRegularDoor.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ToggleRegularDoor", delegate
				{
					Doors.OpenorClose1RandomDoor();
				}, InteractionsConfig.ToggleRegularDoor.Value));
			}
			if (InteractionsConfig.LockSingleDoor.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("LockONEdoor", delegate
				{
					Doors.LockorUnlockARandomDoor(stateLocked: true);
				}, InteractionsConfig.LockSingleDoor.Value));
			}
			if (InteractionsConfig.UnlockSingleDoor.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("UnlockONEdoor", delegate
				{
					Doors.LockorUnlockARandomDoor(stateLocked: false);
				}, InteractionsConfig.UnlockSingleDoor.Value));
			}
			if (InteractionsConfig.TryHauntSingleDoor.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("TryHauntSingleDoor", delegate
				{
					Doors.HauntDoors(0);
				}, InteractionsConfig.TryHauntSingleDoor.Value));
			}
			if (InteractionsConfig.TryHauntHalfAllDoors.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("TryHauntHalfAllDoors", delegate
				{
					Doors.HauntDoors(50);
				}, InteractionsConfig.TryHauntHalfAllDoors.Value));
			}
			if (InteractionsConfig.TryHauntAllDoors.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("TryHauntAllDoors", delegate
				{
					Doors.HauntDoors(100);
				}, InteractionsConfig.TryHauntAllDoors.Value));
			}
		}

		private static void CruiserStuff()
		{
			if ((Object)(object)Plugin.instance.Cruiser == (Object)null || !Plugin.instance.Cruiser.ignitionStarted)
			{
				return;
			}
			Plugin.MoreLogs("Adding cruiser interactions!!");
			if (InteractionsConfig.ChangeCruiserRadio.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ChangeCruiserRadio", delegate
				{
					Plugin.instance.Cruiser.ChangeRadioStation();
				}, InteractionsConfig.ChangeCruiserRadio.Value));
			}
			if (InteractionsConfig.CruiserEjectDriver.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserEjectDriver", delegate
				{
					Plugin.instance.Cruiser.SpringDriverSeatServerRpc();
				}, InteractionsConfig.CruiserEjectDriver.Value));
			}
			if (InteractionsConfig.CruiserUseBoost.Value > 0 && ((NetworkBehaviour)Plugin.instance.Cruiser).IsOwner)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserUseBoost", delegate
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					Plugin.instance.Cruiser.UseTurboBoostLocalClient(default(Vector2));
				}, InteractionsConfig.CruiserUseBoost.Value));
			}
			if (InteractionsConfig.CruiserPush.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserPush", delegate
				{
					Cruiser.Push();
				}, InteractionsConfig.CruiserPush.Value));
			}
			if (InteractionsConfig.ToggleCruiserDoors.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserDoors", delegate
				{
					Cruiser.Doors();
				}, InteractionsConfig.ToggleCruiserDoors.Value));
			}
			if (InteractionsConfig.ToggleCruiserLights.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ToggleCruiserLights", delegate
				{
					Cruiser.Headlights(1);
				}, InteractionsConfig.ToggleCruiserLights.Value));
			}
			if (InteractionsConfig.FlickerCruiserLights.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("FlickerCruiserLights", delegate
				{
					Cruiser.Headlights(Rand.Next(11));
				}, InteractionsConfig.FlickerCruiserLights.Value));
			}
			if (InteractionsConfig.ToggleCruiserHood.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("ToggleCruiserHood", delegate
				{
					Plugin.instance.Cruiser.ToggleHoodOpenLocalClient();
				}, InteractionsConfig.ToggleCruiserHood.Value));
			}
			if (InteractionsConfig.CruiserWindshield.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserWindshield", delegate
				{
					Cruiser.Windshield();
				}, InteractionsConfig.CruiserWindshield.Value));
			}
			if (InteractionsConfig.CruiserShiftGears.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("CruiserShiftGears", delegate
				{
					Cruiser.GearShift();
				}, InteractionsConfig.CruiserShiftGears.Value));
			}
		}

		private static void ExternalModCheck()
		{
			Plugin.MoreLogs("Checking for any external mods to utilize ghost codes on");
			if (!Plugin.instance.ToilHead || !ToilHead.CheckForToilHeadObjects())
			{
				return;
			}
			Plugin.MoreLogs("Adding toilhead actions");
			if (InteractionsConfig.ToilHeadTurretDisable.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("toilHeadDisable", delegate
				{
					ToilHead.HandleToilHeadCodeAction();
				}, InteractionsConfig.ToilHeadTurretDisable.Value));
			}
			if (InteractionsConfig.ToilHeadTurretBerserk.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("toilHeadBerserk", delegate
				{
					ToilHead.HandleToilHeadBerserkAction();
				}, InteractionsConfig.ToilHeadTurretBerserk.Value));
			}
		}

		private static void NetworkingRequiredActions()
		{
			if (ModConfig.ModNetworking.Value && InteractionsConfig.FlipBreaker.Value > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("facilityLights", delegate
				{
					Lights.FlipLights();
				}, InteractionsConfig.FlipBreaker.Value));
			}
		}

		private static void TerminalObjectActions(StartOfRound instance, int randomObjectNum)
		{
			if (CodeStuff.myTerminalObjects.Count > 0)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("DefaultCodes", delegate
				{
					DefaultTerminalAction(randomObjectNum);
				}, 100f));
			}
			if (!SetupConfig.IgnoreDoors.Value && Bools.IsThisaBigDoor(randomObjectNum))
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("hungryDoor", delegate
				{
					Blastdoors.HandleHungryDoor(randomObjectNum, instance);
				}, InteractionsConfig.HungryBlastDoor.Value));
			}
			if (!SetupConfig.IgnoreTurrets.Value)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("TurretBerserk", delegate
				{
					Turrets.HandleTurretAction();
				}, InteractionsConfig.TurretBerserk.Value));
			}
			if (!SetupConfig.IgnoreLandmines.Value)
			{
				CodeHandling.possibleActions.Add(new ActionPercentage("MineBoom", delegate
				{
					Mines.HandleMineBoom();
				}, InteractionsConfig.MineBoom.Value));
			}
		}

		internal static void DefaultTerminalAction(int randomObjectNum)
		{
			if (randomObjectNum != -1)
			{
				CodeStuff.myTerminalObjects[randomObjectNum].CallFunctionFromTerminal();
			}
		}
	}
	public class ActionPercentage
	{
		public Action Action { get; }

		public float Percentage { get; }

		public string Name { get; set; }

		public ActionPercentage(string name, Action action, float percentage)
		{
			Action = action;
			Percentage = percentage;
			Name = name;
			base..ctor();
		}

		public static List<Action> ChooseActionsFromPercentages(List<ActionPercentage> actions)
		{
			Shuffle(actions);
			List<Action> list = new List<Action>();
			int num = 0;
			foreach (ActionPercentage action in actions)
			{
				Plugin.Spam("Checking " + action.Name + " against percentage");
				int num2 = NumberStuff.Rand.Next(101);
				float num3 = action.Percentage;
				if (RapidFire.startRapidFire)
				{
					num3 = NumberStuff.GetClampedInsanityPercent(num3, InsanityConfig.InsanityModeMultiplier.Value);
				}
				if (num < 3 && ((float)num2 <= num3 || Mathf.Approximately(num3, 100f)))
				{
					Plugin.Spam("Action " + action.Name + " was chosen!");
					list.Add(action.Action);
					num++;
				}
			}
			return list;
		}

		private static void Shuffle<T>(List<T> list)
		{
			int num = list.Count;
			while (num > 1)
			{
				num--;
				int index = NumberStuff.Rand.Next(num);
				T value = list[index];
				list[index] = list[num];
				list[num] = value;
			}
		}
	}
	internal class CodeHandling
	{
		internal static List<ActionPercentage> possibleActions = new List<ActionPercentage>();

		internal static List<Action> chosenActions = new List<Action>();

		internal static void HandleGhostCodeSending(StartOfRound instance)
		{
			Misc.LogTime();
			if (NumberStuff.TryGetObjectNum(out var randomObjectNum))
			{
				chosenActions.Clear();
				CodeActions.InitPossibleActions(instance, randomObjectNum);
			}
			else
			{
				Plugin.WARNING("Unable to get randomObjectNum!");
			}
			if (possibleActions.Count >= 1 && !Bools.endAllCodes)
			{
				chosenActions = ActionPercentage.ChooseActionsFromPercentages(possibleActions);
				HandleChosenActions(randomObjectNum);
				SoundSystem.InsanityAmbient();
				SoundSystem.HandleCodeEffects();
			}
		}

		internal static void HandleRapidFireCodeChoices(StartOfRound instance, int number)
		{
			Misc.LogTime();
			chosenActions.Clear();
			CodeActions.InitPossibleActions(instance, number);
			if (possibleActions.Count >= 1 && !Bools.endAllCodes)
			{
				chosenActions = ActionPercentage.ChooseActionsFromPercentages(possibleActions);
				HandleChosenActions(number);
				SoundSystem.InsanityAmbient();
				SoundSystem.HandleCodeEffects();
			}
		}

		private static void HandleChosenActions(int randomObjectNum)
		{
			if (chosenActions == null && CodeStuff.myTerminalObjects.Count == 0)
			{
				Bools.endAllCodes = true;
				return;
			}
			if (chosenActions.Count > 0)
			{
				foreach (Action chosenAction in chosenActions)
				{
					chosenAction();
				}
				return;
			}
			if (randomObjectNum != -1)
			{
				CodeStuff.myTerminalObjects[randomObjectNum].CallFunctionFromTerminal();
				Plugin.GC.LogInfo((object)"No Special action chosen, calling function from terminal");
			}
		}
	}
	internal class Coroutines
	{
		internal static bool rapidFireStart;

		internal static bool codeLooperStarted;

		internal static bool activeFlicker;

		internal static IEnumerator InitEnumerator(StartOfRound instance)
		{
			int wait = NumberStuff.GetWait(SetupConfig.RandomIntervals.Value, SetupConfig.FirstRandIntervalMin.Value, SetupConfig.FirstRandIntervalMax.Value, SetupConfig.FirstSetInterval.Value);
			InitPlugin.CodesInit();
			Plugin.MoreLogs($"Codes Amount: {Plugin.instance.RandCodeAmount}");
			if (SetupConfig.GhostCodesSettings.HauntingsMode && ModConfig.ModNetworking.Value)
			{
				Plugin.MoreLogs("The ghost girl has been enhanced, prepare for your next haunting! >:)");
				TerminalAdditions.CreateAllNodes();
			}
			else if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
			{
				yield return (object)new WaitForSeconds((float)wait);
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(CodeLooper(instance));
				Plugin.MoreLogs("The ghost is in the machine...");
				TerminalAdditions.CreateAllNodes();
			}
			else
			{
				Plugin.MoreLogs("Ghost Girl Enhanced is disabled and you are not the host.");
				TerminalAdditions.CreateAllNodes();
			}
		}

		internal static IEnumerator RestartEnum(StartOfRound instance)
		{
			int @int = NumberStuff.GetInt(20, 100);
			yield return (object)new WaitForSeconds((float)@int);
			int wait = NumberStuff.GetWait(SetupConfig.RandomIntervals.Value, SetupConfig.FirstRandIntervalMin.Value, SetupConfig.FirstRandIntervalMax.Value, SetupConfig.FirstSetInterval.Value);
			Plugin.MoreLogs($"Codes: {Plugin.instance.CodeCount} / {Plugin.instance.RandCodeAmount}");
			if (SetupConfig.GhostCodesSettings.HauntingsMode && ModConfig.ModNetworking.Value)
			{
				Plugin.MoreLogs("The ghost girl has been enhanced, prepare for your next haunting! >:)");
			}
			else if (((NetworkBehaviour)GameNetworkManager.Instance.localPlayerController).IsHost)
			{
				yield return (object)new WaitForSeconds((float)wait);
				Bools.endAllCodes = false;
				rapidFireStart = false;
				RapidFire.startRapidFire = false;
				((MonoBehaviour)instance).StartCoroutine(CodeLooper(instance));
				Plugin.MoreLogs("The ghost is in the machine...");
			}
			else
			{
				Plugin.MoreLogs("Ghost Girl Enhanced is disabled and you are not the host.");
			}
		}

		internal static IEnumerator CodeLooper(StartOfRound instance)
		{
			if (codeLooperStarted)
			{
				yield break;
			}
			Plugin.MoreLogs("CodeLooper coroutine initiated...");
			codeLooperStarted = true;
			if (Bools.CanSendCodes())
			{
				while (Bools.KeepSendingCodes())
				{
					yield return (object)new WaitForSeconds(1f);
					if (!Bools.IsCodeSent())
					{
						float randomWaitNum = NumberStuff.GetWait(SetupConfig.RandomIntervals.Value, SetupConfig.SecondRandIntervalMin.Value, SetupConfig.SecondRandIntervalMax.Value, SetupConfig.SecondSetInterval.Value);
						if (SetupConfig.GhostCodesSettings.InsanityMode)
						{
							InsanityStuff.ApplyInsanityMode(instance, ref randomWaitNum);
							if (RapidFire.startRapidFire)
							{
								Plugin.MoreLogs("startRapidFire detected from codeLooper");
								codeLooperStarted = false;
								yield break;
							}
						}
						yield return (object)new WaitForSeconds(randomWaitNum);
						CodeHandling.HandleGhostCodeSending(instance);
						Plugin.instance.CodeCount++;
						Plugin.instance.CodeSent = true;
						Plugin.MoreLogs($"Code Sent, count: {Plugin.instance.CodeCount}");
					}
					else
					{
						float randomWaitNum2 = NumberStuff.GetWait(SetupConfig.RandomIntervals.Value, SetupConfig.RandIntervalACMin.Value, SetupConfig.RandIntervalACMax.Value, SetupConfig.SetIntervalAC.Value);
						Plugin.MoreLogs($"ghostCode was just sent, waiting {randomWaitNum2}");
						if (SetupConfig.GhostCodesSettings.InsanityMode)
						{
							InsanityStuff.ApplyInsanityMode(instance, ref randomWaitNum2);
						}
						yield return (object)new WaitForSeconds(randomWaitNum2);
						Plugin.instance.CodeSent = false;
					}
					if (StartOfRound.Instance.shipIsLeaving)
					{
						Plugin.MoreLogs($"Ship is leaving, {Plugin.instance.CodeCount} codes were sent.");
						codeLooperStarted = false;
						yield break;
					}
				}
				Plugin.MoreLogs($"the ghost is bored of sending codes, {Plugin.instance.CodeCount} codes were sent.");
				codeLooperStarted = false;
			}
			else
			{
				Plugin.MoreLogs("No codes can be sent at this time.");
				codeLooperStarted = false;
			}
		}

		private static void RapidFireStoppers(int startTime, int currentTime)
		{
			DressGirl.GGrapidFireChecks();
			RapidFire.TimeCheck(startTime, currentTime);
		}

		internal static IEnumerator RapidFireStart(StartOfRound instance)
		{
			if (rapidFireStart)
			{
				yield break;
			}
			Plugin.MoreLogs("start of rapidFire");
			int startTime = TimeOfDay.Instance.hour;
			rapidFireStart = true;
			if (Bools.CanSendCodes())
			{
				while (Bools.KeepSendingCodes() && RapidFire.startRapidFire && !Bools.endAllCodes)
				{
					RapidFire.CheckInsanityToContinue();
					RapidFire.HandleLights();
					if (!Bools.IsCodeSent())
					{
						if (CodeStuff.myTerminalObjects.Count == 0)
						{
							for (int j = 0; j < CodeHandling.possibleActions.Count; j++)
							{
								if (!Bools.KeepSendingCodes())
								{
									break;
								}
								RapidFireStoppers(startTime, TimeOfDay.Instance.hour);
								CodeHandling.HandleRapidFireCodeChoices(instance, -1);
								yield return (object)new WaitForSeconds(Random.Range(0.5f, 3f));
							}
						}
						else
						{
							for (int j = 0; j < CodeStuff.myTerminalObjects.Count; j++)
							{
								if (!Bools.KeepSendingCodes())
								{
									break;
								}
								RapidFireStoppers(startTime, TimeOfDay.Instance.hour);
								CodeHandling.HandleRapidFireCodeChoices(instance, j);
								yield return (object)new WaitForSeconds(Random.Range(0.5f, 3f));
							}
						}
						RapidFire.CountSentCodes();
						Plugin.instance.CodeSent = true;
					}
					else
					{
						RapidFireStoppers(startTime, TimeOfDay.Instance.hour);
						float num = Random.Range(1f, 4f);
						RapidFireStoppers(startTime, TimeOfDay.Instance.hour);
						yield return (object)new WaitForSeconds(num);
						Plugin.instance.CodeSent = false;
					}
					if (RapidFire.LoopBreakers())
					{
						yield break;
					}
				}
				if (!Bools.KeepSendingCodes())
				{
					Plugin.GC.LogInfo((object)"end of rapidFire....");
				}
				if (!RapidFire.startRapidFire && Bools.KeepSendingCodes() && !Bools.endAllCodes)
				{
					RapidFire.ReturnFromRapidFire();
					RapidFire.startRapidFire = false;
					rapidFireStart = false;
				}
				else
				{
					_ = Bools.endAllCodes;
					RapidFire.startRapidFire = false;
					rapidFireStart = false;
				}
			}
			else
			{
				RapidFire.startRapidFire = false;
				rapidFireStart = false;
			}
		}

		internal static IEnumerator EmptyShip()
		{
			Plugin.MoreLogs("Emptying the ship of any players!");
			PlayerControllerB localPlayer = StartOfRound.Instance.localPlayerController;
			Vector3 playerPosition = ((Component)localPlayer).transform.position;
			Vector3 shipDoorPosition = StartOfRound.Instance.shipDoorNode.position;
			float oldfriction = localPlayer.slideFriction;
			localPlayer.isPlayerSliding = true;
			localPlayer.slideFriction = localPlayer.maxSlideFriction * 2f;
			while (localPlayer.isInHangarShipRoom)
			{
				if (Physics.Linecast(playerPosition, shipDoorPosition, StartOfRound.Instance.collidersAndRoomMask))
				{
					Vector3 val = Vector3.Normalize(shipDoorPosition - playerPosition);
					localPlayer.externalForces = val * 350f;
					Plugin.MoreLogs("applying external forces");
				}
				yield return (object)new WaitForSeconds(0.1f);
			}
			localPlayer.isPlayerSliding = false;
			localPlayer.slideFriction = oldfriction;
		}

		internal static IEnumerator AlarmLights()
		{
			if (Bools.lightsFlickering)
			{
				yield break;
			}
			Bools.lightsFlickering = true;
			BreakerBox breakerBox = Object.FindObjectOfType<BreakerBox>();
			if ((Object)(object)breakerBox == (Object)null)
			{
				yield break;
			}
			Plugin.Spam("Starting light flicker loop");
			NetHandler.Instance.AlarmLightsServerRpc(normal: false);
			while (RapidFire.startRapidFire && !StartOfRound.Instance.localPlayerController.isPlayerDead && !Bools.endAllCodes)
			{
				if (StartOfRound.Instance.localPlayerController.isInsideFactory)
				{
					NetHandler.Instance.FlickerLightsServerRpc(flickerFlash: false, disableFlash: false);
				}
				yield return (object)new WaitForSeconds(Random.Range(SetupConfig.RapidLightsMin.Value, SetupConfig.RapidLightsMax.Value));
			}
			NetHandler.Instance.AlarmLightsServerRpc(normal: true);
			yield return (object)new WaitForSeconds(1f);
			if (!breakerBox.isPowerOn)
			{
				breakerBox.SwitchBreaker(true);
				Plugin.GC.LogInfo((object)"returning to normal");
			}
			Bools.lightsFlickering = false;
		}

		internal static IEnumerator GhostGirlEnhanced(StartOfRound instance)
		{
			Plugin.MoreLogs("GhostGirl is being enhanced");
			if (RapidFire.startRapidFire)
			{
				yield break;
			}
			while (Plugin.instance.DressGirl.staringInHaunt)
			{
				float num = Random.Range(1f, 4f);
				if (!Plugin.instance.CodeSent && !DressGirl.girlIsChasing)
				{
					CodeHandling.HandleGhostCodeSending(instance);
					Plugin.instance.CodeSent = true;
				}
				else
				{
					Plugin.GC.LogInfo((object)$"ghostCode was just sent, waiting {num}");
					yield return (object)new WaitForSeconds(num);
					Plugin.instance.CodeSent = false;
				}
				if (RapidFire.LoopBreakers())
				{
					yield break;
				}
			}
			Plugin.MoreLogs("End of GhostGirlEnhanced Coroutine...");
		}
	}
	internal class Doors
	{
		internal static List<DoorLock> AllDoors = new List<DoorLock>();

		internal static bool CustomHauntRunning = false;

		internal static Random Rand = new Random();

		internal static void UpdateCacheDoorsList()
		{
			DoorLock[] array = Object.FindObjectsOfType<DoorLock>();
			List<DoorLock> list = new List<DoorLock>(array.Length);
			list.AddRange(array);
			AllDoors = list;
		}

		internal static void OpenOrCloseALLDoors()
		{
			Plugin.MoreLogs("All doors changing state");
			for (int i = 0; i < AllDoors.Count; i++)
			{
				if (!((Object)(object)AllDoors[i] == (Object)null))
				{
					AllDoors[i].OpenOrCloseDoor(StartOfRound.Instance.localPlayerController);
				}
			}
			Plugin.MoreLogs($"All {AllDoors.Count} doors have been opened or closed");
		}

		internal static void OpenorClose1RandomDoor()
		{
			int @int = NumberStuff.GetInt(0, AllDoors.Count);
			if (!((Object)(object)AllDoors[@int] == (Object)null))
			{
				AllDoors[@int].OpenOrCloseDoor(StartOfRound.Instance.localPlayerController);
				Plugin.MoreLogs("Opened or Closed one door");
			}
		}

		internal static void LockorUnlockARandomDoor(bool stateLocked)
		{
			for (int i = 0; i < AllDoors.Count; i++)
			{
				int @int = NumberStuff.GetInt(0, AllDoors.Count);
				if (!((Object)(object)AllDoors[@int] == (Object)null))
				{
					if (AllDoors[@int].isLocked && stateLocked)
					{
						AllDoors[@int].UnlockDoorServerRpc();
						Plugin.MoreLogs("Unlocked random door");
						break;
					}
					if (!AllDoors[@int].isLocked && !stateLocked)
					{
						AllDoors[@int].LockDoor(30f);
						Plugin.MoreLogs("Locked random door");
						break;
					}
				}
			}
		}

		internal static void HauntDoors(int value)
		{
			float num = (float)value / 100f;
			Plugin.MoreLogs($"Attempting to Haunt {value}% of doors!");
			float num2 = ((value != 0) ? ((float)AllDoors.Count * num) : 1f);
			for (int i = 0; i < (int)num2; i++)
			{
				if (!((Object)(object)AllDoors[i] == (Object)null))
				{
					MonoBehaviour component = ((Component)AllDoors[i]).gameObject.GetComponent<MonoBehaviour>();
					component.StopAllCoroutines();
					component.StartCoroutine(CustomDoorHaunt(AllDoors[i]));
				}
			}
			Plugin.MoreLogs($"Attempted to haunt {(int)num2} doors!");
		}

		internal static IEnumerator CustomDoorHaunt(DoorLock thisDoor)
		{
			int times = Rand.Next(9);
			for (int i = 0; i < times; i++)
			{
				float num = ((!thisDoor.isDoorOpened && Rand.Next(100) >= 92) ? Random.Range(2f, 7f) : ((!thisDoor.isDoorOpened) ? Random.Range(0.2f, 1.7f) : Random.Range(0.15f, 0.3f)));
				yield return (object)new WaitForSeconds(num);
				thisDoor.OpenOrCloseDoor(StartOfRound.Instance.localPlayerController);
			}
			yield return (object)new WaitForSeconds(0.2f);
			if (thisDoor.isDoorOpened)
			{
				thisDoor.OpenOrCloseDoor(StartOfRound.Instance.localPlayerController);
			}
		}
	}
	public class GamePatchStuff
	{
		[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
		public class NextDayPatch
		{
			private static void Postfix()
			{
				Plugin.Spam("Next day detected!");
				OpenLibEvents.GhostCodesReset.Invoke();
			}
		}

		[HarmonyPatch(typeof(TerminalAccessibleObject), "Start")]
		public class TerminalAccessibleObject_StartPatch
		{
			private static void Postfix(TerminalAccessibleObject __instance)
			{
				CodeStuff.NewUsableCode(__instance);
			}
		}

		[HarmonyPatch(typeof(TerminalAccessibleObject), "OnDestroy")]
		public class TerminalAccessibleObject_DestroyPatch
		{
			private static void Postfix(TerminalAccessibleObject __instance)
			{
				CodeStuff.RemoveUsableCode(__instance);
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public class ApparatusPullPatch
		{
			private static bool instructionAdded;

			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> ApparatusPullPatch_Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				CodeInstruction myMethod = CodeInstruction.Call("ghostCodes.Patches.OpenLibEvents:GetInvoke", (Type[])null, (Type[])null);
				foreach (CodeInstruction instruction in instructions)
				{
					if (!instructionAdded)
					{
						Plugin.GC.LogInfo((object)"Custom Instruction added in DisconnectFromMachinery enumerator");
						yield return myMethod;
						yield return instruction;
						instructionAdded = true;
					}
					else
					{
						yield return instruction;
					}
				}
				Plugin.GC.LogInfo((object)"Transpiler Success! - Added ApparatusPull Invoke Event");
			}
		}

		[HarmonyPatch(typeof(DressGirlAI), "Start")]
		public class DressGirlExists : DressGirlAI
		{
			private static void Postfix(DressGirlAI __instance)
			{
				Plugin.instance.DressGirl = __instance;
				Plugin.MoreLogs("Dressgirl instance detected.");
			}

			protected override void __initializeVariables()
			{
				((DressGirlAI)this).__initializeVariables();
			}

			protected internal override string __getTypeName()
			{
				return "DressGirlExists";
			}
		}

		[HarmonyPatch(typeof(DressGirlAI), "SetHauntStarePosition")]
		public class StaringInHauntPatch : DressGirlAI
		{
			private static void Postfix(DressGirlAI __instance)
			{
				if (!(SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings"))
				{
					if ((Object)(object)__instance == (Object)null)
					{
						Plugin.GC.LogError((object)"Failed to grab dressgirl instance");
					}
					else if (__instance.staringInHaunt && Bools.CanSendCodes() && Bools.DressGirlStartCodes())
					{
						Plugin.instance.DressGirl = __instance;
						Plugin.GC.LogInfo((object)"The ghostGirl wants to play!");
						((MonoBehaviour)Plugin.instance.DressGirl).StartCoroutine(Coroutines.GhostGirlEnhanced(StartOfRound.Instance));
					}
				}
			}

			protected override void __initializeVariables()
			{
				((DressGirlAI)this).__initializeVariables();
			}

			protected internal override string __getTypeName()
			{
				return "StaringInHauntPatch";
			}
		}

		[HarmonyPatch(typeof(DressGirlAI), "FlipLightsBreakerServerRpc")]
		public class DressGirlRPCFix : DressGirlAI
		{
			private static void Postfix(DressGirlAI __instance)
			{
				if (SetupConfig.FixGhostGirlBreakers.Value)
				{
					Plugin.MoreLogs("Fixing lightbreaker Rpc");
					__instance.FlipLightsBreakerClientRpc();
				}
			}

			protected override void __initializeVariables()
			{
				((DressGirlAI)this).__initializeVariables();
			}

			protected internal override string __getTypeName()
			{
				return "DressGirlRPCFix";
			}
		}

		[HarmonyPatch(typeof(DressGirlAI), "BeginChasing")]
		public class TheChaseBegins
		{
			private static void Postfix(DressGirlAI __instance)
			{
				DressGirl.BreakersFix(__instance);
				if (!(SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings"))
				{
					RapidFire.startRapidFire = true;
					DressGirl.girlIsChasing = true;
					Plugin.MoreLogs("Girl has begun chasing, setting rapidFire to TRUE");
					((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Coroutines.RapidFireStart(StartOfRound.Instance));
				}
			}
		}

		[HarmonyPatch(typeof(DressGirlAI), "StopChasing")]
		public class TheChaseEnds : DressGirlAI
		{
			private static void Postfix()
			{
				if (!(SetupConfig.GhostCodesSettings.CurrentMode.ToLower() != "hauntings"))
				{
					RapidFire.startRapidFire = false;
					DressGirl.girlIsChasing = false;
					Plugin.MoreLogs("Chase sequence has ended.");
				}
			}

			protected override void __initializeVariables()
			{
				((DressGirlAI)this).__initializeVariables();
			}

			protected internal override string __getTypeName()
			{
				return "TheChaseEnds";
			}
		}

		[HarmonyPatch(typeof(VehicleController), "Awake")]
		public class GetVehicleController
		{
			private static void Postfix(VehicleController __instance)
			{
				Plugin.instance.Cruiser = __instance;
				Plugin.MoreLogs("Cruiser instance detected.");
			}
		}
	}
	internal class DressGirl : EnemyAI
	{
		internal static bool girlIsChasing;

		internal static void InitDressGirl()
		{
			Plugin.MoreLogs("Resetting DressGirl Variables...");
			girlIsChasing = false;
			Plugin.instance.DressGirl = null;
		}

		internal static void ChangeHauntedPlayer(PlayerControllerB player)
		{
			Plugin.instance.DressGirl.hauntingPlayer = player;
			((EnemyAI)Plugin.instance.DressGirl).ChangeOwnershipOfEnemy(Plugin.instance.DressGirl.hauntingPlayer.actualClientId);
			Plugin.instance.DressGirl.hauntingLocalPlayer = (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)(object)Plugin.instance.DressGirl.hauntingPlayer;
		}

		internal static void GGrapidFireChecks()
		{
			if (!((Object)(object)Plugin.instance.DressGirl == (Object)null) && SetupConfig.GhostCodesSettings.HauntingsMode)
			{
				Plugin.MoreLogs("Checking for rapidFire ending events");
				DancingCheck();
				ShowerStuff.CheckForHauntedPlayerInShower();
			}
		}

		private static void DancingCheck()
		{
			if (InteractionsConfig.EmoteStopChasing.Value > 1 || !girlIsChasing)
			{
				return;
			}
			if (!Bools.IsThisEffective(InteractionsConfig.EmoteStopChasing.Value))
			{
				Plugin.MoreLogs("Ghost girl doesn't want to see you dance!");
				return;
			}
			int numberPlayersEmoting = NumberStuff.GetNumberPlayersEmoting();
			int alivePlayers = NumberStuff.GetAlivePlayers();
			if (Bools.AreEnoughPlayersDancing(alivePlayers, numberPlayersEmoting, InteractionsConfig.EmoteStopChaseRequiredPlayers.Value))
			{
				Plugin.MoreLogs("Enough players emoting, stopping chase");
				StopGirlFromChasing();
			}
			else
			{
				Plugin.MoreLogs("You might wanna keep running...");
			}
		}

		internal static void StopGirlFromChasing()
		{
			if (!((Object)(object)Plugin.instance.DressGirl == (Object)null) && Plugin.instance.DressGirl.hauntingLocalPlayer)
			{
				Plugin.instance.DressGirl.StopChasing();
				Plugin.MoreLogs("initiating stop chase.");
			}
		}

		internal static void GirlDisappear()
		{
			if (!((Object)(object)Plugin.instance.DressGirl == (Object)null) && Plugin.instance.DressGirl.hauntingLocalPlayer)
			{
				Plugin.instance.DressGirl.DisappearDuringHaunt();
			}
		}

		internal static void EndAllGirlStuff()
		{
			if (girlIsChasing)
			{
				StopGirlFromChasing();
			}
			if (Plugin.instance.DressGirl.staringInHaunt)
			{
				GirlDisappear();
			}
		}

		internal static void BreakersFix(DressGirlAI instance)
		{
			if (SetupConfig.FixGhostGirlBreakers.Value && ((EnemyAI)instance).currentBehaviourStateIndex != 1 && instance.timesChased == 1 && Random.Range(0, 100) < SetupConfig.VanillaBreakersChance.Value)
			{
				instance.FlipLightsBreakerServerRpc();
				Plugin.GC.LogInfo((object)"patched updated breaker chance for vanilla");
			}
		}

		protected override void __initializeVariables()
		{
			((EnemyAI)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "DressGirl";
		}
	}
	internal class InitPlugin
	{
		internal static void StartTheRound()
		{
			if (!(((Object)StartOfRound.Instance.currentLevel).name == "CompanyBuildingLevel") && !(StartOfRound.Instance.currentLevel.riskLevel == "Safe"))
			{
				InitMode();
				BaseReset();
				DressGirl.InitDressGirl();
				StartPlugin();
			}
		}

		private static void StartPlugin()
		{
			if (Bools.ShouldInitPlugin())
			{
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Coroutines.InitEnumerator(StartOfRound.Instance));
			}
		}

		internal static void RestartPlugin()
		{
			if (Bools.ShouldInitPlugin())
			{
				((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Coroutines.RestartEnum(StartOfRound.Instance));
			}
		}

		internal static void InitMode()
		{
			Plugin.MoreLogs("Initializing ghostCodes mode settings");
			SetupConfig.GhostCodesSettings.UpdateSettings(StartOfRound.Instance.currentLevel);
		}

		internal static void BaseReset()
		{
			Bools.appPullInvoked = false;
			Plugin.instance.CodeSent = false;
			RapidFire.startRapidFire = false;
			Coroutines.rapidFireStart = false;
			Coroutines.codeLooperStarted = false;
			Plugin.instance.MaxSanity = 0f;
			Plugin.instance.GroupSanity = 0f;
			GetPlayersAtStart();
			Plugin.instance.CodeCount = 0;
			Plugin.instance.RandCodeAmount = 0;
			ShipStuff.ResetLever();
			TerminalAdditions.RestoreCreds();
		}

		internal static void CodesInit()
		{
			Plugin.MoreLogs("Initializing GhostCode core variables");
			Bools.endAllCodes = false;
			TerminalAdditions.ResetBools();
			Doors.UpdateCacheDoorsList();
			Plugin.instance.RandCodeAmount = NumberStuff.GetInt(SetupConfig.MinCodes.Value, SetupConfig.MaxCodes.Value);
			if (SetupConfig.SoloAssist.Value)
			{
				InsanityStuff.InitsoloAssist();
			}
		}

		internal static void GetPlayersAtStart()
		{
			Plugin.instance.playersAtStart = 0;
			Plugin.instance.players = StartOfRound.Instance.allPlayerScripts;
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Count(); i++)
			{
				if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled)
				{
					Plugin.instance.playersAtStart++;
				}
			}
			Plugin.MoreLogs($"Players at Start: {Plugin.instance.playersAtStart}");
			if (Plugin.instance.playersAtStart > 1)
			{
				Plugin.MoreLogs("SoloAssist Buff disabled, more than one player detected.");
			}
		}
	}
	internal class InsanityStuff
	{
		internal static Dictionary<string, ConfigEntry<int>> stageKeyVal = new Dictionary<string, ConfigEntry<int>>();

		internal static Stages stage1 = SetStageInfo("Stage 1", 0, 6, SoloAssistConfig.S1percent, SoloAssistConfig.S1inside, SoloAssistConfig.S1outside);

		internal static Stages stage2 = SetStageInfo("Stage 2", 7, 10, SoloAssistConfig.S2percent, SoloAssistConfig.S2inside, SoloAssistConfig.S2outside);

		internal static Stages stage3 = SetStageInfo("Stage 3", 11, 15, SoloAssistConfig.S3percent, SoloAssistConfig.S3inside, SoloAssistConfig.S3outside);

		internal static List<Stages> allStages = new List<Stages>();

		public static void ApplyInsanityMode(StartOfRound instance, ref float randomWaitNum)
		{
			GetAllSanity();
			float groupSanity = Plugin.instance.GroupSanity;
			float maxSanity = Plugin.instance.MaxSanity;
			if (RapidFire.startRapidFire && SetupConfig.RapidFireMaxHours.Value > 0)
			{
				Plugin.GC.LogInfo((object)"max insanity level reached!!! startRapidFire TRUE");
				((MonoBehaviour)instance).StartCoroutine(Coroutines.RapidFireStart(instance));
			}
			else
			{
				AdjustWaitNum(groupSanity, maxSanity, ref randomWaitNum);
				Plugin.MoreLogs($"waiting {randomWaitNum}");
			}
		}

		internal static void InitsoloAssist()
		{
			allStages.Clear();
			allStages.Add(stage1);
			allStages.Add(stage2);
			allStages.Add(stage3);
		}

		internal static void GetAllSanity()
		{
			Plugin.instance.GroupSanity = 0f;
			Plugin.instance.MaxSanity = 0f;
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Count(); i++)
			{
				if (!StartOfRound.Instance.allPlayerScripts[i].isPlayerDead && StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled)
				{
					Plugin.instance.GroupSanity += StartOfRound.Instance.allPlayerScripts[i].insanityLevel;
					Plugin.instance.MaxSanity += StartOfRound.Instance.allPlayerScripts[i].maxInsanityLevel;
				}
			}
			float groupSanity = Plugin.instance.GroupSanity;
			ApplyBonuses(ref groupSanity, Plugin.instance.MaxSanity);
			Plugin.instance.GroupSanity = groupSanity;
			CheckSanityRapidFire();
		}

		private static void CheckSanityRapidFire()
		{
			if (SetupConfig.RapidFireMaxHours.Value >= 1)
			{
				if (Mathf.Round(Plugin.instance.GroupSanity) >= Mathf.Round(Plugin.instance.MaxSanity) * ((float)InsanityConfig.SanityMaxLevel.Value / 100f))
				{
					RapidFire.startRapidFire = true;
					Plugin.MoreLogs("max sanity hit, CheckSanityRapidFire()");
					Plugin.MoreLogs($"Group Sanity Level: {Mathf.Round(Plugin.instance.GroupSanity)}");
					Plugin.MoreLogs($"Group Max Insanity level: {Mathf.Round(Plugin.instance.MaxSanity)}");
				}
				else
				{
					RapidFire.startRapidFire = false;
					Plugin.MoreLogs($"Group Sanity Level: {Mathf.Round(Plugin.instance.GroupSanity)}");
					Plugin.MoreLogs($"Group Max Insanity level: {Mathf.Round(Plugin.instance.MaxSanity)}");
				}
			}
		}

		private static float AdjustWaitNum(float groupSanity, float maxSanity, ref float randomWaitNum)
		{
			if (SetupConfig.RapidFireMaxHours.Value < 1 && Mathf.Round(groupSanity) >= Mathf.Round(maxSanity) * ((float)InsanityConfig.SanityMaxLevel.Value / 100f))
			{
				randomWaitNum *= (float)InsanityConfig.WaitMaxLevel.Value / 100f;
				Plugin.MoreLogs("Max Insanity Level reached (rapidFire disabled)");
				return randomWaitNum;
			}
			if (Mathf.Round(groupSanity) >= Mathf.Round(maxSanity) * ((float)InsanityConfig.SanityLevel3.Value / 100f))
			{
				randomWaitNum *= (float)InsanityConfig.WaitLevel3.Value / 100f;
				Plugin.MoreLogs("insanity level 3 reached");
				return randomWaitNum;
			}
			if (Mathf.Round(groupSanity) >= Mathf.Round(maxSanity) * ((float)InsanityConfig.SanityLevel2.Value / 100f))
			{
				randomWaitNum *= (float)InsanityConfig.WaitLevel2.Value / 100f;
				Plugin.MoreLogs("insanity level 2 reached");
				return randomWaitNum;
			}
			if (Mathf.Round(groupSanity) >= Mathf.Round(maxSanity) * ((float)InsanityConfig.SanityLevel1.Value / 100f))
			{
				randomWaitNum *= (float)InsanityConfig.WaitLevel1.Value / 100f;
				Plugin.MoreLogs("insanity level 1 reached");
				return randomWaitNum;
			}
			Plugin.MoreLogs("insanity levels low");
			return randomWaitNum;
		}

		private static Tuple<float, float> ApplyBonuses(ref float groupSanity, float maxSanity)
		{
			Plugin.MoreLogs($"Applying bonuses & debuffs\nplayersAtStart = {Plugin.instance.playersAtStart}");
			if (SetupConfig.SoloAssist.Value && Plugin.instance.playersAtStart == 1)
			{
				Plugin.MoreLogs("SoloAssist Activated");
				groupSanity = SoloAssist(ref groupSanity, maxSanity);
			}
			if (InsanityConfig.DeathBonus.Value > 0)
			{
				Plugin.MoreLogs("Death Bonus Activated");
				groupSanity = ApplyDeathBonus(ref groupSanity, maxSanity);
			}
			if (InsanityConfig.GhostGirlBonus.Value > 0 && (Object)(object)Plugin.instance.DressGirl != (Object)null)
			{
				Plugin.MoreLogs("Ghost Girl Bonus Activated");
				groupSanity = ApplyGirlBonus(ref groupSanity, maxSanity);
			}
			if (InsanityConfig.EmoteBuff.Value > 1)
			{
				Plugin.MoreLogs("Emote Buff Activated");
				groupSanity = EmoteBuff(ref groupSanity);
			}
			return Tuple.Create(groupSanity, maxSanity);
		}

		private static float ApplyDeathBonus(ref float groupSanity, float maxSanity)
		{
			int num = Plugin.instance.players.Count((PlayerControllerB player) => player.isPlayerDead && player.isPlayerControlled);
			for (int i = 0; i < num; i++)
			{
				float num2 = groupSanity * ((float)InsanityConfig.DeathBonus.Value / 100f);
				Plugin.MoreLogs($"Dead Player detected. Adding {num2} to group sanity");
				groupSanity = ApplyBonus(groupSanity, maxSanity, num2, (float _) => true);
			}
			Plugin.MoreLogs("Death bonus applied to insanity values");
			return groupSanity;
		}

		private static float ApplyGirlBonus(ref float groupSanity, float maxSanity)
		{
			Plugin.MoreLogs("Ghost Girl Bonus applied to insanity values");
			float num = groupSanity * ((float)InsanityConfig.GhostGirlBonus.Value / 100f);
			Plugin.MoreLogs($"Ghost Girl Bonus adding {num} to group sanity");
			groupSanity = ApplyBonus(groupSanity, maxSanity, num, (float _) => true);
			return groupSanity;
		}

		private static float ApplyBonus(float groupSanity, float maxSanity, float bonusValue, Func<float, bool> condition)
		{
			if (condition(groupSanity) && maxSanity >= groupSanity + bonusValue)
			{
				groupSanity += bonusValue;
			}
			return groupSanity;
		}

		private static Stages SetStageInfo(string name, int startHour, int endHour, ConfigEntry<int> percentKey, ConfigEntry<int> insideKey, ConfigEntry<int> outsideKey)
		{
			return new Stages
			{
				Name = name,
				StartHour = startHour,
				EndHour = endHour,
				PercentKey = percentKey,
				InsideKey = insideKey,
				OutsideKey = outsideKey
			};
		}

		private static float EmoteBuff(ref float groupSanity)
		{
			if (InsanityConfig.EmoteBuff.Value > 0)
			{
				PlayerControllerB[] players = Plugin.instance.players;
				foreach (PlayerControllerB val in players)
				{
					if (!val.isPlayerDead && val.performingEmote)
					{
						float num = groupSanity * ((float)InsanityConfig.EmoteBuff.Value / 100f);
						Plugin.MoreLogs($"Emote buff removing {num} from group sanity");
						ApplySanityDebuff(ref groupSanity, num);
					}
				}
			}
			return groupSanity;
		}

		private static float SoloAssist(ref float groupSanity, float maxSanity)
		{
			if (SetupConfig.SoloAssist.Value && Plugin.instance.playersAtStart == 1)
			{
				int hour = TimeOfDay.Instance.hour;
				Plugin.GC.LogInfo((object)$"Hour: {hour}");
				foreach (Stages allStage in allStages)
				{
					if (Bools.IsHourInRange(hour, allStage.StartHour, allStage.EndHour))
					{
						float num = maxSanity * ((float)allStage.PercentKey.Value / 100f);
						float num2 = (Bools.IsInsideFactory() ? allStage.InsideKey.Value : allStage.OutsideKey.Value);
						Plugin.MoreLogs($"threshold: {num}, debuffAmount: {num2}, GroupSanity: {groupSanity}");
						if (groupSanity >= num)
						{
							ApplySanityDebuff(ref groupSanity, num2);
							Plugin.MoreLogs(allStage.Name + " detected and debuffs applied");
						}
						else
						{
							Plugin.MoreLogs("No solo assist buff added.");
						}
						break;
					}
				}
			}
			return groupSanity;
		}

		private static void ApplySanityDebuff(ref float groupSanity, float debuffAmount)
		{
			if (groupSanity > debuffAmount)
			{
				groupSanity -= debuffAmount;
				Plugin.GC.LogInfo((object)$"Subtracted {debuffAmount} from Group Sanity Level.");
			}
			else
			{
				groupSanity = 0f;
				Plugin.GC.LogInfo((object)$"Subtracted {debuffAmount} from Group Sanity Level which set value to 0.");
			}
		}
	}
	internal class Stages
	{
		internal string Name { get; set; }

		internal int StartHour { get; set; }

		internal int EndHour { get; set; }

		internal ConfigEntry<int> PercentKey { get; set; }

		internal ConfigEntry<int> InsideKey { get; set; }

		internal ConfigEntry<int> OutsideKey { get; set; }
	}
	internal class Lights
	{
		internal static void GGFlashlight()
		{
			NetHandler.Instance.FlickerLightsServerRpc(flickerFlash: true, disableFlash: false);
			Plugin.MoreLogs("nosfaratu is that you??");
		}

		internal static void FlipLights()
		{
			Plugin.MoreLogs("who turned out the lights??");
			NetHandler.Instance.FacilityBreakerServerRpc();
		}
	}
	internal class Mines
	{
		internal static void HandleMineBoom()
		{
			if (CodeStuff.myTerminalObjects.Count == 0)
			{
				return;
			}
			List<TerminalAccessibleObject> list = CodeStuff.myTerminalObjects.FindAll((TerminalAccessibleObject m) => (Object)(object)((Component)m).gameObject.GetComponent<Landmine>() != (Object)null && !((Component)m).gameObject.GetComponent<Landmine>().hasExploded);
			if (list.Count > 0)
			{
				int index = NumberStuff.Rand.Next(list.Count);
				Landmine component = ((Component)list[index]).gameObject.GetComponent<Landmine>();
				if (!component.hasExploded)
				{
					component.ExplodeMineClientRpc();
					component.ExplodeMineServerRpc();
					Plugin.MoreLogs("WHAT THE FUUUUUU-");
				}
			}
			else
			{
				Plugin.Spam("No landmines to go kaboom");
			}
		}
	}
	internal class Misc
	{
		internal static List<PlayerControllerB> GetAllLivingPlayers()
		{
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			Plugin.MoreLogs("Getting alive players");
			PlayerControllerB[] players = Plugin.instance.players;
			foreach (PlayerControllerB val in players)
			{
				if (!val.isPlayerDead && val.isPlayerControlled)
				{
					list.Add(val);
				}
			}
			return list;
		}

		internal static void LogTime()
		{
			string text = ((TMP_Text)HUDManager.Instance.clockNumber).text;
			string text2 = text.Replace("\n", "").Replace("\r", "");
			Plugin.MoreLogs("TIME: " + text2);
		}
	}
	public class NetHandler : NetworkBehaviour
	{
		public static NetHandler Instance { get; private set; }

		[ServerRpc(RequireOwnership = false)]
		public void BreatheOnWalkiesServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2364017171u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2364017171u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !((Object)(object)Plugin.instance.DressGirl == (Object)null))
				{
					Plugin.MoreLogs("SERVER: ghost breathing on all walkies");
					BreatheOnWalkiesClientRpc();
				}
			}
		}

		[ClientRpc]
		public void BreatheOnWalkiesClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3488792323u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3488792323u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					WalkieStuff.BreatheOnWalkiesFunc();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void GarbleWalkiesServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1741569032u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1741569032u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					Plugin.MoreLogs("SERVER: garbling all walkies");
					GarbleWalkiesClientRpc();
				}
			}
		}

		[ClientRpc]
		public void GarbleWalkiesClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1040546466u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1040546466u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					WalkieStuff.GarbleAllWalkiesFunc();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void ChangeDressGirlToPlayerServerRpc(string playerName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(139550563u, val, (RpcDelivery)0);
				bool flag = playerName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(playerName, false);
				}
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 139550563u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !((Object)(object)Plugin.instance.DressGirl == (Object)null))
			{
				Plugin.MoreLogs("SERVER: Changing dressgirl to " + playerName);
				ChangeDressGirlToPlayerClientRpc(playerName);
			}
		}

		[ClientRpc]
		public void ChangeDressGirlToPlayerClientRpc(string playerName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2913833147u, val, (RpcDelivery)0);
				bool flag = playerName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(playerName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2913833147u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				PlayerControllerB player = default(PlayerControllerB);
				if ((Object)(object)Plugin.instance.DressGirl == (Object)null)
				{
					Plugin.MoreLogs("DressGirl instance is null");
				}
				else if (Misc.TryGetPlayerFromName(playerName, ref player))
				{
					Plugin.instance.DressGirl.switchedHauntingPlayer = true;
					((MonoBehaviour)Plugin.instance.DressGirl).StartCoroutine(Plugin.instance.DressGirl.setSwitchingHauntingPlayer());
					DressGirl.ChangeHauntedPlayer(player);
					Plugin.MoreLogs("Changing haunted player to " + playerName);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void AlarmLightsServerRpc(bool normal)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3389752968u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref normal, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3389752968u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !(SetupConfig.RapidLightsColorValue.Value.ToLower() == "nochange") && !(SetupConfig.RapidLightsColorValue.Value.ToLower() == "default") && SetupConfig.RapidLightsColorValue.Value.Length != 0)
				{
					Plugin.MoreLogs("AlarmLights color ServerRpc");
					AlarmLightsClientRpc(normal);
				}
			}
		}

		[ClientRpc]
		public void AlarmLightsClientRpc(bool normalLights)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2480206829u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref normalLights, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2480206829u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			if (!normalLights)
			{
				Color32 val3 = Color32.op_Implicit(Misc.HexToColor(SetupConfig.RapidLightsColorValue.Value));
				for (int i = 0; i < RoundManager.Instance.allPoweredLights.Count; i++)
				{
					RoundManager.Instance.allPoweredLights[i].color = Color32.op_Implicit(val3);
				}
				Plugin.MoreLogs("Alarm lights set");
			}
			else if (normalLights)
			{
				for (int j = 0; j < RoundManager.Instance.allPoweredLights.Count; j++)
				{
					RoundManager.Instance.allPoweredLights[j].color = Color.white;
				}
				Plugin.MoreLogs("Lights set back to normal");
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void FlickerLightsServerRpc(bool flickerFlash, bool disableFlash)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1489712227u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flickerFlash, default(ForPrimitives));
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref disableFlash, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1489712227u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					FlickerLightsClientRpc(flickerFlash, disableFlash);
				}
			}
		}

		[ClientRpc]
		public void FlickerLightsClientRpc(bool flickerFlash, bool disableFlash)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(976836047u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flickerFlash, default(ForPrimitives));
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref disableFlash, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 976836047u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					RoundManager.Instance.FlickerLights(flickerFlash, disableFlash);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void FacilityBreakerServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1805593341u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1805593341u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					FacilityBreakerClientRpc();
				}
			}
		}

		[ClientRpc]
		public void FacilityBreakerClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1895890339u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1895890339u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			BreakerBox val3 = Object.FindObjectOfType<BreakerBox>();
			if ((Object)(object)val3 != (Object)null)
			{
				Plugin.GC.LogInfo((object)"flipping facility breaker for this client");
				if (val3.isPowerOn)
				{
					val3.SetSwitchesOff();
					RoundManager.Instance.TurnOnAllLights(false);
					GameNetworkManager.Instance.localPlayerController.JumpToFearLevel(0.2f, true);
				}
				else
				{
					val3.SwitchBreaker(true);
					RoundManager.Instance.TurnOnAllLights(true);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void ShockTerminalSoundServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1506833215u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1506833215u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ShockTerminalSoundClientRpc();
				}
			}
		}

		[ClientRpc]
		public void ShockTerminalSoundClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(711897171u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 711897171u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					SoundSystem.PlayTerminalSound(TerminalAdditions.Shock);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BatteryAdjustSoundServerRpc(int clientID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1275206633u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clientID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1275206633u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					BatteryAdjustSoundClientRpc(clientID);
				}
			}
		}

		[ClientRpc]
		public void BatteryAdjustSoundClientRpc(int clientID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(224827583u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientID);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 224827583u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				int clientID2 = clientID;
				PlayerControllerB val3 = Misc.GetAllLivingPlayers().Find((PlayerControllerB x) => (int)x.actualClientId == clientID2);
				val3.itemAudio.PlayOneShot(Items.Adjuster, 0.8f);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BatteryAdjustServerRpc(int clientID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3610163735u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clientID);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3610163735u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					BatteryAdjustClientRpc(clientID);
				}
			}
		}

		[ClientRpc]
		public void BatteryAdjustClientRpc(int clientID)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2028423813u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientID);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2028423813u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				int clientID2 = clientID;
				PlayerControllerB player = Misc.GetAllLivingPlayers().Find((PlayerControllerB x) => (int)x.actualClientId == clientID2);
				Items.PlayerAffectBatteries(player);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void RebootTerminalSpookyServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3644623586u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3644623586u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					RebootTerminalSpookyClientRpc();
				}
			}
		}

		[ClientRpc]
		public void RebootTerminalSpookyClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2