Decompiled source of LethalFixes v1.2.4

BepInEx/plugins/LethalFixes/uk.1a3.lethalfixes.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using LethalFixes.Patches;
using Microsoft.CodeAnalysis;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("uk.1a3.lethalfixes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.4.0")]
[assembly: AssemblyInformationalVersion("1.2.4+517384d60457c9334b33376366f449baa9cfb35d")]
[assembly: AssemblyProduct("LethalFixes")]
[assembly: AssemblyTitle("uk.1a3.lethalfixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalFixes
{
	[BepInPlugin("uk.1a3.lethalfixes", "LethalFixes", "1.2.4")]
	internal class PluginLoader : BaseUnityPlugin
	{
		internal static readonly Harmony harmony = new Harmony("uk.1a3.lethalfixes");

		private static bool initialized;

		internal static ManualLogSource logSource;

		public static PluginLoader Instance { get; private set; }

		private void Awake()
		{
			if (initialized)
			{
				return;
			}
			initialized = true;
			Instance = this;
			logSource = ((BaseUnityPlugin)this).Logger;
			FixesConfig.InitConfig();
			int num = FixesConfig.LogLevelDissonance.Value;
			if (num < 0 || num > 4)
			{
				if (num != -1)
				{
					FixesConfig.LogLevelDissonance.Value = -1;
					((BaseUnityPlugin)this).Config.Save();
				}
				num = 4;
			}
			Logs.SetLogLevel((LogCategory)1, (LogLevel)num);
			Logs.SetLogLevel((LogCategory)3, (LogLevel)num);
			Logs.SetLogLevel((LogCategory)2, (LogLevel)num);
			harmony.PatchAll(typeof(Patches_General));
			harmony.PatchAll(typeof(Patches_Enemy));
			harmony.PatchAll(typeof(Patches_Hazards));
			harmony.PatchAll(typeof(Patches_UI));
			logSource.LogInfo((object)"Patches Loaded");
		}

		public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
		{
			config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
		}

		public static int GetCurrentGameVersion()
		{
			int gameVersionNum = GameNetworkManager.Instance.gameVersionNum;
			if (gameVersionNum >= 16480)
			{
				return gameVersionNum - 16440;
			}
			if (gameVersionNum >= 9999)
			{
				return gameVersionNum - 9950;
			}
			return gameVersionNum;
		}
	}
	internal class FixesConfig
	{
		public static List<string> lightShadowItems = new List<string> { "FancyLamp", "LungApparatus" };

		public static Dictionary<string, LightShadows> lightShadowDefaults = new Dictionary<string, LightShadows>();

		internal static ConfigEntry<bool> ExactItemScan;

		internal static ConfigEntry<bool> PropShadows;

		internal static ConfigEntry<bool> VACSpeakingIndicator;

		internal static ConfigEntry<bool> ModTerminalScan;

		internal static ConfigEntry<bool> SpikeTrapActivateSound;

		internal static ConfigEntry<bool> SpikeTrapDeactivateSound;

		internal static ConfigEntry<bool> SpikeTrapSafetyInverse;

		internal static ConfigEntry<int> LogLevelDissonance;

		internal static ConfigEntry<int> LogLevelNetworkManager;

		internal static void InitConfig()
		{
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			PluginLoader.Instance.BindConfig(ref ExactItemScan, "Settings", "Exact Item Scan", defaultValue: false, "Should the terminal scan command show the exact total value?");
			PluginLoader.Instance.BindConfig(ref PropShadows, "Settings", "Prop Shadows", defaultValue: false, "Setting this to false will disable prop shadows to improve performance.");
			PluginLoader.Instance.BindConfig(ref VACSpeakingIndicator, "Settings", "Voice Activity Icon", defaultValue: true, "Should the PTT speaking indicator be visible whilst using voice activation?");
			PluginLoader.Instance.BindConfig(ref ModTerminalScan, "Compatibility", "Terminal Scan Command", defaultValue: true, "Should the terminal scan command be modified by this mod?");
			PluginLoader.Instance.BindConfig(ref SpikeTrapActivateSound, "Spike Trap", "Sound On Enable", defaultValue: false, "Should spike traps make a sound when re-enabled after being disabled via the terminal?");
			PluginLoader.Instance.BindConfig(ref SpikeTrapDeactivateSound, "Spike Trap", "Sound On Disable", defaultValue: true, "Should spike traps make a sound when disabled via the terminal?");
			PluginLoader.Instance.BindConfig(ref SpikeTrapSafetyInverse, "Spike Trap", "Inverse Teleport Safety", defaultValue: false, "Should spike traps have the safe period if a player inverse teleports underneath?");
			AcceptableValueRange<int> val = new AcceptableValueRange<int>(-1, 4);
			LogLevelDissonance = ((BaseUnityPlugin)PluginLoader.Instance).Config.Bind<int>("Debug", "Log Level (Dissonance)", -1, new ConfigDescription("-1 = Mod Default, 0 = Trace, 1 = Debug, 2 = Info, 3 = Warn, 4 = Error", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			AcceptableValueRange<int> val2 = new AcceptableValueRange<int>(-1, 3);
			LogLevelNetworkManager = ((BaseUnityPlugin)PluginLoader.Instance).Config.Bind<int>("Debug", "Log Level (NetworkManager)", -1, new ConfigDescription("-1 = Mod Default, 0 = Developer, 1 = Normal, 2 = Error, 3 = Nothing", (AcceptableValueBase)(object)val2, Array.Empty<object>()));
			PropShadows.SettingChanged += delegate
			{
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090->IL0090: Incompatible stack types: O vs I4
				//IL_007b->IL0090: Incompatible stack types: I4 vs O
				//IL_007b->IL0090: Incompatible stack types: O vs I4
				GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)0);
				foreach (GrabbableObject val3 in array)
				{
					if (lightShadowItems.Contains(((Object)val3.itemProperties).name))
					{
						Light componentInChildren = ((Component)val3).GetComponentInChildren<Light>();
						if ((Object)(object)componentInChildren != (Object)null)
						{
							if (!lightShadowDefaults.ContainsKey(((Object)val3.itemProperties).name))
							{
								lightShadowDefaults.Add(((Object)val3.itemProperties).name, componentInChildren.shadows);
							}
							object obj = componentInChildren;
							int num;
							if (PropShadows.Value)
							{
								obj = lightShadowDefaults[((Object)val3.itemProperties).name];
								num = (int)obj;
							}
							else
							{
								num = 0;
								obj = num;
								num = (int)obj;
							}
							((Light)num).shadows = (LightShadows)obj;
						}
					}
				}
			};
		}
	}
	[HarmonyPatch]
	internal static class Patches_General
	{
		[HarmonyPatch(typeof(NetworkManager), "Awake")]
		[HarmonyPostfix]
		private static void Fix_RPCLogLevel(NetworkManager __instance)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			int num = FixesConfig.LogLevelNetworkManager.Value;
			if (num < 0 || num > 3)
			{
				if (num != -1)
				{
					FixesConfig.LogLevelNetworkManager.Value = -1;
					((BaseUnityPlugin)PluginLoader.Instance).Config.Save();
				}
				num = 1;
			}
			__instance.LogLevel = (LogLevel)num;
		}

		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		[HarmonyPostfix]
		[HarmonyPriority(800)]
		public static void Fix_OnItemStart(GrabbableObject __instance)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.itemProperties.isConductiveMetal)
			{
				StormyWeather val = Object.FindFirstObjectByType<StormyWeather>();
				if ((Object)(object)val != (Object)null && val.metalObjects.Count > 0 && !val.metalObjects.Contains(__instance))
				{
					val.metalObjects.Add(__instance);
				}
			}
			if (FixesConfig.PropShadows.Value || !FixesConfig.lightShadowItems.Contains(((Object)__instance.itemProperties).name))
			{
				return;
			}
			Light componentInChildren = ((Component)__instance).GetComponentInChildren<Light>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if (!FixesConfig.lightShadowDefaults.ContainsKey(((Object)__instance.itemProperties).name))
				{
					FixesConfig.lightShadowDefaults.Add(((Object)__instance.itemProperties).name, componentInChildren.shadows);
				}
				componentInChildren.shadows = (LightShadows)0;
			}
		}

		[HarmonyPatch(typeof(NetworkBehaviour), "OnDestroy")]
		[HarmonyPostfix]
		public static void StormyFix_OnItemDestroy(NetworkBehaviour __instance)
		{
			GrabbableObject val = (GrabbableObject)(object)((__instance is GrabbableObject) ? __instance : null);
			if (val != null)
			{
				StormyWeather val2 = Object.FindFirstObjectByType<StormyWeather>();
				if ((Object)(object)val2 != (Object)null && val2.metalObjects.Contains(val))
				{
					val2.metalObjects.Remove(val);
				}
			}
		}

		[HarmonyPatch(typeof(StormyWeather), "OnDisable")]
		[HarmonyPostfix]
		public static void StormyFix_OnDisable(StormyWeather __instance)
		{
			__instance.metalObjects.Clear();
		}

		[HarmonyPatch(typeof(StartMatchLever), "BeginHoldingInteractOnLever")]
		[HarmonyPostfix]
		public static void Fix_LeverDeadline(StartMatchLever __instance)
		{
			if (TimeOfDay.Instance.daysUntilDeadline <= 0 && __instance.playersManager.inShipPhase && StartOfRound.Instance.currentLevel.planetHasTime)
			{
				__instance.triggerScript.timeToHold = 4f;
			}
			else
			{
				__instance.triggerScript.timeToHold = 0.7f;
			}
		}

		[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
		[HarmonyPrefix]
		public static void Fix_TerminalScan(ref string modifiedDisplayText)
		{
			if (!FixesConfig.ModTerminalScan.Value || !modifiedDisplayText.Contains("[scanForItems]"))
			{
				return;
			}
			Random random = new Random(StartOfRound.Instance.randomMapSeed + 91);
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsSortMode)1);
			for (int i = 0; i < array.Length; i++)
			{
				if (!array[i].itemProperties.isScrap)
				{
					continue;
				}
				if (!array[i].isInShipRoom && !array[i].isInElevator)
				{
					if (FixesConfig.ExactItemScan.Value)
					{
						num2 += array[i].scrapValue;
					}
					else if (array[i].itemProperties.maxValue >= array[i].itemProperties.minValue)
					{
						num2 += Mathf.Clamp((int)((float)random.Next(array[i].itemProperties.minValue, array[i].itemProperties.maxValue) * RoundManager.Instance.scrapValueMultiplier), array[i].scrapValue - 6 * num, array[i].scrapValue + 9 * num);
					}
					num++;
				}
				else
				{
					if (FixesConfig.ExactItemScan.Value)
					{
						num4 += array[i].scrapValue;
					}
					else if (array[i].itemProperties.maxValue >= array[i].itemProperties.minValue)
					{
						num4 += Mathf.Clamp((int)((float)random.Next(array[i].itemProperties.minValue, array[i].itemProperties.maxValue) * RoundManager.Instance.scrapValueMultiplier), array[i].scrapValue - 6 * num3, array[i].scrapValue + 9 * num3);
					}
					num3++;
				}
			}
			if (FixesConfig.ExactItemScan.Value)
			{
				modifiedDisplayText = modifiedDisplayText.Replace("[scanForItems]", $"There are {num} objects outside the ship, totalling at an exact value of ${num2}.");
			}
			else
			{
				modifiedDisplayText = modifiedDisplayText.Replace("[scanForItems]", $"There are {num} objects outside the ship, totalling at an approximate value of ${num2}.");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "KickPlayer")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> KickPlayer_Reason(IEnumerable<CodeInstruction> instructions)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			bool flag = false;
			bool flag2 = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (!flag2)
				{
					if (!flag && instruction.opcode == OpCodes.Ldfld && instruction.operand?.ToString() == "System.UInt64 actualClientId")
					{
						flag = true;
						list.Add(instruction);
						CodeInstruction item = new CodeInstruction(OpCodes.Ldstr, (object)"You have been kicked.");
						list.Add(item);
						continue;
					}
					if (flag && instruction.opcode == OpCodes.Callvirt && instruction.operand?.ToString() == "Void DisconnectClient(UInt64)")
					{
						flag2 = true;
						instruction.operand = AccessTools.Method(typeof(NetworkManager), "DisconnectClient", new Type[2]
						{
							typeof(ulong),
							typeof(string)
						}, (Type[])null);
					}
				}
				list.Add(instruction);
			}
			if (!flag2)
			{
				PluginLoader.logSource.LogWarning((object)"KickPlayer failed to add reason");
			}
			IEnumerable<CodeInstruction> source;
			if (!flag2)
			{
				source = instructions;
			}
			else
			{
				IEnumerable<CodeInstruction> enumerable = list;
				source = enumerable;
			}
			return source.AsEnumerable();
		}

		[HarmonyPatch(typeof(HUDManager), "SetSavedValues")]
		[HarmonyPostfix]
		private static void HUDSetSavedValues(HUDManager __instance)
		{
			if (((NetworkBehaviour)__instance).IsHost)
			{
				GameNetworkManager.Instance.localPlayerController.playerLevelNumber = __instance.localPlayerLevel;
			}
		}

		[HarmonyPatch(typeof(VehicleController), "SetPassengerInCar")]
		[HarmonyPrefix]
		private static bool SetPassengerInCar(PlayerControllerB player)
		{
			return (Object)(object)player != (Object)null;
		}

		[HarmonyPatch(typeof(VehicleController), "SetCarEffects")]
		[HarmonyPrefix]
		public static void SetCarEffects(VehicleController __instance, ref float setSteering, ref float ___steeringWheelAnimFloat)
		{
			setSteering = 0f;
			___steeringWheelAnimFloat = __instance.steeringInput / 6f;
		}

		public static IEnumerator CancelSpecialTriggerAnimationsAfterDelay(VehicleController __instance)
		{
			yield return (object)new WaitForSeconds(1f);
			object obj;
			if (__instance == null)
			{
				obj = null;
			}
			else
			{
				Transform transform = ((Component)__instance).transform;
				if (transform == null)
				{
					obj = null;
				}
				else
				{
					Transform obj2 = transform.Find("Triggers/DriverSide/DriverSeatTrigger");
					obj = ((obj2 != null) ? ((Component)obj2).GetComponent<InteractTrigger>() : null);
				}
			}
			InteractTrigger val = (InteractTrigger)obj;
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController.currentTriggerInAnimationWith == (Object)(object)val)
			{
				localPlayerController.CancelSpecialTriggerAnimations();
				PluginLoader.logSource.LogInfo((object)"[TakeControlOfVehicle] Forced player out of drivers seat");
			}
		}

		[HarmonyPatch(typeof(VehicleController), "TakeControlOfVehicle")]
		[HarmonyPostfix]
		public static void TakeControlOfVehicle(VehicleController __instance)
		{
			if (!__instance.localPlayerInControl)
			{
				((MonoBehaviour)__instance).StartCoroutine(CancelSpecialTriggerAnimationsAfterDelay(__instance));
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "uk.1a3.lethalfixes";

		public const string PLUGIN_NAME = "LethalFixes";

		public const string PLUGIN_VERSION = "1.2.4";
	}
}
namespace LethalFixes.Patches
{
	[HarmonyPatch]
	internal static class Patches_Enemy
	{
		internal static Dictionary<string, int> outsideObjectWidths = new Dictionary<string, int>();

