Decompiled source of Rebind Controls v1.0.0

RebindControls.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BrigadeModMenu;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RebindControls;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(RebindControlsMod), "Rebind Controls", "1.0.0", "Rebind Controls", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RebindControls")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RebindControls")]
[assembly: AssemblyTitle("RebindControls")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class Tr
{
	private static Func<string, string> _t;

	private static Func<int> _version;

	private static float _nextLook;

	private static bool _found;

	public static int Version
	{
		get
		{
			if (!Find())
			{
				return 0;
			}
			try
			{
				return _version();
			}
			catch
			{
				return 0;
			}
		}
	}

	private static bool Find()
	{
		if (_found)
		{
			return true;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime < _nextLook)
		{
			return false;
		}
		_nextLook = unscaledTime + 5f;
		try
		{
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == "BrigadeModMenu")
				{
					type = assembly.GetType("BrigadeModMenu.Lang");
					break;
				}
			}
			MethodInfo methodInfo = type?.GetMethod("T", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(string) }, null);
			MethodInfo methodInfo2 = type?.GetProperty("Version", BindingFlags.Static | BindingFlags.Public)?.GetGetMethod();
			if (methodInfo == null || methodInfo2 == null)
			{
				return false;
			}
			_t = (Func<string, string>)Delegate.CreateDelegate(typeof(Func<string, string>), methodInfo);
			_version = (Func<int>)Delegate.CreateDelegate(typeof(Func<int>), methodInfo2);
			_found = true;
		}
		catch
		{
		}
		return _found;
	}

	public static string T(string english)
	{
		if (string.IsNullOrEmpty(english) || !Find())
		{
			return english;
		}
		try
		{
			return _t(english);
		}
		catch
		{
			return english;
		}
	}

	public static string F(string englishPattern, params object[] args)
	{
		try
		{
			return string.Format(T(englishPattern), args);
		}
		catch (FormatException)
		{
			return string.Format(englishPattern, args);
		}
	}
}
namespace BrigadeModMenu
{
	public static class ModMenuCompat
	{
		public static Page Entry(this Page page, MelonPreferences_Entry entry, Func<string> label = null)
		{
			if (entry != null)
			{
				return page.Entry(entry.Raw, label ?? ((Func<string>)(() => entry.DisplayName)));
			}
			return page;
		}

		public static Page Category(this Page page, MelonPreferences_Category category)
		{
			if (category == null)
			{
				return page;
			}
			Menu.HideCategory(category.Identifier);
			foreach (MelonPreferences_Entry e in category.Entries)
			{
				if (e != null && !e.IsHidden)
				{
					page.Entry(e.Raw, (Func<string>)(() => e.DisplayName));
				}
			}
			return page;
		}
	}
}
namespace RebindControls
{
	internal static class Capture
	{
		internal const float Seconds = 5f;

		private static string _id;

		private static bool _pad;

		private static bool _armed;

		private static bool _releasing;

		private static float _endAt;

		private static float _nextRescan;

		private static Action<string> _set;

		private static readonly List<InputAction> Paused = new List<InputAction>();

		private static readonly string[] MouseButtons = new string[5] { "leftButton", "rightButton", "middleButton", "backButton", "forwardButton" };

		private static readonly string[] PadButtons = new string[24]
		{
			"buttonSouth", "buttonEast", "buttonWest", "buttonNorth", "leftShoulder", "rightShoulder", "leftTrigger", "rightTrigger", "start", "select",
			"leftStickPress", "rightStickPress", "dpad/up", "dpad/down", "dpad/left", "dpad/right", "leftStick/up", "leftStick/down", "leftStick/left", "leftStick/right",
			"rightStick/up", "rightStick/down", "rightStick/left", "rightStick/right"
		};

		internal static bool Active => _id != null;

		internal static string Text(string id)
		{
			if (_id != id)
			{
				return null;
			}
			int num = Mathf.Max(1, Mathf.CeilToInt(_endAt - Time.unscaledTime));
			return Lang.F(_pad ? "Press a button… {0}" : "Press a key… {0}", new object[1] { num });
		}

		internal static void Start(string id, bool pad, Action<string> set)
		{
			if (_id == id)
			{
				Stop();
				return;
			}
			_id = id;
			_pad = pad;
			_set = set;
			_armed = false;
			_endAt = Time.unscaledTime + 5f;
			if (!_releasing)
			{
				Pause();
			}
			_releasing = false;
		}

		internal static void Tick()
		{
			if (_releasing)
			{
				if (!AnyHeld())
				{
					_releasing = false;
					Resume();
				}
			}
			else
			{
				if (_id == null)
				{
					return;
				}
				KeepPaused();
				if (Time.unscaledTime >= _endAt)
				{
					Stop();
					return;
				}
				if (!_armed)
				{
					if (!AnyHeld())
					{
						_armed = true;
					}
					return;
				}
				string text = (_pad ? PadPressed() : KeyPressed());
				if (text != null)
				{
					Action<string> set = _set;
					Stop();
					try
					{
						set?.Invoke(text);
					}
					catch (Exception ex)
					{
						RebindControlsMod.Log.Warning("setting the control: " + ex.Message);
					}
				}
			}
		}

		private static void Stop()
		{
			_id = null;
			_set = null;
			_releasing = true;
		}

		internal static void Abort()
		{
			_id = null;
			_set = null;
			_releasing = false;
			Resume();
		}

		private static void Pause()
		{
			Keybinds.Suspended = true;
			_nextRescan = 0f;
			KeepPaused();
		}

		private static void KeepPaused()
		{
			if (Time.unscaledTime < _nextRescan)
			{
				return;
			}
			_nextRescan = Time.unscaledTime + 0.25f;
			foreach (InputActionAsset item in Resources.FindObjectsOfTypeAll<InputActionAsset>())
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				ReadOnlyArray<InputActionMap> actionMaps = item.actionMaps;
				for (int i = 0; i < actionMaps.Count; i++)
				{
					InputActionMap obj = actionMaps[i];
					ReadOnlyArray<InputAction> val = ((obj != null) ? obj.actions : null);
					if (val == null)
					{
						continue;
					}
					for (int j = 0; j < val.Count; j++)
					{
						InputAction action = val[j];
						if (action != null && action.enabled)
						{
							action.Disable();
							if (!Paused.Exists((InputAction p) => ((Il2CppObjectBase)p).Pointer == ((Il2CppObjectBase)action).Pointer))
							{
								Paused.Add(action);
							}
						}
					}
				}
			}
		}

		private static void Resume()
		{
			foreach (InputAction item in Paused)
			{
				try
				{
					if (item != null && !((Il2CppObjectBase)item).WasCollected)
					{
						item.Enable();
					}
				}
				catch
				{
				}
			}
			Paused.Clear();
			Keybinds.Suspended = false;
		}

