Decompiled source of Mod Settings v1.0.1

Mods/WoodStudios.ModManager.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ModManager;
using S1API.PhoneApp;
using S1API.UI;
using S1API.Utils;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using WoodKit;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Mod Settings", "1.0.1", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonPriority(-100)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WoodStudios.ModManager")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WoodStudios.ModManager")]
[assembly: AssemblyTitle("WoodStudios.ModManager")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[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 WoodKit
{
	internal static class InputUtil
	{
		private static bool _legacyBroken;

		public static bool Suppressed;

		public static KeyCode Parse(string name, KeyCode fallback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (!string.IsNullOrWhiteSpace(name) && Enum.TryParse<KeyCode>(name.Trim(), ignoreCase: true, out KeyCode result))
			{
				return result;
			}
			return fallback;
		}

		public static bool Down(KeyCode key)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!Suppressed)
			{
				return RawDown(key);
			}
			return false;
		}

		public static bool Held(KeyCode key)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!Suppressed)
			{
				return RawHeld(key);
			}
			return false;
		}

		public static bool RawDown(KeyCode key)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetKeyDown(key);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			KeyControl val = Control(key);
			if (val != null)
			{
				return ((ButtonControl)val).wasPressedThisFrame;
			}
			return false;
		}

		public static bool RawHeld(KeyCode key)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetKey(key);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			KeyControl val = Control(key);
			if (val != null)
			{
				return ((ButtonControl)val).isPressed;
			}
			return false;
		}

		public static bool MouseDown(int button)
		{
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetMouseButtonDown(button);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			try
			{
				Mouse current = Mouse.current;
				if (current == null)
				{
					return false;
				}
				return (button == 0) ? current.leftButton.wasPressedThisFrame : current.rightButton.wasPressedThisFrame;
			}
			catch
			{
				return false;
			}
		}

		public static bool MouseHeld(int button)
		{
			if (!_legacyBroken)
			{
				try
				{
					return Input.GetMouseButton(button);
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			try
			{
				Mouse current = Mouse.current;
				if (current == null)
				{
					return false;
				}
				return (button == 0) ? current.leftButton.isPressed : current.rightButton.isPressed;
			}
			catch
			{
				return false;
			}
		}

		private unsafe static KeyControl Control(KeyCode key)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return null;
				}
				string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
				if (text.StartsWith("Alpha"))
				{
					text = "Digit" + text.Substring(5);
				}
				else if (text == "Return")
				{
					text = "Enter";
				}
				else if (text == "KeypadEnter")
				{
					text = "NumpadEnter";
				}
				else if (text.StartsWith("Keypad"))
				{
					text = "Numpad" + text.Substring(6);
				}
				if (!Enum.TryParse<Key>(text, ignoreCase: true, out Key result))
				{
					return null;
				}
				return current[result];
			}
			catch
			{
				return null;
			}
		}
	}
}
namespace ModManager
{
	public sealed class Core : MelonMod
	{
		internal static Instance Log;

		private static float _warnedAt = -100f;

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			Log.Msg("Mod Settings loaded. Open the Mods app on your phone.");
		}

