Decompiled source of Silent PEAK v2.0.0

tony4twentys-Silent PEAK.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Peak;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyTitle("Silent PEAK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Silent PEAK")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f2481b33-e0f3-4ef9-90de-62fe65db12f6")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace tony4twentys.Silent_PEAK
{
	[BepInPlugin("tony4twentys.Silent_PEAK", "Silent PEAK", "2.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SilentPEAKPlugin : BaseUnityPlugin
	{
		internal const byte EventCode = 195;

		internal const int ProtocolVersion = 201;

		internal static SilentPEAKPlugin Instance;

		public static ConfigEntry<bool> modEnabled;

		public static ConfigEntry<bool> usePeakFilter;

		public static ConfigEntry<float> musicVolume;

		public static ConfigEntry<string> deepFogColorHex;

		public static ConfigEntry<float> gloomSoften;

		public static ConfigEntry<float> heightFogHeightOffset;

		public static ConfigEntry<KeyCode> menuKey;

		public static ConfigEntry<float> peakFilterIntensity;

		public static ConfigEntry<float> peakFilterPixelSize;

		public static ConfigEntry<float> peakFilterOutlineStrength;

		public static ConfigEntry<float> peakFilterDitherAmount;

		private static bool levelEffectsRunning;

		internal const string DefaultDeepFogColorHex = "#FFFFFF";

		internal const float DefaultGloomSoften = 0f;

		internal const float DefaultHeightFogHeightOffset = 1000f;

		internal const float DefaultPeakFilterIntensity = 1f;

		internal const float DefaultPeakFilterPixelSize = 10f;

		internal const float DefaultPeakFilterOutlineStrength = 0f;

		internal const float DefaultPeakFilterDitherAmount = 0f;

		public static AudioSource musicSource;

		private static AudioClip silentHillMix;

		private static bool musicLoaded;

		public static bool IsModActive => GetModEnabled();

		public static bool UsePeakFilterEnabled => GetUsePeakFilter();

		private void Awake()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Expected O, but got Unknown
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Expected O, but got Unknown
			Instance = this;
			modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle for Silent PEAK.");
			usePeakFilter = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsePeakFilter", true, "Apply PeakFilter Pixelate on level load when PeakFilter is installed.");
			musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MusicVolume", 25f, new ConfigDescription("Volume of Silent Hill music (0 to 100). 100 is full volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MenuKey", (KeyCode)290, "Key to open the Silent PEAK mod menu.");
			deepFogColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("Fog", "DeepFogColor", "#FFFFFF", "Fog tint as hex color (#RRGGBB).");
			gloomSoften = ((BaseUnityPlugin)this).Config.Bind<float>("Fog", "GloomSoften", 0f, new ConfigDescription("Fog visibility curve (HeightFogSoften / GloomSoften). 0 = thickest.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4.5f), Array.Empty<object>()));
			heightFogHeightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Fog", "HeightFogHeightOffset", 1000f, new ConfigDescription("Adds to HeightFogHeight relative to the player's Y. Higher = fog fills more of the screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5000f), Array.Empty<object>()));
			peakFilterIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("PeakFilter", "Intensity", 1f, new ConfigDescription("PeakFilter Pixelate intensity applied on level load (0-1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			peakFilterPixelSize = ((BaseUnityPlugin)this).Config.Bind<float>("PeakFilter", "PixelSize", 10f, new ConfigDescription("PeakFilter Pixelate block size applied on level load (1-30).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 30f), Array.Empty<object>()));
			peakFilterOutlineStrength = ((BaseUnityPlugin)this).Config.Bind<float>("PeakFilter", "OutlineStrength", 0f, new ConfigDescription("PeakFilter Pixelate outline strength applied on level load (0-3).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			peakFilterDitherAmount = ((BaseUnityPlugin)this).Config.Bind<float>("PeakFilter", "DitherAmount", 0f, new ConfigDescription("PeakFilter Pixelate dither amount applied on level load (0-1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Silent PEAK v2.0.0 loaded successfully!");
			new Harmony("tony4twentys.Silent_PEAK").PatchAll();
			SilentPeakRuntime.RefreshFromLocalConfig();
			BindSyncedSettingHandlers();
			GameObject val = new GameObject("SilentPEAK_Net");
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<SilentPeakNetworkSync>();
			SilentPeakMenu.EnsureCreated();
			SceneManager.sceneLoaded += OnSceneLoaded;
			((MonoBehaviour)this).StartCoroutine(LoadSilentHillMusic());
		}

		private void Update()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!SilentPeakMenu.IsCapturingKey && SilentPeakRuntime.CanOpenMenu() && Input.GetKeyDown(menuKey.Value))
			{
				SilentPeakMenu.Toggle();
			}
		}

		private void BindSyncedSettingHandlers()
		{
			modEnabled.SettingChanged += OnSyncedHostSettingChanged;
			usePeakFilter.SettingChanged += OnSyncedHostSettingChanged;
			deepFogColorHex.SettingChanged += OnSyncedHostSettingChanged;
			gloomSoften.SettingChanged += OnSyncedHostSettingChanged;
			heightFogHeightOffset.SettingChanged += OnSyncedHostSettingChanged;
			peakFilterIntensity.SettingChanged += OnSyncedHostSettingChanged;
			peakFilterPixelSize.SettingChanged += OnSyncedHostSettingChanged;
			peakFilterOutlineStrength.SettingChanged += OnSyncedHostSettingChanged;
			peakFilterDitherAmount.SettingChanged += OnSyncedHostSettingChanged;
		}

		private void OnSyncedHostSettingChanged(object sender, EventArgs e)
		{
			if (!SilentPeakRuntime.IsSyncingFromNet && SilentPeakRuntime.IsHostOrSolo)
			{
				SilentPeakRuntime.RefreshFromLocalConfig();
				HandleModStateChanged();
				HandlePeakFilterSettingChanged();
				SilentPeakNetworkSync.ScheduleBroadcast();
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void LateUpdate()
		{
			if (!SilentPeakRuntime.ShouldApplyModEffects())
			{
				if (levelEffectsRunning || ((Object)(object)musicSource != (Object)null && musicSource.isPlaying))
				{
					StopMusic();
				}
				PeakFilterIntegration.DisableIfAppliedByUs();
				PostFogController.Disable(((BaseUnityPlugin)this).Logger);
				levelEffectsRunning = false;
				return;
			}
			if (!ShouldRunLevelEffects())
			{
				if (levelEffectsRunning || ((Object)(object)musicSource != (Object)null && musicSource.isPlaying))
				{
					StopMusic();
				}
				PeakFilterIntegration.DisableIfAppliedByUs();
				PostFogController.Disable(((BaseUnityPlugin)this).Logger);
				levelEffectsRunning = false;
				return;
			}
			if (!levelEffectsRunning)
			{
				PostFogController.Reset();
				StartMusic();
				try
				{
					PeakFilterIntegration.ApplyOnLevelLoad();
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogDebug((object)("Silent PEAK: PeakFilter apply failed: " + ex.Message));
				}
				levelEffectsRunning = true;
			}
			PostFogController.Apply(((BaseUnityPlugin)this).Logger);
		}

		private static bool ShouldRunLevelEffects()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (string.IsNullOrEmpty(((Scene)(ref activeScene)).name) || !((Scene)(ref activeScene)).name.Contains("Level_"))
			{
				return false;
			}
			if (Character.localCharacterExists && Character.localCharacter.inAirport)
			{
				return false;
			}
			return true;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("=== SILENT PEAK: Scene loaded - " + ((Scene)(ref scene)).name + " ==="));
			SilentPeakMenu.OnAfterSceneLoad();
			PostFogController.Reset();
			levelEffectsRunning = false;
			SilentPeakNetworkSync.OnAfterSceneLoad(((Scene)(ref scene)).name);
		}

		internal static void HandleModStateChanged()
		{
			levelEffectsRunning = false;
		}

		internal static void LogDebug(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogDebug((object)message);
			}
		}

		internal static void HandlePeakFilterSettingChanged()
		{
			try
			{
				if (!ShouldRunLevelEffectsForFilter())
				{
					PeakFilterIntegration.DisableIfAppliedByUs();
				}
				else if (UsePeakFilterEnabled)
				{
					PeakFilterIntegration.ApplyOnLevelLoad();
				}
				else
				{
					PeakFilterIntegration.DisableIfAppliedByUs();
				}
			}
			catch (Exception ex)
			{
				LogDebug("Silent PEAK: PeakFilter setting change failed: " + ex.Message);
			}
		}

		private static bool ShouldRunLevelEffectsForFilter()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!SilentPeakRuntime.ShouldApplyModEffects())
			{
				return false;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			return !string.IsNullOrEmpty(((Scene)(ref activeScene)).name) && ((Scene)(ref activeScene)).name.Contains("Level_");
		}

		internal static bool GetModEnabled()
		{
			if (SilentPeakRuntime.VanillaHostMode)
			{
				return false;
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedModEnabled;
			}
			return modEnabled != null && modEnabled.Value;
		}

		internal static bool GetUsePeakFilter()
		{
			if (SilentPeakRuntime.VanillaHostMode)
			{
				return false;
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedUsePeakFilter;
			}
			return usePeakFilter != null && usePeakFilter.Value;
		}

		internal static string GetDeepFogColorHex()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedDeepFogColorHex;
			}
			return (deepFogColorHex != null) ? deepFogColorHex.Value : "#FFFFFF";
		}

		internal static float GetGloomSoften()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedGloomSoften;
			}
			return (gloomSoften != null) ? gloomSoften.Value : 0f;
		}

		internal static float GetHeightFogHeightOffset()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedHeightFogHeightOffset;
			}
			return (heightFogHeightOffset != null) ? heightFogHeightOffset.Value : 1000f;
		}

		internal static float GetPeakFilterIntensity()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedPeakFilterIntensity;
			}
			return (peakFilterIntensity != null) ? peakFilterIntensity.Value : 1f;
		}

		internal static float GetPeakFilterPixelSize()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedPeakFilterPixelSize;
			}
			return (peakFilterPixelSize != null) ? peakFilterPixelSize.Value : 10f;
		}

		internal static float GetPeakFilterOutlineStrength()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedPeakFilterOutlineStrength;
			}
			return (peakFilterOutlineStrength != null) ? peakFilterOutlineStrength.Value : 0f;
		}

		internal static float GetPeakFilterDitherAmount()
		{
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				return SilentPeakRuntime.SyncedPeakFilterDitherAmount;
			}
			return (peakFilterDitherAmount != null) ? peakFilterDitherAmount.Value : 0f;
		}

		internal static Color GetFogColor()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return FogColorUtil.ParseHex(GetDeepFogColorHex(), Color.white);
		}

		internal static void RevertFogAndPeakFilterDefaults()
		{
			if (SilentPeakRuntime.IsHostOrSolo)
			{
				deepFogColorHex.Value = "#FFFFFF";
				gloomSoften.Value = 0f;
				heightFogHeightOffset.Value = 1000f;
				peakFilterIntensity.Value = 1f;
				peakFilterPixelSize.Value = 10f;
				peakFilterOutlineStrength.Value = 0f;
				peakFilterDitherAmount.Value = 0f;
				SilentPeakMenu.ResetFogColorField();
				if (IsModActive && UsePeakFilterEnabled)
				{
					PeakFilterIntegration.ApplySettings();
				}
			}
		}

		private IEnumerator LoadSilentHillMusic()
		{
			string pluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("=== SILENT PEAK: Looking for Silent Hill music in: " + pluginDirectory + " ==="));
			string[] audioFiles = Directory.GetFiles(pluginDirectory, "*.ogg", SearchOption.AllDirectories);
			if (audioFiles.Length == 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("=== SILENT PEAK: No .ogg files found in " + pluginDirectory + " ==="));
				yield break;
			}
			string musicFile = audioFiles[0];
			string url = "file://" + Path.GetFullPath(musicFile).Replace("\\", "/");
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)14);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result != 1)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("=== SILENT PEAK: Failed to load music: " + www.error + " ==="));
					yield break;
				}
				silentHillMix = DownloadHandlerAudioClip.GetContent(www);
				if ((Object)(object)silentHillMix == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"=== SILENT PEAK: Failed to create audio clip ===");
					yield break;
				}
				SetupMusicSource();
				musicLoaded = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"=== SILENT PEAK: Silent Hill music loaded successfully ===");
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		private void SetupMusicSource()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("SilentPEAKMusicHost");
			musicSource = val.AddComponent<AudioSource>();
			musicSource.clip = silentHillMix;
			musicSource.loop = true;
			musicSource.playOnAwake = false;
			musicSource.volume = GetMusicVolumeNormalized();
			musicSource.spatialBlend = 0f;
			musicSource.dopplerLevel = 0f;
			musicSource.rolloffMode = (AudioRolloffMode)1;
			musicSource.minDistance = 1f;
			musicSource.maxDistance = 500f;
			musicSource.ignoreListenerPause = true;
			musicSource.bypassReverbZones = true;
			AudioMixerGroup val2 = TryGetGameMixerGroup();
			if ((Object)(object)val2 != (Object)null)
			{
				musicSource.outputAudioMixerGroup = val2;
			}
			Object.DontDestroyOnLoad((Object)(object)val);
		}

		private static AudioMixerGroup TryGetGameMixerGroup()
		{
			AudioSource val = ((IEnumerable<AudioSource>)Object.FindObjectsByType<AudioSource>((FindObjectsSortMode)0)).FirstOrDefault((Func<AudioSource, bool>)((AudioSource a) => (Object)(object)a != (Object)null && ((Behaviour)a).isActiveAndEnabled && (Object)(object)a.outputAudioMixerGroup != (Object)null));
			return ((Object)(object)val != (Object)null) ? val.outputAudioMixerGroup : null;
		}

		internal static float GetMusicVolumeNormalized()
		{
			return Mathf.Clamp(musicVolume.Value, 0f, 100f) / 100f;
		}

		public static void StartMusic()
		{
			if (SilentPeakRuntime.ShouldApplyModEffects() && !((Object)(object)musicSource == (Object)null) && musicLoaded)
			{
				musicSource.volume = GetMusicVolumeNormalized();
				musicSource.Play();
			}
		}

		public static void StopMusic()
		{
			if ((Object)(object)musicSource != (Object)null && musicSource.isPlaying)
			{
				musicSource.Stop();
			}
		}

		public static void UpdateMusicVolume()
		{
			if ((Object)(object)musicSource != (Object)null)
			{
				musicSource.volume = GetMusicVolumeNormalized();
			}
		}
	}
	internal static class PostFogController
	{
		private static readonly int ID_USEFOG = Shader.PropertyToID("USEFOG");

		private static readonly int ID_HEIGHT_FOG_AMT = Shader.PropertyToID("HeightFogAmount");

		private static readonly int ID_HEIGHT_FOG_HEIGHT = Shader.PropertyToID("HeightFogHeight");

		private static readonly int ID_DEEP_FOG_COLOR = Shader.PropertyToID("DeepFogColor");

		private static readonly int ID_SAFEZONE = Shader.PropertyToID("FogSafeZone");

		private static readonly int ID_GLOOM_SOFTEN = Shader.PropertyToID("GloomSoften");

		private static readonly int ID_FOG_CUTOUT = Shader.PropertyToID("FogCutoutAmount");

		private static readonly int ID_FOG_CENTER = Shader.PropertyToID("FogCenter");

		private static GameObject postFogObject;

		private static bool searchedThisScene;

		private static float fogAmount;

		internal static void Reset()
		{
			postFogObject = null;
			searchedThisScene = false;
			fogAmount = 0f;
		}

		internal static void Disable(ManualLogSource log)
		{
			fogAmount = 0f;
			ClearFogGlobals();
		}

		private static GameObject FindPostFog()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Post Fog");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).IsValid())
			{
				return null;
			}
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			for (int i = 0; i < rootGameObjects.Length; i++)
			{
				val = FindInChildren(rootGameObjects[i].transform, "Post Fog");
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static GameObject FindInChildren(Transform parent, string objectName)
		{
			if (((Object)parent).name == objectName)
			{
				return ((Component)parent).gameObject;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				GameObject val = FindInChildren(parent.GetChild(i), objectName);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static void ClearFogGlobals()
		{
			Shader.SetGlobalFloat(ID_USEFOG, 0f);
			Shader.SetGlobalFloat(ID_HEIGHT_FOG_AMT, 0f);
		}

		internal static void Apply(ManualLogSource log)
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			if (!searchedThisScene)
			{
				searchedThisScene = true;
				postFogObject = FindPostFog();
				if ((Object)(object)postFogObject != (Object)null && log != null)
				{
					log.LogInfo((object)"=== SILENT PEAK: Found Post Fog (CameraQuad / GD/ScreenFog) ===");
				}
				else if ((Object)(object)postFogObject == (Object)null && log != null)
				{
					log.LogWarning((object)"=== SILENT PEAK: Post Fog object not found in scene ===");
				}
			}
			if (Character.localCharacterExists && !((Object)(object)postFogObject == (Object)null))
			{
				if (!postFogObject.activeSelf)
				{
					postFogObject.SetActive(true);
				}
				if (fogAmount < 1f)
				{
					fogAmount = Mathf.Min(1f, fogAmount + Time.deltaTime);
				}
				Shader.SetGlobalFloat(ID_USEFOG, 1f);
				Shader.SetGlobalFloat(ID_HEIGHT_FOG_AMT, fogAmount);
				Shader.SetGlobalFloat(ID_HEIGHT_FOG_HEIGHT, Character.localCharacter.Center.y + SilentPEAKPlugin.GetHeightFogHeightOffset());
				Shader.SetGlobalFloat(ID_GLOOM_SOFTEN, Mathf.Clamp(SilentPEAKPlugin.GetGloomSoften(), 0f, 4.5f));
				Shader.SetGlobalColor(ID_DEEP_FOG_COLOR, SilentPEAKPlugin.GetFogColor());
				Shader.SetGlobalFloat(ID_SAFEZONE, 0f);
				Shader.SetGlobalFloat(ID_FOG_CUTOUT, 0f);
				Shader.SetGlobalVector(ID_FOG_CENTER, Vector4.op_Implicit(Character.localCharacter.Center));
			}
		}
	}
	[HarmonyPatch(typeof(StatusFieldGloom), "TickStatus")]
	public static class StatusFieldGloomTickPatch
	{
		public static bool Prefix()
		{
			return !SilentPEAKPlugin.IsModActive;
		}
	}
	[HarmonyPatch(typeof(StatusFieldGloom), "Update")]
	public static class StatusFieldGloomUpdatePatch
	{
		public static void Postfix(StatusFieldGloom __instance)
		{
			if (SilentPEAKPlugin.IsModActive)
			{
				((StatusFieldBase)__instance).inflicting = false;
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public static class MusicVolumeUpdatePatch
	{
		public static void Postfix(ConfigEntry<float> __instance)
		{
			if (__instance == SilentPEAKPlugin.musicVolume)
			{
				SilentPEAKPlugin.UpdateMusicVolume();
			}
		}
	}
	internal static class FogColorUtil
	{
		internal static Color ParseHex(string hex, Color fallback)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(hex))
			{
				return fallback;
			}
			hex = hex.Trim().TrimStart(new char[1] { '#' });
			if (hex.Length != 6)
			{
				return fallback;
			}
			if (!int.TryParse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result))
			{
				return fallback;
			}
			float num = (float)((result >> 16) & 0xFF) / 255f;
			float num2 = (float)((result >> 8) & 0xFF) / 255f;
			float num3 = (float)(result & 0xFF) / 255f;
			return new Color(num, num2, num3, 1f);
		}

		internal static string ToHex(Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Mathf.RoundToInt(color.r * 255f), 0, 255);
			int num2 = Mathf.Clamp(Mathf.RoundToInt(color.g * 255f), 0, 255);
			int num3 = Mathf.Clamp(Mathf.RoundToInt(color.b * 255f), 0, 255);
			return $"#{num:X2}{num2:X2}{num3:X2}";
		}
	}
	internal static class PeakFilterIntegration
	{
		private const string PluginGuid = "com.peak.filter";

		private const string AssemblyName = "PeakFilter";

		private const string FilterConfigTypeName = "PeakFilter.FilterConfig";

		private const string FilterTypeName = "PeakFilter.FilterType";

		private static bool appliedByUs;

		private static bool resolved;

		private static bool available;

		private static Type filterConfigType;

		private static Type filterTypeEnum;

		private static object pixelateFilterValue;

		internal static bool IsAvailable
		{
			get
			{
				EnsureResolved();
				return available;
			}
		}

		internal static void ApplyOnLevelLoad()
		{
			ApplySettings();
		}

		internal static void ApplySettings()
		{
			if (!SilentPEAKPlugin.IsModActive || !SilentPEAKPlugin.UsePeakFilterEnabled || !EnsureResolved())
			{
				return;
			}
			try
			{
				SetConfigBool("ModEnabled", value: true);
				SetConfigEnum("ActiveFilter", pixelateFilterValue);
				SetConfigFloat("Intensity", SilentPEAKPlugin.GetPeakFilterIntensity());
				SetConfigFloat("PixelSize", SilentPEAKPlugin.GetPeakFilterPixelSize());
				SetConfigFloat("PixelOutlineStrength", SilentPEAKPlugin.GetPeakFilterOutlineStrength());
				SetConfigFloat("PixelDitherAmount", SilentPEAKPlugin.GetPeakFilterDitherAmount());
				appliedByUs = true;
			}
			catch (Exception ex)
			{
				SilentPEAKPlugin.LogDebug("Silent PEAK: PeakFilter apply skipped: " + ex.Message);
			}
		}

		internal static void DisableIfAppliedByUs()
		{
			if (!appliedByUs || !EnsureResolved())
			{
				return;
			}
			try
			{
				SetConfigBool("ModEnabled", value: false);
			}
			catch (Exception ex)
			{
				SilentPEAKPlugin.LogDebug("Silent PEAK: PeakFilter disable skipped: " + ex.Message);
			}
			finally
			{
				appliedByUs = false;
			}
		}

		private static bool EnsureResolved()
		{
			if (resolved)
			{
				return available;
			}
			resolved = true;
			available = false;
			if (!Chainloader.PluginInfos.ContainsKey("com.peak.filter"))
			{
				return false;
			}
			try
			{
				Assembly assembly = FindPeakFilterAssembly();
				if (assembly == null)
				{
					return false;
				}
				filterConfigType = assembly.GetType("PeakFilter.FilterConfig", throwOnError: false);
				filterTypeEnum = assembly.GetType("PeakFilter.FilterType", throwOnError: false);
				if (filterConfigType == null || filterTypeEnum == null)
				{
					return false;
				}
				pixelateFilterValue = Enum.Parse(filterTypeEnum, "Pixelate");
				available = true;
			}
			catch (Exception ex)
			{
				SilentPEAKPlugin.LogDebug("Silent PEAK: PeakFilter resolve failed: " + ex.Message);
				available = false;
			}
			return available;
		}

		private static Assembly FindPeakFilterAssembly()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == "PeakFilter")
				{
					return assembly;
				}
			}
			return null;
		}

		private static void SetConfigBool(string fieldName, bool value)
		{
			SetConfigValue(fieldName, value);
		}

		private static void SetConfigFloat(string fieldName, float value)
		{
			SetConfigValue(fieldName, value);
		}

		private static void SetConfigEnum(string fieldName, object value)
		{
			SetConfigValue(fieldName, value);
		}

		private static void SetConfigValue(string fieldName, object value)
		{
			FieldInfo field = filterConfigType.GetField(fieldName, BindingFlags.Static | BindingFlags.Public);
			if (field == null)
			{
				throw new MissingFieldException(filterConfigType.FullName, fieldName);
			}
			object value2 = field.GetValue(null);
			if (value2 == null)
			{
				throw new MissingMemberException(filterConfigType.FullName, fieldName);
			}
			PropertyInfo property = value2.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public);
			if (property == null)
			{
				throw new MissingMemberException(value2.GetType().FullName, "Value");
			}
			property.SetValue(value2, value, null);
		}
	}
	internal sealed class SilentPeakColorPicker : MonoBehaviour
	{
		private sealed class WheelHit : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IDragHandler
		{
			internal Action<Vector2> OnHit;

			public void OnPointerDown(PointerEventData eventData)
			{
				Hit(eventData);
			}

			public void OnDrag(PointerEventData eventData)
			{
				Hit(eventData);
			}

			private void Hit(PointerEventData eventData)
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				Transform transform = ((Component)this).transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				Vector2 val2 = default(Vector2);
				if (!((Object)(object)val == (Object)null) && eventData != null && RectTransformUtility.ScreenPointToLocalPointInRectangle(val, eventData.position, eventData.pressEventCamera, ref val2))
				{
					Rect rect = val.rect;
					float num = Mathf.InverseLerp(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).xMax, val2.x);
					float num2 = Mathf.InverseLerp(((Rect)(ref rect)).yMin, ((Rect)(ref rect)).yMax, val2.y);
					OnHit?.Invoke(new Vector2(num, num2));
				}
			}
		}

		private const float WheelSize = 168f;

		internal Action<Color> OnChanged;

		private RectTransform _wheelRt;

		private Image _preview;

		private RectTransform _marker;

		private Slider _brightness;

		private TextMeshProUGUI _brightnessValue;

		private Texture2D _wheelTex;

		private Sprite _wheelSprite;

		private float _h;

		private float _s = 1f;

		private float _v = 1f;

		private bool _suppress;

		internal Color Current => Color.HSVToRGB(_h, _s, _v);

		internal static SilentPeakColorPicker Create(Transform parent, Color start, Action<Color> onChanged)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ColorPicker", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.minHeight = 248f;
			val2.preferredHeight = 248f;
			val2.flexibleWidth = 1f;
			((LayoutGroup)SilentPeakUi.AddVerticalLayout(val, 8f, new RectOffset(4, 4, 4, 4))).childAlignment = (TextAnchor)1;
			SilentPeakColorPicker silentPeakColorPicker = val.AddComponent<SilentPeakColorPicker>();
			silentPeakColorPicker.OnChanged = onChanged;
			silentPeakColorPicker.Build();
			silentPeakColorPicker.SetColor(start, notify: false);
			return silentPeakColorPicker;
		}

		internal void SetColor(Color color, bool notify)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			Color.RGBToHSV(color, ref _h, ref _s, ref _v);
			_suppress = true;
			if ((Object)(object)_brightness != (Object)null)
			{
				_brightness.SetValueWithoutNotify(Mathf.Round(_v * 100f));
			}
			UpdateValueLabels();
			UpdateMarker();
			UpdatePreview();
			_suppress = false;
			if (notify)
			{
				RaiseChanged();
			}
		}

		private void Build()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Wheel", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(((Component)this).transform, false);
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.preferredWidth = 168f;
			val2.preferredHeight = 168f;
			val2.minWidth = 168f;
			val2.minHeight = 168f;
			_wheelRt = val.GetComponent<RectTransform>();
			_wheelRt.sizeDelta = new Vector2(168f, 168f);
			_wheelTex = MakeWheelTexture();
			_wheelSprite = Sprite.Create(_wheelTex, new Rect(0f, 0f, (float)((Texture)_wheelTex).width, (float)((Texture)_wheelTex).height), new Vector2(0.5f, 0.5f), 100f);
			((Object)_wheelSprite).name = "SilentPeak_ColorWheel";
			Image component = val.GetComponent<Image>();
			component.sprite = _wheelSprite;
			((Graphic)component).raycastTarget = true;
			component.preserveAspect = true;
			WheelHit wheelHit = val.AddComponent<WheelHit>();
			wheelHit.OnHit = OnWheelHit;
			GameObject val3 = new GameObject("Marker", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val3.transform.SetParent(val.transform, false);
			_marker = val3.GetComponent<RectTransform>();
			RectTransform marker = _marker;
			RectTransform marker2 = _marker;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0.5f);
			marker2.anchorMax = val4;
			marker.anchorMin = val4;
			_marker.sizeDelta = new Vector2(14f, 14f);
			Image component2 = val3.GetComponent<Image>();
			component2.sprite = SilentPeakUi.WhiteSprite();
			((Graphic)component2).color = Color.white;
			((Graphic)component2).raycastTarget = false;
			Outline val5 = val3.AddComponent<Outline>();
			((Shadow)val5).effectColor = Color.black;
			((Shadow)val5).effectDistance = new Vector2(1.2f, -1.2f);
			_preview = MakePreview();
			AddSliderRow("Brightness", out _brightness, out _brightnessValue, delegate(float v)
			{
				if (!_suppress)
				{
					_v = Mathf.Clamp01(v / 100f);
					UpdatePreview();
					RaiseChanged();
				}
			});
		}

		private Image MakePreview()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			GameObject val = new GameObject("Preview", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			SilentPeakUi.MakeNonCollapsing(val, 28f);
			((LayoutGroup)SilentPeakUi.AddHorizontalLayout(val, 8f)).childAlignment = (TextAnchor)4;
			GameObject val2 = new GameObject("Color", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val2.transform.SetParent(val.transform, false);
			LayoutElement val3 = val2.AddComponent<LayoutElement>();
			val3.flexibleWidth = 1f;
			val3.minHeight = 28f;
			val3.preferredHeight = 28f;
			Image component = val2.GetComponent<Image>();
			component.sprite = SilentPeakUi.WhiteSprite();
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private void AddSliderRow(string label, out Slider slider, out TextMeshProUGUI valueLabel, UnityAction<float> onChanged)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(label, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(((Component)this).transform, false);
			SilentPeakUi.MakeNonCollapsing(val, 24f);
			((LayoutGroup)SilentPeakUi.AddHorizontalLayout(val, 8f)).childAlignment = (TextAnchor)3;
			TextMeshProUGUI val2 = SilentPeakUi.CreateLabel(val.transform, "N", label, 14f, (FontStyles)0, (TextAlignmentOptions)513);
			((Graphic)val2).color = SilentPeakUi.CreamDim;
			SilentPeakUi.MakeNonCollapsing(((Component)val2).gameObject, 22f, 90f);
			slider = SilentPeakUi.CreateSlider(val.transform, 0f, 100f, 100f, wholeNumbers: true, onChanged);
			valueLabel = SilentPeakUi.CreateLabel(val.transform, "V", "100%", 13f, (FontStyles)0, (TextAlignmentOptions)516);
			((Graphic)valueLabel).color = SilentPeakUi.CreamDim;
			SilentPeakUi.MakeNonCollapsing(((Component)valueLabel).gameObject, 22f, 44f);
		}

		private void OnWheelHit(Vector2 local01)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			float num = local01.x * 2f - 1f;
			float num2 = local01.y * 2f - 1f;
			float num3 = Mathf.Sqrt(num * num + num2 * num2);
			if (!(num3 > 1.05f))
			{
				if (num3 > 1f)
				{
					num3 = 1f;
				}
				_s = num3;
				float num4 = Mathf.Atan2(num2, num) / ((float)Math.PI * 2f);
				if (num4 < 0f)
				{
					num4 += 1f;
				}
				_h = num4;
				UpdateMarker();
				UpdatePreview();
				RaiseChanged();
			}
		}

		private void UpdateMarker()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_marker == (Object)null))
			{
				float num = _h * (float)Math.PI * 2f;
				float num2 = _s * 80f;
				_marker.anchoredPosition = new Vector2(Mathf.Cos(num) * num2, Mathf.Sin(num) * num2);
				((Graphic)((Component)_marker).GetComponent<Image>()).color = ((_v > 0.55f) ? Color.black : Color.white);
			}
		}

		private void UpdatePreview()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_preview != (Object)null)
			{
				((Graphic)_preview).color = Current;
			}
			UpdateValueLabels();
		}

		private void UpdateValueLabels()
		{
			if ((Object)(object)_brightnessValue != (Object)null)
			{
				((TMP_Text)_brightnessValue).text = Mathf.RoundToInt(_v * 100f) + "%";
			}
		}

		private void RaiseChanged()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!_suppress)
			{
				OnChanged?.Invoke(Current);
			}
		}

		private static Texture2D MakeWheelTexture()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			Color[] array = (Color[])(object)new Color[16384];
			float num = 63.5f;
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num2 = ((float)j - num) / num;
					float num3 = ((float)i - num) / num;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					if (num4 > 1f)
					{
						array[i * 128 + j] = Color.clear;
						continue;
					}
					float num5 = Mathf.Atan2(num3, num2) / ((float)Math.PI * 2f);
					if (num5 < 0f)
					{
						num5 += 1f;
					}
					Color val2 = Color.HSVToRGB(num5, num4, 1f);
					val2.a = 1f;
					array[i * 128 + j] = val2;
				}
			}
			val.SetPixels(array);
			val.Apply(false, false);
			return val;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_wheelSprite != (Object)null)
			{
				Object.Destroy((Object)(object)_wheelSprite);
			}
			if ((Object)(object)_wheelTex != (Object)null)
			{
				Object.Destroy((Object)(object)_wheelTex);
			}
		}
	}
	internal sealed class SilentPeakMenu : MonoBehaviour
	{
		private enum Tab
		{
			General,
			Fog,
			Filter,
			Keys
		}

		[HarmonyPatch(typeof(GUIManager), "UpdateWindowStatus")]
		private static class Patch_UpdateWindowStatus
		{
			private static void Postfix(GUIManager __instance)
			{
				if (!((Object)(object)__instance == (Object)null) && IsOpen)
				{
					__instance.windowBlockingInput = true;
					__instance.windowShowingCursor = true;
				}
			}
		}

		[HarmonyPatch(typeof(Character), "CanDoInput")]
		private static class Patch_CanDoInput
		{
			private static void Postfix(ref bool __result)
			{
				if (IsOpen)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(CursorHandler), "Update")]
		private static class Patch_CursorHandler
		{
			private static void Postfix()
			{
				if (IsOpen)
				{
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
			}
		}

		private const int SortOrder = 9350;

		private static SilentPeakMenu _instance;

		private static KeyCode? _pendingBind;

		private RectTransform _panel;

		private GameObject _generalPage;

		private GameObject _fogPage;

		private GameObject _filterPage;

		private GameObject _keysPage;

		private Button _generalTab;

		private Button _fogTab;

		private Button _filterTab;

		private Button _keysTab;

		private Tab _activeTab = Tab.General;

		private Toggle _enabledToggle;

		private Toggle _usePeakFilterToggle;

		private Slider _musicSlider;

		private TextMeshProUGUI _musicValue;

		private Slider _gloomSlider;

		private TextMeshProUGUI _gloomValue;

		private Slider _heightFogSlider;

		private TextMeshProUGUI _heightFogValue;

		private SilentPeakColorPicker _colorPicker;

		private TextMeshProUGUI _captureHint;

		private TextMeshProUGUI _menuKeyLabel;

		private Slider _pfIntensitySlider;

		private Slider _pfPixelSlider;

		private Slider _pfOutlineSlider;

		private Slider _pfDitherSlider;

		private TextMeshProUGUI _pfIntensityValue;

		private TextMeshProUGUI _pfPixelValue;

		private TextMeshProUGUI _pfOutlineValue;

		private TextMeshProUGUI _pfDitherValue;

		private TextMeshProUGUI _clientHint;

		private TextMeshProUGUI _titleLabel;

		private GameObject _revertDefaultsButton;

		private TextMeshProUGUI _filterUnavailableHint;

		private bool _visible;

		private bool _built;

		private bool _syncing;

		private CursorLockMode _prevLock;

		private bool _prevCursorVisible;

		private Vector2 _frozenLookValues;

		private bool _hasFrozenLook;

		private Action<KeyCode> _captureTarget;

		private TextMeshProUGUI _captureLabel;

		public static bool IsOpen => (Object)(object)_instance != (Object)null && _instance._visible && ((Component)_instance).gameObject.activeInHierarchy;

		public static bool IsCapturingKey => _pendingBind.HasValue;

		public static void EnsureCreated()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)_instance != (Object)null))
			{
				GameObject val = new GameObject("SilentPEAK_Menu");
				Object.DontDestroyOnLoad((Object)(object)val);
				_instance = val.AddComponent<SilentPeakMenu>();
				val.SetActive(false);
			}
		}

		public static void Toggle()
		{
			if (SilentPeakRuntime.CanOpenMenu())
			{
				EnsureCreated();
				if (_instance._visible)
				{
					_instance.CloseInternal();
				}
				else
				{
					_instance.Open();
				}
			}
		}

		public static void Close()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.CloseInternal();
			}
		}

		public static void OnAfterSceneLoad()
		{
			SilentPeakUi.InvalidateButtonDonor();
			if ((Object)(object)_instance == (Object)null)
			{
				return;
			}
			try
			{
				if (_instance._visible)
				{
					_instance.CloseInternal();
				}
			}
			catch
			{
			}
		}

		internal static void ResetFogColorField()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance != (Object)null && (Object)(object)_instance._colorPicker != (Object)null)
			{
				_instance._colorPicker.SetColor(SilentPEAKPlugin.GetFogColor(), notify: false);
			}
		}

		internal unsafe static string FormatKey(KeyCode key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return ((int)key == 0) ? "None" : ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
		}

		private void Open()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Build();
			_visible = true;
			((Component)this).gameObject.SetActive(true);
			_prevLock = Cursor.lockState;
			_prevCursorVisible = Cursor.visible;
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			ApplyMenuInputBlock(block: true);
			CaptureFrozenLook();
			ApplyMenuLayout();
			SyncFromConfig();
			ShowTab(GetDefaultTab());
			SilentPeakUi.ApplyAllFonts(((Component)this).transform);
		}

		private static Tab GetDefaultTab()
		{
			return SilentPeakRuntime.IsHostOrSolo ? Tab.General : Tab.General;
		}

		private void ApplyMenuLayout()
		{
			bool isHostOrSolo = SilentPeakRuntime.IsHostOrSolo;
			if ((Object)(object)_titleLabel != (Object)null)
			{
				((TMP_Text)_titleLabel).text = (isHostOrSolo ? "Silent PEAK   (drag)" : "Silent PEAK   (local settings)");
			}
			if ((Object)(object)_generalTab != (Object)null)
			{
				((Component)_generalTab).gameObject.SetActive(true);
				TextMeshProUGUI componentInChildren = ((Component)_generalTab).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((TMP_Text)componentInChildren).text = (isHostOrSolo ? "General" : "Local");
				}
			}
			if ((Object)(object)_fogTab != (Object)null)
			{
				((Component)_fogTab).gameObject.SetActive(isHostOrSolo);
			}
			if ((Object)(object)_filterTab != (Object)null)
			{
				((Component)_filterTab).gameObject.SetActive(isHostOrSolo);
			}
			if ((Object)(object)_keysTab != (Object)null)
			{
				((Component)_keysTab).gameObject.SetActive(true);
			}
			if ((Object)(object)_enabledToggle != (Object)null)
			{
				((Component)_enabledToggle).gameObject.SetActive(isHostOrSolo);
			}
			if ((Object)(object)_usePeakFilterToggle != (Object)null)
			{
				((Component)_usePeakFilterToggle).gameObject.SetActive(isHostOrSolo);
			}
			if ((Object)(object)_revertDefaultsButton != (Object)null)
			{
				_revertDefaultsButton.SetActive(isHostOrSolo);
			}
			if ((Object)(object)_clientHint != (Object)null)
			{
				((Component)_clientHint).gameObject.SetActive(!isHostOrSolo);
			}
			if ((Object)(object)_fogPage != (Object)null)
			{
				_fogPage.SetActive(false);
			}
			if ((Object)(object)_filterPage != (Object)null)
			{
				_filterPage.SetActive(false);
			}
		}

		private void CloseInternal()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (_visible)
			{
				_visible = false;
				_pendingBind = null;
				_hasFrozenLook = false;
				SilentPeakUi.ReleaseUiFocus();
				ApplyMenuInputBlock(block: false);
				Cursor.lockState = _prevLock;
				Cursor.visible = _prevCursorVisible;
				((Component)this).gameObject.SetActive(false);
			}
		}

		private void Update()
		{
			if (_visible)
			{
				if (_pendingBind.HasValue)
				{
					PollKeyCapture();
				}
				else if (Input.GetKeyDown((KeyCode)27))
				{
					CloseInternal();
				}
			}
		}

		private void LateUpdate()
		{
			if (_visible)
			{
				HoldFrozenLook();
			}
		}

		private void Build()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Expected O, but got Unknown
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Expected O, but got Unknown
			if (!_built)
			{
				_built = true;
				SilentPeakUi.CreateOverlayCanvas(((Component)this).gameObject, 9350);
				_panel = SilentPeakUi.CreatePanel(((Component)this).transform, "Panel", new Vector2(520f, 680f), SilentPeakUi.PanelColor);
				SilentPeakUi.AddVerticalLayout(((Component)_panel).gameObject, 6f, new RectOffset(16, 16, 12, 12));
				GameObject val = new GameObject("TitleBar", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent((Transform)(object)_panel, false);
				SilentPeakUi.MakeNonCollapsing(val, 34f);
				SilentPeakUi.Stretch(((TMP_Text)(_titleLabel = SilentPeakUi.CreateLabel(val.transform, "Title", "Silent PEAK   (drag)", 24f, (FontStyles)0, (TextAlignmentOptions)514))).rectTransform, 0f, 0f);
				SilentPeakUi.MakeDraggable(val, _panel);
				GameObject val2 = new GameObject("Tabs", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent((Transform)(object)_panel, false);
				SilentPeakUi.MakeNonCollapsing(val2, 36f);
				((LayoutGroup)SilentPeakUi.AddHorizontalLayout(val2, 6f)).childAlignment = (TextAnchor)4;
				_generalTab = SilentPeakUi.CreatePlainButton(val2.transform, "General", (UnityAction)delegate
				{
					ShowTab(Tab.General);
				}, new Vector2(118f, 34f));
				_fogTab = SilentPeakUi.CreatePlainButton(val2.transform, "Fog", (UnityAction)delegate
				{
					ShowTab(Tab.Fog);
				}, new Vector2(118f, 34f));
				_filterTab = SilentPeakUi.CreatePlainButton(val2.transform, "Filter", (UnityAction)delegate
				{
					ShowTab(Tab.Filter);
				}, new Vector2(118f, 34f));
				_keysTab = SilentPeakUi.CreatePlainButton(val2.transform, "Keys", (UnityAction)delegate
				{
					ShowTab(Tab.Keys);
				}, new Vector2(118f, 34f));
				GameObject val3 = new GameObject("Pages", new Type[1] { typeof(RectTransform) });
				val3.transform.SetParent((Transform)(object)_panel, false);
				LayoutElement val4 = val3.AddComponent<LayoutElement>();
				val4.flexibleHeight = 1f;
				val4.minHeight = 360f;
				_generalPage = BuildGeneralPage(val3.transform);
				_fogPage = BuildFogPage(val3.transform);
				_filterPage = BuildFilterPage(val3.transform);
				_keysPage = BuildKeysPage(val3.transform);
				_captureHint = SilentPeakUi.CreateLabel((Transform)(object)_panel, "Capture", string.Empty, 14f, (FontStyles)0, (TextAlignmentOptions)514);
				((Graphic)_captureHint).color = SilentPeakUi.CreamDim;
				SilentPeakUi.MakeNonCollapsing(((Component)_captureHint).gameObject, 22f);
				SilentPeakUi.CreatePlainButton((Transform)(object)_panel, "Close", new UnityAction(CloseInternal), new Vector2(200f, 36f));
				ShowTab(Tab.General);
			}
		}

		private GameObject BuildGeneralPage(Transform parent)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			GameObject val = MakePage(parent, "GeneralPage");
			RectTransform content;
			ScrollRect val2 = SilentPeakUi.CreateScrollView(val.transform, out content);
			SilentPeakUi.Stretch(((Component)val2).GetComponent<RectTransform>(), 0f, 0f);
			SilentPeakUi.AddVerticalLayout(((Component)content).gameObject, 8f, new RectOffset(4, 4, 4, 4));
			ContentSizeFitter val3 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
			val3.verticalFit = (FitMode)2;
			_enabledToggle = SilentPeakUi.CreateToggle((Transform)(object)content, "Enable Silent PEAK", SilentPEAKPlugin.modEnabled.Value, OnEnabledChanged);
			_usePeakFilterToggle = SilentPeakUi.CreateToggle((Transform)(object)content, "Use PeakFilter Pixelate", SilentPEAKPlugin.usePeakFilter.Value, OnUsePeakFilterChanged);
			_clientHint = AddHint((Transform)(object)content, "Fog and PeakFilter settings are controlled by the host.");
			((Component)_clientHint).gameObject.SetActive(false);
			AddHint((Transform)(object)content, "Music volume uses the same 0-100 scale as config. 100 is full volume.");
			AddSliderRow((Transform)(object)content, "Music Volume", 0f, 100f, SilentPEAKPlugin.musicVolume.Value, wholeNumbers: true, out _musicSlider, out _musicValue, delegate(float v)
			{
				SilentPEAKPlugin.musicVolume.Value = v;
				SilentPEAKPlugin.UpdateMusicVolume();
			});
			Button val4 = SilentPeakUi.CreatePlainButton((Transform)(object)content, "Revert Fog + PeakFilter Defaults", (UnityAction)delegate
			{
				SilentPEAKPlugin.RevertFogAndPeakFilterDefaults();
				SyncFromConfig();
			}, new Vector2(420f, 34f));
			_revertDefaultsButton = ((Component)val4).gameObject;
			return val;
		}

		private GameObject BuildFogPage(Transform parent)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = MakePage(parent, "FogPage");
			RectTransform content;
			ScrollRect val2 = SilentPeakUi.CreateScrollView(val.transform, out content);
			SilentPeakUi.Stretch(((Component)val2).GetComponent<RectTransform>(), 0f, 0f);
			SilentPeakUi.AddVerticalLayout(((Component)content).gameObject, 8f, new RectOffset(4, 4, 4, 4));
			ContentSizeFitter val3 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
			val3.verticalFit = (FitMode)2;
			AddSectionLabel((Transform)(object)content, "Fog Color");
			_colorPicker = SilentPeakColorPicker.Create((Transform)(object)content, SilentPEAKPlugin.GetFogColor(), delegate(Color color)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				if (!_syncing && SilentPeakRuntime.IsHostOrSolo)
				{
					SilentPEAKPlugin.deepFogColorHex.Value = FogColorUtil.ToHex(color);
				}
			});
			AddSliderRow((Transform)(object)content, "Gloom Soften", 0f, 4.5f, SilentPEAKPlugin.gloomSoften.Value, wholeNumbers: false, out _gloomSlider, out _gloomValue, delegate(float v)
			{
				if (SilentPeakRuntime.IsHostOrSolo)
				{
					SilentPEAKPlugin.gloomSoften.Value = v;
				}
			});
			AddSliderRow((Transform)(object)content, "Height Fog Offset", 0f, 5000f, SilentPEAKPlugin.heightFogHeightOffset.Value, wholeNumbers: true, out _heightFogSlider, out _heightFogValue, delegate(float v)
			{
				if (SilentPeakRuntime.IsHostOrSolo)
				{
					SilentPEAKPlugin.heightFogHeightOffset.Value = v;
				}
			});
			return val;
		}

		private GameObject BuildFilterPage(Transform parent)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			GameObject val = MakePage(parent, "FilterPage");
			RectTransform content;
			ScrollRect val2 = SilentPeakUi.CreateScrollView(val.transform, out content);
			SilentPeakUi.Stretch(((Component)val2).GetComponent<RectTransform>(), 0f, 0f);
			SilentPeakUi.AddVerticalLayout(((Component)content).gameObject, 8f, new RectOffset(4, 4, 4, 4));
			ContentSizeFitter val3 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
			val3.verticalFit = (FitMode)2;
			_filterUnavailableHint = AddHint((Transform)(object)content, PeakFilterIntegration.IsAvailable ? "PeakFilter Pixelate preset applied on level load when Use PeakFilter is enabled." : "PeakFilter is not installed.");
			if (PeakFilterIntegration.IsAvailable)
			{
				AddSliderRow((Transform)(object)content, "Intensity", 0f, 1f, SilentPEAKPlugin.peakFilterIntensity.Value, wholeNumbers: false, out _pfIntensitySlider, out _pfIntensityValue, delegate(float v)
				{
					if (SilentPeakRuntime.IsHostOrSolo)
					{
						SilentPEAKPlugin.peakFilterIntensity.Value = v;
						PeakFilterIntegration.ApplySettings();
					}
				});
				AddSliderRow((Transform)(object)content, "Pixel Size", 1f, 30f, SilentPEAKPlugin.peakFilterPixelSize.Value, wholeNumbers: false, out _pfPixelSlider, out _pfPixelValue, delegate(float v)
				{
					if (SilentPeakRuntime.IsHostOrSolo)
					{
						SilentPEAKPlugin.peakFilterPixelSize.Value = v;
						PeakFilterIntegration.ApplySettings();
					}
				});
				AddSliderRow((Transform)(object)content, "Outline", 0f, 3f, SilentPEAKPlugin.peakFilterOutlineStrength.Value, wholeNumbers: false, out _pfOutlineSlider, out _pfOutlineValue, delegate(float v)
				{
					if (SilentPeakRuntime.IsHostOrSolo)
					{
						SilentPEAKPlugin.peakFilterOutlineStrength.Value = v;
						PeakFilterIntegration.ApplySettings();
					}
				});
				AddSliderRow((Transform)(object)content, "Dither", 0f, 1f, SilentPEAKPlugin.peakFilterDitherAmount.Value, wholeNumbers: false, out _pfDitherSlider, out _pfDitherValue, delegate(float v)
				{
					if (SilentPeakRuntime.IsHostOrSolo)
					{
						SilentPEAKPlugin.peakFilterDitherAmount.Value = v;
						PeakFilterIntegration.ApplySettings();
					}
				});
			}
			return val;
		}

		private GameObject BuildKeysPage(Transform parent)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			GameObject val = MakePage(parent, "KeysPage");
			RectTransform content;
			ScrollRect val2 = SilentPeakUi.CreateScrollView(val.transform, out content);
			SilentPeakUi.Stretch(((Component)val2).GetComponent<RectTransform>(), 0f, 0f);
			SilentPeakUi.AddVerticalLayout(((Component)content).gameObject, 8f, new RectOffset(4, 4, 4, 4));
			ContentSizeFitter val3 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
			val3.verticalFit = (FitMode)2;
			AddHint((Transform)(object)content, "Press Set, then press the key you want for the mod menu.");
			AddBindRow((Transform)(object)content, "Menu Key", () => SilentPEAKPlugin.menuKey.Value, delegate(KeyCode key)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				SilentPEAKPlugin.menuKey.Value = key;
			}, out _menuKeyLabel);
			return val;
		}

		private static GameObject MakePage(Transform parent, string name)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			SilentPeakUi.Stretch(val.GetComponent<RectTransform>(), 0f, 0f);
			return val;
		}

		private static TextMeshProUGUI AddHint(Transform parent, string text)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = SilentPeakUi.CreateLabel(parent, "Hint", text, 14f, (FontStyles)0, (TextAlignmentOptions)513);
			((Graphic)val).color = SilentPeakUi.CreamDim;
			SilentPeakUi.MakeNonCollapsing(((Component)val).gameObject, 36f);
			((TMP_Text)val).enableWordWrapping = true;
			return val;
		}

		private static void AddSectionLabel(Transform parent, string text)
		{
			TextMeshProUGUI val = SilentPeakUi.CreateLabel(parent, "Section", text, 16f, (FontStyles)1, (TextAlignmentOptions)513);
			SilentPeakUi.MakeNonCollapsing(((Component)val).gameObject, 24f);
		}

		private static void AddSliderRow(Transform parent, string label, float min, float max, float value, bool wholeNumbers, out Slider slider, out TextMeshProUGUI valueLabel, Action<float> onChanged)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SliderRow_" + SilentPeakUi.Sanitize(label), new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			SilentPeakUi.MakeNonCollapsing(val, 28f);
			((LayoutGroup)SilentPeakUi.AddHorizontalLayout(val, 8f)).childAlignment = (TextAnchor)3;
			TextMeshProUGUI val2 = SilentPeakUi.CreateLabel(val.transform, "N", label, 15f, (FontStyles)0, (TextAlignmentOptions)513);
			SilentPeakUi.MakeNonCollapsing(((Component)val2).gameObject, 24f, 130f);
			slider = SilentPeakUi.CreateSlider(val.transform, min, max, value, wholeNumbers, delegate(float v)
			{
				onChanged?.Invoke(v);
			});
			valueLabel = SilentPeakUi.CreateLabel(val.transform, "V", FormatSliderValue(value, wholeNumbers), 14f, (FontStyles)0, (TextAlignmentOptions)516);
			((Graphic)valueLabel).color = SilentPeakUi.CreamDim;
			SilentPeakUi.MakeNonCollapsing(((Component)valueLabel).gameObject, 24f, 52f);
			TextMeshProUGUI sliderValueLabel = valueLabel;
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate(float v)
			{
				((TMP_Text)sliderValueLabel).text = FormatSliderValue(v, wholeNumbers);
			});
		}

		private static string FormatSliderValue(float value, bool wholeNumbers)
		{
			return wholeNumbers ? Mathf.RoundToInt(value).ToString() : value.ToString("0.00");
		}

		private void AddBindRow(Transform parent, string label, Func<KeyCode> get, Action<KeyCode> set, out TextMeshProUGUI valueLabel)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			GameObject val = MakeRow(parent);
			TextMeshProUGUI val2 = SilentPeakUi.CreateLabel(val.transform, "N", label, 16f, (FontStyles)0, (TextAlignmentOptions)513);
			SilentPeakUi.MakeNonCollapsing(((Component)val2).gameObject, 32f, 120f);
			valueLabel = SilentPeakUi.CreateLabel(val.transform, "V", FormatKey(get()), 16f, (FontStyles)0, (TextAlignmentOptions)513);
			SilentPeakUi.MakeNonCollapsing(((Component)valueLabel).gameObject, 32f, 120f);
			TextMeshProUGUI bindValueLabel = valueLabel;
			SilentPeakUi.CreatePlainButton(val.transform, "Set", (UnityAction)delegate
			{
				BeginCapture(label, set, bindValueLabel);
			}, new Vector2(70f, 32f));
			SilentPeakUi.CreatePlainButton(val.transform, "Clear", (UnityAction)delegate
			{
				set((KeyCode)0);
				((TMP_Text)bindValueLabel).text = FormatKey((KeyCode)0);
			}, new Vector2(70f, 32f));
		}

		private static GameObject MakeRow(Transform parent)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			GameObject val = new GameObject("Row", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			SilentPeakUi.MakeNonCollapsing(val, 36f);
			((LayoutGroup)SilentPeakUi.AddHorizontalLayout(val, 8f)).childAlignment = (TextAnchor)3;
			return val;
		}

		private void BeginCapture(string label, Action<KeyCode> set, TextMeshProUGUI valueLabel)
		{
			_pendingBind = (KeyCode)0;
			_captureTarget = set;
			_captureLabel = valueLabel;
			if ((Object)(object)_captureHint != (Object)null)
			{
				((TMP_Text)_captureHint).text = "Press a key for " + label + "  (Esc cancels)";
			}
		}

		private void PollKeyCapture()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown((KeyCode)27))
			{
				_pendingBind = null;
				if ((Object)(object)_captureHint != (Object)null)
				{
					((TMP_Text)_captureHint).text = string.Empty;
				}
				return;
			}
			foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
			{
				if ((int)value == 0 || (int)value == 27 || ((int)value >= 323 && (int)value <= 329) || !Input.GetKeyDown(value))
				{
					continue;
				}
				_captureTarget?.Invoke(value);
				if ((Object)(object)_captureLabel != (Object)null)
				{
					((TMP_Text)_captureLabel).text = FormatKey(value);
				}
				_pendingBind = null;
				if ((Object)(object)_captureHint != (Object)null)
				{
					((TMP_Text)_captureHint).text = string.Empty;
				}
				break;
			}
		}

		private void OnEnabledChanged(bool enabled)
		{
			if (SilentPeakRuntime.IsHostOrSolo)
			{
				SilentPEAKPlugin.modEnabled.Value = enabled;
				SilentPEAKPlugin.HandleModStateChanged();
			}
		}

		private void OnUsePeakFilterChanged(bool enabled)
		{
			if (SilentPeakRuntime.IsHostOrSolo)
			{
				SilentPEAKPlugin.usePeakFilter.Value = enabled;
				SilentPEAKPlugin.HandlePeakFilterSettingChanged();
			}
		}

		private void ShowTab(Tab tab)
		{
			if (!SilentPeakRuntime.IsHostOrSolo && (tab == Tab.Fog || tab == Tab.Filter))
			{
				tab = Tab.General;
			}
			_activeTab = tab;
			if ((Object)(object)_generalPage != (Object)null)
			{
				_generalPage.SetActive(tab == Tab.General);
			}
			if ((Object)(object)_fogPage != (Object)null)
			{
				_fogPage.SetActive(tab == Tab.Fog);
			}
			if ((Object)(object)_filterPage != (Object)null)
			{
				_filterPage.SetActive(tab == Tab.Filter);
			}
			if ((Object)(object)_keysPage != (Object)null)
			{
				_keysPage.SetActive(tab == Tab.Keys);
			}
			StyleTabButton(_generalTab, tab == Tab.General);
			StyleTabButton(_fogTab, tab == Tab.Fog);
			StyleTabButton(_filterTab, tab == Tab.Filter);
			StyleTabButton(_keysTab, tab == Tab.Keys);
		}

		private static void StyleTabButton(Button button, bool selected)
		{
			//IL_003a: 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)
			if (!((Object)(object)button == (Object)null))
			{
				Graphic targetGraphic = ((Selectable)button).targetGraphic;
				Image val = (Image)(((object)((targetGraphic is Image) ? targetGraphic : null)) ?? ((object)((Component)button).GetComponent<Image>()));
				if ((Object)(object)val != (Object)null)
				{
					((Graphic)val).color = (selected ? SilentPeakUi.AccentOn : SilentPeakUi.ButtonColor);
				}
			}
		}

		private void SyncFromConfig()
		{
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			_syncing = true;
			if (SilentPeakRuntime.IsHostOrSolo)
			{
				SilentPeakUi.SetToggleVisual(_enabledToggle, SilentPEAKPlugin.modEnabled.Value);
				SilentPeakUi.SetToggleVisual(_usePeakFilterToggle, SilentPEAKPlugin.usePeakFilter.Value);
				if ((Object)(object)_gloomSlider != (Object)null)
				{
					_gloomSlider.SetValueWithoutNotify(SilentPEAKPlugin.gloomSoften.Value);
				}
				if ((Object)(object)_gloomValue != (Object)null)
				{
					((TMP_Text)_gloomValue).text = FormatSliderValue(SilentPEAKPlugin.gloomSoften.Value, wholeNumbers: false);
				}
				if ((Object)(object)_heightFogSlider != (Object)null)
				{
					_heightFogSlider.SetValueWithoutNotify(SilentPEAKPlugin.heightFogHeightOffset.Value);
				}
				if ((Object)(object)_heightFogValue != (Object)null)
				{
					((TMP_Text)_heightFogValue).text = FormatSliderValue(SilentPEAKPlugin.heightFogHeightOffset.Value, wholeNumbers: true);
				}
				if ((Object)(object)_colorPicker != (Object)null)
				{
					_colorPicker.SetColor(SilentPEAKPlugin.GetFogColor(), notify: false);
				}
				if ((Object)(object)_pfIntensitySlider != (Object)null)
				{
					_pfIntensitySlider.SetValueWithoutNotify(SilentPEAKPlugin.peakFilterIntensity.Value);
				}
				if ((Object)(object)_pfPixelSlider != (Object)null)
				{
					_pfPixelSlider.SetValueWithoutNotify(SilentPEAKPlugin.peakFilterPixelSize.Value);
				}
				if ((Object)(object)_pfOutlineSlider != (Object)null)
				{
					_pfOutlineSlider.SetValueWithoutNotify(SilentPEAKPlugin.peakFilterOutlineStrength.Value);
				}
				if ((Object)(object)_pfDitherSlider != (Object)null)
				{
					_pfDitherSlider.SetValueWithoutNotify(SilentPEAKPlugin.peakFilterDitherAmount.Value);
				}
				if ((Object)(object)_pfIntensityValue != (Object)null)
				{
					((TMP_Text)_pfIntensityValue).text = FormatSliderValue(SilentPEAKPlugin.peakFilterIntensity.Value, wholeNumbers: false);
				}
				if ((Object)(object)_pfPixelValue != (Object)null)
				{
					((TMP_Text)_pfPixelValue).text = FormatSliderValue(SilentPEAKPlugin.peakFilterPixelSize.Value, wholeNumbers: false);
				}
				if ((Object)(object)_pfOutlineValue != (Object)null)
				{
					((TMP_Text)_pfOutlineValue).text = FormatSliderValue(SilentPEAKPlugin.peakFilterOutlineStrength.Value, wholeNumbers: false);
				}
				if ((Object)(object)_pfDitherValue != (Object)null)
				{
					((TMP_Text)_pfDitherValue).text = FormatSliderValue(SilentPEAKPlugin.peakFilterDitherAmount.Value, wholeNumbers: false);
				}
			}
			if ((Object)(object)_musicSlider != (Object)null)
			{
				_musicSlider.SetValueWithoutNotify(SilentPEAKPlugin.musicVolume.Value);
			}
			if ((Object)(object)_musicValue != (Object)null)
			{
				((TMP_Text)_musicValue).text = FormatSliderValue(SilentPEAKPlugin.musicVolume.Value, wholeNumbers: true);
			}
			if ((Object)(object)_menuKeyLabel != (Object)null)
			{
				((TMP_Text)_menuKeyLabel).text = FormatKey(SilentPEAKPlugin.menuKey.Value);
			}
			_syncing = false;
		}

		private void CaptureFrozenLook()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter?.data == (Object)null))
			{
				_frozenLookValues = localCharacter.data.lookValues;
				_hasFrozenLook = true;
			}
		}

		private void HoldFrozenLook()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (_hasFrozenLook)
			{
				Character localCharacter = Character.localCharacter;
				if (!((Object)(object)localCharacter?.data == (Object)null))
				{
					localCharacter.data.lookValues = _frozenLookValues;
				}
			}
		}

		private static void ApplyMenuInputBlock(bool block)
		{
			GUIManager instance = GUIManager.instance;
			if (!((Object)(object)instance == (Object)null) && block)
			{
				instance.windowBlockingInput = true;
				instance.windowShowingCursor = true;
			}
		}
	}
	internal sealed class SilentPeakNetworkSync : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		private const byte SubConfig = 1;

		private const byte SubConfigRequest = 2;

		private const float HostSyncTimeoutSeconds = 12f;

		private const float HostSyncRetrySeconds = 2f;

		private static SilentPeakNetworkSync _instance;

		private Coroutine _debounce;

		private Coroutine _hostSyncWatch;

		private void Awake()
		{
			_instance = this;
		}

		public override void OnEnable()
		{
			((MonoBehaviourPunCallbacks)this).OnEnable();
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		public override void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
			((MonoBehaviourPunCallbacks)this).OnDisable();
		}

		public override void OnJoinedRoom()
		{
			if (PhotonNetwork.IsMasterClient)
			{
				SilentPeakRuntime.OnJoinedRoom(isMaster: true);
				BroadcastNow();
			}
			else
			{
				SilentPeakRuntime.OnJoinedRoom(isMaster: false);
				RequestHostSync();
				RestartHostSyncWatch();
			}
		}

		public override void OnLeftRoom()
		{
			StopHostSyncWatch();
			SilentPeakRuntime.OnLeftRoom();
		}

		public void OnMasterClientSwitched(Player newMasterClient)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				SilentPeakRuntime.OnJoinedRoom(isMaster: true);
				BroadcastNow();
				StopHostSyncWatch();
			}
			else
			{
				SilentPeakRuntime.OnJoinedRoom(isMaster: false);
				RequestHostSync();
				RestartHostSyncWatch();
			}
		}

		public void OnPlayerEnteredRoom(Player newPlayer)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				((MonoBehaviour)this).StartCoroutine(BroadcastAfterDelay(0.5f));
			}
		}

		public void OnEvent(EventData e)
		{
			if (e?.Code != 195 || !(e.CustomData is object[] array) || array.Length < 2 || (int)array[0] != 201)
			{
				return;
			}
			byte b = (byte)array[1];
			if (b == 2 && PhotonNetwork.IsMasterClient)
			{
				Debug.Log((object)"[Silent PEAK] Client requested host config — broadcasting.");
				BroadcastNow();
			}
			else
			{
				if (b != 1 || array.Length < 11)
				{
					return;
				}
				try
				{
					SilentPeakRuntime.IsSyncingFromNet = true;
					StopHostSyncWatch();
					SilentPeakRuntime.ApplyNetworkSnapshot(Convert.ToBoolean(array[2]), Convert.ToBoolean(array[3]), Convert.ToString(array[4]), Convert.ToSingle(array[5]), Convert.ToSingle(array[6]), Convert.ToSingle(array[7]), Convert.ToSingle(array[8]), Convert.ToSingle(array[9]), Convert.ToSingle(array[10]));
					SilentPeakRuntime.OnHostSyncReceived();
					SilentPEAKPlugin.HandleModStateChanged();
					SilentPEAKPlugin.HandlePeakFilterSettingChanged();
					SilentPeakMenu.ResetFogColorField();
					Debug.Log((object)"[Silent PEAK] Host config sync applied.");
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[Silent PEAK] Config sync error: " + ex.Message));
				}
				finally
				{
					SilentPeakRuntime.IsSyncingFromNet = false;
				}
			}
		}

		internal static void ScheduleBroadcast()
		{
			if (!((Object)(object)_instance == (Object)null) && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				if (_instance._debounce != null)
				{
					((MonoBehaviour)_instance).StopCoroutine(_instance._debounce);
				}
				_instance._debounce = ((MonoBehaviour)_instance).StartCoroutine(_instance.DebounceBroadcast());
			}
		}

		internal static void RequestHostSync()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				Debug.Log((object)"[Silent PEAK] Requesting host config sync.");
				PhotonNetwork.RaiseEvent((byte)195, (object)new object[2]
				{
					201,
					(byte)2
				}, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)2
				}, SendOptions.SendReliable);
			}
		}

		internal static void RestartClientSyncWatch()
		{
			_instance?.RestartHostSyncWatch();
		}

		internal static void OnAfterSceneLoad(string sceneName)
		{
			if (!PhotonNetwork.InRoom)
			{
				return;
			}
			if (PhotonNetwork.IsMasterClient)
			{
				if (sceneName.Contains("Level_"))
				{
					ScheduleBroadcast();
				}
			}
			else if (sceneName.Contains("Level_"))
			{
				if (SilentPeakRuntime.VanillaHostMode)
				{
					SilentPeakRuntime.PrepareClientSyncRetry();
				}
				RequestHostSync();
				RestartClientSyncWatch();
			}
		}

		private void RestartHostSyncWatch()
		{
			StopHostSyncWatch();
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				_hostSyncWatch = ((MonoBehaviour)this).StartCoroutine(WatchForHostSync());
			}
		}

		private void StopHostSyncWatch()
		{
			if (_hostSyncWatch != null)
			{
				((MonoBehaviour)this).StopCoroutine(_hostSyncWatch);
				_hostSyncWatch = null;
			}
		}

		private IEnumerator WatchForHostSync()
		{
			float elapsed = 0f;
			float nextRetry = 2f;
			while (elapsed < 12f)
			{
				if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient || SilentPeakRuntime.HostModConfirmed)
				{
					yield break;
				}
				elapsed += Time.unscaledDeltaTime;
				if (elapsed >= nextRetry)
				{
					RequestHostSync();
					nextRetry += 2f;
				}
				yield return null;
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !SilentPeakRuntime.HostModConfirmed)
			{
				Debug.LogWarning((object)"[Silent PEAK] Host does not appear to have Silent PEAK — disabling mod effects.");
				SilentPeakRuntime.OnHostModMissing();
			}
			_hostSyncWatch = null;
		}

		private IEnumerator DebounceBroadcast()
		{
			yield return (object)new WaitForSeconds(0.25f);
			BroadcastNow();
			_debounce = null;
		}

		private IEnumerator BroadcastAfterDelay(float seconds)
		{
			yield return (object)new WaitForSeconds(seconds);
			BroadcastNow();
		}

		private static void BroadcastNow()
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				SilentPeakRuntime.RefreshFromLocalConfig();
				object[] array = new object[11]
				{
					201,
					(byte)1,
					SilentPEAKPlugin.modEnabled.Value,
					SilentPEAKPlugin.usePeakFilter.Value,
					SilentPEAKPlugin.deepFogColorHex.Value,
					SilentPEAKPlugin.gloomSoften.Value,
					SilentPEAKPlugin.heightFogHeightOffset.Value,
					SilentPEAKPlugin.peakFilterIntensity.Value,
					SilentPEAKPlugin.peakFilterPixelSize.Value,
					SilentPEAKPlugin.peakFilterOutlineStrength.Value,
					SilentPEAKPlugin.peakFilterDitherAmount.Value
				};
				PhotonNetwork.RaiseEvent((byte)195, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
				Debug.Log((object)"[Silent PEAK] Broadcast host config to clients.");
			}
		}
	}
	internal static class SilentPeakRuntime
	{
		internal static bool HostModConfirmed;

		internal static bool VanillaHostMode;

		internal static bool IsSyncingFromNet;

		internal static bool SyncedModEnabled = true;

		internal static bool SyncedUsePeakFilter = true;

		internal static string SyncedDeepFogColorHex = "#FFFFFF";

		internal static float SyncedGloomSoften = 0f;

		internal static float SyncedHeightFogHeightOffset = 1000f;

		internal static float SyncedPeakFilterIntensity = 1f;

		internal static float SyncedPeakFilterPixelSize = 10f;

		internal static float SyncedPeakFilterOutlineStrength = 0f;

		internal static float SyncedPeakFilterDitherAmount = 0f;

		internal static bool IsHostOrSolo => !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;

		internal static bool IsAwaitingHostSync => PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !HostModConfirmed && !VanillaHostMode;

		internal static bool ShouldApplyModEffects()
		{
			if (VanillaHostMode)
			{
				return false;
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !HostModConfirmed)
			{
				return false;
			}
			return SilentPEAKPlugin.GetModEnabled();
		}

		internal static bool CanOpenMenu()
		{
			return !VanillaHostMode;
		}

		internal static void OnJoinedRoom(bool isMaster)
		{
			VanillaHostMode = false;
			HostModConfirmed = isMaster;
			if (isMaster)
			{
				RefreshFromLocalConfig();
			}
		}

		internal static void OnHostSyncReceived()
		{
			HostModConfirmed = true;
			VanillaHostMode = false;
		}

		internal static void OnLeftRoom()
		{
			HostModConfirmed = false;
			VanillaHostMode = false;
			RefreshFromLocalConfig();
			SilentPEAKPlugin.HandleModStateChanged();
		}

		internal static void PrepareClientSyncRetry()
		{
			VanillaHostMode = false;
			HostModConfirmed = false;
		}

		internal static void OnHostModMissing()
		{
			HostModConfirmed = false;
			VanillaHostMode = true;
			RestoreVanillaEffects();
		}

		internal static void ApplyNetworkSnapshot(bool modEnabled, bool usePeakFilter, string deepFogColorHex, float gloomSoften, float heightFogHeightOffset, float peakFilterIntensity, float peakFilterPixelSize, float peakFilterOutlineStrength, float peakFilterDitherAmount)
		{
			SyncedModEnabled = modEnabled;
			SyncedUsePeakFilter = usePeakFilter;
			SyncedDeepFogColorHex = deepFogColorHex ?? "#FFFFFF";
			SyncedGloomSoften = gloomSoften;
			SyncedHeightFogHeightOffset = heightFogHeightOffset;
			SyncedPeakFilterIntensity = peakFilterIntensity;
			SyncedPeakFilterPixelSize = peakFilterPixelSize;
			SyncedPeakFilterOutlineStrength = peakFilterOutlineStrength;
			SyncedPeakFilterDitherAmount = peakFilterDitherAmount;
		}

		internal static void RefreshFromLocalConfig()
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
			{
				SyncedModEnabled = SilentPEAKPlugin.modEnabled.Value;
				SyncedUsePeakFilter = SilentPEAKPlugin.usePeakFilter.Value;
				SyncedDeepFogColorHex = SilentPEAKPlugin.deepFogColorHex.Value;
				SyncedGloomSoften = SilentPEAKPlugin.gloomSoften.Value;
				SyncedHeightFogHeightOffset = SilentPEAKPlugin.heightFogHeightOffset.Value;
				SyncedPeakFilterIntensity = SilentPEAKPlugin.peakFilterIntensity.Value;
				SyncedPeakFilterPixelSize = SilentPEAKPlugin.peakFilterPixelSize.Value;
				SyncedPeakFilterOutlineStrength = SilentPEAKPlugin.peakFilterOutlineStrength.Value;
				SyncedPeakFilterDitherAmount = SilentPEAKPlugin.peakFilterDitherAmount.Value;
			}
		}

		internal static void RestoreVanillaEffects()
		{
			SilentPEAKPlugin.StopMusic();
			PeakFilterIntegration.DisableIfAppliedByUs();
			PostFogController.Disable(null);
			SilentPEAKPlugin.HandleModStateChanged();
			SilentPeakMenu.Close();
		}
	}
	internal static class SilentPeakUi
	{
		internal static readonly Color PanelColor = new Color(0.08f, 0.06f, 0.05f, 0.94f);

		internal static readonly Color ButtonColor = new Color(0.1792453f, 0.1253449f, 0.09046815f, 62f / 85f);

		internal static readonly Color ButtonHover = new Color(0.26f, 0.18f, 0.13f, 0.92f);

		internal static readonly Color Cream = new Color(0.95f, 0.93f, 0.88f, 1f);

		internal static readonly Color CreamDim = new Color(0.82f, 0.78f, 0.72f, 0.92f);

		internal static readonly Color AccentOn = new Color(0.55f, 0.42f, 0.22f, 0.95f);

		private static readonly Color CheckboxWellColor = new Color(0.1f, 0.08f, 0.06f, 0.92f);

		private static Sprite _whiteSprite;

		private static GameObject _buttonDonor;

		private static TMP_FontAsset _cachedFont;

		private static int _cachedSceneHandle = -1;

		internal static Canvas CreateOverlayCanvas(GameObject root, int sortingOrder)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Canvas val = root.GetComponent<Canvas>() ?? root.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = sortingOrder;
			val.additionalShaderChannels = (AdditionalCanvasShaderChannels)25;
			CanvasScaler val2 = root.GetComponent<CanvasScaler>() ?? root.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 1f;
			if ((Object)(object)root.GetComponent<GraphicRaycaster>() == (Object)null)
			{
				root.AddComponent<GraphicRaycaster>();
			}
			return val;
		}

		internal static RectTransform CreatePanel(Transform parent, string name, Vector2 size, Color color)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component.anchorMax = val2;
			component.anchorMin = val2;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = size;
			Image component2 = val.GetComponent<Image>();
			component2.sprite = WhiteSprite();
			component2.type = (Type)1;
			((Graphic)component2).color = color;
			((Graphic)component2).raycastTarget = true;
			return component;
		}

		internal static TextMeshProUGUI CreateLabel(Transform parent, string name, string text, float fontSize, FontStyles style = (FontStyles)0, TextAlignmentOptions align = (TextAlignmentOptions)513)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).text = text ?? string.Empty;
			((TMP_Text)val2).fontSize = fontSize;
			((TMP_Text)val2).fontStyle = style;
			((TMP_Text)val2).alignment = align;
			((Graphic)val2).color = Cream;
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).enableWordWrapping = false;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((MaskableGraphic)val2).maskable = true;
			ApplyFont(val2);
			return val2;
		}

		internal static LayoutElement MakeNonCollapsing(GameObject go, float height, float minWidth = 0f)
		{
			LayoutElement val = go.GetComponent<LayoutElement>() ?? go.AddComponent<LayoutElement>();
			val.minHeight = height;
			val.preferredHeight = height;
			val.flexibleHeight = 0f;
			if (minWidth > 0f)
			{
				val.minWidth = minWidth;
				if (val.preferredWidth < minWidth)
				{
					val.preferredWidth = minWidth;
				}
			}
			return val;
		}

		internal static Button CreateButton(Transform parent, string label, UnityAction onClick, Vector2 preferredSize)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = TryClonePauseButton(parent, label) ?? CreatePlainButtonObject(parent, label);
			ApplyButtonSize(val, preferredSize);
			TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = label;
				((TMP_Text)componentInChildren).fontStyle = (FontStyles)0;
				((TMP_Text)componentInChildren).enableAutoSizing = true;
				((TMP_Text)componentInChildren).fontSizeMin = 12f;
				((TMP_Text)componentInChildren).fontSizeMax = 20f;
				((Graphic)componentInChildren).color = Cream;
				ApplyFont(componentInChildren);
			}
			Button val2 = val.GetComponent<Button>() ?? val.AddComponent<Button>();
			((UnityEventBase)val2.onClick).RemoveAllListeners();
			if (onClick != null)
			{
				((UnityEvent)val2.onClick).AddListener(onClick);
			}
			return val2;
		}

		internal static Button CreatePlainButton(Transform parent, string label, UnityAction onClick, Vector2 preferredSize)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreatePlainButtonObject(parent, label);
			ApplyButtonSize(val, preferredSize);
			TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = label ?? string.Empty;
				ApplyFont(componentInChildren);
			}
			Button component = val.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			if (onClick != null)
			{
				((UnityEvent)component.onClick).AddListener(onClick);
			}
			return component;
		}

		internal static Image CreateSwatch(Transform parent, Color color, UnityAction onClick, Vector2 size)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Swatch", new Type[4]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image),
				typeof(Button)
			});
			val.transform.SetParent(parent, false);
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.minWidth = size.x;
			val2.preferredWidth = size.x;
			val2.minHeight = size.y;
			val2.preferredHeight = size.y;
			Image component = val.GetComponent<Image>();
			component.sprite = WhiteSprite();
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = true;
			Button component2 = val.GetComponent<Button>();
			((UnityEvent)component2.onClick).AddListener(onClick);
			return component;
		}

		internal static GameObject ShowOptionList(Transform parent, string[] options, int selected, Action<int> onPicked)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			if ((Object)(object)parent == (Object)null || options == null || options.Length == 0)
			{
				return null;
			}
			Transform val = parent.Find("OptionList");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			GameObject go = new GameObject("OptionList", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			go.transform.SetParent(parent, false);
			go.transform.SetAsLastSibling();
			RectTransform component = go.GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component.anchorMax = val2;
			component.anchorMin = val2;
			component.sizeDelta = new Vector2(280f, Mathf.Min(520f, 48f + (float)options.Length * 34f));
			go.GetComponent<Image>().sprite = WhiteSprite();
			((Graphic)go.GetComponent<Image>()).color = PanelColor;
			AddVerticalLayout(go, 4f, new RectOffset(10, 10, 10, 10));
			TextMeshProUGUI val3 = CreateLabel(go.transform, "Title", "Pick one", 16f, (FontStyles)0, (TextAlignmentOptions)514);
			MakeNonCollapsing(((Component)val3).gameObject, 22f);
			RectTransform content;
			ScrollRect val4 = CreateScrollView(go.transform, out content);
			LayoutElement val5 = ((Component)val4).gameObject.AddComponent<LayoutElement>();
			val5.flexibleHeight = 1f;
			val5.minHeight = 120f;
			AddVerticalLayout(((Component)content).gameObject, 4f, new RectOffset(4, 4, 4, 4));
			ContentSizeFitter val6 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
			val6.verticalFit = (FitMode)2;
			for (int i = 0; i < options.Length; i++)
			{
				int index = i;
				string text = options[i];
				if (index == selected)
				{
					text = "> " + text;
				}
				CreatePlainButton((Transform)(object)content, text, (UnityAction)delegate
				{
					onPicked?.Invoke(index);
					Object.Destroy((Object)(object)go);
				}, new Vector2(240f, 30f));
			}
			CreatePlainButton(go.transform, "Cancel", (UnityAction)delegate
			{
				Object.Destroy((Object)(object)go);
			}, new Vector2(120f, 30f));
			return go;
		}

		internal static Toggle CreateToggle(Transform parent, string label, bool isOn, UnityAction<bool> onChanged, float height = 28f, bool highContrast = false)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Toggle_" + Sanitize(label), new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.minHeight = height;
			val2.preferredHeight = height;
			val2.flexibleWidth = 1f;
			HorizontalLayoutGroup val3 = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val3).spacing = 8f;
			((LayoutGroup)val3).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)val3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val3).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val3).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val3).childForceExpandWidth = false;
			((LayoutGroup)val3).padding = new RectOffset(4, 4, 2, 2);
			Color well = (Color)(highContrast ? new Color(0.32f, 0.26f, 0.18f, 1f) : CheckboxWellColor);
			Color check = (Color)(highContrast ? new Color(1f, 0.92f, 0.28f, 1f) : Cream);
			float num = (highContrast ? 26f : 22f);
			float num2 = (highContrast ? 3f : 5f);
			GameObject val4 = new GameObject("Box", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val4.transform.SetParent(val.transform, false);
			Image boxImg = val4.GetComponent<Image>();
			boxImg.sprite = WhiteSprite();
			((Graphic)boxImg).color = well;
			LayoutElement val5 = val4.AddComponent<LayoutElement>();
			val5.preferredWidth = num;
			val5.preferredHeight = num;
			val5.minWidth = num;
			val5.minHeight = num;
			GameObject val6 = new GameObject("Check", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val6.transform.SetParent(val4.transform, false);
			Stretch(val6.GetComponent<RectTransform>(), num2, num2);
			Image checkImg = val6.GetComponent<Image>();
			checkImg.sprite = WhiteSprite();
			((Graphic)checkImg).color = check;
			((Graphic)checkImg).raycastTarget = false;
			TextMeshProUGUI val7 = CreateLabel(val.transform, "Label", label, highContrast ? 15f : 16f, (FontStyles)0, (TextAlignmentOptions)513);
			if (highContrast)
			{
				((TMP_Text)val7).fontStyle = (FontStyles)1;
			}
			LayoutElement val8 = ((Component)val7).gameObject.AddComponent<LayoutElement>();
			val8.flexibleWidth = 1f;
			val8.minHeight = height - 4f;
			val8.preferredHeight = height - 4f;
			Toggle val9 = val.AddComponent<Toggle>();
			((Selectable)val9).targetGraphic = (Graphic)(object)boxImg;
			val9.graphic = (Graphic)(object)checkImg;
			val9.SetIsOnWithoutNotify(isOn);
			((Behaviour)checkImg).enabled = true;
			((Graphic)checkImg).canvasRenderer.SetAlpha(isOn ? 1f : 0f);
			((UnityEvent<bool>)(object)val9.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				((Graphic)boxImg).color = well;
				((Graphic)checkImg).color = check;
				((Behaviour)checkImg).enabled = true;
				((Graphic)c