Decompiled source of BetterFog v3.2.4

BepInEx/plugins/BetterFog.dll

Decompiled 2 days 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 UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Rendering.HighDefinition;
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")]
namespace BetterFog
{
	[BepInPlugin("ironthumb.BetterFog", "BetterFog", "3.2.3")]
	public class BetterFog : BaseUnityPlugin
	{
		public const string modGUID = "ironthumb.BetterFog";

		public const string modName = "BetterFog";

		public const string modVersion = "3.2.3";

		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> nextHotKeyEnabled;

		private static ConfigEntry<string> refreshPresetHotkeyConfig;

		public static ConfigEntry<bool> refreshHotKeyEnabled;

		public static ConfigEntry<string> weatherScaleHotkeyConfig;

		public static ConfigEntry<bool> weatherScaleHotKeyEnabled;

		private static ConfigEntry<bool> applyToFogExclusionZone;

		private static ConfigEntry<bool> noFogEnabled;

		public static ConfigEntry<bool> guiEnabled;

		private static ConfigEntry<bool> weatherScaleEnabled;

		public static bool isDensityScaleEnabled;

		public static string currentWeatherType = "None";

		private static float currentDensityScale = 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 bool applyingFogSettings = false;

		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()
		{
			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, noFog: false),
				new FogConfigPreset("Heavy Fog", 50f, 0f, 0f, 0f, noFog: false),
				new FogConfigPreset("Light Fog", 9850f, 5f, 5f, 5f, noFog: false),
				new FogConfigPreset("Red Fog", 500f, 20f, 0f, 0f, noFog: false),
				new FogConfigPreset("Orange Fog", 500f, 20f, 9.33f, 4.5f, noFog: false),
				new FogConfigPreset("Yellow Fog", 1300f, 20f, 20f, 0f, noFog: false),
				new FogConfigPreset("Green Fog", 1300f, 0f, 20f, 0f, noFog: false),
				new FogConfigPreset("Blue Fog", 1300f, 37f, 155f, 218f, noFog: false),
				new FogConfigPreset("Purple Fog", 500f, 11.5f, 7.2f, 20f, noFog: false),
				new FogConfigPreset("Pink Fog", 500f, 20f, 4.75f, 20f, noFog: false),
				new FogConfigPreset("No Fog", 10000000f, 1f, 1f, 1f, noFog: true)
			};
			mls.LogInfo((object)"FogConfigPresets initialized.");
			string text = "Default Fog Preset";
			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, NoFog\nMean Free Path - Density of fog. The greater the number, the less dense. 50000 is max (less fog) and 0 is min (more fog).\nAlbedo Color - Color of fog. 255 is max and 0 is min.\nNo Fog - Density is negligible, so no fog appears when set to true.\n");
			string text2 = "Key Bindings";
			nextPresetHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Next Preset Hotkey", "n", "Hotkey to switch to the next fog preset.");
			nextHotKeyEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text2, "Enable Next Hotkey", true, "Enable or disable hotkeys for switching fog presets.");
			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 Sale Hotkey", false, "Enable or disable hotkey for Weather Scaling toggle.");
			string text3 = "Fog Settings";
			applyToFogExclusionZone = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Apply to Fog Exclusion Zone", false, "Apply fog settings to the Fog Exclusion Zone (eg. inside of ship).");
			noFogEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "No Fog Enabled Default", false, "Set value to true to enable No Fog by default.");
			weatherScaleEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Weather Scale Enabled Default", true, "Enable weather scaling for fog presets.");
			guiEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "GUI Enabled", true, "Enable or disable the GUI for the mod.");
			IngameKeybinds.Instance.InitializeKeybindings(nextPresetHotkeyConfig.Value, refreshPresetHotkeyConfig.Value, weatherScaleHotkeyConfig.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 text4 = "Weather Scales";
			moonScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text4, "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,...} Moon Scales are applied before weather fog density scales.");
			MoonScales = ParseMoonScales(moonScalesConfig.Value);
			weatherScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text4, "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,...} Weather Scales are applied after moon fog density scales.");
			WeatherScales = ParseWeatherScales(weatherScalesConfig.Value);
			mls.LogInfo((object)"Finished Parsing");
			if (defaultPresetName == null)
			{
				currentPreset = FogConfigPresets[0];
				currentPresetIndex = 0;
			}
			else
			{
				try
				{
					currentPreset = FogConfigPresets.Find((FogConfigPreset preset) => preset.PresetName == defaultPresetName.Value);
					currentPresetIndex = FogConfigPresets.IndexOf(currentPreset);
				}
				catch (Exception arg)
				{
					mls.LogError((object)$"Failed to find the default preset: {arg}");
					currentPreset = FogConfigPresets[0];
					currentPresetIndex = 0;
				}
			}
			currentPreset.NoFog = noFogEnabled.Value;
			isDensityScaleEnabled = weatherScaleEnabled.Value;
			try
			{
				harmony.PatchAll(typeof(StartOfRoundPatch).Assembly);
				mls.LogInfo((object)"StartOfRound patches applied successfully.");
				harmony.PatchAll(typeof(QuickMenuManagerPatch).Assembly);
				mls.LogInfo((object)"QuickMenuManager patches applied successfully.");
				harmony.PatchAll(typeof(IngamePlayerSettingsPatch).Assembly);
				mls.LogInfo((object)"IngamePlayerSettings patches applied successfully.");
				harmony.PatchAll(typeof(EntranceTeleportPatch).Assembly);
				mls.LogInfo((object)"EntranceTeleport patches applied successfully.");
				harmony.PatchAll(typeof(TerminalPatch).Assembly);
				mls.LogInfo((object)"Terminal patches applied successfully.");
				harmony.PatchAll(typeof(AudioReverbTriggerPatch).Assembly);
				mls.LogInfo((object)"AudioReverb patches applied successfully.");
			}
			catch (Exception arg2)
			{
				mls.LogError((object)$"Failed to apply Harmony patches: {arg2}");
				throw;
			}
			if ((Object)(object)FogSettingsManager.Instance != (Object)null)
			{
				mls.LogInfo((object)((object)FogSettingsManager.Instance).ToString());
			}
			else
			{
				mls.LogError((object)"FogSettingsManager instance is null.");
			}
		}

		public static void ApplyFogSettings()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			List<LocalVolumetricFog> list = Resources.FindObjectsOfTypeAll<LocalVolumetricFog>().ToList();
			foreach (LocalVolumetricFog item in list)
			{
				if (!((Object)(object)item != (Object)null) || (((Object)item).name == "FogExclusionZone" && !applyToFogExclusionZone.Value))
				{
					continue;
				}
				LocalVolumetricFogArtistParameters parameters = item.parameters;
				if (currentPreset.NoFog)
				{
					parameters.meanFreePath = 10000000f;
					parameters.albedo = new Color(1f, 1f, 1f, 0f);
				}
				else
				{
					if (isDensityScaleEnabled)
					{
						currentDensityScale = 1f;
						foreach (MoonScale moonScale in MoonScales)
						{
							if (currentLevel == moonScale.MoonName)
							{
								currentDensityScale = moonScale.Scale;
								mls.LogInfo((object)(currentLevel + " moon detected. Set density scale to " + currentDensityScale));
								break;
							}
							if (moonScale.MoonName == MoonScales[MoonScales.Count - 1].MoonName)
							{
								mls.LogWarning((object)$"{currentLevel} moon not found in records. Using scale of {currentDensityScale}.");
							}
						}
						foreach (WeatherScale weatherScale in WeatherScales)
						{
							if (currentWeatherType == weatherScale.WeatherName)
							{
								currentDensityScale *= weatherScale.Scale;
								mls.LogInfo((object)(currentWeatherType + " weather type detected. Set density scale to " + currentDensityScale));
								break;
							}
							if (weatherScale.WeatherName == WeatherScales[WeatherScales.Count - 1].WeatherName)
							{
								mls.LogWarning((object)$"{currentWeatherType} weather type not found in records. Using scale of {currentDensityScale}.");
							}
						}
						parameters.meanFreePath = currentPreset.MeanFreePath * currentDensityScale;
					}
					else
					{
						mls.LogInfo((object)"Weather scaling is disabled. Using a scale of 1.");
						parameters.meanFreePath = currentPreset.MeanFreePath;
					}
					parameters.albedo = new Color(currentPreset.AlbedoR, currentPreset.AlbedoG, currentPreset.AlbedoB, 1f);
				}
				item.parameters = parameters;
			}
		}

		public static void ApplyFogSettingsGradually(float duration, float interval)
		{
			applyingFogSettings = true;
			((MonoBehaviour)Instance).StartCoroutine(ApplyFogSettingsCoroutine(duration, interval));
		}

		private static IEnumerator ApplyFogSettingsCoroutine(float duration, float interval)
		{
			for (float elapsedTime = 0f; elapsedTime < duration; elapsedTime += interval)
			{
				ApplyFogSettings();
				yield return (object)new WaitForSeconds(interval);
			}
			ApplyFogSettings();
			applyingFogSettings = false;
		}

		public static void NextPreset()
		{
			mls.LogInfo((object)"Next preset hotkey pressed.");
			mls.LogInfo((object)((object)FogSettingsManager.Instance).ToString());
			currentPresetIndex = FogConfigPresets.IndexOf(currentPreset);
			if (currentPresetIndex == FogConfigPresets.Count - 1)
			{
				currentPresetIndex = -1;
			}
			currentPresetIndex++;
			currentPreset = FogConfigPresets[currentPresetIndex];
			mls.LogInfo((object)("Current preset index: " + currentPresetIndex));
			mls.LogInfo((object)("Current preset: " + currentPreset.PresetName));
			ApplyFogSettings();
			FogSettingsManager.Instance.UpdateSettingsWithCurrentPreset();
		}

		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;
		}
	}
}
namespace BetterFog.Patches
{
	[HarmonyPatch(typeof(QuickMenuManager))]
	public class QuickMenuManagerPatch
	{
		[HarmonyPatch("OpenQuickMenu")]
		[HarmonyPostfix]
		public static void OpenQuickMenuPatch()
		{
			FogSettingsManager instance = FogSettingsManager.Instance;
			if ((Object)(object)instance != (Object)null && !instance.IsSettingsEnabled())
			{
				instance.EnableSettings();
			}
		}

