Decompiled source of RemoveInteriorFog v1.1.0

BepInEx/plugins/com.github.zehsteam.RemoveInteriorFog.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen.Graph;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using com.github.zehsteam.RemoveInteriorFog.Dependencies.LethalConfigMod;
using com.github.zehsteam.RemoveInteriorFog.Extensions;
using com.github.zehsteam.RemoveInteriorFog.Helpers;
using com.github.zehsteam.RemoveInteriorFog.Managers;
using com.github.zehsteam.RemoveInteriorFog.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Zehs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026 Zehs")]
[assembly: AssemblyDescription("Removes interior fog. Configurable!")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+49dd0ec8dac2a5cba51494cfbfadafd770db5039")]
[assembly: AssemblyProduct("RemoveInteriorFog")]
[assembly: AssemblyTitle("com.github.zehsteam.RemoveInteriorFog")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 com.github.zehsteam.RemoveInteriorFog
{
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static bool IsExtendedLoggingEnabled => ConfigManager.Misc_ExtendedLogging?.Value ?? false;

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogDebug(object data)
		{
			Log((LogLevel)32, data);
		}

		public static void LogInfo(object data, bool extended = false)
		{
			Log((LogLevel)16, data, extended);
		}

		public static void LogMessage(object data, bool extended = false)
		{
			Log((LogLevel)8, data, extended);
		}

		public static void LogWarning(object data, bool extended = false)
		{
			Log((LogLevel)4, data, extended);
		}

		public static void LogError(object data, bool extended = false)
		{
			Log((LogLevel)2, data, extended);
		}

		public static void LogFatal(object data, bool extended = false)
		{
			Log((LogLevel)1, data, extended);
		}

		public static void Log(LogLevel logLevel, object data, bool extended = false)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!extended || IsExtendedLoggingEnabled)
			{
				ManualLogSource manualLogSource = ManualLogSource;
				if (manualLogSource != null)
				{
					manualLogSource.Log(logLevel, data);
				}
			}
		}
	}
	[BepInPlugin("com.github.zehsteam.RemoveInteriorFog", "RemoveInteriorFog", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.zehsteam.RemoveInteriorFog");

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("com.github.zehsteam.RemoveInteriorFog"));
			Logger.LogInfo("RemoveInteriorFog has awoken!");
			_harmony.PatchAll(typeof(RoundManager_Patches));
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.RemoveInteriorFog";

		public const string PLUGIN_NAME = "RemoveInteriorFog";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal static class RoundManager_Patches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void Start_Patch()
		{
			string allMoonNames = LevelHelper.GetAllMoonNames();
			ConfigManager.Values_AllMoonNames.Value = allMoonNames;
			Logger.LogMessage("All available moon names for config: " + allMoonNames);
			string allInteriorNames = LevelHelper.GetAllInteriorNames();
			ConfigManager.Values_AllInteriorNames.Value = allInteriorNames;
			Logger.LogMessage("All available interior names for config: " + allInteriorNames);
		}

		[HarmonyPatch("RefreshEnemiesList")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void RefreshEnemiesList_Patch()
		{
			FogHelper.DisableEventFogUsingConfig();
		}

		[HarmonyPatch("FinishGeneratingLevel")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void FinishGeneratingLevel_Patch()
		{
			FogHelper.DisableOtherFogUsingConfig();
		}
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.MonoBehaviours
{
	internal class CoroutineRunner : MonoBehaviour
	{
		public static CoroutineRunner Instance { get; private set; }

		public static CoroutineRunner Spawn()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if ((Object)(object)Instance != (Object)null)
			{
				return Instance;
			}
			GameObject val = new GameObject("RemoveInteriorFog CoroutineRunner", new Type[1] { typeof(CoroutineRunner) })
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)val);
			return val.GetComponent<CoroutineRunner>();
		}

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				Instance = this;
			}
		}

		public static Coroutine Start(IEnumerator routine)
		{
			if ((Object)(object)Instance == (Object)null)
			{
				CoroutineRunner coroutineRunner = Spawn();
				return ((coroutineRunner != null) ? ((MonoBehaviour)coroutineRunner).StartCoroutine(routine) : null) ?? null;
			}
			CoroutineRunner instance = Instance;
			return ((instance != null) ? ((MonoBehaviour)instance).StartCoroutine(routine) : null) ?? null;
		}

		public static void Stop(IEnumerator routine)
		{
			CoroutineRunner instance = Instance;
			if (instance != null)
			{
				((MonoBehaviour)instance).StopCoroutine(routine);
			}
		}

		public static void Stop(Coroutine routine)
		{
			CoroutineRunner instance = Instance;
			if (instance != null)
			{
				((MonoBehaviour)instance).StopCoroutine(routine);
			}
		}
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.Managers
{
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> Misc_ExtendedLogging { get; private set; }

		public static ConfigEntry<bool> Fog_RemoveEventFog { get; private set; }

		public static ConfigEntry<bool> Fog_RemoveOtherFog { get; private set; }

		public static ConfigEntry<string> Fog_OtherFogMoonWhitelist { get; private set; }

		public static ConfigEntry<string> Fog_OtherFogInteriorWhitelist { get; private set; }

		public static string[] Fog_OtherFogMoonWhitelist_Array => Fog_OtherFogMoonWhitelist.Value.ToCollection<string>().ToArray();

		public static string[] Fog_OtherFogInteriorWhitelist_Array => Fog_OtherFogInteriorWhitelist.Value.ToCollection<string>().ToArray();

		public static ConfigEntry<string> Values_AllMoonNames { get; private set; }

		public static ConfigEntry<string> Values_AllInteriorNames { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			ConfigHelper.SkipAutoGen();
			Misc_ExtendedLogging = ConfigHelper.Bind("Misc", "ExtendedLogging", defaultValue: false, "Enable extended logging.");
			Fog_RemoveEventFog = ConfigHelper.Bind("Fog", "RemoveEventFog", defaultValue: true, "If enabled, the rare vanilla thick interior fog that was added in v67 will be disabled.");
			Fog_RemoveOtherFog = ConfigHelper.Bind("Fog", "RemoveOtherFog", defaultValue: false, "If enabled, other interior fog will be disabled.");
			Fog_OtherFogMoonWhitelist = ConfigHelper.Bind("Fog", "OtherFogMoonWhitelist", "Example Moon, Second Moon", "List of moon names to not disable other interior fog on. Comma-separated list. Use the AllMoonNames config setting for a list of all available moon names.");
			Fog_OtherFogInteriorWhitelist = ConfigHelper.Bind("Fog", "OtherFogInteriorWhitelist", "Example Interior, Second Interior", "List of interior names to not disable other interior fog on. Comma-separated list. Use the AllInteriorNames config setting for a list of all available interior names.");
			ConfigHelper.AddButton("Fog", "Event Fog", "Remove", "Will disable the rare vanilla thick interior fog that was added in v67 for the current moon.", FogHelper.DisableEventFog);
			ConfigHelper.AddButton("Fog", "Other Fog", "Remove", "Will disable other interior fog for the current moon.", FogHelper.DisableOtherFog);
			Values_AllMoonNames = ConfigHelper.Bind("Values", "AllMoonNames", "", "These are all of the available moon names. Values will generate after loading into the ship.");
			Values_AllInteriorNames = ConfigHelper.Bind("Values", "AllInteriorNames", "", "These are all of the available interior names. Values will generate after loading into the ship.");
		}
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.Helpers
{
	internal static class ConfigHelper
	{
		public static void SkipAutoGen()
		{
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.SkipAutoGen();
			}
		}

		public static void AddButton(string section, string name, string buttonText, string description, Action callback)
		{
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.AddButton(section, name, buttonText, description, callback);
			}
		}

		public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description, bool requiresRestart = false, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			if (configFile == null)
			{
				configFile = ConfigManager.ConfigFile;
			}
			ConfigEntry<T> configEntry = configFile.Bind(section, key, defaultValue, description, acceptableValues);
			if (settingChanged != null)
			{
				configEntry.SettingChanged += delegate
				{
					settingChanged?.Invoke(configEntry.Value);
				};
			}
			if (LethalConfigProxy.IsInstalled)
			{
				LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
			}
			return configEntry;
		}
	}
	internal static class FogHelper
	{
		public static void DisableEventFogUsingConfig()
		{
			if (ConfigManager.Fog_RemoveEventFog.Value)
			{
				DisableEventFog();
			}
		}

		public static void DisableEventFog()
		{
			LocalVolumetricFog eventFog = GetEventFog();
			if (!((Object)(object)eventFog == (Object)null))
			{
				bool activeSelf = ((Component)eventFog).gameObject.activeSelf;
				((Behaviour)eventFog).enabled = false;
				((Component)eventFog).gameObject.SetActive(false);
				if (activeSelf)
				{
					Logger.LogInfo("Disabled event fog.");
				}
				else
				{
					Logger.LogInfo("Event fog was not enabled.", extended: true);
				}
			}
		}

		public static void DisableOtherFogUsingConfig()
		{
			if (!ConfigManager.Fog_RemoveOtherFog.Value)
			{
				return;
			}
			string currentMoonName = LevelHelper.GetCurrentMoonName();
			string[] fog_OtherFogMoonWhitelist_Array = ConfigManager.Fog_OtherFogMoonWhitelist_Array;
			if (!fog_OtherFogMoonWhitelist_Array.Contains<string>(currentMoonName, StringComparer.OrdinalIgnoreCase))
			{
				string currentInteriorName = LevelHelper.GetCurrentInteriorName();
				string[] fog_OtherFogInteriorWhitelist_Array = ConfigManager.Fog_OtherFogInteriorWhitelist_Array;
				if (!fog_OtherFogInteriorWhitelist_Array.Contains<string>(currentInteriorName, StringComparer.OrdinalIgnoreCase))
				{
					DisableOtherFog();
				}
			}
		}

		public static void DisableOtherFog()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			GameObject dungeonRoot = GetDungeonRoot();
			if ((Object)(object)dungeonRoot == (Object)null)
			{
				Logger.LogError("Failed to disable other fog. Dungeon root was not found.");
				return;
			}
			LocalVolumetricFog[] componentsInChildren = dungeonRoot.GetComponentsInChildren<LocalVolumetricFog>(true);
			LocalVolumetricFog[] array = componentsInChildren;
			foreach (LocalVolumetricFog localVolumetricFog in array)
			{
				DisableLocalVolumetricFog(localVolumetricFog);
			}
			Vector3 position = dungeonRoot.transform.position;
			LocalVolumetricFog[] array2 = Object.FindObjectsByType<LocalVolumetricFog>((FindObjectsSortMode)0);
			LocalVolumetricFog[] array3 = array2;
			foreach (LocalVolumetricFog val in array3)
			{
				if (!componentsInChildren.Contains(val))
				{
					Vector3 bottomPosition = val.GetBottomPosition();
					if (bottomPosition.y < position.y)
					{
						DisableLocalVolumetricFog(val);
					}
				}
			}
		}

		private static void DisableLocalVolumetricFog(LocalVolumetricFog localVolumetricFog)
		{
			if ((Object)(object)localVolumetricFog == (Object)null)
			{
				return;
			}
			GameObject gameObject = ((Component)localVolumetricFog).gameObject;
			LocalVolumetricFog eventFog = GetEventFog();
			if ((Object)(object)gameObject == (Object)(object)((eventFog != null) ? ((Component)eventFog).gameObject : null))
			{
				return;
			}
			bool enabled = ((Behaviour)localVolumetricFog).enabled;
			bool activeSelf = ((Component)localVolumetricFog).gameObject.activeSelf;
			string name = ((Object)localVolumetricFog).name;
			if (!enabled && !activeSelf)
			{
				Logger.LogInfo("Fog \"" + name + "\" is already disabled. Path: \"" + ((Component)localVolumetricFog).transform.GetHierarchyPath() + "\"", extended: true);
				return;
			}
			((Behaviour)localVolumetricFog).enabled = false;
			((Component)localVolumetricFog).gameObject.SetActive(false);
			Logger.LogInfo("Disabled fog \"" + name + "\". Path: \"" + ((Component)localVolumetricFog).transform.GetHierarchyPath() + "\"");
			if (!Logger.IsExtendedLoggingEnabled)
			{
				return;
			}
			if (enabled && activeSelf)
			{
				Logger.LogInfo("Disabled LocalVolumetricFog script and GameObject.", extended: true);
				return;
			}
			if (enabled)
			{
				Logger.LogInfo("Disabled LocalVolumetricFog script.", extended: true);
			}
			else
			{
				Logger.LogInfo("LocalVolumetricFog script was already disabled.", extended: true);
			}
			if (activeSelf)
			{
				Logger.LogInfo("Disabled LocalVolumetricFog GameObject.", extended: true);
			}
			else
			{
				Logger.LogInfo("LocalVolumetricFog GameObject was already disabled.", extended: true);
			}
		}

		private static LocalVolumetricFog GetEventFog()
		{
			return RoundManager.Instance?.indoorFog;
		}

		private static GameObject GetDungeonRoot()
		{
			return RoundManager.Instance?.dungeonGenerator?.Root;
		}
	}
	internal static class LevelHelper
	{
		private static readonly Dictionary<string, string> _dungeonFlowToReadableNames;

		static LevelHelper()
		{
			_dungeonFlowToReadableNames = new Dictionary<string, string>();
			_dungeonFlowToReadableNames.TryAdd("Level1Flow", "Facility");
			_dungeonFlowToReadableNames.TryAdd("Level2Flow", "Mansion");
			_dungeonFlowToReadableNames.TryAdd("Level3Flow", "Mineshaft");
		}

		public static string GetAllMoonNames()
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return string.Empty;
			}
			SelectableLevel[] source = StartOfRound.Instance.levels.Where((SelectableLevel x) => !x.lockedForDemo).ToArray();
			string[] value = source.Select((SelectableLevel x) => x.PlanetName).ToArray();
			return string.Join(", ", value);
		}

		public static string GetAllInteriorNames()
		{
			if ((Object)(object)RoundManager.Instance == (Object)null)
			{
				return string.Empty;
			}
			IndoorMapType[] dungeonFlowTypes = RoundManager.Instance.dungeonFlowTypes;
			if (dungeonFlowTypes == null || dungeonFlowTypes.Length == 0)
			{
				return string.Empty;
			}
			string[] array = dungeonFlowTypes.Select((IndoorMapType x) => GetInteriorName(x.dungeonFlow)).ToArray();
			if (array.Length == 0)
			{
				return string.Empty;
			}
			return string.Join(", ", array.Distinct());
		}

		public static string GetCurrentMoonName()
		{
			return StartOfRound.Instance?.currentLevel?.PlanetName;
		}

		public static string GetCurrentInteriorName()
		{
			return GetInteriorName(GetCurrentDungeonFlow());
		}

		public static string GetInteriorName(DungeonFlow dungeonFlow)
		{
			if ((Object)(object)dungeonFlow == (Object)null)
			{
				return "DungeonFlow is null";
			}
			foreach (KeyValuePair<string, string> dungeonFlowToReadableName in _dungeonFlowToReadableNames)
			{
				if (((Object)dungeonFlow).name.StartsWith(dungeonFlowToReadableName.Key, StringComparison.OrdinalIgnoreCase))
				{
					return dungeonFlowToReadableName.Value;
				}
			}
			return ((Object)dungeonFlow).name;
		}

		private static DungeonFlow GetCurrentDungeonFlow()
		{
			if ((Object)(object)RoundManager.Instance == (Object)null)
			{
				return null;
			}
			return RoundManager.Instance.dungeonFlowTypes[RoundManager.Instance.currentDungeonType].dungeonFlow;
		}
	}
	internal static class NetworkUtils
	{
		private static readonly FieldInfo _rpcExecStageField = AccessTools.Field(typeof(NetworkBehaviour), "__rpc_exec_stage");

		public static bool IsConnected
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (singleton == null)
				{
					return false;
				}
				return singleton.IsConnectedClient;
			}
		}

		public static bool IsServer
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (singleton == null)
				{
					return false;
				}
				return singleton.IsServer;
			}
		}

		public static ulong LocalClientId
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (singleton == null)
				{
					return 0uL;
				}
				return singleton.LocalClientId;
			}
		}

		public static int ConnectedPlayerCount => GameNetworkManager.Instance?.connectedPlayers ?? 0;

		public static bool IsLocalClientId(ulong clientId)
		{
			return clientId == LocalClientId;
		}

		public static bool HasClient(ulong clientId)
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return false;
			}
			return NetworkManager.Singleton.ConnectedClients.ContainsKey(clientId);
		}

		public static bool IsNetworkPrefab(GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return false;
			}
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return false;
			}
			IReadOnlyList<NetworkPrefab> prefabs = NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs;
			return prefabs.Any((NetworkPrefab x) => (Object)(object)x.Prefab == (Object)(object)prefab);
		}

		public static void NetcodePatcherAwake()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				IEnumerable<Type> loadableTypes = executingAssembly.GetLoadableTypes();
				foreach (Type item in loadableTypes)
				{
					MethodInfo[] methods = item.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					MethodInfo[] array = methods;
					foreach (MethodInfo methodInfo in array)
					{
						try
						{
							object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
							if (customAttributes.Length != 0)
							{
								try
								{
									methodInfo.Invoke(null, null);
								}
								catch (TargetInvocationException ex)
								{
									Logger.LogWarning("[NetworkUtils] Failed to invoke method " + methodInfo.Name + ": " + ex.Message);
								}
							}
						}
						catch (Exception ex2)
						{
							Logger.LogWarning("[NetworkUtils] Error processing method " + methodInfo.Name + " in type " + item.Name + ": " + ex2.Message);
						}
					}
				}
			}
			catch (Exception ex3)
			{
				Logger.LogError("[NetworkUtils] Failed to run NetcodePatcherAwake: " + ex3.Message);
			}
		}

		public static bool IsExecutingRPCMethod(NetworkBehaviour networkBehaviour)
		{
			if ((Object)(object)networkBehaviour == (Object)null)
			{
				return false;
			}
			NetworkManager networkManager = networkBehaviour.NetworkManager;
			if ((Object)(object)networkManager == (Object)null || !networkManager.IsListening)
			{
				return false;
			}
			if (_rpcExecStageField == null)
			{
				Logger.LogError("[NetworkUtils] IsExecutingRPCMethod: Failed to find \"__rpc_exec_stage\" field.");
				return false;
			}
			object value = _rpcExecStageField.GetValue(networkBehaviour);
			int num = (int)value;
			if (num != 0)
			{
				return num == 1;
			}
			return true;
		}
	}
	internal static class PlayerUtils
	{
		public static PlayerControllerB LocalPlayerScript => GameNetworkManager.Instance?.localPlayerController ?? null;

		public static PlayerControllerB[] AllPlayerScripts => StartOfRound.Instance?.allPlayerScripts ?? Array.Empty<PlayerControllerB>();

		public static PlayerControllerB[] ConnectedPlayerScripts => AllPlayerScripts.Where(IsConnected).ToArray();

		public static PlayerControllerB[] AlivePlayerScripts => ConnectedPlayerScripts.Where((PlayerControllerB x) => !x.isPlayerDead).ToArray();

		public static PlayerControllerB[] DeadPlayerScripts => ConnectedPlayerScripts.Where((PlayerControllerB x) => x.isPlayerDead).ToArray();

		public static bool TryGetLocalPlayerScript(out PlayerControllerB playerScript)
		{
			playerScript = LocalPlayerScript;
			return (Object)(object)playerScript != (Object)null;
		}

		public static bool IsLocalPlayer(PlayerControllerB playerScript)
		{
			if ((Object)(object)playerScript == (Object)null)
			{
				return false;
			}
			return (Object)(object)playerScript == (Object)(object)LocalPlayerScript;
		}

		public static bool IsConnected(PlayerControllerB playerScript)
		{
			if ((Object)(object)playerScript == (Object)null)
			{
				return false;
			}
			if (!playerScript.isPlayerControlled)
			{
				return playerScript.isPlayerDead;
			}
			return true;
		}

		public static PlayerControllerB GetPlayerScriptByClientId(ulong clientId)
		{
			return ((IEnumerable<PlayerControllerB>)ConnectedPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB playerScript) => playerScript.actualClientId == clientId));
		}

		public static bool TryGetPlayerScriptByClientId(ulong clientId, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByClientId(clientId);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetPlayerScriptByPlayerId(int playerId)
		{
			if (playerId < 0 || playerId > ConnectedPlayerScripts.Length - 1)
			{
				return null;
			}
			return ConnectedPlayerScripts[playerId];
		}

		public static bool TryGetPlayerScriptByPlayerId(int playerId, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByPlayerId(playerId);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetPlayerScriptByUsername(string username)
		{
			PlayerControllerB[] source = ConnectedPlayerScripts.OrderBy((PlayerControllerB x) => x.playerUsername.Length).ToArray();
			PlayerControllerB val = ((IEnumerable<PlayerControllerB>)source).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerUsername.Equals(username, StringComparison.OrdinalIgnoreCase)));
			if (val == null)
			{
				val = ((IEnumerable<PlayerControllerB>)source).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerUsername.StartsWith(username, StringComparison.OrdinalIgnoreCase)));
			}
			if (val == null)
			{
				val = ((IEnumerable<PlayerControllerB>)source).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerUsername.Contains(username, StringComparison.OrdinalIgnoreCase)));
			}
			return val;
		}

		public static bool TryGetPlayerScriptByUsername(string username, out PlayerControllerB playerScript)
		{
			playerScript = GetPlayerScriptByUsername(username);
			return (Object)(object)playerScript != (Object)null;
		}

		public static PlayerControllerB GetRandomPlayerScript(PlayerControllerB[] playerScripts, bool excludeLocal = false)
		{
			if (playerScripts == null || playerScripts.Length == 0)
			{
				return null;
			}
			PlayerControllerB[] array = playerScripts.Where((PlayerControllerB playerScript) => !excludeLocal || !IsLocalPlayer(playerScript)).ToArray();
			if (array.Length == 0)
			{
				return null;
			}
			return array[Random.Range(0, array.Length)];
		}

		public static bool TryGetRandomPlayerScript(PlayerControllerB[] playerScripts, out PlayerControllerB playerScript, bool excludeLocal = false)
		{
			playerScript = GetRandomPlayerScript(playerScripts, excludeLocal);
			return (Object)(object)playerScript != (Object)null;
		}
	}
	internal static class Utils
	{
		public static string GetPluginDirectoryPath()
		{
			return Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
		}

		public static string GetConfigDirectoryPath()
		{
			return Paths.ConfigPath;
		}

		public static string GetPluginPersistentDataPath()
		{
			return Path.Combine(Application.persistentDataPath, "RemoveInteriorFog");
		}

		public static ConfigFile CreateConfigFile(BaseUnityPlugin plugin, string path, string name = null, bool saveOnInit = false)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			BepInPlugin metadata = MetadataHelper.GetMetadata((object)plugin);
			if (name == null)
			{
				name = metadata.GUID;
			}
			name += ".cfg";
			return new ConfigFile(Path.Combine(path, name), saveOnInit, metadata);
		}

		public static ConfigFile CreateLocalConfigFile(BaseUnityPlugin plugin, string name = null, bool saveOnInit = false)
		{
			return CreateConfigFile(plugin, GetConfigDirectoryPath(), name, saveOnInit);
		}

		public static ConfigFile CreateGlobalConfigFile(BaseUnityPlugin plugin, string name = null, bool saveOnInit = false)
		{
			string pluginPersistentDataPath = GetPluginPersistentDataPath();
			if (name == null)
			{
				name = "global";
			}
			return CreateConfigFile(plugin, pluginPersistentDataPath, name, saveOnInit);
		}

		public static bool RollPercentChance(float percent)
		{
			if (percent <= 0f)
			{
				return false;
			}
			if (percent >= 100f)
			{
				return true;
			}
			return Random.value * 100f <= percent;
		}
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.Extensions
{
	internal static class AssemblyExtensions
	{
		public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
		{
			if (assembly == null)
			{
				return Array.Empty<Type>();
			}
			try
			{
				return assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				return ex.Types.Where((Type type) => type != null);
			}
		}
	}
	internal static class CollectionExtensions
	{
		public static IEnumerable<T> ToCollection<T>(this string s, string separator = ",")
		{
			if (string.IsNullOrEmpty(s))
			{
				return Array.Empty<T>();
			}
			T result;
			return from x in s.Split(separator, StringSplitOptions.RemoveEmptyEntries)
				where !string.IsNullOrWhiteSpace(x)
				select x.Trim() into x
				select (!x.TryConvertTo<T>(out result)) ? default(T) : result into x
				where x != null
				select x;
		}

		public static string AsString<T>(this IEnumerable<T> value, string separator = ", ")
		{
			if (value == null || !value.Any())
			{
				return string.Empty;
			}
			return string.Join(separator, from x in value
				where x != null && !string.IsNullOrWhiteSpace(x.ToString())
				select x.ToString().Trim());
		}
	}
	internal static class ConfigFileExtensions
	{
		public static ConfigEntry<T> Bind<T>(this ConfigFile configFile, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if (acceptableValues == null)
			{
				return configFile.Bind<T>(section, key, defaultValue, description);
			}
			return configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>()));
		}
	}
	internal static class LocalVolumetricFogExtensions
	{
		public static Vector3 GetBottomPosition(this LocalVolumetricFog localVolumetricFog)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)localVolumetricFog == (Object)null)
			{
				return Vector3.zero;
			}
			Vector3 position = ((Component)localVolumetricFog).transform.position;
			position.y -= localVolumetricFog.parameters.size.y / 2f;
			return position;
		}
	}
	internal static class StringExtensions
	{
		public static bool IsHexColor(this string value)
		{
			return Regex.IsMatch(value, "^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$");
		}

		public static T ConvertTo<T>(this string s)
		{
			Type typeFromHandle = typeof(T);
			if ((object)typeFromHandle != null)
			{
				Type type = typeFromHandle;
				object obj;
				if (type == typeof(int) && int.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result))
				{
					obj = result;
				}
				else
				{
					Type type2 = typeFromHandle;
					if (type2 == typeof(float) && float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
					{
						obj = result2;
					}
					else
					{
						Type type3 = typeFromHandle;
						if (type3 == typeof(double) && double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
						{
							obj = result3;
						}
						else
						{
							Type type4 = typeFromHandle;
							if (type4 == typeof(bool) && bool.TryParse(s, out var result4))
							{
								obj = result4;
							}
							else
							{
								Type type5 = typeFromHandle;
								if (type5 == typeof(string))
								{
									obj = s;
								}
								else
								{
									Type type6 = typeFromHandle;
									if (!type6.IsEnum || !Enum.TryParse(type6, s, ignoreCase: true, out object result5))
									{
										goto IL_0121;
									}
									obj = result5;
								}
							}
						}
					}
				}
				object obj2 = obj;
				return (T)obj2;
			}
			goto IL_0121;
			IL_0121:
			throw new NotSupportedException($"Unsupported value type: {typeof(T)}");
		}

		public static bool TryConvertTo<T>(this string s, out T result)
		{
			try
			{
				result = s.ConvertTo<T>();
				return true;
			}
			catch
			{
				result = default(T);
				return false;
			}
		}
	}
	internal static class TransformExtensions
	{
		public static string GetHierarchyPath(this Transform transform)
		{
			if ((Object)(object)transform == (Object)null)
			{
				return string.Empty;
			}
			string text = ((Object)transform).name;
			Transform val = transform;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
				text = ((Object)val).name + "/" + text;
			}
			return text;
		}
	}
}
namespace com.github.zehsteam.RemoveInteriorFog.Dependencies.LethalConfigMod
{
	internal static class LethalConfigProxy
	{
		public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";

