Decompiled source of BetterFog v3.3.2

BepInEx/plugins/BetterFog.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetterFog.Assets;
using BetterFog.Input;
using BetterFog.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[HarmonyPatch(typeof(Fog))]
public class FogPatch
{
	[HarmonyPrefix]
	private static bool Prefix(HDCamera hdCamera, Fog __instance)
	{
		return false;
	}
}
namespace BetterFog
{
	[BepInPlugin("ironthumb.BetterFog", "BetterFog", "3.3.0")]
	public class BetterFog : BaseUnityPlugin
	{
		public const string modGUID = "ironthumb.BetterFog";

		public const string modName = "BetterFog";

		public const string modVersion = "3.3.0";

		private readonly Harmony harmony = new Harmony("ironthumb.BetterFog");

		public static ManualLogSource mls;

		private static BetterFog instance;

		public static bool hotkeysEnabled = true;

		private static ConfigEntry<string> nextPresetHotkeyConfig;

		public static ConfigEntry<bool> nextPresetHotKeyEnabled;

		private static ConfigEntry<string> nextModeHotkeyConfig;

		public static ConfigEntry<bool> nextModeHotKeyEnabled;

		private static ConfigEntry<string> refreshPresetHotkeyConfig;

		public static ConfigEntry<bool> refreshHotKeyEnabled;

		public static ConfigEntry<string> weatherScaleHotkeyConfig;

		public static ConfigEntry<bool> weatherScaleHotKeyEnabled;

		public static ConfigEntry<string> settingsHotkeyConfig;

		public static ConfigEntry<bool> settingsHotKeyEnabled;

		public static ConfigEntry<bool> excludeShipFogDefault;

		public static bool excludeShipFogEnabled;

		public static ConfigEntry<bool> verboseLoggingDefault;

		public static bool verboseLoggingEnabled;

		public static ConfigEntry<bool> excludeEnemyFogDefault;

		public static bool excludeEnemyFogEnabled;

		public static bool fogRefreshLock = true;

		private static List<string> weatherScaleBlacklist = new List<string>();

		private static List<string> moonScaleBlacklist = new List<string>();

		private static ConfigEntry<string> weatherScaleBlacklistConfig;

		private static ConfigEntry<string> moonScaleBlacklistConfig;

		private static ConfigEntry<bool> densityScaleEnabledDefault;

		public static bool densityScaleEnabled;

		public static string currentWeatherType = "None";

		private static float moonDensityScale = 1f;

		private static float weatherDensityScale = 1f;

		public static float combinedDensityScale = 1f;

		public static List<WeatherScale> weatherScales;

		private static ConfigEntry<string> weatherScalesConfig;

		public static string currentLevel = "";

		public static List<MoonScale> moonScales;

		private static ConfigEntry<string> moonScalesConfig;

		private static ConfigEntry<string> defaultPresetName;

		public static List<FogConfigPreset> fogConfigPresets;

		private ConfigEntry<string>[] presetEntries;

		public static int currentPresetIndex;

		public static FogConfigPreset currentPreset;

		public static Dictionary<GameObject, LocalVolumetricFogArtistParameters> fogParameterChanges = new Dictionary<GameObject, LocalVolumetricFogArtistParameters>();

		private static ConfigEntry<string> defaultMode;

		public static List<BetterFogMode> fogModes;

		public static int currentModeIndex;

		public static BetterFogMode currentMode;

		public static bool applyingFogSettings = false;

		public static PlayerControllerB player;

