using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using 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.3")]
public class BetterFog : BaseUnityPlugin
{
public const string modGUID = "ironthumb.BetterFog";
public const string modName = "BetterFog";
public const string modVersion = "3.3.3";
private readonly Harmony harmony = new Harmony("ironthumb.BetterFog");
public static ManualLogSource mls;
private static BetterFog instance;
public static bool hotkeysEnabled = true;
public static ConfigEntry<string> nextPresetHotkeyConfig;
public static ConfigEntry<string> nextModeHotkeyConfig;
public static ConfigEntry<string> refreshPresetHotkeyConfig;
public static ConfigEntry<string> weatherScaleHotkeyConfig;
public static ConfigEntry<string> settingsHotkeyConfig;
public static ConfigEntry<string> autoPresetModeHotkeyConfig;
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 const float maxDensitySliderValue = 15000f;
public static List<WeatherScale> weatherScales;
private static ConfigEntry<string> weatherScalesConfig;
public static bool weatherSaveLoaded = false;
public static SelectableLevel currentLevelType;
public static string currentLevel = "";
public static List<MoonScale> moonScales;
private static ConfigEntry<string> moonScalesConfig;
private static List<AutoPresetMode> autoPresetModes;
private static ConfigEntry<string> autoPresetModeConfig;
private static ConfigEntry<bool> autoPresetModeEnabledDefault;
public static bool autoPresetModeEnabled;
public static bool autoPresetModeMatchFound = false;
public static AutoPresetMode matchedPreset = null;
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 lockPresetDropdownModification = false;
public static bool lockPresetValueModification = false;
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 lockModeDropdownModification = false;
public static bool isFogSettingsActive = false;
public static bool settingsHotkeyEnabled;
public static bool applyingFogSettings = false;
public static bool inTerminal = 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_0ba8: Unknown result type (might be due to invalid IL or missing references)
//IL_0bb5: Expected O, but got Unknown
//IL_0be3: Unknown result type (might be due to invalid IL or missing references)
//IL_0bf0: Expected O, but got Unknown
//IL_0c1e: Unknown result type (might be due to invalid IL or missing references)
//IL_0c2b: Expected O, but got Unknown
//IL_0c59: Unknown result type (might be due to invalid IL or missing references)
//IL_0c66: Expected O, but got Unknown
//IL_0c94: Unknown result type (might be due to invalid IL or missing references)
//IL_0ca1: Expected O, but got Unknown
//IL_0ccf: Unknown result type (might be due to invalid IL or missing references)
//IL_0cdc: Expected O, but got Unknown
//IL_0d0a: Unknown result type (might be due to invalid IL or missing references)
//IL_0d17: Expected O, but got Unknown
//IL_0d45: Unknown result type (might be due to invalid IL or missing references)
//IL_0d52: Expected O, but got Unknown
//IL_0d80: Unknown result type (might be due to invalid IL or missing references)
//IL_0d8d: Expected O, but got Unknown
//IL_0dbb: Unknown result type (might be due to invalid IL or missing references)
//IL_0dc8: Expected O, but got Unknown
//IL_0e15: Unknown result type (might be due to invalid IL or missing references)
//IL_0e22: 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;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
fogConfigPresets = new List<FogConfigPreset>
{
new FogConfigPreset("Default", 14915f, 0.441f, 0.459f, 0.5f),
new FogConfigPreset("Heavy Fog", 14923f, 0.25f, 0.25f, 0.25f),
new FogConfigPreset("Light Fog", 5150f, 5f, 5f, 5f),
new FogConfigPreset("Mist", 0f, 1f, 1f, 1f),
new FogConfigPreset("Red Fog", 14915f, 3f, 0f, 0f),
new FogConfigPreset("Orange Fog", 14915f, 20f, 9.33f, 4.5f),
new FogConfigPreset("Yellow Fog", 14915f, 3f, 3f, 0f),
new FogConfigPreset("Green Fog", 14915f, 0f, 3f, 0f),
new FogConfigPreset("Blue Fog", 14909f, 0f, 0f, 3f),
new FogConfigPreset("Purple Fog", 14915f, 11.5f, 7.2f, 20f),
new FogConfigPreset("Pink Fog", 14915f, 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.");
nextPresetHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Next Preset Hotkey", "n", "Hotkey to switch to the next fog preset.");
nextModeHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Next Mode Hotkey", "m", "Hotkey to switch to the next fog mode.");
refreshPresetHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Refresh Hotkey", "r", "Hotkey to refresh fog settings.");
weatherScaleHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Weather Scale Hotkey", "c", "Hotkey to toggle weather scaling.");
autoPresetModeHotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text2, "Auto Sync Hotkey", "j", "Hotkey to toggle auto sync.");
string text3 = "Fog Settings";
excludeShipFogDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Exclude Ship", true, "Enable or Disable 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;
autoPresetModeEnabledDefault = ((BaseUnityPlugin)this).Config.Bind<bool>(text3, "Auto Preset/Mode Enabled", false, "Enable or disable auto preset/mode settings by default.");
autoPresetModeEnabled = autoPresetModeEnabledDefault.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, autoPresetModeHotkeyConfig.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)
{
continue;
}
string text5 = array3[0].Trim();
string text6 = array3[1].Trim();
switch (text5)
{
case "PresetName":
fogConfigPresets[i].PresetName = text6;
break;
case "Density":
{
float num = float.Parse(text6);
if (num < 0f)
{
num = 0f;
}
else if (num > 15000f)
{
num = 15000f;
}
else
{
fogConfigPresets[i].MeanFreePath = float.Parse(text6, CultureInfo.InvariantCulture);
}
break;
}
case "Red Hue":
fogConfigPresets[i].AlbedoR = float.Parse(text6, CultureInfo.InvariantCulture);
break;
case "Green Hue":
fogConfigPresets[i].AlbedoG = float.Parse(text6, CultureInfo.InvariantCulture);
break;
case "Blue Hue":
fogConfigPresets[i].AlbedoB = float.Parse(text6, CultureInfo.InvariantCulture);
break;
}
}
}
if (verboseLoggingEnabled)
{
foreach (FogConfigPreset fogConfigPreset2 in fogConfigPresets)
{
mls.LogInfo((object)$"Preset '{fogConfigPreset2.PresetName}': Density={fogConfigPreset2.MeanFreePath}, AlbedoR={fogConfigPreset2.AlbedoR}, AlbedoG={fogConfigPreset2.AlbedoG}, AlbedoB={fogConfigPreset2.AlbedoB}");
}
}
string text7 = "Weather and Moon Density Scales";
moonScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "MoonScales", "71 Gordion=1,41 Experimentation=0.998,220 Assurance=1,56 Vow=1.003,21 Offense=1,61 March=1.003,20 Adamance=1.003,85 Rend=1.002,7 Dine=1.001,8 Titan=1.002,68 Artifice=1.001,5 Embrion=1.002,44 Liquidation=1,Fallback=1", "Moon scales in the format {71 Gordion=1,41 Experimentation=0.998,220 Assurance=1,...}. When \"Fallback={number}\" is in the list, the density will default to \nthis value if no moon is detected.");
moonScales = ParseMoonScales(moonScalesConfig.Value);
weatherScalesConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text7, "WeatherScales", "none=1,rainy=1.002,stormy=1.0022,foggy=1.0025,eclipsed=1.002,dust clouds=1.001,flooded=1.002,Fallback=1", "Weather scales in the format {none=1,rainy=1.002,stormy=1.0022,...}. When \"Fallback={number}\" is in the list, the density will default to this value if no moon is detected.");
weatherScales = ParseWeatherScales(weatherScalesConfig.Value);
foreach (FogConfigPreset fogConfigPreset3 in fogConfigPresets)
{
foreach (MoonScale moonScale in moonScales)
{
foreach (WeatherScale weatherScale in weatherScales)
{
if (fogConfigPreset3.MeanFreePath * moonScale.Scale * weatherScale.Scale > 15000f)
{
mls.LogWarning((object)("Preset '" + fogConfigPreset3.PresetName + "' exceeds max density slider value with Moon '" + moonScale.MoonName + "' and Weather '" + weatherScale.WeatherName + "'. Decrease the scales or preset fog density to prevent a black screen..."));
}
}
}
}
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);
string text8 = "Auto Sync Preset/Mode Settings";
autoPresetModeConfig = ((BaseUnityPlugin)this).Config.Bind<string>(text8, "Auto Sync Preset/Mode Settings", "", "Automatically apply presets and modes to moons and weathers. On the left of = enter \na moon and/or weather name, and on the right enter a single preset or mode name. Entering a preset name on the right automatically sets the mode to \"Better Fog\". \nTo have a condition that requires both a moon and weather, enter \"&\" in between entries. This will override single entries if both moon and weather are present. \nIf a preset name is the same as a mode name, the mode will be set to \"Better Fog\" and that preset will be set. \nWarning: If you create different conditions that conflict (such as none=mist,68 Artifice=No Fog and you land on Art with no weather), the leftmost condition will apply. \nFor that reason, put double conditions with the most specific condition first, and single condition last. Keyword \"All\" Matches all moons and whethers. Use this last as \na fallback value in case no matches are found. Example: 61 March=Light Fog,7 Dine&eclipsed=Orange Fog,7 Dine=Heavy Fog,eclipsed=Red Fog,8 Titan=Heavy Fog,none=Mist,none&8 Titan=No Fog,All=Default");
autoPresetModes = ParseAutoPresetMode(autoPresetModeConfig.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(Terminal), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(TerminalPatch), "StartPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)AccessTools.Method(typeof(QuickMenuManager), "OpenQuickMenu", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(QuickMenuManagerPatch), "OpenQuickMenuPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
harmony.Patch((MethodBase)AccessTools.Method(typeof(QuickMenuManager), "CloseQuickMenu", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(QuickMenuManagerPatch), "CloseQuickMenuPatch", (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 (settingsHotkeyEnabled)
{
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.");
}
}
else if (verboseLoggingEnabled)
{
mls.LogInfo((object)"Settings hotkey is disabled. Settings GUI will not be instantiated");
}
}
public static void ApplyFogSettings(bool activateAutoPresetMode)
{
if (verboseLoggingEnabled)
{
mls.LogInfo((object)$"autoPresetModeEnabled: {autoPresetModeEnabled}");
mls.LogInfo((object)$"activateAutoPresetMode: {activateAutoPresetMode}");
}
if (fogRefreshLock && !autoPresetModeEnabled)
{
if (verboseLoggingEnabled)
{
mls.LogWarning((object)"Fog settings refresh is locked. Skipping fog settings application.");
}
return;
}
if (activateAutoPresetMode)
{
matchedPreset = null;
foreach (AutoPresetMode autoPresetMode in autoPresetModes)
{
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Checking Conditions: " + string.Join(", ", autoPresetMode.Conditions) + " against Current weather: " + currentWeatherType + ", Current moon: " + currentLevel));
}
if (autoPresetMode.Conditions.All((string condition) => condition.Equals(currentLevel) || condition.Equals(currentWeatherType) || condition.Equals("all")))
{
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Preset match found between Conditions: " + string.Join(", ", autoPresetMode.Conditions) + " and Current Moon: " + currentLevel + ", Current Weather: " + currentWeatherType));
mls.LogInfo((object)("Effect to apply: " + autoPresetMode.Effect));
}
matchedPreset = autoPresetMode;
break;
}
}
if (matchedPreset != null)
{
autoPresetModeMatchFound = true;
string effect = matchedPreset.Effect;
FogConfigPreset fogConfigPreset = fogConfigPresets.FirstOrDefault((FogConfigPreset p) => p.PresetName.ToLower() == effect);
if (fogConfigPreset != null)
{
currentMode = fogModes.FirstOrDefault((BetterFogMode m) => m.Name == "Better Fog");
currentModeIndex = fogModes.IndexOf(currentMode);
currentPreset = fogConfigPreset;
currentPresetIndex = fogConfigPresets.IndexOf(currentPreset);
Instance.UpdateMode();
if (settingsHotkeyEnabled && isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
}
if (verboseLoggingEnabled)
{
mls.LogInfo((object)$"Preset applied: {currentPreset}, Mode set to {currentMode.Name}");
}
}
else
{
BetterFogMode betterFogMode = fogModes.FirstOrDefault((BetterFogMode m) => m.Name.ToLower() == effect);
if (betterFogMode != null)
{
currentMode = betterFogMode;
currentModeIndex = fogModes.IndexOf(currentMode);
Instance.UpdateMode();
if (settingsHotkeyEnabled && isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
}
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Mode set to " + currentMode.Name));
}
}
}
}
else
{
autoPresetModeMatchFound = false;
}
}
UpdateLockInteractionSettings();
SetWeatherScale();
List<LocalVolumetricFog> list = Resources.FindObjectsOfTypeAll<LocalVolumetricFog>().ToList();
foreach (LocalVolumetricFog item in list)
{
ProcessFogObject(item, activateAutoPresetMode);
}
}
private static void ProcessFogObject(LocalVolumetricFog fogObject, bool activateAutoPresetMode)
{
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
int num = LayerMask.NameToLayer("Enemies");
if ((Object)(object)fogObject != (Object)null && (!(((Object)fogObject).name == "FogExclusionZone") || !excludeShipFogEnabled) && (((Component)fogObject).gameObject.layer != num || !excludeEnemyFogEnabled) && !(currentMode.Name == "Vanilla"))
{
ApplyFogParameters(fogObject);
}
else if (currentMode.Name == "Vanilla" || ((Object)(object)fogObject != (Object)null && (!(((Object)fogObject).name == "FogExclusionZone") || !excludeShipFogEnabled) && ((Component)fogObject).gameObject.layer == num && excludeEnemyFogEnabled && !(currentMode.Name == "Vanilla")))
{
ResetFogToVanilla(((Component)fogObject).gameObject);
}
if (verboseLoggingEnabled)
{
Color albedo = fogObject.parameters.albedo;
mls.LogInfo((object)$"Found LocalVolumetricFog object: {((Object)fogObject).name}, MeanFreePath: {fogObject.parameters.meanFreePath}, AlbedoR: {albedo.r}, AlbedoG: {albedo.g}, AlbedoB: {albedo.b}");
}
}
private static void ApplyFogParameters(LocalVolumetricFog fogObject)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: 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)
LocalVolumetricFogArtistParameters parameters = fogObject.parameters;
if (currentPreset.MeanFreePath * combinedDensityScale > 15000f)
{
parameters.meanFreePath = 0f;
}
else
{
parameters.meanFreePath = 15000f - currentPreset.MeanFreePath * combinedDensityScale;
}
parameters.albedo = new Color(currentPreset.AlbedoR, currentPreset.AlbedoG, currentPreset.AlbedoB, 1f);
fogObject.parameters = parameters;
}
private static void SetWeatherScale()
{
moonDensityScale = 1f;
weatherDensityScale = 1f;
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 == "Fallback")
{
moonDensityScale = moonScale.Scale;
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Fallback moon scale detected. Set moon density scale to " + moonDensityScale));
}
}
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 == "Fallback")
{
weatherDensityScale = weatherScale.Scale;
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Fallback weather scale detected. Set weather density scale to " + weatherDensityScale));
}
}
if (weatherScale.WeatherName == weatherScales[weatherScales.Count - 1].WeatherName && verboseLoggingEnabled)
{
mls.LogWarning((object)$"{currentWeatherType} weather type not found in records. Using scale of {weatherDensityScale}.");
}
}
}
else if (verboseLoggingEnabled)
{
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: {15000f} - {currentPreset.MeanFreePath * combinedDensityScale} = {15000f - currentPreset.MeanFreePath * combinedDensityScale}");
if (currentPreset.MeanFreePath * combinedDensityScale > 15000f)
{
mls.LogWarning((object)$"MeanFreePath value exceeded max Density SliderValue. Setting density to {15000f}");
}
}
}
private static void ApplyAutoPresetMode(LocalVolumetricFog fogObject)
{
ApplyFogParameters(fogObject);
}
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(activateAutoPresetMode: false);
yield return (object)new WaitForSecondsRealtime(1f);
}
}
public static void NextPreset()
{
if (lockPresetDropdownModification)
{
mls.LogWarning((object)"Cannot switch presets when preset interaction is disabled.");
return;
}
currentPresetIndex = fogConfigPresets.IndexOf(currentPreset);
if (currentPresetIndex == fogConfigPresets.Count - 1)
{
currentPresetIndex = -1;
}
currentPresetIndex++;
currentPreset = fogConfigPresets[currentPresetIndex];
mls.LogInfo((object)("Switched to preset: " + currentPreset.PresetName));
ApplyFogSettings(activateAutoPresetMode: false);
if (isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
}
}
public static void NextMode()
{
if (lockModeDropdownModification)
{
mls.LogWarning((object)"Cannot switch modes when mode interaction is disabled.");
return;
}
currentModeIndex = fogModes.IndexOf(currentMode);
if (currentModeIndex == fogModes.Count - 1)
{
currentModeIndex = -1;
}
currentModeIndex++;
currentMode = fogModes[currentModeIndex];
mls.LogInfo((object)("Switched to next mode: " + currentMode.Name));
Instance.UpdateMode();
if (settingsHotkeyEnabled && (currentMode.Name == "No Fog" || currentMode.Name == "Vanilla") && autoPresetModeMatchFound)
{
lockPresetDropdownModification = true;
lockPresetValueModification = true;
}
else if (settingsHotkeyEnabled)
{
lockPresetDropdownModification = false;
}
if (isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
FogSettingsManager.Instance.LockPresetDropdownInteract(lockPresetDropdownModification);
FogSettingsManager.Instance.LockPresetValueInteract(lockPresetValueModification);
}
ApplyFogSettings(activateAutoPresetMode: false);
}
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].ToLower(), 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))
{
if (result < 0f)
{
result = 0f;
}
list.Add(new MoonScale(array3[0].ToLower(), 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 text in array2)
{
list.Add(text.ToLower());
}
return list;
}
private List<AutoPresetMode> ParseAutoPresetMode(string configString)
{
List<AutoPresetMode> list = new List<AutoPresetMode>();
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)
{
list.Add(new AutoPresetMode(array3[0].ToLower(), array3[1].ToLower()));
}
}
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);
if (verboseLoggingEnabled)
{
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");
if (verboseLoggingEnabled)
{
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);
if (verboseLoggingEnabled)
{
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(activateAutoPresetMode: false);
}
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)
{
if (verboseLoggingEnabled)
{
mls.LogInfo((object)("Local player found: " + ((Object)val).name));
}
return val;
}
}
mls.LogError((object)"Local player not found!");
return null;
}
public static void ToggleAutoPresetMode()
{
autoPresetModeEnabled = !autoPresetModeEnabled;
if (autoPresetModeEnabled)
{
mls.LogInfo((object)"Auto Preset/Mode enabled.");
ApplyFogSettings(activateAutoPresetMode: true);
}
else
{
mls.LogInfo((object)"Auto Preset/Mode disabled.");
ApplyFogSettings(activateAutoPresetMode: false);
}
if (isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
}
}
public static void ToggleWeatherScaling()
{
if (lockPresetDropdownModification)
{
mls.LogWarning((object)"Cannot toggle weather when preset interaction is disabled.");
return;
}
densityScaleEnabled = !densityScaleEnabled;
ApplyFogSettings(activateAutoPresetMode: false);
if (isFogSettingsActive)
{
FogSettingsManager.Instance.UpdateSettings();
}
}
public static void UpdateLockInteractionSettings()
{
if (autoPresetModeMatchFound & autoPresetModeEnabled)
{
mls.LogInfo((object)("AutoPresetMode Match Found: " + matchedPreset.Effect));
lockModeDropdownModification = true;
lockPresetDropdownModification = true;
lockPresetValueModification = currentMode.Name == "No Fog" || currentMode.Name == "Vanilla";
}
else if (currentMode.Name == "No Fog" || currentMode.Name == "Vanilla")
{
mls.LogInfo((object)("AutoPresetMode Match Not Found. Mode: " + currentMode.Name));
lockModeDropdownModification = false;
lockPresetDropdownModification = true;
lockPresetValueModification = true;
}
else
{
mls.LogInfo((object)("AutoPresetMode Match Not Found. Mode: " + currentMode.Name));
lockModeDropdownModification = false;
lockPresetDropdownModification = false;
lockPresetValueModification = false;
}
if (isFogSettingsActive)
{
FogSettingsManager.Instance.LockPresetDropdownInteract(lockPresetDropdownModification);
FogSettingsManager.Instance.LockPresetValueInteract(lockPresetValueModification);
FogSettingsManager.Instance.LockModeDropdownInteract(lockModeDropdownModification);
}
}
}
}
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()
{
if (!BetterFog.inTerminal)
{
IngameKeybinds.EnableHotkeys();
BetterFog.mls.LogInfo((object)"Chat submitted. Enabling hotkeys.");
}
else if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)"Chat submitted. Hotkeys remain disabled due to terminal being open.");
}
}
[HarmonyPatch("OpenMenu_performed")]
[HarmonyPostfix]
public static void OpenMenu_performedPatch()
{
}
}
[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(typeof(QuickMenuManager))]
public class QuickMenuManagerPatch
{
[HarmonyPatch("OpenQuickMenu")]
[HarmonyPostfix]
public static void OpenQuickMenuPatch()
{
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)"Quick menu opened. Disabling hotkeys");
}
IngameKeybinds.DisableHotkeys();
}
[HarmonyPatch("CloseQuickMenu")]
[HarmonyPostfix]
public static void CloseQuickMenuPatch()
{
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)"Quick menu closed. Enabling hotkeys");
}
IngameKeybinds.EnableHotkeys();
}
}
[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(activateAutoPresetMode: false);
}
}
[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(activateAutoPresetMode: false);
}
}
}
[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(activateAutoPresetMode: false);
}
}
[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(activateAutoPresetMode: false);
}
}
}
[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()
{
BetterFog.inTerminal = true;
IngameKeybinds.DisableHotkeys();
}
[HarmonyPatch("QuitTerminal")]
[HarmonyPostfix]
public static void QuitTerminalPatch()
{
BetterFog.inTerminal = false;
IngameKeybinds.EnableHotkeys();
BetterFog.mls.LogInfo((object)"Terminal closed. Enabling hotkeys.");
}
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void StartPatch(Terminal __instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
BetterFog.mls.LogInfo((object)"Terminal Start() has finished!");
SelectableLevel currentLevelType = BetterFog.currentLevelType;
string text = (BetterFog.currentWeatherType = (((int)currentLevelType.currentWeather == -1) ? "none" : (((object)(LevelWeatherType)(ref currentLevelType.currentWeather)).ToString() ?? "").ToLower()));
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)("Weather pulled from save file: Current level: " + currentLevelType.PlanetName + " | Weather: " + text));
}
if (BetterFog.autoPresetModeEnabled)
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: true);
}
else
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
BetterFog.weatherSaveLoaded = true;
IngameKeybinds.EnableHotkeys();
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatch
{
[HarmonyPatch("ChangeLevel")]
[HarmonyPostfix]
public static void ChangeLevelPatch(StartOfRound __instance, int levelID)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Invalid comparison between Unknown and I4
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
BetterFog.currentLevelType = __instance.currentLevel;
BetterFog.currentLevel = BetterFog.currentLevelType.PlanetName.ToLower();
BetterFog.CollectVanillaValues();
if (BetterFog.weatherSaveLoaded)
{
if ((int)BetterFog.currentLevelType.currentWeather >= 0)
{
WeatherEffect val = TimeOfDay.Instance.effects[BetterFog.currentLevelType.currentWeather];
BetterFog.mls.LogInfo((object)("Weather changed from " + BetterFog.currentWeatherType + " to " + val.name.ToLower()));
BetterFog.currentWeatherType = val.name.ToLower();
}
else
{
BetterFog.currentWeatherType = "none";
BetterFog.mls.LogWarning((object)$"Invalid weather index: {BetterFog.currentLevelType.currentWeather}. Set to none");
}
if (BetterFog.autoPresetModeEnabled)
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: true);
}
else
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
}
}
}
}
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 InputAction autoPresetModeHotkey { 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, string autoPresetModeHotkeyString)
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Expected O, but got Unknown
//IL_0210: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Expected O, but got Unknown
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Expected O, but got Unknown
//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
//IL_03c7: Expected O, but got Unknown
//IL_0494: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: 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.nextPresetHotkeyConfig.Value != "")
{
nextPresetHotkey.Enable();
nextPresetHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Next preset hotkey pressed.");
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.nextModeHotkeyConfig.Value != "")
{
nextModeHotkey.Enable();
nextModeHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Next mode hotkey pressed.");
BetterFog.NextMode();
}
};
}
else
{
nextModeHotkey.Disable();
}
if (autoPresetModeHotkey != null && autoPresetModeHotkey.enabled)
{
autoPresetModeHotkey.Disable();
autoPresetModeHotkey.performed -= delegate
{
BetterFog.ToggleAutoPresetMode();
};
}
autoPresetModeHotkey = new InputAction("Auto Preset Mode", (InputActionType)0, "<Keyboard>/" + autoPresetModeHotkeyString, (string)null, (string)null, (string)null);
if (BetterFog.autoPresetModeHotkeyConfig.Value != "")
{
autoPresetModeHotkey.Enable();
autoPresetModeHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Auto preset mode hotkey pressed.");
BetterFog.ToggleAutoPresetMode();
}
};
}
else
{
autoPresetModeHotkey.Disable();
}
if (refreshPresetHotkey != null && refreshPresetHotkey.enabled)
{
refreshPresetHotkey.Disable();
refreshPresetHotkey.performed -= delegate
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
};
}
refreshPresetHotkey = new InputAction("Refresh Fog Preset", (InputActionType)0, "<Keyboard>/" + refreshHotkeyString, (string)null, (string)null, (string)null);
if (BetterFog.refreshPresetHotkeyConfig.Value != "")
{
refreshPresetHotkey.Enable();
refreshPresetHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Refresh preset hotkey pressed.");
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
};
}
else
{
refreshPresetHotkey.Disable();
}
if (weatherScalePresetHotkey != null && weatherScalePresetHotkey.enabled)
{
weatherScalePresetHotkey.Disable();
weatherScalePresetHotkey.performed -= delegate
{
BetterFog.ToggleWeatherScaling();
};
}
weatherScalePresetHotkey = new InputAction("Weather Scale Preset", (InputActionType)0, "<Keyboard>/" + weatherScaleHotkeyString, (string)null, (string)null, (string)null);
if (BetterFog.weatherScaleHotkeyConfig.Value != "")
{
weatherScalePresetHotkey.Enable();
weatherScalePresetHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Weather scaling hotkey pressed.");
BetterFog.ToggleWeatherScaling();
}
};
}
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.settingsHotkeyConfig.Value != "")
{
settingsHotkey.Enable();
BetterFog.settingsHotkeyEnabled = true;
settingsHotkey.performed += delegate
{
if (InLobby())
{
BetterFog.mls.LogInfo((object)"Settings hotkey pressed.");
FogSettingsManager.Instance.ToggleSettings();
}
};
}
else
{
settingsHotkey.Disable();
BetterFog.settingsHotkeyEnabled = false;
}
}
private static bool InLobby()
{
if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsClient)
{
BetterFog.mls.LogError((object)"Hotkeys cannot be used when not in a lobby.");
return false;
}
return true;
}
public static void DisableHotkeys()
{
BetterFog.hotkeysEnabled = false;
Instance.nextPresetHotkey.Disable();
Instance.nextModeHotkey.Disable();
Instance.refreshPresetHotkey.Disable();
Instance.weatherScalePresetHotkey.Disable();
Instance.settingsHotkey.Disable();
Instance.autoPresetModeHotkey.Disable();
}
public static void EnableHotkeys()
{
BetterFog.hotkeysEnabled = true;
Instance.nextPresetHotkey.Enable();
Instance.nextModeHotkey.Enable();
Instance.refreshPresetHotkey.Enable();
Instance.weatherScalePresetHotkey.Enable();
Instance.settingsHotkey.Enable();
Instance.autoPresetModeHotkey.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 AutoPresetMode
{
public List<string> Conditions { get; set; }
public string Effect { get; set; }
public AutoPresetMode(string condition, string effect)
{
string[] source = condition.Split(new char[1] { '&' });
Conditions = source.ToList();
Effect = effect;
}
}
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.ToString(CultureInfo.InvariantCulture) + ",Red Hue=" + AlbedoR.ToString(CultureInfo.InvariantCulture) + ",Green Hue=" + AlbedoG.ToString(CultureInfo.InvariantCulture) + ",Blue Hue=" + AlbedoB.ToString(CultureInfo.InvariantCulture);
}
}
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 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 TextMeshProUGUI currentWeatherVal;
public TextMeshProUGUI currentMoonVal;
public Toggle densityScaleCheckbox;
public TextMeshProUGUI currentDensityVal;
public TextMeshProUGUI densityScaleVal;
public TextMeshProUGUI calcDensityVal;
public TextMeshProUGUI matchVal;
public TextMeshProUGUI detectionsVal;
public Toggle excludeShipCheckbox;
public Toggle excludeEnemiesCheckbox;
public Toggle verboseLogsCheckbox;
public Toggle autoPresetModeCheckbox;
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_072a: Unknown result type (might be due to invalid IL or missing references)
//IL_0734: 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>();
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>();
currentWeatherVal = ((Component)settingsText.transform.Find("CurrentWeatherVal")).GetComponent<TextMeshProUGUI>();
currentMoonVal = ((Component)settingsText.transform.Find("CurrentMoonVal")).GetComponent<TextMeshProUGUI>();
densityScaleCheckbox = ((Component)settingsInteractables.transform.Find("DensityScaleToggle")).GetComponent<Toggle>();
densityScaleCheckbox.isOn = BetterFog.densityScaleEnabled;
currentDensityVal = ((Component)settingsText.transform.Find("CurrentDensityVal")).GetComponent<TextMeshProUGUI>();
densityScaleVal = ((Component)settingsText.transform.Find("DensityScaleVal")).GetComponent<TextMeshProUGUI>();
calcDensityVal = ((Component)settingsText.transform.Find("CalcDensityVal")).GetComponent<TextMeshProUGUI>();
matchVal = ((Component)settingsText.transform.Find("MatchVal")).GetComponent<TextMeshProUGUI>();
detectionsVal = ((Component)settingsText.transform.Find("DetectionsVal")).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;
autoPresetModeCheckbox = ((Component)settingsInteractables.transform.Find("AutoPresetModeToggle")).GetComponent<Toggle>();
autoPresetModeCheckbox.isOn = BetterFog.autoPresetModeEnabled;
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)autoPresetModeCheckbox.onValueChanged).AddListener((UnityAction<bool>)delegate(bool isChecked)
{
OnAutoPresetModeCheckboxValueChanged(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)
{
if (value < 0f)
{
value = 0f;
}
else if (value > 15000f)
{
value = 15000f;
}
fogDensitySlider.value = value;
densityValInput.text = value.ToString("0");
((TMP_Text)currentDensityVal).text = BetterFog.currentPreset.MeanFreePath.ToString("00000.000");
((TMP_Text)calcDensityVal).text = (BetterFog.currentPreset.MeanFreePath * BetterFog.combinedDensityScale).ToString("00000.000");
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;
}
if (!BetterFog.lockPresetValueModification)
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
}
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(activateAutoPresetMode: false);
UpdateText();
}
private void OnExcludeShipCheckboxValueChanged(bool isChecked)
{
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)$"Exclude Ship Checkbox value changed: {isChecked}");
}
BetterFog.excludeShipFogEnabled = isChecked;
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
private void OnExcludeEnemiesCheckboxValueChanged(bool isChecked)
{
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)$"Exclude Enemies Checkbox value changed: {isChecked}");
}
BetterFog.excludeEnemyFogEnabled = isChecked;
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
private void OnAutoPresetModeCheckboxValueChanged(bool isChecked)
{
if (BetterFog.verboseLoggingEnabled)
{
BetterFog.mls.LogInfo((object)$"Auto Preset Mode Checkbox value changed: {isChecked}");
}
BetterFog.autoPresetModeEnabled = isChecked;
if (isChecked)
{
BetterFog.ApplyFogSettings(activateAutoPresetMode: true);
}
else
{
BetterFog.lockModeDropdownModification = false;
LockModeDropdownInteract(BetterFog.lockModeDropdownModification);
if (!(BetterFog.currentMode.Name == "Vanilla") && !(BetterFog.currentMode.Name == "No Fog"))
{
BetterFog.lockPresetDropdownModification = false;
BetterFog.lockPresetValueModification = false;
LockPresetDropdownInteract(BetterFog.lockPresetDropdownModification);
LockPresetValueInteract(BetterFog.lockPresetValueModification);
}
IngameKeybinds.Instance.nextPresetHotkey.Enable();
IngameKeybinds.Instance.nextModeHotkey.Enable();
}
UpdateText();
}
private void OnVerboseLogsCheckboxValueChanged(bool isChecked)
{
BetterFog.mls.LogInfo((object)$"Verbose Logs Checkbox value changed: {isChecked}");
BetterFog.verboseLoggingEnabled = isChecked;
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
}
private void UpdateCheckboxValues()
{
UpdateDensityScaleCheckbox();
UpdateExcludeShipCheckbox();
UpdateExcludeEnemiesCheckbox();
UpdateVerboseLogsCheckbox();
UpdateAutoPresetModeCheckbox();
}
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.excludeEnemyFogEnabled;
}
}
private void UpdateVerboseLogsCheckbox()
{
if ((Object)(object)verboseLogsCheckbox != (Object)null)
{
verboseLogsCheckbox.isOn = BetterFog.verboseLoggingEnabled;
}
}
private void UpdateAutoPresetModeCheckbox()
{
if ((Object)(object)autoPresetModeCheckbox != (Object)null)
{
autoPresetModeCheckbox.isOn = BetterFog.autoPresetModeEnabled;
}
}
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()
{
UpdateText();
UpdateDropdownWithCurrentOption(presetDropdown);
UpdateDropdownWithCurrentOption(modeDropdown);
UpdateSlidersWithCurrentPreset();
UpdateCheckboxValues();
}
private void UpdateText()
{
((TMP_Text)currentWeatherVal).text = BetterFog.currentWeatherType;
((TMP_Text)currentMoonVal).text = BetterFog.currentLevel;
((TMP_Text)currentDensityVal).text = BetterFog.currentPreset.MeanFreePath.ToString("00000.0000");
((TMP_Text)densityScaleVal).text = "x" + BetterFog.combinedDensityScale.ToString("00.0000");
((TMP_Text)calcDensityVal).text = (BetterFog.currentPreset.MeanFreePath * BetterFog.combinedDensityScale).ToString("00000.000");
BetterFog.mls.LogInfo((object)$"{15000f} - {15000f - BetterFog.currentPreset.MeanFreePath} * {BetterFog.combinedDensityScale}");
if (BetterFog.autoPresetModeEnabled)
{
if (BetterFog.matchedPreset != null)
{
((TMP_Text)matchVal).text = "Match Found!";
((TMP_Text)detectionsVal).text = BetterFog.matchedPreset.Conditions[0] + ",\n" + ((BetterFog.matchedPreset.Conditions.Count > 1) ? (BetterFog.matchedPreset.Conditions[1] + "\n") : "") + ">" + BetterFog.matchedPreset.Effect + "<\n";
}
else
{
((TMP_Text)matchVal).text = "Match Not Found";
((TMP_Text)detectionsVal).text = "";
}
}
else
{
((TMP_Text)matchVal).text = "";
((TMP_Text)detectionsVal).text = "";
}
}
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();
}
private void OnModeChanged(int currentIndex, int previousIndex)
{
BetterFog.mls.LogInfo((object)("GUI Mode Update - Mode changed from: " + BetterFog.currentMode.Name + " to: " + BetterFog.fogModes[currentIndex].Name));
BetterFog.currentModeIndex = currentIndex;
BetterFog.currentMode = BetterFog.fogModes[currentIndex];
BetterFog.Instance.UpdateMode();
BetterFog.ApplyFogSettings(activateAutoPresetMode: false);
BetterFog.UpdateLockInteractionSettings();
}
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 (BetterFog.isFogSettingsActive)
{
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;
BetterFog.isFogSettingsActive = 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);
BetterFog.UpdateLockInteractionSettings();
LockPresetDropdownInteract(BetterFog.lockPresetDropdownModification);
LockPresetValueInteract(BetterFog.lockPresetValueModification);
LockPresetDropdownInteract(BetterFog.lockPresetDropdownModification);
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
BetterFog.mls.LogInfo((object)"Fog Settings opened.");
if (BetterFog.verboseLoggingEnabled)
{
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;
BetterFog.isFogSettingsActive = 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;
}
public void LockPresetDropdownInteract(bool isLocked)
{
((Selectable)presetDropdown).interactable = !isLocked;
}
public void LockPresetValueInteract(bool isLocked)
{
((Selectable)redValInput).interactable = !isLocked;
((Selectable)greenValInput).interactable = !isLocked;
((Selectable)blueValInput).interactable = !isLocked;
((Selectable)densityValInput).interactable = !isLocked;
((Selectable)fogRedSlider).interactable = !isLocked;
((Selectable)fogGreenSlider).interactable = !isLocked;
((Selectable)fogBlueSlider).interactable = !isLocked;
((Selectable)fogDensitySlider).interactable = !isLocked;
((Selectable)densityScaleCheckbox).interactable = !isLocked;
}
public void LockModeDropdownInteract(bool isLocked)
{
((Selectable)modeDropdown).interactable = !isLocked;
}
private void OnDestroy()
{
if ((Object)(object)fogsettingsgui != (Object)null)
{
fogsettingsgui.Unload(false);
}
instance = null;
}
}
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;
}
}
}