Decompiled source of Settings Extender v0.0.1

plugins/SettingsExtender.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SettingsExtender")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("Settings Extender")]
[assembly: AssemblyTitle("SettingsExtender")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SettingsExtender
{
	[BepInPlugin("SettingsExtender", "Settings Extender", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private GameObject buttonSrc;

		private Coroutine updateTabsRoutine;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin SettingsExtender is loaded!");
		}

		private void Start()
		{
		}

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (updateTabsRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(updateTabsRoutine);
				updateTabsRoutine = null;
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if (updateTabsRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(updateTabsRoutine);
				updateTabsRoutine = null;
			}
			updateTabsRoutine = ((MonoBehaviour)this).StartCoroutine(UpdateTabs(scene));
		}

		private IEnumerator UpdateTabs(Scene scene)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Logger.LogInfo((object)("Scene loadeeeed: " + ((Scene)(ref scene)).name));
			while ((Object)(object)buttonSrc == (Object)null)
			{
				List<SettingsTABSButton> buttons = FindAllInScene(scene);
				if (buttons.Count != 0)
				{
					buttonSrc = ((Component)buttons[0]).gameObject;
				}
				yield return (object)new WaitForSeconds(0.05f);
			}
			if (!((Object)(object)buttonSrc != (Object)null))
			{
				yield break;
			}
			Logger.LogInfo((object)"Found TABS/General");
			foreach (var (name, category) in SettingsRegistry.GetPages())
			{
				Logger.LogInfo((object)$"Creating {name} with category {category}");
				GameObject newButton = Object.Instantiate<GameObject>(buttonSrc, buttonSrc.transform.parent);
				SettingsTABSButton tabsButton = newButton.GetComponent<SettingsTABSButton>();
				tabsButton.category = category;
				((TMP_Text)((TAB_Button)tabsButton).text).text = name;
			}
		}

		public static List<SettingsTABSButton> FindAllInScene(Scene scene)
		{
			List<SettingsTABSButton> list = new List<SettingsTABSButton>();
			GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
			foreach (GameObject val in rootGameObjects)
			{
				SettingsTABSButton[] componentsInChildren = val.GetComponentsInChildren<SettingsTABSButton>();
				list.AddRange(componentsInChildren);
			}
			return list;
		}
	}
	public class SettingsRegistry
	{
		internal static Dictionary<string, SettingsCategory> nameToCategoryId = new Dictionary<string, SettingsCategory>();

		public static void Register(string name)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!nameToCategoryId.ContainsKey(name))
			{
				SettingsCategory val = Enum.GetValues(typeof(SettingsCategory)).Cast<SettingsCategory>().Max();
				if (nameToCategoryId.Count != 0)
				{
					val = nameToCategoryId.Values.Max();
				}
				nameToCategoryId[name] = (SettingsCategory)(val + 1);
			}
		}

		public static string GetPageId(string name)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			SettingsCategory val = nameToCategoryId[name];
			return ((object)(SettingsCategory)(ref val)).ToString();
		}

		public static Dictionary<string, SettingsCategory> GetPages()
		{
			return nameToCategoryId;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SettingsExtender";

		public const string PLUGIN_NAME = "Settings Extender";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}