		public static BetterFog Instance
		{
			get
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null)
				{
					instance = Object.FindObjectOfType<BetterFog>();
					if ((Object)(object)instance == (Object)null)
					{
						GameObject val = new GameObject("BetterFog");
						Object.DontDestroyOnLoad((Object)(object)val);
						instance = val.AddComponent<BetterFog>();
					}
				}
				return instance;
			}
		}

		public void Awake()
		{
			//IL_0966: Unknown result type (might be due to invalid IL or missing references)
			//IL_0973: Expected O, but got Unknown
			//IL_09a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ae: Expected O, but got Unknown
			//IL_09dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e9: Expected O, but got Unknown
			//IL_0a17: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a24: Expected O, but got Unknown
			//IL_0a52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5f: Expected O, but got Unknown
			//IL_0a8d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9a: Expected O, but got Unknown
			//IL_0ac8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad5: Expected O, but got Unknown
			//IL_0b22: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b2f: Expected O, but got Unknown
			if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			mls = ((BaseUnityPlugin)this).Logger;
			fogConfigPresets = new List<FogConfigPreset>
			{
				new FogConfigPreset("Default", 250f, 0.441f, 0.459f, 0.5f),
				new FogConfigPreset("Heavy Fog", 50f, 0f, 0f, 0f),
				new FogConfigPreset("Light Fog", 9850f, 5f, 5f, 5f),
				new FogConfigPreset("Mist", 10000000f, 1f, 1f, 1f),
				new FogConfigPreset("Red Fog", 500f, 20f, 0f, 0f),
				new FogConfigPreset("Orange Fog", 500f, 20f, 9.33f, 4.5f),
				new FogConfigPreset("Yellow Fog", 1300f, 20f, 20f, 0f),
				new FogConfigPreset("Green Fog", 1300f, 0f, 20f, 0f),
				new FogConfigPreset("Blue Fog", 1300f, 0f, 0f, 20f),
				new FogConfigPreset("Purple Fog", 500f, 11.5f, 7.2f, 20f),
				new FogConfigPreset("Pink Fog", 500f, 20f, 4.75f, 20f)
			};
			mls.LogInfo((object)"fogConfigPresets initialized.");
			fogModes = new List<BetterFogMode>
			{
				new BetterFogMode("Better Fog"),
				new BetterFogMode("No Fog"),
				new BetterFogMode("Vanilla")
			};
			mls.LogInfo((object)"fogModes initialized");
			string text = "Default Fog Settings";
			defaultPresetName = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Default Preset Name", "Default", "Name of the default fog preset (No value sets default to first in list).\nOrder of settings: Preset Name, Mean Free Path, Albedo Red, Albedo Green, Albedo Blue\nMean Free Path - Density of fog. The greater the number, the less dense. 0 is the minimum (opaque fog).\n");
			defaultMode = ((BaseUnityPlugin)this).Config.Bind<string>(text, "Default Fog Mode", "Better Fog", "Name of the default fog mode. Options: Better Fog, No Fog, Vanilla");
			string text2 = "Key Bindings";
			settingsHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Settings Hotkey", "f1", "Hotkey to open the BetterFog settings menu.");
			settingsHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Settings Hotkey", true, "Enable or disable hotkey for opening the BetterFog settings menu.");
			nextPresetHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Next Preset Hotkey", "n", "Hotkey to switch to the next fog preset.");
			nextPresetHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Next Hotkey", true, "Enable or disable hotkeys for switching fog presets.");
			nextModeHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Next Mode Hotkey", "m", "Hotkey to switch to the next fog mode.");
			nextModeHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Next Mode Hotkey", false, "Enable or disable hotkey for switching fog modes.");
			refreshPresetHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Refresh Hotkey", "r", "Hotkey to refresh fog settings.");
			refreshHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Refresh Hotkey", true, "Enable or disable hotkey for refreshing fog settings.");
			weatherScaleHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Weather Scale Hotkey", "c", "Hotkey to toggle weather scaling.");
			weatherScaleHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Weather Scale Hotkey", false, "Enable or disable hotkey for Weather Scaling toggle.");
			string text3 = "Fog Settings";
			excludeShipFogDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Apply to Fog Exclusion Zone", true, "Apply fog settings to the Fog Exclusion Zone (eg. inside of ship).");
			excludeShipFogEnabled = excludeShipFogDefault.Value;
			densityScaleEnabledDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Weather Scale Enabled Default", true, "Enable density scaling for moons and weather by default when booting game.");
			densityScaleEnabled = densityScaleEnabledDefault.Value;
			verboseLoggingDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Verbose Logging Enabled", false, "Enable or disable verbose logging for the mod. Can be used for debugging.");
			verboseLoggingEnabled = verboseLoggingDefault.Value;
			excludeEnemyFogDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Exclude Enemy Fog", true, "Exclude enemy fog when applying better fog settings.");
			excludeEnemyFogEnabled = excludeEnemyFogDefault.Value;
			IngameKeybinds.Instance.InitializeKeybindings(nextPresetHotkeyConfig.Value, nextModeHotkeyConfig.Value, refreshPresetHotkeyConfig.Value, weatherScaleHotkeyConfig.Value, settingsHotkeyConfig.Value);
			presetEntries = new ConfigEntry<string>[fogConfigPresets.Count];
			for (int i = 0; i < fogConfigPresets.Count; i++)
			{
				FogConfigPreset fogConfigPreset = fogConfigPresets[i];
				presetEntries[i] = ((BaseUnityPlugin)this).Config.Bind<string>("Fog Presets", "Preset " + i, fogConfigPreset.ToString(), "Preset " + fogConfigPreset.PresetName);
				string[] array = presetEntries[i].Value.Split(new char[1] { ',' });
				string[] array2 = array;
				foreach (string text4 in array2)
				{
					string[] array3 = text4.Split(new char[1] { '=' });
					if (array3.Length == 2)
					{
						string text5 = array3[0].Trim();
						string text6 = array3[1].Trim();
						switch (text5)
						{
						case "PresetName":
							fogConfigPresets[i].PresetName = text6;
							break;
						case "Density":
							fogConfigPresets[i].MeanFreePath = float.Parse(text6);
							break;
						case "Red Hue":
							fogConfigPresets[i].AlbedoR = float.Parse(text6);
							break;
						case "Green Hue":
							fogConfigPresets[i].AlbedoG = float.Parse(text6);
							break;
						case "Blue Hue":
							fogConfigPresets[i].AlbedoB = float.Parse(text6);
							break;
						}
					}
				}
			}
			string text7 = "Weather and Moon Density Scales";
			moonScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "MoonScales", "71 Gordion=1,41 Experimentation=0.95,220 Assurance=0.9,56 Vow=0.8,21 Offense=0.9,61 March=0.75,20 Adamance=0.75,85 Rend=0.285,7 Dine=0.325,8 Titan=0.285,68 Artifice=0.9,5 Embrion=0.85,44 Liquidation=0.85", "Moon scales in the format {Gordion=1,41 Experimentation=0.95,220 Assurance=0.9,...}");
			moonScales = ParseMoonScales(moonScalesConfig.Value);
			weatherScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "WeatherScales", "none=1,rainy=0.75,stormy=0.5,foggy=0.45,eclipsed=0.77,dust clouds=0.8,flooded=0.765", "Weather scales in the format {none=1,rainy=0.69,stormy=0.65,...}");
			weatherScales = ParseWeatherScales(weatherScalesConfig.Value);
			weatherScaleBlacklistConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "Weather Scaling Blacklist", "", "Enter weather names or moon names to trigger temporary disablement of fog WEATHER density scaling. This is only effective when WeatherScale is enabled. \nFull moon or weather names must be typed in, comma separated. Example: {eclipsed,20 Adamance,85 Rend}");
			moonScaleBlacklistConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "Moon Scaling Blacklist", "", "Enter weather names or moon names to trigger temporary disablement of MOON fog density scaling. This is only effective when WeatherScale is enabled. \nFull moon or weather names must be typed in, comma separated. Example: {eclipsed,20 Adamance,85 Rend}");
			weatherScaleBlacklist = ParseDensityScaleBlacklist(weatherScaleBlacklistConfig.Value);
			moonScaleBlacklist = ParseDensityScaleBlacklist(moonScaleBlacklistConfig.Value);
			mls.LogInfo((object)"Finished parsing config entries");
			if (defaultPresetName == null)
			{
				currentPreset = fogConfigPresets[0];
				currentPresetIndex = 0;
				mls.LogInfo((object)("Default preset not found. Using the first preset in the list: " + currentPreset.PresetName));
			}
			else
			{
				try
				{
					currentPreset = fogConfigPresets.Find((FogConfigPreset preset) => preset.PresetName == defaultPresetName.Value);
					currentPresetIndex = fogConfigPresets.IndexOf(currentPreset);
					mls.LogInfo((object)("Default preset found: " + currentPreset.PresetName));
				}
				catch (Exception arg)
				{
					mls.LogError((object)$"Failed to find the default preset: {arg}");
					currentPreset = fogConfigPresets[0];
					currentPresetIndex = 0;
				}
			}
			if (defaultMode == null)
			{
				currentMode = fogModes[0];
				currentModeIndex = 0;
			}
			else
			{
				try
				{
					currentMode = fogModes.Find((BetterFogMode mode) => mode.Name == defaultMode.Value);
					currentModeIndex = fogModes.IndexOf(currentMode);
					mls.LogInfo((object)("Default mode found: " + currentMode.Name));
					UpdateMode();
				}
				catch (Exception arg2)
				{
					mls.LogError((object)$"Failed to find the default mode: {arg2}");
					currentMode = fogModes[0];
					currentModeIndex = 0;
				}
			}
			try
			{
				harmony.Patch((MethodBase)AccessTools.Method(typeof(StartOfRound), "ChangeLevel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(StartOfRoundPatch), "ChangeLevelPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(Terminal), "BeginUsingTerminal", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TerminalPatch), "BeginUsingTerminalPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(Terminal), "QuitTerminal", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TerminalPatch), "QuitTerminalPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(HUDManager), "EnableChat_performed", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(HUDManagerPatch), "EnableChat_performedPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(HUDManager), "SubmitChat_performed", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(HUDManagerPatch), "SubmitChat_performedPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(HUDManager), "OpenMenu_performed", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(HUDManagerPatch), "OpenMenu_performedPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(LocalVolumetricFog), "OnEnable", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LocalVolumetricFogPatch), "OnEnablePatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.Method(typeof(SceneManager), "LoadScene", new Type[2]
				{
					typeof(string),
					typeof(LoadSceneParameters)
				}, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(SceneManagerPatch), "LoadScenePatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				mls.LogInfo((object)"BetterFog patches applied successfully!");
			}
			catch (Exception arg3)
			{
				mls.LogError((object)$"Failed to apply Harmony patches: {arg3}");
				throw;
			}
			if ((Object)(object)FogSettingsManager.Instance != (Object)null)
			{
				if (verboseLoggingEnabled)
				{
					mls.LogInfo((object)"FogSettingsManager instance is valid.");
				}
			}
			else if (verboseLoggingEnabled)
			{
				mls.LogError((object)"FogSettingsManager instance is null.");
			}
		}

		public static void ApplyFogSettings()
		{
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			moonDensityScale = 1f;
			weatherDensityScale = 1f;
			if (fogRefreshLock)
			{
				if (verboseLoggingEnabled)
				{
					mls.LogWarning((object)"Fog settings refresh is locked. Skipping fog settings application.");
				}
				return;
			}
			if (densityScaleEnabled)
			{
				if (!moonScaleBlacklist.Contains(currentLevel) && !moonScaleBlacklist.Contains(currentWeatherType))
				{
					foreach (MoonScale moonScale in moonScales)
					{
						if (currentLevel == moonScale.MoonName)
						{
							moonDensityScale = moonScale.Scale;
							if (verboseLoggingEnabled)
							{
								mls.LogInfo((object)(currentLevel + " moon detected. Set moon density scale to " + moonDensityScale));
							}
							break;
						}
						if (moonScale.MoonName == moonScales[moonScales.Count - 1].MoonName && verboseLoggingEnabled)
						{
							mls.LogWarning((object)$"{currentLevel} moon not found in records. Using moon scale of {moonDensityScale}.");
						}
					}
				}
				else
				{
					mls.LogInfo((object)"Blacklisted moon or weather detected. Setting moon density scale to 1.");
				}
				if (!weatherScaleBlacklist.Contains(currentLevel) && !weatherScaleBlacklist.Contains(currentWeatherType))
				{
					foreach (WeatherScale weatherScale in weatherScales)
					{
						if (currentWeatherType == weatherScale.WeatherName)
						{
							weatherDensityScale = weatherScale.Scale;
							if (verboseLoggingEnabled)
							{
								mls.LogInfo((object)(currentWeatherType + " weather type detected. Set weather density scale to " + weatherDensityScale));
							}
							break;
						}
						if (weatherScale.WeatherName == weatherScales[weatherScales.Count - 1].WeatherName && verboseLoggingEnabled)
						{
							mls.LogWarning((object)$"{currentWeatherType} weather type not found in records. Using scale of {weatherDensityScale}.");
						}
					}
				}
				else
				{
					mls.LogInfo((object)"Blacklisted moon or weather detected. Setting weather density scale to 1.");
				}
			}
			combinedDensityScale = moonDensityScale * weatherDensityScale;
			if (verboseLoggingEnabled)
			{
				mls.LogInfo((object)$"Final density scale applied: {moonDensityScale} * {weatherDensityScale} = {combinedDensityScale}");
				mls.LogInfo((object)$"Preset original MeanFreePath: {currentPreset.MeanFreePath}");
				mls.LogInfo((object)$"Scaled MeanFreePath: {currentPreset.MeanFreePath} * {combinedDensityScale} = {currentPreset.MeanFreePath * combinedDensityScale}");
			}
			List<LocalVolumetricFog> list = Resources.FindObjectsOfTypeAll<LocalVolumetricFog>().ToList();
			foreach (LocalVolumetricFog item in list)
			{
				int num = LayerMask.NameToLayer("Enemies");
				if ((Object)(object)item != (Object)null && (!(((Object)item).name == "FogExclusionZone") || !excludeShipFogEnabled) && (((Component)item).gameObject.layer != num || !excludeEnemyFogEnabled) && !(currentMode.Name == "Vanilla"))
				{
					LocalVolumetricFogArtistParameters parameters = item.parameters;
					if (densityScaleEnabled)
					{
						parameters.meanFreePath = currentPreset.MeanFreePath * combinedDensityScale;
					}
					else
					{
						parameters.meanFreePath = currentPreset.MeanFreePath;
					}
					parameters.albedo = new Color(currentPreset.AlbedoR, currentPreset.AlbedoG, currentPreset.AlbedoB, 1f);
					item.parameters = parameters;
				}
				else if (currentMode.Name == "Vanilla")
				{
					ResetFogToVanilla(((Component)item).gameObject);
				}
				if (verboseLoggingEnabled)
				{
					Color albedo = item.parameters.albedo;
					mls.LogInfo((object)$"Found LocalVolumetricFog object: {((Object)item).name}, MeanFreePath: {item.parameters.meanFreePath}, AlbedoR: {albedo.r}, AlbedoG: {albedo.g}, AlbedoB: {albedo.b}");
				}
			}
			if (currentMode.Name == "Better Fog")
			{
				mls.LogInfo((object)$"Applied Preset: {currentPreset.ToString()}, DensityScale={combinedDensityScale}");
			}
		}

		public static void ApplyFogSettingsOnGameStart()
		{
			applyingFogSettings = true;
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && GameNetworkManager.Instance.gameHasStarted)
			{
				mls.LogInfo((object)"Game has already started. Applying fog settings immediately.");
				((MonoBehaviour)Instance).StartCoroutine(ApplyFogSettingsRepeated(8));
				applyingFogSettings = false;
			}
			else
			{
				((MonoBehaviour)Instance).StartCoroutine(WaitForGameStartAndApplyFog());
			}
		}

		private static IEnumerator WaitForGameStartAndApplyFog()
		{
			int waitTime = 0;
			int waitTimeLimit = 60;
			if (verboseLoggingEnabled)
			{
				mls.LogInfo((object)$"Waiting for game to start... ({waitTime}s)");
			}
			while ((Object)(object)GameNetworkManager.Instance != (Object)null && !GameNetworkManager.Instance.gameHasStarted && waitTime < waitTimeLimit)
			{
				yield return (object)new WaitForSecondsRealtime(1f);
				waitTime++;
			}
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && GameNetworkManager.Instance.gameHasStarted)
			{
				mls.LogWarning((object)"Game has started. Applying fog settings.");
				((MonoBehaviour)Instance).StartCoroutine(ApplyFogSettingsRepeated(8));
			}
			else if (verboseLoggingEnabled)
			{
				mls.LogInfo((object)$"{waitTime}s Timeout reached, game has not started yet. Fog settings not applied.");
			}
			applyingFogSettings = false;
		}

		private static IEnumerator ApplyFogSettingsRepeated(int repeatCount)
		{
			for (int i = 0; i < repeatCount; i++)
			{
				if (verboseLoggingEnabled)
				{
					mls.LogInfo((object)$"Applying fog settings... ({i + 1}/{repeatCount})");
				}
				ApplyFogSettings();
				yield return (object)new WaitForSecondsRealtime(1f);
			}
		}

		public static void NextPreset()
		{
			mls.LogInfo((object)"Next preset hotkey pressed.");
			currentPresetIndex = fogConfigPresets.IndexOf(currentPreset);
			if (currentPresetIndex == fogConfigPresets.Count - 1)
			{
				currentPresetIndex = -1;
			}
			currentPresetIndex++;
			currentPreset = fogConfigPresets[currentPresetIndex];
			mls.LogInfo((object)("Switched to preset: " + currentPreset.PresetName));
			ApplyFogSettings();
			FogSettingsManager.Instance.UpdateSettings();
		}

		public static void NextMode()
		{
			mls.LogInfo((object)"Next mode hotkey pressed.");
			currentModeIndex = fogModes.IndexOf(currentMode);
			if (currentModeIndex == fogModes.Count - 1)
			{
				currentModeIndex = -1;
			}
			currentModeIndex++;
			currentMode = fogModes[currentModeIndex];
			mls.LogInfo((object)("Switched to mode: " + currentMode.Name));
			Instance.UpdateMode();
			FogSettingsManager.Instance.UpdateSettings();
		}

		public void UpdateMode()
		{
			if (currentMode.Name == "No Fog")
			{
				mls.LogInfo((object)"No Fog mode selected.");
				EnableFogPatch();
				fogRefreshLock = true;
				return;
			}
			fogRefreshLock = false;
			DisableFogPatch();
			if (currentMode.Name == "Vanilla")
			{
				mls.LogInfo((object)"Vanilla mode selected.");
				DisableVanillaPatches();
			}
			else
			{
				EnableVanillaPatches();
			}
		}

		private List<WeatherScale> ParseWeatherScales(string configString)
		{
			List<WeatherScale> list = new List<WeatherScale>();
			string[] array = configString.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { '=' });
				if (array3.Length == 2 && float.TryParse(array3[1], out var result))
				{
					list.Add(new WeatherScale(array3[0], result));
				}
			}
			return list;
		}

		private List<MoonScale> ParseMoonScales(string configString)
		{
			List<MoonScale> list = new List<MoonScale>();
			string[] array = configString.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { '=' });
				if (array3.Length == 2 && float.TryParse(array3[1], out var result))
				{
					list.Add(new MoonScale(array3[0], result));
				}
			}
			return list;
		}

		private List<string> ParseDensityScaleBlacklist(string configString)
		{
			List<string> list = new List<string>();
			string[] array = configString.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string item in array2)
			{
				list.Add(item);
			}
			return list;
		}

		public void EnableFogPatch()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Fog), "UpdateShaderVariablesGlobalCBFogParameters", (Type[])null, (Type[])null), new HarmonyMethod(typeof(FogPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			mls.LogInfo((object)"No Fog enabled successfully.");
		}

		public void DisableFogPatch()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(Fog), "UpdateShaderVariablesGlobalCBFogParameters", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			mls.LogInfo((object)"No Fog patch disabled successfully.");
		}

		public void EnableVanillaPatches()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(AudioReverbTrigger), "changeVolume", (Type[])null, (Type[])null), new HarmonyMethod(typeof(AudioReverbTriggerPatch), "changeVolumePrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TimeOfDay), "SetWeatherBasedOnVariables", (Type[])null, (Type[])null), new HarmonyMethod(typeof(TimeOfDayPatch), "SetWeatherBasedOnVariablesPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(ToggleFogTrigger), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(ToggleFogTriggerPatch), "UpdatePatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(ToggleFogTrigger), "OnTriggerEnter", (Type[])null, (Type[])null), new HarmonyMethod(typeof(ToggleFogTriggerPatch), "OnTriggerEnterPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(ToggleFogTrigger), "OnTriggerExit", (Type[])null, (Type[])null), new HarmonyMethod(typeof(ToggleFogTriggerPatch), "OnTriggerExitPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EntranceTeleport), "TeleportPlayer", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(EntranceTeleportPatch), "TeleportPlayerPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "TeleportPlayer", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(PlayerControllerBPatch), "TeleportPlayerPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "SpectateNextPlayer", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(PlayerControllerBPatch), "SpectateNextPlayerPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(NetworkSceneManager), "OnSceneLoaded", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(NetworkSceneManagerPatch), "OnSceneLoadedPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			mls.LogInfo((object)"Vanilla patches enabled successfully!");
		}

		public void DisableVanillaPatches()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(AudioReverbTrigger), "changeVolume", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(TimeOfDay), "SetWeatherBasedOnVariables", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(ToggleFogTrigger), "Update", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(ToggleFogTrigger), "OnTriggerEnter", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(ToggleFogTrigger), "OnTriggerExit", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(EntranceTeleport), "TeleportPlayer", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(PlayerControllerB), "TeleportPlayer", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(PlayerControllerB), "SpectateNextPlayer", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			methodInfo = AccessTools.Method(typeof(NetworkSceneManager), "OnSceneLoaded", (Type[])null, (Type[])null);
			harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "ironthumb.BetterFog");
			mls.LogInfo((object)"Vanilla patches disabled successfully!");
		}

		public static void CollectVanillaValues()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			List<LocalVolumetricFog> list = Resources.FindObjectsOfTypeAll<LocalVolumetricFog>().ToList();
			foreach (LocalVolumetricFog item in list)
			{
				LocalVolumetricFogArtistParameters parameters = item.parameters;
				Color albedo = item.parameters.albedo;
				if (verboseLoggingEnabled)
				{
					mls.LogInfo((object)$"Found LocalVolumetricFog object: {((Object)item).name}, MeanFreePath: {item.parameters.meanFreePath}, AlbedoR: {albedo.r}, AlbedoG: {albedo.g}, AlbedoB: {albedo.b}");
				}
				if (!fogParameterChanges.ContainsKey(((Component)item).gameObject))
				{
					fogParameterChanges[((Component)item).gameObject] = parameters;
					if (verboseLoggingEnabled)
					{
						mls.LogInfo((object)("Captured vanilla fog parameters for " + ((Object)((Component)item).gameObject).name));
					}
				}
			}
		}

		public static void ResetFogToVanilla(GameObject fogObject)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (fogParameterChanges.TryGetValue(fogObject, out var value))
			{
				LocalVolumetricFog component = fogObject.GetComponent<LocalVolumetricFog>();
				if ((Object)(object)component != (Object)null)
				{
					component.parameters = value;
				}
			}
		}

		public void WaitToApplySettings(float seconds)
		{
			((MonoBehaviour)this).StartCoroutine(DelayAndApplySettings(seconds));
		}

		private IEnumerator DelayAndApplySettings(float seconds)
		{
			mls.LogInfo((object)$"Waiting for {seconds} seconds...");
			yield return (object)new WaitForSeconds(seconds);
			mls.LogInfo((object)$"Waited {seconds} seconds.");
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				mls.LogInfo((object)"Game has started. Applying fog settings to moon.");
				ApplyFogSettings();
			}
			else
			{
				mls.LogInfo((object)"Game has not started yet. Refusing to apply fog settings.");
			}
		}

		public PlayerControllerB FindLocalPlayer(ulong localClientId)
		{
			PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
			PlayerControllerB[] array2 = array;
			foreach (PlayerControllerB val in array2)
			{
				if (val.actualClientId == localClientId)
				{
					mls.LogInfo((object)("Local player found: " + ((Object)val).name));
					return val;
				}
			}
			mls.LogError((object)"Local player not found!");
			return null;
		}
	}
}
namespace BetterFog.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class HUDManagerPatch
	{
		[HarmonyPatch("EnableChat_performed")]
		[HarmonyPostfix]
		public static void EnableChat_performedPatch()
		{
			IngameKeybinds.DisableHotkeys();
		}

		[HarmonyPatch("SubmitChat_performed")]
		[HarmonyPostfix]
		public static void SubmitChat_performedPatch()
		{
			IngameKeybinds.EnableHotkeys();
		}

		[HarmonyPatch("OpenMenu_performed")]
		[HarmonyPostfix]
		public static void OpenMenu_performedPatch()
		{
			IngameKeybinds.EnableHotkeys();
		}
	}
	[HarmonyPatch(typeof(LocalVolumetricFog))]
	public static class LocalVolumetricFogPatch
	{
		private static void OnEnablePatch(LocalVolumetricFog __instance)
		{
			//IL_001b: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)"LocalVolumetricFog created, capturing vanilla values.");
			}
			LocalVolumetricFogArtistParameters parameters = __instance.parameters;
			if (!BetterFog.fogParameterChanges.ContainsKey(((Component)__instance).gameObject))
			{
				BetterFog.fogParameterChanges[((Component)__instance).gameObject] = parameters;
				if (BetterFog.verboseLoggingEnabled)
				{
					BetterFog.mls.LogInfo((object)("Captured vanilla fog parameters for " + ((Object)((Component)__instance).gameObject).name));
				}
			}
		}
	}
	[HarmonyPatch]
	public class SceneManagerPatch
	{
		private static MethodBase TargetMethod()
		{
			return typeof(SceneManager).GetMethod("LoadScene", new Type[2]
			{
				typeof(string),
				typeof(LoadSceneParameters)
			});
		}

		[HarmonyPostfix]
		public static void LoadScenePatch(string sceneName, LoadSceneParameters parameters)
		{
			BetterFog.CollectVanillaValues();
			BetterFog.ApplyFogSettings();
		}
	}
	[HarmonyPatch(typeof(ToggleFogTrigger))]
	public class ToggleFogTriggerPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		public static bool UpdatePatch()
		{
			return false;
		}

		[HarmonyPatch("OnTriggerEnter")]
		[HarmonyPrefix]
		public static bool OnTriggerEnterPatch()
		{
			return false;
		}

		[HarmonyPatch("OnTriggerExit")]
		[HarmonyPrefix]
		public static bool OnTriggerExitPatch()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	public class TimeOfDayPatch
	{
		[HarmonyPrefix]
		public static bool SetWeatherBasedOnVariablesPatch()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport))]
	public class EntranceTeleportPatch
	{
		[HarmonyPatch("TeleportPlayer")]
		[HarmonyPostfix]
		public static void TeleportPlayerPatch()
		{
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				BetterFog.mls.LogInfo((object)"Exited dungeon. Applying fog settings to moon.");
				BetterFog.ApplyFogSettings();
			}
		}
	}
	[HarmonyPatch(typeof(AudioReverbTrigger))]
	public class AudioReverbTriggerPatch
	{
		[HarmonyPatch("changeVolume")]
		[HarmonyPrefix]
		public static bool changeVolumePrefix(ref IEnumerator __result, AudioSource aud, float changeVolumeTo, AudioReverbTrigger __instance)
		{
			LocalVolumetricFog localFog = __instance.localFog;
			float fogEnabledAmount = __instance.fogEnabledAmount;
			bool toggleLocalFog = __instance.toggleLocalFog;
			PlayerControllerB playerScript = __instance.playerScript;
			__result = CustomChangeVolumeCoroutine(aud, changeVolumeTo, localFog, fogEnabledAmount, toggleLocalFog, playerScript);
			return false;
		}

		private static IEnumerator CustomChangeVolumeCoroutine(AudioSource aud, float changeVolumeTo, LocalVolumetricFog localFog, float fogEnabledAmount, bool toggleLocalFog, PlayerControllerB playerScript)
		{
			for (int i = 0; i < 40; i++)
			{
				aud.volume = Mathf.Lerp(aud.volume, changeVolumeTo, (float)i / 40f);
				yield return (object)new WaitForSeconds(0.004f);
			}
			playerScript.audioCoroutines.Remove(aud);
			playerScript.audioCoroutines2.Remove(aud);
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class PlayerControllerBPatch
	{
		[HarmonyPatch("TeleportPlayer")]
		[HarmonyPostfix]
		public static void TeleportPlayerPatch()
		{
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				BetterFog.mls.LogInfo((object)"Teleported player. Applying fog settings to moon.");
				BetterFog.ApplyFogSettings();
			}
		}

		[HarmonyPatch("SpectateNextPlayer")]
		[HarmonyPostfix]
		public static void SpectateNextPlayerPatch()
		{
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				BetterFog.mls.LogInfo((object)"Spectating the next player. Applying fog settings to moon.");
				BetterFog.ApplyFogSettings();
			}
		}
	}
	[HarmonyPatch(typeof(NetworkSceneManager))]
	public class NetworkSceneManagerPatch
	{
		[HarmonyPatch("OnSceneLoaded")]
		[HarmonyPostfix]
		public static void OnSceneLoadedPatch()
		{
			BetterFog.mls.LogInfo((object)"OnSceneLoaded invoked. Applying fog settings to moon.");
			BetterFog.ApplyFogSettingsOnGameStart();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		[HarmonyPatch("BeginUsingTerminal")]
		[HarmonyPostfix]
		public static void BeginUsingTerminalPatch()
		{
			IngameKeybinds.DisableHotkeys();
		}

		[HarmonyPatch("QuitTerminal")]
		[HarmonyPostfix]
		public static void QuitTerminalPatch()
		{
			IngameKeybinds.EnableHotkeys();
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("ChangeLevel")]
		[HarmonyPostfix]
		public static void ChangeLevelPatch(StartOfRound __instance, int levelID)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			SelectableLevel currentLevel = __instance.currentLevel;
			if ((int)currentLevel.currentWeather >= 0 && (int)currentLevel.currentWeather < TimeOfDay.Instance.effects.Length)
			{
				WeatherEffect val = TimeOfDay.Instance.effects[currentLevel.currentWeather];
				BetterFog.currentWeatherType = val.name;
			}
			else
			{
				BetterFog.currentWeatherType = "none";
				BetterFog.mls.LogWarning((object)$"Invalid weather index: {currentLevel.currentWeather}. Set to none");
			}
			BetterFog.currentLevel = currentLevel.PlanetName;
			BetterFog.CollectVanillaValues();
			BetterFog.ApplyFogSettings();
		}
	}
}
namespace BetterFog.Input
{
	internal class IngameKeybinds : LcInputActions
	{
		private static IngameKeybinds _instance;

