Decompiled source of ConfigurableWarning v1.15.2

RedstoneWizard08.ConfigurableWarning.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using ConfigurableWarning;
using ConfigurableWarning.API;
using ConfigurableWarning.API.Attributes;
using ConfigurableWarning.API.Compat;
using ConfigurableWarning.API.Options;
using ContentSettings.API;
using ContentSettings.API.Attributes;
using ContentSettings.API.Settings;
using ContentSettings.API.Settings.DebugUI;
using ContentSettings.API.Settings.UI;
using ContentSettings.Internal;
using CurvedUI;
using Flashcard;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
using Newtonsoft.Json;
using Photon.Pun;
using Spookdivers;
using Steamworks;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Virality;
using Zorro.Core;
using Zorro.Settings;
using Zorro.Settings.DebugUI;
using pworld.Scripts.Extensions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("cheese.spookdivers-publicized")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[assembly: IgnoresAccessChecksTo("MaxWasUnavailable.Virality-publicized")]
[assembly: IgnoresAccessChecksTo("me.loaforc.Flashcard-publicized")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("pworld")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Unity.Localization")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("Zorro.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.Settings.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.UI.Runtime")]
[assembly: AssemblyCompany("RedstoneWizard08")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Makes the game configurable!")]
[assembly: AssemblyFileVersion("1.14.0.0")]
[assembly: AssemblyInformationalVersion("1.14.0+72844d0573a3acae9bbc136254c0b693772ada90")]
[assembly: AssemblyProduct("RedstoneWizard08.ConfigurableWarning")]
[assembly: AssemblyTitle("RedstoneWizard08.ConfigurableWarning")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/RedstoneWizard08/ConfigurableWarning")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.14.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ContentSetings
{
	public static class CSPluginInfo
	{
		public const string PLUGIN_GUID = "CommanderCat101.ContentSettings";

		public const string PLUGIN_NAME = "CommanderCat101.ContentSettings";
	}
}
namespace ContentSettings
{
	[ContentWarningPlugin("CommanderCat101.ContentSettings", "1.14.0", true)]
	[BepInPlugin("CommanderCat101.ContentSettings", "CommanderCat101.ContentSettings", "1.14.0")]
	public class ContentSettings : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			SettingsAssets.LoadAssets();
		}

		private void Update()
		{
			SettingsLoader.Update();
		}
	}
}
namespace ContentSettings.Internal
{
	internal static class SettingsAssets
	{
		internal const string BundlePath = "contentsettings.bundle";

		internal static GameObject SettingsNavigationPrefab { get; private set; } = null;


		internal static GameObject SettingsTabPrefab { get; private set; } = null;


		internal static GameObject SettingsCategoryPrefab { get; private set; } = null;


		internal static GameObject SettingsTextInputPrefab { get; private set; } = null;


		internal static GameObject SettingsIntInputPrefab { get; private set; } = null;


		internal static GameObject SettingsBoolInputPrefab { get; private set; } = null;


		private static Dictionary<string, AssetBundle> AssetBundles { get; } = new Dictionary<string, AssetBundle>();


		internal static void LoadAssets()
		{
			SettingsNavigationPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsNavigation.prefab");
			SettingsTabPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsTab.prefab");
			SettingsCategoryPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsCategory.prefab");
			SettingsTextInputPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsTextInput.prefab");
			SettingsIntInputPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsIntInput.prefab");
			SettingsBoolInputPrefab = LoadAsset<GameObject>("contentsettings.bundle", "Assets/ContentSettings/SettingsBoolInput.prefab");
		}

		private static T LoadAsset<T>(string bundleName, string assetName) where T : Object
		{
			ContentSettings.Logger.LogDebug((object)("Loading asset '" + assetName + "' from asset bundle '" + bundleName + "'."));
			if (AssetBundles.TryGetValue(bundleName, out AssetBundle value))
			{
				return value.LoadAsset<T>(assetName);
			}
			Stream manifestResourceStream = typeof(ContentSettings).Assembly.GetManifestResourceStream(typeof(global::ConfigurableWarning.ConfigurableWarning).Namespace + "." + bundleName);
			if (manifestResourceStream == null)
			{
				throw new Exception("Failed to load asset bundle '" + bundleName + "' from embedded resource.");
			}
			using (manifestResourceStream)
			{
				AssetBundle val = AssetBundle.LoadFromStream(manifestResourceStream);
				if ((Object)(object)val == (Object)null)
				{
					throw new Exception("Failed to load asset bundle '" + bundleName + "' from stream.");
				}
				T val2 = val.LoadAsset<T>(assetName);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new Exception("Failed to load asset '" + assetName + "' from asset bundle '" + bundleName + "'.");
				}
				ContentSettings.Logger.LogDebug((object)("Loaded asset '" + assetName + "' from asset bundle '" + bundleName + "'."));
				AssetBundles.Add(bundleName, val);
				return val2;
			}
		}
	}
	internal static class SettingsMapper
	{
		private static GameObject? _textSettingCell;

		private static GameObject? _intSettingCell;

		private static GameObject? _boolSettingCell;

		public static GameObject TextSettingCell
		{
			get
			{
				if ((Object)(object)_textSettingCell == (Object)null)
				{
					_textSettingCell = SettingsAssets.SettingsTextInputPrefab;
				}
				if ((Object)(object)_textSettingCell.GetComponent<TextSettingUI>() == (Object)null)
				{
					_textSettingCell.AddComponent<TextSettingUI>();
				}
				return _textSettingCell;
			}
		}

		public static GameObject IntSettingCell
		{
			get
			{
				if ((Object)(object)_intSettingCell == (Object)null)
				{
					_intSettingCell = SettingsAssets.SettingsIntInputPrefab;
				}
				if ((Object)(object)_intSettingCell.GetComponent<IntSettingUI>() == (Object)null)
				{
					_intSettingCell.AddComponent<IntSettingUI>();
				}
				return _intSettingCell;
			}
		}

		public static GameObject BoolSettingCell
		{
			get
			{
				if ((Object)(object)_boolSettingCell == (Object)null)
				{
					_boolSettingCell = SettingsAssets.SettingsBoolInputPrefab;
				}
				if ((Object)(object)_boolSettingCell.GetComponent<BoolSettingUI>() == (Object)null)
				{
					_boolSettingCell.AddComponent<BoolSettingUI>();
				}
				return _boolSettingCell;
			}
		}
	}
	[HarmonyPatch]
	internal class SettingsPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(DefaultSettingsSaveLoad), "WriteToDisk")]
		internal static void WriteToDiskPatch()
		{
			SettingsLoader.SaveSettings();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingsMenu), "OnEnable")]
		internal static bool OnEnablePatch(SettingsMenu __instance)
		{
			GameBooter.Initialize();
			ContentSettings.Logger.LogInfo((object)$"Has game booted: {GameBooter.Initialized}");
			SettingsLoader.RegisterSettings();
			SettingsLoader.CreateSettingsMenu(__instance);
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(MainMenuHandler), "Start")]
		internal static bool MainMenuHandlerStartPatch(MainMenuHandler __instance)
		{
			SettingsLoader.RegisterSettings();
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SFX_Instance), "Play")]
		internal static bool PlayPatch(SFX_Instance __instance)
		{
			if ((Object)(object)__instance.settings.mixerGroup != (Object)(object)SingletonAsset<MixerHolder>.Instance.sfxMixer)
			{
				ContentSettings.Logger.LogDebug((object)("Changing mixer group for " + ((Object)__instance).name));
			}
			__instance.settings.mixerGroup = SingletonAsset<MixerHolder>.Instance.sfxMixer;
			return true;
		}
	}
}
namespace ContentSettings.API
{
	public static class SettingsLoader
	{
		[UsedImplicitly]
		public static IEnumerable<Setting> Settings => RegisteredSettings.Values;

		private static DefaultSettingsSaveLoad SaveLoader { get; } = new DefaultSettingsSaveLoad();


		private static Dictionary<string, Dictionary<string, List<Setting>>> SettingsByCategoryByTab { get; set; } = new Dictionary<string, Dictionary<string, List<Setting>>>();


		private static Dictionary<Type, Setting> RegisteredSettings { get; } = new Dictionary<Type, Setting>();


		private static bool IsInitialized { get; set; }

		private static bool IsDirty { get; set; }

		private static SettingsNavigation? SettingsNavigation { get; set; }

		[UsedImplicitly]
		public static bool HasTab(string tab)
		{
			return SettingsByCategoryByTab.ContainsKey(tab);
		}

		public static bool TryGetTab(string tab, out Dictionary<string, List<Setting>> settingsByCategory)
		{
			return SettingsByCategoryByTab.TryGetValue(tab, out settingsByCategory);
		}

		public static T? GetSetting<T>() where T : Setting
		{
			if (RegisteredSettings.TryGetValue(typeof(T), out Setting value))
			{
				return (T)(object)value;
			}
			return default(T);
		}

		[UsedImplicitly]
		public static void RegisterSetting(string tab, string? category, Setting setting)
		{
			if (category == null)
			{
				category = string.Empty;
			}
			Type type = ((object)setting).GetType();
			ContentSettings.Logger.LogDebug((object)("Registering setting " + type.Name + "(" + type.BaseType?.Name + ") to tab " + tab + " and category " + category + "."));
			Dictionary<string, List<Setting>> valueOrDefault = SettingsByCategoryByTab.GetValueOrDefault(tab, new Dictionary<string, List<Setting>>());
			List<Setting> list = (valueOrDefault[category] = valueOrDefault.GetValueOrDefault(category, new List<Setting>()));
			SettingsByCategoryByTab[tab] = valueOrDefault;
			list.Add(setting);
			if (!RegisteredSettings.ContainsKey(type))
			{
				setting.Load((ISettingsSaveLoad)(object)SaveLoader);
				setting.ApplyValue();
				RegisteredSettings.Add(type, setting);
			}
			if (IsInitialized)
			{
				IsDirty = true;
			}
		}

		[UsedImplicitly]
		public static void RegisterSetting(string tab, Setting setting)
		{
			RegisterSetting(tab, string.Empty, setting);
		}

		[UsedImplicitly]
		public static void RegisterSetting(Setting setting)
		{
			RegisterSetting("MODDED", string.Empty, setting);
		}

		internal static void SaveSettings()
		{
			ContentSettings.Logger.LogDebug((object)"Saving settings to disk.");
			foreach (Setting setting in Settings)
			{
				setting.Save((ISettingsSaveLoad)(object)SaveLoader);
			}
		}