		public static bool IsInstalled => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void SkipAutoGen()
		{
			LethalConfigManager.SkipAutoGen();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static object AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			if (typeof(T).IsEnum)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(LethalConfigProxy), "AddEnumDropdown", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = methodInfo.MakeGenericMethod(typeof(T));
				object? obj = methodInfo2.Invoke(null, new object[2] { configEntry, requiresRestart });
				return (obj is BaseConfigItem) ? obj : null;
			}
			AcceptableValueBase acceptableValues = ((ConfigEntryBase)configEntry).Description.AcceptableValues;
			if (acceptableValues != null)
			{
				if (acceptableValues is AcceptableValueRange<float> || acceptableValues is AcceptableValueRange<int>)
				{
					return AddConfigSlider<T>(configEntry, requiresRestart);
				}
				if (acceptableValues is AcceptableValueList<string>)
				{
					return AddConfigDropdown<T>(configEntry, requiresRestart);
				}
			}
			if (configEntry is ConfigEntry<string> val && IsConfigEntryForHexColor(val))
			{
				return AddConfigItem((BaseConfigItem)new HexColorInputFieldConfigItem(val, requiresRestart));
			}
			if (!(configEntry is ConfigEntry<int> val2))
			{
				if (!(configEntry is ConfigEntry<float> val3))
				{
					if (!(configEntry is ConfigEntry<bool> val4))
					{
						if (configEntry is ConfigEntry<string> val5)
						{
							return AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val5, requiresRestart));
						}
						throw new NotSupportedException($"Unsupported type: {typeof(T)}");
					}
					return AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val4, requiresRestart));
				}
				return AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
			}
			return AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val2, requiresRestart));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static object AddButton(string section, string name, string buttonText, string description, Action callback)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			BaseConfigItem configItem = (BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
			{
				callback?.Invoke();
			});
			return AddConfigItem(configItem);
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (!(configEntry is ConfigEntry<float> val))
			{
				if (configEntry is ConfigEntry<int> val2)
				{
					return AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
				}
				throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
			}
			return AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (configEntry is ConfigEntry<string> val)
			{
				return AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(val, requiresRestart));
			}
			throw new NotSupportedException($"Dropdown not supported for type: {typeof(T)}");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddEnumDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false) where T : Enum
		{
			return AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<T>(configEntry, requiresRestart));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static bool IsConfigEntryForHexColor(ConfigEntry<string> configEntry)
		{
			if (!(((ConfigEntryBase)configEntry).DefaultValue is string value))
			{
				return false;
			}
			return value.IsHexColor();
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static BaseConfigItem AddConfigItem(BaseConfigItem configItem)
		{
			LethalConfigManager.AddConfigItem(configItem);
			return configItem;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}