		private static bool AnyHeld()
		{
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current.anyKey).isPressed)
			{
				return true;
			}
			Mouse current2 = Mouse.current;
			if (current2 != null)
			{
				string[] mouseButtons = MouseButtons;
				foreach (string name in mouseButtons)
				{
					ButtonControl obj = Button((InputDevice)(object)current2, name);
					if (obj != null && obj.isPressed)
					{
						return true;
					}
				}
			}
			ReadOnlyArray<Gamepad> all = Gamepad.all;
			for (int j = 0; j < all.Count; j++)
			{
				string[] mouseButtons = PadButtons;
				foreach (string name2 in mouseButtons)
				{
					ButtonControl obj2 = Button((InputDevice)(object)all[j], name2);
					if (obj2 != null && obj2.isPressed)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static string KeyPressed()
		{
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current.anyKey).isPressed)
			{
				ReadOnlyArray<KeyControl> allKeys = current.allKeys;
				for (int i = 0; i < allKeys.Count; i++)
				{
					if (allKeys[i] != null && ((ButtonControl)allKeys[i]).isPressed)
					{
						return "<Keyboard>/" + ((InputControl)allKeys[i]).name;
					}
				}
			}
			Mouse current2 = Mouse.current;
			if (current2 != null)
			{
				string[] mouseButtons = MouseButtons;
				foreach (string text in mouseButtons)
				{
					ButtonControl obj = Button((InputDevice)(object)current2, text);
					if (obj != null && obj.isPressed)
					{
						return "<Mouse>/" + text;
					}
				}
			}
			return null;
		}

		private static string PadPressed()
		{
			ReadOnlyArray<Gamepad> all = Gamepad.all;
			for (int i = 0; i < all.Count; i++)
			{
				string[] padButtons = PadButtons;
				foreach (string text in padButtons)
				{
					ButtonControl obj = Button((InputDevice)(object)all[i], text);
					if (obj != null && obj.isPressed)
					{
						return "<Gamepad>/" + text;
					}
				}
			}
			return null;
		}

		private static ButtonControl Button(InputDevice device, string name)
		{
			try
			{
				object result;
				if (device == null)
				{
					result = null;
				}
				else
				{
					InputControl obj = ((InputControl)device).TryGetChildControl(name);
					result = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<ButtonControl>() : null);
				}
				return (ButtonControl)result;
			}
			catch
			{
				return null;
			}
		}
	}
	internal sealed class Slot
	{
		public string Id;

		public bool Pad;

		public Func<string> Path;

		public Func<string> Default;

		public Action<string> Set;

		public string Scope;

		public bool Changed => Path() != Default();
	}
	internal static class ControlsUi
	{
		private enum Kind
		{
			Header,
			Note,
			Control,
			ResetAll
		}

		private sealed class Entry
		{
			public Kind Kind;

			public string Label;

			public string Section;

			public string Scope;

			public readonly List<Slot> Keys = new List<Slot>();

			public readonly List<Slot> Buttons = new List<Slot>();

			public readonly List<string> FixedKeys = new List<string>();

			public readonly List<string> FixedButtons = new List<string>();

			public float Height => Kind switch
			{
				Kind.Header => 96f, 
				Kind.Note => 150f, 
				_ => 90f, 
			};
		}

		private sealed class Cell
		{
			public GameObject Go;

			public Slot Slot;

			public bool ResetAll;

			public Image Glow;

			public Column Column;

			public int Line;
		}

		private sealed class Column
		{
			public RectTransform Root;

			public GameObject Prompts;

			public ScrollRect Scroll;

			public RectTransform Content;

			public TMP_Text LabelTemplate;

			public bool Pad;

			public bool PlayStation;

			public float Width;

			public readonly List<List<Cell>> Lines = new List<List<Cell>>();

			public readonly List<(TMP_Text label, string text, Entry entry)> Labels = new List<(TMP_Text, string, Entry)>();

			public InputDeviceType Device
			{
				get
				{
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					//IL_0016: Invalid comparison between Unknown and I4
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					if (Pad)
					{
						if (!PlayStation)
						{
							if ((int)Icons.PadType() != 1)
							{
								return Icons.PadType();
							}
							return (InputDeviceType)2;
						}
						return (InputDeviceType)1;
					}
					return (InputDeviceType)0;
				}
			}
		}

		private sealed class Screen
		{
			private readonly Transform _panel;

			private readonly Selectable _tab;

			private readonly List<Column> _columns = new List<Column>();

			private readonly List<Cell> _cells = new List<Cell>();

			private List<Entry> _entries = new List<Entry>();

			private string _built;

			private bool _wasOpen;

			private float _scrollY;

			private float _nextCheck;

			private float _nextFit;

			private string _visibleKey;

			public bool Broken { get; private set; }

			public bool Dead
			{
				get
				{
					if (!((Object)(object)_panel == (Object)null))
					{
						return ((Il2CppObjectBase)_panel).WasCollected;
					}
					return true;
				}
			}

			public bool Is(Transform t)
			{
				if (!Dead)
				{
					return ((Il2CppObjectBase)_panel).Pointer == ((Il2CppObjectBase)t).Pointer;
				}
				return false;
			}

			public static Screen Failed(Transform panel)
			{
				return new Screen(panel);
			}

			private Screen(Transform panel)
			{
				_panel = panel;
				Broken = true;
			}

			public Screen(Transform panel, Selectable tab)
			{
				_panel = panel;
				_tab = tab;
				string[] array = new string[3] { "KeyboardLayout_Panel", "ControllerLayout_Panel", "PS5ControllerLayout_Panel" };
				foreach (string text in array)
				{
					Transform val = Find(panel, text);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Transform val2 = val.Find("Prompts_Panel");
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					TMP_Text val3 = null;
					foreach (TMP_Text componentsInChild in ((Component)val2).GetComponentsInChildren<TMP_Text>(true))
					{
						if (((Object)componentsInChild).name == "Action_Text")
						{
							val3 = componentsInChild;
							break;
						}
					}
					if (!((Object)(object)val3 == (Object)null))
					{
						Column column = new Column
						{
							Root = ((Component)val).GetComponent<RectTransform>(),
							Prompts = ((Component)val2).gameObject,
							LabelTemplate = val3,
							Pad = !text.StartsWith("Keyboard"),
							PlayStation = text.StartsWith("PS5")
						};
						BuildScroll(column, ((Component)val2).GetComponent<RectTransform>());
						_columns.Add(column);
					}
				}
				if (_columns.Count == 0)
				{
					throw new InvalidOperationException("no keyboard / controller layout in the Controls panel");
				}
				RebindControlsMod.Log.Msg($"Controls list added ({_columns.Count} columns)");
			}

			private static Transform Find(Transform t, string name)
			{
				if (((Object)t).name == name)
				{
					return t;
				}
				for (int i = 0; i < t.childCount; i++)
				{
					Transform val = Find(t.GetChild(i), name);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				return null;
			}

			private static void BuildScroll(Column col, RectTransform prompts)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: 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)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: 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)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: 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_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0121: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0162: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: 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)
				RectTransform val = new GameObject("RebindControls_List").AddComponent<RectTransform>();
				((Transform)val).SetParent((Transform)(object)col.Root, false);
				val.anchorMin = prompts.anchorMin;
				val.anchorMax = prompts.anchorMax;
				val.pivot = new Vector2(0f, 0f);
				val.anchoredPosition = prompts.anchoredPosition - Vector2.Scale(prompts.pivot, prompts.sizeDelta) - new Vector2(24f, 0f);
				val.sizeDelta = prompts.sizeDelta + new Vector2(48f, 12f);
				col.Width = prompts.sizeDelta.x;
				ScrollRect val2 = ((Component)val).gameObject.AddComponent<ScrollRect>();
				val2.horizontal = false;
				val2.vertical = true;
				val2.movementType = (MovementType)2;
				val2.scrollSensitivity = 60f;
				val2.inertia = false;
				RectTransform val3 = new GameObject("Viewport").AddComponent<RectTransform>();
				((Transform)val3).SetParent((Transform)(object)val, false);
				val3.anchorMin = Vector2.zero;
				val3.anchorMax = Vector2.one;
				Vector2 offsetMin = (val3.offsetMax = Vector2.zero);
				val3.offsetMin = offsetMin;
				((Component)val3).gameObject.AddComponent<RectMask2D>();
				((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
				RectTransform val4 = new GameObject("Content").AddComponent<RectTransform>();
				((Transform)val4).SetParent((Transform)(object)val3, false);
				val4.anchorMin = new Vector2(0f, 1f);
				val4.anchorMax = new Vector2(1f, 1f);
				val4.pivot = new Vector2(0.5f, 1f);
				val4.sizeDelta = Vector2.zero;
				val4.anchoredPosition = Vector2.zero;
				val2.viewport = val3;
				val2.content = val4;
				col.Scroll = val2;
				col.Content = val4;
			}

			public void Update()
			{
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				bool activeInHierarchy = ((Component)_panel).gameObject.activeInHierarchy;
				bool flag = activeInHierarchy && !_wasOpen;
				_wasOpen = activeInHierarchy;
				if (!activeInHierarchy)
				{
					return;
				}
				foreach (Column column in _columns)
				{
					if ((Object)(object)column.Prompts != (Object)null && column.Prompts.activeSelf)
					{
						column.Prompts.SetActive(false);
					}
				}
				if (flag || Time.unscaledTime >= _nextCheck)
				{
					_nextCheck = Time.unscaledTime + 0.5f;
					Keybinds.All();
					string text = $"{GameControls.Version}/{GameControls.Rows.Count}/{Keybinds.Version}/{_modVersion}/{Icons.PadType()}/{Lang.Version}";
					if (text != _built)
					{
						Rebuild(text);
					}
				}
				string text2 = "";
				foreach (Column column2 in _columns)
				{
					text2 += (((Component)column2.Root).gameObject.activeInHierarchy ? "1" : "0");
				}
				if (text2 != _visibleKey)
				{
					_visibleKey = text2;
					LinkNavigation();
				}
				if (flag)
				{
					OnOpened();
				}
				Countdowns();
				if (Time.unscaledTime >= _nextFit)
				{
					_nextFit = Time.unscaledTime + 0.5f;
					foreach (Column column3 in _columns)
					{
						Lang.FitFonts((Transform)(object)column3.Content);
					}
				}
				ResetKey();
				KeepSelectionVisible();
				SyncScroll();
				WheelBetweenColumns();
				Highlight();
			}

			private void OnOpened()
			{
				string focus = FocusSection;
				FocusSection = null;
				int num = 0;
				if (focus != null)
				{
					int num2 = _entries.FindIndex((Entry e) => e.Kind == Kind.Header && e.Section == focus);
					if (num2 >= 0)
					{
						num = num2;
						float num3 = 0f;
						for (int num4 = 0; num4 < num2; num4++)
						{
							num3 += _entries[num4].Height;
						}
						SetScroll(num3);
					}
				}
				if (MouseMode() && focus == null)
				{
					return;
				}
				Column column = VisibleColumns().Find((Column c) => true);
				if (column == null)
				{
					return;
				}
				for (int num5 = num; num5 < column.Lines.Count; num5++)
				{
					Cell cell = column.Lines[num5].Find((Cell c) => c.Slot != null);
					if (cell != null)
					{
						Select(cell.Go);
						break;
					}
				}
			}

			private void Rebuild(string key)
			{
				_built = key;
				Cell cell = SelectedCell();
				string selectedId = ((cell == null) ? null : ((cell.ResetAll ? "reset" : cell.Slot?.Id) + (cell.Column.Pad ? "|pad" : "|kb")));
				_entries = Entries();
				_conflicts = Conflicts(_entries);
				_cells.Clear();
				foreach (Column column in _columns)
				{
					Build(column);
					Lang.FitFonts((Transform)(object)column.Content);
				}
				LinkNavigation();
				if (selectedId != null)
				{
					Cell cell2 = _cells.Find((Cell c) => (c.ResetAll ? "reset" : c.Slot?.Id) + (c.Column.Pad ? "|pad" : "|kb") == selectedId);
					if (cell2 != null)
					{
						Select(cell2.Go);
					}
				}
			}

			private void Build(Column col)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_038d: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03dd: 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_0201: 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)
				//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0300: Unknown result type (might be due to invalid IL or missing references)
				//IL_0354: Unknown result type (might be due to invalid IL or missing references)
				for (int num = ((Transform)col.Content).childCount - 1; num >= 0; num--)
				{
					GameObject gameObject = ((Component)((Transform)col.Content).GetChild(num)).gameObject;
					gameObject.SetActive(false);
					Object.Destroy((Object)(object)gameObject);
				}
				col.Lines.Clear();
				col.Labels.Clear();
				InputDeviceType device = col.Device;
				float num2 = 0f;
				for (int i = 0; i < _entries.Count; i++)
				{
					Entry entry = _entries[i];
					RectTransform val = new GameObject("Row" + i).AddComponent<RectTransform>();
					((Transform)val).SetParent((Transform)(object)col.Content, false);
					val.anchorMin = new Vector2(0f, 1f);
					val.anchorMax = new Vector2(0f, 1f);
					val.pivot = new Vector2(0f, 1f);
					val.anchoredPosition = new Vector2(24f, 0f - num2);
					val.sizeDelta = new Vector2(col.Width, entry.Height);
					num2 += entry.Height;
					List<Cell> list = new List<Cell>();
					col.Lines.Add(list);
					switch (entry.Kind)
					{
					case Kind.Header:
						Label(col, val, entry.Label, 0f, col.Width, Gold, 1f, entry).alignment = (TextAlignmentOptions)1025;
						continue;
					case Kind.Note:
						Label(col, val, Lang.T(col.Pad ? "Pick a button, then press the new one within 5 seconds. X / Square: back to the game's button." : "Click a key, then press the new one within 5 seconds. Delete: back to the game's key.") + ((_conflicts.Count > 0) ? ("\n<color=#E8524A>" + Lang.T("Red: also used by another control.") + "</color>") : ""), 0f, col.Width, Dim, 0.62f, entry).textWrappingMode = (TextWrappingModes)1;
						continue;
					case Kind.ResetAll:
					{
						Cell cell = Key(col, val, null, device, list, i, Lang.T(col.Pad ? "Reset All Buttons" : "Reset All Keys"));
						cell.ResetAll = true;
						bool pad = col.Pad;
						((UnityEvent)cell.Go.GetComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)delegate
						{
							Capture.Abort();
							ResetAll(pad);
						}));
						Arrange(list, val, 0f, col.Width);
						continue;
					}
					}
					List<Slot> obj = (col.Pad ? entry.Buttons : entry.Keys);
					List<string> list2 = (col.Pad ? entry.FixedButtons : entry.FixedKeys);
					foreach (Slot item in obj)
					{
						Key(col, val, item, device, list, i, null);
					}
					foreach (string item2 in list2)
					{
						Key(col, val, null, device, list, i, null, item2);
					}
					float num3 = Arrange(list, val, 568f, col.Width);
					Label(col, val, entry.Label, 0f, num3 - 20f, Color.white, 1f, entry);
				}
				col.Content.sizeDelta = new Vector2(0f, num2 + 30f);
				RectTransform content = col.Content;
				float scrollY = _scrollY;
				float num4 = num2 + 30f;
				Rect rect = col.Scroll.viewport.rect;
				content.anchoredPosition = new Vector2(0f, Mathf.Clamp(scrollY, 0f, Mathf.Max(0f, num4 - ((Rect)(ref rect)).height)));
			}

			private static float Arrange(List<Cell> cells, RectTransform row, float x, float width)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: 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)
				float num = 0f;
				foreach (Cell cell in cells)
				{
					num += cell.Go.GetComponent<RectTransform>().sizeDelta.x + 10f;
				}
				num -= 10f;
				float num2 = Mathf.Max(0f, Mathf.Min(x, width - num));
				float num3 = num2;
				foreach (Cell cell2 in cells)
				{
					RectTransform component = cell2.Go.GetComponent<RectTransform>();
					component.anchoredPosition = new Vector2(num3, 0f);
					num3 += component.sizeDelta.x + 10f;
				}
				return num2;
			}

			private TMP_Text Label(Column col, RectTransform row, string text, float x, float width, Color color, float scale, Entry entry)
			{
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: 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_012c: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = Object.Instantiate<GameObject>(((Component)col.LabelTemplate).gameObject, (Transform)(object)row, false);
				((Object)val).name = "Label";
				val.SetActive(true);
				foreach (MonoBehaviour component2 in val.GetComponents<MonoBehaviour>())
				{
					if ((Object)(object)component2 != (Object)null && ((MemberInfo)((Object)component2).GetIl2CppType()).Name != "TextMeshProUGUI")
					{
						Object.DestroyImmediate((Object)(object)component2);
					}
				}
				TMP_Text component = val.GetComponent<TMP_Text>();
				component.text = text;
				((Graphic)component).color = color;
				if (scale != 1f)
				{
					component.enableAutoSizing = false;
					component.fontSize = col.LabelTemplate.fontSize * scale;
				}
				component.textWrappingMode = (TextWrappingModes)0;
				component.overflowMode = (TextOverflowModes)1;
				component.alignment = (TextAlignmentOptions)4097;
				((Graphic)component).raycastTarget = false;
				RectTransform rectTransform = component.rectTransform;
				rectTransform.anchorMin = new Vector2(0f, 0f);
				rectTransform.anchorMax = new Vector2(0f, 1f);
				rectTransform.pivot = new Vector2(0f, 0.5f);
				rectTransform.anchoredPosition = new Vector2(x, 0f);
				rectTransform.sizeDelta = new Vector2(width, 0f);
				col.Labels.Add((component, text, entry));
				return component;
			}

			private Cell Key(Column col, RectTransform row, Slot slot, InputDeviceType device, List<Cell> cells, int line, string word, string fixedPath = null)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0149: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_018d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cd: 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_0204: Unknown result type (might be due to invalid IL or missing references)
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0232: Unknown result type (might be due to invalid IL or missing references)
				//IL_0233: Unknown result type (might be due to invalid IL or missing references)
				//IL_023a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_0249: Unknown result type (might be due to invalid IL or missing references)
				//IL_0276: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_0299: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_037f: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_049a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0475: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_040c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0424: Unknown result type (might be due to invalid IL or missing references)
				//IL_0429: Unknown result type (might be due to invalid IL or missing references)
				//IL_042a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0431: Unknown result type (might be due to invalid IL or missing references)
				//IL_0441: Unknown result type (might be due to invalid IL or missing references)
				//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0505: Unknown result type (might be due to invalid IL or missing references)
				//IL_050c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0524: Unknown result type (might be due to invalid IL or missing references)
				//IL_053f: Unknown result type (might be due to invalid IL or missing references)
				//IL_055a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0572: Unknown result type (might be due to invalid IL or missing references)
				string path = ((slot != null) ? slot.Path() : fixedPath);
				RectTransform val = new GameObject((slot != null) ? "Key" : ((word != null) ? "ResetAll" : "Fixed")).AddComponent<RectTransform>();
				((Transform)val).SetParent((Transform)(object)row, false);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, 0.5f);
				val.anchorMax = val2;
				val.anchorMin = val2;
				val.pivot = new Vector2(0f, 0.5f);
				bool flag = slot != null && _conflicts.Contains(slot.Id);
				if (flag)
				{
					Image obj = new GameObject("Conflict").AddComponent<Image>();
					((Transform)((Graphic)obj).rectTransform).SetParent((Transform)(object)val, false);
					((Graphic)obj).rectTransform.anchorMin = Vector2.zero;
					((Graphic)obj).rectTransform.anchorMax = Vector2.one;
					((Graphic)obj).rectTransform.offsetMin = new Vector2(-6f, -6f);
					((Graphic)obj).rectTransform.offsetMax = new Vector2(6f, 6f);
					obj.sprite = Icons.Round();
					obj.type = (Type)1;
					((Graphic)obj).color = Conflict;
					((Graphic)obj).raycastTarget = false;
				}
				Image val3 = new GameObject("Glow").AddComponent<Image>();
				((Transform)((Graphic)val3).rectTransform).SetParent((Transform)(object)val, false);
				((Graphic)val3).rectTransform.anchorMin = Vector2.zero;
				((Graphic)val3).rectTransform.anchorMax = Vector2.one;
				((Graphic)val3).rectTransform.offsetMin = new Vector2(-8f, -8f);
				((Graphic)val3).rectTransform.offsetMax = new Vector2(8f, 8f);
				val3.sprite = Icons.Round();
				val3.type = (Type)1;
				((Graphic)val3).color = new Color(Gold.r, Gold.g, Gold.b, 0f);
				((Graphic)val3).raycastTarget = false;
				Image val4 = new GameObject("Icon").AddComponent<Image>();
				((Transform)((Graphic)val4).rectTransform).SetParent((Transform)(object)val, false);
				((Graphic)val4).rectTransform.anchorMin = Vector2.zero;
				((Graphic)val4).rectTransform.anchorMax = Vector2.one;
				val2 = (((Graphic)val4).rectTransform.offsetMin = (((Graphic)val4).rectTransform.offsetMax = Vector2.zero));
				Sprite val6 = ((word == null) ? Icons.For(path, device) : null);
				float num = 76f;
				if ((Object)(object)val6 != (Object)null)
				{
					val4.sprite = val6;
					val4.preserveAspect = true;
					Rect rect = val6.rect;
					float num2;
					if (!(((Rect)(ref rect)).height > 0f))
					{
						num2 = 1f;
					}
					else
					{
						rect = val6.rect;
						float width = ((Rect)(ref rect)).width;
						rect = val6.rect;
						num2 = width / ((Rect)(ref rect)).height;
					}
					float num3 = num2;
					num = Mathf.Max(76f, 76f * num3);
				}
				else
				{
					val4.sprite = Icons.Keycap();
					val4.type = (Type)1;
					TMP_Text component = Object.Instantiate<GameObject>(((Component)col.LabelTemplate).gameObject, ((Component)val4).transform, false).GetComponent<TMP_Text>();
					((Object)((Component)component).gameObject).name = "Word";
					((Component)component).gameObject.SetActive(true);
					foreach (MonoBehaviour component2 in ((Component)component).GetComponents<MonoBehaviour>())
					{
						if ((Object)(object)component2 != (Object)null && ((MemberInfo)((Object)component2).GetIl2CppType()).Name != "TextMeshProUGUI")
						{
							Object.DestroyImmediate((Object)(object)component2);
						}
					}
					string text = (component.text = word ?? Icons.Word(path, device));
					component.enableAutoSizing = false;
					component.fontSize = Mathf.Min(col.LabelTemplate.fontSize, 40f) * ((text.Length <= 2) ? 1f : 0.8f);
					component.textWrappingMode = (TextWrappingModes)0;
					component.alignment = (TextAlignmentOptions)514;
					((Graphic)component).color = Color.white;
					((Graphic)component).raycastTarget = false;
					component.rectTransform.anchorMin = Vector2.zero;
					component.rectTransform.anchorMax = Vector2.one;
					val2 = (component.rectTransform.offsetMin = (component.rectTransform.offsetMax = Vector2.zero));
					num = Mathf.Max(76f, component.GetPreferredValues(text).x + 36f);
				}
				if (slot == null && word == null)
				{
					((Graphic)val4).color = new Color(1f, 1f, 1f, 0.75f);
				}
				else if (flag)
				{
					((Graphic)val4).color = new Color(1f, 0.7f, 0.7f, 1f);
				}
				val.sizeDelta = new Vector2(num, 76f);
				if (slot != null && slot.Changed)
				{
					Image val8 = new GameObject("Changed").AddComponent<Image>();
					((Transform)((Graphic)val8).rectTransform).SetParent((Transform)(object)val, false);
					RectTransform rectTransform = ((Graphic)val8).rectTransform;
					RectTransform rectTransform2 = ((Graphic)val8).rectTransform;
					((Vector2)(ref val2))..ctor(1f, 1f);
					rectTransform2.anchorMax = val2;
					rectTransform.anchorMin = val2;
					((Graphic)val8).rectTransform.pivot = new Vector2(0.5f, 0.5f);
					((Graphic)val8).rectTransform.anchoredPosition = new Vector2(-4f, -4f);
					((Graphic)val8).rectTransform.sizeDelta = new Vector2(22f, 22f);
					val8.sprite = Icons.Round();
					((Graphic)val8).color = Gold;
					((Graphic)val8).raycastTarget = false;
				}
				Cell cell = new Cell
				{
					Go = ((Component)val).gameObject,
					Slot = slot,
					Glow = val3,
					Column = col,
					Line = line
				};
				if (slot != null || word != null)
				{
					Button val9 = ((Component)val).gameObject.AddComponent<Button>();
					((Selectable)val9).targetGraphic = (Graphic)(object)val4;
					((Selectable)val9).transition = (Transition)0;
					if (slot != null)
					{
						Slot s = slot;
						((UnityEvent)val9.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
						{
							Capture.Start(s.Id, s.Pad, s.Set);
						}));
					}
					_cells.Add(cell);
				}
				else
				{
					((Graphic)val4).raycastTarget = false;
				}
				cells.Add(cell);
				return cell;
			}

			private List<Column> VisibleColumns()
			{
				List<Column> list = _columns.FindAll((Column c) => (Object)(object)c.Root != (Object)null && ((Component)c.Root).gameObject.activeInHierarchy);
				list.Sort((Column a, Column b) => ((Transform)a.Root).position.x.CompareTo(((Transform)b.Root).position.x));
				return list;
			}

			private void LinkNavigation()
			{
				//IL_019b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Invalid comparison between Unknown and I4
				//IL_0065: 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_0073: Expected O, but got Unknown
				List<Column> list = VisibleColumns();
				int count = _entries.Count;
				for (int i = 0; i < list.Count; i++)
				{
					Column column = list[i];
					for (int j = 0; j < column.Lines.Count; j++)
					{
						List<Cell> list2 = column.Lines[j].FindAll((Cell c) => (Object)(object)c.Go.GetComponent<Button>() != (Object)null);
						for (int num = 0; num < list2.Count; num++)
						{
							Navigation val = new Navigation
							{
								mode = (Mode)4
							};
							val.selectOnUp = Near(column, j, -1, num);
							val.selectOnDown = Near(column, j, 1, num);
							val.selectOnLeft = ((num > 0) ? Sel(list2[num - 1]) : ((i > 0) ? (Last(list[i - 1], j) ?? _tab) : _tab));
							val.selectOnRight = ((num < list2.Count - 1) ? Sel(list2[num + 1]) : ((i < list.Count - 1) ? First(list[i + 1], j) : null));
							((Selectable)list2[num].Go.GetComponent<Button>()).navigation = val;
						}
					}
				}
				if (!((Object)(object)_tab != (Object)null) || list.Count <= 0)
				{
					return;
				}
				Navigation navigation = _tab.navigation;
				if ((int)navigation.mode == 4)
				{
					Selectable val2 = First(list[0], 0);
					int num2 = 1;
					while ((Object)(object)val2 == (Object)null && num2 < count)
					{
						val2 = First(list[0], num2);
						num2++;
					}
					navigation.selectOnRight = val2;
					_tab.navigation = navigation;
				}
			}

			private static Selectable Sel(Cell c)
			{
				if (c == null)
				{
					return null;
				}
				return (Selectable)(object)c.Go.GetComponent<Button>();
			}

			private static Selectable Near(Column col, int line, int step, int j)
			{
				for (int i = line + step; i >= 0 && i < col.Lines.Count; i += step)
				{
					List<Cell> list = col.Lines[i].FindAll((Cell c) => (Object)(object)c.Go.GetComponent<Button>() != (Object)null);
					if (list.Count > 0)
					{
						return Sel(list[Math.Min(j, list.Count - 1)]);
					}
				}
				return null;
			}

			private static Selectable First(Column col, int line)
			{
				if (line >= col.Lines.Count)
				{
					return null;
				}
				return Sel(col.Lines[line].Find((Cell c) => (Object)(object)c.Go.GetComponent<Button>() != (Object)null)) ?? Near(col, line, -1, 0) ?? Near(col, line, 1, 0);
			}

			private static Selectable Last(Column col, int line)
			{
				if (line >= col.Lines.Count)
				{
					return null;
				}
				List<Cell> list = col.Lines[line].FindAll((Cell c) => (Object)(object)c.Go.GetComponent<Button>() != (Object)null);
				Selectable obj;
				if (list.Count <= 0)
				{
					obj = Near(col, line, -1, 99);
					if (obj == null)
					{
						return Near(col, line, 1, 99);
					}
				}
				else
				{
					obj = Sel(list[list.Count - 1]);
				}
				return obj;
			}

			private Cell SelectedCell()
			{
				EventSystem current = EventSystem.current;
				GameObject selected = ((current != null) ? current.currentSelectedGameObject : null);
				if ((Object)(object)selected == (Object)null)
				{
					return null;
				}
				return _cells.Find((Cell c) => (Object)(object)c.Go != (Object)null && ((Il2CppObjectBase)c.Go).Pointer == ((Il2CppObjectBase)selected).Pointer);
			}

			private static void Select(GameObject go)
			{
				try
				{
					UINavigator instance = SingletonPersistent<UINavigator>.Instance;
					if (instance != null)
					{
						instance.SetSelected(go);
					}
				}
				catch
				{
					EventSystem current = EventSystem.current;
					if (current != null)
					{
						current.SetSelectedGameObject(go);
					}
				}
			}

			private void ResetKey()
			{
				if (Capture.Active)
				{
					return;
				}
				Cell cell = SelectedCell();
				if (cell?.Slot != null && cell.Slot.Changed)
				{
					Keyboard current = Keyboard.current;
					bool flag = current != null && (((ButtonControl)current.deleteKey).wasPressedThisFrame || ((ButtonControl)current.backspaceKey).wasPressedThisFrame);
					ReadOnlyArray<Gamepad> all = Gamepad.all;
					int num = 0;
					while (!flag && num < all.Count)
					{
						flag = all[num].buttonWest.wasPressedThisFrame;
						num++;
					}
					if (flag)
					{
						Slot slot = cell.Slot;
						slot.Set(slot.Default());
					}
				}
			}

			private void Countdowns()
			{
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				foreach (Column column in _columns)
				{
					foreach (var (val, text, entry) in column.Labels)
					{
						if ((Object)(object)val == (Object)null || entry.Kind != Kind.Control)
						{
							continue;
						}
						string text2 = null;
						foreach (Slot item in column.Pad ? entry.Buttons : entry.Keys)
						{
							if (text2 == null)
							{
								text2 = Capture.Text(item.Id);
							}
						}
						string text3 = text2 ?? text;
						if (val.text != text3)
						{
							val.text = text3;
							((Graphic)val).color = ((text2 != null) ? Gold : Color.white);
						}
					}
				}
			}

			private void Highlight()
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				EventSystem current = EventSystem.current;
				GameObject val = ((current != null) ? current.currentSelectedGameObject : null);
				bool flag = MouseMode();
				Mouse current2 = Mouse.current;
				Vector2 val2 = (Vector2)((current2 != null) ? ((InputControl<Vector2>)(object)((Pointer)current2).position).ReadValue() : new Vector2(-1f, -1f));
				Canvas componentInParent = ((Component)_panel).GetComponentInParent<Canvas>();
				Camera val3 = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
				foreach (Cell cell in _cells)
				{
					if (!((Object)(object)cell.Go == (Object)null) && !((Object)(object)cell.Glow == (Object)null))
					{
						bool num = cell.Slot != null && Capture.Text(cell.Slot.Id) != null;
						bool flag2 = (flag ? RectTransformUtility.RectangleContainsScreenPoint(cell.Go.GetComponent<RectTransform>(), val2, val3) : ((Object)(object)val != (Object)null && ((Il2CppObjectBase)val).Pointer == ((Il2CppObjectBase)cell.Go).Pointer));
						float num2 = (num ? (0.6f + 0.4f * Mathf.Abs(Mathf.Sin(Time.unscaledTime * 4f))) : (flag2 ? 0.9f : 0f));
						if (Mathf.Abs(((Graphic)cell.Glow).color.a - num2) > 0.01f)
						{
							((Graphic)cell.Glow).color = new Color(Gold.r, Gold.g, Gold.b, num2);
						}
					}
				}
			}

			private void KeepSelectionVisible()
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				Cell cell = SelectedCell();
				if (cell == null || MouseMode())
				{
					return;
				}
				RectTransform viewport = cell.Column.Scroll.viewport;
				Il2CppStructArray<Vector3> val = new Il2CppStructArray<Vector3>(4L);
				cell.Go.GetComponent<RectTransform>().GetWorldCorners(val);
				float y = ((Transform)viewport).InverseTransformPoint(((Il2CppArrayBase<Vector3>)(object)val)[1]).y;
				float y2 = ((Transform)viewport).InverseTransformPoint(((Il2CppArrayBase<Vector3>)(object)val)[0]).y;
				float num = 0f;
				float num2 = y + 100f;
				Rect rect = viewport.rect;
				if (num2 > ((Rect)(ref rect)).yMax)
				{
					float num3 = y + 100f;
					rect = viewport.rect;
					num = num3 - ((Rect)(ref rect)).yMax;
				}
				else
				{
					float num4 = y2 - 40f;
					rect = viewport.rect;
					if (num4 < ((Rect)(ref rect)).yMin)
					{
						float num5 = y2 - 40f;
						rect = viewport.rect;
						num = num5 - ((Rect)(ref rect)).yMin;
					}
				}
				if (Mathf.Abs(num) > 0.5f)
				{
					SetScroll(cell.Column.Content.anchoredPosition.y - num);
				}
			}

			private void WheelBetweenColumns()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: 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_005b: 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)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				Mouse current = Mouse.current;
				if (current == null)
				{
					return;
				}
				float y = ((InputControl<Vector2>)(object)current.scroll).ReadValue().y;
				if (Mathf.Abs(y) < 0.01f)
				{
					return;
				}
				Canvas componentInParent = ((Component)_panel).GetComponentInParent<Canvas>();
				Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
				Vector2 val2 = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
				RectTransform component = ((Component)_panel).GetComponent<RectTransform>();
				if ((Object)(object)component == (Object)null || !RectTransformUtility.RectangleContainsScreenPoint(component, val2, val))
				{
					return;
				}
				foreach (Column column in _columns)
				{
					if (((Component)column.Root).gameObject.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(column.Scroll.viewport, val2, val))
					{
						return;
					}
				}
				SetScroll(_scrollY - Mathf.Sign(y) * 60f);
			}

			private void SyncScroll()
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				foreach (Column column in _columns)
				{
					float y = column.Content.anchoredPosition.y;
					if (Mathf.Abs(y - _scrollY) > 0.5f && ((Component)column.Root).gameObject.activeInHierarchy)
					{
						SetScroll(y);
						break;
					}
				}
			}

			private void SetScroll(float y)
			{
				//IL_0021: 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_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				foreach (Column column in _columns)
				{
					float y2 = column.Content.sizeDelta.y;
					Rect rect = column.Scroll.viewport.rect;
					float num = Mathf.Max(0f, y2 - ((Rect)(ref rect)).height);
					_scrollY = Mathf.Clamp(y, 0f, num);
					column.Content.anchoredPosition = new Vector2(0f, _scrollY);
				}
			}
		}

		private static readonly List<Screen> Screens = new List<Screen>();

		private static float _nextScan;

		internal static string FocusSection;

		private static int _modVersion;

		private static HashSet<string> _conflicts = new HashSet<string>();

		private static readonly Color Conflict = new Color(0.9f, 0.22f, 0.2f, 1f);

		private static readonly Color Gold = new Color(0.96f, 0.76f, 0.3f, 1f);

		private static readonly Color Dim = new Color(1f, 1f, 1f, 0.6f);

		internal static void Init()
		{
			Keybinds.OpenEditor = delegate(string id)
			{
				FocusSection = id;
				if (!Menu.OpenTab("Controls"))
				{
					FocusSection = null;
				}
			};
		}

		internal static void Tick()
		{
			if (Time.unscaledTime >= _nextScan)
			{
				_nextScan = Time.unscaledTime + 1f;
				Screens.RemoveAll((Screen s) => s.Dead);
				foreach (SettingsPanel item in Object.FindObjectsOfType<SettingsPanel>())
				{
					List<SubPanel> subPanels = item.subPanels;
					int num = 0;
					while (subPanels != null && num < subPanels.Count)
					{
						SubPanel val = subPanels[num];
						if (!((Object)(object)((val != null) ? val.Panel : null) == (Object)null) && ((Object)val.Panel).name.Contains("Controls"))
						{
							Transform panel = ((Component)val.Panel).transform;
							if (!Screens.Exists((Screen s) => s.Is(panel)))
							{
								try
								{
									List<Screen> screens = Screens;
									Transform panel2 = panel;
									SelectableButton button = val.Button;
									screens.Add(new Screen(panel2, (Selectable)(object)((button != null) ? ((Component)button).GetComponent<Button>() : null)));
								}
								catch (Exception value)
								{
									RebindControlsMod.Log.Error($"couldn't build the Controls list: {value}");
									Screens.Add(Screen.Failed(panel));
								}
							}
						}
						num++;
					}
				}
			}
			foreach (Screen screen in Screens)
			{
				if (!screen.Dead && !screen.Broken)
				{
					try
					{
						screen.Update();
					}
					catch (Exception ex)
					{
						RebindControlsMod.Log.Warning("controls list: " + ex.Message);
					}
				}
			}
		}

		private static List<Entry> Entries()
		{
			List<Entry> list = new List<Entry>
			{
				new Entry
				{
					Kind = Kind.Note
				}
			};
			string text = null;
			foreach (GameRow row in GameControls.Rows)
			{
				if (row.Map != text)
				{
					text = row.Map;
					list.Add(new Entry
					{
						Kind = Kind.Header,
						Label = Lang.T(GameControls.MapTitle(text)),
						Section = "game:" + text
					});
				}
				Entry entry = new Entry
				{
					Kind = Kind.Control,
					Label = Lang.T(row.Label),
					Scope = row.Map
				};
				foreach (GameSlot key2 in row.Keys)
				{
					entry.Keys.Add(GameSlot(key2));
				}
				foreach (GameSlot button in row.Buttons)
				{
					entry.Buttons.Add(GameSlot(button));
				}
				entry.FixedKeys.AddRange(row.FixedKeys);
				entry.FixedButtons.AddRange(row.FixedButtons);
				list.Add(entry);
			}
			List<string> list2 = new List<string>();
			List<Keybind> list3 = Keybinds.All();
			foreach (Keybind item in list3)
			{
				if (!list2.Contains(item.ModId))
				{
					list2.Add(item.ModId);
				}
			}
			foreach (string modId in list2)
			{
				List<Keybind> list4 = list3.FindAll((Keybind k) => k.ModId == modId);
				list.Add(new Entry
				{
					Kind = Kind.Header,
					Label = Lang.T(list4[0].ModName ?? modId),
					Section = modId
				});
				foreach (Keybind item2 in list4)
				{
					Keybind key = item2;
					string text2;
					try
					{
						text2 = key.Label?.Invoke() ?? key.Id;
					}
					catch
					{
						text2 = key.Id;
					}
					Entry entry2 = new Entry
					{
						Kind = Kind.Control,
						Label = Lang.T(text2)
					};
					entry2.Keys.Add(new Slot
					{
						Id = $"mod:{modId}/{key.Id}:kb",
						Pad = false,
						Scope = "Gameplay",
						Path = () => key.Keyboard,
						Default = () => key.DefaultKeyboard,
						Set = delegate(string path)
						{
							SetMod(key, pad: false, path);
						}
					});
					if (!key.KeyboardOnly)
					{
						entry2.Buttons.Add(new Slot
						{
							Id = $"mod:{modId}/{key.Id}:pad",
							Pad = true,
							Scope = "Gameplay",
							Path = () => key.Gamepad,
							Default = () => key.DefaultGamepad,
							Set = delegate(string path)
							{
								SetMod(key, pad: true, path);
							}
						});
					}
					list.Add(entry2);
				}
			}
			list.Add(new Entry
			{
				Kind = Kind.ResetAll
			});
			return list;
		}

		private static Slot GameSlot(GameSlot s)
		{
			return new Slot
			{
				Id = "game:" + s.Key,
				Pad = s.Pad,
				Scope = s.Map,
				Path = () => s.Path,
				Default = () => s.Default,
				Set = delegate(string path)
				{
					GameControls.Set(s, path);
				}
			};
		}

		private static void SetMod(Keybind key, bool pad, string path)
		{
			string text = (pad ? key.Gamepad : key.Keyboard);
			if (!(path == text))
			{
				if (pad)
				{
					key.Gamepad = path;
				}
				else
				{
					key.Keyboard = path;
				}
				_modVersion++;
			}
		}

		private static HashSet<string> Conflicts(List<Entry> entries)
		{
			Dictionary<string, List<(string id, bool changed)>> uses = new Dictionary<string, List<(string, bool)>>();
			foreach (Entry entry in entries)
			{
				if (entry.Kind != Kind.Control)
				{
					continue;
				}
				foreach (Slot key2 in entry.Keys)
				{
					Use(key2.Scope, pad: false, key2.Path(), key2.Id, key2.Changed);
				}
				foreach (Slot button in entry.Buttons)
				{
					Use(button.Scope, pad: true, button.Path(), button.Id, button.Changed);
				}
				foreach (string fixedKey in entry.FixedKeys)
				{
					Use(entry.Scope, pad: false, fixedKey, null, changed: false);
				}
				foreach (string fixedButton in entry.FixedButtons)
				{
					Use(entry.Scope, pad: true, fixedButton, null, changed: false);
				}
			}
			HashSet<string> hashSet = new HashSet<string>();
			foreach (List<(string, bool)> value2 in uses.Values)
			{
				if (value2.Count < 2 || !value2.Exists(((string id, bool changed) u) => u.changed))
				{
					continue;
				}
				foreach (var item in value2)
				{
					if (item.Item1 != null)
					{
						hashSet.Add(item.Item1);
					}
				}
			}
			return hashSet;
			void Use(string scope, bool pad, string path, string id, bool changed)
			{
				if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(scope))
				{
					string key = $"{scope}|{pad}|{path}";
					if (!uses.TryGetValue(key, out List<(string, bool)> value))
					{
						value = (uses[key] = new List<(string, bool)>());
					}
					value.Add((id, changed));
				}
			}
		}

		private static void ResetAll(bool pad)
		{
			GameControls.ResetAll(pad);
			foreach (Keybind item in Keybinds.All())
			{
				if (pad)
				{
					if (!item.KeyboardOnly)
					{
						item.Gamepad = item.DefaultGamepad;
					}
				}
				else
				{
					item.Keyboard = item.DefaultKeyboard;
				}
			}
			_modVersion++;
		}

		private static bool MouseMode()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			try
			{
				return (Object)(object)SingletonPersistent<UINavigator>.Instance == (Object)null || (int)SingletonPersistent<UINavigator>.Instance.CurrentNavigationMode == 0;
			}
			catch
			{
				return true;
			}
		}
	}
	internal sealed class GameSlot
	{
		public string Map;

		public string Action;

		public string Default;

		public int Index;

		public bool Pad;

		public string Key => $"{Map}/{Action}/{Index}";

		public string Path
		{
			get
			{
				if (!GameControls.Overrides.TryGetValue(Key, out var value))
				{
					return Default;
				}
				return value;
			}
		}

		public bool Changed => Path != Default;
	}
	internal sealed class GameRow
	{
		public string Map;

		public string Label;

		public readonly List<GameSlot> Keys = new List<GameSlot>();

		public readonly List<GameSlot> Buttons = new List<GameSlot>();

		public readonly List<string> FixedKeys = new List<string>();

		public readonly List<string> FixedButtons = new List<string>();
	}
	internal static class GameControls
	{
		private sealed class Def
		{
			public readonly string Map;

			public readonly string Label;

			public readonly string Keys;

			public readonly string Buttons;

			public readonly string Order;

			public readonly string FixedKeys;

			public readonly string FixedButtons;

			public Def(string map, string label, string keys, string buttons = null, string order = null, string fixedKeys = null, string fixedButtons = null)
			{
				Map = map;
				Label = label;
				Keys = keys;
				Buttons = buttons;
				Order = order;
				FixedKeys = fixedKeys;
				FixedButtons = fixedButtons;
			}
		}

		internal static readonly Dictionary<string, string> Overrides = new Dictionary<string, string>();

		internal static readonly List<GameRow> Rows = new List<GameRow>();

		private static readonly Dictionary<string, string> Defaults = new Dictionary<string, string>();

		private static readonly Dictionary<IntPtr, int> Applied = new Dictionary<IntPtr, int>();

		private static float _nextScan;

		internal static readonly string[] Maps = new string[2] { "Gameplay", "UI" };

		private static readonly Def[] Defs = new Def[24]
		{
			new Def("Gameplay", "Move", "Move#0", "Move", "up,left,down,right"),
			new Def("Gameplay", "Move", "Move#1", "AlternateMove", "up,left,down,right"),
			new Def("Gameplay", "Pause", "OpenPauseMenu"),
			new Def("Gameplay", "Quick Stats", "ShowStats"),
			new Def("Gameplay", "Show Tooltips", "ShowTooltips"),
			new Def("Gameplay", "Emote", "ShowRadialMenu"),
			new Def("Gameplay", "Ping", "SmartPing"),
			new Def("Gameplay", "Quick Chat", "QuickChat", null, "up,left,right,down"),
			new Def("Gameplay", "Close Quick Chat", "QuickChatCancel"),
			new Def("Gameplay", "Fast Forward", "FastForward", null, "modifier,binding"),
			new Def("UI", "Select", "", "", null, "<Keyboard>/enter,<Keyboard>/space", "<Gamepad>/buttonSouth"),
			new Def("UI", "Back", "", "", null, "<Keyboard>/escape,<Mouse>/rightButton", "<Gamepad>/buttonEast"),
			new Def("UI", "Previous / Next Tab", "PreviousCategory,NextCategory"),
			new Def("UI", "Previous / Next Sub-Tab", "PreviousSubCategory,NextSubCategory"),
			new Def("UI", "Previous / Next Stats Page", "PreviousStatCategory,NextStatCategory"),
			new Def("UI", "Ready", "Ready"),
			new Def("UI", "Invite", "Invite"),
			new Def("UI", "Matchmaking", "MatchmakingPreferences"),
			new Def("UI", "Lobby Code", "LobbyCode"),
			new Def("UI", "Refund Upgrade", "SingleUpgradeRefund"),
			new Def("UI", "Prestige", "Prestige"),
			new Def("UI", "Show Lore", "ToggleLoreDisplay"),
			new Def("UI", "Report Player", "Report"),
			new Def("UI", "Patch Notes", "OpenPatchNotes")
		};

		internal static int Version { get; private set; }

		internal static InputActionAsset Asset { get; private set; }

		private static string FilePath => Path.Combine(Paths.ConfigPath, "RebindControls.txt");

		internal static string MapTitle(string map)
		{
			if (!(map == "Gameplay"))
			{
				return "Menus";
			}
			return "In Missions";
		}

		internal static void Tick()
		{
			if (Time.unscaledTime < _nextScan)
			{
				return;
			}
			_nextScan = Time.unscaledTime + 2f;
			foreach (InputActionAsset item in Resources.FindObjectsOfTypeAll<InputActionAsset>())
			{
				if (!((Object)(object)item == (Object)null) && item.FindActionMap("Gameplay", false) != null)
				{
					Asset = item;
					if (Rows.Count == 0)
					{
						Build(item);
					}
					if (!Applied.TryGetValue(((Il2CppObjectBase)item).Pointer, out var value) || value != Version)
					{
						Apply(item);
						Applied[((Il2CppObjectBase)item).Pointer] = Version;
					}
				}
			}
		}

		private static void Build(InputActionAsset asset)
		{
			Def[] defs = Defs;
			foreach (Def def in defs)
			{
				GameRow gameRow = new GameRow
				{
					Map = def.Map,
					Label = def.Label
				};
				Fill(asset, def, def.Keys, pad: false, gameRow);
				Fill(asset, def, def.Buttons ?? def.Keys, pad: true, gameRow);
				if (def.FixedKeys != null)
				{
					gameRow.FixedKeys.AddRange(def.FixedKeys.Split(','));
				}
				if (def.FixedButtons != null)
				{
					gameRow.FixedButtons.AddRange(def.FixedButtons.Split(','));
				}
				if (gameRow.Keys.Count + gameRow.Buttons.Count + gameRow.FixedKeys.Count + gameRow.FixedButtons.Count > 0)
				{
					Rows.Add(gameRow);
				}
			}
			foreach (string item in new List<string>(Overrides.Keys))
			{
				GameSlot gameSlot = Find(item);
				if (gameSlot == null || (Defaults.TryGetValue(item, out var value) && value != gameSlot.Default))
				{
					Overrides.Remove(item);
				}
			}
			Version++;
			RebindControlsMod.Log.Msg($"{Rows.Count} game controls, {Overrides.Count} changed");
		}

		private static void Fill(InputActionAsset asset, Def def, string sources, bool pad, GameRow row)
		{
			if (string.IsNullOrEmpty(sources))
			{
				return;
			}
			string[] array = sources.Split(',');
			foreach (string text in array)
			{
				string text2 = text;
				int num = -1;
				int num2 = text.IndexOf('#');
				if (num2 >= 0)
				{
					text2 = text.Substring(0, num2);
					num = int.Parse(text.Substring(num2 + 1));
				}
				InputAction val = asset.FindAction(def.Map + "/" + text2, false);
				if (val == null)
				{
					continue;
				}
				List<(GameSlot, string)> list = new List<(GameSlot, string)>();
				ReadOnlyArray<InputBinding> bindings = val.bindings;
				int num3 = -1;
				for (int j = 0; j < bindings.Count; j++)
				{
					InputBinding val2 = bindings[j];
					if (val2.isComposite)
					{
						num3++;
						continue;
					}
					bool isPartOfComposite = val2.isPartOfComposite;
					string text3 = val2.path ?? "";
					bool flag = text3.StartsWith("<Gamepad>/");
					bool flag2 = text3.StartsWith("<Keyboard>/") || text3.StartsWith("<Mouse>/");
					if ((pad ? (!flag) : (!flag2)) || (num >= 0 && (!isPartOfComposite || num3 != num)))
					{
						continue;
					}
					if (IsButton(text3))
					{
						list.Add((new GameSlot
						{
							Map = def.Map,
							Action = text2,
							Index = j,
							Default = text3,
							Pad = pad
						}, isPartOfComposite ? (val2.name ?? "").ToLowerInvariant() : ""));
					}
					else
					{
						List<string> list2 = (pad ? row.FixedButtons : row.FixedKeys);
						if (!list2.Contains(text3))
						{
							list2.Add(text3);
						}
					}
				}
				if (def.Order != null)
				{
					List<string> order = new List<string>(def.Order.Split(','));
					list.Sort(((GameSlot slot, string part) a, (GameSlot slot, string part) b) => Rank(order, a.part).CompareTo(Rank(order, b.part)));
				}
				foreach (var item2 in list)
				{
					GameSlot item = item2.Item1;
					(pad ? row.Buttons : row.Keys).Add(item);
				}
			}
		}

		private static int Rank(List<string> order, string part)
		{
			int num = order.IndexOf(part);
			if (num >= 0)
			{
				return num;
			}
			return order.Count;
		}

		private static void Apply(InputActionAsset asset)
		{
			foreach (GameSlot item in AllSlots())
			{
				InputAction val = asset.FindAction(item.Map + "/" + item.Action, false);
				if (val == null)
				{
					continue;
				}
				ReadOnlyArray<InputBinding> bindings = val.bindings;
				if (item.Index < bindings.Count && !(bindings[item.Index].path != item.Default))
				{
					if (item.Changed)
					{
						InputActionRebindingExtensions.ApplyBindingOverride(val, item.Index, item.Path);
					}
					else if (!string.IsNullOrEmpty(bindings[item.Index].overridePath))
					{
						InputActionRebindingExtensions.RemoveBindingOverride(val, item.Index);
					}
				}
			}
		}

		internal static IEnumerable<GameSlot> AllSlots()
		{
			foreach (GameRow row in Rows)
			{
				foreach (GameSlot key in row.Keys)
				{
					yield return key;
				}
				foreach (GameSlot button in row.Buttons)
				{
					yield return button;
				}
			}
		}

		private static GameSlot Find(string key)
		{
			foreach (GameSlot item in AllSlots())
			{
				if (item.Key == key)
				{
					return item;
				}
			}
			return null;
		}

		private static bool IsButton(string path)
		{
			string text = path.Substring(path.IndexOf('/') + 1);
			if (text.Length > 0 && text != "leftStick" && text != "rightStick" && text != "dpad" && text != "position" && text != "scroll" && text != "delta")
			{
				return !text.StartsWith("{");
			}
			return false;
		}

		internal static void Set(GameSlot slot, string path)
		{
			if (!(path == slot.Path))
			{
				SetRaw(slot, path);
				Changed();
			}
		}

		internal static void Reset(GameSlot slot)
		{
			if (slot.Changed)
			{
				Set(slot, slot.Default);
			}
		}

		internal static void ResetAll(bool pad)
		{
			foreach (GameSlot item in AllSlots())
			{
				if (item.Pad == pad)
				{
					Overrides.Remove(item.Key);
				}
			}
			Changed();
		}

		private static void SetRaw(GameSlot slot, string path)
		{
			if (path == slot.Default)
			{
				Overrides.Remove(slot.Key);
				return;
			}
			Overrides[slot.Key] = path;
			Defaults[slot.Key] = slot.Default;
		}

		private static void Changed()
		{
			Version++;
			_nextScan = 0f;
			Save();
		}

		internal static void Load()
		{
			try
			{
				if (!File.Exists(FilePath))
				{
					return;
				}
				string[] array = File.ReadAllLines(FilePath);
				foreach (string text in array)
				{
					int num = text.IndexOf('=');
					if (num > 0 && !text.StartsWith("#"))
					{
						string[] array2 = text.Substring(num + 1).Split('|');
						string key = text.Substring(0, num).Trim();
						Overrides[key] = array2[0].Trim();
						if (array2.Length > 1)
						{
							Defaults[key] = array2[1].Trim();
						}
					}
				}
			}
			catch (Exception ex)
			{
				RebindControlsMod.Log.Warning("reading " + FilePath + ": " + ex.Message);
			}
		}

		private static void Save()
		{
			try
			{
				List<string> list = new List<string> { "# The game's controls changed in Options → Controls: Map/Action/binding=new input|the game's input" };
				foreach (var (text3, value) in Overrides)
				{
					list.Add($"{text3}={value}|{(Defaults.TryGetValue(text3, out var value2) ? value2 : "")}");
				}
				File.WriteAllLines(FilePath, list);
			}
			catch (Exception ex)
			{
				RebindControlsMod.Log.Warning("saving " + FilePath + ": " + ex.Message);
			}
		}
	}
	internal static class Icons
	{
		private static readonly Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>();

		private static float _scannedAt = -100f;

		private static Sprite _keycap;

		private static readonly Dictionary<string, string> KeyNames = new Dictionary<string, string>
		{
			["leftCtrl"] = "ctrl",
			["rightCtrl"] = "ctrl",
			["leftShift"] = "shift",
			["rightShift"] = "shift",
			["enter"] = "enter",
			["numpadEnter"] = "enter",
			["escape"] = "esc",
			["space"] = "space",
			["upArrow"] = "arrow_up",
			["downArrow"] = "arrow_down",
			["leftArrow"] = "arrow_left",
			["rightArrow"] = "arrow_right"
		};

		private static readonly Dictionary<string, string> MouseNames = new Dictionary<string, string>
		{
			["leftButton"] = "mouse1",
			["rightButton"] = "mouse2",
			["middleButton"] = "scroll"
		};

		private static readonly Dictionary<string, (string xbox, string ps, string deck)> PadNames = new Dictionary<string, (string, string, string)>
		{
			["buttonSouth"] = ("xbox_a", "playstation_cross", "steamdeck_a"),
			["buttonEast"] = ("xbox_b", "playstation_circle", "steamdeck_b"),
			["buttonWest"] = ("xbox_x", "playstation_square", "steamdeck_x"),
			["buttonNorth"] = ("xbox_y", "playstation_triangle", "steamdeck_y"),
			["leftShoulder"] = ("xbox_lb", "playstation_l1", "steamdeck_l1"),
			["rightShoulder"] = ("xbox_rb", "playstation_r1", "steamdeck_r1"),
			["leftTrigger"] = ("xbox_lt", "playstation_l2", null),
			["rightTrigger"] = ("xbox_rt", "playstation_r2", null),
			["start"] = ("xbox_start", "playstation_options", "steamdeck_start"),
			["select"] = ("xbox_options", null, null),
			["rightStickPress"] = ("xbox_R", "ps_R3", null),
			["dpad/up"] = ("xbox_up", "playstation_up", "steamdeck_up"),
			["dpad/down"] = ("xbox_down", "playstation_down", "steamdeck_down"),
			["dpad/left"] = ("xbox_left", "playstation_left", "steamdeck_left"),
			["dpad/right"] = ("xbox_right", "playstation_right", "steamdeck_right"),
			["dpad"] = ("xbox_up", "playstation_dpad", "steamdeck_dpad"),
			["leftStick"] = ("stick_l", "stick_l", "stick_l"),
			["rightStick"] = ("stick_r", "stick_r", "stick_r")
		};

		private static readonly Dictionary<string, string> PadWords = new Dictionary<string, string>
		{
			["leftTrigger"] = "L2",
			["rightTrigger"] = "R2",
			["leftStickPress"] = "L3",
			["rightStickPress"] = "R3",
			["select"] = "Select",
			["start"] = "Start",
			["leftShoulder"] = "L1",
			["rightShoulder"] = "R1"
		};

		private static readonly Dictionary<string, string> KeyWords = new Dictionary<string, string>
		{
			["leftCtrl"] = "Ctrl",
			["rightCtrl"] = "Ctrl",
			["leftAlt"] = "Alt",
			["rightAlt"] = "Alt",
			["leftShift"] = "Shift",
			["rightShift"] = "Shift",
			["backspace"] = "Bksp",
			["capsLock"] = "Caps",
			["pageUp"] = "PgUp",
			["pageDown"] = "PgDn",
			["insert"] = "Ins",
			["delete"] = "Del",
			["escape"] = "Esc",
			["printScreen"] = "PrtSc",
			["scrollLock"] = "ScrLk",
			["numLock"] = "NumLk",
			["leftMeta"] = "Win",
			["rightMeta"] = "Win",
			["contextMenu"] = "Menu",
			["backquote"] = "`",
			["upArrow"] = "Up",
			["downArrow"] = "Down",
			["leftArrow"] = "Left",
			["rightArrow"] = "Right",
			["backButton"] = "M4",
			["forwardButton"] = "M5",
			["middleButton"] = "M3",
			["leftButton"] = "M1",
			["rightButton"] = "M2"
		};

		private static Sprite _round;

		internal static InputDeviceType PadType()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				InputDeviceType val = (InputDeviceType)((!((Object)(object)SingletonPersistent<UINavigator>.Instance != (Object)null)) ? 2 : ((int)SingletonPersistent<UINavigator>.Instance.CurrentInputDeviceType));
				return (InputDeviceType)(((int)val == 0) ? 2 : ((int)val));
			}
			catch
			{
				return (InputDeviceType)2;
			}
		}

		internal static Sprite For(string path, InputDeviceType pad)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Invalid comparison between Unknown and I4
			if (string.IsNullOrEmpty(path))
			{
				return null;
			}
			int num = path.IndexOf('/');
			if (num < 0)
			{
				return null;
			}
			string text = path.Substring(0, num);
			string text2 = path.Substring(num + 1);
			string text3 = null;
			switch (text)
			{
			case "<Keyboard>":
			{
				if (KeyNames.TryGetValue(text2, out var value2))
				{
					text3 = "key_pc_" + value2;
				}
				else if (text2.Length == 1)
				{
					text3 = "key_pc_" + text2.ToLowerInvariant();
				}
				break;
			}
			case "<Mouse>":
			{
				if (MouseNames.TryGetValue(text2, out var value3))
				{
					text3 = "key_pc_" + value3;
				}
				break;
			}
			case "<Gamepad>":
			{
				if (!PadNames.TryGetValue(text2, out (string, string, string) value))
				{
					break;
				}
				string text4;
				if ((int)pad != 1)
				{
					if ((int)pad != 3)
					{
						(text4, _, _) = value;
					}
					else
					{
						text4 = value.Item3;
						if (text4 == null)
						{
							(text4, _, _) = value;
						}
					}
				}
				else
				{
					text4 = value.Item2;
				}
				string text5 = text4;
				if (text5 != null)
				{
					text3 = "key_" + text5;
				}
				break;
			}
			}
			if (text3 == null)
			{
				return null;
			}
			return Find(text3);
		}

		internal static string Word(string path, InputDeviceType pad)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Invalid comparison between Unknown and I4
			if (string.IsNullOrEmpty(path))
			{
				return "—";
			}
			int num = path.IndexOf('/');
			string obj = ((num < 0) ? "" : path.Substring(0, num));
			string text = ((num < 0) ? path : path.Substring(num + 1));
			if (obj == "<Gamepad>")
			{
				if ((int)pad == 2 && text == "leftTrigger")
				{
					return "LT";
				}
				if ((int)pad == 2 && text == "rightTrigger")
				{
					return "RT";
				}
				if ((int)pad == 2 && text == "leftStickPress")
				{
					return "LS";
				}
				if ((int)pad == 2 && text == "rightStickPress")
				{
					return "RS";
				}
				if ((int)pad == 1 && text == "select")
				{
					return "Share";
				}
				if (PadWords.TryGetValue(text, out var value))
				{
					return value;
				}
			}
			if (KeyWords.TryGetValue(text, out var value2))
			{
				return value2;
			}
			string text2 = Keybinds.DisplayName(path);
			if (text2.Length <= 0)
			{
				return text;
			}
			return text2;
		}

		internal static Sprite Find(string name)
		{
			if (Sprites.TryGetValue(name, out var value) && (Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
			{
				return value;
			}
			if (Time.unscaledTime - _scannedAt < 3f && Sprites.Count > 0)
			{
				return null;
			}
			_scannedAt = Time.unscaledTime;
			Sprites.Clear();
			foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
			{
				if ((Object)(object)item != (Object)null && ((Object)item).name.StartsWith("key_"))
				{
					Sprites[((Object)item).name] = item;
				}
			}
			if (!Sprites.TryGetValue(name, out value))
			{
				return null;
			}
			return value;
		}

		internal static Sprite Round()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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_0170: Expected O, but got Unknown
			//IL_0084: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_round != (Object)null && !((Il2CppObjectBase)_round).WasCollected)
			{
				return _round;
			}
			Color32[] array = (Color32[])(object)new Color32[4096];
			float num = 31.5f;
			float num2 = 31f;
			float num3 = 16f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num4 = Mathf.Abs((float)j - num) - (num2 - num3);
					float num5 = Mathf.Abs((float)i - num) - (num2 - num3);
					Vector2 val = new Vector2(Mathf.Max(num4, 0f), Mathf.Max(num5, 0f));
					float num6 = ((Vector2)(ref val)).magnitude + Mathf.Min(Mathf.Max(num4, num5), 0f) - num3;
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(0.5f - num6) * 255f));
				}
			}
			Texture2D val2 = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			val2.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val2.Apply();
			_round = Sprite.Create(val2, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(20f, 20f, 20f, 20f));
			((Object)_round).hideFlags = (HideFlags)61;
			return _round;
		}

		internal static Sprite Keycap()
		{
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_keycap != (Object)null && !((Il2CppObjectBase)_keycap).WasCollected)
			{
				return _keycap;
			}
			Color32[] array = (Color32[])(object)new Color32[9216];
			float num = 47.5f;
			float num2 = 45f;
			float num3 = 14f;
			Color val = default(Color);
			((Color)(ref val))..ctor(0.16f, 0.16f, 0.22f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.36f, 0.36f, 0.46f, 1f);
			for (int i = 0; i < 96; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num4 = Mathf.Abs((float)j - num) - (num2 - num3);
					float num5 = Mathf.Abs((float)i - num) - (num2 - num3);
					Vector2 val3 = new Vector2(Mathf.Max(num4, 0f), Mathf.Max(num5, 0f));
					float num6 = ((Vector2)(ref val3)).magnitude + Mathf.Min(Mathf.Max(num4, num5), 0f) - num3;
					float num7 = Mathf.Clamp01(0.5f - num6);
					Color val4 = Color.Lerp(val, val2, Mathf.Clamp01(num6 + 4.5f));
					array[i * 96 + j] = new Color32((byte)(val4.r * 255f), (byte)(val4.g * 255f), (byte)(val4.b * 255f), (byte)(num7 * 255f));
				}
			}
			Texture2D val5 = new Texture2D(96, 96, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			val5.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val5.Apply();
			_keycap = Sprite.Create(val5, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(28f, 28f, 28f, 28f));
			((Object)_keycap).hideFlags = (HideFlags)61;
			return _keycap;
		}
	}
	internal static class Prompts
	{
		private static readonly Dictionary<string, (string map, string action)> Actions = new Dictionary<string, (string, string)>
		{
			["ShowStats"] = ("Gameplay", "ShowStats"),
			["ShowInfo"] = ("Gameplay", "ShowTooltips"),
			["SingleRefund"] = ("UI", "SingleUpgradeRefund"),
			["Select"] = ("UI", "Submit"),
			["Back"] = ("UI", "Cancel")
		};

		private const string LabelName = "RebindControls_Word";

		private static int _refreshedVersion = -1;

		internal static void Install(Harmony harmony)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(ButtonPromptUpdater), "UpdateIcon", (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					RebindControlsMod.Log.Warning("ButtonPromptUpdater.UpdateIcon not found; the on-screen hints keep the game's keys");
				}
				else
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Prompts), "UpdateIconPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				RebindControlsMod.Log.Warning("on-screen hints: " + ex.Message);
			}
		}

		internal static void Tick()
		{
			//IL_002c: 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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (_refreshedVersion == GameControls.Version)
			{
				return;
			}
			_refreshedVersion = GameControls.Version;
			InputDeviceType val;
			try
			{
				val = (InputDeviceType)(((Object)(object)SingletonPersistent<UINavigator>.Instance != (Object)null) ? ((int)SingletonPersistent<UINavigator>.Instance.CurrentInputDeviceType) : 0);
			}
			catch
			{
				return;
			}
			foreach (ButtonPromptUpdater item in Object.FindObjectsOfType<ButtonPromptUpdater>())
			{
				try
				{
					item.UpdateIcon(val);
				}
				catch
				{
				}
			}
		}

		private static void UpdateIconPostfix(ButtonPromptUpdater __instance, InputDeviceType inputDeviceType)
		{
			//IL_0016: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Image image = __instance.image;
				if ((Object)(object)image == (Object)null)
				{
					return;
				}
				string text = NewPath(((object)__instance.actionType/*cast due to .constrained prefix*/).ToString(), (int)inputDeviceType > 0);
				Transform val = ((Component)image).transform.Find("RebindControls_Word");
				if (text == null)
				{
					if ((Object)(object)val != (Object)null)
					{
						((Component)val).gameObject.SetActive(false);
					}
					return;
				}
				Sprite val2 = Icons.For(text, inputDeviceType);
				if ((Object)(object)val2 != (Object)null)
				{
					image.sprite = val2;
					if ((Object)(object)val != (Object)null)
					{
						((Component)val).gameObject.SetActive(false);
					}
					return;
				}
				image.sprite = Icons.Keycap();
				image.type = (Type)1;
				TMP_Text val3;
				if ((Object)(object)val == (Object)null)
				{
					val3 = (TMP_Text)(object)new GameObject("RebindControls_Word").AddComponent<TextMeshProUGUI>();
					((Transform)val3.rectTransform).SetParent(((Component)image).transform, false);
					val3.rectTransform.anchorMin = Vector2.zero;
					val3.rectTransform.anchorMax = Vector2.one;
					val3.rectTransform.offsetMin = new Vector2(4f, 2f);
					val3.rectTransform.offsetMax = new Vector2(-4f, -2f);
					TextMeshProUGUI obj = Object.FindObjectOfType<TextMeshProUGUI>();
					TMP_FontAsset val4 = ((obj != null) ? ((TMP_Text)obj).font : null);
					if ((Object)(object)val4 != (Object)null)
					{
						val3.font = val4;
					}
					val3.alignment = (TextAlignmentOptions)514;
					val3.enableAutoSizing = true;
					val3.fontSizeMin = 6f;
					val3.fontSizeMax = 200f;
					val3.textWrappingMode = (TextWrappingModes)0;
					((Graphic)val3).color = Color.white;
					((Graphic)val3).raycastTarget = false;
				}
				else
				{
					val3 = ((Component)val).GetComponent<TMP_Text>();
				}
				((Component)val3).gameObject.SetActive(true);
				val3.text = Icons.Word(text, inputDeviceType);
			}
			catch (Exception ex)
			{
				RebindControlsMod.Log.Warning("on-screen hint: " + ex.Message);
			}
		}

		private static string NewPath(string hint, bool pad)
		{
			string text;
			string text2;
			if (Actions.TryGetValue(hint, out (string, string) value))
			{
				(text, text2) = value;
			}
			else
			{
				text2 = hint;
				text = "UI";
			}
			GameSlot gameSlot = null;
			foreach (GameSlot item in GameControls.AllSlots())
			{
				if (!(item.Map != text) && !(item.Action != text2) && item.Pad == pad && (gameSlot == null || item.Index < gameSlot.Index))
				{
					gameSlot = item;
				}
			}
			if (gameSlot == null || !gameSlot.Changed)
			{
				return null;
			}
			return gameSlot.Path;
		}
	}
	public class RebindControlsMod : MelonMod
	{
		internal static MelonLogger.Instance Log;

		private string _lastError;

		private float _retryAt;

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			GameControls.Load();
			ControlsUi.Init();
			Prompts.Install(base.HarmonyInstance);
			Log.Msg("ready");
		}

		public override void OnUpdate()
		{
			float unscaledTime = Time.unscaledTime;
			try
			{
				Capture.Tick();
			}
			catch (Exception e)
			{
				Report(e);
				Capture.Abort();
			}
			if (unscaledTime < _retryAt)
			{
				return;
			}
			try
			{
				GameControls.Tick();
				ControlsUi.Tick();
				Prompts.Tick();
			}
			catch (Exception e2)
			{
				Report(e2);
				_retryAt = unscaledTime + 2f;
			}
		}

		private void Report(Exception e)
		{
			string name = e.GetType().Name;
			string? stackTrace = e.StackTrace;
			string text = name + ((stackTrace != null) ? stackTrace.Split('\n')[0] : null);
			if (!(_lastError == text))
			{
				_lastError = text;
				Log.Error(e.ToString());
			}
		}
	}
}
namespace RebindControls.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.RebindControls", "Rebind Controls", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.RebindControls";

		public override void Load()
		{
			MelonCompat.Start<RebindControlsMod, Runner>((BasePlugin)(object)this, "SpellBrigade.RebindControls");
		}
	}
	public class Runner : MonoBehaviour
	{
		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			MelonCompat.Update();
		}
	}
}
namespace MelonLoader
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonInfoAttribute : Attribute
	{
		public MelonInfoAttribute(Type type, string name, string version, string author, string downloadLink = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public sealed class MelonGameAttribute : Attribute
	{
		public MelonGameAttribute(string developer = null, string name = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonOptionalDependenciesAttribute : Attribute
	{
		public MelonOptionalDependenciesAttribute(params string[] names)
		{
		}
	}
	public abstract class MelonBase
	{
		public MelonLogger.Instance LoggerInstance { get; internal set; }

		public Harmony HarmonyInstance { get; internal set; }

		public static object FindMelon(string name, string author)
		{
			try
			{
				foreach (PluginInfo value in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Values)
				{
					if (((value != null) ? value.Metadata : null) != null && string.Equals(value.Metadata.Name, name, StringComparison.OrdinalIgnoreCase) && value.Instance != null)
					{
						return value;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	public abstract class MelonMod : MelonBase
	{
		public virtual void OnInitializeMelon()
		{
		}

		public virtual void OnLateInitializeMelon()
		{
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnLateUpdate()
		{
		}

		public virtual void OnFixedUpdate()
		{
		}

		public virtual void OnGUI()
		{
		}

		public virtual void OnApplicationQuit()
		{
		}

		public virtual void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
		}
	}
	public static class MelonLogger
	{
		public sealed class Instance
		{
			private readonly ManualLogSource _log;

			public Instance(ManualLogSource log)
			{
				_log = log;
			}

			public void Msg(string text)
			{
				_log.LogInfo((object)text);
			}

			public void Msg(object value)
			{
				_log.LogInfo(value);
			}

			public void Msg(string format, params object[] args)
			{
				_log.LogInfo((object)string.Format(format, args));
			}

			public void Warning(string text)
			{
				_log.LogWarning((object)text);
			}

			public void Warning(object value)
			{
				_log.LogWarning(value);
			}

			public void Error(string text)
			{
				_log.LogError((object)text);
			}

			public void Error(object value)
			{
				_log.LogError(value);
			}

			public void Error(string text, Exception e)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e);
				}
				log.LogError(val);
			}
		}
	}
	public static class MelonCompat
	{
		internal static ConfigFile Config;

		private static MelonMod _mod;

		private static bool _lateInit;

		public static void Start<TMod, TRunner>(BasePlugin plugin, string harmonyId) where TMod : MelonMod, new() where TRunner : MonoBehaviour
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Config = plugin.Config;
			_mod = new TMod
			{
				LoggerInstance = new MelonLogger.Instance(plugin.Log),
				HarmonyInstance = new Harmony(harmonyId)
			};
			try
			{
				_mod.HarmonyInstance.PatchAll(typeof(TMod).Assembly);
			}
			catch (Exception ex)
			{
				ManualLogSource log = plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patches: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_mod.OnInitializeMelon();
			HookScenes();
			ClassInjector.RegisterTypeInIl2Cpp<TRunner>();
			plugin.AddComponent<TRunner>();
		}

		private static void HookScenes()
		{
			SceneManager.sceneLoaded += DelegateSupport.ConvertDelegate<UnityAction<Scene, LoadSceneMode>>((Delegate)new Action<Scene, LoadSceneMode>(OnSceneLoaded));
			SceneManager.sceneUnloaded += DelegateSupport.ConvertDelegate<UnityAction<Scene>>((Delegate)new Action<Scene>(OnSceneUnloaded));
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0006: 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)
			Guard(delegate
			{
				_mod.OnSceneWasLoaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
			Guard(delegate
			{
				_mod.OnSceneWasInitialized(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		private static void OnSceneUnloaded(Scene scene)
		{
			//IL_0006: 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)
			Guard(delegate
			{
				_mod.OnSceneWasUnloaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		public static void Update()
		{
			if (_mod != null)
			{
				if (!_lateInit)
				{
					_lateInit = true;
					Guard(_mod.OnLateInitializeMelon);
				}
				_mod.OnUpdate();
			}
		}

		public static void LateUpdate()
		{
			_mod?.OnLateUpdate();
		}

		public static void FixedUpdate()
		{
			_mod?.OnFixedUpdate();
		}

		public static void OnGUI()
		{
			_mod?.OnGUI();
		}

		public static void Quit()
		{
			_mod?.OnApplicationQuit();
		}

		private static void Guard(Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				_mod.LoggerInstance.Error(ex.ToString());
			}
		}
	}
	public static class MelonPreferences
	{
		private static readonly Dictionary<string, MelonPreferences_Category> Categories = new Dictionary<string, MelonPreferences_Category>();

		public static MelonPreferences_Category CreateCategory(string identifier, string displayName = null, bool is_hidden = false, bool is_inlined = false)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				value = (Categories[identifier] = new MelonPreferences_Category(identifier, displayName ?? identifier)
				{
					IsHidden = is_hidden
				});
			}
			return value;
		}

		public static MelonPreferences_Category GetCategory(string identifier)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Save()
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}
	}
	public sealed class MelonPreferences_Category
	{
		public readonly List<MelonPreferences_Entry> Entries = new List<MelonPreferences_Entry>();

		public string Identifier { get; }

		public string DisplayName { get; }

		public bool IsHidden { get; internal set; }

		internal MelonPreferences_Category(string identifier, string displayName)
		{
			Identifier = identifier;
			DisplayName = displayName;
		}

		public MelonPreferences_Entry<T> CreateEntry<T>(string identifier, T default_value, string display_name = null, string description = null, bool is_hidden = false, bool dont_save_default = false, ValueValidator validator = null, string oldIdentifier = null)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				DispName = (display_name ?? identifier),
				Browsable = (!is_hidden && !IsHidden),
				Order = -Entries.Count,
				Category = DisplayName
			};
			AcceptableValueBase val = validator?.ToAcceptable(typeof(T));
			ConfigEntry<T> cfg = MelonCompat.Config.Bind<T>(Identifier, identifier, default_value, new ConfigDescription(description ?? "", val, new object[1] { configurationManagerAttributes }));
			MelonPreferences_Entry<T> melonPreferences_Entry = new MelonPreferences_Entry<T>(this, cfg, identifier, display_name ?? identifier, description, is_hidden);
			Entries.Add(melonPreferences_Entry);
			return melonPreferences_Entry;
		}

		public MelonPreferences_Entry GetEntry(string identifier)
		{
			return Entries.Find((MelonPreferences_Entry e) => e.Identifier == identifier);
		}

		public MelonPreferences_Entry<T> GetEntry<T>(string identifier)
		{
			return GetEntry(identifier) as MelonPreferences_Entry<T>;
		}

		public bool HasEntry(string identifier)
		{
			return GetEntry(identifier) != null;
		}

		public void SaveToFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}

		public void LoadFromFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Reload();
			}
		}
	}
	public abstract class MelonPreferences_Entry
	{
		public readonly MelonEvent<object, object> OnEntryValueChangedUntyped = new MelonEvent<object, object>();

		public MelonPreferences_Category Category { get; protected set; }

		public string Identifier { get; protected set; }

		public string DisplayName { get; pr