		internal static void CreateSettingsMenu(SettingsMenu menu)
		{
			ContentSettings.Logger.LogDebug((object)"Initializing settings.");
			Transform obj = ((Component)menu).transform.Find("Content");
			Transform val = ((obj != null) ? obj.Find("TABS") : null);
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Failed to find settings tab.");
			}
			if ((Object)(object)SettingsNavigation == (Object)null)
			{
				SettingsNavigation settingsNavigation = ((Component)TransformExtensions.FindChildRecursive(Object.Instantiate<GameObject>(SettingsAssets.SettingsNavigationPrefab, val.parent, false).transform, "Content")).gameObject.AddComponent<SettingsNavigation>();
				foreach (string key in SettingsByCategoryByTab.Keys)
				{
					settingsNavigation.Create(key);
				}
				SettingsNavigation = settingsNavigation;
			}
			((Component)val).gameObject.SetActive(false);
		}

		internal static void RegisterSettings()
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			if (IsInitialized)
			{
				return;
			}
			RegisterDefaultSettings();
			ContentSettings.Logger.LogDebug((object)"Registering settings.");
			foreach (Type item in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes()))
			{
				if (item.IsAbstract || item.IsInterface || !item.IsSubclassOf(typeof(Setting)) || RegisteredSettings.ContainsKey(item))
				{
					continue;
				}
				IEnumerable<SettingRegister> customAttributes = item.GetCustomAttributes<SettingRegister>(inherit: false);
				Setting val = null;
				foreach (SettingRegister item2 in customAttributes)
				{
					if (val == null)
					{
						val = (Setting)Activator.CreateInstance(item);
					}
					RegisterSetting(item2.Tab, item2.Category, val);
				}
			}
			ContentSettings.Logger.LogDebug((object)$"Registered {RegisteredSettings.Count} settings.");
			IsInitialized = true;
		}

		internal static void Update()
		{
			foreach (Setting setting in Settings)
			{
				setting.Update();
			}
		}

		private static void RegisterDefaultSettings()
		{
			//IL_0064: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			ContentSettings.Logger.LogDebug((object)"Registering default settings.");
			Dictionary<string, Dictionary<string, List<Setting>>> settingsByCategoryByTab = SettingsByCategoryByTab;
			SettingsByCategoryByTab = new Dictionary<string, Dictionary<string, List<Setting>>>();
			SettingsHandler settingsHandler = GameHandler.Instance.SettingsHandler;
			ContentSettings.Logger.LogInfo((object)$"SettingsHandler is null: {settingsHandler == null}");
			foreach (SettingCategory value in Enum.GetValues(typeof(SettingCategory)))
			{
				SettingCategory val = value;
				foreach (Setting setting in settingsHandler.GetSettings(val))
				{
					RegisterSetting(((object)(SettingCategory)(ref val)).ToString().ToUpper(), setting);
				}
			}
			foreach (string item in settingsByCategoryByTab.Keys.Where((string tab) => !SettingsByCategoryByTab.ContainsKey(tab)))
			{
				SettingsByCategoryByTab.Add(item, settingsByCategoryByTab[item]);
			}
		}
	}
}
namespace ContentSettings.API.Settings
{
	public abstract class BoolSetting : Setting
	{
		public bool Value { get; protected set; }

		public override void Load(ISettingsSaveLoad loader)
		{
			int num = default(int);
			Value = (loader.TryLoadInt(((object)this).GetType(), ref num) ? (num != 0) : GetDefaultValue());
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			saver.SaveInt(((object)this).GetType(), Value ? 1 : 0);
		}

		public void SetValue(bool newValue, ISettingHandler settingHandler)
		{
			Value = newValue;
			((Setting)this).ApplyValue();
			settingHandler.SaveSetting((Setting)(object)this);
		}

		public override GameObject GetSettingUICell()
		{
			return SettingsMapper.BoolSettingCell;
		}

		public override SettingUI GetDebugUI(ISettingHandler settingHandler)
		{
			return (SettingUI)(object)new BoolSettingsUI(this, settingHandler);
		}

		public virtual string Expose(bool value)
		{
			return value.ToString();
		}

		public abstract bool GetDefaultValue();
	}
	public class BoolSettingUI : SettingInputUICell
	{
		[SerializeField]
		private Toggle? toggle;

		public override void Setup(Setting setting, ISettingHandler settingHandler)
		{
			ISettingHandler settingHandler2 = settingHandler;
			BoolSetting boolSetting = setting as BoolSetting;
			if (boolSetting != null && !((Object)(object)toggle == (Object)null))
			{
				toggle.isOn = boolSetting.Value;
				((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)OnToggleChanged);
			}
			void OnToggleChanged(bool value)
			{
				boolSetting.SetValue(value, settingHandler2);
			}
		}

		private void Awake()
		{
			toggle = ((Component)this).GetComponentInChildren<Toggle>();
		}
	}
	[UsedImplicitly]
	public interface ICustomSetting : IExposedSetting
	{
		SettingCategory IExposedSetting.GetSettingCategory()
		{
			return (SettingCategory)2;
		}
	}
	public abstract class IntSetting : Setting
	{
		public int Value { get; set; }

		public int MinValue { get; private set; }

		public int MaxValue { get; private set; }

		public override void Load(ISettingsSaveLoad loader)
		{
			(int, int) minMaxValue = GetMinMaxValue();
			int item = minMaxValue.Item1;
			int item2 = minMaxValue.Item2;
			MinValue = item;
			MaxValue = item2;
			int num = default(int);
			Value = Clamp(loader.TryLoadInt(((object)this).GetType(), ref num) ? num : GetDefaultValue());
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			saver.SaveInt(((object)this).GetType(), Value);
		}

		public void SetValue(int newValue, ISettingHandler settingHandler)
		{
			Value = Clamp(newValue);
			((Setting)this).ApplyValue();
			settingHandler.SaveSetting((Setting)(object)this);
		}

		public override SettingUI GetDebugUI(ISettingHandler settingHandler)
		{
			return (SettingUI)(object)new IntSettingsUI(this, settingHandler);
		}

		public override GameObject GetSettingUICell()
		{
			return SettingsMapper.IntSettingCell;
		}

		[UsedImplicitly]
		public virtual string Expose(int value)
		{
			return value.ToString();
		}

		[UsedImplicitly]
		public virtual int Clamp(int value)
		{
			return Mathf.Clamp(value, MinValue, MaxValue);
		}

		public abstract int GetDefaultValue();

		protected abstract (int, int) GetMinMaxValue();
	}
	public class IntSettingUI : SettingInputUICell
	{
		[SerializeField]
		private TMP_InputField? inputField;

		[SerializeField]
		private Slider? slider;

		public override void Setup(Setting setting, ISettingHandler settingHandler)
		{
			ISettingHandler settingHandler2 = settingHandler;
			IntSetting intSetting = setting as IntSetting;
			if (intSetting != null && !((Object)(object)inputField == (Object)null) && !((Object)(object)slider == (Object)null))
			{
				slider.maxValue = intSetting.MaxValue;
				slider.minValue = intSetting.MinValue;
				inputField.SetTextWithoutNotify(intSetting.Expose(intSetting.Value));
				slider.SetValueWithoutNotify((float)intSetting.Value);
				((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)OnInputChanged);
				((UnityEvent<string>)(object)inputField.onDeselect).AddListener((UnityAction<string>)delegate
				{
					OnInputChanged(inputField.text);
				});
				((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)OnSliderChanged);
			}
			void OnInputChanged(string value)
			{
				if (int.TryParse(value, out var result))
				{
					intSetting.SetValue(result, settingHandler2);
					inputField.SetTextWithoutNotify(intSetting.Expose(result));
					slider.SetValueWithoutNotify((float)result);
				}
			}
			void OnSliderChanged(float value)
			{
				intSetting.SetValue((int)value, settingHandler2);
				inputField.SetTextWithoutNotify(intSetting.Expose(intSetting.Value));
				slider.SetValueWithoutNotify((float)intSetting.Value);
			}
		}

		private void Awake()
		{
			inputField = ((Component)this).GetComponentInChildren<TMP_InputField>();
			slider = ((Component)this).GetComponentInChildren<Slider>();
		}
	}
	public abstract class TextSetting : Setting
	{
		public string Value { get; protected set; } = string.Empty;


		public override void Load(ISettingsSaveLoad loader)
		{
			string text = default(string);
			Value = (loader.TryGetString(((object)this).GetType(), ref text) ? text : GetDefaultValue());
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			saver.SaveString(((object)this).GetType(), Value);
		}

		public void SetValue(string newValue, ISettingHandler settingHandler)
		{
			Value = newValue;
			((Setting)this).ApplyValue();
			settingHandler.SaveSetting((Setting)(object)this);
		}

		public override GameObject GetSettingUICell()
		{
			return SettingsMapper.TextSettingCell;
		}

		public override SettingUI GetDebugUI(ISettingHandler settingHandler)
		{
			return (SettingUI)(object)new TextSettingsUI(this, settingHandler);
		}

		public virtual string Expose(string value)
		{
			return value;
		}

		public abstract string GetDefaultValue();
	}
	public class TextSettingUI : SettingInputUICell
	{
		[SerializeField]
		private TMP_InputField? inputField;

		public override void Setup(Setting setting, ISettingHandler settingHandler)
		{
			ISettingHandler settingHandler2 = settingHandler;
			TextSetting textSetting = setting as TextSetting;
			if (textSetting != null && !((Object)(object)inputField == (Object)null))
			{
				inputField.SetTextWithoutNotify(textSetting.Expose(textSetting.Value));
				((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)OnInputChanged);
			}
			void OnInputChanged(string value)
			{
				inputField.SetTextWithoutNotify(value);
				textSetting.SetValue(value, settingHandler2);
			}
		}

		private void Awake()
		{
			inputField = ((Component)this).GetComponentInChildren<TMP_InputField>();
		}
	}
}
namespace ContentSettings.API.Settings.UI
{
	public class SettingsButton : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		[SerializeField]
		private TextMeshProUGUI? textMeshPro;

		[SerializeField]
		private Image? image;

		public string Name
		{
			get
			{
				TextMeshProUGUI? obj = textMeshPro;
				return ((obj != null) ? ((TMP_Text)obj).text : null) ?? string.Empty;
			}
			set
			{
				if ((Object)(object)textMeshPro != (Object)null)
				{
					((TMP_Text)textMeshPro).text = value;
				}
			}
		}

		[UsedImplicitly]
		public bool IsHovered { get; private set; }

		[UsedImplicitly]
		public bool IsSelected { get; private set; }

		public void OnPointerEnter(PointerEventData eventData)
		{
			IsHovered = true;
			OnHover();
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			IsHovered = false;
			OnUnhover();
		}

		public void Select()
		{
			IsSelected = true;
			OnSelected();
		}

		public void Deselect()
		{
			IsSelected = false;
			OnDeselected();
		}

		public virtual void OnSelected()
		{
			SetColorActive();
		}

		public virtual void OnDeselected()
		{
			SetColorInactive();
		}

		public virtual void OnHover()
		{
			SetColorActive();
		}

		public virtual void OnUnhover()
		{
			SetColorInactive();
		}

		protected virtual void Awake()
		{
			textMeshPro = ((Component)this).GetComponentInChildren<TextMeshProUGUI>();
			image = ((Component)this).GetComponentInChildren<Image>();
		}