		internal static List<Transform> cachedOutsideObjects = new List<Transform>();

		public static bool ShouldDenyLocation(GameObject[] spawnDenialPoints, Vector3 spawnPosition)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			for (int i = 0; i < spawnDenialPoints.Length; i++)
			{
				if (Vector3.Distance(spawnPosition, spawnDenialPoints[i].transform.position) < 16f)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				foreach (Transform cachedOutsideObject in cachedOutsideObjects)
				{
					if (!((Object)(object)cachedOutsideObject == (Object)null))
					{
						string key = ((Object)cachedOutsideObject).name.Replace("(Clone)", "");
						if (outsideObjectWidths.ContainsKey(key) && Vector3.Distance(spawnPosition, cachedOutsideObject.position) <= (float)outsideObjectWidths[key])
						{
							flag = true;
							break;
						}
					}
				}
			}
			return flag;
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnMapObjects")]
		[HarmonyPostfix]
		public static void Fix_OutdoorEnemySpawn_CacheValues(RoundManager __instance)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			outsideObjectWidths.Clear();
			cachedOutsideObjects.Clear();
			if (__instance.currentLevel.spawnableMapObjects.Length >= 1)
			{
				SpawnableOutsideObject[] array = __instance.currentLevel.spawnableOutsideObjects.Select((SpawnableOutsideObjectWithRarity x) => x.spawnableObject).ToArray();
				foreach (SpawnableOutsideObject val in array)
				{
					if ((Object)(object)val.prefabToSpawn != (Object)null && !outsideObjectWidths.ContainsKey(((Object)val.prefabToSpawn).name))
					{
						outsideObjectWidths.Add(((Object)val.prefabToSpawn).name, val.objectWidth);
					}
				}
				foreach (Transform item in __instance.mapPropsContainer.transform)
				{
					Transform val2 = item;
					if ((Object)(object)val2 != (Object)null && outsideObjectWidths.ContainsKey(((Object)val2).name.Replace("(Clone)", "")))
					{
						cachedOutsideObjects.Add(val2);
					}
				}
			}
			PluginLoader.logSource.LogInfo((object)$"Cached {cachedOutsideObjects.Count} Outside Map Objects");
		}

