Decompiled source of ContentSettings v1.0.3

BepInEx/plugins/ContentSettings/dhkatz.ContentSettings.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using ContentSettings.API;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Localization.PropertyVariants;
using Zorro.Settings;

[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-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("com.rlabrecque.steamworks.net")]
[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("SteamAudioUnity")]
[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.0.3.8659814332")]
[assembly: AssemblyInformationalVersion("1.0.3+d92c4dbd492f721881db89308a3583e24eec54a1")]
[assembly: AssemblyProduct("dhkatz.ContentSettings")]
[assembly: AssemblyTitle("dhkatz.ContentSettings")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/dhkatz/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 ContentSettings
{
	[BepInPlugin("dhkatz.ContentSettings", "dhkatz.ContentSettings", "1.0.3")]
	public class ContentSettings : BaseUnityPlugin
	{
		private Harmony Harmony { get; } = new Harmony("dhkatz.ContentSettings");


		private void Awake()
		{
			Harmony.PatchAll();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "dhkatz.ContentSettings";

		public const string PLUGIN_NAME = "dhkatz.ContentSettings";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace ContentSettings.Patch
{
	[HarmonyPatch]
	internal class SettingsPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(DefaultSettingsSaveLoad), "WriteToDisk")]
		internal static void WriteToDiskPatch()
		{
			SettingsLoader.SaveSettings();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingCategoryTab), "Select")]
		internal static bool SelectPatch(SettingCategoryTab __instance)
		{
			if (((Object)__instance).name == "MODDED")
			{
				SettingsLoader.LoadSettingsMenu(__instance.settingsMenu);
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingsMenu), "OnEnable")]
		internal static bool OnEnablePatch(SettingsMenu __instance)
		{
			SettingsLoader.CreateSettings(__instance);
			return true;
		}
	}
}
namespace ContentSettings.API
{
	public static class SettingsLoader
	{
		private static readonly DefaultSettingsSaveLoad SaveLoader = new DefaultSettingsSaveLoad();

		private static readonly List<Setting> Settings = new List<Setting>();

		public static void RegisterSetting(Setting setting)
		{
			Settings.Add(setting);
			setting.Load((ISettingsSaveLoad)(object)SaveLoader);
			setting.ApplyValue();
		}

		internal static void LoadSettingsMenu(SettingsMenu menu)
		{
			foreach (SettingsCell cell in menu.m_cells)
			{
				Object.Destroy((Object)(object)((Component)cell).gameObject);
			}
			menu.m_cells.Clear();
			SettingsHandler settingsHandler = GameHandler.Instance.SettingsHandler;
			foreach (Setting setting in Settings)
			{
				SettingsCell component = Object.Instantiate<GameObject>(menu.m_settingsCell, menu.m_settingsContainer).GetComponent<SettingsCell>();
				component.Setup(setting, (ISettingHandler)(object)settingsHandler);
				menu.m_cells.Add(component);
			}
		}

		internal static void SaveSettings()
		{
			foreach (Setting setting in Settings)
			{
				setting.Save((ISettingsSaveLoad)(object)SaveLoader);
			}
		}

		internal static void CreateSettings(SettingsMenu menu)
		{
			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)val.Find("MODDED") != (Object)null))
			{
				Transform child = val.GetChild(0);
				GameObject obj2 = ((child != null) ? ((Component)child).gameObject : null);
				if ((Object)(object)obj2 == (Object)null)
				{
					throw new Exception("Failed to find existing tab.");
				}
				GameObject obj3 = Object.Instantiate<GameObject>(obj2, val, true);
				((Object)obj3).name = "MODDED";
				Transform child2 = obj3.transform.GetChild(1);
				Object.Destroy((Object)(object)((Component)child2).GetComponent<GameObjectLocalizer>());
				((TMP_Text)((Component)child2).GetComponent<TextMeshProUGUI>()).SetText("MODDED", true);
				LoadSettingsMenu(menu);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}