		private void SetColorActive()
		{
			//IL_0022: 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)
			if (image != null)
			{
				((Graphic)image).color = new Color(0.992f, 0.839f, 0f, 0.6f);
			}
			if (textMeshPro != null)
			{
				((Graphic)textMeshPro).color = new Color(0f, 0f, 0f, 1f);
			}
		}

		private void SetColorInactive()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (image != null && !IsHovered && !IsSelected)
			{
				((Graphic)image).color = new Color(0.122f, 0.122f, 0.122f, 0.482f);
			}
			if (textMeshPro != null && !IsHovered && !IsSelected)
			{
				((Graphic)textMeshPro).color = new Color(1f, 1f, 1f, 1f);
			}
		}
	}
	[UsedImplicitly]
	public class SettingsNavigation : MonoBehaviour
	{
		[SerializeField]
		private SettingsMenu? settingsMenu;

		[SerializeField]
		private SettingsTab? selectedTab;

		[SerializeField]
		private List<SettingsTab> settingsTabs = new List<SettingsTab>();

		[SerializeField]
		private int pageSize = 3;

		[UsedImplicitly]
		public int Page { get; private set; }

		[UsedImplicitly]
		public int PageCount => Mathf.CeilToInt((float)settingsTabs.Count / (float)pageSize);

		public void Add(SettingsTab tab)
		{
			settingsTabs.Add(tab);
		}

		public SettingsTab Create(string tabName)
		{
			SettingsTab settingsTab = Object.Instantiate<GameObject>(SettingsAssets.SettingsTabPrefab, ((Component)this).transform).AddComponent<SettingsTab>();
			settingsTab.Name = tabName;
			Add(settingsTab);
			return settingsTab;
		}

		public void Select(SettingsTab tab)
		{
			if ((Object)(object)selectedTab != (Object)null)
			{
				Deselect(selectedTab);
			}
			selectedTab = tab;
			tab.Select();
			OnSelected(tab);
		}

		public void Deselect(SettingsTab tab)
		{
			selectedTab = null;
			tab.Deselect();
		}

		public void NextPage()
		{
			SetPage((Page + 1) % PageCount);
		}

		public void PreviousPage()
		{
			SetPage((Page - 1 + PageCount) % PageCount);
		}

		public void SelectPage(int page)
		{
			SetPage(Mathf.Clamp(page, 0, PageCount - 1));
		}

		public virtual void OnSelected(SettingsTab tab)
		{
			tab.Show();
			int num = settingsTabs.IndexOf(tab) / pageSize;
			for (int i = 0; i < settingsTabs.Count; i++)
			{
				((Component)settingsTabs[i]).gameObject.SetActive(i / pageSize == num);
			}
		}

		private void SetPage(int page)
		{
			Page = page;
			for (int i = 0; i < settingsTabs.Count; i++)
			{
				((Component)settingsTabs[i]).gameObject.SetActive(i / pageSize == page);
			}
		}

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			settingsMenu = ((Component)this).GetComponentInParent<SettingsMenu>();
			Transform obj = TransformExtensions.FindChildRecursive(((Component)settingsMenu).transform, "Next Tabs");
			if (obj != null)
			{
				((Component)obj).gameObject.AddComponent<SettingsButton>();
			}
			if (obj != null)
			{
				Button component = ((Component)obj).GetComponent<Button>();
				if (component != null)
				{
					((UnityEvent)component.onClick).AddListener(new UnityAction(NextPage));
				}
			}
			Transform obj2 = TransformExtensions.FindChildRecursive(((Component)settingsMenu).transform, "Previous Tabs");
			if (obj2 != null)
			{
				((Component)obj2).gameObject.AddComponent<SettingsButton>();
			}
			if (obj2 != null)
			{
				Button component2 = ((Component)obj2).GetComponent<Button>();
				if (component2 != null)
				{
					((UnityEvent)component2.onClick).AddListener(new UnityAction(PreviousPage));
				}
			}
		}

		private void Start()
		{
			if ((Object)(object)selectedTab != (Object)null)
			{
				Select(selectedTab);
			}
			else if (settingsTabs.Count > 0)
			{
				Select(settingsTabs[0]);
			}
		}

		private void OnEnable()
		{
			if ((Object)(object)selectedTab != (Object)null)
			{
				Select(selectedTab);
			}
		}
	}
	public class SettingsTab : SettingsButton
	{
		[SerializeField]
		private SettingsMenu? settingsMenu;

		public void Show()
		{
			if (!SettingsLoader.TryGetTab(base.Name, out Dictionary<string, List<Setting>> settingsByCategory) || (Object)(object)settingsMenu == (Object)null)
			{
				return;
			}
			settingsMenu.m_cells.ForEach(delegate(SettingsCell c)
			{
				Object.Destroy((Object)(object)((Component)c).gameObject);
			});
			settingsMenu.m_cells.Clear();
			Transform settingsContainer = settingsMenu.m_settingsContainer;
			if (settingsContainer != null)
			{
				TransformExtensions.ClearChildren(settingsContainer);
			}
			if ((Object)(object)settingsMenu.m_settingsCell == (Object)null || (Object)(object)settingsMenu.m_settingsContainer == (Object)null)
			{
				return;
			}
			if (settingsByCategory.ContainsKey(string.Empty))
			{
				settingsByCategory[string.Empty].ForEach(CreateSettingCell);
			}
			foreach (var (text2, list2) in settingsByCategory.Where((KeyValuePair<string, List<Setting>> s) => s.Key != string.Empty))
			{
				((TMP_Text)Object.Instantiate<GameObject>(SettingsAssets.SettingsCategoryPrefab, settingsMenu.m_settingsContainer).GetComponentInChildren<TextMeshProUGUI>()).text = text2;
				list2.ForEach(CreateSettingCell);
			}
		}

		public void OnPointerClicked()
		{
			((Component)((Component)this).transform.parent).GetComponent<SettingsNavigation>().Select(this);
		}

		protected void Start()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			((UnityEvent)((Component)this).GetComponent<Button>().onClick).AddListener(new UnityAction(OnPointerClicked));
		}

		protected override void Awake()
		{
			base.Awake();
			settingsMenu = ((Component)this).GetComponentInParent<SettingsMenu>();
		}

		private void CreateSettingCell(Setting setting)
		{
			if ((Object)(object)settingsMenu == (Object)null)
			{
				throw new Exception("Settings menu is null.");
			}
			SettingsCell component = Object.Instantiate<GameObject>(settingsMenu.m_settingsCell, settingsMenu.m_settingsContainer).GetComponent<SettingsCell>();
			component.Setup(setting, (ISettingHandler)(object)GameHandler.Instance.SettingsHandler);
			settingsMenu.m_cells.Add(component);
		}
	}
}
namespace ContentSettings.API.Settings.DebugUI
{
	public class BoolSettingsUI : SettingUI
	{
		private readonly BoolSetting _setting;

		private readonly ISettingHandler _handler;

		public BoolSettingsUI(BoolSetting setting, ISettingHandler settingHandler)
		{
			_setting = setting;
			_handler = settingHandler;
			SingletonAsset<SettingUxmls>.Instance.IntSettingUxml.CloneTree((VisualElement)(object)this);
			Label val = UQueryExtensions.Q<Label>((VisualElement)(object)this, "SettingName", (string)null);
			IntegerField obj = UQueryExtensions.Q<IntegerField>((VisualElement)(object)this, (string)null, (string)null);
			((TextElement)val).text = ((object)setting).GetType().Name;
			((BaseField<int>)(object)obj).SetValueWithoutNotify(setting.Value ? 1 : 0);
			INotifyValueChangedExtensions.RegisterValueChangedCallback<int>((INotifyValueChanged<int>)(object)obj, (EventCallback<ChangeEvent<int>>)Callback);
		}

		private void Callback(ChangeEvent<int> changeEvent)
		{
			_setting.SetValue(changeEvent.newValue != 0, _handler);
		}
	}
	public class IntSettingsUI : SettingUI
	{
		private readonly IntSetting _setting;

		private readonly ISettingHandler _handler;

		public IntSettingsUI(IntSetting setting, ISettingHandler settingHandler)
		{
			_setting = setting;
			_handler = settingHandler;
			SingletonAsset<SettingUxmls>.Instance.IntSettingUxml.CloneTree((VisualElement)(object)this);
			Label val = UQueryExtensions.Q<Label>((VisualElement)(object)this, "SettingName", (string)null);
			IntegerField obj = UQueryExtensions.Q<IntegerField>((VisualElement)(object)this, (string)null, (string)null);
			((TextElement)val).text = ((object)setting).GetType().Name;
			((BaseField<int>)(object)obj).SetValueWithoutNotify(setting.Value);
			INotifyValueChangedExtensions.RegisterValueChangedCallback<int>((INotifyValueChanged<int>)(object)obj, (EventCallback<ChangeEvent<int>>)Callback);
		}

		private void Callback(ChangeEvent<int> changeEvent)
		{
			_setting.SetValue(changeEvent.newValue, _handler);
		}
	}
	public class TextSettingsUI : SettingUI
	{
		private TextSetting _setting;

		private ISettingHandler _handler;

		public TextSettingsUI(TextSetting setting, ISettingHandler settingHandler)
		{
			_setting = setting;
			_handler = settingHandler;
			SingletonAsset<SettingUxmls>.Instance.FloatSettingUxml.CloneTree((VisualElement)(object)this);
			((TextElement)UQueryExtensions.Q<Label>((VisualElement)(object)this, "SettingName", (string)null)).text = ((object)setting).GetType().Name;
		}
	}
}
namespace ContentSettings.API.Attributes
{
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
	public class SettingRegister : Attribute
	{
		public string Tab { get; }

		public string? Category { get; }