		[HarmonyPatch(typeof(RoundManager), "PositionWithDenialPointsChecked")]
		[HarmonyPrefix]
		public static bool Fix_OutdoorEnemySpawn_Denial(ref RoundManager __instance, ref Vector3 __result, Vector3 spawnPosition, GameObject[] spawnPoints, EnemyType enemyType)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (spawnPoints.Length == 0)
			{
				return true;
			}
			if (ShouldDenyLocation(__instance.spawnDenialPoints, spawnPosition))
			{
				bool flag = false;
				List<Vector3> list = (from x in spawnPoints
					select x.transform.position into x
					orderby Vector3.Distance(spawnPosition, x)
					select x).ToList();
				while (!flag && list.Count > 0)
				{
					Vector3 val = list[0];
					list.RemoveAt(0);
					if (!ShouldDenyLocation(__instance.spawnDenialPoints, val))
					{
						Vector3 randomNavMeshPositionInBoxPredictable = __instance.GetRandomNavMeshPositionInBoxPredictable(val, 10f, default(NavMeshHit), __instance.AnomalyRandom, __instance.GetLayermaskForEnemySizeLimit(enemyType));
						if (!ShouldDenyLocation(__instance.spawnDenialPoints, randomNavMeshPositionInBoxPredictable))
						{
							flag = true;
							__result = randomNavMeshPositionInBoxPredictable;
							break;
						}
					}
				}
				if (!flag)
				{
					__result = spawnPosition;
				}
			}
			else
			{
				__result = spawnPosition;
			}
			return false;
		}

		[HarmonyPatch(typeof(EnemyAI), "Start")]
		[HarmonyPostfix]
		public static void EnemyAI_Start(EnemyAI __instance)
		{
			if ((Object)(object)__instance.dieSFX == (Object)null && (Object)(object)__instance.enemyType.deathSFX != (Object)null && (__instance is BaboonBirdAI || __instance is HoarderBugAI || __instance is NutcrackerEnemyAI))
			{
				__instance.dieSFX = __instance.enemyType.deathSFX;
			}
		}

		[HarmonyPatch(typeof(RadMechAI), "Update")]
		[HarmonyPrefix]
		public static void RadMech_SetFinishingFlight(RadMechAI __instance, ref bool ___finishingFlight, ref bool ___inFlyingMode)
		{
			if (!((NetworkBehaviour)__instance).IsServer && ((EnemyAI)__instance).previousBehaviourStateIndex == 2 && ((EnemyAI)__instance).currentBehaviourStateIndex != 2)
			{
				if (___finishingFlight)
				{
					___finishingFlight = false;
				}
				if (___inFlyingMode)
				{
					___inFlyingMode = false;
					((EnemyAI)__instance).inSpecialAnimation = false;
				}
			}
		}

		[HarmonyPatch(typeof(MaskedPlayerEnemy), "DoAIInterval")]
		[HarmonyPostfix]
		public static void MaskedEnemy_DoAIInterval(MaskedPlayerEnemy __instance)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			if (GameNetworkManager.Instance.gameVersionNum < 64 && !((EnemyAI)__instance).isEnemyDead && ((EnemyAI)__instance).currentBehaviourStateIndex == 0 && (Object)(object)__instance.elevatorScript == (Object)null && (!(__instance.interestInShipCooldown >= 17f) || !(Vector3.Distance(((Component)__instance).transform.position, StartOfRound.Instance.elevatorTransform.position) < 22f)) && Time.realtimeSinceStartup - __instance.timeAtLastUsingEntrance > 3f && !Object.op_Implicit((Object)(object)((EnemyAI)__instance).GetClosestPlayer(!((EnemyAI)__instance).isOutside, false, false)))
			{
				bool flag = __instance.GoTowardsEntrance();
				if (Vector3.Distance(((Component)__instance).transform.position, __instance.mainEntrancePosition) < 1f)
				{
					__instance.TeleportMaskedEnemyAndSync(RoundManager.FindMainEntrancePosition(true, !((EnemyAI)__instance).isOutside), !((EnemyAI)__instance).isOutside);
				}
				else if (flag && __instance.searchForPlayers.inProgress)
				{
					((EnemyAI)__instance).StopSearch(__instance.searchForPlayers, true);
				}
			}
		}

		public static void RadMech_FixThreatTransform(RadMechAI __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)__instance.focusedThreatTransform) && ((EnemyAI)__instance).currentBehaviourStateIndex == 1 && GameNetworkManager.Instance.gameVersionNum < 64)
			{
				GameObject val = (GameObject)(((object)GameObject.Find("RadMechTarget")) ?? ((object)new GameObject("RadMechTarget")));
				val.transform.position = new Vector3(0f, -5000f, 0f);
				__instance.focusedThreatTransform = val.transform;
			}
		}

		[HarmonyPatch(typeof(RadMechAI), "MoveTowardsThreat")]
		[HarmonyPrefix]
		public static void RadMechAI_MoveTowardsThreat(RadMechAI __instance)
		{
			RadMech_FixThreatTransform(__instance);
		}

		[HarmonyPatch(typeof(RadMechAI), "Update")]
		[HarmonyPrefix]
		public static void RadMechAI_Update(RadMechAI __instance)
		{
			RadMech_FixThreatTransform(__instance);
		}
	}
	[HarmonyPatch]
	internal static class Patches_Hazards
	{
		internal static AudioClip spikeTrapActivateSound;

		internal static AudioClip spikeTrapDeactivateSound;

		[HarmonyPatch(typeof(SpikeRoofTrap), "GetNearEntrance")]
		[HarmonyPrefix]
		public static bool GetNearEntrance(SpikeRoofTrap __instance, ref bool __result, ref EntranceTeleport ___nearEntrance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			EntranceTeleport[] array = Object.FindObjectsByType<EntranceTeleport>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				if (!array[i].isEntranceToBuilding && Vector3.Distance(((Component)__instance.spikeTrapAudio).transform.position, array[i].entrancePoint.position) < 7f)
				{
					flag = true;
					___nearEntrance = array[i];
				}
			}
			bool flag2 = false;
			if (flag)
			{
				for (int j = 0; j < array.Length; j++)
				{
					if ((Object)(object)array[j].entrancePoint == (Object)(object)___nearEntrance.exitPoint)
					{
						___nearEntrance = array[j];
						flag2 = true;
					}
				}
			}
			__result = flag2;
			return false;
		}

		[HarmonyPatch(typeof(SpikeRoofTrap), "Start")]
		[HarmonyPostfix]
		public static void Fix_SpikeTrapSafety_Start(ref SpikeRoofTrap __instance)
		{
			Landmine[] array = Resources.FindObjectsOfTypeAll<Landmine>();
			spikeTrapActivateSound = ((array == null) ? null : array[0]?.mineDeactivate);
			Landmine[] array2 = Resources.FindObjectsOfTypeAll<Landmine>();
			spikeTrapDeactivateSound = ((array2 == null) ? null : array2[0]?.mineDeactivate);
			Light component = ((Component)((Component)__instance).transform.parent.Find("Spot Light")).GetComponent<Light>();
			if ((Object)(object)component != (Object)null)
			{
				component.intensity = 5f;
			}
		}

		[HarmonyPatch(typeof(SpikeRoofTrap), "Update")]
		[HarmonyPrefix]
		public static void Fix_SpikeTrapSafety_Update(ref SpikeRoofTrap __instance, EntranceTeleport ___nearEntrance)
		{
			if (__instance.trapActive)
			{
				float num = 1.2f;
				if ((Object)(object)___nearEntrance != (Object)null && Time.realtimeSinceStartup - ___nearEntrance.timeAtLastUse < num)
				{
					__instance.timeSinceMovingUp = Time.realtimeSinceStartup;
				}
			}
		}

		[HarmonyPatch(typeof(SpikeRoofTrap), "ToggleSpikesEnabledLocalClient")]
		[HarmonyPostfix]
		public static void Fix_SpikeTrapSafety_ToggleSound(SpikeRoofTrap __instance, bool enabled)
		{
			if (enabled)
			{
				if (FixesConfig.SpikeTrapActivateSound.Value && (Object)(object)spikeTrapActivateSound != (Object)null)
				{
					__instance.spikeTrapAudio.PlayOneShot(spikeTrapActivateSound);
					WalkieTalkie.TransmitOneShotAudio(__instance.spikeTrapAudio, spikeTrapActivateSound, 1f);
				}
			}
			else if (FixesConfig.SpikeTrapDeactivateSound.Value && (Object)(object)spikeTrapDeactivateSound != (Object)null)
			{
				__instance.spikeTrapAudio.PlayOneShot(spikeTrapDeactivateSound);
				WalkieTalkie.TransmitOneShotAudio(__instance.spikeTrapAudio, spikeTrapDeactivateSound, 1f);
			}
			Light component = ((Component)((Component)__instance).transform.parent.Find("Spot Light")).GetComponent<Light>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = enabled;
			}
		}
	}
	[HarmonyPatch]
	internal static class Patches_UI
	{
		[HarmonyPatch(typeof(MenuManager), "Awake")]
		[HarmonyPostfix]
		public static void MenuManager_Awake(MenuManager __instance)
		{
			try
			{
				if (SteamApps.CurrentBetaName == "public_beta")
				{
					string text = null;
					if (SteamApps.BuildId <= 15598010)
					{
						text = "64";
					}
					if (text != null)
					{
						((TMP_Text)__instance.menuNotificationText).SetText("You are on an outdated version of v" + text + ". Please ensure beta participation is disabled in the preferences when right clicking the game on Steam!", true);
						((TMP_Text)__instance.menuNotificationButtonText).SetText("[ CLOSE ]", true);
						__instance.menuNotification.SetActive(true);
					}
				}
			}
			catch
			{
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "DetectVoiceChatAmplitude")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static void SpeakingIndicator_VAC(StartOfRound __instance)
		{
			if ((Object)(object)__instance.voiceChatModule != (Object)null)
			{
				VoicePlayerState val = __instance.voiceChatModule.FindPlayer(__instance.voiceChatModule.LocalPlayerName);
				((Behaviour)HUDManager.Instance.PTTIcon).enabled = val.IsSpeaking && IngamePlayerSettings.Instance.settings.micEnabled && !__instance.voiceChatModule.IsMuted && (IngamePlayerSettings.Instance.settings.pushToTalk || FixesConfig.VACSpeakingIndicator.Value);
			}
		}

		[HarmonyPatch(typeof(NetworkSceneManager), "PopulateScenePlacedObjects")]
		[HarmonyPostfix]
		public static void Fix_LANUsernameBillboard()
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				((TMP_Text)val.usernameBillboardText).text = val.playerUsername;
			}
		}

		[HarmonyPatch(typeof(MenuManager), "OnEnable")]
		[HarmonyPostfix]
		public static void AlignMenuButtons(MenuManager __instance, Button ___startHostButton)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)___startHostButton != (Object)null)
			{
				float x = ((Component)___startHostButton).transform.localPosition.x;
				float z = ((Component)___startHostButton).transform.localPosition.z;
				Button[] componentsInChildren = __instance.menuButtons.GetComponentsInChildren<Button>(true);
				foreach (Button val in componentsInChildren)
				{
					((Component)val).transform.localPosition = new Vector3(x, ((Component)val).transform.localPosition.y, z);
				}
			}
		}

		[HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")]
		[HarmonyPostfix]
		public static void DebugMenu_ButtonStateText(QuickMenuManager __instance)
		{
			TextMeshProUGUI component = ((Component)__instance.debugMenuUI.transform.Find("Image/ToggleTestRoomButton/Text (TMP)")).GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).text = (((Object)(object)StartOfRound.Instance.testRoom != (Object)null) ? "Test Room: Enabled" : "Test Room: Disabled");
			((TMP_Text)component).fontSize = 12f;
			((TMP_Text)((Component)__instance.debugMenuUI.transform.Find("Image/ToggleInvincibility/Text (TMP)")).GetComponent<TextMeshProUGUI>()).text = ((!StartOfRound.Instance.allowLocalPlayerDeath) ? "God Mode: Enabled" : "God Mode: Disabled");
		}

		[HarmonyPatch(typeof(StartOfRound), "Debug_EnableTestRoomClientRpc")]
		[HarmonyPostfix]
		public static void DebugMenu_ButtonStateText_TestRoom(bool enable)
		{
			((TMP_Text)((Component)Object.FindFirstObjectByType<QuickMenuManager>().debugMenuUI.transform.Find("Image/ToggleTestRoomButton/Text (TMP)")).GetComponent<TextMeshProUGUI>()).text = (enable ? "Test Room: Enabled" : "Test Room: Disabled");
		}

		[HarmonyPatch(typeof(StartOfRound), "Debug_ToggleAllowDeathClientRpc")]
		[HarmonyPostfix]
		public static void DebugMenu_ButtonStateText_Invincibility(bool allowDeath)
		{
			((TMP_Text)((Component)Object.FindFirstObjectByType<QuickMenuManager>().debugMenuUI.transform.Find("Image/ToggleInvincibility/Text (TMP)")).GetComponent<TextMeshProUGUI>()).text = ((!allowDeath) ? "God Mode: Enabled" : "God Mode: Disabled");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}