Decompiled source of ModsMenu v0.3.2

ModsMenu.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StolenRealmModAPI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ModsMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+170bee66ef82872534ee913dc7aac45a42464837")]
[assembly: AssemblyProduct("ModsMenu")]
[assembly: AssemblyTitle("ModsMenu")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ModsMenu
{
	internal sealed class ModCard
	{
		private readonly UiKit _kit;

		private readonly ModsMenuApi.Section _section;

		private readonly Action<ModCard> _toggled;

		private RectTransform _body;

		private TMP_Text _marker;

		public bool IsOpen { get; private set; }

		public string Guid => _section.Plugin.Metadata.GUID;

		private ModCard(UiKit kit, ModsMenuApi.Section section, Action<ModCard> toggled)
		{
			_kit = kit;
			_section = section;
			_toggled = toggled;
		}

		public static ModCard Create(UiKit kit, Transform parent, ModsMenuApi.Section section, bool open, Action<ModCard> toggled)
		{
			ModCard modCard = new ModCard(kit, section, toggled);
			modCard.Build(parent);
			modCard.SetOpen(open);
			return modCard;
		}

		private void Build(Transform parent)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Expected O, but got Unknown
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Expected O, but got Unknown
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Expected O, but got Unknown
			BepInPlugin metadata = _section.Plugin.Metadata;
			Image val = UiKit.Rect(parent, "ModCard (" + metadata.Name + ")", UiKit.CardColor);
			VerticalLayoutGroup obj = ((Component)val).gameObject.AddComponent<VerticalLayoutGroup>();
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			Image val2 = UiKit.Rect(((Component)val).transform, "Header", Color.white);
			((Graphic)val2).raycastTarget = true;
			((Component)val2).gameObject.AddComponent<LayoutElement>().minHeight = 38f;
			HorizontalLayoutGroup obj2 = ((Component)val2).gameObject.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj2).padding = new RectOffset(0, 14, 0, 0);
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 10f;
			((LayoutGroup)obj2).childAlignment = (TextAnchor)3;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = childControlWidth;
			Button obj3 = ((Component)val2).gameObject.AddComponent<Button>();
			((Selectable)obj3).targetGraphic = (Graphic)(object)val2;
			ColorBlock colors = ((Selectable)obj3).colors;
			((ColorBlock)(ref colors)).normalColor = UiKit.BarColor;
			((ColorBlock)(ref colors)).highlightedColor = UiKit.BarHoverColor;
			((ColorBlock)(ref colors)).pressedColor = UiKit.BarPressedColor;
			((ColorBlock)(ref colors)).selectedColor = UiKit.BarSelectedColor;
			((ColorBlock)(ref colors)).fadeDuration = 0f;
			((Selectable)obj3).colors = colors;
			((ColorBlock)(ref colors)).fadeDuration = 0.08f;
			((Selectable)obj3).colors = colors;
			((UnityEvent)obj3.onClick).AddListener((UnityAction)delegate
			{
				SetOpen(!IsOpen);
				_toggled?.Invoke(this);
			});
			LayoutElement obj4 = ((Component)UiKit.Rect(((Component)val2).transform, "Accent", _kit.HeaderColor)).gameObject.AddComponent<LayoutElement>();
			float minWidth = (obj4.preferredWidth = 4f);
			obj4.minWidth = minWidth;
			obj4.flexibleHeight = 1f;
			_marker = (TMP_Text)(object)_kit.Text(((Component)val2).transform, "", 0.8f, header: true);
			_marker.alignment = (TextAlignmentOptions)514;
			((Component)_marker).gameObject.AddComponent<LayoutElement>().minWidth = 16f;
			TextMeshProUGUI obj5 = _kit.Text(((Component)val2).transform, metadata.Name, 1f, header: true);
			((TMP_Text)obj5).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)obj5).overflowMode = (TextOverflowModes)1;
			((Component)obj5).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			TextMeshProUGUI val3 = _kit.Text(((Component)val2).transform, "v" + metadata.Version, 0.75f);
			((Graphic)val3).color = new Color(((Graphic)val3).color.r, ((Graphic)val3).color.g, ((Graphic)val3).color.b, 0.5f);
			((TMP_Text)val3).textWrappingMode = (TextWrappingModes)0;
			GameObject val4 = new GameObject("Body", new Type[1] { typeof(RectTransform) });
			_body = (RectTransform)val4.transform;
			((Transform)_body).SetParent(((Component)val).transform, false);
			VerticalLayoutGroup obj6 = val4.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj6).padding = new RectOffset(16, 12, 8, 12);
			((HorizontalOrVerticalLayoutGroup)obj6).spacing = 8f;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj6).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj6).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj6).childForceExpandHeight = false;
		}

		private void SetOpen(bool open)
		{
			IsOpen = open;
			_marker.text = (open ? _kit.FoldGlyphs.open : _kit.FoldGlyphs.closed);
			UiKit.ClearChildren((Transform)(object)_body);
			((Component)_body).gameObject.SetActive(open);
			if (open)
			{
				Fill();
			}
		}

		private void Fill()
		{
			SectionBuilder sectionBuilder = new SectionBuilder(_kit, (Transform)(object)_body);
			if (_section.ShowConfig)
			{
				sectionBuilder.AddConfigFile(_section.Plugin.Instance.Config);
			}
			if (_section.Custom == null)
			{
				return;
			}
			foreach (Action<SectionBuilder> item in _section.Custom)
			{
				try
				{
					item(sectionBuilder);
				}
				catch (Exception arg)
				{
					Plugin.ModLog.LogError((object)$"Mods tab: {_section.Plugin.Metadata.Name} failed: {arg}");
				}
			}
		}
	}
	public static class ModsMenuApi
	{
		internal sealed class Section
		{
			public PluginInfo Plugin;

			public bool ShowConfig;

			public List<Action<SectionBuilder>> Custom;
		}

		public const string Guid = "com.helvetica.modsmenu";

		private static readonly Dictionary<string, List<Action<SectionBuilder>>> CustomBuilders = new Dictionary<string, List<Action<SectionBuilder>>>();

		public static void AddSection(string pluginGuid, Action<SectionBuilder> build)
		{
			if (!string.IsNullOrEmpty(pluginGuid) && build != null)
			{
				if (!CustomBuilders.TryGetValue(pluginGuid, out var value))
				{
					value = (CustomBuilders[pluginGuid] = new List<Action<SectionBuilder>>());
				}
				value.Add(build);
			}
		}

		internal static List<Section> CollectSections()
		{
			List<Section> list = new List<Section>();
			foreach (PluginInfo value2 in Chainloader.PluginInfos.Values)
			{
				if (value2 != null && value2.Instance != null)
				{
					string gUID = value2.Metadata.GUID;
					bool flag = gUID == "com.helvetica.modsmenu" || value2.Dependencies.Any((BepInDependency d) => d.DependencyGUID == "com.helvetica.modsmenu");
					ConfigFile config = value2.Instance.Config;
					bool num = config != null && config.Count > 0;
					CustomBuilders.TryGetValue(gUID, out var value);
					bool flag2 = num && (flag || Plugin.ShowAllPlugins.Value);
					if (flag2 || value != null)
					{
						list.Add(new Section
						{
							Plugin = value2,
							ShowConfig = flag2,
							Custom = value
						});
					}
				}
			}
			return list.OrderBy((Section s) => s.Plugin.Metadata.GUID == "com.helvetica.modsmenu").ThenBy<Section, string>((Section s) => s.Plugin.Metadata.Name, StringComparer.OrdinalIgnoreCase).ToList();
		}
	}
	internal class ModsTab : MonoBehaviour
	{
		public const string TabLabel = "Mods";

		private OptionsManager _options;

		private MenuTabManager _tabs;

		private MenuTab _tab;

		private GameObject _panel;

		private RectTransform _content;

		private UiKit _kit;

		private static readonly HashSet<string> OpenCards = new HashSet<string>();

		public static void Install(OptionsManager options)
		{
			if ((Object)(object)options == (Object)null || (Object)(object)((Component)options).GetComponent<ModsTab>() != (Object)null)
			{
				return;
			}
			try
			{
				((Component)options).gameObject.AddComponent<ModsTab>().Build(options);
			}
			catch (Exception arg)
			{
				Plugin.ModLog.LogError((object)$"Couldn't add the Mods tab: {arg}");
			}
		}

		private void Build(OptionsManager options)
		{
			_options = options;
			Traverse obj = Traverse.Create((object)options);
			MenuTab value = obj.Field("TabTwitch").GetValue<MenuTab>();
			GameObject value2 = obj.Field("twitchPanel").GetValue<GameObject>();
			_tabs = ((Component)options).GetComponentInChildren<MenuTabManager>(true);
			if ((Object)(object)value == (Object)null || (Object)(object)value2 == (Object)null || (Object)(object)_tabs == (Object)null)
			{
				throw new InvalidOperationException("Options window layout changed (Twitch tab/panel not found).");
			}
			if (Plugin.LogUiLayout.Value)
			{
				UiLayoutLogger.LogOnce(options, value, value2);
			}
			_kit = UiKit.FromOptions(options, value, _tabs);
			BuildTab(value);
			BuildPanel(value2);
			Plugin.ModLog.LogInfo((object)"Mods tab added to the Options window.");
		}

		private void BuildTab(MenuTab twitchTab)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(((Component)twitchTab).gameObject, ((Component)twitchTab).transform.parent, false);
			((Object)val).name = "TabMods";
			UiKit.Sanitize(val);
			val.transform.SetSiblingIndex(((Component)twitchTab).transform.GetSiblingIndex() + 1);
			val.SetActive(true);
			_tab = val.GetComponent<MenuTab>();
			RefreshLabels();
			Button component = val.GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				((UnityEvent)component.onClick).AddListener(new UnityAction(Open));
			}
			Traverse obj = Traverse.Create((object)_tabs).Field("MenuTabs");
			List<MenuTab> list = ((IEnumerable<MenuTab>)(((object)obj.GetValue<MenuTab[]>()) ?? ((object)new MenuTab[0]))).ToList();
			int num = list.IndexOf(twitchTab);
			list.Insert((num < 0) ? list.Count : (num + 1), _tab);
			obj.SetValue((object)list.ToArray());
		}

		public void RefreshLabels()
		{
			if (!((Object)(object)_tab == (Object)null))
			{
				TMP_Text[] componentsInChildren = ((Component)_tab).GetComponentsInChildren<TMP_Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].text = "Mods";
				}
				Text[] componentsInChildren2 = ((Component)_tab).GetComponentsInChildren<Text>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					componentsInChildren2[i].text = "Mods";
				}
			}
		}

		private void BuildPanel(GameObject twitchPanel)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_005d: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			_panel = new GameObject("ModsPanel", new Type[1] { typeof(RectTransform) });
			RectTransform val = (RectTransform)_panel.transform;
			RectTransform val2 = (RectTransform)twitchPanel.transform;
			((Transform)val).SetParent(((Transform)val2).parent, false);
			((Transform)val).SetSiblingIndex(((Transform)val2).GetSiblingIndex() + 1);
			val.anchorMin = val2.anchorMin;
			val.anchorMax = val2.anchorMax;
			val.pivot = val2.pivot;
			val.offsetMin = val2.offsetMin;
			val.offsetMax = val2.offsetMax;
			((Transform)val).localScale = ((Transform)val2).localScale;
			Image component = twitchPanel.GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				Image obj = _panel.AddComponent<Image>();
				obj.sprite = component.sprite;
				obj.type = component.type;
				((Graphic)obj).color = ((Graphic)component).color;
				obj.pixelsPerUnitMultiplier = component.pixelsPerUnitMultiplier;
			}
			GameObject val3 = new GameObject("Viewport", new Type[1] { typeof(RectTransform) });
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val, false);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			Vector2 offsetMin = (val4.offsetMax = Vector2.zero);
			val4.offsetMin = offsetMin;
			val3.AddComponent<RectMask2D>();
			((Graphic)val3.AddComponent<Image>()).color = Color.clear;
			GameObject val5 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			_content = (RectTransform)val5.transform;
			((Transform)_content).SetParent((Transform)(object)val4, false);
			_content.anchorMin = new Vector2(0f, 1f);
			_content.anchorMax = new Vector2(1f, 1f);
			_content.pivot = new Vector2(0.5f, 1f);
			RectTransform content = _content;
			offsetMin = (_content.offsetMax = Vector2.zero);
			content.offsetMin = offsetMin;
			VerticalLayoutGroup obj2 = val5.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)obj2).padding = new RectOffset(16, 16, 12, 20);
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = 10f;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
			val5.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			ScrollRect obj3 = _panel.AddComponent<ScrollRect>();
			obj3.viewport = val4;
			obj3.content = _content;
			obj3.horizontal = false;
			obj3.movementType = (MovementType)2;
			obj3.scrollSensitivity = 30f;
			_panel.SetActive(false);
		}

		public void Open()
		{
			_options.CloseAllMenus();
			_panel.SetActive(true);
			Rebuild();
			_options.AnyWindowOpen();
			_tabs.SelectButton(_tab);
		}

		public void Hide()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				_panel.SetActive(false);
			}
		}

		private void Rebuild()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			UiKit.ClearChildren((Transform)(object)_content);
			List<ModsMenuApi.Section> list = ModsMenuApi.CollectSections();
			if (list.Count == 0)
			{
				new SectionBuilder(_kit, (Transform)(object)_content).AddLabel("No mods have added settings here yet.");
				return;
			}
			bool flag = list.Count == 1;
			foreach (ModsMenuApi.Section item in list)
			{
				ModCard.Create(_kit, (Transform)(object)_content, item, flag || OpenCards.Contains(item.Plugin.Metadata.GUID), OnCardToggled);
			}
			LayoutRebuilder.ForceRebuildLayoutImmediate(_content);
			_content.anchoredPosition = Vector2.zero;
		}

		private void OnCardToggled(ModCard card)
		{
			if (card.IsOpen)
			{
				OpenCards.Add(card.Guid);
			}
			else
			{
				OpenCards.Remove(card.Guid);
			}
			LayoutRebuilder.ForceRebuildLayoutImmediate(_content);
		}
	}
	[HarmonyPatch(typeof(OptionsManager), "Awake")]
	internal static class OptionsManager_Awake_Patch
	{
		private static void Postfix(OptionsManager __instance)
		{
			ModsTab.Install(__instance);
		}
	}
	[HarmonyPatch(typeof(OptionsManager), "CloseAllMenus")]
	internal static class OptionsManager_CloseAllMenus_Patch
	{
		private static void Postfix(OptionsManager __instance)
		{
			((Component)__instance).GetComponent<ModsTab>()?.Hide();
		}
	}
	[HarmonyPatch(typeof(OptionsManager), "LocalizeUI")]
	internal static class OptionsManager_LocalizeUI_Patch
	{
		private static void Postfix()
		{
			OptionsManager instance = OptionsManager.instance;
			if ((Object)(object)instance != (Object)null)
			{
				((Component)instance).GetComponent<ModsTab>()?.RefreshLabels();
			}
		}
	}
	[BepInPlugin("com.helvetica.modsmenu", "Mods Menu", "0.3.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : StolenRealmMod
	{
		public const string PluginGuid = "com.helvetica.modsmenu";

		public const string PluginName = "Mods Menu";

		public const string PluginVersion = "0.3.2";

		internal static ManualLogSource ModLog;

		internal static ConfigEntry<bool> ShowAllPlugins;

		internal static ConfigEntry<bool> LogUiLayout;

		protected override void OnModLoaded()
		{
			ModLog = ((BaseUnityPlugin)this).Logger;
			ShowAllPlugins = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowAllPlugins", false, "List every installed plugin that has settings, not just mods that opted in to the Mods tab.");
			LogUiLayout = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogUiLayout", false, "Write the Options window's UI layout to the BepInEx log once per launch (helps mod development).");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mods Menu v0.3.2 loaded.");
		}
	}
	public sealed class SectionBuilder
	{
		private readonly UiKit _kit;

		private readonly Transform _content;

		private const float SliderRowHeight = 52f;

		private const float SliderRightInset = 48f;

		private const float SliderDrop = 8f;

		private static readonly Regex WordBreak = new Regex("(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])");

		internal SectionBuilder(UiKit kit, Transform content)
		{
			_kit = kit;
			_content = content;
		}

		public void AddHeader(string text)
		{
			_kit.Text(_content, text, 1.15f, header: true);
		}

		public void AddSubheader(string text)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Subheader", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(_content, false);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			val.AddComponent<LayoutElement>().minHeight = 26f;
			TextMeshProUGUI val2 = _kit.Text(val.transform, text, 0.8f);
			((Graphic)val2).color = new Color(((Graphic)val2).color.r, ((Graphic)val2).color.g, ((Graphic)val2).color.b, 0.5f);
			((TMP_Text)val2).fontStyle = (FontStyles)(((TMP_Text)val2).fontStyle | 0x10);
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			GameObject val3 = new GameObject("Line", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(val.transform, false);
			LayoutElement obj2 = val3.AddComponent<LayoutElement>();
			obj2.flexibleWidth = 1f;
			obj2.flexibleHeight = 1f;
			RectTransform val4 = (RectTransform)((Component)UiKit.Rect(val3.transform, "Rule", UiKit.RuleColor)).transform;
			val4.anchorMin = new Vector2(0f, 0.5f);
			val4.anchorMax = new Vector2(1f, 0.5f);
			val4.sizeDelta = new Vector2(0f, 1f);
		}

		public void AddLabel(string text)
		{
			_kit.Text(_content, text, 0.85f);
		}

		public void AddToggle(string label, Func<bool> get, Action<bool> set, string description = null)
		{
			if ((Object)(object)_kit.ToggleTemplate == (Object)null)
			{
				Unsupported(label);
				return;
			}
			Toggle val = _kit.Clone<Toggle>(_kit.ToggleTemplate, _content, "Options Checkbox (" + label + ")");
			TMP_Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = label;
			}
			FixHeight(((Component)val).gameObject, ((Component)_kit.ToggleTemplate).transform, 28f);
			val.SetIsOnWithoutNotify(get());
			((UnityEvent<bool>)(object)val.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
			{
				set(v);
			});
			Describe(description);
		}

		public void AddSlider(string label, float min, float max, bool wholeNumbers, Func<float> get, Action<float> set, string description = null)
		{
			TMP_Text valueText = null;
			TMP_Text val = null;
			TMP_Text val2 = null;
			Slider val3;
			if ((Object)(object)_kit.SliderRowTemplate != (Object)null)
			{
				GameObject obj = _kit.CloneObject(_kit.SliderRowTemplate, _content, "Options Slider (" + label + ")");
				SetHeight(obj, 52f);
				val3 = obj.GetComponentInChildren<Slider>(true);
				LayOutSliderRow(obj, val3, label);
				SliderLabels componentInChildren = obj.GetComponentInChildren<SliderLabels>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Traverse val4 = Traverse.Create((object)componentInChildren);
					valueText = (TMP_Text)(object)val4.Field("currentLabel").GetValue<TextMeshProUGUI>();
					val = (TMP_Text)(object)val4.Field("minLabel").GetValue<TextMeshProUGUI>();
					val2 = (TMP_Text)(object)val4.Field("maxLabel").GetValue<TextMeshProUGUI>();
					val4.Field("currentLabel").SetValue((object)null);
					val4.Field("dontSyncMinMax").SetValue((object)true);
				}
			}
			else
			{
				if (!((Object)(object)_kit.SliderTemplate != (Object)null))
				{
					Unsupported(label);
					return;
				}
				Transform parent = Row(label);
				val3 = _kit.Clone<Slider>(_kit.SliderTemplate, parent, "Slider");
				UiKit.ClearTexts(((Component)val3).gameObject);
				UiKit.KeepSize((Component)(object)val3, (Component)(object)_kit.SliderTemplate);
				valueText = (TMP_Text)(object)_kit.Text(parent, "", 0.9f);
				LayoutElement obj2 = ((Component)valueText).gameObject.AddComponent<LayoutElement>();
				obj2.preferredWidth = 70f;
				obj2.flexibleWidth = 0f;
			}
			val3.wholeNumbers = wholeNumbers;
			val3.minValue = min;
			val3.maxValue = max;
			val3.SetValueWithoutNotify(get());
			if ((Object)(object)valueText != (Object)null)
			{
				valueText.text = Format(val3.value);
			}
			if ((Object)(object)val != (Object)null)
			{
				val.text = Format(min);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				val2.text = Format(max);
			}
			((UnityEvent<float>)(object)val3.onValueChanged).AddListener((UnityAction<float>)delegate(float v)
			{
				if ((Object)(object)valueText != (Object)null)
				{
					valueText.text = Format(v);
				}
				set(v);
			});
			Describe(description);
			string Format(float v)
			{
				if (!wholeNumbers)
				{
					return v.ToString("0.##");
				}
				return Mathf.RoundToInt(v).ToString();
			}
		}

		public void AddDropdown(string label, IList<string> options, Func<int> get, Action<int> set, string description = null)
		{
			if ((Object)(object)_kit.DropdownTemplate == (Object)null)
			{
				Unsupported(label);
				return;
			}
			Transform parent = Row(label);
			Dropdown obj = _kit.Clone<Dropdown>(_kit.DropdownTemplate, parent, "Dropdown");
			UiKit.KeepSize((Component)(object)obj, (Component)(object)_kit.DropdownTemplate);
			obj.ClearOptions();
			obj.AddOptions(options.ToList());
			obj.SetValueWithoutNotify(Mathf.Clamp(get(), 0, options.Count - 1));
			obj.RefreshShownValue();
			((UnityEvent<int>)(object)obj.onValueChanged).AddListener((UnityAction<int>)delegate(int i)
			{
				set(i);
			});
			Describe(description);
		}

		public void AddInput(string label, Func<string> get, Func<string, bool> set, string description = null)
		{
			if ((Object)(object)_kit.InputTemplate == (Object)null)
			{
				Unsupported(label);
				return;
			}
			Transform parent = Row(label);
			TMP_InputField input = _kit.Clone<TMP_InputField>(_kit.InputTemplate, parent, "Input");
			for (int num = ((Component)input).transform.childCount - 1; num >= 0; num--)
			{
				Transform child = ((Component)input).transform.GetChild(num);
				if ((Object)(object)child != (Object)(object)input.textViewport)
				{
					Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
				}
			}
			UiKit.KeepSize((Component)(object)input, (Component)(object)_kit.InputTemplate);
			input.SetTextWithoutNotify(get());
			((UnityEvent<string>)(object)input.onEndEdit).AddListener((UnityAction<string>)delegate(string text)
			{
				bool flag;
				try
				{
					flag = set(text);
				}
				catch
				{
					flag = false;
				}
				if (!flag)
				{
					input.SetTextWithoutNotify(get());
				}
			});
			Describe(description);
		}

		public void AddButton(string label, Action onClick, string description = null)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			if ((Object)(object)_kit.ButtonTemplate == (Object)null)
			{
				Unsupported(label);
				return;
			}
			Transform parent = Row(description ?? "");
			Button val = _kit.Clone<Button>(_kit.ButtonTemplate, parent, "Button");
			UiKit.KeepSize((Component)(object)val, (Component)(object)_kit.ButtonTemplate, 200f, 40f);
			TMP_Text[] componentsInChildren = ((Component)val).GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = label;
			}
			Text[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Text>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].text = label;
			}
			((UnityEvent)val.onClick).AddListener((UnityAction)delegate
			{
				onClick();
			});
		}

		public void AddConfigFile(ConfigFile config)
		{
			foreach (IGrouping<string, ConfigDefinition> item in from k in config.Keys
				group k by k.Section)
			{
				AddSubheader(Pretty(item.Key));
				foreach (ConfigDefinition item2 in item)
				{
					try
					{
						AddConfigEntry(config[item2]);
					}
					catch (Exception ex)
					{
						Plugin.ModLog.LogWarning((object)$"Mods tab: skipped {item2}: {ex.Message}");
					}
				}
			}
		}

		public void AddConfigEntry(ConfigEntryBase entry)
		{
			string label = Pretty(entry.Definition.Key);
			ConfigDescription description = entry.Description;
			string description2 = ((description != null) ? description.Description : null);
			Type type = entry.SettingType;
			ConfigDescription description3 = entry.Description;
			AcceptableValueBase acceptable = ((description3 != null) ? description3.AcceptableValues : null);
			if (type == typeof(bool))
			{
				AddToggle(label, () => (bool)entry.BoxedValue, delegate(bool v)
				{
					entry.BoxedValue = v;
				}, description2);
			}
			else if (type.IsEnum)
			{
				string[] names = Enum.GetNames(type);
				AddDropdown(label, names.Select(Pretty).ToList(), () => Array.IndexOf<string>(names, entry.BoxedValue.ToString()), delegate(int i)
				{
					entry.BoxedValue = Enum.Parse(type, names[i]);
				}, description2);
			}
			else if (acceptable != null && ((object)acceptable).GetType().Name.StartsWith("AcceptableValueRange") && (type == typeof(float) || type == typeof(int) || type == typeof(double)))
			{
				float min = Convert.ToSingle(((object)acceptable).GetType().GetProperty("MinValue").GetValue(acceptable));
				float max = Convert.ToSingle(((object)acceptable).GetType().GetProperty("MaxValue").GetValue(acceptable));
				AddSlider(label, min, max, type == typeof(int), () => Convert.ToSingle(entry.BoxedValue), delegate(float v)
				{
					entry.BoxedValue = Convert.ChangeType((type == typeof(int)) ? Mathf.Round(v) : v, type);
				}, description2);
			}
			else if (acceptable != null && ((object)acceptable).GetType().Name.StartsWith("AcceptableValueList"))
			{
				List<object> values = ((Array)((object)acceptable).GetType().GetProperty("AcceptableValues").GetValue(acceptable)).Cast<object>().ToList();
				AddDropdown(label, values.Select((object v) => v.ToString()).ToList(), () => values.FindIndex((object v) => object.Equals(v, entry.BoxedValue)), delegate(int i)
				{
					entry.BoxedValue = values[i];
				}, description2);
			}
			else if (TomlTypeConverter.CanConvert(type))
			{
				AddInput(label, (Func<string>)entry.GetSerializedValue, (Func<string, bool>)delegate(string text)
				{
					object obj = TomlTypeConverter.ConvertToValue(text, type);
					if (acceptable != null && !acceptable.IsValid(obj))
					{
						return false;
					}
					entry.BoxedValue = obj;
					return true;
				}, description2);
			}
			else
			{
				Unsupported(label);
			}
		}

		private Transform Row(string label)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			GameObject val = new GameObject("Row", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(_content, false);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 16f;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			val.AddComponent<LayoutElement>().minHeight = 36f;
			((Component)_kit.Text(val.transform, label)).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			return val.transform;
		}

		private void Describe(string description)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrEmpty(description))
			{
				TextMeshProUGUI val = _kit.Text(_content, description, 0.75f);
				((Graphic)val).color = new Color(((Graphic)val).color.r, ((Graphic)val).color.g, ((Graphic)val).color.b, 0.55f);
				((TMP_Text)val).margin = new Vector4(32f, 0f, 0f, 6f);
			}
		}

		private static void FixHeight(GameObject go, Transform template, float fallback)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = ((RectTransform)template).rect;
			float height = ((Rect)(ref rect)).height;
			SetHeight(go, (height > 1f) ? (height + 8f) : fallback);
		}

		private static void SetHeight(GameObject go, float height)
		{
			LayoutElement obj = go.GetComponent<LayoutElement>() ?? go.AddComponent<LayoutElement>();
			float preferredHeight = (obj.minHeight = height);
			obj.preferredHeight = preferredHeight;
		}

		private static void LayOutSliderRow(GameObject row, Slider slider, string label)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)((Component)slider).transform;
			val.anchoredPosition = new Vector2(-48f, -8f);
			float x = ((Transform)val).localScale.x;
			Rect rect = val.rect;
			float num = ((Rect)(ref rect)).width * val.pivot.x * x;
			SliderLabels component = ((Component)slider).GetComponent<SliderLabels>();
			TextMeshProUGUI val2 = (((Object)(object)component != (Object)null) ? Traverse.Create((object)component).Field("minLabel").GetValue<TextMeshProUGUI>() : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)((TMP_Text)val2).transform.parent == (Object)(object)val)
			{
				RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
				rect = val.rect;
				float num2 = ((Rect)(ref rect)).width * (val.pivot.x - rectTransform.anchorMin.x);
				float x2 = rectTransform.anchoredPosition.x;
				rect = rectTransform.rect;
				float num3 = 0f - (x2 - ((Rect)(ref rect)).width * rectTransform.pivot.x);
				num = Mathf.Max(num, (num2 + num3) * x);
			}
			TMP_Text val3 = UiKit.FindRowLabel(row.transform);
			val3.text = label;
			RectTransform rectTransform2 = val3.rectTransform;
			rectTransform2.anchorMin = new Vector2(0f, 0.5f);
			rectTransform2.anchorMax = new Vector2(1f, 0.5f);
			rectTransform2.pivot = new Vector2(0f, 0.5f);
			rectTransform2.sizeDelta = new Vector2(0f - (48f + num + 8f), 36f);
			rectTransform2.anchoredPosition = new Vector2(0f, -8f);
			val3.textWrappingMode = (TextWrappingModes)1;
			val3.fontSizeMax = val3.fontSize;
			val3.fontSizeMin = Mathf.Min(11f, val3.fontSize);
			val3.enableAutoSizing = true;
		}

		private void Unsupported(string label)
		{
			AddLabel(label + ": <alpha=#99>edit in the mod's .cfg file");
		}

		internal static string Pretty(string key)
		{
			return WordBreak.Replace(key ?? "", " ").Replace('_', ' ');
		}
	}
	internal sealed class UiKit
	{
		private static readonly HashSet<string> LocalizationComponents = new HashSet<string> { "LocalizedObject", "ManualLocalization", "LocalizationSetting", "PrefabLocalizer" };

		public Toggle ToggleTemplate;

		public GameObject SliderRowTemplate;

		public Slider SliderTemplate;

		public Dropdown DropdownTemplate;

		public TMP_InputField InputTemplate;

		public Button ButtonTemplate;

		public TextMeshProUGUI LabelStyle;

		public TextMeshProUGUI HeaderStyle;

		public Color HeaderColor = Color.white;

		public static readonly Color CardColor = Hex(1314573);

		public static readonly Color BarColor = Hex(2826523);

		public static readonly Color BarHoverColor = Hex(3681059);

		public static readonly Color BarPressedColor = Hex(4338474);

		public static readonly Color BarSelectedColor = Hex(3221024);

		public static readonly Color RuleColor = Hex(5523517);

		private (string closed, string open)? _foldGlyphs;

		public (string closed, string open) FoldGlyphs
		{
			get
			{
				if (_foldGlyphs.HasValue)
				{
					return _foldGlyphs.Value;
				}
				TextMeshProUGUI obj = HeaderStyle ?? LabelStyle;
				TMP_FontAsset font = ((obj != null) ? ((TMP_Text)obj).font : null);
				if (Has('▸') && Has('▾'))
				{
					_foldGlyphs = ("▸", "▾");
				}
				else if (Has('►') && Has('▼'))
				{
					_foldGlyphs = ("►", "▼");
				}
				else
				{
					_foldGlyphs = ("+", "-");
				}
				ManualLogSource modLog = Plugin.ModLog;
				string[] obj2 = new string[7]
				{
					"Mods tab fold markers: '",
					_foldGlyphs.Value.closed,
					"' / '",
					_foldGlyphs.Value.open,
					"' (font ",
					null,
					null
				};
				TMP_FontAsset obj3 = font;
				obj2[5] = ((obj3 != null) ? ((Object)obj3).name : null) ?? "none";
				obj2[6] = ").";
				modLog.LogInfo((object)string.Concat(obj2));
				return _foldGlyphs.Value;
				bool Has(char c)
				{
					if ((Object)(object)font != (Object)null)
					{
						return font.HasCharacter(c, true, true);
					}
					return false;
				}
			}
		}

		public static Color Hex(int rgb)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)((rgb >> 16) & 0xFF) / 255f, (float)((rgb >> 8) & 0xFF) / 255f, (float)(rgb & 0xFF) / 255f);
		}

		public static UiKit FromOptions(OptionsManager om, MenuTab twitchTab, MenuTabManager tabs)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)om);
			UiKit uiKit = new UiKit
			{
				ToggleTemplate = val.Field("screenShakeToggle").GetValue<Toggle>(),
				SliderTemplate = val.Field("masterSlider").GetValue<Slider>(),
				DropdownTemplate = val.Field("qualityDropDown").GetValue<Dropdown>(),
				InputTemplate = val.Field("twitchServerNameInputField").GetValue<TMP_InputField>(),
				ButtonTemplate = val.Field("twitchChannelConnectButton").GetValue<Button>(),
				HeaderStyle = (((Object)(object)twitchTab != (Object)null) ? twitchTab.TextMeshProUGUI : null)
			};
			if ((Object)(object)tabs != (Object)null)
			{
				uiKit.HeaderColor = Traverse.Create((object)tabs).Field("SelectedColor").GetValue<Color>();
			}
			Slider value = val.Field("twitchVotingTimeSlider").GetValue<Slider>();
			Transform val2 = (((Object)(object)value != (Object)null) ? ((Component)value).transform.parent : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)FindRowLabel(val2) != (Object)null)
			{
				uiKit.SliderRowTemplate = ((Component)val2).gameObject;
			}
			GameObject value2 = val.Field("gameplayPanel").GetValue<GameObject>();
			if ((Object)(object)value2 != (Object)null)
			{
				TextMeshProUGUI[] componentsInChildren = value2.GetComponentsInChildren<TextMeshProUGUI>(true);
				foreach (TextMeshProUGUI val3 in componentsInChildren)
				{
					if ((Object)(object)((Component)val3).GetComponentInParent<Selectable>() == (Object)null && !string.IsNullOrWhiteSpace(((TMP_Text)val3).text))
					{
						uiKit.LabelStyle = val3;
						break;
					}
				}
			}
			return uiKit;
		}

		public static TMP_Text FindRowLabel(Transform row)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in row)
			{
				TMP_Text component = ((Component)item).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null)
				{
					return component;
				}
			}
			return null;
		}

		public GameObject CloneObject(GameObject template, Transform parent, string name)
		{
			GameObject obj = Object.Instantiate<GameObject>(template, parent, false);
			((Object)obj).name = name;
			Sanitize(obj);
			obj.SetActive(true);
			return obj;
		}

		public T Clone<T>(T template, Transform parent, string name) where T : Component
		{
			GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, parent, false);
			((Object)obj).name = name;
			Sanitize(obj);
			obj.SetActive(true);
			return obj.GetComponent<T>();
		}

		public static void Sanitize(GameObject root)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if (LocalizationComponents.Contains(((object)val).GetType().Name))
				{
					Object.DestroyImmediate((Object)(object)val);
					continue;
				}
				Toggle val2 = (Toggle)(object)((val is Toggle) ? val : null);
				if (val2 == null)
				{
					Slider val3 = (Slider)(object)((val is Slider) ? val : null);
					if (val3 == null)
					{
						Dropdown val4 = (Dropdown)(object)((val is Dropdown) ? val : null);
						if (val4 == null)
						{
							Button val5 = (Button)(object)((val is Button) ? val : null);
							if (val5 == null)
							{
								TMP_InputField val6 = (TMP_InputField)(object)((val is TMP_InputField) ? val : null);
								if (val6 == null)
								{
									EventTrigger val7 = (EventTrigger)(object)((val is EventTrigger) ? val : null);
									if (val7 != null)
									{
										val7.triggers.RemoveAll((Entry e) => TargetsOptions((UnityEventBase)(object)e.callback));
									}
								}
								else
								{
									val6.onValueChanged = new OnChangeEvent();
									val6.onEndEdit = new SubmitEvent();
									val6.onSubmit = new SubmitEvent();
									val6.onSelect = new SelectionEvent();
									val6.onDeselect = new SelectionEvent();
								}
							}
							else
							{
								val5.onClick = new ButtonClickedEvent();
							}
						}
						else
						{
							val4.onValueChanged = new DropdownEvent();
						}
					}
					else
					{
						val3.onValueChanged = new SliderEvent();
					}
				}
				else
				{
					val2.onValueChanged = new ToggleEvent();
				}
			}
		}

		private static bool TargetsOptions(UnityEventBase evt)
		{
			for (int i = 0; i < evt.GetPersistentEventCount(); i++)
			{
				if (evt.GetPersistentTarget(i) is OptionsManager)
				{
					return true;
				}
			}
			return false;
		}

		public TextMeshProUGUI Text(Transform parent, string text, float sizeScale = 1f, bool header = false)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(header ? "Header" : "Label", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			TextMeshProUGUI val3 = (header ? (HeaderStyle ?? LabelStyle) : (LabelStyle ?? HeaderStyle));
			if ((Object)(object)val3 != (Object)null)
			{
				((TMP_Text)val2).font = ((TMP_Text)val3).font;
				((TMP_Text)val2).fontSharedMaterial = ((TMP_Text)val3).fontSharedMaterial;
				((TMP_Text)val2).fontSize = ((TMP_Text)val3).fontSize * sizeScale;
				((TMP_Text)val2).fontStyle = ((TMP_Text)val3).fontStyle;
				((Graphic)val2).color = (header ? HeaderColor : ((Graphic)val3).color);
			}
			else
			{
				((TMP_Text)val2).fontSize = 24f * sizeScale;
			}
			((TMP_Text)val2).richText = true;
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)1;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)val2).text = text;
			return val2;
		}

		public static void ClearTexts(GameObject go)
		{
			TMP_Text[] componentsInChildren = go.GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = "";
			}
			Text[] componentsInChildren2 = go.GetComponentsInChildren<Text>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].text = "";
			}
		}

		public static Image Rect(Transform parent, string name, Color color)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			Image obj = val.AddComponent<Image>();
			((Graphic)obj).color = color;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		public static void ClearChildren(Transform parent)
		{
			for (int num = parent.childCount - 1; num >= 0; num--)
			{
				GameObject gameObject = ((Component)parent.GetChild(num)).gameObject;
				gameObject.SetActive(false);
				Object.Destroy((Object)(object)gameObject);
			}
		}

		public static void KeepSize(Component control, Component template, float fallbackW = 220f, float fallbackH = 32f)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = ((RectTransform)template.transform).rect;
			LayoutElement obj = control.gameObject.GetComponent<LayoutElement>() ?? control.gameObject.AddComponent<LayoutElement>();
			obj.preferredWidth = ((((Rect)(ref rect)).width > 1f) ? ((Rect)(ref rect)).width : fallbackW);
			obj.preferredHeight = ((((Rect)(ref rect)).height > 1f) ? ((Rect)(ref rect)).height : fallbackH);
			obj.flexibleWidth = 0f;
		}
	}
	internal static class UiLayoutLogger
	{
		private static bool _done;

		public static void LogOnce(OptionsManager options, MenuTab twitchTab, GameObject twitchPanel)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (_done)
			{
				return;
			}
			_done = true;
			StringBuilder stringBuilder = new StringBuilder("Options window layout (Mods Menu debug; turn off with [Debug] LogUiLayout):\n");
			stringBuilder.AppendLine("-- Tab bar");
			Dump(stringBuilder, ((Component)twitchTab).transform.parent, 0, 2);
			stringBuilder.AppendLine("-- Twitch panel");
			Dump(stringBuilder, twitchPanel.transform, 0, 4);
			GameObject value = Traverse.Create((object)options).Field("gameplayPanel").GetValue<GameObject>();
			if ((Object)(object)value != (Object)null)
			{
				stringBuilder.AppendLine("-- Gameplay panel");
				Dump(stringBuilder, value.transform, 0, 4);
			}
			Dropdown value2 = Traverse.Create((object)options).Field("qualityDropDown").GetValue<Dropdown>();
			if ((Object)(object)value2 != (Object)null)
			{
				Transform parent = ((Component)value2).transform.parent;
				RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				string arg = ((val != null) ? ((Object)val).name : null);
				float? obj;
				Rect rect;
				if (val == null)
				{
					obj = null;
				}
				else
				{
					rect = val.rect;
					obj = ((Rect)(ref rect)).width;
				}
				object arg2 = obj;
				float? obj2;
				if (val == null)
				{
					obj2 = null;
				}
				else
				{
					rect = val.rect;
					obj2 = ((Rect)(ref rect)).height;
				}
				stringBuilder.AppendLine($"-- Quality dropdown (in {arg} [{arg2:0}x{obj2:0}])");
				Dump(stringBuilder, ((Component)value2).transform, 0, 3);
			}
			Plugin.ModLog.LogInfo((object)stringBuilder.ToString());
		}

		private static void Dump(StringBuilder sb, Transform t, int depth, int maxDepth)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
			object obj;
			if (!((Object)(object)val != (Object)null))
			{
				obj = "";
			}
			else
			{
				Rect rect = val.rect;
				object arg = ((Rect)(ref rect)).width;
				rect = val.rect;
				obj = $" [{arg:0}x{((Rect)(ref rect)).height:0}]";
			}
			string value = (string)obj;
			string value2 = string.Join(", ", from c in ((Component)t).GetComponents<Component>()
				where (Object)(object)c != (Object)null && !(c is Transform)
				select ((object)c).GetType().Name);
			string value3 = "";
			TMP_Text component = ((Component)t).GetComponent<TMP_Text>();
			if ((Object)(object)component != (Object)null)
			{
				value3 = " \"" + Shorten(component.text) + "\"";
			}
			sb.Append(' ', depth * 2).Append(((Object)t).name).Append(((Component)t).gameObject.activeSelf ? "" : " (inactive)")
				.Append(value)
				.Append(" {")
				.Append(value2)
				.Append('}')
				.AppendLine(value3);
			if (depth >= maxDepth)
			{
				return;
			}
			foreach (Transform item in t)
			{
				Transform t2 = item;
				Dump(sb, t2, depth + 1, maxDepth);
			}
		}

		private static string Shorten(string s)
		{
			if (s != null)
			{
				return ((s.Length > 40) ? (s.Substring(0, 40) + "…") : s).Replace("\n", " ");
			}
			return "";
		}
	}
}