		public SettingRegister(string tab, string? category = null)
		{
			Tab = tab;
			Category = category;
		}
	}
}
namespace ConfigurableWarning
{
	[ContentWarningPlugin("RedstoneWizard08.ConfigurableWarning", "1.14.0", false)]
	[BepInPlugin("RedstoneWizard08.ConfigurableWarning", "RedstoneWizard08.ConfigurableWarning", "1.14.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ConfigurableWarning : BaseUnityPlugin
	{
		public const uint ModID = 13584215u;

		internal static readonly ManualLogSource Logger = Logger.CreateLogSource("RedstoneWizard08.ConfigurableWarning");

		private readonly Harmony _harmony = new Harmony("RedstoneWizard08.ConfigurableWarning");

		public void Awake()
		{
			Logger.LogInfo((object)"Loading plugin RedstoneWizard08.ConfigurableWarning...");
			ConfigurableWarningAPI.Init();
			Patch();
			OptionLoader.RegisterOptions();
			Logger.LogInfo((object)"Plugin RedstoneWizard08.ConfigurableWarning loaded!");
		}

		public void Patch()
		{
			Logger.LogInfo((object)"Patching...");
			_harmony.PatchAll();
		}

		public void Unpatch()
		{
			Logger.LogInfo((object)"Unpatching...");
			Harmony.UnpatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RedstoneWizard08.ConfigurableWarning";

		public const string PLUGIN_NAME = "RedstoneWizard08.ConfigurableWarning";

		public const string PLUGIN_VERSION = "1.14.0";
	}
}
namespace ConfigurableWarning.Settings
{
	[Tab("GAMEPLAY")]
	public static class BuiltInSettings
	{
		[Group("GENERAL")]
		private static class General
		{
			[Register]
			private class PrivateHost : BoolOption
			{
				public PrivateHost()
					: base("PrivateHost", defaultValue: true, "Host Privately (friends-only)")
				{
				}
			}

			[Register]
			private class DaysPerQuota : IntOption
			{
				public DaysPerQuota()
					: base("DaysPerQuota", 3, "Days Per Quota", 0, 30, new Action<IntOption>[1] { SettingsUtil.UpdateQuotaDays }, doClamp: false)
				{
				}
			}

			[Register]
			private class RequireAllPlayersInDiveBell : BoolOption
			{
				public RequireAllPlayersInDiveBell()
					: base("RequireAllPlayersInDiveBell", defaultValue: true, "Require All Players in Dive Bell")
				{
				}
			}

			[Register]
			private class RequireDiveBellDoorClosed : BoolOption
			{
				public RequireDiveBellDoorClosed()
					: base("RequireDiveBellDoorClosed", defaultValue: true, "Require Dive Bell Door Closed")
				{
				}
			}

			[Register]
			private class Fov : FloatOption
			{
				public Fov()
					: base("Fov", 70f, "Field of View", 20f, 120f, doClamp: false)
				{
				}
			}
		}

		[Group("PLAYER")]
		private static class Player
		{
			[Register]
			private class MaxHealth : FloatOption
			{
				public MaxHealth()
					: base("Health", 100f, "Maximum Health", 0f, 1000f, doClamp: false)
				{
				}
			}

			[Register]
			private class MaxStamina : FloatOption
			{
				public MaxStamina()
					: base("MaxStamina", 10f, "Maximum Stamina", 0f, 100f, doClamp: false)
				{
				}
			}

			[Register]
			private class StaminaRegenRate : FloatOption
			{
				public StaminaRegenRate()
					: base("StaminaRegenRate", 1f, "Stamina Regen Rate", 0f, 100f, doClamp: false)
				{
				}
			}

			[Register]
			private class SprintSpeed : FloatOption
			{
				public SprintSpeed()
					: base("SprintSpeed", 2f, "Sprint Speed", 0f, 100f, doClamp: false)
				{
				}
			}
		}

		[Group("OXYGEN")]
		private static class Oxygen
		{
			[Register]
			private class MaxOxygen : FloatOption
			{
				public MaxOxygen()
					: base("Oxygen", 500f, "Maximum Oxygen (in seconds)", 0f, 2000f, doClamp: false)
				{
				}
			}

			[Register]
			private class InfiniteOxygen : BoolOption
			{
				public InfiniteOxygen()
					: base("InfiniteOxygen", defaultValue: false, "Enable Infinite Oxygen")
				{
				}
			}

			[Register]
			private class OxygenUsageMultiplier : FloatOption
			{
				public OxygenUsageMultiplier()
					: base("OxygenUsageMultiplier", 1f, "Oxygen Usage Multiplier", 0f, 20f, doClamp: false)
				{
				}
			}

			[Register]
			private class SprintMultiplier : FloatOption
			{
				public SprintMultiplier()
					: base("SprintMultiplier", 1f, "Sprinting Oxygen Usage Multiplier", 1f, 10f, doClamp: false)
				{
				}
			}

			[Register]
			private class UseOxygenInDiveBell : BoolOption
			{
				public UseOxygenInDiveBell()
					: base("UseOxygenInDiveBell", defaultValue: false, "Use Oxygen in Dive Bell")
				{
				}
			}

			[Register]
			private class RefillOxygenInDiveBell : BoolOption
			{
				public RefillOxygenInDiveBell()
					: base("RefillOxygenInDiveBell", defaultValue: false, "Refill Oxygen in Dive Bell")
				{
				}
			}

			[Register]
			private class UseOxygenOnSurface : BoolOption
			{
				public UseOxygenOnSurface()
					: base("UseOxygenOnSurface", defaultValue: false, "Use Oxygen on Surface (useful for debugging)")
				{
				}
			}

			[Register]
			private class RefillOxygenOnSurface : BoolOption
			{
				public RefillOxygenOnSurface()
					: base("RefillOxygenOnSurface", defaultValue: true, "Refill Oxygen on Surface (useful for debugging)")
				{
				}
			}

			[Register]
			private class OxygenRefillRate : FloatOption
			{
				public OxygenRefillRate()
					: base("OxygenRefillRate", 20f, "Oxygen Refill Rate", 0f, 500f, doClamp: false)
				{
				}
			}
		}
	}
	public static class SettingKeys
	{
		public const string PrivateHost = "PrivateHost";

		public const string DaysPerQuota = "DaysPerQuota";

		public const string RequireAllPlayersInDiveBell = "RequireAllPlayersInDiveBell";

		public const string RequireDiveBellDoorClosed = "RequireDiveBellDoorClosed";

		public const string Fov = "Fov";

		public const string Health = "Health";

		public const string MaxStamina = "MaxStamina";

		public const string StaminaRegenRate = "StaminaRegenRate";

		public const string SprintSpeed = "SprintSpeed";

		public const string Oxygen = "Oxygen";

		public const string InfiniteOxygen = "InfiniteOxygen";

		public const string OxygenUsageMultiplier = "OxygenUsageMultiplier";

		public const string SprintMultiplier = "SprintMultiplier";

		public const string UseOxygenInDiveBell = "UseOxygenInDiveBell";

		public const string RefillOxygenInDiveBell = "RefillOxygenInDiveBell";

		public const string UseOxygenOnSurface = "UseOxygenOnSurface";

		public const string RefillOxygenOnSurface = "RefillOxygenOnSurface";

		public const string OxygenRefillRate = "OxygenRefillRate";
	}
	public static class SettingsUtil
	{
		public static void UpdateQuotaDays(IntOption _opt)
		{
			if (SurfaceNetworkHandler.RoomStats != null)
			{
				SurfaceNetworkHandler.RoomStats.DaysPerQutoa = States.Ints["DaysPerQuota"];
			}
		}
	}
}
namespace ConfigurableWarning.Settings.Compat
{
	public static class FlashcardSettingKeys
	{
		public const string EnableExtraCamera = "EnableExtraCamera";

		public const string ClipLength = "ClipLength";

		public const string ClipFramerate = "ClipFramerate";

		public const string ClipQuality = "ClipQuality";

		public const string PacketDelay = "PacketDelay";

		public const string VerboseLogging = "VerboseLogging";
	}
	[CompatModule(new string[] { "Flashcard" })]
	public class FlashcardCompat : ICompatModule
	{
		[CompatTab("FLASHCARD")]
		private static class Settings
		{
			[CompatGroup("UPGRADES")]
			private static class Upgrades
			{
				[Register]
				private class EnableExtraCamera : BoolOption
				{
					public EnableExtraCamera()
						: base("EnableExtraCamera", defaultValue: true, "Enable Extra Camera Upgrade", new Action<BoolOption>[1] { ApplySettings })
					{
					}
				}
			}

			[CompatGroup("RECORDING")]
			private static class Recording
			{
				[Register]
				private class ClipLength : FloatOption
				{
					public ClipLength()
						: base("ClipLength", 120f, "Clip Length", 1f, 1000f, new Action<FloatOption>[1] { ApplySettings }, doClamp: false)
					{
					}
				}

				[Register]
				private class ClipFramerate : IntOption
				{
					public ClipFramerate()
						: base("ClipFramerate", 24, "Clip Framerate", 1, 30, new Action<IntOption>[1] { ApplySettings }, doClamp: false)
					{
					}
				}

				[Register]
				private class ClipQuality : TextOption
				{
					public ClipQuality()
						: base("ClipQuality", "512k", "Clip Quality (Bitrate)", new Action<TextOption>[1] { ApplySettings })
					{
					}
				}
			}

			[CompatGroup("UPLOADING")]
			private static class Uploading
			{
				[Register]
				private class PacketDelay : FloatOption
				{
					public PacketDelay()
						: base("PacketDelay", 0.5f, "Delay Between Packets", 0f, 10f, new Action<FloatOption>[1] { ApplySettings }, doClamp: false)
					{
					}
				}
			}

			[CompatGroup("DEBUGGING")]
			private static class Debugging
			{
				[Register]
				private class VerboseLogging : BoolOption
				{
					public VerboseLogging()
						: base("VerboseLogging", defaultValue: false, "Enable Verbose Logging", new Action<BoolOption>[1] { ApplySettings })
					{
					}
				}
			}
		}

		public void Init()
		{
			States.Bools["EnableExtraCamera"] = FlashcardPlugin.config.UPGRADES_EXTRA_CAMERA.Value == "disabled";
			States.Floats["ClipLength"] = FlashcardPlugin.config.RECORDING_CLIP_LENGTH.Value;
			States.Ints["ClipFramerate"] = FlashcardPlugin.config.RECORDING_CLIP_FRAMERATE.Value;
			States.Strings["ClipQuality"] = FlashcardPlugin.config.RECORDING_CLIP_QUALITY.Value;
			States.Floats["PacketDelay"] = FlashcardPlugin.config.UPLOADING_DELAY_BETWEEN_PACKETS.Value;
			States.Bools["VerboseLogging"] = FlashcardPlugin.config.DEBUGGING_VERBOSE_LOGGING.Value;
		}

		internal static void ApplySettings(IUntypedOption _opt)
		{
			if (new string[6] { "EnableExtraCamera", "ClipLength", "ClipFramerate", "ClipQuality", "PacketDelay", "VerboseLogging" }.All((string v) => OptionsState.Instance.Has(v)))
			{
				FlashcardPlugin.config.UPGRADES_EXTRA_CAMERA.Value = (States.Bools["EnableExtraCamera"] ? "always" : "disabled");
				FlashcardPlugin.config.RECORDING_CLIP_LENGTH.Value = States.Floats["ClipLength"];
				FlashcardPlugin.config.RECORDING_CLIP_FRAMERATE.Value = States.Ints["ClipFramerate"];
				FlashcardPlugin.config.RECORDING_CLIP_QUALITY.Value = States.Strings["ClipQuality"];
				FlashcardPlugin.config.UPLOADING_DELAY_BETWEEN_PACKETS.Value = States.Floats["PacketDelay"];
				FlashcardPlugin.config.DEBUGGING_VERBOSE_LOGGING.Value = States.Bools["VerboseLogging"];
			}
		}
	}
	public static class SpookdiversSettingKeys
	{
		public const string ReadyTime = "ReadyTime";

		public const string ForceScene = "ForceScene";

		public const string SceneName = "SceneName";

		public const string FakeBells = "FakeBells";

		public const string LoweringSpeed = "LoweringSpeed";
	}
	public enum SceneType
	{
		FactoryScene,
		HarbourScene,
		MinesScene
	}
	[CompatModule(new string[] { "Spookdivers" })]
	public class SpookdiversCompat : ICompatModule
	{
		[CompatGroup("SPOOKDIVERS", "GENERAL")]
		private static class Settings
		{
			[Register]
			private class ReadyTime : FloatOption
			{
				public ReadyTime()
					: base("ReadyTime", 30f, "Max Players", 0f, 100f, new Action<FloatOption>[1] { ApplySettings }, doClamp: false)
				{
				}
			}

			[Register]
			private class ForceScene : BoolOption
			{
				public ForceScene()
					: base("ForceScene", defaultValue: false, "Force Scene Change", new Action<BoolOption>[1] { ApplySettings })
				{
				}
			}

			[Register]
			private class SceneName : EnumOption<SceneType>
			{
				public SceneName()
					: base("SceneName", SceneType.FactoryScene, "Scene Name", new Action<EnumOption<SceneType>>[1] { ApplySettings })
				{
				}
			}

			[Register]
			private class FakeBells : BoolOption
			{
				public FakeBells()
					: base("FakeBells", defaultValue: false, "Enable Fake Bells", new Action<BoolOption>[1] { ApplySettings })
				{
				}
			}

			[Register]
			private class LoweringSpeed : FloatOption
			{
				public LoweringSpeed()
					: base("LoweringSpeed", 2f, "Bell Lowering Speed", 0f, 30f, new Action<FloatOption>[1] { ApplySettings }, doClamp: false)
				{
				}
			}
		}

		public void Init()
		{
			States.Floats["ReadyTime"] = Plugin.Instance.ReadyTime.Value;
			States.Bools["ForceScene"] = Plugin.Instance.ForceScene.Value;
			States.Enums.Set("SceneName", Enum.Parse<SceneType>(Plugin.Instance.SceneName.Value));
			States.Bools["FakeBells"] = Plugin.Instance.FakeBellsConfig.Value;
			States.Floats["LoweringSpeed"] = Plugin.Instance.LoweringSpeedConfig.Value;
		}

		internal static void ApplySettings(IUntypedOption _opt)
		{
			if (new string[5] { "ReadyTime", "ForceScene", "SceneName", "FakeBells", "LoweringSpeed" }.All((string v) => OptionsState.Instance.Has(v)))
			{
				Plugin.Instance.ReadyTime.Value = States.Floats["ReadyTime"];
				Plugin.Instance.ForceScene.Value = States.Bools["ForceScene"];
				Plugin.Instance.SceneName.Value = Enum.GetName(typeof(SceneType), States.Enums.Get<SceneType>("SceneName"));
				Plugin.Instance.FakeBellsConfig.Value = States.Bools["FakeBells"];
				Plugin.Instance.LoweringSpeedConfig.Value = States.Floats["LoweringSpeed"];
			}
		}
	}
	public static class ViralitySettingKeys
	{
		public const string MaxPlayers = "MaxPlayers";

		public const string AllowLateJoin = "AllowLateJoin";

		public const string EnableVoiceFix = "EnableVoiceFix";
	}
	[CompatModule(new string[] { "Virality" })]
	public class ViralityCompat : ICompatModule
	{
		[CompatGroup("VIRALITY", "GENERAL")]
		private static class Settings
		{
			[Register]
			private class MaxPlayers : IntOption
			{
				public MaxPlayers()
					: base("MaxPlayers", 12, "Max Players", 4, 100, new Action<IntOption>[1] { ApplySettings }, doClamp: false)
				{
				}
			}

			[Register]
			private class AllowLateJoin : BoolOption
			{
				public AllowLateJoin()
					: base("AllowLateJoin", defaultValue: true, "Allow Late Joining", new Action<BoolOption>[1] { ApplySettings })
				{
				}
			}

			[Register]
			private class EnableVoiceFix : BoolOption
			{
				public EnableVoiceFix()
					: base("EnableVoiceFix", defaultValue: true, "Enable Voice Fix", new Action<BoolOption>[1] { ApplySettings })
				{
				}
			}
		}

		public void Init()
		{
			States.Ints["MaxPlayers"] = Virality.MaxPlayers.Value;
			States.Bools["AllowLateJoin"] = Virality.AllowLateJoin.Value;
			States.Bools["EnableVoiceFix"] = Virality.EnableVoiceFix.Value;
		}

		internal static void ApplySettings(IUntypedOption _opt)
		{
			if (new string[3] { "MaxPlayers", "AllowLateJoin", "EnableVoiceFix" }.All((string v) => OptionsState.Instance.Has(v)))
			{
				Virality.MaxPlayers.Value = States.Ints["MaxPlayers"];
				Virality.AllowLateJoin.Value = States.Bools["AllowLateJoin"];
				Virality.EnableVoiceFix.Value = States.Bools["EnableVoiceFix"];
			}
		}
	}
}
namespace ConfigurableWarning.Patches
{
	[HarmonyPatch]
	public class CameraPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(MainCamera), "Update")]
		public static void Update(MainCamera __instance)
		{
			__instance.baseFOV = States.Floats["Fov"];
		}
	}
	[HarmonyPatch]
	public class DivingBellPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(DivingBellDoor), "IsFullyClosed")]
		public static void IsFullyClosed(DivingBellDoor __instance, ref bool __result)
		{
			__result = __result || !States.Bools["RequireDiveBellDoorClosed"];
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DiveBellPlayerDetector), "CheckForPlayers")]
		public static void CheckForPlayers(DiveBellPlayerDetector __instance, ref ICollection<Player> __result)
		{
			if (!States.Bools["RequireAllPlayersInDiveBell"])
			{
				__result = PlayerHandler.instance.players;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DivingBell), "Update")]
		public static void Update(DivingBell __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (__instance.onSurface && (int)TimeOfDayHandler.TimeOfDay == 10)
			{
				((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellRechargingState>();
				return;
			}
			ICollection<Player> playersFoundInBell = __instance.playerDetector.CheckForPlayers();
			bool flag = PlayerHandler.instance.players.All((Player player) => playersFoundInBell.Contains(player));
			bool flag2 = !__instance.door.IsFullyClosed() && States.Bools["RequireDiveBellDoorClosed"];
			bool flag3 = !flag && States.Bools["RequireAllPlayersInDiveBell"];
			if (!flag2)
			{
				__instance.opened = false;
			}
			if (__instance.onSurface)
			{
				if (flag3)
				{
					((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellNotReadyMissingPlayersState>();
				}
				else if (flag2)
				{
					((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellNotReadyDoorOpenState>();
				}
				else
				{
					((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellReadyState>();
				}
			}
			else if (flag2)
			{
				((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellNotReadyDoorOpenState>();
			}
			else
			{
				((StateMachine<DivingBellState>)(object)__instance.StateMachine).SwitchState<DivingBellReadyState>();
			}
		}
	}
	[HarmonyPatch]
	public class LobbyPatch
	{
		private static bool IsFriendsWith(CSteamID cSteamID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return SteamFriends.HasFriend(cSteamID, (EFriendFlags)0);
		}

		private static bool IsPublic(SteamLobbyHandler __instance)
		{
			if (__instance.IsMasterClient)
			{
				return !States.Bools["PrivateHost"];
			}
			return __instance.IsPlayingWithRandoms();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SteamLobbyHandler), "IsPlayingWithRandoms")]
		public static void IsPlayingWithRandoms(SteamLobbyHandler __instance, ref bool __result)
		{
			if (__instance.IsMasterClient)
			{
				__result = !States.Bools["PrivateHost"];
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamLobbyHandler), "AddSteamClient")]
		public static bool AddSteamClient(SteamLobbyHandler __instance, CSteamID cSteamID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!IsFriendsWith(cSteamID) && !IsPublic(__instance))
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamLobbyHandler), "OnNetworkingSessionRequest")]
		public static bool OnNetworkingSessionRequest(SteamLobbyHandler __instance, SteamNetworkingMessagesSessionRequest_t param)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!IsFriendsWith(((SteamNetworkingIdentity)(ref param.m_identityRemote)).GetSteamID()))
			{
				return IsPublic(__instance);
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamLobbyHandler), "OpenLobby")]
		public static bool OpenLobby(SteamLobbyHandler __instance)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.IsMasterClient)
			{
				return false;
			}
			SteamMatchmaking.SetLobbyType(__instance.m_CurrentLobby, (ELobbyType)((!IsPublic(__instance)) ? 1 : 2));
			SteamMatchmaking.SetLobbyJoinable(__instance.m_CurrentLobby, true);
			return false;
		}
	}
	[HarmonyPatch]
	public class PlayerPatch
	{
		private static bool _tmpUsingOxygen;

		public static float GetMaxOxygen()
		{
			return States.Floats["Oxygen"];
		}

		public static float GetMaxHealth()
		{
			return States.Floats["Health"];
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "CheckOxygen")]
		public static bool CheckOxygen(Player __instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (States.Bools["InfiniteOxygen"])
			{
				__instance.data.remainingOxygen = States.Floats["Oxygen"];
				return false;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			bool num = ((Scene)(ref activeScene)).name == "SurfaceScene";
			bool flag = num && !States.Bools["UseOxygenOnSurface"];
			__instance.data.usingOxygen = !flag;
			if (num && States.Bools["RefillOxygenOnSurface"])
			{
				PlayerData data = __instance.data;
				data.remainingOxygen += Time.deltaTime * States.Floats["OxygenRefillRate"];
			}
			if (__instance.ai)
			{
				__instance.data.usingOxygen = false;
			}
			if (__instance.data.remainingOxygen > States.Floats["Oxygen"])
			{
				__instance.data.remainingOxygen = States.Floats["Oxygen"];
			}
			if (__instance.data.remainingOxygen < 0f)
			{
				__instance.data.remainingOxygen = 0f;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerData), "UpdateValues")]
		public static bool UpdateValuesPre(PlayerData __instance)
		{
			CheckOxygen(__instance.player);
			_tmpUsingOxygen = __instance.usingOxygen;
			PlayerData.maxHealth = States.Floats["Health"];
			__instance.maxOxygen = States.Floats["Oxygen"];
			__instance.usingOxygen = false;
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerData), "UpdateValues")]
		public static void UpdateValuesPost(PlayerData __instance)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			__instance.usingOxygen = _tmpUsingOxygen;
			if (__instance.usingOxygen && (!__instance.isInDiveBell || States.Bools["UseOxygenInDiveBell"]))
			{
				float num = (__instance.isSprinting ? States.Floats["SprintMultiplier"] : 1f) * States.Floats["OxygenUsageMultiplier"];
				__instance.remainingOxygen -= Time.deltaTime * num;
				if (__instance.remainingOxygen < States.Floats["Oxygen"] * 0.5f && PhotonNetwork.IsMasterClient && PhotonGameLobbyHandler.CurrentObjective is FilmSomethingScaryObjective)
				{
					PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new ReturnToTheDiveBellObjective());
				}
			}
		}
	}
	[HarmonyPatch]
	public class QuotaPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void Constructor(RoomStatsHolder __instance, SurfaceNetworkHandler handler, int startMoney, int startQuotaToReachToReach, int daysPerQuota)
		{
			__instance.DaysPerQutoa = States.Ints["DaysPerQuota"];
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void GetDaysPerQuota(RoomStatsHolder __instance, ref int __result)
		{
			__result = States.Ints["DaysPerQuota"];
		}
	}
	[HarmonyPatch]
	public class SpawnPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(BigNumbers), "GetExtraBudgetForDay")]
		public static void GetExtraBudgetForDay(int day, ref int __result)
		{
			BigNumbers instance = SingletonAsset<BigNumbers>.Instance;
			int day3ExtraMoBudget = instance.day3ExtraMoBudget;
			int day1ExtraMoBudget = instance.day1ExtraMoBudget;
			int num = day3ExtraMoBudget - day1ExtraMoBudget;
			int num2 = States.Ints["DaysPerQuota"];
			int num3 = num / num2;
			__result = num3 * day + day1ExtraMoBudget;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BigNumbers), "GetMonsterBudgetForDayFirstWave")]
		public static void GetMonsterBudgetForDayFirstWave(int day, ref int __result)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			BigNumbers instance = SingletonAsset<BigNumbers>.Instance;
			int num = States.Ints["DaysPerQuota"];
			int num2 = (day - 1) % num + 1;
			int __result2 = 0;
			GetExtraBudgetForDay(num2, ref __result2);
			int num3 = Mathf.RoundToInt(instance.monsterBudgetPerDay.Evaluate((float)day) + (float)__result2);
			float firstWaveSizeWas = ExtDataTypes.PRndRange(SingletonAsset<BigNumbers>.Instance.firstSpawnAmount);
			SingletonAsset<BigNumbers>.Instance.firstWaveSizeWas = firstWaveSizeWas;
			num3 = CurvedUIExtensionMethods.ToInt(instance.firstWaveSizeWas * (float)num3);
			Debug.LogWarning((object)$"1st wave Day: {day} quotaDay: {num2} budget {num3}");
			__result = num3;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BigNumbers), "GetMonsterBudgetForSecondWave")]
		public static void GetMonsterBudgetForSecondWave(int day, ref int __result)
		{
			BigNumbers instance = SingletonAsset<BigNumbers>.Instance;
			int num = States.Ints["DaysPerQuota"];
			int num2 = (day - 1) % num + 1;
			int __result2 = 0;
			GetExtraBudgetForDay(num2, ref __result2);
			int num3 = Mathf.RoundToInt(instance.monsterBudgetPerDay.Evaluate((float)day) + (float)__result2);
			num3 = CurvedUIExtensionMethods.ToInt((1f - instance.firstWaveSizeWas) * (float)num3);
			Debug.LogWarning((object)$"2nd wave Day: {day} quotaDay: {num2} budget {num3}");
			__result = num3;
		}
	}
	[HarmonyPatch]
	public class StaminaPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerController), "Start")]
		public static void Start(ref PlayerController __instance)
		{
			Update(ref __instance);
			Player.localPlayer.data.currentStamina = States.Floats["MaxStamina"];
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerController), "Update")]
		public static void Update(ref PlayerController __instance)
		{
			__instance.maxStamina = States.Floats["MaxStamina"];
			__instance.sprintMultiplier = States.Floats["SprintSpeed"];
			__instance.staminaRegRate = States.Floats["StaminaRegenRate"];
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerController), "Update")]
		public static void UpdatePost(ref PlayerController __instance)
		{
			PlayerData data = Player.localPlayer.data;
			float num = States.Floats["MaxStamina"];
			float num2 = States.Floats["StaminaRegenRate"];
			if (data.sinceSprint > 1f)
			{
				float currentStamina = ((num2 > 1f) ? Mathf.MoveTowards(data.currentStamina, num, (num2 - 1f) * Time.deltaTime) : ((!(num2 > 0f)) ? data.currentStamina : Mathf.MoveTowards(data.currentStamina, 0f, (1f - num2) * Time.deltaTime)));
				data.currentStamina = currentStamina;
			}
		}
	}
	[HarmonyPatch]
	public class UIPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(UI_Health), "Update")]
		public static void UpdateHealth(UI_Health __instance)
		{
			((Image)__instance.fill).fillAmount = Player.localPlayer.data.health / States.Floats["Health"];
		}
	}
}
namespace ConfigurableWarning.API
{
	public static class ConfigurableWarningAPI
	{
		public static OptionSyncer Sync { get; private set; }