		public InputAction nextPresetHotkey { get; set; }

		public InputAction nextModeHotkey { get; set; }

		public InputAction refreshPresetHotKey { get; set; }

		public InputAction weatherScalePresetHotKey { get; set; }

		public InputAction settingsHotKey { get; set; }

		public static IngameKeybinds Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new IngameKeybinds();
				}
				return _instance;
			}
		}

		internal void InitializeKeybindings(string nextPresetHotkeyString, string nextModeHotkeyString, string refreshHotkeyString, string weatherScaleHotkeyString, string settingsHotkeyString)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Expected O, but got Unknown
			if (nextPresetHotkey != null && nextPresetHotkey.enabled)
			{
				nextPresetHotkey.Disable();
				nextPresetHotkey.performed -= delegate
				{
					BetterFog.NextPreset();
				};
			}
			nextPresetHotkey = new InputAction("Next Fog Preset", (InputActionType)0, "<Keyboard>/" + nextPresetHotkeyString, (string)null, (string)null, (string)null);
			if (BetterFog.nextPresetHotKeyEnabled.Value)
			{
				nextPresetHotkey.Enable();
				nextPresetHotkey.performed += delegate
				{
					BetterFog.NextPreset();
				};
			}
			else
			{
				nextPresetHotkey.Disable();
			}
			if (nextModeHotkey != null && nextModeHotkey.enabled)
			{
				nextModeHotkey.Disable();
				nextModeHotkey.performed -= delegate
				{
					BetterFog.NextMode();
				};
			}
			nextModeHotkey = new InputAction("Next Fog Preset", (InputActionType)0, "<Keyboard>/" + nextModeHotkeyString, (string)null, (string)null, (string)null);
			if (BetterFog.nextModeHotKeyEnabled.Value)
			{
				nextModeHotkey.Enable();
				nextModeHotkey.performed += delegate
				{
					BetterFog.NextMode();
				};
			}
			else
			{
				nextModeHotkey.Disable();
			}
			if (refreshPresetHotKey != null && refreshPresetHotKey.enabled)
			{
				refreshPresetHotKey.Disable();
				refreshPresetHotKey.performed -= delegate
				{
					BetterFog.ApplyFogSettings();
				};
			}
			refreshPresetHotKey = new InputAction("Refresh Fog Preset", (InputActionType)0, "<Keyboard>/" + refreshHotkeyString, (string)null, (string)null, (string)null);
			if (BetterFog.refreshHotKeyEnabled.Value)
			{
				refreshPresetHotKey.Enable();
				refreshPresetHotKey.performed += delegate
				{
					BetterFog.ApplyFogSettings();
				};
			}
			else
			{
				refreshPresetHotKey.Disable();
			}
			if (weatherScalePresetHotKey != null && weatherScalePresetHotKey.enabled)
			{
				weatherScalePresetHotKey.Disable();
				weatherScalePresetHotKey.performed -= delegate
				{
					BetterFog.densityScaleEnabled = !BetterFog.densityScaleEnabled;
					BetterFog.ApplyFogSettings();
					if (FogSettingsManager.Instance.IsSettingsEnabled())
					{
						FogSettingsManager.Instance.UpdateSettings();
					}
				};
			}
			weatherScalePresetHotKey = new InputAction("Weather Scale Preset", (InputActionType)0, "<Keyboard>/" + weatherScaleHotkeyString, (string)null, (string)null, (string)null);
			if (BetterFog.weatherScaleHotKeyEnabled.Value)
			{
				weatherScalePresetHotKey.Enable();
				weatherScalePresetHotKey.performed += delegate
				{
					BetterFog.densityScaleEnabled = !BetterFog.densityScaleEnabled;
					BetterFog.ApplyFogSettings();
					if (FogSettingsManager.Instance.IsSettingsEnabled())
					{
						FogSettingsManager.Instance.UpdateSettings();
					}
				};
			}
			else
			{
				weatherScalePresetHotKey.Disable();
			}
			if (settingsHotKey != null && settingsHotKey.enabled)
			{
				settingsHotKey.Disable();
				settingsHotKey.performed -= delegate
				{
					FogSettingsManager.Instance.ToggleSettings();
				};
			}
			settingsHotKey = new InputAction("Settings", (InputActionType)0, "<Keyboard>/" + settingsHotkeyString, (string)null, (string)null, (string)null);
			if (BetterFog.settingsHotKeyEnabled.Value)
			{
				settingsHotKey.Enable();
				settingsHotKey.performed += delegate
				{
					FogSettingsManager.Instance.ToggleSettings();
				};
			}
			else
			{
				settingsHotKey.Disable();
			}
		}

		public static void DisableHotkeys()
		{
			BetterFog.hotkeysEnabled = false;
			Instance.nextPresetHotkey.Disable();
			Instance.refreshPresetHotKey.Disable();
			Instance.weatherScalePresetHotKey.Disable();
			Instance.settingsHotKey.Disable();
		}

		public static void EnableHotkeys()
		{
			BetterFog.hotkeysEnabled = true;
			Instance.nextPresetHotkey.Enable();
			Instance.refreshPresetHotKey.Enable();
			Instance.weatherScalePresetHotKey.Enable();
			Instance.settingsHotKey.Enable();
		}
	}
	[HarmonyPatch]
	public static class KeybindDisplayNames
	{
		public static bool usingControllerPrevious = false;

		public static string[] keyboardKeywords = new string[2] { "keyboard", "mouse" };

		public static string[] controllerKeywords = new string[2] { "gamepad", "controller" };

		public static bool usingController => StartOfRound.Instance.localPlayerUsingController;

		public static string GetKeybindDisplayName(InputAction inputAction)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			if (inputAction == null || !inputAction.enabled)
			{
				return "";
			}
			int num = (usingController ? 1 : 0);
			InputBinding val = inputAction.bindings[num];
			string effectivePath = ((InputBinding)(ref val)).effectivePath;
			return GetKeybindDisplayName(effectivePath);
		}

		public static string GetKeybindDisplayName(string controlPath)
		{
			if (controlPath.Length <= 1)
			{
				return "";
			}
			string text = controlPath.ToLower();
			int num = text.IndexOf(">/");
			text = ((num >= 0) ? text.Substring(num + 2) : text);
			if (text.Contains("not-bound"))
			{
				return "";
			}
			text = text.Replace("leftalt", "Alt");
			text = text.Replace("rightalt", "Alt");
			text = text.Replace("leftctrl", "Ctrl");
			text = text.Replace("rightctrl", "Ctrl");
			text = text.Replace("leftshift", "Shift");
			text = text.Replace("rightshift", "Shift");
			text = text.Replace("leftbutton", "LMB");
			text = text.Replace("rightbutton", "RMB");
			text = text.Replace("middlebutton", "MMB");
			text = text.Replace("lefttrigger", "LT");
			text = text.Replace("righttrigger", "RT");
			text = text.Replace("leftshoulder", "LB");
			text = text.Replace("rightshoulder", "RB");
			text = text.Replace("leftstickpress", "LS");
			text = text.Replace("rightstickpress", "RS");
			text = text.Replace("dpad/", "DPad-");
			text = text.Replace("backquote", "`");
			try
			{
				text = char.ToUpper(text[0]) + text.Substring(1);
			}
			catch
			{
			}
			return text;
		}
	}
}
namespace BetterFog.Assets
{
	public class FogConfigPreset
	{
		public string PresetName { get; set; }

