Decompiled source of RebindControls v1.1.1

RebindControls.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using InControl;
using Jotunn.Utils;
using TMPro;
using UnboundLib;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RebindControls")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RebindControls")]
[assembly: AssemblyTitle("RebindControls")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RebindControls
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.willuwontu.rounds.rebindcontrols", "Rebind Controls", "1.1.1")]
	[BepInProcess("Rounds.exe")]
	public class RebindControls : BaseUnityPlugin
	{
		private class BindingInfo : MonoBehaviour
		{
			public PlayerAction action;
		}

		private class ButtonInteraction : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler
		{
			public UnityEvent mouseClick = new UnityEvent();

			public UnityEvent mouseEnter = new UnityEvent();

			public UnityEvent mouseExit = new UnityEvent();

			public Button button;

			public AudioSource source;

			public static ButtonInteraction instance;

			private Random random = new Random();

			private void Start()
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Expected O, but got Unknown
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Expected O, but got Unknown
				instance = this;
				button = ((Component)this).gameObject.GetComponent<Button>();
				source = ExtensionMethods.GetOrAddComponent<AudioSource>(((Component)this).gameObject, false);
				mouseEnter.AddListener(new UnityAction(OnEnter));
				mouseExit.AddListener(new UnityAction(OnExit));
				mouseClick.AddListener(new UnityAction(OnClick));
				mouseClick.AddListener(new UnityAction(RebindControls.instance.UpdateDisplayedBindings));
			}

			public void OnEnter()
			{
				source.PlayOneShot(RebindControls.instance.hover[random.Next(RebindControls.instance.hover.Count)]);
			}

			public void OnExit()
			{
				source.PlayOneShot(RebindControls.instance.hover[random.Next(RebindControls.instance.hover.Count)]);
			}

			public void OnClick()
			{
				source.PlayOneShot(RebindControls.instance.click[random.Next(RebindControls.instance.click.Count)]);
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}

			public void OnPointerEnter(PointerEventData eventData)
			{
				UnityEvent obj = mouseEnter;
				if (obj != null)
				{
					obj.Invoke();
				}
			}

			public void OnPointerExit(PointerEventData eventData)
			{
				UnityEvent obj = mouseExit;
				if (obj != null)
				{
					obj.Invoke();
				}
			}

			public void OnPointerClick(PointerEventData eventData)
			{
				UnityEvent obj = mouseClick;
				if (obj != null)
				{
					obj.Invoke();
				}
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__18_0;

			public static Func<AudioClip, bool> <>9__22_0;

			public static Func<AudioClip, bool> <>9__22_1;

			internal void <Start>b__18_0()
			{
			}

			internal bool <LoadAssets>b__22_0(AudioClip clip)
			{
				return ((Object)clip).name.Contains("UI_Button_Click");
			}

			internal bool <LoadAssets>b__22_1(AudioClip clip)
			{
				return ((Object)clip).name.Contains("UI_Button_Hover");
			}
		}

		private const string ModId = "com.willuwontu.rounds.rebindcontrols";

		private const string ModName = "Rebind Controls";

		public const string Version = "1.1.1";

		public PlayerActions keyboardPlayer;

		public PlayerActions controllerPlayer;

		public bool setupDefault;

		internal AssetBundle UIAssets;

		private GameObject containerFrameAsset;

		private GameObject keyGroupAsset;

		private GameObject bindingButtonAsset;

		public List<AudioClip> click;

		public List<AudioClip> hover;

		private Dictionary<GameObject, Dictionary<BindingInfo, List<TextMeshProUGUI>>> layouts = new Dictionary<GameObject, Dictionary<BindingInfo, List<TextMeshProUGUI>>>();

		public static RebindControls instance { get; private set; }

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.willuwontu.rounds.rebindcontrols").PatchAll();
		}

		private void Start()
		{
			//IL_011c: 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_0127: Expected O, but got Unknown
			instance = this;
			Debug.Log((object)"[RebindControls] Registering Credits");
			Unbound.RegisterCredits("Rebind Controls", new string[1] { "willuwontu" }, new string[2] { "github", "Ko-Fi" }, new string[2] { "https://github.com/willuwontu/RebindControls", "https://ko-fi.com/willuwontu" });
			Debug.Log((object)"[RebindControls] Initializing Default Controls");
			keyboardPlayer = DefaultKeyboardLayout();
			controllerPlayer = DefaultControllersLayout();
			LoadAssets();
			Debug.Log((object)"[RebindControls] Setting up config binds.");
			if (!PlayerPrefs.HasKey("com.willuwontu.rounds.rebindcontrolsKeyboard"))
			{
				PlayerPrefs.SetString("com.willuwontu.rounds.rebindcontrolsKeyboard", ((PlayerActionSet)keyboardPlayer).Save());
			}
			if (!PlayerPrefs.HasKey("com.willuwontu.rounds.rebindcontrolsController"))
			{
				PlayerPrefs.SetString("com.willuwontu.rounds.rebindcontrolsController", ((PlayerActionSet)controllerPlayer).Save());
			}
			((PlayerActionSet)keyboardPlayer).Load(PlayerPrefs.GetString("com.willuwontu.rounds.rebindcontrolsKeyboard"));
			((PlayerActionSet)controllerPlayer).Load(PlayerPrefs.GetString("com.willuwontu.rounds.rebindcontrolsController"));
			setupDefault = true;
			Debug.Log((object)"[RebindControls] Registering Menu");
			object obj = <>c.<>9__18_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
				};
				<>c.<>9__18_0 = val;
				obj = (object)val;
			}
			Unbound.RegisterMenu("Rebind Controls", (UnityAction)obj, (Action<GameObject>)MainGui, (GameObject)null, true);
			Unbound.RegisterClientSideMod("com.willuwontu.rounds.rebindcontrols");
		}

		private PlayerActions DefaultKeyboardLayout()
		{
			PlayerActions obj = PlayerActions.CreateWithKeyboardBindings();
			((PlayerActionSet)obj).ListenOptions.IncludeUnknownControllers = true;
			((PlayerActionSet)obj).ListenOptions.IncludeMouseButtons = true;
			((PlayerActionSet)obj).ListenOptions.MaxAllowedBindings = 3u;
			((PlayerActionSet)obj).ListenOptions.UnsetDuplicateBindingsOnSet = true;
			((PlayerActionSet)obj).ListenOptions.OnBindingFound = null;
			((PlayerActionSet)obj).ListenOptions.OnBindingRejected = null;
			((PlayerActionSet)obj).ListenOptions.OnBindingAdded = null;
			BindingListenOptions listenOptions = ((PlayerActionSet)obj).ListenOptions;
			listenOptions.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Combine(listenOptions.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundKeyboard));
			BindingListenOptions listenOptions2 = ((PlayerActionSet)obj).ListenOptions;
			listenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(listenOptions2.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions3 = ((PlayerActionSet)obj).ListenOptions;
			listenOptions3.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(listenOptions3.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			return obj;
		}

		private PlayerActions DefaultControllersLayout()
		{
			PlayerActions obj = PlayerActions.CreateWithControllerBindings();
			((PlayerActionSet)obj).ListenOptions.IncludeUnknownControllers = true;
			((PlayerActionSet)obj).ListenOptions.IncludeMouseButtons = true;
			((PlayerActionSet)obj).ListenOptions.MaxAllowedBindings = 3u;
			((PlayerActionSet)obj).ListenOptions.UnsetDuplicateBindingsOnSet = true;
			((PlayerActionSet)obj).ListenOptions.OnBindingFound = null;
			((PlayerActionSet)obj).ListenOptions.OnBindingRejected = null;
			((PlayerActionSet)obj).ListenOptions.OnBindingAdded = null;
			BindingListenOptions listenOptions = ((PlayerActionSet)obj).ListenOptions;
			listenOptions.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Combine(listenOptions.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundController));
			BindingListenOptions listenOptions2 = ((PlayerActionSet)obj).ListenOptions;
			listenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(listenOptions2.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions3 = ((PlayerActionSet)obj).ListenOptions;
			listenOptions3.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(listenOptions3.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			return obj;
		}

		private void SaveLayouts()
		{
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Expected O, but got Unknown
			BindingListenOptions listenOptions = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Remove(listenOptions.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundKeyboard));
			BindingListenOptions listenOptions2 = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions2.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Remove(listenOptions2.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions3 = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions3.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Remove(listenOptions3.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			BindingListenOptions listenOptions4 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions4.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Remove(listenOptions4.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundController));
			BindingListenOptions listenOptions5 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions5.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Remove(listenOptions5.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions6 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions6.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Remove(listenOptions6.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			PlayerPrefs.SetString("com.willuwontu.rounds.rebindcontrolsKeyboard", ((PlayerActionSet)keyboardPlayer).Save());
			PlayerPrefs.SetString("com.willuwontu.rounds.rebindcontrolsController", ((PlayerActionSet)controllerPlayer).Save());
			BindingListenOptions listenOptions7 = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions7.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Combine(listenOptions7.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundKeyboard));
			BindingListenOptions listenOptions8 = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions8.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(listenOptions8.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions9 = ((PlayerActionSet)keyboardPlayer).ListenOptions;
			listenOptions9.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(listenOptions9.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			BindingListenOptions listenOptions10 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions10.OnBindingFound = (Func<PlayerAction, BindingSource, bool>)Delegate.Combine(listenOptions10.OnBindingFound, new Func<PlayerAction, BindingSource, bool>(OnBindingFoundController));
			BindingListenOptions listenOptions11 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions11.OnBindingRejected = (Action<PlayerAction, BindingSource, BindingSourceRejectionType>)Delegate.Combine(listenOptions11.OnBindingRejected, new Action<PlayerAction, BindingSource, BindingSourceRejectionType>(OnBindingRejectedMenu));
			BindingListenOptions listenOptions12 = ((PlayerActionSet)controllerPlayer).ListenOptions;
			listenOptions12.OnBindingAdded = (Action<PlayerAction, BindingSource>)Delegate.Combine(listenOptions12.OnBindingAdded, new Action<PlayerAction, BindingSource>(OnBindingAdded));
			foreach (Player player in PlayerManager.instance.players)
			{
				PlayerActions val = new PlayerActions();
				if (((PlayerActionSet)player.data.playerActions).Device != null)
				{
					((PlayerActionSet)val).Load(((PlayerActionSet)controllerPlayer).Save());
					player.data.playerActions = val;
				}
				else
				{
					((PlayerActionSet)val).Load(((PlayerActionSet)keyboardPlayer).Save());
					player.data.playerActions = val;
				}
			}
		}

		private void LoadAssets()
		{
			Debug.Log((object)"[RebindControls] Attempting to load assetbundle.");
			UIAssets = AssetUtils.LoadAssetBundleFromResources("rebindcontrolsui", typeof(RebindControls).Assembly);
			Debug.Log((object)"[RebindControls] Attempting to load assets.");
			containerFrameAsset = UIAssets.LoadAsset<GameObject>("BindingGridFrame");
			keyGroupAsset = UIAssets.LoadAsset<GameObject>("KeyGroup");
			bindingButtonAsset = UIAssets.LoadAsset<GameObject>("KeyBindingGroup");
			click = (from clip in UIAssets.LoadAllAssets<AudioClip>().ToList()
				where ((Object)clip).name.Contains("UI_Button_Click")
				select clip).ToList();
			hover = (from clip in UIAssets.LoadAllAssets<AudioClip>().ToList()
				where ((Object)clip).name.Contains("UI_Button_Hover")
				select clip).ToList();
		}

		private void OnBindingAdded(PlayerAction action, BindingSource binding)
		{
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			Debug.Log("[RebindControls] Binding added... " + binding.DeviceName + ": " + binding.Name);
			Debug.Log((object)("[RebindControls] Binding added for " + binding.DeviceName + ": " + binding.Name));
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)SaveLayouts);
		}

		private bool OnBindingFoundKeyboard(PlayerAction action, BindingSource binding)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Invalid comparison between Unknown and I4
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			if (binding == (BindingSource)new KeyBindingSource((Key[])(object)new Key[1] { (Key)13 }))
			{
				action.StopListeningForBinding();
				return false;
			}
			if ((int)binding.BindingSourceType != 2 && (int)binding.BindingSourceType != 3)
			{
				return false;
			}
			return true;
		}

		private bool OnBindingFoundController(PlayerAction action, BindingSource binding)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			if (binding == (BindingSource)new KeyBindingSource((Key[])(object)new Key[1] { (Key)13 }))
			{
				action.StopListeningForBinding();
				return false;
			}
			if (binding == (BindingSource)new DeviceBindingSource((InputControlType)100))
			{
				action.StopListeningForBinding();
				return false;
			}
			if ((int)binding.BindingSourceType != 1)
			{
				return false;
			}
			return true;
		}

		private void OnBindingRejectedMenu(PlayerAction action, BindingSource binding, BindingSourceRejectionType reason)
		{
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			Debug.Log("[RebindControls] Binding rejected... " + ((object)(BindingSourceRejectionType)(ref reason)).ToString());
			Debug.Log((object)("[RebindControls] Binding rejected... " + ((object)(BindingSourceRejectionType)(ref reason)).ToString()));
		}

		private void MainGui(GameObject menu)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			TextMeshProUGUI val = default(TextMeshProUGUI);
			MenuHandler.CreateText("Keyboard Layout", menu, ref val, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			CreateKeyBindingLayout(menu, keyboardPlayer);
			MenuHandler.CreateText(" ", menu, ref val, 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateButton("Reset keyboard layout to default".ToUpper(), menu, new UnityAction(OnResetKeyboardLayoutPressed), 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText(" ", menu, ref val, 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText("Controller Layout", menu, ref val, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			CreateKeyBindingLayout(menu, controllerPlayer);
			MenuHandler.CreateText(" ", menu, ref val, 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateButton("Reset controller layout to default".ToUpper(), menu, new UnityAction(OnResetControllerLayoutPressed), 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText(" ", menu, ref val, 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateButton(" ".ToUpper(), menu, (UnityAction)null, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)this, 5, (Action)UpdateDisplayedBindings);
		}

		private GameObject CreateKeyBindingLayout(GameObject parent, PlayerActions actions)
		{
			if (Object.op_Implicit((Object)(object)parent.transform.Find("Group/Grid/Scroll View/Viewport/Content")))
			{
				parent = ((Component)parent.transform.Find("Group/Grid/Scroll View/Viewport/Content")).gameObject;
			}
			GameObject val = Object.Instantiate<GameObject>(containerFrameAsset, parent.transform);
			ExtensionMethods.GetOrAddComponent<GridLayoutGroup>(val, false);
			layouts.Add(val, new Dictionary<BindingInfo, List<TextMeshProUGUI>>());
			foreach (PlayerAction action in ((PlayerActionSet)actions).Actions)
			{
				CreateBindingFrame(val, action);
			}
			return val;
		}

		private GameObject CreateBindingFrame(GameObject parent, PlayerAction action)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(keyGroupAsset, parent.transform);
			((TMP_Text)((Component)val.transform.Find("KeyTitle/Title")).gameObject.GetComponent<TextMeshProUGUI>()).text = action.Name;
			ExtensionMethods.GetOrAddComponent<ButtonInteraction>(((Component)val.transform.Find("KeyTitle/Reset")).gameObject, false).mouseClick.AddListener((UnityAction)delegate
			{
				OnResetButtonPressed(action);
			});
			GameObject gameObject = ((Component)val.transform.Find("Bindings")).gameObject;
			BindingInfo bindingInfo = val.AddComponent<BindingInfo>();
			layouts[parent].Add(bindingInfo, new List<TextMeshProUGUI>());
			for (int i = 0; i < 3; i++)
			{
				TextMeshProUGUI item = CreateKeyBindButton(gameObject, action, i);
				layouts[parent][bindingInfo].Add(item);
			}
			bindingInfo.action = action;
			return val;
		}

		private TextMeshProUGUI CreateKeyBindButton(GameObject parent, PlayerAction action, int slot)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(bindingButtonAsset, parent.transform);
			GameObject gameObject = ((Component)obj.transform.Find("Binding")).gameObject;
			TextMeshProUGUI component = ((Component)gameObject.transform.Find("Name")).gameObject.GetComponent<TextMeshProUGUI>();
			GameObject gameObject2 = ((Component)obj.transform.Find("Clear")).gameObject;
			ExtensionMethods.GetOrAddComponent<ButtonInteraction>(gameObject, false).mouseClick.AddListener((UnityAction)delegate
			{
				OnBindingButtonPressed(action, slot);
			});
			ExtensionMethods.GetOrAddComponent<ButtonInteraction>(gameObject2, false).mouseClick.AddListener((UnityAction)delegate
			{
				OnClearButtonPressed(action, slot);
			});
			return component;
		}

		private void OnResetKeyboardLayoutPressed()
		{
			Debug.Log((object)"[RebindControls] Reset Keyboard Layout pressed.");
			((PlayerActionSet)keyboardPlayer).Reset();
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)SaveLayouts);
		}

		private void OnResetControllerLayoutPressed()
		{
			Debug.Log((object)"[RebindControls] Reset Controller Layout pressed.");
			((PlayerActionSet)controllerPlayer).Reset();
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)SaveLayouts);
		}

		private void OnClearButtonPressed(PlayerAction action, int slot)
		{
			Debug.Log((object)"[RebindControls] Clear Button Pressed");
			if (slot < action.Bindings.Count)
			{
				action.RemoveBindingAt(slot);
			}
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)SaveLayouts);
		}

		private void OnBindingButtonPressed(PlayerAction action, int slot)
		{
			Debug.Log((object)"[RebindControls] Binding Button Pressed");
			if (slot < action.UnfilteredBindings.Count)
			{
				Debug.Log((object)$"[RebindControls] Slot {slot + 1} has found {action.UnfilteredBindings.Count} bindings on {action.Name}. Replacing existing binding now.");
				action.ListenForBindingReplacing(action.UnfilteredBindings[slot]);
			}
			else
			{
				Debug.Log((object)$"[RebindControls] Slot {slot + 1} has found {action.UnfilteredBindings.Count} bindings on {action.Name}. Listening for a binding.");
				action.ListenForBinding();
			}
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
		}

		private void OnResetButtonPressed(PlayerAction action)
		{
			action.ResetBindings();
			Debug.Log((object)"[RebindControls] Reset Button Pressed");
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)UpdateDisplayedBindings);
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)instance, 1, (Action)SaveLayouts);
		}

		public void UpdateDisplayedBindings()
		{
			foreach (KeyValuePair<GameObject, Dictionary<BindingInfo, List<TextMeshProUGUI>>> layout in layouts)
			{
				foreach (KeyValuePair<BindingInfo, List<TextMeshProUGUI>> item in layout.Value)
				{
					PlayerAction action = item.Key.action;
					int num = 0;
					foreach (TextMeshProUGUI item2 in item.Value)
					{
						if (num < action.Bindings.Count())
						{
							((TMP_Text)item2).text = action.Bindings[num].Name;
						}
						else if (action.IsListeningForBinding)
						{
							((TMP_Text)item2).text = "Waiting for input...";
						}
						else
						{
							((TMP_Text)item2).text = "";
						}
						num++;
					}
				}
			}
		}
	}
}
namespace RebindControls.Patches
{
	[HarmonyPatch(typeof(GoBack))]
	internal class GoBack_Patch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static bool KeyboardLayout()
		{
			bool flag = false;
			foreach (InputDevice activeDevice in InputManager.ActiveDevices)
			{
				if (((OneAxisInputControl)activeDevice.Action2).WasPressed)
				{
					flag = true;
				}
			}
			if ((Input.GetKeyDown((KeyCode)27) || flag) && (((PlayerActionSet)RebindControls.instance.keyboardPlayer).IsListeningForBinding || ((PlayerActionSet)RebindControls.instance.controllerPlayer).IsListeningForBinding) && !GameManager.instance.isPlaying)
			{
				if (((PlayerActionSet)RebindControls.instance.keyboardPlayer).IsListeningForBinding)
				{
					Debug.Log((object)"[RebindControls] Keyboard layout is listening for input. Skipping go back.");
				}
				else
				{
					Debug.Log((object)"[RebindControls] Controller layout is listening for input. Skipping go back.");
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerActions))]
	internal class PlayerActions_Patch
	{
		[HarmonyPrefix]
		[HarmonyPatch("CreateWithKeyboardBindings")]
		private static bool KeyboardLayout(ref PlayerActions __result)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (RebindControls.instance.setupDefault)
			{
				Debug.Log((object)"[RebindControls] Default Keyboard layout has been setup already, attempting to substitute the player's layout instead.");
				PlayerActions val = new PlayerActions();
				((PlayerActionSet)val).Load(((PlayerActionSet)RebindControls.instance.keyboardPlayer).Save());
				__result = val;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("CreateWithControllerBindings")]
		private static bool ControllerLayout(ref PlayerActions __result)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (RebindControls.instance.setupDefault)
			{
				Debug.Log((object)"[RebindControls] Default Controller layout has been setup already, attempting to substitute the player's layout instead.");
				PlayerActions val = new PlayerActions();
				((PlayerActionSet)val).Load(((PlayerActionSet)RebindControls.instance.controllerPlayer).Save());
				__result = val;
				return false;
			}
			return true;
		}
	}
}