		internal static void Init()
		{
			ConfigurableWarning.Logger.LogInfo((object)"Initializing ConfigurableWarning API...");
			Sync = new OptionSyncer();
		}
	}
	public sealed class EnumStateHolder
	{
		public T? Get<T>(string name)
		{
			return OptionsState.Instance.Get<T>(name);
		}

		public void Set<T>(string name, T value)
		{
			OptionsState.Instance.Set(name, value);
		}
	}
	public static class EnumUtil
	{
		public static string[] GetOptions<T>() where T : struct
		{
			return Enum.GetNames(typeof(T));
		}

		public static T Parse<T>(string value) where T : struct
		{
			return (T)Enum.Parse(typeof(T), value);
		}

		public static int GetIndex<T>(T value) where T : struct
		{
			return Array.IndexOf<string>(GetOptions<T>(), value.ToString());
		}
	}
	public static class OptionExt
	{
		public static BoolOption? BoolOpt(this string name)
		{
			return BoolOption.Instance(name);
		}

		public static FloatOption? FloatOpt(this string name)
		{
			return FloatOption.Instance(name);
		}

		public static IntOption? IntOpt(this string name)
		{
			return IntOption.Instance(name);
		}

		public static TextOption? TextOpt(this string name)
		{
			return TextOption.Instance(name);
		}