		public float MeanFreePath { get; set; }

		public float AlbedoR { get; set; }

		public float AlbedoG { get; set; }

		public float AlbedoB { get; set; }

		public FogConfigPreset()
		{
		}

		public FogConfigPreset(string presetName, float meanFreePath, float albedoR, float albedoG, float albedoB)
		{
			PresetName = presetName;
			MeanFreePath = meanFreePath;
			AlbedoR = albedoR;
			AlbedoG = albedoG;
			AlbedoB = albedoB;
		}

		public override string ToString()
		{
			return $"PresetName={PresetName},Density={MeanFreePath},Red Hue={AlbedoR},Green Hue={AlbedoG},Blue Hue={AlbedoB}";
		}
	}
	public class BetterFogMode
	{
		public string Name { get; set; }

		public string Description { get; set; }

		public string FogType { get; set; }

		public BetterFogMode(string name)
		{
			Name = name;
		}
	}
	public class FogSettingsManager : MonoBehaviour
	{
		private bool isSettingsEnabled = false;

		private AssetBundle fogsettingsgui;

		private GameObject settingsCanvas;

		private GameObject settingsText;

		private GameObject settingsInteractables;

		private TMP_FontAsset customFont;

		public TMP_Dropdown modeDropdown;

		public TMP_Dropdown presetDropdown;

