Decompiled source of ContentSettings v1.2.2

BepInEx/plugins/ContentSettings/CommanderCat101.ContentSettings.dll

Decompiled 7 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 ContentSettings.API;
using ContentSettings.API.Attributes;
using ContentSettings.API.Settings;
using ContentSettings.API.Settings.DebugUI;
using ContentSettings.API.Settings.UI;
using ContentSettings.Internal;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Zorro.Core;
using Zorro.Settings;
using Zorro.Settings.DebugUI;

[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("Ashley.MeshSplitter")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[assembly: IgnoresAccessChecksTo("Discord")]
[assembly: IgnoresAccessChecksTo("HBAO.Demo.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Runtime")]
[assembly: IgnoresAccessChecksTo("HBAO.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("MeshSplit")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("pworld")]
[assembly: IgnoresAccessChecksTo("sc.posteffects.runtime")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Modules.UnityLocalization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Tayx.Graphy")]
[assembly: IgnoresAccessChecksTo("Unity.Addressables")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InternalAPIEngineBridge.013")]
[assembly: IgnoresAccessChecksTo("Unity.Localization")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.PlayableGraphVisualizer")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipeline.Universal.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Shaders")]
[assembly: IgnoresAccessChecksTo("Unity.ResourceManager")]
[assembly: IgnoresAccessChecksTo("Unity.ScriptableBuildPipeline")]
[assembly: IgnoresAccessChecksTo("Unity.Splines")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("Zorro.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.PhotonUtility")]
[assembly: IgnoresAccessChecksTo("Zorro.Recorder")]
[assembly: IgnoresAccessChecksTo("Zorro.Settings.Runtime")]
[assembly: IgnoresAccessChecksTo("Zorro.UI.Runtime")]
[assembly: AssemblyCompany("CommanderCat101;dhkatz")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A library for adding Modded Settings.")]
[assembly: AssemblyFileVersion("1.2.2.8777214664")]
[assembly: AssemblyInformationalVersion("1.2.2+e95c84e3598c199b852e5129940091da52d1b738")]
[assembly: AssemblyProduct("CommanderCat101.ContentSettings")]
[assembly: AssemblyTitle("CommanderCat101.ContentSettings")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Commander-Cat101/ContentSettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace ContentSettings
{
	[ContentWarningPlugin("CommanderCat101.ContentSettings", "1.2.2", true)]
	[BepInPlugin("CommanderCat101.ContentSettings", "CommanderCat101.ContentSettings", "1.2.2")]
	public class ContentSettings : BaseUnityPlugin
	{
		public const string Id = "CommanderCat101.ContentSettings";

		internal static ManualLogSource Logger { get; private set; }

		private Harmony Harmony { get; } = new Harmony("CommanderCat101.ContentSettings");


		public static string Name => "CommanderCat101.ContentSettings";

		public static string Version => "1.2.2";

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

		private void Update()
		{
			SettingsLoader.Update();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CommanderCat101.ContentSettings";

		public const string PLUGIN_NAME = "CommanderCat101.ContentSettings";

		public const string PLUGIN_VERSION = "1.2.2";
	}
}
namespace ContentSettings.Internal
{
	internal static class SettingsAssets
	{
		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(ContentSettings).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)
		{
			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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			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;
			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; private 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();
		}

		protected 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; private 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]
		protected virtual int Clamp(int value)
		{
			return Mathf.Clamp(value, MinValue, MaxValue);
		}

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

		protected 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 System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}