		public static EnumOption<T>? EnumOpt<T>(this string name) where T : struct
		{
			return EnumOption<T>.Instance(name);
		}

		public static bool BoolState(this string opt)
		{
			return opt.BoolOpt().State;
		}

		public static float? FloatState(this string opt)
		{
			return opt.FloatOpt()?.State;
		}

		public static int? IntState(this string opt)
		{
			return opt.IntOpt()?.State;
		}

		public static string? TextState(this string opt)
		{
			return opt.TextOpt()?.State;
		}

		public static T? EnumState<T>(this string opt) where T : struct
		{
			return opt.EnumOpt<T>()?.State;
		}
	}
	public static class OptionLoader
	{
		public static readonly Dictionary<Type, IUntypedOption> RegisteredOptions = new Dictionary<Type, IUntypedOption>();

		public static readonly Dictionary<Type, Tab> RegisteredTabs = new Dictionary<Type, Tab>();

		public static readonly Dictionary<Type, Group> RegisteredGroups = new Dictionary<Type, Group>();

		public static void RegisterOptions()
		{
			foreach (Type item in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes()))
			{
				TryRegisterTab(item);
				TryRegisterGroup(null, item);
			}
			CompatLoader.LoadModules();
		}

		public static bool TryRegisterSetting(string tab, string group, Type type)
		{
			if (type.IsInterface || type.IsAbstract || !type.IsSubclassOf(typeof(Setting)))
			{
				return false;
			}
			if (RegisteredOptions.ContainsKey(type))
			{
				return false;
			}
			if (type.GetCustomAttribute<Register>(inherit: false) == null)
			{
				return false;
			}
			ConfigurableWarning.Logger.LogInfo((object)("Found setting " + type.FullName));
			IUntypedOption untypedOption = (IUntypedOption)Activator.CreateInstance(type);
			untypedOption.Register(tab, group);
			RegisteredOptions.Add(type, untypedOption);
			return true;
		}