		[HarmonyPatch("CloseQuickMenu")]
		[HarmonyPostfix]
		public static void CloseQuickMenuPatch()
		{
			FogSettingsManager instance = FogSettingsManager.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsSettingsEnabled())
			{
				instance.DisableSettings();
			}
		}
	}
	[HarmonyPatch(typeof(IngamePlayerSettings))]
	public class IngamePlayerSettingsPatch
	{
		[HarmonyPatch("RefreshAndDisplayCurrentMicrophone")]
		[HarmonyPostfix]
		public static void RefreshAndDisplayCurrentMicrophonePatch()
		{
			FogSettingsManager instance = FogSettingsManager.Instance;
			if ((Object)(object)instance != (Object)null && instance.IsSettingsEnabled())
			{
				instance.DisableSettings();
			}
		}

		[HarmonyPatch("DiscardChangedSettings")]
		[HarmonyPostfix]
		public static void DiscardChangedSettingsPatch()
		{
			FogSettingsManager.Instance.EnableSettings();
			FogSettingsManager instance = FogSettingsManager.Instance;
			if ((Object)(object)instance != (Object)null && !instance.IsSettingsEnabled())
			{
				instance.EnableSettings();
			}
			else
			{
				BetterFog.mls.LogWarning((object)"Settings are already open.");
			}
		}
	}
	[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)
		{
			BetterFog.mls.LogMessage((object)"AudioReverbTrigger changeVolume");
			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)
		{
			if ((Object)(object)localFog != (Object)null)
			{
				if (!toggleLocalFog)
				{
				}
				for (int j = 0; j < 40; j++)
				{
					aud.volume = Mathf.Lerp(aud.volume, changeVolumeTo, (float)j / 40f);
					yield return (object)new WaitForSeconds(0.004f);
				}
			}
			else
			{
				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 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("StartGame")]
		[HarmonyPostfix]
		public static void StartGamePatch()
		{
			if (GameNetworkManager.Instance.gameHasStarted)
			{
				BetterFog.mls.LogInfo((object)"Game has started. Applying fog settings to moon.");
				if (!BetterFog.applyingFogSettings)
				{
					BetterFog.ApplyFogSettingsGradually(15f, 0.99f);
				}
			}
		}

		[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;
		}
	}
}
namespace BetterFog.Input
{
	internal class IngameKeybinds : LcInputActions
	{
		internal static IngameKeybinds Instance = new IngameKeybinds();