		private Slider fogDensitySlider;

		private TMP_InputField densityValInput;

		private Slider fogRedSlider;

		private TMP_InputField redValInput;

		private Slider fogGreenSlider;

		private TMP_InputField greenValInput;

		private Slider fogBlueSlider;

		private TMP_InputField blueValInput;

		public Toggle densityScaleCheckbox;

		public TextMeshProUGUI densityScaleVal;

		public Toggle excludeShipCheckbox;

		public Toggle excludeEnemiesCheckbox;

		public Toggle verboseLogsCheckbox;

		private Button closeButton;

		private static FogSettingsManager instance;

		private static bool isInitializing;

		private int previousModeIndex;

		public static FogSettingsManager Instance
		{
			get
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null && !isInitializing)
				{
					isInitializing = true;
					if (BetterFog.verboseLoggingEnabled)
					{
						BetterFog.mls.LogInfo((object)"Instance is null, creating new instance.");
					}
					GameObject val = new GameObject("FogSettingsManager");
					Object.DontDestroyOnLoad((Object)(object)val);
					instance = val.AddComponent<FogSettingsManager>();
					instance.Initialize();
					isInitializing = false;
				}
				return instance;
			}
		}

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				if (BetterFog.verboseLoggingEnabled)
				{
					BetterFog.mls.LogInfo((object)"FogSettingsManager created and started.");
				}
			}
			else if ((Object)(object)instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				if (BetterFog.verboseLoggingEnabled)
				{
					BetterFog.mls.LogWarning((object)"FogSettingsManager already exists. Duplicate destroyed.");
				}
			}
		}

		private void Initialize()
		{
			BetterFog.mls.LogInfo((object)"Initializing FogSettingsManager.");
			string[] files = Directory.GetFiles(Paths.PluginPath, "fogsettingsgui", SearchOption.AllDirectories);
			if (files.Length != 0)
			{
				string text = files[0];
				fogsettingsgui = AssetBundle.LoadFromFile(text);
				if ((Object)(object)fogsettingsgui != (Object)null)
				{
					BetterFog.mls.LogInfo((object)"AssetBundle loaded successfully.");
					LoadAssetsFromBundle();
				}
				else
				{
					BetterFog.mls.LogError((object)"Failed to load AssetBundle.");
				}
			}
			else
			{
				BetterFog.mls.LogError((object)"fogsettingsgui file not found in any subdirectory of BepInEx/plugins.");
			}
			previousModeIndex = BetterFog.currentModeIndex;
		}

		private void LoadAssetsFromBundle()
		{
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Expected O, but got Unknown
			if ((Object)(object)fogsettingsgui != (Object)null)
			{
				BetterFog.mls.LogInfo((object)"AssetBundle loaded successfully.");
				customFont = fogsettingsgui.LoadAsset<TMP_FontAsset>("3270Condensed-Regular SDF");
				BetterFog.mls.LogInfo((object)"If you see an error indicating 'shader compiler platform 4 is not available', nothing is broken.");
				if (!((Object)(object)customFont != (Object)null))
				{
					BetterFog.mls.LogError((object)"Custom font asset not found in AssetBundle.");
				}
				Shader val = Shader.Find("TextMeshPro/Distance Field");
				if ((Object)(object)val != (Object)null)
				{
					((TMP_Asset)customFont).material.shader = val;
				}
				else
				{
					BetterFog.mls.LogError((object)"TextMeshPro/Distance Field shader not found!");
				}
				GameObject val2 = fogsettingsgui.LoadAsset<GameObject>("FogSettingsCanvas");
				if ((Object)(object)val2 != (Object)null)
				{
					settingsCanvas = Object.Instantiate<GameObject>(val2);
					settingsCanvas.SetActive(false);
					BetterFog.mls.LogInfo((object)"FogSettingsCanvas instantiated and hidden.");
					ApplyCustomFont(settingsCanvas);
					BetterFog.mls.LogInfo((object)"Custom font applied to TextMeshPro components.");
					settingsInteractables = ((Component)settingsCanvas.transform.Find("Interactables")).gameObject;
					settingsText = ((Component)settingsCanvas.transform.Find("Text")).gameObject;
					presetDropdown = ((Component)settingsInteractables.transform.Find("PresetDropdown")).GetComponent<TMP_Dropdown>();
					PopulateDropdown(presetDropdown);
					if (BetterFog.verboseLoggingEnabled)
					{
						BetterFog.mls.LogInfo((object)"Fog preset dropdown is now populated.");
					}
					SetCurrentOption(presetDropdown);
					modeDropdown = ((Component)settingsInteractables.transform.Find("ModeDropdown")).GetComponent<TMP_Dropdown>();
					PopulateDropdown(modeDropdown);
					if (BetterFog.verboseLoggingEnabled)
					{
						BetterFog.mls.LogInfo((object)"Fog mode dropdown is now populated.");
					}
					SetCurrentOption(modeDropdown);
					fogDensitySlider = ((Component)settingsInteractables.transform.Find("DensitySlider")).GetComponent<Slider>();
					densityValInput = ((Component)settingsInteractables.transform.Find("DensityInput")).GetComponent<TMP_InputField>();
					fogRedSlider = ((Component)settingsInteractables.transform.Find("RedHueSlider")).GetComponent<Slider>();
					redValInput = ((Component)settingsInteractables.transform.Find("RedHueInput")).GetComponent<TMP_InputField>();
					BetterFog.mls.LogInfo((object)"Fog red hue slider and input found.");
					fogGreenSlider = ((Component)settingsInteractables.transform.Find("GreenHueSlider")).GetComponent<Slider>();
					greenValInput = ((Component)settingsInteractables.transform.Find("GreenHueInput")).GetComponent<TMP_InputField>();
					fogBlueSlider = ((Component)settingsInteractables.transform.Find("BlueHueSlider")).GetComponent<Slider>();
					blueValInput = ((Component)settingsInteractables.transform.Find("BlueHueInput")).GetComponent<TMP_InputField>();
					densityScaleCheckbox = ((Component)settingsInteractables.transform.Find("DensityScaleToggle")).GetComponent<Toggle>();
					densityScaleCheckbox.isOn = BetterFog.densityScaleEnabled;
					densityScaleVal = ((Component)settingsText.transform.Find("DensityScaleVal")).GetComponent<TextMeshProUGUI>();
					excludeShipCheckbox = ((Component)settingsInteractables.transform.Find("ExcludeShipToggle")).GetComponent<Toggle>();
					excludeShipCheckbox.isOn = BetterFog.excludeShipFogEnabled;
					excludeEnemiesCheckbox = ((Component)settingsInteractables.transform.Find("ExcludeEnemiesToggle")).GetComponent<Toggle>();
					excludeEnemiesCheckbox.isOn = BetterFog.excludeEnemyFogEnabled;
					verboseLogsCheckbox = ((Component)settingsInteractables.transform.Find("VerboseLogsToggle")).GetComponent<Toggle>();
					verboseLogsCheckbox.isOn = BetterFog.verboseLoggingEnabled;
					closeButton = ((Component)settingsInteractables.transform.Find("CloseButton")).GetComponent<Button>();
					if ((Object)(object)fogDensitySlider != (Object)null && (Object)(object)densityValInput != (Object)null)
					{
						densityValInput.text = fogDensitySlider.value.ToString();
						redValInput.text = fogRedSlider.value.ToString();
						greenValInput.text = fogGreenSlider.value.ToString();
						blueValInput.text = fogBlueSlider.value.ToString();
						((UnityEvent<float>)(object)fogDensitySlider.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
						{
							OnSliderValueChanged(fogDensitySlider, value);
						});
						((UnityEvent<float>)(object)fogRedSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
						{
							OnSliderValueChanged(fogRedSlider, value);
						});
						((UnityEvent<float>)(object)fogGreenSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
						{
							OnSliderValueChanged(fogGreenSlider, value);
						});
						((UnityEvent<float>)(object)fogBlueSlider.onValueChanged).AddListener((UnityAction<float>)delegate(float value)
						{
							OnSliderValueChanged(fogBlueSlider, value);
						});
						((UnityEvent<string>)(object)densityValInput.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
						{
							OnInputValueChanged(densityValInput, value);
						});
						((UnityEvent<string>)(object)redValInput.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
						{
							OnInputValueChanged(redValInput, value);
						});
						((UnityEvent<string>)(object)greenValInput.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
						{
							OnInputValueChanged(greenValInput, value);
						});
						((UnityEvent<string>)(object)blueValInput.onValueChanged).AddListener((UnityAction<string>)delegate(string value)
						{
							OnInputValueChanged(blueValInput, value);
						});
						((UnityEvent<bool>)(object)densityScaleCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnDensityScaleCheckboxValueChanged(isChecked);
						});
						((UnityEvent<bool>)(object)excludeEnemiesCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnExcludeEnemiesCheckboxValueChanged(isChecked);
						});
						((UnityEvent<bool>)(object)excludeShipCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnExcludeShipCheckboxValueChanged(isChecked);
						});
						((UnityEvent<bool>)(object)verboseLogsCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnVerboseLogsCheckboxValueChanged(isChecked);
						});
						((UnityEvent)closeButton.onClick).AddListener((UnityAction)delegate
						{
							DisableSettings();
						});
					}
				}
				else
				{
					BetterFog.mls.LogError((object)"FogSettings prefab not found in AssetBundle.");
				}
			}
			else
			{
				BetterFog.mls.LogError((object)"Failed to load AssetBundle.");
			}
		}

		private void ApplyCustomFont(GameObject canvas)
		{
			TextMeshProUGUI[] componentsInChildren = canvas.GetComponentsInChildren<TextMeshProUGUI>();
			TextMeshProUGUI[] array = componentsInChildren;
			foreach (TextMeshProUGUI val in array)
			{
				((TMP_Text)val).font = customFont;
			}
			TMP_Dropdown[] componentsInChildren2 = canvas.GetComponentsInChildren<TMP_Dropdown>();
			TMP_Dropdown[] array2 = componentsInChildren2;
			foreach (TMP_Dropdown val2 in array2)
			{
				if ((Object)(object)val2.captionText != (Object)null)
				{
					val2.captionText.font = customFont;
				}
				RectTransform template = val2.template;
				Transform val3 = ((template != null) ? ((Transform)template).Find("Viewport/Content/Item") : null);
				if ((Object)(object)val3 != (Object)null)
				{
					TextMeshProUGUI[] componentsInChildren3 = ((Component)val3).GetComponentsInChildren<TextMeshProUGUI>();
					TextMeshProUGUI[] array3 = componentsInChildren3;
					foreach (TextMeshProUGUI val4 in array3)
					{
						((TMP_Text)val4).font = customFont;
					}
				}
			}
		}

		private void OnValueChanged(string sourceName, float value)
		{
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)$"Value changed: {sourceName} = {value}");
			}
			switch (sourceName)
			{
			case "Density":
				if ((Object)(object)fogDensitySlider != (Object)null && (Object)(object)densityValInput != (Object)null)
				{
					fogDensitySlider.value = value;
					densityValInput.text = value.ToString("0");
					BetterFog.currentPreset.MeanFreePath = value;
				}
				break;
			case "Red":
				if ((Object)(object)fogRedSlider != (Object)null && (Object)(object)redValInput != (Object)null)
				{
					fogRedSlider.value = value;
					redValInput.text = value.ToString("0.00");
					BetterFog.currentPreset.AlbedoR = value;
				}
				break;
			case "Green":
				if ((Object)(object)fogGreenSlider != (Object)null && (Object)(object)greenValInput != (Object)null)
				{
					fogGreenSlider.value = value;
					greenValInput.text = value.ToString("0.00");
					BetterFog.currentPreset.AlbedoG = value;
				}
				break;
			case "Blue":
				if ((Object)(object)fogBlueSlider != (Object)null && (Object)(object)blueValInput != (Object)null)
				{
					fogBlueSlider.value = value;
					blueValInput.text = value.ToString("0.00");
					BetterFog.currentPreset.AlbedoB = value;
				}
				break;
			}
			BetterFog.ApplyFogSettings();
		}

		private void OnSliderValueChanged(Slider slider, float value)
		{
			if ((Object)(object)slider == (Object)(object)fogDensitySlider)
			{
				OnValueChanged("Density", value);
			}
			else if ((Object)(object)slider == (Object)(object)fogRedSlider)
			{
				OnValueChanged("Red", value);
			}
			else if ((Object)(object)slider == (Object)(object)fogGreenSlider)
			{
				OnValueChanged("Green", value);
			}
			else if ((Object)(object)slider == (Object)(object)fogBlueSlider)
			{
				OnValueChanged("Blue", value);
			}
		}

		private void OnInputValueChanged(TMP_InputField input, string inputValue)
		{
			if (float.TryParse(inputValue, out var result))
			{
				if ((Object)(object)input == (Object)(object)densityValInput)
				{
					OnValueChanged("Density", result);
				}
				else if ((Object)(object)input == (Object)(object)redValInput)
				{
					OnValueChanged("Red", result);
				}
				else if ((Object)(object)input == (Object)(object)greenValInput)
				{
					OnValueChanged("Green", result);
				}
				else if ((Object)(object)input == (Object)(object)blueValInput)
				{
					OnValueChanged("Blue", result);
				}
			}
		}

		private void UpdateSlidersWithCurrentPreset()
		{
			if ((Object)(object)fogDensitySlider != (Object)null && (Object)(object)densityValInput != (Object)null && (Object)(object)fogRedSlider != (Object)null && (Object)(object)redValInput != (Object)null && (Object)(object)fogGreenSlider != (Object)null && (Object)(object)greenValInput != (Object)null && (Object)(object)fogBlueSlider != (Object)null && (Object)(object)blueValInput != (Object)null && BetterFog.currentPreset != null)
			{
				fogDensitySlider.value = BetterFog.currentPreset.MeanFreePath;
				densityValInput.text = fogDensitySlider.value.ToString();
				fogRedSlider.value = BetterFog.currentPreset.AlbedoR;
				redValInput.text = fogRedSlider.value.ToString();
				fogGreenSlider.value = BetterFog.currentPreset.AlbedoG;
				greenValInput.text = fogGreenSlider.value.ToString();
				fogBlueSlider.value = BetterFog.currentPreset.AlbedoB;
				blueValInput.text = fogBlueSlider.value.ToString();
			}
		}

		private void OnDensityScaleCheckboxValueChanged(bool isChecked)
		{
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)$"Density Scale Checkbox value changed: {isChecked}");
			}
			BetterFog.densityScaleEnabled = isChecked;
			BetterFog.ApplyFogSettings();
		}

		private void OnExcludeShipCheckboxValueChanged(bool isChecked)
		{
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)$"Exclude Ship Checkbox value changed: {isChecked}");
			}
			BetterFog.excludeShipFogEnabled = isChecked;
			BetterFog.ApplyFogSettings();
		}

		private void OnExcludeEnemiesCheckboxValueChanged(bool isChecked)
		{
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)$"Exclude Enemies Checkbox value changed: {isChecked}");
			}
			BetterFog.excludeEnemyFogEnabled = isChecked;
			BetterFog.ApplyFogSettings();
		}

		private void OnVerboseLogsCheckboxValueChanged(bool isChecked)
		{
			if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogInfo((object)$"Verbose Logs Checkbox value changed: {isChecked}");
			}
			BetterFog.verboseLoggingEnabled = isChecked;
			BetterFog.ApplyFogSettings();
		}

		private void UpdateCheckboxValues()
		{
			UpdateDensityScaleCheckbox();
			UpdateExcludeShipCheckbox();
			UpdateExcludeEnemiesCheckbox();
			UpdateVerboseLogsCheckbox();
		}

		private void UpdateDensityScaleCheckbox()
		{
			if ((Object)(object)densityScaleCheckbox != (Object)null)
			{
				densityScaleCheckbox.isOn = BetterFog.densityScaleEnabled;
			}
		}

		private void UpdateExcludeShipCheckbox()
		{
			if ((Object)(object)excludeShipCheckbox != (Object)null)
			{
				excludeShipCheckbox.isOn = BetterFog.excludeShipFogEnabled;
			}
		}

		private void UpdateExcludeEnemiesCheckbox()
		{
			if ((Object)(object)excludeEnemiesCheckbox != (Object)null)
			{
				excludeEnemiesCheckbox.isOn = BetterFog.excludeShipFogEnabled;
			}
		}

		private void UpdateVerboseLogsCheckbox()
		{
			if ((Object)(object)verboseLogsCheckbox != (Object)null)
			{
				verboseLogsCheckbox.isOn = BetterFog.verboseLoggingEnabled;
			}
		}

		private void PopulateDropdown(TMP_Dropdown dropdown)
		{
			try
			{
				dropdown.ClearOptions();
				if ((Object)(object)dropdown == (Object)(object)presetDropdown)
				{
					dropdown.AddOptions(GetFogPresets());
				}
				else if ((Object)(object)dropdown == (Object)(object)modeDropdown)
				{
					dropdown.AddOptions(GetFogModes());
				}
			}
			catch
			{
				BetterFog.mls.LogError((object)"Dropdown does not exist. Cannot populate");
			}
		}

		private List<string> GetFogPresets()
		{
			List<string> list = new List<string>();
			foreach (FogConfigPreset fogConfigPreset in BetterFog.fogConfigPresets)
			{
				list.Add(fogConfigPreset.PresetName);
			}
			return list;
		}

		private List<string> GetFogModes()
		{
			List<string> list = new List<string>();
			foreach (BetterFogMode fogMode in BetterFog.fogModes)
			{
				list.Add(fogMode.Name);
			}
			return list;
		}

		private void SetCurrentOption(TMP_Dropdown dropdown)
		{
			if (!((Object)(object)dropdown != (Object)null))
			{
				return;
			}
			UpdateDropdownWithCurrentOption(dropdown);
			((UnityEventBase)dropdown.onValueChanged).RemoveAllListeners();
			if ((Object)(object)dropdown == (Object)(object)presetDropdown)
			{
				((UnityEvent<int>)(object)dropdown.onValueChanged).AddListener((UnityAction<int>)OnPresetChanged);
			}
			else if ((Object)(object)dropdown == (Object)(object)modeDropdown)
			{
				((UnityEvent<int>)(object)dropdown.onValueChanged).AddListener((UnityAction<int>)delegate
				{
					OnModeChanged(dropdown.value, previousModeIndex);
					previousModeIndex = dropdown.value;
				});
			}
		}

		public void UpdateSettings()
		{
			((TMP_Text)densityScaleVal).text = BetterFog.combinedDensityScale.ToString("00.000");
			UpdateDropdownWithCurrentOption(presetDropdown);
			UpdateDropdownWithCurrentOption(modeDropdown);
			UpdateSlidersWithCurrentPreset();
			UpdateCheckboxValues();
		}

		private void UpdateDropdownWithCurrentOption(TMP_Dropdown dropdown)
		{
			if ((Object)(object)dropdown != (Object)null)
			{
				if ((Object)(object)dropdown == (Object)(object)presetDropdown)
				{
					dropdown.value = BetterFog.currentPresetIndex;
					if (BetterFog.verboseLoggingEnabled)
					{
						BetterFog.mls.LogInfo((object)("Preset dropdown updated to: " + BetterFog.fogConfigPresets[dropdown.value].PresetName));
					}
				}
				else if ((Object)(object)dropdown == (Object)(object)modeDropdown)
				{
					dropdown.value = BetterFog.currentModeIndex;
					if (BetterFog.verboseLoggingEnabled)
					{
						BetterFog.mls.LogInfo((object)("Mode dropdown updated to: " + BetterFog.fogModes[dropdown.value].Name));
					}
				}
			}
			else if (BetterFog.verboseLoggingEnabled)
			{
				BetterFog.mls.LogError((object)"Dropdown is null. Cannot update");
			}
		}

		private void OnPresetChanged(int index)
		{
			BetterFog.currentPresetIndex = index;
			BetterFog.currentPreset = BetterFog.fogConfigPresets[index];
			UpdateSlidersWithCurrentPreset();
			ApplyPreset(BetterFog.currentPreset);
		}

		private void OnModeChanged(int currentIndex, int previousIndex)
		{
			BetterFog.currentModeIndex = currentIndex;
			BetterFog.currentMode = BetterFog.fogModes[currentIndex];
			BetterFog.Instance.UpdateMode();
			BetterFog.ApplyFogSettings();
		}

		private void ApplyPreset(FogConfigPreset preset)
		{
			BetterFog.currentPresetIndex = BetterFog.fogConfigPresets.IndexOf(preset);
			BetterFog.currentPreset = preset;
			BetterFog.ApplyFogSettings();
		}

		public void ToggleSettings()
		{
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsClient)
			{
				BetterFog.mls.LogError((object)"FogSettingsManager cannot be manipulated when not in a lobby.");
				return;
			}
			if (isSettingsEnabled)
			{
				DisableSettings();
				return;
			}
			EnableSettings();
			UpdateSettings();
		}

		public void EnableSettings()
		{
			ulong localClientId = NetworkManager.Singleton.LocalClientId;
			BetterFog.player = BetterFog.Instance.FindLocalPlayer(localClientId);
			BetterFog.player.disableInteract = true;
			BetterFog.player.disableLookInput = true;
			BetterFog.player.disableMoveInput = true;
			BetterFog.player.inSpecialMenu = true;
			isSettingsEnabled = true;
			if ((Object)(object)settingsCanvas == (Object)null)
			{
				Object.Destroy((Object)(object)settingsCanvas);
				settingsCanvas = null;
				if (BetterFog.verboseLoggingEnabled)
				{
					BetterFog.mls.LogWarning((object)"Canvas prefab not found. Initializing new Canvas.");
				}
				UnloadAssetBundle();
				Initialize();
			}
			settingsCanvas.SetActive(true);
			SetCurrentOption(presetDropdown);
			SetCurrentOption(modeDropdown);
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			BetterFog.mls.LogInfo((object)"Fog Settings opened.");
			BetterFog.mls.LogInfo((object)$"disableInteract: {BetterFog.player.disableInteract}, disableLookInput {BetterFog.player.disableLookInput}, disableMoveInput: {BetterFog.player.disableMoveInput}");
		}

		private void UnloadAssetBundle()
		{
			if ((Object)(object)fogsettingsgui != (Object)null)
			{
				fogsettingsgui.Unload(true);
				fogsettingsgui = null;
				BetterFog.mls.LogInfo((object)"AssetBundle unloaded.");
			}
		}

		public void DisableSettings()
		{
			BetterFog.player.disableInteract = false;
			BetterFog.player.disableLookInput = false;
			BetterFog.player.disableMoveInput = false;
			BetterFog.player.inSpecialMenu = false;
			isSettingsEnabled = false;
			if ((Object)(object)settingsCanvas != (Object)null)
			{
				settingsCanvas.SetActive(false);
				BetterFog.mls.LogInfo((object)"Fog Settings closed.");
			}
			else
			{
				Object.Destroy((Object)(object)settingsCanvas);
				settingsCanvas = null;
				if (BetterFog.verboseLoggingEnabled)
				{
					BetterFog.mls.LogWarning((object)"Canvas prefab not found. Initializing new Canvas.");
				}
				UnloadAssetBundle();
				Initialize();
			}
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsClient)
			{
				Cursor.lockState = (CursorLockMode)1;
			}
			Cursor.visible = false;
		}

		private void OnDestroy()
		{
			if ((Object)(object)fogsettingsgui != (Object)null)
			{
				fogsettingsgui.Unload(false);
			}
			instance = null;
		}

		public bool IsSettingsEnabled()
		{
			return isSettingsEnabled;
		}
	}
	public class MoonScale
	{
		public string MoonName { get; set; }

		public float Scale { get; set; }

		public MoonScale()
		{
		}

		public override string ToString()
		{
			return $"{MoonName}:{Scale}";
		}

		public MoonScale(string moonName, float scale)
		{
			MoonName = moonName;
			Scale = scale;
		}
	}
	public class WeatherScale
	{
		public string WeatherName { get; set; }

		public float Scale { get; set; }

		public WeatherScale(string weatherName, float weatherScale)
		{
			WeatherName = weatherName;
			Scale = weatherScale;
		}

		public List<WeatherScale> ParseWeatherScales(string configString)
		{
			List<WeatherScale> list = new List<WeatherScale>();
			string[] array = configString.Split(new char[1] { ';' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { '=' });
				if (array3.Length == 2 && float.TryParse(array3[1], out var result))
				{
					list.Add(new WeatherScale(array3[0], result));
				}
			}
			return list;
		}
	}
}