		public static bool TryRegisterGroup(string? tab, Type type)
		{
			if (RegisteredGroups.ContainsKey(type))
			{
				return false;
			}
			Group customAttribute = type.GetCustomAttribute<Group>(inherit: false);
			if (customAttribute == null)
			{
				return false;
			}
			ConfigurableWarning.Logger.LogInfo((object)("Found group " + customAttribute.Category + " in " + type.FullName));
			if (tab == null && customAttribute.Tab == null)
			{
				ConfigurableWarning.Logger.LogError((object)"Cannot register a Group with no tab!");
				return false;
			}
			Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type type2 in nestedTypes)
			{
				TryRegisterSetting(tab ?? customAttribute.Tab, customAttribute.Category, type2);
			}
			RegisteredGroups.Add(type, customAttribute);
			return true;
		}

		public static bool TryRegisterTab(Type type)
		{
			if (RegisteredTabs.ContainsKey(type))
			{
				return false;
			}
			Tab customAttribute = type.GetCustomAttribute<Tab>(inherit: false);
			if (customAttribute == null)
			{
				return false;
			}
			ConfigurableWarning.Logger.LogInfo((object)("Found tab " + customAttribute.Name + " in " + type.FullName + " (from " + type.Assembly.GetName().Name + ".dll"));
			Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type type2 in nestedTypes)
			{
				TryRegisterGroup(customAttribute.Name, type2);
			}
			RegisteredTabs.Add(type, customAttribute);
			return true;
		}
	}
	public class OptionManager
	{
		private readonly Dictionary<string, IUntypedOption> _options = new Dictionary<string, IUntypedOption>();

		public static OptionManager Instance { get; } = new OptionManager();


		public static DefaultSettingsSaveLoad SaveLoader { get; } = new DefaultSettingsSaveLoad();


		public void Register<T>(IOption<T> opt)
		{
			_options.Add(opt.GetName(), opt.AsUntyped());
		}

		public void Register(IUntypedOption opt)
		{
			_options.Add(opt.GetName(), opt);
		}

		public IUntypedOption? Get(string name)
		{
			return _options[name];
		}

		public IOption<T>? Get<T>(string name)
		{
			return (IOption<T>)Get(name);
		}
	}
	public class OptionsState
	{
		private Dictionary<string, object> _states = new Dictionary<string, object>();

		public static OptionsState Instance { get; } = new OptionsState();


		public void Register<T>(IOption<T> opt)
		{
			if (!Has(opt))
			{
				Set(opt, opt.GetValue());
			}
		}

		public void Set<T>(IOption<T> opt, T value)
		{
			_states[opt.GetName()] = value;
		}

		public void Set<T>(string name, T value)
		{
			_states[name] = value;
		}

		public T? Get<T>(IOption<T> opt)
		{
			return Get<T>(opt.GetName());
		}

		public T? Get<T>(string name)
		{
			object obj = _states[name];
			object obj2 = obj;
			if (!(obj2 is double num))
			{
				if (obj2 is long num2 && typeof(T) == typeof(int))
				{
					return (T)(object)(int)num2;
				}
			}
			else if (typeof(T) == typeof(float))
			{
				return (T)(object)(float)num;
			}
			return (T)obj;
		}

		public bool Has<T>(IOption<T> opt)
		{
			return _states.ContainsKey(opt.GetName());
		}

		public bool Has(string name)
		{
			return _states.ContainsKey(name);
		}

		public void Remove<T>(IOption<T> opt)
		{
			_states.Remove(opt.GetName());
		}

		public void Remove(string name)
		{
			_states.Remove(name);
		}

		public void Clear()
		{
			_states.Clear();
		}

		public void Update<T>(IOption<T> opt)
		{
			Set(opt, opt.GetValue());
		}

		public string Collect()
		{
			return JsonConvert.SerializeObject((object)_states);
		}

		public void Apply(string json)
		{
			_states = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
		}
	}
	public class OptionSyncer
	{
		private string _lastRecv = "";

		private string _lastSent = "";

		internal OptionSyncer()
		{
			MyceliumNetwork.RegisterNetworkObject((object)this, 13584215u, 0);
		}

		public void ResetCache()
		{
			_lastSent = "";
			_lastRecv = "";
		}

		[CustomRPC]
		public void SyncSettingsRecv(string data)
		{
			if (!(data == _lastRecv))
			{
				_lastRecv = data;
				OptionsState.Instance.Apply(data);
			}
		}

		public void SyncSettings()
		{
			string text = OptionsState.Instance.Collect();
			if (!(text == _lastSent))
			{
				_lastSent = text;
				MyceliumNetwork.RPC(13584215u, "SyncSettingsRecv", (ReliableType)1, new object[1] { text });
			}
		}
	}
	[HarmonyPatch]
	public class SettingPatches
	{
		private static float _originalFloatValue;

		private static int _originalIntValue;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(FloatSetting), "SetValue")]
		public static void SetValueFloatPre(ref FloatSetting __instance, float value, ISettingHandler handler)
		{
			_originalFloatValue = value;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(FloatSetting), "SetValue")]
		public static void SetValueFloat(ref FloatSetting __instance, float value, ISettingHandler handler)
		{
			if (__instance is FloatOption floatOption)
			{
				__instance.Value = (floatOption._shouldClamp ? __instance.Clamp(_originalFloatValue) : _originalFloatValue);
				((Setting)__instance).ApplyValue();
				handler.SaveSetting((Setting)(object)__instance);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(IntSetting), "SetValue")]
		public static void SetValueIntPre(ref IntSetting __instance, int newValue, ISettingHandler settingHandler)
		{
			_originalIntValue = newValue;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(IntSetting), "SetValue")]
		public static void SetValueInt(ref IntSetting __instance, int newValue, ISettingHandler settingHandler)
		{
			if (__instance is IntOption intOption)
			{
				__instance.Value = (intOption._shouldClamp ? __instance.Clamp(_originalIntValue) : _originalIntValue);
				((Setting)__instance).ApplyValue();
				settingHandler.SaveSetting((Setting)(object)__instance);
			}
		}
	}
	public sealed class StateHolder<T>
	{
		public T? this[string name]
		{
			get
			{
				return OptionsState.Instance.Get<T>(name);
			}
			set
			{
				OptionsState.Instance.Set(name, value);
			}
		}
	}
	public static class States
	{
		public static readonly StateHolder<bool> Bools = new StateHolder<bool>();

		public static readonly StateHolder<float> Floats = new StateHolder<float>();

		public static readonly StateHolder<int> Ints = new StateHolder<int>();

		public static readonly StateHolder<string> Strings = new StateHolder<string>();

		public static readonly EnumStateHolder Enums = new EnumStateHolder();
	}
}
namespace ConfigurableWarning.API.Options
{
	public class BoolOption : BoolSetting, IOption<bool>, ICustomSetting, IExposedSetting, IUntypedOption
	{
		private readonly List<Action<BoolOption>> _applyActions;

		private readonly bool _defaultValue;

		private readonly string _displayName;

		private readonly string _name;

		public bool State
		{
			get
			{
				return AsOption().State;
			}
			set
			{
				AsOption().State = value;
			}
		}

		protected BoolOption(string name, bool defaultValue, string displayName)
			: this(name, defaultValue, displayName, Array.Empty<Action<BoolOption>>())
		{
		}

		protected BoolOption(string name, bool defaultValue, string displayName, Action<BoolOption>[] actions)
		{
			_name = name;
			_displayName = displayName;
			_defaultValue = defaultValue;
			List<Action<BoolOption>> list = new List<Action<BoolOption>>(actions.Length);
			list.AddRange(actions);
			_applyActions = list;
		}

		public void RegisterSetting(string tab, string category)
		{
			SettingsLoader.RegisterSetting(tab, category, (Setting)(object)this);
		}

		public void SetValue(bool value)
		{
			base.Value = value;
			GameHandler.Instance.SettingsHandler.SaveSetting((Setting)(object)this);
		}

		public string GetName()
		{
			return _name;
		}

		public bool GetValue()
		{
			return base.Value;
		}

		public string GetDisplayName()
		{
			return _displayName;
		}

		public IUntypedOption AsUntyped()
		{
			return this;
		}

		public override bool GetDefaultValue()
		{
			return _defaultValue;
		}

		public IOption<bool> AsOption()
		{
			return this;
		}

		object IUntypedOption.GetValue()
		{
			return GetValue();
		}

		public void SetValue(object value)
		{
			SetValue((bool)value);
		}

		public static BoolOption? Instance(string name)
		{
			return (BoolOption)IOption<bool>.Instance(name);
		}

		public override void ApplyValue()
		{
			OptionsState.Instance.Update(this);
			ConfigurableWarningAPI.Sync.SyncSettings();
			foreach (Action<BoolOption> applyAction in _applyActions)
			{
				applyAction(this);
			}
		}
	}
	public class EnumOption<T> : EnumSetting, IOption<T>, ICustomSetting, IExposedSetting, IUntypedOption where T : struct
	{
		private readonly List<Action<EnumOption<T>>> _applyActions;

		private readonly T _defaultValue;

		private readonly string _displayName;

		private readonly string _name;

		public string WrappedValue
		{
			get
			{
				return EnumUtil.GetOptions<T>()[((IntSetting)this).Value];
			}
			set
			{
				((IntSetting)this).Value = EnumUtil.GetIndex(EnumUtil.Parse<T>(value));
			}
		}

		public T State
		{
			get
			{
				return AsOption().State;
			}
			set
			{
				AsOption().State = value;
			}
		}

		protected EnumOption(string name, T defaultValue, string displayName)
			: this(name, defaultValue, displayName, Array.Empty<Action<EnumOption<T>>>())
		{
		}

		protected EnumOption(string name, T defaultValue, string displayName, Action<EnumOption<T>>[] actions)
		{
			_name = name;
			_displayName = displayName;
			_defaultValue = defaultValue;
			List<Action<EnumOption<T>>> list = new List<Action<EnumOption<T>>>(actions.Length);
			list.AddRange(actions);
			_applyActions = list;
		}

		public void RegisterSetting(string tab, string category)
		{
			SettingsLoader.RegisterSetting(tab, category, (Setting)(object)this);
		}

		public void SetValue(T value)
		{
			WrappedValue = value.ToString();
			GameHandler.Instance.SettingsHandler.SaveSetting((Setting)(object)this);
		}

		public string GetName()
		{
			return _name;
		}

		public T GetValue()
		{
			return Enum.Parse<T>(WrappedValue);
		}

		public string GetDisplayName()
		{
			return _displayName;
		}

		public IUntypedOption AsUntyped()
		{
			return this;
		}

		T IOption<T>.GetDefaultValue()
		{
			return _defaultValue;
		}

		public IOption<T> AsOption()
		{
			return this;
		}

		object IUntypedOption.GetValue()
		{
			return GetValue();
		}

		public void SetValue(object value)
		{
			SetValue((T)value);
		}

		public override int GetDefaultValue()
		{
			return EnumUtil.GetIndex(_defaultValue);
		}

		public override List<string> GetChoices()
		{
			return EnumUtil.GetOptions<T>().ToList();
		}

		public static EnumOption<T>? Instance(string name)
		{
			return (EnumOption<T>)IOption<T>.Instance(name);
		}

		public override void ApplyValue()
		{
			OptionsState.Instance.Update(this);
			ConfigurableWarningAPI.Sync.SyncSettings();
			foreach (Action<EnumOption<T>> applyAction in _applyActions)
			{
				applyAction(this);
			}
		}
	}
	public class FloatOption : FloatSetting, IOption<float>, ICustomSetting, IExposedSetting, IUntypedOption
	{
		private readonly List<Action<FloatOption>> _applyActions;

		private readonly float _defaultValue;

		private readonly string _displayName;

		private readonly float2 _minMax;

		private readonly string _name;

		internal readonly bool _shouldClamp;

		public float State
		{
			get
			{
				return AsOption().State;
			}
			set
			{
				AsOption().State = value;
			}
		}

		protected FloatOption(string name, float defaultValue, string displayName, float min, float max, bool doClamp = true)
			: this(name, defaultValue, displayName, min, max, Array.Empty<Action<FloatOption>>(), doClamp)
		{
		}

		protected FloatOption(string name, float defaultValue, string displayName, float min, float max, Action<FloatOption>[] actions, bool doClamp = true)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			_name = name;
			_displayName = displayName;
			_defaultValue = defaultValue;
			_minMax = new float2(min, max);
			_shouldClamp = doClamp;
			List<Action<FloatOption>> list = new List<Action<FloatOption>>(actions.Length);
			list.AddRange(actions);
			_applyActions = list;
		}

		public void RegisterSetting(string tab, string category)
		{
			SettingsLoader.RegisterSetting(tab, category, (Setting)(object)this);
		}

		public void SetValue(float value)
		{
			((FloatSetting)this).Value = (_shouldClamp ? ((FloatSetting)this).Clamp(value) : value);
			GameHandler.Instance.SettingsHandler.SaveSetting((Setting)(object)this);
		}

		public string GetName()
		{
			return _name;
		}

		public float GetValue()
		{
			return ((FloatSetting)this).Value;
		}

		public string GetDisplayName()
		{
			return _displayName;
		}

		public IUntypedOption AsUntyped()
		{
			return this;
		}

		public override float GetDefaultValue()
		{
			return _defaultValue;
		}

		public IOption<float> AsOption()
		{
			return this;
		}

		object IUntypedOption.GetValue()
		{
			return GetValue();
		}

		public void SetValue(object value)
		{
			SetValue((float)value);
		}

		public static FloatOption? Instance(string name)
		{
			return (FloatOption)IOption<float>.Instance(name);
		}