		public override void OnUpdate()
		{
			try
			{
				ModsApp.Tick();
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime - _warnedAt > 30f)
				{
					_warnedAt = Time.unscaledTime;
					Log.Warning("Mods app: " + ex.Message);
				}
			}
		}
	}
	public sealed class ModsApp : PhoneApp
	{
		private static readonly Color Bg = new Color(0.08f, 0.07f, 0.06f);

		private static readonly Color RowBg = new Color(0.14f, 0.12f, 0.1f);

		private static readonly Color SubText = new Color(0.75f, 0.72f, 0.68f);

		private static readonly Color OnCol = new Color(0.2f, 0.55f, 0.25f);

		private static readonly Color OffCol = new Color(0.45f, 0.18f, 0.15f);

		private static readonly Color ChoiceCol = new Color(0.18f, 0.35f, 0.6f);

		private static readonly Color Amber = new Color(0.85f, 0.62f, 0.25f);

		private static readonly Color Brown = new Color(0.42f, 0.27f, 0.13f);

		private static readonly Color Box = new Color(0.05f, 0.045f, 0.04f);

		private static readonly Color Grey = new Color(0.24f, 0.22f, 0.2f);

		private static ModsApp _instance;

		private static Sprite _icon;

		private static float _nextRefresh;

		private Text _title;

		private Text _sub;

		private RectTransform _list;

		private ScrollRect _scroll;

		private GameObject _back;

		private GameObject _confirm;

		private Text _confirmText;

		private Action _confirmYes;

		private readonly List<Action> _refreshers = new List<Action>();

		private List<ModInfo> _mods = new List<ModInfo>();

		private ModInfo _page;

		private string _message;

		private MelonPreferences_Entry _edit;

		private bool _editKey;

		private readonly StringBuilder _buf = new StringBuilder();

		private int _editFrame;

		private bool _fresh;

		private Text _editLabel;

		private Image _editImg;

		private Color _editImgCol;

		private int _endFrame = -100;

		private unsafe static readonly KeyCode[] AllKeys = (from KeyCode k in Enum.GetValues(typeof(KeyCode))
			where (int)k != 0 && !((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString().StartsWith("Mouse") && !((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString().StartsWith("Joystick")
			select k).Distinct().ToArray();

		protected override string AppName => "WoodStudios_ModManager";

		protected override string AppTitle => "Mods";

		protected override string IconLabel => "Mods";

		protected override string IconFileName => "WoodStudios_ModManager.png";

		protected override Sprite IconSprite => _icon ?? (_icon = MakeIcon());

		protected override void OnCreated()
		{
			((PhoneApp)this).OnCreated();
			_instance = this;
		}

		protected override void OnCreatedUI(GameObject container)
		{
			try
			{
				Build(container);
			}
			catch (Exception ex)
			{
				try
				{
					Core.Log.Warning("Mods app: couldn't build its screen (" + ex.Message + ").");
				}
				catch
				{
				}
			}
		}

		private void Build(GameObject container)
		{
			//IL_000b: 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)
			//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)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIFactory.Panel("ModsPanel", container.transform, Bg, (Vector2?)null, (Vector2?)null, true);
			_title = UIFactory.Text("Title", "MOD SETTINGS", val.transform, 26, (TextAnchor)1, (FontStyle)1);
			_title.horizontalOverflow = (HorizontalWrapMode)0;
			Top(((Graphic)_title).rectTransform, -8f, 40f, 200f);
			_sub = UIFactory.Text("Sub", "", val.transform, 14, (TextAnchor)1, (FontStyle)0);
			_sub.horizontalOverflow = (HorizontalWrapMode)0;
			_sub.supportRichText = true;
			((Graphic)_sub).color = SubText;
			Top(((Graphic)_sub).rectTransform, -46f, 26f, 20f);
			_list = UIFactory.ScrollableVerticalList("ModsList", val.transform, ref _scroll);
			_list.sizeDelta = new Vector2(0f, _list.sizeDelta.y);
			RectTransform component = ((Component)_scroll).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchorMin = new Vector2(0f, 0f);
				component.anchorMax = new Vector2(1f, 1f);
				component.offsetMin = new Vector2(10f, 10f);
				component.offsetMax = new Vector2(-44f, -76f);
			}
			AddScrollBar(val.transform, _scroll, 76f);
			ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("Back", "< Back", val.transform, Brown, 92f, 32f);
			GameObject item = valueTuple.Item1;
			Button item2 = valueTuple.Item2;
			Text item3 = valueTuple.Item3;
			RectTransform component2 = item.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 1f);
			component2.anchorMax = new Vector2(0f, 1f);
			component2.pivot = new Vector2(0f, 1f);
			component2.anchoredPosition = new Vector2(10f, -10f);
			item3.fontSize = 16;
			EventHelper.AddListener((Action)delegate
			{
				Commit();
				ShowHome();
			}, (UnityEvent)(object)item2.onClick);
			_back = item;
			_confirm = UIFactory.Panel("ModsConfirm", val.transform, new Color(0.07f, 0.06f, 0.05f, 1f), (Vector2?)null, (Vector2?)null, true);
			_confirmText = UIFactory.Text("Text", "", _confirm.transform, 19, (TextAnchor)1, (FontStyle)0);
			_confirmText.horizontalOverflow = (HorizontalWrapMode)0;
			_confirmText.supportRichText = true;
			RectTransform rectTransform = ((Graphic)_confirmText).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 0.3f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.offsetMin = new Vector2(28f, 0f);
			rectTransform.offsetMax = new Vector2(-28f, -28f);
			var (val2, val3, _) = UIFactory.ButtonWithLabel("Yes", "Do it", _confirm.transform, OffCol, 170f, 46f);
			Bottom(val2.GetComponent<RectTransform>(), -100f);
			var (val4, val5, _) = UIFactory.ButtonWithLabel("No", "Cancel", _confirm.transform, Brown, 170f, 46f);
			Bottom(val4.GetComponent<RectTransform>(), 100f);
			EventHelper.AddListener((Action)delegate
			{
				Action confirmYes = _confirmYes;
				_confirmYes = null;
				_confirm.SetActive(false);
				confirmYes?.Invoke();
			}, (UnityEvent)(object)val3.onClick);
			EventHelper.AddListener((Action)delegate
			{
				_confirmYes = null;
				_confirm.SetActive(false);
			}, (UnityEvent)(object)val5.onClick);
			_confirm.SetActive(false);
			ShowHome();
		}

		private static void Top(RectTransform rt, float y, float h, float margin)
		{
			//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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = new Vector2(0f, 1f);
			rt.anchorMax = new Vector2(1f, 1f);
			rt.pivot = new Vector2(0.5f, 1f);
			rt.sizeDelta = new Vector2(0f - margin, h);
			rt.anchoredPosition = new Vector2(0f, y);
		}

		private static void Bottom(RectTransform rt, float x)
		{
			//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)
			rt.anchorMin = new Vector2(0.5f, 0f);
			rt.anchorMax = new Vector2(0.5f, 0f);
			rt.pivot = new Vector2(0.5f, 0f);
			rt.anchoredPosition = new Vector2(x, 36f);
		}

		private void ClearList()
		{
			_refreshers.Clear();
			for (int num = ((Transform)_list).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)_list).GetChild(num)).gameObject);
			}
			try
			{
				_scroll.verticalNormalizedPosition = 1f;
			}
			catch
			{
			}
		}

		private void ShowHome()
		{
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_list == (Object)null)
			{
				return;
			}
			_page = null;
			_back.SetActive(false);
			_title.text = "MOD SETTINGS";
			_mods = Prefs.Scan();
			int value = _mods.Count((ModInfo m) => m.Melon != null);
			int num = _mods.Count((ModInfo m) => m.OffNextLaunch);
			_sub.text = _message ?? $"{value} mods running{((num > 0) ? $", {num} turned off" : "")}. Open one to change its settings.";
			_message = null;
			ClearList();
			foreach (ModInfo mod2 in _mods)
			{
				ModInfo mod = mod2;
				GameObject row = Row(64f);
				int settingCount = mod2.SettingCount;
				string value2 = (string.IsNullOrEmpty(mod2.Author) ? "" : ((mod2.Melon == null && mod2.Author == "settings") ? "  <size=13>settings group</size>" : ("  <size=13>by " + mod2.Author + "</size>")));
				string value3 = (string.IsNullOrEmpty(mod2.Version) ? "" : ("  <size=13>v" + mod2.Version + "</size>"));
				string value4 = (mod2.NotLoaded ? "<color=#ff9a7a>Turned off. Turn it on and restart the game.</color>" : (mod2.OffNextLaunch ? "<color=#ff9a7a>Off next time you start the game.</color>" : ((settingCount == 0) ? "No settings" : $"{settingCount} setting{((settingCount == 1) ? "" : "s")}")));
				Label(row, $"<b>{mod2.Name}</b>{value3}{value2}\n<size=13>{value4}</size>", 132f);
				if (mod2.NotLoaded)
				{
					Button(row, "Turn on", OnCol, 112f, 0f, delegate
					{
						_message = Prefs.SetOffNextLaunch(mod, off: false);
						ShowHome();
					});
				}
				else
				{
					Button(row, (settingCount > 0) ? "Settings" : "Open", (settingCount > 0) ? Brown : Grey, 112f, 0f, delegate
					{
						ShowMod(mod);
					});
				}
			}
			if (_mods.Count == 0)
			{
				Label(Row(60f), "No mods found.", 10f);
			}
		}

		private void ShowMod(ModInfo m)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			Commit();
			_page = m;
			_back.SetActive(true);
			_title.text = m.Name;
			string text = ((string.IsNullOrEmpty(m.Version) ? "" : ("v" + m.Version)) + ((string.IsNullOrEmpty(m.Author) || m.Author == "settings") ? "" : (" by " + m.Author))).Trim();
			_sub.text = _message ?? (((text.Length > 0) ? (text + ".  ") : "") + "Changes save right away. Some mods only pick them up after a restart.");
			_message = null;
			ClearList();
			foreach (MelonPreferences_Category category in m.Categories)
			{
				if (m.Categories.Count > 1)
				{
					((Graphic)Label(Row(34f, (Color?)new Color(0.1f, 0.09f, 0.08f)), "<b>" + (string.IsNullOrWhiteSpace(category.DisplayName) ? category.Identifier : category.DisplayName) + "</b>", 10f)).color = Amber;
				}
				foreach (MelonPreferences_Entry entry in category.Entries)
				{
					if (entry != null && !entry.IsHidden)
					{
						AddSetting(entry);
					}
				}
			}
			if (m.SettingCount == 0)
			{
				((Graphic)Label(Row(60f), "This mod doesn't have any settings to change.", 10f)).color = SubText;
			}
			GameObject row = Row(60f, Bg);
			if (m.SettingCount > 0)
			{
				Button(row, "Reset all", Brown, 150f, 170f, delegate
				{
					Ask("<size=26><b>Reset " + m.Name + "?</b></size>\n\nEvery setting goes back to how the mod came.", delegate
					{
						int num = Prefs.ResetAll(m);
						_message = ((num == 0) ? "Everything was already at its default." : $"Reset {num} setting{((num == 1) ? "" : "s")} to default.");
						ShowMod(m);
					});
				});
			}
			if (!m.CanTurnOff || m.Melon == null)
			{
				return;
			}
			if (m.OffNextLaunch)
			{
				Button(row, "Turn back on", OnCol, 150f, 0f, delegate
				{
					_message = Prefs.SetOffNextLaunch(m, off: false);
					ShowMod(m);
				});
				return;
			}
			Button(row, "Turn off", OffCol, 150f, 0f, delegate
			{
				Ask("<size=26><b>Turn off " + m.Name + "?</b></size>\n\nIt keeps running until you quit, then it won't load next time you start the game. You can turn it back on here." + (m.IsLibrary ? "\n\n<color=#ffb27a>Other mods need this one to work. They'll stop working too.</color>" : ""), delegate
				{
					_message = Prefs.SetOffNextLaunch(m, off: true);
					ShowMod(m);
				});
			});
		}

		private void Ask(string text, Action yes)
		{
			Commit();
			_confirmText.text = text;
			_confirmYes = yes;
			_confirm.SetActive(true);
		}

		private void AddSetting(MelonPreferences_Entry e)
		{
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			Prefs.Kind kind = Prefs.KindOf(e);
			float num = kind switch
			{
				Prefs.Kind.Bool => 84f, 
				Prefs.Kind.Whole => 186f, 
				Prefs.Kind.Number => 186f, 
				_ => 170f, 
			};
			string text = (string.IsNullOrWhiteSpace(e.DisplayName) ? e.Identifier : e.DisplayName);
			string text2 = (string.IsNullOrWhiteSpace(e.Description) ? "" : e.Description.Trim());
			float h = ((text2.Length > 90) ? 82f : ((text2.Length > 0) ? 66f : 50f));
			GameObject val = Row(h);
			Label(val, (text2.Length > 0) ? $"<b>{text}</b>\n<size=13>{text2}</size>" : ("<b>" + text + "</b>"), num + 22f);
			switch (kind)
			{
			case Prefs.Kind.Bool:
				var (img4, label5) = Button(val, "", Grey, 84f, 0f, delegate
				{
					Commit();
					Prefs.Toggle(e);
					Refresh();
				});
				_refreshers.Add(delegate
				{
					//IL_0040: Unknown result type (might be due to invalid IL or missing references)
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					bool flag = (bool)e.BoxedValue;
					label5.text = (flag ? "ON" : "OFF");
					((Graphic)img4).color = (flag ? OnCol : OffCol);
				});
				break;
			case Prefs.Kind.Choice:
			{
				Text label4 = Button(val, "", ChoiceCol, 170f, 0f, delegate
				{
					Commit();
					Prefs.Cycle(e, 1);
					Refresh();
				}).Item2;
				label4.fontSize = 15;
				_refreshers.Add(delegate
				{
					label4.text = Prefs.Show(e);
				});
				break;
			}
			case Prefs.Kind.Key:
				var (img3, label3) = Button(val, "", Brown, 170f, 0f, null);
				label3.fontSize = 15;
				SetClick(((Component)img3).gameObject, delegate
				{
					StartEdit(e, key: true, label3, img3);
				});
				_refreshers.Add(delegate
				{
					if (_edit != e)
					{
						label3.text = Prefs.Show(e);
					}
				});
				break;
			case Prefs.Kind.Whole:
			case Prefs.Kind.Number:
				Button(val, "+", Brown, 40f, 0f, delegate
				{
					Commit();
					Prefs.Step(e, 1);
					Refresh();
				});
				var (img2, label2) = Button(val, "", Box, 98f, 44f, null);
				label2.fontSize = 16;
				SetClick(((Component)img2).gameObject, delegate
				{
					StartEdit(e, key: false, label2, img2);
				});
				Button(val, "-", Brown, 40f, 146f, delegate
				{
					Commit();
					Prefs.Step(e, -1);
					Refresh();
				});
				_refreshers.Add(delegate
				{
					if (_edit != e)
					{
						label2.text = Prefs.Show(e);
					}
				});
				break;
			case Prefs.Kind.Text:
				var (img, label) = Button(val, "", Box, 170f, 0f, null);
				label.fontSize = 15;
				SetClick(((Component)img).gameObject, delegate
				{
					StartEdit(e, key: false, label, img);
				});
				_refreshers.Add(delegate
				{
					if (_edit != e)
					{
						label.text = Clip(Prefs.Show(e), 18);
					}
				});
				break;
			default:
			{
				Text obj = UIFactory.Text("Value", Clip(Prefs.Show(e), 40), val.transform, 13, (TextAnchor)5, (FontStyle)0);
				((Graphic)obj).color = SubText;
				obj.horizontalOverflow = (HorizontalWrapMode)0;
				RectTransform rectTransform = ((Graphic)obj).rectTransform;
				rectTransform.anchorMin = new Vector2(1f, 0f);
				rectTransform.anchorMax = new Vector2(1f, 1f);
				rectTransform.pivot = new Vector2(1f, 0.5f);
				rectTransform.sizeDelta = new Vector2(170f, 0f);
				rectTransform.anchoredPosition = new Vector2(-10f, 0f);
				break;
			}
			}
		}

		private static void Deselect()
		{
			try
			{
				EventSystem current = EventSystem.current;
				if ((Object)(object)current != (Object)null)
				{
					current.SetSelectedGameObject((GameObject)null);
				}
			}
			catch
			{
			}
		}

		private static string Clip(string s, int n)
		{
			if (s != null)
			{
				if (s.Length > n)
				{
					return s.Substring(0, n - 1) + "...";
				}
				return s;
			}
			return "";
		}

		private void Refresh()
		{
			foreach (Action refresher in _refreshers)
			{
				try
				{
					refresher();
				}
				catch
				{
				}
			}
		}

		private void StartEdit(MelonPreferences_Entry e, bool key, Text label, Image img)
		{
			//IL_0037: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (Time.frameCount - _endFrame >= 3)
			{
				Commit();
				Deselect();
				_editImg = img;
				_editImgCol = (((Object)(object)img != (Object)null) ? ((Graphic)img).color : Box);
				if ((Object)(object)img != (Object)null)
				{
					((Graphic)img).color = new Color(0.32f, 0.22f, 0.09f);
				}
				_edit = e;
				_editKey = key;
				_editLabel = label;
				_editFrame = Time.frameCount;
				_fresh = true;
				_buf.Clear();
				if (!key && Prefs.KindOf(e) != Prefs.Kind.Text)
				{
					_buf.Append(Prefs.Show(e));
				}
				else if (!key)
				{
					_buf.Append((e.BoxedValue as string) ?? "");
				}
				InputUtil.Suppressed = true;
				try
				{
					GameInput.IsTyping = true;
				}
				catch
				{
				}
				ShowEdit();
			}
		}

		private void ShowEdit()
		{
			if ((Object)(object)_editLabel == (Object)null)
			{
				return;
			}
			if (_editKey)
			{
				_editLabel.text = "<color=#ffd27a>Press a key...</color>";
				return;
			}
			string text = ((Time.unscaledTime % 1f < 0.55f) ? "|" : " ");
			string text2 = _buf.ToString();
			if (_fresh)
			{
				_editLabel.text = "<color=#ffd27a><b>" + ((text2.Length > 16) ? (text2.Substring(0, 15) + "...") : text2) + "</b></color>";
				return;
			}
			if (text2.Length > 16)
			{
				text2 = "..." + text2.Substring(text2.Length - 15);
			}
			_editLabel.text = "<color=#ffd27a>" + text2 + text + "</color>";
		}

		private void Commit()
		{
			EndEdit(keep: true);
		}

		private void EndEdit(bool keep)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			MelonPreferences_Entry edit = _edit;
			if (edit == null)
			{
				return;
			}
			_edit = null;
			_endFrame = Time.frameCount;
			if ((Object)(object)_editImg != (Object)null)
			{
				try
				{
					((Graphic)_editImg).color = _editImgCol;
				}
				catch
				{
				}
			}
			_editImg = null;
			Deselect();
			InputUtil.Suppressed = false;
			try
			{
				GameInput.IsTyping = false;
			}
			catch
			{
			}
			if (keep && !_editKey && !Prefs.SetFromText(edit, _buf.ToString()))
			{
				_sub.text = "<color=#ff9a7a>That isn't a valid value, so it wasn't changed.</color>";
			}
			_editLabel = null;
			Refresh();
		}

		private void UpdateEdit()
		{
			//IL_0045: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			if (_edit == null)
			{
				return;
			}
			if (Time.frameCount - _editFrame < 2)
			{
				ShowEdit();
				return;
			}
			if (InputUtil.RawDown((KeyCode)27))
			{
				EndEdit(keep: false);
				return;
			}
			if (_editKey)
			{
				KeyCode[] allKeys = AllKeys;
				foreach (KeyCode val in allKeys)
				{
					if (InputUtil.RawDown(val))
					{
						MelonPreferences_Entry edit = _edit;
						EndEdit(keep: false);
						Prefs.SetKey(edit, val);
						Refresh();
						break;
					}
				}
				return;
			}
			bool shift = InputUtil.RawHeld((KeyCode)304) || InputUtil.RawHeld((KeyCode)303);
			Prefs.Kind kind = Prefs.KindOf(_edit);
			string text = Typing.ThisFrame(shift);
			foreach (char c in text)
			{
				if (c == '\n' || c == '\r')
				{
					Commit();
					return;
				}
				if (_fresh)
				{
					_fresh = false;
					_buf.Clear();
					if (c == '\b')
					{
						continue;
					}
				}
				if (c == '\b')
				{
					if (_buf.Length > 0)
					{
						_buf.Length--;
					}
				}
				else if (kind == Prefs.Kind.Text)
				{
					if (_buf.Length < 200 && !char.IsControl(c))
					{
						_buf.Append(c);
					}
				}
				else if ((char.IsDigit(c) || c == '-' || (kind == Prefs.Kind.Number && (c == '.' || c == ','))) && _buf.Length < 20)
				{
					_buf.Append(c);
				}
			}
			ShowEdit();
		}

		public static void Tick()
		{
			ModsApp instance = _instance;
			if (instance == null || (Object)(object)instance._list == (Object)null)
			{
				return;
			}
			bool flag = false;
			try
			{
				flag = ((PhoneApp)instance).IsOpen();
			}
			catch
			{
			}
			if (!flag)
			{
				if (instance._edit != null)
				{
					instance.EndEdit(keep: false);
				}
				return;
			}
			try
			{
				instance.UpdateEdit();
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Mods app typing: " + ex.Message);
				instance.EndEdit(keep: false);
			}
			if (Time.unscaledTime >= _nextRefresh)
			{
				_nextRefresh = Time.unscaledTime + 1f;
				instance.Refresh();
			}
		}

		private GameObject Row(float h, Color? bg = null)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			GameObject val = new GameObject("Row");
			val.transform.SetParent((Transform)(object)_list, false);
			val.AddComponent<RectTransform>();
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.preferredHeight = h;
			obj.minHeight = h;
			((Graphic)val.AddComponent<Image>()).color = (Color)(((??)bg) ?? RowBg);
			return val;
		}

		private static Text Label(GameObject row, string text, float right)
		{
			//IL_003b: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Text obj = UIFactory.Text("Text", text, row.transform, 17, (TextAnchor)3, (FontStyle)0);
			obj.horizontalOverflow = (HorizontalWrapMode)0;
			obj.verticalOverflow = (VerticalWrapMode)0;
			obj.supportRichText = true;
			RectTransform rectTransform = ((Graphic)obj).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 0f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.offsetMin = new Vector2(12f, 3f);
			rectTransform.offsetMax = new Vector2(0f - right, -3f);
			return obj;
		}

		private static (Image, Text) Button(GameObject row, string text, Color color, float w, float fromRight, Action click)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("Btn", text, row.transform, color, w, 38f);
			GameObject item = valueTuple.Item1;
			Button item2 = valueTuple.Item2;
			Text item3 = valueTuple.Item3;
			RectTransform component = item.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 0.5f);
			component.anchorMax = new Vector2(1f, 0.5f);
			component.pivot = new Vector2(1f, 0.5f);
			component.anchoredPosition = new Vector2(-10f - fromRight, 0f);
			item3.supportRichText = true;
			Image component2 = item.GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				((Graphic)component2).color = color;
			}
			if (click != null)
			{
				EventHelper.AddListener((Action)delegate
				{
					try
					{
						click();
					}
					catch (Exception ex)
					{
						Core.Log.Warning("Mods app: " + ex.Message);
					}
				}, (UnityEvent)(object)item2.onClick);
			}
			return (component2, item3);
		}

		private static void SetClick(GameObject go, Action click)
		{
			Button component = go.GetComponent<Button>();
			if (!((Object)(object)component != (Object)null))
			{
				return;
			}
			EventHelper.AddListener((Action)delegate
			{
				try
				{
					click();
				}
				catch (Exception ex)
				{
					Core.Log.Warning("Mods app: " + ex.Message);
				}
			}, (UnityEvent)(object)component.onClick);
		}

		private static void AddScrollBar(Transform parent, ScrollRect scroll, float top)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)scroll == (Object)null)
			{
				return;
			}
			try
			{
				scroll.scrollSensitivity = Mathf.Max(scroll.scrollSensitivity, 45f);
				GameObject val = new GameObject("ModsScrollBar");
				val.transform.SetParent(parent, false);
				RectTransform obj = val.AddComponent<RectTransform>();
				obj.anchorMin = new Vector2(1f, 0f);
				obj.anchorMax = new Vector2(1f, 1f);
				obj.pivot = new Vector2(1f, 0.5f);
				obj.offsetMin = new Vector2(-38f, 10f);
				obj.offsetMax = new Vector2(-8f, 0f - top);
				((Graphic)val.AddComponent<Image>()).color = new Color(0.2f, 0.17f, 0.14f);
				GameObject val2 = new GameObject("SlidingArea");
				val2.transform.SetParent(val.transform, false);
				RectTransform obj2 = val2.AddComponent<RectTransform>();
				obj2.anchorMin = Vector2.zero;
				obj2.anchorMax = Vector2.one;
				obj2.offsetMin = new Vector2(3f, 3f);
				obj2.offsetMax = new Vector2(-3f, -3f);
				GameObject val3 = new GameObject("Handle");
				val3.transform.SetParent(val2.transform, false);
				RectTransform val4 = val3.AddComponent<RectTransform>();
				val4.anchorMin = Vector2.zero;
				val4.anchorMax = Vector2.one;
				val4.offsetMin = Vector2.zero;
				val4.offsetMax = Vector2.zero;
				Image val5 = val3.AddComponent<Image>();
				((Graphic)val5).color = Amber;
				Scrollbar val6 = val.AddComponent<Scrollbar>();
				val6.handleRect = val4;
				((Selectable)val6).targetGraphic = (Graphic)(object)val5;
				val6.direction = (Direction)2;
				ColorBlock colors = ((Selectable)val6).colors;
				((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 0.85f, 0.55f);
				((ColorBlock)(ref colors)).pressedColor = new Color(1f, 0.92f, 0.7f);
				((Selectable)val6).colors = colors;
				scroll.verticalScrollbar = val6;
				scroll.verticalScrollbarVisibility = (ScrollbarVisibility)0;
				scroll.verticalScrollbarSpacing = 0f;
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Mods app scroll bar: " + ex.Message);
			}
		}

		private static Sprite MakeIcon()
		{
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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)
			Color32[] array = (Color32[])(object)new Color32[16384];
			Color val = default(Color);
			((Color)(ref val))..ctor(0.36f, 0.22f, 0.11f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.16f, 0.1f, 0.05f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(1f, 0.74f, 0.3f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.95f, 0.88f, 0.75f);
			float[] array2 = new float[3] { 92f, 64f, 36f };
			float[] array3 = new float[3] { 44f, 84f, 60f };
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					Color val5 = val;
					float num = Mathf.Max(0f, Mathf.Max(14f - (float)j, (float)j - 113f));
					float num2 = Mathf.Max(0f, Mathf.Max(14f - (float)i, (float)i - 113f));
					if (num * num + num2 * num2 > 196f)
					{
						array[i * 128 + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
						continue;
					}
					for (int k = 0; k < 3; k++)
					{
						if (j >= 22 && j <= 106 && Mathf.Abs((float)i - array2[k]) <= 4f)
						{
							val5 = (((float)j < array3[k]) ? val4 : val2);
						}
						float num3 = (float)j - array3[k];
						float num4 = (float)i - array2[k];
						if (num3 * num3 + num4 * num4 <= 121f)
						{
							val5 = val3;
						}
					}
					array[i * 128 + j] = Color32.op_Implicit(val5);
				}
			}
			Texture2D val6 = new Texture2D(128, 128, (TextureFormat)4, false);
			val6.SetPixels32(new Il2CppStructArray<Color32>(array));
			val6.Apply();
			((Object)val6).hideFlags = (HideFlags)32;
			Sprite obj = Sprite.Create(val6, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
	internal sealed class ModInfo
	{
		public string Name;

		public string Version;

		public string Author;

		public string File;

		public MelonBase Melon;

		public bool OffNextLaunch;

		public bool NotLoaded;

		public readonly List<MelonPreferences_Category> Categories = new List<MelonPreferences_Category>();

		public IEnumerable<MelonPreferences_Entry> Entries => Categories.SelectMany((MelonPreferences_Category c) => c.Entries.Where((MelonPreferences_Entry e) => e != null && !e.IsHidden));

		public int SettingCount => Entries.Count();

		public bool IsSelf
		{
			get
			{
				if (Melon != null)
				{
					MelonAssembly melonAssembly = Melon.MelonAssembly;
					return ((melonAssembly != null) ? melonAssembly.Assembly : null) == typeof(Prefs).Assembly;
				}
				return false;
			}
		}

		public bool IsLibrary => (Name ?? "").IndexOf("S1API", StringComparison.OrdinalIgnoreCase) >= 0;

		public bool CanTurnOff
		{
			get
			{
				if (!IsSelf)
				{
					return !string.IsNullOrEmpty(File);
				}
				return false;
			}
		}
	}
	internal static class Prefs
	{
		public enum Kind
		{
			Bool,
			Whole,
			Number,
			Choice,
			Key,
			Text,
			Other
		}

		private static string Key(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder();
			string text = s.ToLowerInvariant();
			foreach (char c in text)
			{
				if (char.IsLetterOrDigit(c))
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		public static List<ModInfo> Scan()
		{
			List<ModInfo> list = new List<ModInfo>();
			List<(ModInfo mod, string key)> keys = new List<(ModInfo, string)>();
			foreach (MelonBase registeredMelon in MelonBase.RegisteredMelons)
			{
				if (registeredMelon == null || registeredMelon.Info == null)
				{
					continue;
				}
				ModInfo info = new ModInfo
				{
					Name = registeredMelon.Info.Name,
					Version = registeredMelon.Info.Version,
					Author = registeredMelon.Info.Author,
					Melon = registeredMelon
				};
				try
				{
					info.File = registeredMelon.MelonAssembly.Location;
				}
				catch
				{
				}
				list.Add(info);
				K(registeredMelon.Info.Name);
				try
				{
					string name = registeredMelon.MelonAssembly.Assembly.GetName().Name;
					K(name);
					if (name.Contains('.'))
					{
						K(name.Substring(name.LastIndexOf('.') + 1));
					}
					K(((object)registeredMelon).GetType().Namespace);
					K(((object)registeredMelon).GetType().Name);
				}
				catch
				{
				}
				try
				{
					info.OffNextLaunch = !string.IsNullOrEmpty(info.File) && !File.Exists(info.File) && File.Exists(info.File + ".disabled");
				}
				catch
				{
				}
				void K(string s)
				{
					string text5 = Key(s);
					if (text5.Length >= 3)
					{
						keys.Add((info, text5));
					}
				}
			}
			List<MelonPreferences_Category> list2 = new List<MelonPreferences_Category>();
			foreach (MelonPreferences_Category category in MelonPreferences.Categories)
			{
				if (category == null || category.IsHidden || category.Entries.All((MelonPreferences_Entry e) => e == null || e.IsHidden))
				{
					continue;
				}
				string text = Key(category.Identifier);
				string text2 = Key(category.DisplayName);
				ModInfo modInfo = null;
				int num = 0;
				foreach (var (modInfo2, text3) in keys)
				{
					if ((text == text3 || text2 == text3 || (text3.Length >= 4 && (text.StartsWith(text3) || text2.StartsWith(text3))) || (text.Length >= 5 && text3.StartsWith(text))) && text3.Length > num)
					{
						modInfo = modInfo2;
						num = text3.Length;
					}
				}
				if (modInfo != null)
				{
					modInfo.Categories.Add(category);
				}
				else
				{
					list2.Add(category);
				}
			}
			foreach (MelonPreferences_Category item in list2)
			{
				list.Add(new ModInfo
				{
					Name = (string.IsNullOrWhiteSpace(item.DisplayName) ? item.Identifier : item.DisplayName),
					Version = "",
					Author = "settings",
					Categories = { item }
				});
			}
			try
			{
				foreach (string item2 in (from m in list
					where !string.IsNullOrEmpty(m.File)
					select Path.GetDirectoryName(m.File)).Distinct().ToList())
				{
					string[] files = Directory.GetFiles(item2, "*.dll.disabled");
					foreach (string text4 in files)
					{
						string dll = text4.Substring(0, text4.Length - ".disabled".Length);
						if (!list.Any((ModInfo m) => string.Equals(m.File, dll, StringComparison.OrdinalIgnoreCase)))
						{
							list.Add(new ModInfo
							{
								Name = Pretty(Path.GetFileNameWithoutExtension(dll)),
								Version = "",
								Author = "",
								File = dll,
								OffNextLaunch = true,
								NotLoaded = true
							});
						}
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Couldn't look through the Mods folder: " + ex.Message);
			}
			return (from m in list
				orderby m.NotLoaded, m.Categories.Count == 0
				select m).ThenBy<ModInfo, string>((ModInfo m) => m.Name, StringComparer.OrdinalIgnoreCase).ToList();
		}

		private static string Pretty(string file)
		{
			string text = file;
			if (text.StartsWith("WoodStudios."))
			{
				text = text.Substring(12);
			}
			return text.Replace('_', ' ');
		}

		public static string SetOffNextLaunch(ModInfo m, bool off)
		{
			if (m == null || string.IsNullOrEmpty(m.File))
			{
				return "That mod's file couldn't be found.";
			}
			string file = m.File;
			string text = m.File + ".disabled";
			try
			{
				if (off)
				{
					if (!File.Exists(file))
					{
						return "Already off.";
					}
					if (File.Exists(text))
					{
						File.Delete(text);
					}
					File.Move(file, text);
					m.OffNextLaunch = true;
					Core.Log.Msg(m.Name + " turned off for the next launch (" + Path.GetFileName(text) + ").");
					return m.Name + " won't load next time you start the game.";
				}
				if (!File.Exists(text))
				{
					return "Already on.";
				}
				if (File.Exists(file))
				{
					return "There's already a copy of it turned on.";
				}
				File.Move(text, file);
				m.OffNextLaunch = false;
				Core.Log.Msg(m.Name + " turned back on (" + Path.GetFileName(file) + ").");
				return m.NotLoaded ? (m.Name + " will load next time you start the game.") : (m.Name + " stays on.");
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Couldn't rename " + Path.GetFileName(file) + ": " + ex.Message);
				return "Windows wouldn't let the file be renamed. Close the game and rename it in the Mods folder.";
			}
		}

		public static Kind KindOf(MelonPreferences_Entry e)
		{
			Type reflectedType;
			try
			{
				reflectedType = e.GetReflectedType();
			}
			catch
			{
				return Kind.Other;
			}
			if (reflectedType == typeof(bool))
			{
				return Kind.Bool;
			}
			if (reflectedType == typeof(KeyCode))
			{
				return Kind.Key;
			}
			if (reflectedType.IsEnum)
			{
				return Kind.Choice;
			}
			if (reflectedType == typeof(int) || reflectedType == typeof(long) || reflectedType == typeof(short) || reflectedType == typeof(byte) || reflectedType == typeof(uint) || reflectedType == typeof(ulong) || reflectedType == typeof(ushort) || reflectedType == typeof(sbyte))
			{
				return Kind.Whole;
			}
			if (reflectedType == typeof(float) || reflectedType == typeof(double) || reflectedType == typeof(decimal))
			{
				return Kind.Number;
			}
			if (reflectedType == typeof(string))
			{
				if (!LooksLikeKey(e))
				{
					return Kind.Text;
				}
				return Kind.Key;
			}
			return Kind.Other;
		}

		private static bool LooksLikeKey(MelonPreferences_Entry e)
		{
			string text = e.Identifier ?? "";
			if (!text.EndsWith("Key", StringComparison.OrdinalIgnoreCase) && !text.EndsWith("Keybind", StringComparison.OrdinalIgnoreCase) && !text.EndsWith("Hotkey", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			string text2 = e.BoxedValue as string;
			KeyCode result;
			if (!string.IsNullOrWhiteSpace(text2))
			{
				return Enum.TryParse<KeyCode>(text2.Trim(), ignoreCase: true, out result);
			}
			return false;
		}

		public unsafe static void SetKey(MelonPreferences_Entry e, KeyCode k)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (e.GetReflectedType() == typeof(string))
			{
				Set(e, ((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString());
			}
			else
			{
				Set(e, k);
			}
		}

		public static string Show(MelonPreferences_Entry e)
		{
			//IL_0080: 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)
			try
			{
				object boxedValue = e.BoxedValue;
				KeyCode result;
				return KindOf(e) switch
				{
					Kind.Bool => ((bool)boxedValue) ? "ON" : "OFF", 
					Kind.Number => Convert.ToDouble(boxedValue, CultureInfo.InvariantCulture).ToString("0.###", CultureInfo.InvariantCulture), 
					Kind.Key => (!(boxedValue is string text)) ? KeyName((KeyCode)boxedValue) : (Enum.TryParse<KeyCode>(text.Trim(), ignoreCase: true, out result) ? KeyName(result) : text), 
					Kind.Text => string.IsNullOrEmpty((string)boxedValue) ? "(empty)" : ((string)boxedValue), 
					Kind.Choice => Nice(boxedValue.ToString()), 
					Kind.Other => e.GetValueAsString(), 
					_ => Convert.ToString(boxedValue, CultureInfo.InvariantCulture), 
				};
			}
			catch
			{
				return "?";
			}
		}

		public unsafe static string KeyName(KeyCode k)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected I4, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			string text = ((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString();
			if (text.StartsWith("Alpha"))
			{
				return text.Substring(5);
			}
			if (text.StartsWith("Keypad"))
			{
				return "Num " + text.Substring(6);
			}
			if ((int)k <= 13)
			{
				if ((int)k == 0)
				{
					return "None";
				}
				if ((int)k == 13)
				{
					return "Enter";
				}
			}
			else
			{
				if ((int)k == 96)
				{
					return "`";
				}
				switch (k - 303)
				{
				case 5:
					return "Left Alt";
				case 4:
					return "Right Alt";
				case 1:
					return "Left Shift";
				case 0:
					return "Right Shift";
				case 3:
					return "Left Ctrl";
				case 2:
					return "Right Ctrl";
				}
			}
			return text;
		}

		private static string Nice(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return s;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < s.Length; i++)
			{
				if (i > 0 && char.IsUpper(s[i]) && char.IsLower(s[i - 1]))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append((s[i] == '_') ? ' ' : s[i]);
			}
			return stringBuilder.ToString();
		}

		public static bool Set(MelonPreferences_Entry e, object value)
		{
			try
			{
				Type reflectedType = e.GetReflectedType();
				object obj = value;
				if (obj != null && obj.GetType() != reflectedType && !reflectedType.IsEnum)
				{
					obj = Convert.ChangeType(obj, reflectedType, CultureInfo.InvariantCulture);
				}
				if (e.Validator != null)
				{
					obj = e.Validator.EnsureValid(obj);
				}
				e.BoxedValue = obj;
				MelonPreferences.Save();
				Instance log = Core.Log;
				DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(4, 3);
				MelonPreferences_Category category = e.Category;
				defaultInterpolatedStringHandler.AppendFormatted((category != null) ? category.Identifier : null);
				defaultInterpolatedStringHandler.AppendLiteral(".");
				defaultInterpolatedStringHandler.AppendFormatted(e.Identifier);
				defaultInterpolatedStringHandler.AppendLiteral(" = ");
				defaultInterpolatedStringHandler.AppendFormatted(Show(e));
				log.Msg(defaultInterpolatedStringHandler.ToStringAndClear());
				return true;
			}
			catch (Exception ex)
			{
				Core.Log.Warning("Couldn't set " + e.Identifier + ": " + ex.Message);
				return false;
			}
		}

		public static void Toggle(MelonPreferences_Entry e)
		{
			Set(e, !(bool)e.BoxedValue);
		}

		public static void Cycle(MelonPreferences_Entry e, int dir)
		{
			List<object> list = Enum.GetValues(e.GetReflectedType()).Cast<object>().Distinct()
				.ToList();
			int num = list.IndexOf(e.BoxedValue);
			num = (((num >= 0) ? (num + dir) : 0) % list.Count + list.Count) % list.Count;
			Set(e, list[num]);
		}

		public static void Step(MelonPreferences_Entry e, int dir)
		{
			double num = Convert.ToDouble(e.BoxedValue, CultureInfo.InvariantCulture);
			double num2 = Math.Abs(num);
			if (KindOf(e) == Kind.Whole)
			{
				long num3 = ((num2 >= 2000.0) ? 100 : ((num2 >= 200.0) ? 10 : ((!(num2 >= 50.0)) ? 1 : 5)));
				long v = (long)Math.Round(num) + dir * num3;
				Set(e, ClampWhole(e, v));
				return;
			}
			double num4 = ((num2 >= 100.0) ? 10.0 : ((num2 >= 10.0) ? 1.0 : ((num2 >= 1.0) ? 0.1 : ((num2 >= 0.1) ? 0.05 : 0.01))));
			if (num2 < 1E-09)
			{
				num4 = 0.1;
			}
			Set(e, Math.Round(num + (double)dir * num4, 4));
		}

		private static object ClampWhole(MelonPreferences_Entry e, long v)
		{
			Type reflectedType = e.GetReflectedType();
			if (reflectedType == typeof(byte))
			{
				return (byte)Math.Max(0L, Math.Min(255L, v));
			}
			if (reflectedType == typeof(short))
			{
				return (short)Math.Max(-32768L, Math.Min(32767L, v));
			}
			if (reflectedType == typeof(int))
			{
				return (int)Math.Max(-2147483648L, Math.Min(2147483647L, v));
			}
			if (reflectedType == typeof(uint) || reflectedType == typeof(ulong) || reflectedType == typeof(ushort))
			{
				return Math.Max(0L, v);
			}
			return v;
		}

		public static bool SetFromText(MelonPreferences_Entry e, string text)
		{
			text = (text ?? "").Trim();
			switch (KindOf(e))
			{
			case Kind.Text:
				return Set(e, text);
			case Kind.Whole:
			{
				if (!long.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2))
				{
					return false;
				}
				return Set(e, ClampWhole(e, result2));
			}
			case Kind.Number:
			{
				if (!double.TryParse(text.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					return false;
				}
				return Set(e, result);
			}
			default:
				return false;
			}
		}

		public static bool IsDefault(MelonPreferences_Entry e)
		{
			try
			{
				return e.GetValueAsString() == e.GetDefaultValueAsString();
			}
			catch
			{
				return true;
			}
		}

		public static int ResetAll(ModInfo m)
		{
			int num = 0;
			foreach (MelonPreferences_Entry item in m.Entries.ToList())
			{
				if (!IsDefault(item))
				{
					try
					{
						item.ResetToDefault();
						num++;
					}
					catch
					{
					}
				}
			}
			try
			{
				MelonPreferences.Save();
			}
			catch
			{
			}
			return num;
		}
	}
	internal static class Typing
	{
		private static bool _legacyBroken;

		private static readonly (KeyCode k, char c, char s)[] Keys = Build();

		private static (KeyCode, char, char)[] Build()
		{
			List<(KeyCode, char, char)> list = new List<(KeyCode, char, char)>();
			for (char c = 'a'; c <= 'z'; c = (char)(c + 1))
			{
				list.Add(((KeyCode)(97 + (c - 97)), c, char.ToUpperInvariant(c)));
			}
			string text = ")!@#$%^&*(";
			for (int i = 0; i <= 9; i++)
			{
				list.Add(((KeyCode)(48 + i), (char)(48 + i), text[i]));
			}
			for (int j = 0; j <= 9; j++)
			{
				list.Add(((KeyCode)(256 + j), (char)(48 + j), (char)(48 + j)));
			}
			list.Add(((KeyCode)32, ' ', ' '));
			list.Add(((KeyCode)45, '-', '_'));
			list.Add(((KeyCode)269, '-', '-'));
			list.Add(((KeyCode)61, '=', '+'));
			list.Add(((KeyCode)46, '.', '>'));
			list.Add(((KeyCode)266, '.', '.'));
			list.Add(((KeyCode)44, ',', '<'));
			list.Add(((KeyCode)39, '\'', '"'));
			list.Add(((KeyCode)47, '/', '?'));
			list.Add(((KeyCode)92, '\\', '|'));
			list.Add(((KeyCode)59, ';', ':'));
			list.Add(((KeyCode)91, '[', '{'));
			list.Add(((KeyCode)93, ']', '}'));
			list.Add(((KeyCode)8, '\b', '\b'));
			list.Add(((KeyCode)13, '\n', '\n'));
			list.Add(((KeyCode)271, '\n', '\n'));
			return list.ToArray();
		}

		public static string ThisFrame(bool shift)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!_legacyBroken)
			{
				try
				{
					return Input.inputString ?? "";
				}
				catch
				{
					_legacyBroken = true;
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			(KeyCode, char, char)[] keys = Keys;
			for (int i = 0; i < keys.Length; i++)
			{
				var (key, c, c2) = keys[i];
				if (InputUtil.RawDown(key))
				{
					stringBuilder.Append(shift ? c2 : c);
				}
			}
			return stringBuilder.ToString();
		}
	}
}