Decompiled source of ModList v0.5.2

ModList.dll

Decompiled an hour 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.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyVersion("0.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 ModList
{
	[HarmonyPatch(typeof(UIManager), "CloseCurrentUIScreen")]
	internal static class CloseCurrentUIScreenPatch
	{
		private static bool Prefix()
		{
			return !ModListScreen.TryGoBack();
		}
	}
	internal static class ConfigEditor
	{
		private sealed class NumericRange
		{
			internal Type Type;

			internal IComparable Min;

			internal IComparable Max;

			internal bool Floating;

			internal bool AllowNegative;
		}

		private sealed class EntryControl
		{
			internal GameObject Root;

			internal Selectable Selectable;

			internal Action Refresh;
		}

		private static ManualLogSource log;

		internal static void Initialize(ManualLogSource logger)
		{
			log = logger;
		}

		internal static int CountEntries(PluginInfo info)
		{
			return GetVisibleEntries(info).Count;
		}

		internal static void Populate(PluginInfo info)
		{
			UiFactory.AddText(heading: false, "<alpha=#99>Changes are written to the .cfg file right away. Some mods only read their settings at startup, so restart the game for those.<alpha=#FF>");
			List<string> list = new List<string>();
			Dictionary<string, List<ConfigEntryBase>> dictionary = new Dictionary<string, List<ConfigEntryBase>>();
			foreach (ConfigEntryBase visibleEntry in GetVisibleEntries(info))
			{
				string section = visibleEntry.Definition.Section;
				if (!dictionary.ContainsKey(section))
				{
					dictionary[section] = new List<ConfigEntryBase>();
					list.Add(section);
				}
				dictionary[section].Add(visibleEntry);
			}
			foreach (string item in list)
			{
				UiFactory.AddText(heading: false, "<b><size=120%>" + UiFactory.Plain(item) + "</size></b>");
				foreach (ConfigEntryBase item2 in dictionary[item].OrderByDescending(OrderOf))
				{
					AddEntry(item2);
				}
			}
		}

		private static List<ConfigEntryBase> GetVisibleEntries(PluginInfo info)
		{
			List<ConfigEntryBase> list = new List<ConfigEntryBase>();
			if ((Object)(object)info.Instance == (Object)null || info.Instance.Config == null)
			{
				return list;
			}
			ConfigFile config = info.Instance.Config;
			foreach (ConfigDefinition item in new List<ConfigDefinition>(config.Keys))
			{
				ConfigEntryBase val = config[item];
				if (IsBrowsable(val))
				{
					list.Add(val);
				}
			}
			return list;
		}

		private static object ReadTag(ConfigEntryBase entry, string fieldName)
		{
			object[] array = ((entry.Description != null) ? entry.Description.Tags : null);
			if (array == null)
			{
				return null;
			}
			object[] array2 = array;
			foreach (object obj in array2)
			{
				if (obj == null)
				{
					continue;
				}
				FieldInfo field = obj.GetType().GetField(fieldName);
				if (!(field == null))
				{
					object value = field.GetValue(obj);
					if (value != null)
					{
						return value;
					}
				}
			}
			return null;
		}

		private static bool IsBrowsable(ConfigEntryBase entry)
		{
			object obj = ReadTag(entry, "Browsable");
			bool flag = default(bool);
			int num;
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return num == 0 || flag;
		}

		private static bool IsReadOnly(ConfigEntryBase entry)
		{
			object obj = ReadTag(entry, "ReadOnly");
			bool flag = default(bool);
			int num;
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		private static int OrderOf(ConfigEntryBase entry)
		{
			object obj = ReadTag(entry, "Order");
			if (obj is int)
			{
				return (int)obj;
			}
			return 0;
		}

		private static void AddEntry(ConfigEntryBase entry)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			string labelText = "<b>" + UiFactory.Plain(entry.Definition.Key) + "</b>" + Details(entry);
			EntryControl control = CreateControl(entry);
			if (IsReadOnly(entry))
			{
				control.Selectable.interactable = false;
				UiFactory.AddEntryRow(labelText, control.Root);
				return;
			}
			Button val = UiFactory.CreateSmallButton("Reset", (UnityAction)delegate
			{
				Apply(entry, entry.DefaultValue);
				control.Refresh();
			});
			UiFactory.AddEntryRow(labelText, control.Root, ((Component)val).gameObject);
		}

		private static void Commit(ConfigEntryBase entry)
		{
			if (!entry.ConfigFile.SaveOnConfigSet)
			{
				entry.ConfigFile.Save();
			}
		}

		private static void Apply(ConfigEntryBase entry, object value)
		{
			try
			{
				entry.BoxedValue = value;
				Commit(entry);
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("Could not change " + entry.Definition.Key + ": " + ex.Message));
			}
		}

		private static string Details(ConfigEntryBase entry)
		{
			string text = string.Empty;
			if (entry.Description != null && !string.IsNullOrEmpty(entry.Description.Description))
			{
				text = UiFactory.Plain(entry.Description.Description);
			}
			string text2 = DefaultText(entry);
			if (text2 != null)
			{
				text = text + ((text.Length > 0) ? "  " : string.Empty) + "Default: " + UiFactory.Plain(text2);
			}
			string text3 = RangeText(entry);
			if (text3 != null)
			{
				text = text + ((text.Length > 0) ? "  " : string.Empty) + "Range: " + UiFactory.Plain(text3);
			}
			if (text.Length != 0)
			{
				return "\n<size=70%><alpha=#99>" + text + "<alpha=#FF></size>";
			}
			return string.Empty;
		}

		private static string DefaultText(ConfigEntryBase entry)
		{
			try
			{
				return TomlTypeConverter.ConvertToString(entry.DefaultValue, entry.SettingType);
			}
			catch
			{
				return null;
			}
		}

		private static string RangeText(ConfigEntryBase entry)
		{
			try
			{
				NumericRange range = GetRange(entry);
				if (range == null)
				{
					return null;
				}
				return TomlTypeConverter.ConvertToString((object)range.Min, range.Type) + " to " + TomlTypeConverter.ConvertToString((object)range.Max, range.Type);
			}
			catch
			{
				return null;
			}
		}

		private static EntryControl CreateControl(ConfigEntryBase entry)
		{
			if (entry.SettingType == typeof(bool) && UiFactory.HasToggle)
			{
				return CreateToggle(entry);
			}
			List<object> options = GetOptions(entry);
			if (options == null)
			{
				return CreateInput(entry);
			}
			return CreateCycleButton(entry, options);
		}

		private static EntryControl CreateToggle(ConfigEntryBase entry)
		{
			Toggle toggle = UiFactory.CreateControlToggle((bool)entry.BoxedValue, delegate(bool isOn)
			{
				Apply(entry, isOn);
			});
			return new EntryControl
			{
				Root = ((Component)toggle).gameObject,
				Selectable = (Selectable)(object)toggle,
				Refresh = delegate
				{
					toggle.SetIsOnWithoutNotify((bool)entry.BoxedValue);
				}
			};
		}

		private static List<object> GetOptions(ConfigEntryBase entry)
		{
			Type settingType = entry.SettingType;
			if (settingType == typeof(bool))
			{
				return new List<object> { false, true };
			}
			if (settingType.IsEnum && !settingType.IsDefined(typeof(FlagsAttribute), inherit: false))
			{
				List<object> list = new List<object>();
				{
					foreach (object value in Enum.GetValues(settingType))
					{
						list.Add(value);
					}
					return list;
				}
			}
			AcceptableValueBase val = ((entry.Description != null) ? entry.Description.AcceptableValues : null);
			if (val != null && ((object)val).GetType().Name.StartsWith("AcceptableValueList"))
			{
				PropertyInfo property = ((object)val).GetType().GetProperty("AcceptableValues");
				Array array = ((property != null) ? (property.GetValue(val, null) as Array) : null);
				if (array != null && array.Length > 0)
				{
					List<object> list2 = new List<object>();
					{
						foreach (object item in array)
						{
							list2.Add(item);
						}
						return list2;
					}
				}
			}
			return null;
		}

		private static EntryControl CreateCycleButton(ConfigEntryBase entry, List<object> options)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Button button = null;
			button = UiFactory.CreateControlButton(entry.GetSerializedValue(), (UnityAction)delegate
			{
				int num = IndexOf(options, entry.BoxedValue);
				Apply(entry, options[(num + 1) % options.Count]);
				UiFactory.SetButtonLabel(button, entry.GetSerializedValue());
			});
			return new EntryControl
			{
				Root = ((Component)button).gameObject,
				Selectable = (Selectable)(object)button,
				Refresh = delegate
				{
					UiFactory.SetButtonLabel(button, entry.GetSerializedValue());
				}
			};
		}

		private static int IndexOf(List<object> options, object current)
		{
			for (int i = 0; i < options.Count; i++)
			{
				if (object.Equals(options[i], current))
				{
					return i;
				}
			}
			return -1;
		}

		private static EntryControl CreateInput(ConfigEntryBase entry)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			NumericRange range = GetRange(entry);
			TMP_InputField input = null;
			input = UiFactory.CreateInputField(entry.GetSerializedValue(), delegate(string text)
			{
				if (range != null)
				{
					text = ClampText(text, range);
				}
				if (text != entry.GetSerializedValue())
				{
					try
					{
						entry.SetSerializedValue(text);
						Commit(entry);
					}
					catch (Exception ex)
					{
						log.LogWarning((object)("Could not set " + entry.Definition.Key + " to \"" + text + "\": " + ex.Message));
					}
				}
				input.SetTextWithoutNotify(entry.GetSerializedValue());
			});
			if (range != null)
			{
				input.onValidateInput = (OnValidateInput)((string text, int index, char added) => ValidateChar(input, range, text, index, added));
			}
			return new EntryControl
			{
				Root = ((Component)input).gameObject,
				Selectable = (Selectable)(object)input,
				Refresh = delegate
				{
					input.SetTextWithoutNotify(entry.GetSerializedValue());
				}
			};
		}

		private static bool IsNumeric(Type type)
		{
			if (!(type == typeof(sbyte)) && !(type == typeof(byte)) && !(type == typeof(short)) && !(type == typeof(ushort)) && !(type == typeof(int)) && !(type == typeof(uint)) && !(type == typeof(long)) && !(type == typeof(ulong)) && !(type == typeof(float)) && !(type == typeof(double)))
			{
				return type == typeof(decimal);
			}
			return true;
		}

		private static NumericRange GetRange(ConfigEntryBase entry)
		{
			if (!IsNumeric(entry.SettingType))
			{
				return null;
			}
			AcceptableValueBase val = ((entry.Description != null) ? entry.Description.AcceptableValues : null);
			if (val == null || !((object)val).GetType().Name.StartsWith("AcceptableValueRange"))
			{
				return null;
			}
			PropertyInfo property = ((object)val).GetType().GetProperty("MinValue");
			PropertyInfo property2 = ((object)val).GetType().GetProperty("MaxValue");
			if (property == null || property2 == null)
			{
				return null;
			}
			IComparable comparable = property.GetValue(val, null) as IComparable;
			IComparable comparable2 = property2.GetValue(val, null) as IComparable;
			if (comparable == null || comparable2 == null)
			{
				return null;
			}
			Type settingType = entry.SettingType;
			object obj = TomlTypeConverter.ConvertToValue("0", settingType);
			return new NumericRange
			{
				Type = settingType,
				Min = comparable,
				Max = comparable2,
				Floating = (settingType == typeof(float) || settingType == typeof(double) || settingType == typeof(decimal)),
				AllowNegative = (comparable.CompareTo(obj) < 0)
			};
		}

		private static char ValidateChar(TMP_InputField input, NumericRange range, string text, int index, char added)
		{
			int num = Math.Min(input.selectionStringAnchorPosition, input.selectionStringFocusPosition);
			int num2 = Math.Max(input.selectionStringAnchorPosition, input.selectionStringFocusPosition);
			if (num < 0 || num2 > text.Length)
			{
				num = Math.Max(0, Math.Min(index, text.Length));
				num2 = num;
			}
			if (!IsAllowedPrefix(text.Remove(num, num2 - num).Insert(num, added.ToString()), range))
			{
				return '\0';
			}
			return added;
		}

		private static bool IsAllowedPrefix(string candidate, NumericRange range)
		{
			int i = 0;
			if (candidate.Length > 0 && candidate[0] == '-')
			{
				if (!range.AllowNegative)
				{
					return false;
				}
				i = 1;
			}
			bool flag = false;
			bool flag2 = false;
			for (; i < candidate.Length; i++)
			{
				char c = candidate[i];
				if (c >= '0' && c <= '9')
				{
					flag = true;
					continue;
				}
				if (c == '.' && range.Floating && !flag2)
				{
					flag2 = true;
					continue;
				}
				return false;
			}
			if (!flag)
			{
				return true;
			}
			object obj;
			try
			{
				obj = TomlTypeConverter.ConvertToValue(candidate, range.Type);
			}
			catch
			{
				return false;
			}
			return range.Max.CompareTo(obj) >= 0;
		}

		private static string ClampText(string text, NumericRange range)
		{
			object obj;
			try
			{
				obj = TomlTypeConverter.ConvertToValue(text, range.Type);
			}
			catch
			{
				return text;
			}
			if (range.Min.CompareTo(obj) > 0)
			{
				obj = range.Min;
			}
			else
			{
				if (range.Max.CompareTo(obj) >= 0)
				{
					return text;
				}
				obj = range.Max;
			}
			return TomlTypeConverter.ConvertToString(obj, range.Type);
		}
	}
	[HarmonyPatch(typeof(StartMenuUGUI), "RegisterCallbacks")]
	internal static class StartMenuButtonPatch
	{
		private static void Postfix(StartMenuUGUI __instance)
		{
			ModsButtonInjector.Inject(ModsButtonInjector.StartMenuProgressField, (MonoBehaviour)(object)__instance);
		}
	}
	[HarmonyPatch(typeof(PauseScreenUGui), "RegisterCallbacks")]
	internal static class PauseMenuButtonPatch
	{
		private static void Postfix(PauseScreenUGui __instance)
		{
			ModsButtonInjector.Inject(ModsButtonInjector.PauseMenuProgressField, (MonoBehaviour)(object)__instance);
		}
	}
	internal static class ModListScreen
	{
		private const string ScreenName = "ModListScreen";

		private const string ScreenTitle = "Mod List";

		private const string HeadingText = "Installed Mods";

		private const float RowSpacing = 18f;

		private const float WidthFraction = 0.85f;

		private const float ScrollbarMargin = 30f;

		private const int ContentPadding = 40;

		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private const string DumpHint = "";

		private static readonly FieldInfo RootTransformField = typeof(UIScreenUGUI).GetField("rootTransform", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo CurrentScreenField = typeof(UIManager).GetField("currentScreen", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo AllScreensField = typeof(UIManager).GetField("allScreens", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo BackButtonField = typeof(CreditsScreenUGUI).GetField("m_BackButton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly string[] SettingsToggleFields = new string[4] { "toggleFullscreen", "toggleCameraMotion", "toggleFastMode", "toggleShowTutorialsAgain" };

		private static readonly MethodInfo ShowMethod = typeof(UIManager).GetMethod("Show", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
		{
			typeof(UIScreenUGUI),
			typeof(bool)
		}, null);

		private static ManualLogSource log;

		private static ConfigEntry<bool> dumpHierarchy;

		private static bool buildFailed;

		private static bool inConfig;

		private static float appliedCanvasWidth;

		private static CreditsScreenUGUI screen;

		private static RectTransform panelRoot;

		private static RectTransform content;

		private static ScrollRect scroll;

		internal static void Initialize(ManualLogSource logger, ConfigEntry<bool> dump)
		{
			log = logger;
			dumpHierarchy = dump;
			ConfigEditor.Initialize(logger);
			if (RootTransformField == null || AllScreensField == null || ShowMethod == null)
			{
				log.LogWarning((object)"UIManager or UIScreenUGUI members were not found, the mod list cannot open.");
			}
		}

		internal static void Open()
		{
			if ((Object)(object)Main.UIManager == (Object)null || RootTransformField == null || AllScreensField == null || ShowMethod == null)
			{
				log.LogWarning((object)"The UI manager is not ready, the mod list cannot open.");
			}
			else if (!((Object)(object)screen == (Object)null) || Build())
			{
				Register();
				Widen(panelRoot, scroll);
				ShowList(focus: false);
				ShowMethod.Invoke(Main.UIManager, new object[2] { screen, true });
			}
		}

		internal static bool TryGoBack()
		{
			if (!inConfig || (Object)(object)screen == (Object)null || (Object)(object)Main.UIManager == (Object)null || CurrentScreenField == null)
			{
				return false;
			}
			object? value = CurrentScreenField.GetValue(Main.UIManager);
			if ((Object)((value is UIScreenUGUI) ? value : null) != (Object)(object)screen)
			{
				return false;
			}
			ShowList(focus: true);
			return true;
		}

		[Conditional("DEBUG")]
		private static void DumpIfEnabled(Transform root)
		{
		}

		private static bool Build()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			if (buildFailed)
			{
				return false;
			}
			appliedCanvasWidth = 0f;
			CreditsScreenUGUI val = FindSource();
			if ((Object)(object)val == (Object)null)
			{
				return Fail("The credits screen was not found.");
			}
			object? value = RootTransformField.GetValue(val);
			RectTransform val2 = (RectTransform)((value is RectTransform) ? value : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return Fail("The credits screen has no root panel.");
			}
			GameObject val3 = new GameObject("ModListHolder", new Type[1] { typeof(RectTransform) });
			val3.SetActive(false);
			GameObject val4 = null;
			GameObject val5 = null;
			try
			{
				val4 = Object.Instantiate<GameObject>(((Component)val).gameObject, val3.transform);
				((Object)val4).name = "ModListScreen";
				CreditsScreenUGUI component = val4.GetComponent<CreditsScreenUGUI>();
				RectTransform val6;
				if (((Transform)val2).IsChildOf(((Component)val).transform))
				{
					object? value2 = RootTransformField.GetValue(component);
					val6 = (RectTransform)((value2 is RectTransform) ? value2 : null);
				}
				else
				{
					val5 = Object.Instantiate<GameObject>(((Component)val2).gameObject, val3.transform);
					((Object)val5).name = "ModListScreenPanel";
					val6 = (RectTransform)val5.transform;
					Remap(component, (Transform)(object)val2, (Transform)(object)val6);
					RootTransformField.SetValue(component, val6);
				}
				if ((Object)(object)val6 == (Object)null || (Object)(object)((Component)val6).gameObject == (Object)(object)val4)
				{
					return Fail("The credits screen layout is not supported.");
				}
				ScrollRect componentInChildren = ((Component)val6).GetComponentInChildren<ScrollRect>(true);
				if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.content == (Object)null)
				{
					return Fail("The credits panel has no scroll view to reuse.");
				}
				Button val7 = (Button)((BackButtonField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val7 == (Object)null)
				{
					return Fail("The credits screen has no Back button to copy the style from.");
				}
				TMP_Text[] componentsInChildren = ((Component)componentInChildren.content).GetComponentsInChildren<TMP_Text>(true);
				if (componentsInChildren.Length == 0)
				{
					return Fail("The credits scroll view has no text to copy the style from.");
				}
				Array.Sort(componentsInChildren, (TMP_Text a, TMP_Text b) => a.fontSize.CompareTo(b.fontSize));
				GameObject heading = CreateTemplate(((Component)componentsInChildren[^1]).gameObject, val4.transform);
				GameObject body = CreateTemplate(((Component)componentsInChildren[componentsInChildren.Length / 2]).gameObject, val4.transform);
				GameObject button = CreateTemplate(((Component)val7).gameObject, val4.transform);
				GameObject toggle = null;
				Toggle val8 = FindSettingsToggle();
				if ((Object)(object)val8 != (Object)null)
				{
					toggle = CreateTemplate(((Component)val8).gameObject, val4.transform);
				}
				else
				{
					log.LogWarning((object)"The settings menu checkbox was not found, on/off settings will use a button instead.");
				}
				RectTransform val9 = componentInChildren.content;
				ClearChildren(val9);
				ConfigureLayout(val9);
				Retitle(val6, val9);
				CanvasGroup[] components = ((Component)val6).GetComponents<CanvasGroup>();
				for (int num = 0; num < components.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)components[num]);
				}
				((Component)val6).gameObject.SetActive(false);
				if ((Object)(object)val5 != (Object)null)
				{
					val5.transform.SetParent(((Transform)val2).parent, false);
					val5.transform.SetSiblingIndex(((Transform)val2).GetSiblingIndex() + 1);
				}
				val4.transform.SetParent(((Component)val).transform.parent, false);
				val4.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				val4.SetActive(true);
				((Component)val6).gameObject.SetActive(false);
				Widen(val6, componentInChildren);
				CanvasGroup component2 = ((Component)val6).GetComponent<CanvasGroup>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.alpha = 0f;
					component2.interactable = false;
					component2.blocksRaycasts = false;
				}
				UiFactory.Bind(val9, heading, body, button, toggle);
				screen = component;
				panelRoot = val6;
				scroll = componentInChildren;
				content = val9;
				log.LogDebug((object)"Built the mod list screen");
				return true;
			}
			catch (Exception ex)
			{
				buildFailed = true;
				log.LogError((object)ex);
				if ((Object)(object)val4 != (Object)null)
				{
					Object.Destroy((Object)(object)val4);
				}
				if ((Object)(object)val5 != (Object)null)
				{
					Object.Destroy((Object)(object)val5);
				}
				return false;
			}
			finally
			{
				Object.Destroy((Object)(object)val3);
			}
		}

		private static void Remap(CreditsScreenUGUI cloneScreen, Transform sourceRoot, Transform cloneRoot)
		{
			Type[] array = new Type[3]
			{
				typeof(UIScreenUGUI),
				typeof(UIMenuScreenUGUI),
				typeof(CreditsScreenUGUI)
			};
			for (int i = 0; i < array.Length; i++)
			{
				FieldInfo[] fields = array[i].GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (typeof(Component).IsAssignableFrom(fieldInfo.FieldType))
					{
						object? value = fieldInfo.GetValue(cloneScreen);
						Component val = MapComponent((Component)((value is Component) ? value : null), fieldInfo.FieldType, sourceRoot, cloneRoot);
						if ((Object)(object)val != (Object)null)
						{
							fieldInfo.SetValue(cloneScreen, val);
						}
					}
					else
					{
						if (!(fieldInfo.FieldType == typeof(List<Selectable>)) || !(fieldInfo.GetValue(cloneScreen) is List<Selectable> list))
						{
							continue;
						}
						List<Selectable> list2 = new List<Selectable>();
						foreach (Selectable item in list)
						{
							Component obj = MapComponent((Component)(object)item, typeof(Selectable), sourceRoot, cloneRoot);
							Selectable val2 = (Selectable)(object)((obj is Selectable) ? obj : null);
							list2.Add(((Object)(object)val2 != (Object)null) ? val2 : item);
						}
						fieldInfo.SetValue(cloneScreen, list2);
					}
				}
			}
		}

		private static Component MapComponent(Component original, Type type, Transform sourceRoot, Transform cloneRoot)
		{
			if ((Object)(object)original == (Object)null || !original.transform.IsChildOf(sourceRoot))
			{
				return null;
			}
			List<int> list = new List<int>();
			Transform val = original.transform;
			while ((Object)(object)val != (Object)(object)sourceRoot)
			{
				list.Add(val.GetSiblingIndex());
				val = val.parent;
			}
			Transform val2 = cloneRoot;
			for (int num = list.Count - 1; num >= 0; num--)
			{
				val2 = val2.GetChild(list[num]);
			}
			return ((Component)val2).GetComponent(type);
		}

		private static bool Fail(string message)
		{
			buildFailed = true;
			log.LogWarning((object)(message + " The mod list is disabled until the game restarts."));
			return false;
		}

		private static CreditsScreenUGUI FindSource()
		{
			CreditsScreenUGUI[] array = Object.FindObjectsByType<CreditsScreenUGUI>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (CreditsScreenUGUI val in array)
			{
				if (((Object)((Component)val).gameObject).name != "ModListScreen")
				{
					return val;
				}
			}
			return null;
		}

		private static Toggle FindSettingsToggle()
		{
			SettingsMenuUGUI[] array = Object.FindObjectsByType<SettingsMenuUGUI>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (SettingsMenuUGUI obj in array)
			{
				string[] settingsToggleFields = SettingsToggleFields;
				foreach (string name in settingsToggleFields)
				{
					FieldInfo field = typeof(SettingsMenuUGUI).GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					Toggle val = (Toggle)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
			return null;
		}

		private static GameObject CreateTemplate(GameObject source, Transform parent)
		{
			GameObject val = Object.Instantiate<GameObject>(source, parent);
			((Object)val).name = "ModListRowTemplate";
			val.SetActive(false);
			StripComponents(val);
			LayoutElement[] components = val.GetComponents<LayoutElement>();
			for (int i = 0; i < components.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components[i]);
			}
			ContentSizeFitter[] components2 = val.GetComponents<ContentSizeFitter>();
			for (int i = 0; i < components2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)components2[i]);
			}
			return val;
		}

		private static void StripComponents(GameObject target)
		{
			MonoBehaviour[] componentsInChildren = target.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string name = ((object)val).GetType().Name;
					if (name == "LocalizeStringEvent" || name.Contains("Typewriter"))
					{
						Object.DestroyImmediate((Object)(object)val);
					}
				}
			}
		}

		private static void ClearChildren(RectTransform target)
		{
			for (int num = ((Transform)target).childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)((Transform)target).GetChild(num)).gameObject);
			}
		}

		private static void Widen(RectTransform panel, ScrollRect scrollRect)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)panel).GetComponentInParent<Canvas>(true);
			RectTransform val = (RectTransform)(((Object)(object)componentInParent != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Rect rect = val.rect;
			float width = ((Rect)(ref rect)).width;
			if (Mathf.Approximately(width, appliedCanvasWidth))
			{
				return;
			}
			float num = width * 0.85f;
			if (num <= 0f)
			{
				return;
			}
			appliedCanvasWidth = width;
			RectTransform val2 = (RectTransform)((Component)scrollRect).transform;
			Transform parent = ((Transform)val2).parent;
			RectTransform val3 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			float num2;
			if (!((Object)(object)val3 != (Object)null))
			{
				num2 = 0f;
			}
			else
			{
				rect = val2.rect;
				float width2 = ((Rect)(ref rect)).width;
				rect = val3.rect;
				num2 = width2 - ((Rect)(ref rect)).width;
			}
			float num3 = num2;
			if ((Object)(object)val3 != (Object)null)
			{
				Resize(val3, num);
			}
			Resize(val2, num + num3);
			Scrollbar verticalScrollbar = scrollRect.verticalScrollbar;
			RectTransform val4 = (RectTransform)(((Object)(object)verticalScrollbar != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val4 != (Object)null)
			{
				val4.pivot = new Vector2(1f, val4.pivot.y);
				ScrollbarPinner scrollbarPinner = ((Component)val4).GetComponent<ScrollbarPinner>();
				if ((Object)(object)scrollbarPinner == (Object)null)
				{
					scrollbarPinner = ((Component)val4).gameObject.AddComponent<ScrollbarPinner>();
				}
				scrollbarPinner.CanvasRect = val;
				scrollbarPinner.Margin = 30f;
			}
		}

		private static float Resize(RectTransform target, float width)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			Rect rect = target.rect;
			float width2 = ((Rect)(ref rect)).width;
			float num = target.anchoredPosition.x - target.pivot.x * width2;
			target.SetSizeWithCurrentAnchors((Axis)0, width);
			target.anchoredPosition = new Vector2(num + target.pivot.x * width, target.anchoredPosition.y);
			return width - width2;
		}

		private static void ConfigureLayout(RectTransform target)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			target.anchorMin = new Vector2(0f, 1f);
			target.anchorMax = new Vector2(1f, 1f);
			target.pivot = new Vector2(0.5f, 1f);
			target.sizeDelta = new Vector2(0f, target.sizeDelta.y);
			target.anchoredPosition = Vector2.zero;
			LayoutGroup[] components = ((Component)target).GetComponents<LayoutGroup>();
			foreach (LayoutGroup val in components)
			{
				if (!(val is VerticalLayoutGroup))
				{
					Object.DestroyImmediate((Object)(object)val);
				}
			}
			VerticalLayoutGroup val2 = ((Component)target).GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)target).gameObject.AddComponent<VerticalLayoutGroup>();
			}
			((LayoutGroup)val2).padding = new RectOffset(40, 40, 40, 40);
			((HorizontalOrVerticalLayoutGroup)val2).spacing = 18f;
			((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = false;
			ContentSizeFitter val3 = ((Component)target).GetComponent<ContentSizeFitter>();
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = ((Component)target).gameObject.AddComponent<ContentSizeFitter>();
			}
			val3.horizontalFit = (FitMode)0;
			val3.verticalFit = (FitMode)2;
		}

		private static void Retitle(RectTransform screenRoot, RectTransform listContent)
		{
			TMP_Text val = null;
			TMP_Text val2 = null;
			TMP_Text[] componentsInChildren = ((Component)screenRoot).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val3 in componentsInChildren)
			{
				if (!val3.transform.IsChildOf((Transform)(object)listContent) && !(((Object)((Component)val3).gameObject).name == "ModListRowTemplate") && !((Object)(object)((Component)val3).GetComponentInParent<Button>(true) != (Object)null))
				{
					if ((Object)(object)val == (Object)null && val3.text.IndexOf("credit", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						val = val3;
					}
					if ((Object)(object)val2 == (Object)null || val3.fontSize > val2.fontSize)
					{
						val2 = val3;
					}
				}
			}
			TMP_Text val4 = (((Object)(object)val != (Object)null) ? val : val2);
			if ((Object)(object)val4 == (Object)null)
			{
				log.LogDebug((object)"No title label was found on the mod list screen.");
				return;
			}
			StripComponents(((Component)val4).gameObject);
			val4.text = "Mod List";
		}

		private static void Register()
		{
			if (AllScreensField.GetValue(Main.UIManager) is List<UIScreenUGUI> list)
			{
				list.RemoveAll((UIScreenUGUI s) => (Object)(object)s == (Object)null);
				if (!list.Contains((UIScreenUGUI)(object)screen))
				{
					list.Add((UIScreenUGUI)(object)screen);
				}
			}
		}

		private static void ShowList(bool focus)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			inConfig = false;
			DiscardChildren(content);
			List<PluginInfo> list = new List<PluginInfo>(Chainloader.PluginInfos.Values);
			list.Sort((PluginInfo a, PluginInfo b) => string.Compare(a.Metadata.Name, b.Metadata.Name, StringComparison.OrdinalIgnoreCase));
			UiFactory.AddText(heading: true, "Installed Mods (" + list.Count + ")");
			foreach (PluginInfo item in list)
			{
				string labelText = Describe(item);
				if (ConfigEditor.CountEntries(item) > 0)
				{
					PluginInfo selected = item;
					Button val = UiFactory.CreateSmallButton("Config", (UnityAction)delegate
					{
						ShowConfig(selected, focus: true);
					});
					UiFactory.AddEntryRow(labelText, ((Component)val).gameObject);
				}
				else
				{
					UiFactory.AddEntryRow(labelText);
				}
			}
			FinishView(focus);
		}

		private static void ShowConfig(PluginInfo info, bool focus)
		{
			inConfig = true;
			DiscardChildren(content);
			UiFactory.AddText(heading: true, UiFactory.Plain(info.Metadata.Name) + " Settings");
			ConfigEditor.Populate(info);
			FinishView(focus);
		}

		private static void FinishView(bool focus)
		{
			scroll.StopMovement();
			scroll.verticalNormalizedPosition = 1f;
			if (focus && !((Object)(object)EventSystem.current == (Object)null))
			{
				Button componentInChildren = ((Component)content).GetComponentInChildren<Button>(false);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject(((Component)componentInChildren).gameObject);
				}
			}
		}

		private static void DiscardChildren(RectTransform target)
		{
			for (int num = ((Transform)target).childCount - 1; num >= 0; num--)
			{
				GameObject gameObject = ((Component)((Transform)target).GetChild(num)).gameObject;
				gameObject.SetActive(false);
				Object.Destroy((Object)(object)gameObject);
			}
		}

		private static string Describe(PluginInfo info)
		{
			string text = "<b>" + UiFactory.Plain(info.Metadata.Name) + "</b>  <alpha=#99>v" + info.Metadata.Version?.ToString() + "<alpha=#FF>";
			if ((Object)(object)info.Instance == (Object)null)
			{
				text += "  <color=#FF6B6B>Not loaded</color>";
			}
			else if (!((Behaviour)info.Instance).enabled)
			{
				text += "  <color=#FF6B6B>Disabled</color>";
			}
			return text + "\n<size=70%><alpha=#99>" + UiFactory.Plain(info.Metadata.GUID) + "<alpha=#FF></size>";
		}
	}
	internal static class ModsButtonInjector
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnClicked;
		}

		private const string ButtonName = "ModListButton";

		private const string ButtonLabel = "Mods";

		private const float FallbackSpacing = 10f;

		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		internal static readonly FieldInfo StartMenuProgressField = typeof(StartMenuUGUI).GetField("m_ProgressButton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		internal static readonly FieldInfo PauseMenuProgressField = typeof(PauseScreenUGui).GetField("m_ProgressButton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo UseToolTipField = typeof(UIMenuButton).GetField("useToolTip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static ManualLogSource log;

		internal static void Initialize(ManualLogSource logger)
		{
			log = logger;
			if (StartMenuProgressField == null)
			{
				log.LogWarning((object)"StartMenuUGUI.m_ProgressButton was not found, the Start menu button will be skipped.");
			}
			if (PauseMenuProgressField == null)
			{
				log.LogWarning((object)"PauseScreenUGui.m_ProgressButton was not found, the Pause menu button will be skipped.");
			}
			if (UseToolTipField == null)
			{
				log.LogWarning((object)"UIMenuButton.useToolTip was not found, the Mods button may show the Progress tooltip.");
			}
		}

		internal static void ScanExisting()
		{
			StartMenuUGUI[] array = Object.FindObjectsByType<StartMenuUGUI>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (StartMenuUGUI screen in array)
			{
				Inject(StartMenuProgressField, (MonoBehaviour)(object)screen);
			}
			PauseScreenUGui[] array2 = Object.FindObjectsByType<PauseScreenUGui>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (PauseScreenUGui screen2 in array2)
			{
				Inject(PauseMenuProgressField, (MonoBehaviour)(object)screen2);
			}
		}

		internal static void Inject(FieldInfo progressField, MonoBehaviour screen)
		{
			try
			{
				InjectInternal(progressField, screen);
			}
			catch (Exception ex)
			{
				log.LogError((object)ex);
			}
		}

		private static void InjectInternal(FieldInfo progressField, MonoBehaviour screen)
		{
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			if (progressField == null)
			{
				return;
			}
			object? value = progressField.GetValue(screen);
			Button val = (Button)((value is Button) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			if ((Object)(object)parent == (Object)null || (Object)(object)parent.Find("ModListButton") != (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
			((Object)val2).name = "ModListButton";
			val2.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
			MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null && ((object)val3).GetType().Name == "LocalizeStringEvent")
				{
					Object.DestroyImmediate((Object)(object)val3);
				}
			}
			Tooltip[] componentsInChildren2 = val2.GetComponentsInChildren<Tooltip>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			if (UseToolTipField != null)
			{
				UIMenuButton[] componentsInChildren3 = val2.GetComponentsInChildren<UIMenuButton>(true);
				foreach (UIMenuButton obj in componentsInChildren3)
				{
					UseToolTipField.SetValue(obj, false);
				}
			}
			TMP_Text[] componentsInChildren4 = val2.GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				componentsInChildren4[i].text = "Mods";
			}
			Button component = val2.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component.onClick;
			object obj2 = <>O.<0>__OnClicked;
			if (obj2 == null)
			{
				UnityAction val4 = OnClicked;
				<>O.<0>__OnClicked = val4;
				obj2 = (object)val4;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj2);
			if ((Object)(object)((Component)parent).GetComponent<LayoutGroup>() == (Object)null)
			{
				RectTransform val5 = (RectTransform)((Component)val).transform;
				RectTransform val6 = (RectTransform)val2.transform;
				Vector2 anchoredPosition = val5.anchoredPosition;
				Vector2 down = Vector2.down;
				Rect rect = val5.rect;
				val6.anchoredPosition = anchoredPosition + down * (((Rect)(ref rect)).height + 10f);
			}
			log.LogDebug((object)("Added Mods button to " + ((object)screen).GetType().Name));
		}

		private static void OnClicked()
		{
			ModListScreen.Open();
		}
	}
	[BepInPlugin("com.king_tajin.modlist", "Mod List", "0.5.2")]
	[BepInProcess("Slots and Daggers.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			ConfigEntry<bool> dump = null;
			ModsButtonInjector.Initialize(((BaseUnityPlugin)this).Logger);
			ModListScreen.Initialize(((BaseUnityPlugin)this).Logger, dump);
			Harmony val = new Harmony("com.king_tajin.modlist");
			Type[] array = new Type[3]
			{
				typeof(CloseCurrentUIScreenPatch),
				typeof(StartMenuButtonPatch),
				typeof(PauseMenuButtonPatch)
			};
			foreach (Type type in array)
			{
				try
				{
					val.PatchAll(type);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)ex);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Mod List loaded");
		}

		private void Start()
		{
			try
			{
				ModsButtonInjector.ScanExisting();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}
	}
	internal sealed class ScrollbarPinner : MonoBehaviour
	{
		internal RectTransform CanvasRect;

		internal float Margin;

		private RectTransform self;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			self = (RectTransform)((Component)this).transform;
		}

		private void LateUpdate()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)CanvasRect == (Object)null))
			{
				RectTransform canvasRect = CanvasRect;
				Rect rect = CanvasRect.rect;
				float num = ((Transform)canvasRect).TransformPoint(new Vector3(((Rect)(ref rect)).xMax, 0f, 0f)).x - Margin * ((Transform)CanvasRect).lossyScale.x;
				Vector3 position = ((Transform)self).position;
				if (!Mathf.Approximately(position.x, num))
				{
					position.x = num;
					((Transform)self).position = position;
				}
			}
		}
	}
	internal static class UiFactory
	{
		private const float EntrySpacing = 24f;

		private const float ControlWidth = 360f;

		private const float SmallButtonWidth = 180f;

		private const float ControlHeight = 64f;

		private static readonly Regex NoParseClose = new Regex("</\\s*noparse[^>]*>", RegexOptions.IgnoreCase);

		private static RectTransform content;

		private static GameObject headingTemplate;

		private static GameObject bodyTemplate;

		private static GameObject buttonTemplate;

		private static GameObject toggleTemplate;

		internal static bool HasToggle => (Object)(object)toggleTemplate != (Object)null;

		internal static void Bind(RectTransform target, GameObject heading, GameObject body, GameObject button, GameObject toggle)
		{
			content = target;
			headingTemplate = heading;
			bodyTemplate = body;
			buttonTemplate = button;
			toggleTemplate = toggle;
		}

		internal static string Plain(string value)
		{
			return "<noparse>" + NoParseClose.Replace(value, string.Empty) + "</noparse>";
		}

		internal static TMP_Text AddText(bool heading, string text)
		{
			return CreateText((Transform)(object)content, heading ? headingTemplate : bodyTemplate, text);
		}

		internal static Button CreateControlButton(string label, UnityAction onClick)
		{
			return CreateSizedButton(label, onClick, 360f);
		}

		internal static Button CreateSmallButton(string label, UnityAction onClick)
		{
			return CreateSizedButton(label, onClick, 180f);
		}

		internal static Toggle CreateControlToggle(bool value, UnityAction<bool> onChanged)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(toggleTemplate, (Transform)(object)content);
			((Object)val).name = "ModListToggle";
			TMP_Text[] componentsInChildren = val.GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val2 in componentsInChildren)
			{
				if ((Object)(object)((Component)val2).gameObject != (Object)(object)val)
				{
					((Component)val2).gameObject.SetActive(false);
				}
			}
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minWidth = 180f;
			obj.preferredWidth = 180f;
			obj.flexibleWidth = 0f;
			obj.minHeight = 64f;
			obj.preferredHeight = 64f;
			Toggle component = val.GetComponent<Toggle>();
			component.onValueChanged = new ToggleEvent();
			component.SetIsOnWithoutNotify(value);
			((UnityEvent<bool>)(object)component.onValueChanged).AddListener(onChanged);
			return component;
		}

		internal static void SetButtonLabel(Button button, string text)
		{
			TMP_Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text obj in componentsInChildren)
			{
				obj.richText = true;
				obj.text = text;
			}
		}

		internal static TMP_InputField CreateInputField(string value, UnityAction<string> onEndEdit)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text component = bodyTemplate.GetComponent<TMP_Text>();
			GameObject val = new GameObject("ModListInput", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(LayoutElement)
			});
			val.SetActive(false);
			val.transform.SetParent((Transform)(object)content, false);
			Image component2 = val.GetComponent<Image>();
			((Graphic)component2).color = new Color(0f, 0f, 0f, 0.45f);
			LayoutElement component3 = val.GetComponent<LayoutElement>();
			component3.minWidth = 360f;
			component3.preferredWidth = 360f;
			component3.flexibleWidth = 0f;
			component3.minHeight = 64f;
			component3.preferredHeight = 64f;
			RectTransform val2 = (RectTransform)new GameObject("TextArea", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			}).transform;
			((Transform)val2).SetParent(val.transform, false);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = new Vector2(12f, 6f);
			val2.offsetMax = new Vector2(-12f, -6f);
			GameObject val3 = new GameObject("Text", new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val2, false);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.offsetMin = Vector2.zero;
			val4.offsetMax = Vector2.zero;
			TextMeshProUGUI component4 = val3.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component4).font = component.font;
			((TMP_Text)component4).fontSharedMaterial = component.fontSharedMaterial;
			((TMP_Text)component4).fontSize = component.fontSize;
			((Graphic)component4).color = ((Graphic)component).color;
			((TMP_Text)component4).enableAutoSizing = false;
			((TMP_Text)component4).alignment = (TextAlignmentOptions)513;
			TMP_InputField obj = val.AddComponent<TMP_InputField>();
			obj.textViewport = val2;
			obj.textComponent = (TMP_Text)(object)component4;
			((Selectable)obj).targetGraphic = (Graphic)(object)component2;
			obj.lineType = (LineType)0;
			obj.richText = false;
			obj.SetTextWithoutNotify(value);
			((UnityEvent<string>)(object)obj.onEndEdit).AddListener(onEndEdit);
			return obj;
		}

		internal static void AddEntryRow(string labelText, params GameObject[] controls)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			GameObject val = new GameObject("ModListEntry", new Type[2]
			{
				typeof(RectTransform),
				typeof(HorizontalLayoutGroup)
			});
			val.transform.SetParent((Transform)(object)content, false);
			HorizontalLayoutGroup component = val.GetComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).spacing = 24f;
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			TMP_Text obj = CreateText(val.transform, bodyTemplate, labelText);
			obj.alignment = (TextAlignmentOptions)257;
			LayoutElement obj2 = ((Component)obj).gameObject.AddComponent<LayoutElement>();
			obj2.flexibleWidth = 1f;
			obj2.minWidth = 120f;
			foreach (GameObject obj3 in controls)
			{
				obj3.transform.SetParent(val.transform, false);
				obj3.SetActive(true);
			}
		}

		private static TMP_Text CreateText(Transform parent, GameObject template, string text)
		{
			GameObject obj = Object.Instantiate<GameObject>(template, parent);
			((Object)obj).name = "ModListRow";
			obj.SetActive(true);
			TMP_Text component = obj.GetComponent<TMP_Text>();
			component.richText = true;
			((Graphic)component).raycastTarget = false;
			component.text = text;
			return component;
		}

		private static Button CreateSizedButton(string label, UnityAction onClick, float width)
		{
			Button obj = CreateButton(label, onClick);
			LayoutElement obj2 = ((Component)obj).gameObject.AddComponent<LayoutElement>();
			obj2.minWidth = width;
			obj2.preferredWidth = width;
			obj2.flexibleWidth = 0f;
			obj2.minHeight = 64f;
			obj2.preferredHeight = 64f;
			return obj;
		}

		private static Button CreateButton(string label, UnityAction onClick)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(buttonTemplate, (Transform)(object)content);
			((Object)obj).name = "ModListButton";
			obj.SetActive(true);
			Button component = obj.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(onClick);
			SetButtonLabel(component, label);
			return component;
		}
	}
}