		public override void ApplyValue()
		{
			OptionsState.Instance.Update(this);
			ConfigurableWarningAPI.Sync.SyncSettings();
			foreach (Action<FloatOption> applyAction in _applyActions)
			{
				applyAction(this);
			}
		}

		public override float2 GetMinMaxValue()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return _minMax;
		}
	}
	public class IntOption : IntSetting, IOption<int>, ICustomSetting, IExposedSetting, IUntypedOption
	{
		private readonly List<Action<IntOption>> _applyActions;

		private readonly int _defaultValue;

		private readonly string _displayName;

		private readonly int2 _minMax;

		private readonly string _name;

		internal readonly bool _shouldClamp;

		public int State
		{
			get
			{
				return AsOption().State;
			}
			set
			{
				AsOption().State = value;
			}
		}

		protected IntOption(string name, int defaultValue, string displayName, int min, int max, bool doClamp = true)
			: this(name, defaultValue, displayName, min, max, Array.Empty<Action<IntOption>>(), doClamp)
		{
		}

		protected IntOption(string name, int defaultValue, string displayName, int min, int max, Action<IntOption>[] actions, bool doClamp = true)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			_name = name;
			_displayName = displayName;
			_defaultValue = defaultValue;
			_minMax = new int2(min, max);
			_shouldClamp = doClamp;
			List<Action<IntOption>> list = new List<Action<IntOption>>(actions.Length);
			list.AddRange(actions);
			_applyActions = list;
		}

		public void RegisterSetting(string tab, string category)
		{
			SettingsLoader.RegisterSetting(tab, category, (Setting)(object)this);
		}

		public void SetValue(int value)
		{
			base.Value = (_shouldClamp ? Clamp(value) : value);
			GameHandler.Instance.SettingsHandler.SaveSetting((Setting)(object)this);
		}

		public string GetName()
		{
			return _name;
		}

		public int GetValue()
		{
			return base.Value;
		}

		public string GetDisplayName()
		{
			return _displayName;
		}

		public IUntypedOption AsUntyped()
		{
			return this;
		}

		public override int GetDefaultValue()
		{
			return _defaultValue;
		}

		public IOption<int> AsOption()
		{
			return this;
		}

		object IUntypedOption.GetValue()
		{
			return GetValue();
		}

		public void SetValue(object value)
		{
			SetValue((int)value);
		}

		public static IntOption? Instance(string name)
		{
			return (IntOption)IOption<int>.Instance(name);
		}

		public override void ApplyValue()
		{
			OptionsState.Instance.Update(this);
			ConfigurableWarningAPI.Sync.SyncSettings();
			foreach (Action<IntOption> applyAction in _applyActions)
			{
				applyAction(this);
			}
		}

		protected override (int, int) GetMinMaxValue()
		{
			return (_minMax.x, _minMax.y);
		}
	}
	public interface IOption<T> : ICustomSetting, IExposedSetting, IUntypedOption
	{
		T? State
		{
			get
			{
				return OptionsState.Instance.Get<T>(GetName());
			}
			set
			{
				OptionsState.Instance.Set(this, value);
			}
		}

		string IExposedSetting.GetDisplayName()
		{
			return GetDisplayName();
		}

		void IUntypedOption.Register(string tab, string category)
		{
			Register(tab, category);
		}

		new string GetName();

		string GetDisplayName();

		T GetDefaultValue();

		new T GetValue();

		void SetValue(T value);

		void RegisterSetting(string tab, string category);

		IUntypedOption AsUntyped();

		IOption<T> AsOption();

		new void Register(string tab, string category)
		{
			RegisterSetting(tab, category);
			OptionManager.Instance.Register(this);
			OptionsState.Instance.Register(this);
		}

		static IOption<T>? Instance(string name)
		{
			return OptionManager.Instance.Get<T>(name);
		}
	}
	public interface IUntypedOption
	{
		string GetName();

		object GetValue();

		void SetValue(object value);

		void Register(string tab, string category);
	}
	public class TextOption : TextSetting, IOption<string>, ICustomSetting, IExposedSetting, IUntypedOption
	{
		private readonly List<Action<TextOption>> _applyActions;

		private readonly string _defaultValue;

		private readonly string _displayName;

		private readonly string _name;

		public string? State
		{
			get
			{
				return AsOption().State;
			}
			set
			{
				AsOption().State = value;
			}
		}

		protected TextOption(string name, string defaultValue, string displayName)
			: this(name, defaultValue, displayName, Array.Empty<Action<TextOption>>())
		{
		}

		protected TextOption(string name, string defaultValue, string displayName, Action<TextOption>[] actions)
		{
			_name = name;
			_displayName = displayName;
			_defaultValue = defaultValue;
			List<Action<TextOption>> list = new List<Action<TextOption>>(actions.Length);
			list.AddRange(actions);
			_applyActions = list;
		}

		public void RegisterSetting(string tab, string category)
		{
			SettingsLoader.RegisterSetting(tab, category, (Setting)(object)this);
		}

		public void SetValue(string value)
		{
			base.Value = value;
			GameHandler.Instance.SettingsHandler.SaveSetting((Setting)(object)this);
		}

		public string GetName()
		{
			return _name;
		}

		public string GetValue()
		{
			return base.Value;
		}

		public string GetDisplayName()
		{
			return _displayName;
		}

		public IUntypedOption AsUntyped()
		{
			return this;
		}

		public override string GetDefaultValue()
		{
			return _defaultValue;
		}

		public IOption<string> AsOption()
		{
			return this;
		}

		object IUntypedOption.GetValue()
		{
			return GetValue();
		}

		public void SetValue(object value)
		{
			SetValue((string)value);
		}

		public static TextOption? Instance(string name)
		{
			return (TextOption)IOption<string>.Instance(name);
		}

		public override void ApplyValue()
		{
			OptionsState.Instance.Update(this);
			ConfigurableWarningAPI.Sync.SyncSettings();
			foreach (Action<TextOption> applyAction in _applyActions)
			{
				applyAction(this);
			}
		}
	}
}
namespace ConfigurableWarning.API.Compat
{
	public static class CompatLoader
	{
		public static readonly Dictionary<Type, ICompatModule> RegisteredModules = new Dictionary<Type, ICompatModule>();

		public static readonly Dictionary<Type, CompatTab> RegisteredTabs = new Dictionary<Type, CompatTab>();

		public static readonly Dictionary<Type, CompatGroup> RegisteredGroups = new Dictionary<Type, CompatGroup>();

		public static bool NamespaceExists(string ns)
		{
			string ns2 = ns;
			return (from v in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => from t in a.GetTypes()
					select t.Namespace)
				where v != null
				select v).Any((string v) => v.StartsWith(ns2 + ".") || v == ns2);
		}

		public static void LoadModules()
		{
			foreach (Type item in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes()))
			{
				if (item.IsAbstract || item.IsInterface || !typeof(ICompatModule).IsAssignableFrom(item) || RegisteredModules.ContainsKey(item))
				{
					continue;
				}
				CompatModule customAttribute = item.GetCustomAttribute<CompatModule>(inherit: false);
				if (customAttribute == null)
				{
					continue;
				}
				ConfigurableWarning.Logger.LogInfo((object)("Checking compat module: " + item.Name + " (from " + item.Assembly.GetName().Name + ".dll"));
				bool flag = true;
				string[] dependencies = customAttribute.Dependencies;
				foreach (string text in dependencies)
				{
					if (NamespaceExists(text))
					{
						ConfigurableWarning.Logger.LogInfo((object)("Found namespace: " + text));
						continue;
					}
					ConfigurableWarning.Logger.LogInfo((object)("Could not find namespace: " + text + "; Skipping..."));
					flag = false;
					break;
				}
				if (flag)
				{
					ConfigurableWarning.Logger.LogInfo((object)("Initializing compat module: " + item.Name));
					Type[] nestedTypes = item.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
					foreach (Type type in nestedTypes)
					{
						TryRegisterCompatTab(type);
						TryRegisterCompatGroup(null, type);
					}
					ICompatModule compatModule = (ICompatModule)Activator.CreateInstance(item);
					compatModule.Init();
					RegisteredModules[item] = compatModule;
				}
			}
		}

		public static bool TryRegisterCompatGroup(string? tab, Type type)
		{
			if (RegisteredGroups.ContainsKey(type))
			{
				return false;
			}
			CompatGroup customAttribute = type.GetCustomAttribute<CompatGroup>(inherit: false);
			if (customAttribute == null)
			{
				return false;
			}
			ConfigurableWarning.Logger.LogInfo((object)("Found compat group " + customAttribute.Category + " in " + type.FullName));
			if (tab == null && customAttribute.Tab == null)
			{
				ConfigurableWarning.Logger.LogError((object)"Cannot register a CompatGroup with no tab!");
				return false;
			}
			Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type type2 in nestedTypes)
			{
				OptionLoader.TryRegisterSetting(tab ?? customAttribute.Tab, customAttribute.Category, type2);
			}
			RegisteredGroups.Add(type, customAttribute);
			return true;
		}

		public static bool TryRegisterCompatTab(Type type)
		{
			if (RegisteredTabs.ContainsKey(type))
			{
				return false;
			}
			CompatTab customAttribute = type.GetCustomAttribute<CompatTab>(inherit: false);
			if (customAttribute == null)
			{
				return false;
			}
			ConfigurableWarning.Logger.LogInfo((object)("Found compat tab " + customAttribute.Name + " in " + type.FullName + " (from " + type.Assembly.GetName().Name + ".dll"));
			Type[] nestedTypes = type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type type2 in nestedTypes)
			{
				OptionLoader.TryRegisterGroup(customAttribute.Name, type2);
				TryRegisterCompatGroup(customAttribute.Name, type2);
			}
			RegisteredTabs.Add(type, customAttribute);
			return true;
		}
	}
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public sealed class CompatModule : Attribute
	{
		public readonly string[] Dependencies;

		public CompatModule(string[] dependencies)
		{
			Dependencies = dependencies;
			base..ctor();
		}
	}
	public interface ICompatModule
	{
		void Init();
	}
}
namespace ConfigurableWarning.API.Attributes
{
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public class CompatGroup : Attribute
	{
		public readonly string Category;

		public readonly string? Tab;

		public CompatGroup(string category)
		{
			Category = category;
			Tab = null;
		}

		public CompatGroup(string tab, string category)
		{
			Tab = tab;
			Category = category;
		}
	}
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public class CompatTab : Attribute
	{
		public readonly string? Name;

		public CompatTab(string tab)
		{
			Name = tab;
		}
	}
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public class Group : Attribute
	{
		public readonly string Category;

		public readonly string? Tab;

		public Group(string category)
		{
			Category = category;
			Tab = null;
		}

		public Group(string tab, string category)
		{
			Tab = tab;
			Category = category;
		}
	}
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public class Register : Attribute
	{
	}
	[MeansImplicitUse]
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public class Tab : Attribute
	{
		public readonly string? Name;

		public Tab(string tab)
		{
			Name = tab;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}