		public InputAction NextPresetHotkey { get; set; }

		public InputAction RefreshPresetHotKey { get; set; }

		public InputAction WeatherScalePresetHotKey { get; set; }

		internal static InputActionAsset GetAsset()
		{
			return ((LcInputActions)Instance).Asset;
		}

		internal void InitializeKeybindings(string nextHotkeyString, string refreshHotkeyString, string weatherScaleHotkeyString)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_006f: 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)
			NextPresetHotkey = new InputAction("Next Fog Preset", (InputActionType)0, "<Keyboard>/" + nextHotkeyString, (string)null, (string)null, (string)null);
			RefreshPresetHotKey = new InputAction("Refresh Fog Preset", (InputActionType)0, "<Keyboard>/" + refreshHotkeyString, (string)null, (string)null, (string)null);
			WeatherScalePresetHotKey = new InputAction("Weather Scale Preset", (InputActionType)0, "<Keyboard>/" + weatherScaleHotkeyString, (string)null, (string)null, (string)null);
			InputActionSetupExtensions.AddBinding(NextPresetHotkey, "<Gamepad>/leftStickPress", (string)null, (string)null, (string)null);
			InputActionSetupExtensions.AddBinding(RefreshPresetHotKey, "<Gamepad>/rightStickPress", (string)null, (string)null, (string)null);
			if (BetterFog.nextHotKeyEnabled.Value)
			{
				NextPresetHotkey.Enable();
				NextPresetHotkey.performed += delegate
				{
					BetterFog.NextPreset();
				};
			}
			else
			{
				NextPresetHotkey.Disable();
			}
			if (BetterFog.refreshHotKeyEnabled.Value)
			{
				RefreshPresetHotKey.Enable();
				RefreshPresetHotKey.performed += delegate
				{
					BetterFog.ApplyFogSettings();
				};
			}
			else
			{
				RefreshPresetHotKey.Disable();
			}
			if (BetterFog.weatherScaleHotKeyEnabled.Value)
			{
				WeatherScalePresetHotKey.Enable();
				WeatherScalePresetHotKey.performed += delegate
				{
					BetterFog.isDensityScaleEnabled = !BetterFog.isDensityScaleEnabled;
					BetterFog.ApplyFogSettings();
					if (FogSettingsManager.Instance.IsSettingsEnabled())
					{
						FogSettingsManager.Instance.UpdateSettingsWithCurrentPreset();
					}
				};
			}
			else
			{
				WeatherScalePresetHotKey.Disable();
			}
		}

		public static void DisableHotkeys()
		{
			BetterFog.hotkeysEnabled = false;
			Instance.NextPresetHotkey.Disable();
			Instance.RefreshPresetHotKey.Disable();
			Instance.WeatherScalePresetHotKey.Disable();
		}

		public static void EnableHotkeys()
		{
			BetterFog.hotkeysEnabled = true;
			Instance.NextPresetHotkey.Enable();
			Instance.RefreshPresetHotKey.Enable();
			Instance.WeatherScalePresetHotKey.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 bool NoFog { get; set; }

		public FogConfigPreset()
		{
		}

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

		public override string ToString()
		{
			return $"PresetName={PresetName},Density={MeanFreePath},Red Hue={AlbedoR},Green Hue={AlbedoG},Blue Hue={AlbedoB},No Fog={NoFog}";
		}

		public static FogConfigPreset FromString(string data)
		{
			string[] array = data.Split(new char[1] { ',' });
			if (array.Length != 6)
			{
				throw new ArgumentException("Invalid preset string format");
			}
			return new FogConfigPreset(array[0].Split(new char[1] { '=' })[1], float.Parse(array[1].Split(new char[1] { '=' })[1]), float.Parse(array[2].Split(new char[1] { '=' })[1]), float.Parse(array[3].Split(new char[1] { '=' })[1]), float.Parse(array[4].Split(new char[1] { '=' })[1]), bool.Parse(array[5].Split(new char[1] { '=' })[1]));
		}
	}
	public class FogSettingsManager : MonoBehaviour
	{
		private AssetBundle fogsettingsgui;

		private GameObject settingsCanvas;

		private TMP_FontAsset customFont;

		public TMP_Dropdown presetDropdown;

		private bool isSettingsEnabled = false;

		private Slider fogDensitySlider;

		private TextMeshProUGUI densityVal;

		private Button densityUp;

		private Button densityDown;

		private Slider fogRedSlider;

		private TextMeshProUGUI redVal;

		private Button redUp;

		private Button redDown;

		private Slider fogGreenSlider;

		private TextMeshProUGUI greenVal;

		private Button greenUp;

		private Button greenDown;

		private Slider fogBlueSlider;

		private TextMeshProUGUI blueVal;

		private Button blueUp;

		private Button blueDown;

		public Toggle noFogCheckbox;

		public Toggle weatherScaleCheckbox;

		private static FogSettingsManager instance;

		private static bool isInitializing;

		private Coroutine adjustCoroutine;

		public static FogSettingsManager Instance
		{
			get
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				if ((Object)(object)instance == (Object)null && !isInitializing)
				{
					isInitializing = true;
					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);
				BetterFog.mls.LogInfo((object)"FogSettingsManager created and started.");
			}
			else if ((Object)(object)instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				BetterFog.mls.LogWarning((object)"FogSettingsManager already exists. Duplicate destroyed.");
			}
		}

		private void Initialize()
		{
			if (!BetterFog.guiEnabled.Value)
			{
				BetterFog.mls.LogWarning((object)"FogSettingsManager GUI is disabled by config file.");
				return;
			}
			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.");
			}
		}

		private void LoadAssetsFromBundle()
		{
			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);
					presetDropdown = ((Component)settingsCanvas.transform.Find("PresetDropdown")).GetComponent<TMP_Dropdown>();
					PopulateDropdown();
					BetterFog.mls.LogInfo((object)"Options are now populated.");
					SetCurrentPreset();
					fogDensitySlider = ((Component)settingsCanvas.transform.Find("ThicknessSlider")).GetComponent<Slider>();
					densityVal = ((Component)settingsCanvas.transform.Find("ThicknessNum")).GetComponent<TextMeshProUGUI>();
					densityDown = ((Component)settingsCanvas.transform.Find("ThicknessDown")).GetComponent<Button>();
					densityUp = ((Component)settingsCanvas.transform.Find("ThicknessUp")).GetComponent<Button>();
					fogRedSlider = ((Component)settingsCanvas.transform.Find("RedSlider")).GetComponent<Slider>();
					redVal = ((Component)settingsCanvas.transform.Find("RedHueNum")).GetComponent<TextMeshProUGUI>();
					redDown = ((Component)settingsCanvas.transform.Find("RedDown")).GetComponent<Button>();
					redUp = ((Component)settingsCanvas.transform.Find("RedUp")).GetComponent<Button>();
					fogGreenSlider = ((Component)settingsCanvas.transform.Find("GreenSlider")).GetComponent<Slider>();
					greenVal = ((Component)settingsCanvas.transform.Find("GreenHueNum")).GetComponent<TextMeshProUGUI>();
					greenDown = ((Component)settingsCanvas.transform.Find("GreenDown")).GetComponent<Button>();
					greenUp = ((Component)settingsCanvas.transform.Find("GreenUp")).GetComponent<Button>();
					fogBlueSlider = ((Component)settingsCanvas.transform.Find("BlueSlider")).GetComponent<Slider>();
					blueVal = ((Component)settingsCanvas.transform.Find("BlueHueNum")).GetComponent<TextMeshProUGUI>();
					blueDown = ((Component)settingsCanvas.transform.Find("BlueDown")).GetComponent<Button>();
					blueUp = ((Component)settingsCanvas.transform.Find("BlueUp")).GetComponent<Button>();
					noFogCheckbox = ((Component)settingsCanvas.transform.Find("NoFogToggle")).GetComponent<Toggle>();
					weatherScaleCheckbox = ((Component)settingsCanvas.transform.Find("WeatherScaleToggle")).GetComponent<Toggle>();
					if ((Object)(object)fogDensitySlider != (Object)null && (Object)(object)densityVal != (Object)null && (Object)(object)noFogCheckbox != (Object)null)
					{
						((TMP_Text)densityVal).text = fogDensitySlider.value.ToString();
						((TMP_Text)redVal).text = fogRedSlider.value.ToString();
						((TMP_Text)greenVal).text = fogGreenSlider.value.ToString();
						((TMP_Text)blueVal).text = fogBlueSlider.value.ToString();
						noFogCheckbox.isOn = BetterFog.currentPreset.NoFog;
						((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);
						});
						InitializeButtonListeners();
						((UnityEvent<bool>)(object)noFogCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnNoFogCheckboxValueChanged(isChecked);
						});
						((UnityEvent<bool>)(object)weatherScaleCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
						{
							OnDensityScaleCheckboxValueChanged(isChecked);
						});
					}
				}
				else
				{
					BetterFog.mls.LogError((object)"FogSettingsCanvas 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 OnSliderValueChanged(Slider slider, float value)
		{
			if ((Object)(object)slider == (Object)(object)fogDensitySlider && (Object)(object)densityVal != (Object)null)
			{
				((TMP_Text)densityVal).text = value.ToString("0");
				BetterFog.currentPreset.MeanFreePath = value;
			}
			else if ((Object)(object)slider == (Object)(object)fogRedSlider && (Object)(object)redVal != (Object)null)
			{
				((TMP_Text)redVal).text = value.ToString("0.00");
				BetterFog.currentPreset.AlbedoR = value;
			}
			else if ((Object)(object)slider == (Object)(object)fogGreenSlider && (Object)(object)greenVal != (Object)null)
			{
				((TMP_Text)greenVal).text = value.ToString("0.00");
				BetterFog.currentPreset.AlbedoG = value;
			}
			else if ((Object)(object)slider == (Object)(object)fogBlueSlider && (Object)(object)blueVal != (Object)null)
			{
				((TMP_Text)blueVal).text = value.ToString("0.00");
				BetterFog.currentPreset.AlbedoB = value;
			}
			UpdateNoFogCheckbox();
			BetterFog.ApplyFogSettings();
		}

		private void UpdateSlidersWithCurrentPreset()
		{
			if ((Object)(object)fogDensitySlider != (Object)null && (Object)(object)densityVal != (Object)null && (Object)(object)fogRedSlider != (Object)null && (Object)(object)redVal != (Object)null && (Object)(object)fogGreenSlider != (Object)null && (Object)(object)greenVal != (Object)null && (Object)(object)fogBlueSlider != (Object)null && (Object)(object)blueVal != (Object)null && BetterFog.currentPreset != null)
			{
				fogDensitySlider.value = BetterFog.currentPreset.MeanFreePath;
				((TMP_Text)redVal).text = fogDensitySlider.value.ToString();
				fogRedSlider.value = BetterFog.currentPreset.AlbedoR;
				((TMP_Text)redVal).text = fogRedSlider.value.ToString();
				fogGreenSlider.value = BetterFog.currentPreset.AlbedoG;
				((TMP_Text)greenVal).text = fogGreenSlider.value.ToString();
				fogBlueSlider.value = BetterFog.currentPreset.AlbedoB;
				((TMP_Text)blueVal).text = fogBlueSlider.value.ToString();
			}
		}

		private void InitializeButtonListeners()
		{
			AddAdjustmentListener(densityDown, -1f, fogDensitySlider);
			AddAdjustmentListener(densityUp, 1f, fogDensitySlider);
			AddAdjustmentListener(redDown, -0.1f, fogRedSlider);
			AddAdjustmentListener(redUp, 0.1f, fogRedSlider);
			AddAdjustmentListener(greenDown, -0.1f, fogGreenSlider);
			AddAdjustmentListener(greenUp, 0.1f, fogGreenSlider);
			AddAdjustmentListener(blueDown, -0.1f, fogBlueSlider);
			AddAdjustmentListener(blueUp, 0.1f, fogBlueSlider);
		}

		private void AddAdjustmentListener(Button button, float adjustmentStep, Slider slider)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0080: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			EventTrigger val = ((Component)button).gameObject.GetComponent<EventTrigger>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)button).gameObject.AddComponent<EventTrigger>();
			}
			Entry val2 = new Entry
			{
				eventID = (EventTriggerType)2
			};
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				StartAdjusting(slider, adjustmentStep);
			});
			val.triggers.Add(val2);
			Entry val3 = new Entry
			{
				eventID = (EventTriggerType)3
			};
			((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				StopAdjusting();
			});
			val.triggers.Add(val3);
			Entry val4 = new Entry
			{
				eventID = (EventTriggerType)1
			};
			((UnityEvent<BaseEventData>)(object)val4.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				StopAdjusting();
			});
			val.triggers.Add(val4);
		}

		private void StartAdjusting(Slider slider, float changeAmount)
		{
			if (adjustCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(adjustCoroutine);
			}
			adjustCoroutine = ((MonoBehaviour)this).StartCoroutine(AdjustSliderValueWithDebounce(slider, changeAmount));
		}

		private IEnumerator AdjustSliderValueWithDebounce(Slider slider, float changeAmount)
		{
			float lastUpdateTime = Time.time;
			while (true)
			{
				if (Time.time - lastUpdateTime >= 0.05f)
				{
					slider.value = Mathf.Clamp(slider.value + changeAmount, slider.minValue, slider.maxValue);
					lastUpdateTime = Time.time;
				}
				yield return null;
			}
		}

		private void StopAdjusting()
		{
			if (adjustCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(adjustCoroutine);
			}
		}

		private void OnNoFogCheckboxValueChanged(bool isChecked)
		{
			BetterFog.currentPreset.NoFog = isChecked;
			BetterFog.ApplyFogSettings();
		}

		private void UpdateNoFogCheckbox()
		{
			if ((Object)(object)noFogCheckbox != (Object)null)
			{
				noFogCheckbox.isOn = BetterFog.currentPreset.NoFog;
			}
		}

		private void OnDensityScaleCheckboxValueChanged(bool isChecked)
		{
			BetterFog.isDensityScaleEnabled = isChecked;
			BetterFog.ApplyFogSettings();
		}

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

		private void PopulateDropdown()
		{
			presetDropdown.ClearOptions();
			List<string> list = new List<string>();
			foreach (FogConfigPreset fogConfigPreset in BetterFog.FogConfigPresets)
			{
				list.Add(fogConfigPreset.PresetName);
			}
			presetDropdown.AddOptions(list);
		}

		private void SetCurrentPreset()
		{
			if ((Object)(object)presetDropdown != (Object)null)
			{
				UpdateSettingsWithCurrentPreset();
				((UnityEventBase)presetDropdown.onValueChanged).RemoveAllListeners();
				((UnityEvent<int>)(object)presetDropdown.onValueChanged).AddListener((UnityAction<int>)OnPresetChanged);
			}
		}

		public void UpdateSettingsWithCurrentPreset()
		{
			UpdateDropdownWithCurrentPreset();
			UpdateSlidersWithCurrentPreset();
			UpdateNoFogCheckbox();
			UpdateDensityScaleCheckbox();
		}

		private void UpdateDropdownWithCurrentPreset()
		{
			if ((Object)(object)presetDropdown != (Object)null)
			{
				presetDropdown.value = BetterFog.currentPresetIndex;
				BetterFog.mls.LogInfo((object)("Dropdown updated to preset: " + BetterFog.currentPreset.PresetName));
			}
			else
			{
				BetterFog.mls.LogError((object)"PresetDropdown is not assigned.");
			}
		}

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

		private void ApplyPreset(FogConfigPreset preset)
		{
			BetterFog.currentPresetIndex = BetterFog.FogConfigPresets.IndexOf(preset);
			BetterFog.currentPreset = preset;
			BetterFog.mls.LogInfo((object)("Applying preset: " + preset.PresetName));
			BetterFog.ApplyFogSettings();
		}

		public void EnableSettings()
		{
			if (!BetterFog.guiEnabled.Value)
			{
				BetterFog.mls.LogWarning((object)"FogSettingsManager GUI is disabled by config file.");
				return;
			}
			isSettingsEnabled = true;
			if ((Object)(object)settingsCanvas == (Object)null)
			{
				Object.Destroy((Object)(object)settingsCanvas);
				settingsCanvas = null;
				BetterFog.mls.LogWarning((object)"Canvas prefab not found. Initializing new Canvas.");
				UnloadAssetBundle();
				Initialize();
			}
			settingsCanvas.SetActive(true);
			SetCurrentPreset();
			BetterFog.mls.LogInfo((object)"Fog Settings enabled.");
		}

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

		public void DisableSettings()
		{
			if (!BetterFog.guiEnabled.Value)
			{
				BetterFog.mls.LogWarning((object)"FogSettingsManager GUI is disabled by config file.");
				return;
			}
			isSettingsEnabled = false;
			if ((Object)(object)settingsCanvas != (Object)null)
			{
				settingsCanvas.SetActive(false);
				BetterFog.mls.LogInfo((object)"Fog Settings disabled.");
				return;
			}
			Object.Destroy((Object)(object)settingsCanvas);
			settingsCanvas = null;
			BetterFog.mls.LogWarning((object)"Canvas prefab not found. Initializing new Canvas.");
			UnloadAssetBundle();
			Initialize();
		}

		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;
		}
	}
}