Decompiled source of AutomaticSignals v1.3.2

AutomaticSignals.dll

Decompiled 5 months ago
#define DEBUG
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutomaticSignals.Checkers;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TestAccount666.AutomaticSignals")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Make the signal translator great again!")]
[assembly: AssemblyFileVersion("1.3.2.0")]
[assembly: AssemblyInformationalVersion("1.3.2+b9ce9b411c670797dd3639b0e2c21ddf8cb4b728")]
[assembly: AssemblyProduct("AutomaticSignals")]
[assembly: AssemblyTitle("TestAccount666.AutomaticSignals")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AutomaticSignals
{
	[BepInPlugin("TestAccount666.AutomaticSignals", "AutomaticSignals", "1.3.2")]
	public class AutomaticSignals : BaseUnityPlugin
	{
		public static AutomaticSignals Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			InitializeConfig();
			Patch();
			Logger.LogInfo((object)"TestAccount666.AutomaticSignals v1.3.2 has loaded!");
			Logger.LogInfo((object)"Please don't forget, that this mod still needs some polishing!");
		}

		internal static void Patch()
		{
			//IL_000d: 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)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("TestAccount666.AutomaticSignals");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}

		public void InitializeConfig()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			IEnumerable<Type> enumerable = types.Where(Predicate);
			foreach (Type item in enumerable)
			{
				item.GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public)?.Invoke(null, new object[1] { ((BaseUnityPlugin)this).Config });
			}
		}

		private static bool Predicate(Type type)
		{
			return type.GetCustomAttributes(typeof(InitializeConfigAttribute), inherit: false).Length != 0;
		}
	}
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
	public class InitializeConfigAttribute : Attribute
	{
	}
	public static class Teleporter
	{
		internal static void TeleportPlayer(PlayerControllerB playerControllerB)
		{
			ShipTeleporter teleporter = GetTeleporter(inverseTeleporter: false);
			if (teleporter != null)
			{
				((MonoBehaviour)teleporter).StartCoroutine(BeamUpPlayer(playerControllerB, teleporter));
			}
		}

		internal static void TeleportPlayerToLocation(PlayerControllerB playerControllerB, Vector3 position)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			ShipTeleporter teleporter = GetTeleporter(inverseTeleporter: true);
			if (teleporter != null)
			{
				teleporter.TeleportPlayerOutWithInverseTeleporter((int)playerControllerB.playerClientId, position);
				teleporter.TeleportPlayerOutServerRpc((int)playerControllerB.playerClientId, position);
			}
		}

		internal static Random? GetTeleporterSeed()
		{
			ShipTeleporter teleporter = GetTeleporter(inverseTeleporter: true);
			return ((Object)(object)teleporter == (Object)null) ? null : teleporter.shipTeleporterSeed;
		}

		private static ShipTeleporter? GetTeleporter(bool inverseTeleporter)
		{
			ShipTeleporter[] source = Object.FindObjectsOfType<ShipTeleporter>();
			return ((IEnumerable<ShipTeleporter>)source).FirstOrDefault((Func<ShipTeleporter, bool>)((ShipTeleporter teleporter) => teleporter.isInverseTeleporter == inverseTeleporter));
		}

		private static IEnumerator BeamUpPlayer(PlayerControllerB? playerToTeleport, ShipTeleporter? teleporter)
		{
			if (teleporter == null)
			{
				yield break;
			}
			teleporter.shipTeleporterAudio.PlayOneShot(teleporter.teleporterSpinSFX);
			if (playerToTeleport == null || playerToTeleport.deadBody != null)
			{
				yield break;
			}
			teleporter.SetPlayerTeleporterId(playerToTeleport, 1);
			playerToTeleport.beamUpParticle.Play();
			playerToTeleport.movementAudio.PlayOneShot(teleporter.beamUpPlayerBodySFX);
			yield return (object)new WaitForSeconds(3f);
			if (playerToTeleport.deadBody == null)
			{
				playerToTeleport.DropAllHeldItems(true, false);
				AudioReverbPresets audioReverbPresets = Object.FindObjectOfType<AudioReverbPresets>();
				if (audioReverbPresets != null)
				{
					audioReverbPresets.audioPresets[3].ChangeAudioReverbForPlayer(playerToTeleport);
				}
				playerToTeleport.isInElevator = true;
				playerToTeleport.isInHangarShipRoom = true;
				playerToTeleport.isInsideFactory = false;
				playerToTeleport.averageVelocity = 0f;
				playerToTeleport.velocityLastFrame = Vector3.zero;
				playerToTeleport.TeleportPlayer(teleporter.teleporterPosition.position, true, 160f, false, true);
				teleporter.SetPlayerTeleporterId(playerToTeleport, -1);
				teleporter.shipTeleporterAudio.PlayOneShot(teleporter.teleporterBeamUpSFX);
				if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
				{
					HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
				}
			}
		}
	}
	public static class Transmitter
	{
		public static bool IsSignalTranslatorUnlocked()
		{
			return (from unlockableItem in StartOfRound.Instance.unlockablesList.unlockables
				where !unlockableItem.alreadyUnlocked
				where unlockableItem.hasBeenUnlockedByPlayer
				where !unlockableItem.inStorage
				select unlockableItem).Any((UnlockableItem unlockableItem) => unlockableItem.unlockableName.ToLower().Contains("translator"));
		}

		public static void SendMessage(string? message)
		{
			if (message == null)
			{
				return;
			}
			HUDManager instance = HUDManager.Instance;
			if (instance == null)
			{
				AutomaticSignals.Logger.LogFatal((object)"HudManager is null?!");
				return;
			}
			SignalTranslator val = Object.FindObjectOfType<SignalTranslator>();
			if (val == null)
			{
				AutomaticSignals.Logger.LogFatal((object)"SignalTranslator is null?!");
				return;
			}
			val.timeLastUsingSignalTranslator = Time.realtimeSinceStartup;
			if (val.signalTranslatorCoroutine != null)
			{
				((MonoBehaviour)instance).StopCoroutine(val.signalTranslatorCoroutine);
			}
			message = message.Substring(0, Mathf.Min(message.Length, 10));
			Coroutine signalTranslatorCoroutine = ((MonoBehaviour)instance).StartCoroutine(instance.DisplaySignalTranslatorMessage(message, val.timesSendingMessage = Math.Max(val.timesSendingMessage + 1, 1), val));
			val.signalTranslatorCoroutine = signalTranslatorCoroutine;
		}
	}
	public static class UnixTime
	{
		public static long GetCurrentTime()
		{
			return (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TestAccount666.AutomaticSignals";

		public const string PLUGIN_NAME = "AutomaticSignals";

		public const string PLUGIN_VERSION = "1.3.2";
	}
}
namespace AutomaticSignals.Patches
{
	[HarmonyPatch(typeof(ForestGiantAI))]
	public class ForestGiantPatch
	{
		[HarmonyPatch("BeginEatPlayer")]
		[HarmonyPostfix]
		public static void AfterBeginEatPlayer(PlayerControllerB playerBeingEaten)
		{
			if (StartOfRound.Instance != null && StartOfRound.Instance.localPlayerController != null && playerBeingEaten.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId && Transmitter.IsSignalTranslatorUnlocked())
			{
				GiantChecker.EatingProcessStart();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public static class PlayerControllerBPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void AfterUpdate(PlayerControllerB __instance)
		{
			if (StartOfRound.Instance != null && StartOfRound.Instance.localPlayerController != null && __instance.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId && Transmitter.IsSignalTranslatorUnlocked())
			{
				EnemyChecker.CheckForEnemies(__instance);
				ShakeChecker.CheckForShaking(__instance);
				BigDoorChecker.CheckForBigDoor(__instance);
				GiantChecker.Update(__instance);
				RadMechChecker.Update(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(RadMechAI))]
	public static class RadMechPatch
	{
		[HarmonyPatch("BeginTorchPlayer")]
		[HarmonyPrefix]
		private static void BeginTorchPlayerPrefix(PlayerControllerB playerBeingTorched)
		{
			if (StartOfRound.Instance != null && StartOfRound.Instance.localPlayerController != null && playerBeingTorched.playerClientId == StartOfRound.Instance.localPlayerController.playerClientId && Transmitter.IsSignalTranslatorUnlocked())
			{
				RadMechChecker.TorchingProcessStart();
			}
		}
	}
	[HarmonyPatch(typeof(Turret))]
	public static class TurretPatch
	{
		[HarmonyPatch("CheckForPlayersInLineOfSight")]
		[HarmonyPostfix]
		public static void AfterCheckForPlayersInLineOfSight(Turret __instance, ref PlayerControllerB __result)
		{
			if (Transmitter.IsSignalTranslatorUnlocked())
			{
				TurretChecker.CheckTurrets(__instance, ref __result);
			}
		}
	}
}
namespace AutomaticSignals.Checkers
{
	[InitializeConfig]
	public static class BigDoorChecker
	{
		private static ConfigEntry<int> _minimumDoorCoolDown = null;

		private static ConfigEntry<int> _maximumDoorCoolDown = null;

		private static ConfigEntry<int> _openChance = null;

		private static ConfigEntry<int> _malfunctionChance = null;

		private static long _nextDoorOpen;

		private static readonly Random _Random = new Random();

		public static void Initialize(ConfigFile configFile)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			_minimumDoorCoolDown = configFile.Bind<int>("Blast Doors", "1. Minimum cooldown", 15000, "Defines the minimum cooldown (in milliseconds) to wait before opening/closing a blast door");
			_maximumDoorCoolDown = configFile.Bind<int>("Blast Doors", "2. Maximum cooldown", 23000, "Defines the maximum cooldown (in milliseconds) to wait before opening/closing a blast door");
			_openChance = configFile.Bind<int>("Blast Doors", "3. Open chance", 40, new ConfigDescription("Defines the chance a blast door will open, if looked at", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_malfunctionChance = configFile.Bind<int>("Blast Doors", "4. Malfunction chance", 15, new ConfigDescription("Defines the chance a blast door will close, if looked at", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		public static void CheckForBigDoor(PlayerControllerB playerControllerB)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			Ray interactRay = playerControllerB.interactRay;
			float maxDistance = playerControllerB.grabDistance * 2f;
			TerminalAccessibleObject bigDoor = GetBigDoor(interactRay, maxDistance);
			if (bigDoor != null)
			{
				long currentTime = UnixTime.GetCurrentTime();
				if (currentTime >= _nextDoorOpen)
				{
					_nextDoorOpen = currentTime + _Random.Next(_minimumDoorCoolDown.Value, _maximumDoorCoolDown.Value);
					OpenOrMalfunctionDoor(bigDoor, bigDoor.isDoorOpen ? _malfunctionChance.Value : _openChance.Value);
				}
			}
		}

		private static TerminalAccessibleObject? GetBigDoor(Ray ray, float maxDistance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(ray, ref val, maxDistance))
			{
				return null;
			}
			if (!((Object)((Component)((RaycastHit)(ref val)).collider).gameObject).name.ToLower().Contains("bigdoor"))
			{
				return null;
			}
			return ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponent<TerminalAccessibleObject>();
		}

		private static void OpenOrMalfunctionDoor(TerminalAccessibleObject accessibleObject, int chance)
		{
			int num = _Random.Next(1, 101);
			if (num <= chance)
			{
				accessibleObject.CallFunctionFromTerminal();
			}
		}
	}
	[InitializeConfig]
	public static class EnemyChecker
	{
		private static ConfigEntry<int> _minimumMessageCoolDown = null;

		private static ConfigEntry<int> _maximumMessageCoolDown = null;

		private static ConfigEntry<int> _minimumWarnDistance = null;

		private static ConfigEntry<int> _warnChance = null;

		private static ConfigEntry<int> _nameEnemyChance = null;

		private static ConfigEntry<int> _idiotChance = null;

		private static ConfigEntry<int> _colorblindChance = null;

		private static long _nextEnemyMessage;

		private static readonly Random _Random = new Random();

		public static void Initialize(ConfigFile configFile)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			_minimumMessageCoolDown = configFile.Bind<int>("Enemy Warning", "1. Minimum message cooldown", 15000, "Defines the minimum cooldown (in milliseconds) to wait before warning about enemies");
			_maximumMessageCoolDown = configFile.Bind<int>("Enemy Warning", "2. Maximum message cooldown", 23000, "Defines the maximum cooldown (in milliseconds) to wait before warning about enemies");
			_minimumWarnDistance = configFile.Bind<int>("Enemy Warning", "3. Minimum warn distance", 20, "Defines the minimum distance the player needs to be to an enemy for a warning to be sent");
			_warnChance = configFile.Bind<int>("Enemy Warning", "4. Warn chance", 20, new ConfigDescription("Defines the chance for a player to be warned", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_nameEnemyChance = configFile.Bind<int>("Enemy Warning", "5. Name enemy chance", 15, new ConfigDescription("Defines the chance for sending the enemy type", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_idiotChance = configFile.Bind<int>("Enemy Warning", "6. Idiot chance", 15, new ConfigDescription("Defines the chance for saying \"Red Dot\" instead of \"Enemy\"", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_colorblindChance = configFile.Bind<int>("Enemy Warning", "7. Colorblind chance", 3, new ConfigDescription("Defines the chance for saying \"Blue Dot\" instead of \"Red Dot\"", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		internal static void CheckForEnemies(PlayerControllerB playerControllerB)
		{
			PlayerControllerB playerControllerB2 = playerControllerB;
			long currentTime = UnixTime.GetCurrentTime();
			if (_nextEnemyMessage > currentTime)
			{
				return;
			}
			int num = _Random.Next(1, 101);
			if (num > _warnChance.Value)
			{
				return;
			}
			using IEnumerator<EnemyAI> enumerator = (from spawnedEnemy in Object.FindObjectsOfType<EnemyAI>()
				where spawnedEnemy?.enemyType?.enemyName != null
				where !spawnedEnemy.isEnemyDead
				where spawnedEnemy.isOutside == !playerControllerB2.isInsideFactory
				where !ShouldIgnoreEnemy(spawnedEnemy.enemyType.enemyName)
				let distance = Vector3.Distance(((Component)playerControllerB2).transform.position, ((Component)spawnedEnemy).transform.position)
				where distance <= (float)_minimumWarnDistance.Value
				select spawnedEnemy).GetEnumerator();
			if (enumerator.MoveNext())
			{
				EnemyAI current = enumerator.Current;
				_nextEnemyMessage = currentTime + _Random.Next(_minimumMessageCoolDown.Value, _maximumMessageCoolDown.Value);
				Transmitter.SendMessage(GetEnemyName(current.enemyType.enemyName));
			}
		}

		private static bool ShouldIgnoreEnemy(string enemyName)
		{
			string text = enemyName.ToLower();
			if (1 == 0)
			{
			}
			bool result = text switch
			{
				"docile locust bees" => true, 
				"red locust bees" => true, 
				"manticoil" => true, 
				_ => false, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private static string GetEnemyName(string? enemyName)
		{
			if (enemyName == null)
			{
				return "";
			}
			int geniusChance = _Random.Next(1, 101);
			int idiotChance = _Random.Next(1, 101);
			int colorBlindChance = _Random.Next(1, 101);
			return IsIdiotOrDressGirl(geniusChance, enemyName) ? GetIdiotName(idiotChance, colorBlindChance) : GetGeniusEnemyName(enemyName);
		}

		private static bool IsIdiotOrDressGirl(int geniusChance, string enemyName)
		{
			return geniusChance >= _nameEnemyChance.Value || enemyName.ToLower().Equals("girl");
		}

		private static string GetIdiotName(int idiotChance, int colorBlindChance)
		{
			if (idiotChance <= _idiotChance.Value && colorBlindChance <= _colorblindChance.Value)
			{
				return "Blue Dot";
			}
			return (idiotChance <= _idiotChance.Value) ? "Red Dot" : "Enemy";
		}

		private static string GetGeniusEnemyName(string enemyName)
		{
			string text = enemyName.ToLower();
			if (1 == 0)
			{
			}
			string result = text switch
			{
				"radmech" => "Old Bird", 
				"flowerman" => GetFlowermanName(), 
				"centipede" => "Snare Flea", 
				"earth leviathan" => "Worm", 
				"mouthdog" => GetMouthDogName(), 
				"forestgiant" => "Giant", 
				"crawler" => "Thumper", 
				"bunker spider" => GetSpiderName(), 
				"masked" => GetMaskedName(), 
				"spring" => "Coil Head", 
				"puffer" => "Lizard", 
				"baboon hawk" => "Bird", 
				"hoarding bug" => GetLootBugName(), 
				"butler" => GetButlerName(), 
				_ => enemyName, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private static string GetButlerName()
		{
			return (_Random.Next(1, 101) > 5) ? "Butler" : "Buttler";
		}

		private static string GetFlowermanName()
		{
			return (_Random.Next(1, 101) > 7) ? "Bracken" : ((_Random.Next(1, 101) >= 50) ? "Behind You" : "Behind U");
		}

		private static string GetMouthDogName()
		{
			return (_Random.Next(1, 101) > 5) ? "Dog" : "Doggo";
		}

		private static string GetSpiderName()
		{
			return (_Random.Next(1, 101) > 5) ? "Spider" : "Spooder";
		}

		private static string GetMaskedName()
		{
			return (_Random.Next(1, 101) > 45) ? "Masked" : "Mimic";
		}

		private static string GetLootBugName()
		{
			return (_Random.Next(1, 101) > 4) ? "Loot Bug" : "Yippee Bug";
		}
	}
	[InitializeConfig]
	public static class GiantChecker
	{
		private static ConfigEntry<int> _minimumTeleportCoolDown = null;

		private static ConfigEntry<int> _maximumTeleportCoolDown = null;

		private static ConfigEntry<int> _minimumTimeWaiting = null;

		private static ConfigEntry<int> _maximumTimeWaiting = null;

		private static ConfigEntry<int> _teleportChance = null;

		private static long _nextTeleport;

		private static readonly Random _Random = new Random();

		private static bool _isBeingEaten;

		private static long _teleport;

		public static void Initialize(ConfigFile configFile)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			_minimumTeleportCoolDown = configFile.Bind<int>("Giants", "1. Minimum teleport cooldown", 1000, "Defines the minimum cooldown (in milliseconds) to wait before teleporting a player that is being eaten");
			_maximumTeleportCoolDown = configFile.Bind<int>("Giants", "2. Maximum teleport cooldown", 20000, "Defines the maximum cooldown (in milliseconds) to wait before teleporting a player that is being eaten");
			_minimumTimeWaiting = configFile.Bind<int>("Giants", "3. Minimum teleport delay", 1000, "Defines the minimum delay (in milliseconds) to wait before actually trying to teleport a player that is being eaten");
			_maximumTimeWaiting = configFile.Bind<int>("Giants", "4. Maximum teleport delay", 2600, "Defines the maximum delay (in milliseconds) to wait before actually trying to teleport a player that is being eaten");
			_teleportChance = configFile.Bind<int>("Giants", "5. Teleport chance", 70, new ConfigDescription("Defines the chance for teleporting a player that is being eaten", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		public static void Update(PlayerControllerB playerControllerB)
		{
			if (_isBeingEaten)
			{
				long currentTime = UnixTime.GetCurrentTime();
				if (_teleport <= currentTime)
				{
					Teleporter.TeleportPlayer(playerControllerB);
					_isBeingEaten = false;
				}
			}
		}

		public static void EatingProcessStart()
		{
			long currentTime = UnixTime.GetCurrentTime();
			if (_nextTeleport <= currentTime)
			{
				_nextTeleport = currentTime + _Random.Next(_minimumTeleportCoolDown.Value, _maximumTeleportCoolDown.Value);
				int num = _Random.Next(1, 101);
				if (num <= _teleportChance.Value)
				{
					int num2 = _Random.Next(_minimumTimeWaiting.Value, _maximumTimeWaiting.Value);
					_teleport = currentTime + num2;
					_isBeingEaten = true;
				}
			}
		}
	}
	[InitializeConfig]
	public static class RadMechChecker
	{
		private static ConfigEntry<int> _minimumTeleportCoolDown = null;

		private static ConfigEntry<int> _maximumTeleportCoolDown = null;

		private static ConfigEntry<int> _minimumTimeWaiting = null;

		private static ConfigEntry<int> _maximumTimeWaiting = null;

		private static ConfigEntry<int> _teleportChance = null;

		private static long _nextTeleport;

		private static readonly Random _Random = new Random();

		private static bool _isBeingTorched;

		private static long _teleport;

		public static void Initialize(ConfigFile configFile)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			_minimumTeleportCoolDown = configFile.Bind<int>("Old Birds", "1. Minimum teleport cooldown", 1000, "Defines the minimum cooldown (in milliseconds) to wait before teleporting a player that is being torched");
			_maximumTeleportCoolDown = configFile.Bind<int>("Old Birds", "2. Maximum teleport cooldown", 20000, "Defines the maximum cooldown (in milliseconds) to wait before teleporting a player that is being torched");
			_minimumTimeWaiting = configFile.Bind<int>("Old Birds", "3. Minimum teleport delay", 300, "Defines the minimum delay (in milliseconds) to wait before actually trying to teleport a player that is being torched");
			_maximumTimeWaiting = configFile.Bind<int>("Old Birds", "4. Maximum teleport delay", 1200, "Defines the maximum delay (in milliseconds) to wait before actually trying to teleport a player that is being torched");
			_teleportChance = configFile.Bind<int>("Old Birds", "5. Teleport chance", 70, new ConfigDescription("Defines the chance for teleporting a player that is being torched", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		public static void Update(PlayerControllerB playerControllerB)
		{
			if (_isBeingTorched)
			{
				long currentTime = UnixTime.GetCurrentTime();
				if (_teleport <= currentTime)
				{
					Teleporter.TeleportPlayer(playerControllerB);
					_isBeingTorched = false;
				}
			}
		}

		public static void TorchingProcessStart()
		{
			long currentTime = UnixTime.GetCurrentTime();
			if (_nextTeleport <= currentTime)
			{
				_nextTeleport = currentTime + _Random.Next(_minimumTeleportCoolDown.Value, _maximumTeleportCoolDown.Value);
				int num = _Random.Next(1, 101);
				if (num <= _teleportChance.Value)
				{
					int num2 = _Random.Next(_minimumTimeWaiting.Value, _maximumTimeWaiting.Value);
					_teleport = currentTime + num2;
					_isBeingTorched = true;
				}
			}
		}
	}
	[InitializeConfig]
	public static class ShakeChecker
	{
		private static ConfigEntry<int> _minimumTeleportCoolDown = null;

		private static ConfigEntry<int> _maximumTeleportCoolDown = null;

		private static ConfigEntry<int> _rotationAccumulationThreshold = null;

		private static ConfigEntry<int> _teleportChance = null;

		private static ConfigEntry<bool> _teleportEnabled = null;

		private static ConfigEntry<bool> _malfunctionTeleportEnabled = null;

		private static ConfigEntry<int> _maximumPeopleAlive = null;

		private static Quaternion _previousRotation;

		private static float _accumulatedRotationDifference;

		private static readonly Random _Random = new Random();

		private static bool _initialized;

		private static PlayerControllerB? _playerControllerB;

		private static long _nextTeleport;

		public static void Initialize(ConfigFile configFile)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			_minimumTeleportCoolDown = configFile.Bind<int>("Panicking Player", "1. Minimum teleport cooldown", 24000, "Defines the minimum cooldown (in milliseconds) to wait before an emergency teleport can occur");
			_maximumTeleportCoolDown = configFile.Bind<int>("Panicking Player", "2. Maximum teleport cooldown", 30000, "Defines the maximum cooldown (in milliseconds) to wait before an emergency teleport can occur");
			_rotationAccumulationThreshold = configFile.Bind<int>("Panicking Player", "3. Rotation Accumulation Threshold", 1600, "Defines the accumulated rotation threshold before an emergency teleportation is being registered (Lower Number = More sensitive, Higher Number = Less Sensitive)");
			_teleportChance = configFile.Bind<int>("Panicking Player", "4. Teleport Chance", 80, new ConfigDescription("Defines the chance of being teleported back to the ship. If not met, will teleport player to a random position inside the facility", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			_teleportEnabled = configFile.Bind<bool>("Panicking Player", "5. Teleport Enabled", true, "If true, will enable the emergency teleport");
			_malfunctionTeleportEnabled = configFile.Bind<bool>("Panicking Player", "6. Malfunction Teleport Enabled", true, "If true, will enable the malfunctional emergency teleport (Requires emergency teleport)");
			_maximumPeopleAlive = configFile.Bind<int>("Panicking Player", "7. Maximum people alive", 1, "Defines how many people can be alive to enable the emergency teleport");
		}

		public static void CheckForShaking(PlayerControllerB playerControllerB)
		{
			if (_teleportEnabled.Value)
			{
				if (_playerControllerB == null || (Object)(object)_playerControllerB != (Object)(object)playerControllerB)
				{
					_playerControllerB = playerControllerB;
				}
				if (!_initialized)
				{
					Start();
				}
				Update();
			}
		}

		private static void Start()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Debug.Assert((Object)(object)_playerControllerB != (Object)null, "_playerControllerB != null");
			_previousRotation = ((Component)_playerControllerB).transform.rotation;
			_initialized = true;
		}

		private static void Update()
		{
			CalculateRotationDifference();
			CheckForTeleportation();
		}

		private static void CalculateRotationDifference()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Debug.Assert((Object)(object)_playerControllerB != (Object)null, "_playerControllerB != null");
			Quaternion rotation = ((Component)_playerControllerB).transform.rotation;
			float num = Quaternion.Angle(_previousRotation, rotation);
			_previousRotation = rotation;
			_accumulatedRotationDifference += num;
			if (!(num > 0.2f))
			{
				_accumulatedRotationDifference = 0f;
			}
		}

		private static void CheckForTeleportation()
		{
			if (!(_accumulatedRotationDifference >= (float)_rotationAccumulationThreshold.Value))
			{
				return;
			}
			_accumulatedRotationDifference = 0f;
			long currentTime = UnixTime.GetCurrentTime();
			if (_nextTeleport > currentTime)
			{
				return;
			}
			_nextTeleport = currentTime + _Random.Next(_minimumTeleportCoolDown.Value, _maximumTeleportCoolDown.Value);
			int num = StartOfRound.Instance.allPlayerScripts.Where(delegate(PlayerControllerB player)
			{
				if (player == null)
				{
					return false;
				}
				return player.isPlayerControlled && !player.isPlayerDead;
			}).Count();
			if (num <= _maximumPeopleAlive.Value)
			{
				if (_Random.Next(1, 101) > _teleportChance.Value)
				{
					TeleportMalfunction();
					return;
				}
				Debug.Assert((Object)(object)_playerControllerB != (Object)null, "_playerControllerB != null");
				Teleporter.TeleportPlayer(_playerControllerB);
			}
		}

		private static void TeleportMalfunction()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (_malfunctionTeleportEnabled.Value && RoundManager.Instance.insideAINodes.Length != 0)
			{
				Vector3? randomTeleportPosition = GetRandomTeleportPosition();
				if (randomTeleportPosition.HasValue)
				{
					Debug.Assert((Object)(object)_playerControllerB != (Object)null, "_playerControllerB != null");
					Teleporter.TeleportPlayerToLocation(_playerControllerB, randomTeleportPosition.Value);
				}
			}
		}

		private static Vector3? GetRandomTeleportPosition()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Random teleporterSeed = Teleporter.GetTeleporterSeed();
			if (teleporterSeed == null)
			{
				return null;
			}
			Vector3 position = RoundManager.Instance.insideAINodes[teleporterSeed.Next(0, RoundManager.Instance.insideAINodes.Length)].transform.position;
			RoundManager instance = RoundManager.Instance;
			Random random = teleporterSeed;
			return instance.GetRandomNavMeshPositionInBoxPredictable(position, 10f, default(NavMeshHit), random, -1);
		}
	}
	[InitializeConfig]
	public static class TurretChecker
	{
		private static ConfigEntry<int> _minimumTurretCoolDown = null;

		private static ConfigEntry<int> _maximumTurretCoolDown = null;

		private static ConfigEntry<int> _malfunctionChance = null;

		private static long _nextTurretDisable;

		private static readonly Random _Random = new Random();

		public static void Initialize(ConfigFile configFile)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			_minimumTurretCoolDown = configFile.Bind<int>("Turrets", "1. Minimum deactivate cooldown", 20000, "Defines the minimum cooldown (in milliseconds) to wait before deactivating a turret again");
			_maximumTurretCoolDown = configFile.Bind<int>("Turrets", "2. Maximum deactivate cooldown", 40000, "Defines the maximum cooldown (in milliseconds) to wait before deactivating a turret again");
			_malfunctionChance = configFile.Bind<int>("Turrets", "3. Malfunction Chance", 15, new ConfigDescription("Defines the chance for deactivating a turret to fail", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		public static void CheckTurrets(Turret turret, ref PlayerControllerB result)
		{
			long currentTime = UnixTime.GetCurrentTime();
			if (_nextTurretDisable > currentTime || (Object)(object)result == (Object)null || result.playerClientId != StartOfRound.Instance.localPlayerController.playerClientId)
			{
				return;
			}
			TerminalAccessibleObject component = ((Component)turret).GetComponent<TerminalAccessibleObject>();
			if (component == null)
			{
				AutomaticSignals.Logger.LogFatal((object)"No TerminalAccessibleObject assigned to turret!");
				return;
			}
			_nextTurretDisable = currentTime + _Random.Next(_minimumTurretCoolDown.Value, _maximumTurretCoolDown.Value);
			int num = _Random.Next(1, 101);
			if (num > _malfunctionChance.Value)
			{
				component.CallFunctionFromTerminal();
				result = null;
			}
		}
	}
}