Decompiled source of SebBinds v1.0.3

BepInEx\plugins\SebBinds\SebBinds.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SebCore;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SebBinds")]
[assembly: AssemblyProduct("SebBinds")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SebBinds
{
	public enum AxisAction
	{
		MoveX,
		MoveY,
		Steering,
		Throttle,
		Brake,
		Clutch,
		CameraLookX,
		CameraLookY
	}
	public static class AxisBindingStore
	{
		private static readonly Dictionary<int, BindingInput> AxisCache = new Dictionary<int, BindingInput>(64);

		private const int BindingPovOffset = 1000;

		private const int BindingKeyOffset = 2000;

		private const int BindingMouseOffset = 10000;

		private const int BindingGamepadButtonOffset = 11000;

		private const int BindingGamepadDpadOffset = 12000;

		private const int BindingGamepadAxisOffset = 14000;

		private const int BindingWheelAxisOffset = 15000;

		private const int BindingGamepadDpadAxisOffset = 16000;

		private const int BindingWheelDpadAxisOffset = 17000;

		private static int CacheKey(BindingScheme scheme, AxisAction action)
		{
			return ((int)scheme << 16) | (int)action;
		}

		internal static void ClearRuntimeCache()
		{
			AxisCache.Clear();
		}

		private static string Key(BindingScheme scheme, AxisAction action)
		{
			switch (scheme)
			{
			case BindingScheme.Wheel:
			{
				int num = (int)action;
				return "SebBinds_Wheel_Axis_" + num;
			}
			case BindingScheme.Keyboard:
			{
				int num = (int)action;
				return "SebBinds_KB_Axis_" + num;
			}
			default:
			{
				int num = (int)action;
				return "SebBinds_Axis_" + num;
			}
			}
		}

		public static BindingInput GetAxisBinding(BindingScheme scheme, AxisAction action)
		{
			int key = CacheKey(scheme, action);
			if (AxisCache.TryGetValue(key, out var value))
			{
				return value;
			}
			string text = Key(scheme, action);
			int @int = PlayerPrefs.GetInt(text, -1);
			BindingInput bindingInput = Decode(@int);
			if (@int < 0 && scheme == BindingScheme.Wheel)
			{
				string text2 = Key(BindingScheme.Controller, action);
				int int2 = PlayerPrefs.GetInt(text2, -1);
				BindingInput bindingInput2 = Decode(int2);
				if (bindingInput2.Kind == BindingKind.WheelAxis || bindingInput2.Kind == BindingKind.WheelDpadAxis)
				{
					PlayerPrefs.SetInt(text, int2);
					PlayerPrefs.DeleteKey(text2);
					bindingInput = bindingInput2;
				}
			}
			if (scheme == BindingScheme.Controller && (bindingInput.Kind == BindingKind.WheelAxis || bindingInput.Kind == BindingKind.WheelDpadAxis))
			{
				BindingInput bindingInput3 = default(BindingInput);
				bindingInput3.Kind = BindingKind.None;
				bindingInput3.Code = 0;
				bindingInput = bindingInput3;
			}
			if (scheme == BindingScheme.Wheel && (bindingInput.Kind == BindingKind.GamepadAxis || bindingInput.Kind == BindingKind.GamepadDpadAxis || bindingInput.Kind == BindingKind.GamepadDpad))
			{
				BindingInput bindingInput3 = default(BindingInput);
				bindingInput3.Kind = BindingKind.None;
				bindingInput3.Code = 0;
				bindingInput = bindingInput3;
			}
			AxisCache[key] = bindingInput;
			return bindingInput;
		}

		public static void SetAxisBinding(BindingScheme scheme, AxisAction action, BindingInput input)
		{
			if (scheme == BindingScheme.Controller && (input.Kind == BindingKind.WheelAxis || input.Kind == BindingKind.WheelDpadAxis))
			{
				BindingInput bindingInput = default(BindingInput);
				bindingInput.Kind = BindingKind.None;
				bindingInput.Code = 0;
				input = bindingInput;
			}
			if (scheme == BindingScheme.Wheel && (input.Kind == BindingKind.GamepadAxis || input.Kind == BindingKind.GamepadDpadAxis || input.Kind == BindingKind.GamepadDpad))
			{
				BindingInput bindingInput = default(BindingInput);
				bindingInput.Kind = BindingKind.None;
				bindingInput.Code = 0;
				input = bindingInput;
			}
			PlayerPrefs.SetInt(Key(scheme, action), Encode(input));
			AxisCache[CacheKey(scheme, action)] = input;
		}

		public static void ClearAxisBinding(BindingScheme scheme, AxisAction action)
		{
			PlayerPrefs.DeleteKey(Key(scheme, action));
			AxisCache.Remove(CacheKey(scheme, action));
		}

		public static BindingInput GetAxisBinding(AxisAction action)
		{
			return GetAxisBinding(BindingScheme.Controller, action);
		}

		public static void SetAxisBinding(AxisAction action, BindingInput input)
		{
			SetAxisBinding(BindingScheme.Controller, action, input);
		}

		public static void ClearAxisBinding(AxisAction action)
		{
			ClearAxisBinding(BindingScheme.Controller, action);
		}

		public static void ClearAll()
		{
			foreach (AxisAction value in Enum.GetValues(typeof(AxisAction)))
			{
				PlayerPrefs.DeleteKey(Key(BindingScheme.Controller, value));
				PlayerPrefs.DeleteKey(Key(BindingScheme.Keyboard, value));
				PlayerPrefs.DeleteKey(Key(BindingScheme.Wheel, value));
			}
			ClearRuntimeCache();
		}

		public static void ClearScheme(BindingScheme scheme)
		{
			foreach (AxisAction value in Enum.GetValues(typeof(AxisAction)))
			{
				PlayerPrefs.DeleteKey(Key(scheme, value));
			}
			ClearRuntimeCache();
		}

		private static int Encode(BindingInput input)
		{
			if (input.Kind == BindingKind.Button)
			{
				return Mathf.Clamp(input.Code, 0, 127);
			}
			if (input.Kind == BindingKind.Pov)
			{
				return 1000 + Mathf.Clamp(input.Code, 0, 3);
			}
			if (input.Kind == BindingKind.Key)
			{
				return 2000 + Mathf.Max(0, input.Code);
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				return 10000 + Mathf.Clamp(input.Code, 0, 31);
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				return 11000 + Mathf.Clamp(input.Code, 0, 255);
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				return 14000 + Mathf.Clamp(input.Code, 0, 15);
			}
			if (input.Kind == BindingKind.WheelAxis)
			{
				return 15000 + Mathf.Clamp(input.Code, 0, 31);
			}
			if (input.Kind == BindingKind.GamepadDpadAxis)
			{
				return 16000 + Mathf.Clamp(input.Code, 0, 1);
			}
			if (input.Kind == BindingKind.WheelDpadAxis)
			{
				return 17000 + Mathf.Clamp(input.Code, 0, 1);
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				return 12000 + Mathf.Clamp(input.Code, 0, 3);
			}
			return -1;
		}

		private static BindingInput Decode(int raw)
		{
			BindingInput result;
			if (raw < 0)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.None;
				result.Code = 0;
				return result;
			}
			if (raw >= 17000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.WheelDpadAxis;
				result.Code = Mathf.Clamp(raw - 17000, 0, 1);
				return result;
			}
			if (raw >= 16000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadDpadAxis;
				result.Code = Mathf.Clamp(raw - 16000, 0, 1);
				return result;
			}
			if (raw >= 15000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.WheelAxis;
				result.Code = Mathf.Clamp(raw - 15000, 0, 31);
				return result;
			}
			if (raw >= 14000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadAxis;
				result.Code = Mathf.Clamp(raw - 14000, 0, 15);
				return result;
			}
			if (raw >= 12000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadDpad;
				result.Code = Mathf.Clamp(raw - 12000, 0, 3);
				return result;
			}
			if (raw >= 11000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadButton;
				result.Code = Mathf.Clamp(raw - 11000, 0, 255);
				return result;
			}
			if (raw >= 10000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.MouseButton;
				result.Code = Mathf.Clamp(raw - 10000, 0, 31);
				return result;
			}
			if (raw >= 2000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.Key;
				result.Code = Mathf.Max(0, raw - 2000);
				return result;
			}
			if (raw >= 1000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.Pov;
				result.Code = Mathf.Clamp(raw - 1000, 0, 3);
				return result;
			}
			result = default(BindingInput);
			result.Kind = BindingKind.Button;
			result.Code = Mathf.Clamp(raw, 0, 127);
			return result;
		}
	}
	internal static class AxisCapture
	{
		private static bool _wheelBaselineValid;

		private static readonly float[] _wheelBaseline = new float[8];

		private static Vector2 _wheelPovBaseline;

		internal static void BeginCaptureSession(BindingScheme scheme)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			if (scheme != BindingScheme.Wheel)
			{
				_wheelBaselineValid = false;
				return;
			}
			for (int i = 0; i < _wheelBaseline.Length; i++)
			{
				_wheelBaseline[i] = WheelInterop.GetWheelRawAxisValue(i);
			}
			_wheelBaselineValid = true;
			if (WheelInterop.TryGetPov8Vector(out var v))
			{
				_wheelPovBaseline = -v;
			}
			else
			{
				_wheelPovBaseline = Vector2.zero;
			}
		}

		internal static bool TryCaptureNextAxis(BindingScheme scheme, out BindingInput input)
		{
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			if (scheme == BindingScheme.Wheel)
			{
				float num = 0f;
				int num2 = -1;
				if (!_wheelBaselineValid)
				{
					BeginCaptureSession(BindingScheme.Wheel);
				}
				for (int i = 0; i <= 7; i++)
				{
					float wheelRawAxisValue = WheelInterop.GetWheelRawAxisValue(i);
					float num3 = _wheelBaseline[i];
					float num4 = Mathf.Abs(wheelRawAxisValue - num3);
					if (num4 > num)
					{
						num = num4;
						num2 = i;
					}
				}
				if (num2 >= 0 && num > 0.35f)
				{
					input = new BindingInput
					{
						Kind = BindingKind.WheelAxis,
						Code = num2
					};
					return true;
				}
				if (WheelInterop.TryGetPov8Vector(out var v))
				{
					Vector2 val = -v;
					if (Mathf.Abs(val.x - _wheelPovBaseline.x) > 0.5f && Mathf.Abs(val.x) > 0.5f)
					{
						input = new BindingInput
						{
							Kind = BindingKind.WheelDpadAxis,
							Code = 0
						};
						return true;
					}
					if (Mathf.Abs(val.y - _wheelPovBaseline.y) > 0.5f && Mathf.Abs(val.y) > 0.5f)
					{
						input = new BindingInput
						{
							Kind = BindingKind.WheelDpadAxis,
							Code = 1
						};
						return true;
					}
				}
			}
			if (scheme == BindingScheme.Controller)
			{
				BindingEvaluator.BeginFrame();
				float num5 = 0f;
				int num6 = -1;
				for (int j = 0; j <= 5; j++)
				{
					BindingInput bindingInput = default(BindingInput);
					bindingInput.Kind = BindingKind.GamepadAxis;
					bindingInput.Code = j;
					BindingInput input2 = bindingInput;
					float axisValue = BindingEvaluator.GetAxisValue(input2);
					float prevAxisValueForCapture = BindingEvaluator.GetPrevAxisValueForCapture(input2);
					float num7 = Mathf.Abs(axisValue - prevAxisValueForCapture);
					if (num7 > num5)
					{
						num5 = num7;
						num6 = j;
					}
				}
				if (num6 >= 0 && num5 > 0.35f)
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadAxis,
						Code = num6
					};
					return true;
				}
				Gamepad current = Gamepad.current;
				if (current != null)
				{
					Vector2 val2 = ((InputControl<Vector2>)(object)current.dpad).ReadValue();
					if (Mathf.Abs(val2.x) > 0.5f)
					{
						input = new BindingInput
						{
							Kind = BindingKind.GamepadDpadAxis,
							Code = 0
						};
						return true;
					}
					if (Mathf.Abs(val2.y) > 0.5f)
					{
						input = new BindingInput
						{
							Kind = BindingKind.GamepadDpadAxis,
							Code = 1
						};
						return true;
					}
				}
			}
			input = default(BindingInput);
			return false;
		}
	}
	internal static class AxisDefaults
	{
		internal static void EnsureControllerDefaults()
		{
			SetIfUnset(AxisAction.MoveY, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 3
			});
			SetIfUnset(AxisAction.MoveX, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 2
			});
			SetIfUnset(AxisAction.Steering, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 2
			});
			SetIfUnset(AxisAction.Throttle, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 1
			});
			SetIfUnset(AxisAction.Brake, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 0
			});
			SetIfUnset(AxisAction.CameraLookX, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 4
			});
			SetIfUnset(AxisAction.CameraLookY, new BindingInput
			{
				Kind = BindingKind.GamepadAxis,
				Code = 5
			});
		}

		private static void SetIfUnset(AxisAction action, BindingInput input)
		{
			if (AxisBindingStore.GetAxisBinding(action).Kind == BindingKind.None)
			{
				AxisBindingStore.SetAxisBinding(action, input);
			}
		}
	}
	public interface IAxisProvider
	{
		bool IsAvailable();

		bool SupportsClutch();

		bool TryGetAxisValue(BindingInput input, out float value);

		bool TryGetAxisLabel(BindingInput input, out string label);

		bool TryCaptureNextAxis(out BindingInput input);
	}
	public enum BindingScheme
	{
		Controller,
		Keyboard,
		Wheel
	}
	public static class BindingStore
	{
		private const int BindingPovOffset = 1000;

		private const int BindingKeyOffset = 2000;

		private const int BindingMouseOffset = 10000;

		private const int BindingGamepadButtonOffset = 11000;

		private const int BindingGamepadDpadOffset = 12000;

		private const int BindingGamepadAxisOffset = 14000;

		private const int BindingWheelAxisOffset = 15000;

		private const int BindingGamepadDpadAxisOffset = 16000;

		private const int BindingWheelDpadAxisOffset = 17000;

		private const string PrefKeyBindModifierController = "ELWS_Bind_Modifier";

		private const string PrefKeyBindModifierKeyboard = "SebBinds_KB_Bind_Modifier";

		private const string PrefKeyBindModifierWheel = "SebBinds_Wheel_Bind_Modifier";

		private static readonly Dictionary<int, BindingInput> BindingCache = new Dictionary<int, BindingInput>(256);

		private static readonly Dictionary<int, BindingInput> ModifierCache = new Dictionary<int, BindingInput>(4);

		private static int Key(BindingScheme scheme, BindingLayer layer, BindAction action)
		{
			return ((int)scheme << 16) | ((int)layer << 8) | (int)action;
		}

		private static int ModKey(BindingScheme scheme)
		{
			return (int)scheme;
		}

		internal static void ClearRuntimeCache()
		{
			BindingCache.Clear();
			ModifierCache.Clear();
		}

		private static string GetModifierPrefKey(BindingScheme scheme)
		{
			return scheme switch
			{
				BindingScheme.Wheel => "SebBinds_Wheel_Bind_Modifier", 
				BindingScheme.Keyboard => "SebBinds_KB_Bind_Modifier", 
				_ => "ELWS_Bind_Modifier", 
			};
		}

		private static string GetBindPrefKey(BindingScheme scheme, BindingLayer layer, BindAction action)
		{
			switch (scheme)
			{
			case BindingScheme.Keyboard:
			{
				int num = (int)layer;
				string text3 = num.ToString();
				num = (int)action;
				return "SebBinds_KB_Bind_" + text3 + "_" + num;
			}
			case BindingScheme.Wheel:
			{
				int num = (int)layer;
				string text2 = num.ToString();
				num = (int)action;
				return "SebBinds_Wheel_Bind_" + text2 + "_" + num;
			}
			default:
			{
				int num = (int)layer;
				string text = num.ToString();
				num = (int)action;
				return "ELWS_Bind_" + text + "_" + num;
			}
			}
		}

		private static string GetLegacyBindPrefKey(BindingScheme scheme, BindingLayer layer, BindAction action)
		{
			return scheme switch
			{
				BindingScheme.Keyboard => "SebBinds_KB_Bind_" + layer.ToString() + "_" + action, 
				BindingScheme.Wheel => "SebBinds_Wheel_Bind_" + layer.ToString() + "_" + action, 
				_ => "ELWS_Bind_" + layer.ToString() + "_" + action, 
			};
		}

		public static void ClearAll()
		{
			foreach (BindAction value in Enum.GetValues(typeof(BindAction)))
			{
				foreach (BindingLayer value2 in Enum.GetValues(typeof(BindingLayer)))
				{
					foreach (BindingScheme value3 in Enum.GetValues(typeof(BindingScheme)))
					{
						PlayerPrefs.DeleteKey(GetBindPrefKey(value3, value2, value));
						PlayerPrefs.DeleteKey(GetLegacyBindPrefKey(value3, value2, value));
					}
				}
			}
			PlayerPrefs.DeleteKey(GetModifierPrefKey(BindingScheme.Controller));
			PlayerPrefs.DeleteKey(GetModifierPrefKey(BindingScheme.Keyboard));
			PlayerPrefs.DeleteKey(GetModifierPrefKey(BindingScheme.Wheel));
			ClearRuntimeCache();
		}

		public static void ClearScheme(BindingScheme scheme)
		{
			foreach (BindAction value in Enum.GetValues(typeof(BindAction)))
			{
				foreach (BindingLayer value2 in Enum.GetValues(typeof(BindingLayer)))
				{
					PlayerPrefs.DeleteKey(GetBindPrefKey(scheme, value2, value));
					PlayerPrefs.DeleteKey(GetLegacyBindPrefKey(scheme, value2, value));
				}
			}
			PlayerPrefs.DeleteKey(GetModifierPrefKey(scheme));
			ClearRuntimeCache();
		}

		public static BindingInput GetBinding(BindingLayer layer, BindAction action)
		{
			return GetBinding(BindingScheme.Controller, layer, action);
		}

		public static BindingInput GetBinding(BindingScheme scheme, BindingLayer layer, BindAction action)
		{
			int key = Key(scheme, layer, action);
			if (BindingCache.TryGetValue(key, out var value))
			{
				return value;
			}
			string bindPrefKey = GetBindPrefKey(scheme, layer, action);
			int @int = PlayerPrefs.GetInt(bindPrefKey, -1);
			if (@int < 0)
			{
				@int = PlayerPrefs.GetInt(GetLegacyBindPrefKey(scheme, layer, action), -1);
				if (@int >= 0)
				{
					PlayerPrefs.SetInt(bindPrefKey, @int);
				}
			}
			BindingInput bindingInput = Decode(@int);
			BindingCache[key] = bindingInput;
			return bindingInput;
		}

		public static void SetBinding(BindingLayer layer, BindAction action, BindingInput input)
		{
			SetBinding(BindingScheme.Controller, layer, action, input);
		}

		public static void SetBinding(BindingScheme scheme, BindingLayer layer, BindAction action, BindingInput input)
		{
			PlayerPrefs.SetInt(GetBindPrefKey(scheme, layer, action), Encode(input));
			BindingCache[Key(scheme, layer, action)] = input;
		}

		public static BindingInput GetModifierBinding()
		{
			return GetModifierBinding(BindingScheme.Controller);
		}

		public static void SetModifierBinding(BindingInput input)
		{
			SetModifierBinding(BindingScheme.Controller, input);
		}

		public static BindingInput GetModifierBinding(BindingScheme scheme)
		{
			int key = ModKey(scheme);
			if (ModifierCache.TryGetValue(key, out var value))
			{
				return value;
			}
			BindingInput bindingInput = Decode(PlayerPrefs.GetInt(GetModifierPrefKey(scheme), -1));
			ModifierCache[key] = bindingInput;
			return bindingInput;
		}

		public static void SetModifierBinding(BindingScheme scheme, BindingInput input)
		{
			PlayerPrefs.SetInt(GetModifierPrefKey(scheme), Encode(input));
			ModifierCache[ModKey(scheme)] = input;
		}

		public static string GetBindingLabel(BindingInput input)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (input.Kind == BindingKind.Button)
			{
				return "But. " + (Mathf.Clamp(input.Code, 0, 127) + 1);
			}
			if (input.Kind == BindingKind.Pov)
			{
				return Mathf.Clamp(input.Code, 0, 3) switch
				{
					0 => "DP-U", 
					1 => "DP-R", 
					2 => "DP-D", 
					_ => "DP-L", 
				};
			}
			if (input.Kind == BindingKind.Key)
			{
				try
				{
					Key val = (Key)Mathf.Max(0, input.Code);
					return ((object)(Key)(ref val)).ToString();
				}
				catch
				{
					return "Key";
				}
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				return input.Code switch
				{
					0 => "Mouse L", 
					1 => "Mouse R", 
					2 => "Mouse M", 
					_ => "Mouse", 
				};
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				return "Pad " + input.Code;
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				return Mathf.Clamp(input.Code, 0, 3) switch
				{
					0 => "DP-U", 
					1 => "DP-R", 
					2 => "DP-D", 
					_ => "DP-L", 
				};
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				return input.Code switch
				{
					0 => "LT Axis", 
					1 => "RT Axis", 
					2 => "LS X", 
					3 => "LS Y", 
					4 => "RS X", 
					5 => "RS Y", 
					_ => "Axis", 
				};
			}
			if (input.Kind == BindingKind.WheelAxis)
			{
				return Mathf.Clamp(input.Code, 0, 7) switch
				{
					0 => "lX", 
					1 => "lY", 
					2 => "lZ", 
					3 => "lRx", 
					4 => "lRy", 
					5 => "lRz", 
					6 => "slider0", 
					7 => "slider1", 
					_ => "lX", 
				};
			}
			if (input.Kind == BindingKind.GamepadDpadAxis)
			{
				if (input.Code != 0)
				{
					return "Dpad Y";
				}
				return "Dpad X";
			}
			if (input.Kind == BindingKind.WheelDpadAxis)
			{
				if (input.Code != 0)
				{
					return "Wheel Dpad Y";
				}
				return "Wheel Dpad X";
			}
			return "None";
		}

		public static string GetChordLabel(BindingInput input, bool modified)
		{
			return GetBindingLabel(input);
		}

		public static string GetActionLabel(BindAction action)
		{
			return action switch
			{
				BindAction.InteractOk => "Interact", 
				BindAction.Back => "Back/Handbrake", 
				BindAction.MapItems => "Map/Items", 
				BindAction.Pause => "Pause", 
				BindAction.Drive => "Drive", 
				BindAction.Brake => "Brake/Reverse", 
				BindAction.Map => "Map", 
				BindAction.Items => "Items", 
				BindAction.Jobs => "Jobs", 
				BindAction.SteerLeft => "Steer Left", 
				BindAction.SteerRight => "Steer Right", 
				BindAction.MoveUp => "Move Up", 
				BindAction.MoveDown => "Move Down", 
				BindAction.MoveLeft => "Move Left", 
				BindAction.MoveRight => "Move Right", 
				BindAction.LookUp => "Look Up", 
				BindAction.LookDown => "Look Down", 
				BindAction.LookLeft => "Look Left", 
				BindAction.LookRight => "Look Right", 
				BindAction.CameraLookX => "Cam Look X", 
				BindAction.CameraLookY => "Cam Look Y", 
				BindAction.SteerAxis => "Steer Axis", 
				BindAction.Camera => "1P/3P Camera", 
				BindAction.IndicatorLeft => "L Indicator", 
				BindAction.IndicatorRight => "R Indicator", 
				BindAction.IndicatorHazards => "4Way Indicator", 
				BindAction.ResetVehicle => "Reset", 
				BindAction.Headlights => "Lights", 
				BindAction.Horn => "Horn", 
				BindAction.RadioPower => "Radio Pwr", 
				BindAction.RadioScanToggle => "Scan", 
				BindAction.RadioScanLeft => "Prev Ch", 
				BindAction.RadioScanRight => "Next Ch", 
				BindAction.ToggleGearbox => "Gearbox", 
				BindAction.ShiftUp => "Shift Up", 
				BindAction.ShiftDown => "Shift Down", 
				BindAction.IgnitionToggle => "Ignition", 
				_ => action.ToString(), 
			};
		}

		private static int Encode(BindingInput input)
		{
			if (input.Kind == BindingKind.Button)
			{
				return Mathf.Clamp(input.Code, 0, 127);
			}
			if (input.Kind == BindingKind.Pov)
			{
				return 1000 + Mathf.Clamp(input.Code, 0, 3);
			}
			if (input.Kind == BindingKind.Key)
			{
				return 2000 + Mathf.Max(0, input.Code);
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				return 10000 + Mathf.Clamp(input.Code, 0, 31);
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				return 11000 + Mathf.Clamp(input.Code, 0, 255);
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				return 12000 + Mathf.Clamp(input.Code, 0, 3);
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				return 14000 + Mathf.Clamp(input.Code, 0, 15);
			}
			if (input.Kind == BindingKind.WheelAxis)
			{
				return 15000 + Mathf.Clamp(input.Code, 0, 31);
			}
			if (input.Kind == BindingKind.GamepadDpadAxis)
			{
				return 16000 + Mathf.Clamp(input.Code, 0, 1);
			}
			if (input.Kind == BindingKind.WheelDpadAxis)
			{
				return 17000 + Mathf.Clamp(input.Code, 0, 1);
			}
			return -1;
		}

		private static BindingInput Decode(int raw)
		{
			BindingInput result;
			if (raw < 0)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.None;
				result.Code = 0;
				return result;
			}
			if (raw >= 17000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.WheelDpadAxis;
				result.Code = Mathf.Clamp(raw - 17000, 0, 1);
				return result;
			}
			if (raw >= 16000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadDpadAxis;
				result.Code = Mathf.Clamp(raw - 16000, 0, 1);
				return result;
			}
			if (raw >= 15000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.WheelAxis;
				result.Code = Mathf.Clamp(raw - 15000, 0, 31);
				return result;
			}
			if (raw >= 14000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadAxis;
				result.Code = Mathf.Clamp(raw - 14000, 0, 15);
				return result;
			}
			if (raw >= 12000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadDpad;
				result.Code = Mathf.Clamp(raw - 12000, 0, 3);
				return result;
			}
			if (raw >= 11000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.GamepadButton;
				result.Code = Mathf.Clamp(raw - 11000, 0, 255);
				return result;
			}
			if (raw >= 10000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.MouseButton;
				result.Code = Mathf.Clamp(raw - 10000, 0, 31);
				return result;
			}
			if (raw >= 2000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.Key;
				result.Code = Mathf.Max(0, raw - 2000);
				return result;
			}
			if (raw >= 1000)
			{
				result = default(BindingInput);
				result.Kind = BindingKind.Pov;
				result.Code = Mathf.Clamp(raw - 1000, 0, 3);
				return result;
			}
			result = default(BindingInput);
			result.Kind = BindingKind.Button;
			result.Code = Mathf.Clamp(raw, 0, 127);
			return result;
		}
	}
	public enum BindAction
	{
		InteractOk = 0,
		Back = 1,
		MapItems = 2,
		Pause = 3,
		Camera = 5,
		ResetVehicle = 6,
		Headlights = 7,
		Horn = 8,
		RadioPower = 9,
		RadioScanToggle = 10,
		RadioScanLeft = 11,
		RadioScanRight = 12,
		ToggleGearbox = 13,
		ShiftUp = 14,
		ShiftDown = 15,
		IgnitionToggle = 16,
		Drive = 100,
		Brake = 101,
		Map = 102,
		Items = 103,
		Jobs = 104,
		SteerLeft = 105,
		SteerRight = 106,
		MoveUp = 111,
		MoveDown = 112,
		MoveLeft = 113,
		MoveRight = 114,
		LookUp = 115,
		LookDown = 116,
		LookLeft = 117,
		LookRight = 118,
		FreeCam = 107,
		CameraLookX = 108,
		CameraLookY = 109,
		SteerAxis = 110,
		IndicatorLeft = 119,
		IndicatorRight = 120,
		IndicatorHazards = 121
	}
	public enum BindingLayer
	{
		Normal,
		Modified
	}
	public enum BindingKind
	{
		None,
		Button,
		Pov,
		Key,
		MouseButton,
		GamepadButton,
		GamepadDpad,
		GamepadAxis,
		WheelAxis,
		GamepadDpadAxis,
		WheelDpadAxis
	}
	public struct BindingInput
	{
		public BindingKind Kind;

		public int Code;
	}
	public class BindsMenuWindow : MonoBehaviour
	{
		private struct BindingConflict
		{
			public BindingLayer Layer;

			public BindAction Action;
		}

		private enum Page
		{
			Bindings,
			BindingCapture,
			AxisCapture,
			SchemeSelect
		}

		private sealed class PageDef
		{
			public string Title;

			public BindAction[] Actions;
		}

		public const string FileName = "binds";

		public const string ListenerName = "SebBindsMenu";

		public const string ListenerData = "listener_SebBindsMenu";

		private float _mouseYLock;

		private UIUtil _util;

		private WindowView _view;

		private Page _page = Page.SchemeSelect;

		private int _bindingsPageIndex;

		private BindingScheme _scheme;

		private BindAction _bindingCaptureAction;

		private BindingLayer _bindingCaptureLayer;

		private bool _isCapturingModifier;

		private bool _bindingCaptureMissingModifier;

		private float _axisCaptureEnterTime;

		private float _bindingCaptureEnterTime = -999f;

		private bool _bindingDupConfirmActive;

		private BindingInput _bindingDupPendingCaptured;

		private BindingLayer _bindingDupPendingLayer;

		private List<BindingConflict> _bindingDupConflicts;

		private string _bindingDupAxisConflict;

		private AxisAction _axisCaptureAction;

		private static readonly BindAction[] AllBindableActions = new BindAction[21]
		{
			BindAction.InteractOk,
			BindAction.Back,
			BindAction.Pause,
			BindAction.Drive,
			BindAction.Brake,
			BindAction.MapItems,
			BindAction.Jobs,
			BindAction.Camera,
			BindAction.ResetVehicle,
			BindAction.Headlights,
			BindAction.Horn,
			BindAction.CameraLookX,
			BindAction.CameraLookY,
			BindAction.RadioPower,
			BindAction.RadioScanRight,
			BindAction.RadioScanLeft,
			BindAction.RadioScanToggle,
			BindAction.IgnitionToggle,
			BindAction.ToggleGearbox,
			BindAction.ShiftUp,
			BindAction.ShiftDown
		};

		internal static float BindingCaptureHeartbeatTime { get; private set; }

		internal static int LastMenuActiveFrame { get; private set; }

		internal static int LastBindingCaptureFrame { get; private set; }

		internal static bool MenuActive
		{
			get
			{
				int frameCount = Time.frameCount;
				if (LastMenuActiveFrame != frameCount)
				{
					return LastMenuActiveFrame == frameCount - 1;
				}
				return true;
			}
		}

		internal static bool BindingCaptureActive
		{
			get
			{
				int frameCount = Time.frameCount;
				if (LastBindingCaptureFrame == frameCount || LastBindingCaptureFrame == frameCount - 1)
				{
					return true;
				}
				return Time.unscaledTime - BindingCaptureHeartbeatTime < 0.5f;
			}
		}

		public void FrameUpdate(WindowView view)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			LastMenuActiveFrame = Time.frameCount;
			if (_page == Page.BindingCapture)
			{
				LastBindingCaptureFrame = Time.frameCount;
			}
			if (view != null)
			{
				_view = view;
				if (_util == null)
				{
					_util = new UIUtil();
				}
				_util.M = view.M;
				_util.R = view.R;
				_util.Nav = view.M.nav;
				Rect p = default(Rect);
				((Rect)(ref p))..ctor(view.position * 8f, view.size * 8f);
				((Rect)(ref p)).position = ((Rect)(ref p)).position + new Vector2(8f, 8f);
				if (((ScreenProgram)_util.M).mouseButtonUp)
				{
					_mouseYLock = 0f;
				}
				if (_mouseYLock > 0f)
				{
					((ScreenProgram)_util.M).mouse.y = _mouseYLock;
				}
				DrawMenu(p);
			}
		}

		public void BackButtonPressed()
		{
			if (_page == Page.BindingCapture)
			{
				_bindingDupConfirmActive = false;
				_page = Page.Bindings;
				return;
			}
			if (_page == Page.AxisCapture)
			{
				_page = Page.Bindings;
				return;
			}
			if (_page == Page.Bindings)
			{
				_page = Page.SchemeSelect;
				return;
			}
			DesktopAppLauncher.TryOpenProgramListener(_util?.M, _util?.R, SebCoreMenuWindow.FileName, "listener_SebCoreMenu");
			WindowView view = _view;
			if (view != null)
			{
				view.Kill();
			}
		}

		private void DrawMenu(Rect p)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			float center = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f - 16f;
			float y = ((Rect)(ref p)).y + 10f;
			float line = 12f;
			float sectionGap = 4f;
			if (_page == Page.SchemeSelect)
			{
				DrawSchemeSelect(p, center, ref y, line, sectionGap);
			}
			else if (_page == Page.BindingCapture)
			{
				Plugin.LogDebug("Binding capture open: " + BindingStore.GetActionLabel(_bindingCaptureAction) + " (" + LayerLabel(_bindingCaptureLayer) + ")");
				DrawBindingCapture(p, center, ref y, line, sectionGap);
			}
			else if (_page == Page.AxisCapture)
			{
				Plugin.LogDebug("Axis capture open: " + _axisCaptureAction);
				DrawAxisCapture(p, center, ref y, line, sectionGap);
			}
			else
			{
				DrawBindings(p, center, ref y, line, sectionGap);
			}
		}

		private void DrawSchemeSelect(Rect p, float center, ref float y, float line, float sectionGap)
		{
			float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			bool flag = WheelInterop.IsWheelPluginPresent();
			float num2 = ((Rect)(ref p)).y + ((Rect)(ref p)).height / 2f - 20f;
			if (flag)
			{
				num2 -= 12f;
			}
			_util.Label("Binds", num, ((Rect)(ref p)).y + 10f);
			_util.Label("Choose Input", num, ((Rect)(ref p)).y + 22f);
			if (_util.FancyButton("Controller", num, num2, 0f))
			{
				_scheme = BindingScheme.Controller;
				_bindingsPageIndex = 0;
				_page = Page.Bindings;
				return;
			}
			if (_util.FancyButton("Keyboard", num, num2 + 24f, 0f))
			{
				_scheme = BindingScheme.Keyboard;
				_bindingsPageIndex = 0;
				_page = Page.Bindings;
				return;
			}
			if (flag && _util.FancyButton("Wheel", num, num2 + 48f, 0f))
			{
				_scheme = BindingScheme.Wheel;
				_bindingsPageIndex = 0;
				_page = Page.Bindings;
				return;
			}
			float num3 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f;
			if (_util.SimpleButtonRaw("Back", num, num3))
			{
				DesktopAppLauncher.TryOpenProgramListener(_util.M, _util.R, SebCoreMenuWindow.FileName, "listener_SebCoreMenu");
				WindowView view = _view;
				if (view != null)
				{
					view.Kill();
				}
			}
		}

		private void DrawBindings(Rect p, float center, ref float y, float line, float sectionGap)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			_util.Label("Binds", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
			y += line;
			string text = ((_scheme == BindingScheme.Keyboard) ? "Keyboard" : ((_scheme == BindingScheme.Wheel) ? "Wheel" : "Controller"));
			_util.Label(text, ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
			y += line;
			if (_scheme == BindingScheme.Wheel && !WheelInterop.HasCalibration())
			{
				DrawWheelNeedsCalibration(p, center, ref y, line, sectionGap);
				return;
			}
			float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			float num2 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f;
			float num3 = ((Rect)(ref p)).x + 40f;
			float num4 = ((Rect)(ref p)).x + ((Rect)(ref p)).width - 40f;
			List<PageDef> pagesForScheme = GetPagesForScheme();
			if (_util.SimpleButtonRaw("Prev", num3, num2))
			{
				_bindingsPageIndex = PrevPageIndex(_bindingsPageIndex, pagesForScheme.Count);
			}
			if (_util.SimpleButtonRaw("Back", num, num2))
			{
				_page = Page.SchemeSelect;
			}
			if (_util.SimpleButtonRaw("Next", num4, num2))
			{
				_bindingsPageIndex = NextPageIndex(_bindingsPageIndex, pagesForScheme.Count);
			}
			y += sectionGap;
			if (pagesForScheme.Count == 0)
			{
				_util.Label("(no pages)", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
				return;
			}
			if (_bindingsPageIndex >= pagesForScheme.Count)
			{
				_bindingsPageIndex = 0;
			}
			PageDef pageDef = pagesForScheme[_bindingsPageIndex];
			_util.Label(pageDef.Title, ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
			y += line + sectionGap;
			_util.Label(_bindingsPageIndex + 1 + "/" + pagesForScheme.Count, ((Rect)(ref p)).x + ((Rect)(ref p)).width - 18f, ((Rect)(ref p)).y + 10f);
			if (pageDef.Actions == null)
			{
				DrawAxesPage(p, center, ref y, line, sectionGap);
			}
			else
			{
				DrawBindingsButtonsPage(p, center, ref y, line, pageDef.Actions);
			}
		}

		private void DrawWheelNeedsCalibration(Rect p, float center, ref float y, float line, float sectionGap)
		{
			float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			float num2 = ((Rect)(ref p)).y + ((Rect)(ref p)).height / 2f - 18f;
			_util.Label("Wheel Not Calibrated", num, num2);
			_util.Label("Run the Calibration Wizard", num, num2 + line);
			_util.Label("before binding wheel inputs.", num, num2 + line * 2f);
			float num3 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f;
			float num4 = num3 - 12f;
			if (_util.SimpleButtonRaw("Calibrate", num, num4))
			{
				WheelInterop.RequestOpenCalibrationWizard();
				TryOpenWheelMenuAndFocus();
			}
			if (_util.SimpleButtonRaw("Back", num, num3))
			{
				_page = Page.SchemeSelect;
			}
		}

		private bool TryOpenWheelMenuAndFocus()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			DesktopDotExe val = ((_util != null) ? _util.M : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			WindowView val2 = default(WindowView);
			new File(((ScreenProgram)val).R, val)
			{
				name = "wheel",
				type = (FileType)1,
				data = "listener_G920Menu",
				icon = 7,
				iconHover = 7,
				position = Vector2.zero,
				visible = false,
				cantFolder = true
			}.Execute(ref val2);
			if (val2 == null)
			{
				return false;
			}
			FieldInfo field = typeof(DesktopDotExe).GetField("windowViewer", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return false;
			}
			field.SetValue(val, val2);
			return true;
		}

		private static List<PageDef> GetPages()
		{
			return new List<PageDef>();
		}

		private List<PageDef> GetPagesForScheme()
		{
			List<PageDef> list;
			if (_scheme == BindingScheme.Controller)
			{
				list = new List<PageDef>();
				list.Add(new PageDef
				{
					Title = "Axes",
					Actions = null
				});
				list.Add(new PageDef
				{
					Title = "Global",
					Actions = new BindAction[6]
					{
						BindAction.InteractOk,
						BindAction.Back,
						BindAction.Pause,
						BindAction.MapItems,
						BindAction.Jobs,
						BindAction.ResetVehicle
					}
				});
				list.Add(new PageDef
				{
					Title = "Vehicle",
					Actions = new BindAction[3]
					{
						BindAction.Camera,
						BindAction.Headlights,
						BindAction.Horn
					}
				});
				list.Add(new PageDef
				{
					Title = "Radio",
					Actions = new BindAction[4]
					{
						BindAction.RadioPower,
						BindAction.RadioScanRight,
						BindAction.RadioScanLeft,
						BindAction.RadioScanToggle
					}
				});
				List<PageDef> list2 = list;
				{
					foreach (SebBindsApi.Page item in SebBindsApi.GetExtraPagesSnapshot())
					{
						if (item != null && !string.IsNullOrWhiteSpace(item.Title) && item.Actions != null)
						{
							list2.Add(new PageDef
							{
								Title = item.Title.Trim(),
								Actions = item.Actions
							});
						}
					}
					return list2;
				}
			}
			if (_scheme == BindingScheme.Wheel)
			{
				list = new List<PageDef>();
				list.Add(new PageDef
				{
					Title = "Axes",
					Actions = null
				});
				list.Add(new PageDef
				{
					Title = "Global",
					Actions = new BindAction[6]
					{
						BindAction.InteractOk,
						BindAction.Back,
						BindAction.Pause,
						BindAction.MapItems,
						BindAction.Jobs,
						BindAction.ResetVehicle
					}
				});
				list.Add(new PageDef
				{
					Title = "Vehicle",
					Actions = new BindAction[3]
					{
						BindAction.Camera,
						BindAction.Headlights,
						BindAction.Horn
					}
				});
				list.Add(new PageDef
				{
					Title = "Radio",
					Actions = new BindAction[4]
					{
						BindAction.RadioPower,
						BindAction.RadioScanRight,
						BindAction.RadioScanLeft,
						BindAction.RadioScanToggle
					}
				});
				List<PageDef> list3 = list;
				{
					foreach (SebBindsApi.Page item2 in SebBindsApi.GetExtraPagesSnapshot())
					{
						if (item2 != null && !string.IsNullOrWhiteSpace(item2.Title) && item2.Actions != null)
						{
							list3.Add(new PageDef
							{
								Title = item2.Title.Trim(),
								Actions = item2.Actions
							});
						}
					}
					return list3;
				}
			}
			list = new List<PageDef>();
			list.Add(new PageDef
			{
				Title = "Global",
				Actions = new BindAction[6]
				{
					BindAction.InteractOk,
					BindAction.Back,
					BindAction.Pause,
					BindAction.MapItems,
					BindAction.Jobs,
					BindAction.ResetVehicle
				}
			});
			list.Add(new PageDef
			{
				Title = "Movement",
				Actions = new BindAction[4]
				{
					BindAction.MoveUp,
					BindAction.MoveDown,
					BindAction.MoveLeft,
					BindAction.MoveRight
				}
			});
			list.Add(new PageDef
			{
				Title = "Vehicle",
				Actions = new BindAction[7]
				{
					BindAction.SteerLeft,
					BindAction.SteerRight,
					BindAction.Drive,
					BindAction.Brake,
					BindAction.Camera,
					BindAction.Headlights,
					BindAction.Horn
				}
			});
			list.Add(new PageDef
			{
				Title = "Camera",
				Actions = new BindAction[4]
				{
					BindAction.LookUp,
					BindAction.LookDown,
					BindAction.LookLeft,
					BindAction.LookRight
				}
			});
			list.Add(new PageDef
			{
				Title = "Radio",
				Actions = new BindAction[4]
				{
					BindAction.RadioPower,
					BindAction.RadioScanRight,
					BindAction.RadioScanLeft,
					BindAction.RadioScanToggle
				}
			});
			List<PageDef> list4 = list;
			foreach (SebBindsApi.Page item3 in SebBindsApi.GetExtraPagesSnapshot())
			{
				if (item3 != null && !string.IsNullOrWhiteSpace(item3.Title) && item3.Actions != null)
				{
					list4.Add(new PageDef
					{
						Title = item3.Title.Trim(),
						Actions = item3.Actions
					});
				}
			}
			return list4;
		}

		private void DrawBindingsButtonsPage(Rect p, float center, ref float y, float line, BindAction[] actions)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			if (_util.CycleButtonRaw("Modifier", BindingStore.GetBindingLabel(BindingStore.GetModifierBinding(_scheme)), center, y))
			{
				_bindingCaptureAction = BindAction.InteractOk;
				_bindingCaptureLayer = BindingLayer.Normal;
				_bindingDupConfirmActive = false;
				_page = Page.BindingCapture;
				_bindingCaptureEnterTime = Time.unscaledTime;
				_isCapturingModifier = true;
				_bindingCaptureMissingModifier = false;
				return;
			}
			y += line;
			y += 3f;
			DrawBindingTable(p, actions, ref y, line);
			float num2 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 30f;
			if (_util.SimpleButtonRaw("Reset Defaults", num, num2))
			{
				BindingStore.ClearScheme(_scheme);
				AxisBindingStore.ClearScheme(_scheme);
				if (_scheme == BindingScheme.Controller)
				{
					DefaultPreset.TryInstallFromInputManager(Plugin.LastInputManager, true, forceReinstall: true);
					AxisDefaults.EnsureControllerDefaults();
				}
				else if (_scheme == BindingScheme.Keyboard)
				{
					KeyboardDefaults.EnsureDefaults();
				}
				PlayerPrefs.Save();
			}
		}

		private void DrawAxesPage(Rect p, float center, ref float y, float line, float sectionGap)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (_scheme == BindingScheme.Wheel)
			{
				DrawWheelAxesRedirect(p, center, ref y, line, sectionGap);
				return;
			}
			float num = ((Rect)(ref p)).x + 12f;
			float num2 = ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f;
			_util.R.fontOptions.alignment = (Alignment)0;
			_util.R.fput("Axis", num, y, 0f, 13f, 0f, -1);
			_util.R.fontOptions.alignment = (Alignment)2;
			_util.R.fput("Binding", num2, y, 0f, 13f, 0f, -1);
			y += line;
			DrawAxisRow(AxisAction.MoveY, "Move Up/Down", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.MoveX, "Move Left/Right", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.Steering, "Steering", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.Throttle, "Throttle", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.Brake, "Brake", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.CameraLookX, "Cam Look X", num, num2, y);
			y += line;
			DrawAxisRow(AxisAction.CameraLookY, "Cam Look Y", num, num2, y);
			y += line + sectionGap;
		}

		private void DrawWheelAxesRedirect(Rect p, float center, ref float y, float line, float sectionGap)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			float num2 = ((Rect)(ref p)).y + ((Rect)(ref p)).height / 2f - 18f;
			_util.Label("Wheel Axes need to be set", num, num2);
			_util.Label("in the Wheel menu.", num, num2 + line);
			_ = ((Rect)(ref p)).y;
			_ = ((Rect)(ref p)).height;
			float num3 = num2 + line * 2f + 8f;
			if (_util.FancyButton("Open Wheel Menu", num, num3, 0f))
			{
				WheelInterop.RequestOpenAxisMapping();
				if (CartridgeApps.EnsureListener(_util.M, CartridgeApps.Wheel))
				{
					DesktopAppLauncher.TryOpenProgramListener(_util.M, _util.R, "wheel", "listener_G920Menu");
				}
			}
		}

		private void DrawAxisRow(AxisAction axis, string label, float labelX, float bindRight, float y)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			_util.R.fontOptions.alignment = (Alignment)0;
			_util.R.fput(label, labelX, y, 0f, 13f, 0f, -1);
			BindingInput axisBinding = AxisBindingStore.GetAxisBinding(_scheme, axis);
			string text = ((axisBinding.Kind == BindingKind.None) ? "[none]" : ("[" + BindingStore.GetBindingLabel(axisBinding) + "]"));
			if (axisBinding.Kind != 0 && HasAxisConflictMark(axis, axisBinding))
			{
				text += " !";
			}
			int num = 96;
			int num2 = (int)(bindRight - (float)num);
			int num3 = (int)y;
			if (_util.M.MouseOver(num2, num3, num, 8))
			{
				((ScreenProgram)_util.M).mouseIcon = 128;
				if (((ScreenProgram)_util.M).mouseButton)
				{
					((ScreenProgram)_util.M).mouseIcon = 160;
				}
				if (((ScreenProgram)_util.M).mouseButtonUp)
				{
					_axisCaptureAction = axis;
					_page = Page.AxisCapture;
					_axisCaptureEnterTime = Time.unscaledTime;
					AxisCapture.BeginCaptureSession(_scheme);
					return;
				}
			}
			_util.R.fontOptions.alignment = (Alignment)2;
			_util.R.fput(text, bindRight, y, 0f, 13f, 0f, -1);
		}

		private bool HasAxisConflictMark(AxisAction axis, BindingInput input)
		{
			foreach (AxisAction value in Enum.GetValues(typeof(AxisAction)))
			{
				if (value != axis && (axis != AxisAction.Steering || value != 0) && (axis != 0 || value != AxisAction.Steering))
				{
					BindingInput axisBinding = AxisBindingStore.GetAxisBinding(_scheme, value);
					if (axisBinding.Kind != 0 && axisBinding.Kind == input.Kind && axisBinding.Code == input.Code)
					{
						return true;
					}
				}
			}
			return false;
		}

		private void DrawBindingTable(Rect p, BindAction[] actions, ref float y, float line)
		{
			//IL_004b: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Rect)(ref p)).x + 12f;
			float num2 = ((Rect)(ref p)).x + ((Rect)(ref p)).width - 84f;
			float num3 = ((Rect)(ref p)).x + ((Rect)(ref p)).width - 12f;
			_util.R.fontOptions.alignment = (Alignment)0;
			_util.R.fput("Action", num, y, 0f, 13f, 0f, -1);
			_util.R.fontOptions.alignment = (Alignment)2;
			_util.R.fput("Press", num2, y, 0f, 13f, 0f, -1);
			_util.R.fput("Modif.", num3, y, 0f, 13f, 0f, -1);
			y += line;
			int num4 = 9;
			for (int i = 0; i < actions.Length && i < num4; i++)
			{
				BindAction action = actions[i];
				DrawBindingRow(p, action, num, num2, num3, y);
				y += line;
			}
		}

		private void DrawBindingRow(Rect p, BindAction action, float labelX, float pressRight, float holdRight, float y)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_util.R.fontOptions.alignment = (Alignment)0;
			_util.R.fput(BindingStore.GetActionLabel(action), labelX, y, 0f, 13f, 0f, -1);
			DrawBindingCell(action, BindingLayer.Normal, pressRight, y);
			DrawBindingCell(action, BindingLayer.Modified, holdRight, y);
		}

		private void DrawBindingCell(BindAction action, BindingLayer layer, float rightX, float y)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			if (!IsLayerSupported(action, layer))
			{
				_util.R.fontOptions.alignment = (Alignment)2;
				_util.R.fput("n/a", rightX, y, 0f, 13f, 0f, -1);
				return;
			}
			BindingInput binding = BindingStore.GetBinding(_scheme, layer, action);
			string text = ((binding.Kind == BindingKind.None) ? "[none]" : ("[" + BindingStore.GetBindingLabel(binding) + "]"));
			int num = 72;
			int num2 = (int)(rightX - (float)num);
			int num3 = (int)y;
			if (_util.M.MouseOver(num2, num3, num, 8))
			{
				((ScreenProgram)_util.M).mouseIcon = 128;
				if (((ScreenProgram)_util.M).mouseButton)
				{
					((ScreenProgram)_util.M).mouseIcon = 160;
				}
				if (((ScreenProgram)_util.M).mouseButtonUp)
				{
					_bindingCaptureAction = action;
					_bindingCaptureLayer = layer;
					_bindingDupConfirmActive = false;
					_page = Page.BindingCapture;
					_bindingCaptureEnterTime = Time.unscaledTime;
					_isCapturingModifier = false;
					_bindingCaptureMissingModifier = layer == BindingLayer.Modified && BindingStore.GetModifierBinding(_scheme).Kind == BindingKind.None;
					return;
				}
			}
			_util.R.fontOptions.alignment = (Alignment)2;
			_util.R.fput(text, rightX, y, 0f, 13f, 0f, -1);
		}

		private void DrawBindingCapture(Rect p, float center, ref float y, float line, float sectionGap)
		{
			BindingCaptureHeartbeatTime = Time.unscaledTime;
			_util.Label("Binds", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
			y += line;
			string text = (_isCapturingModifier ? "Modifier" : (BindingStore.GetActionLabel(_bindingCaptureAction) + " (" + LayerLabel(_bindingCaptureLayer) + ")"));
			float num = ((Rect)(ref p)).y + ((Rect)(ref p)).height / 2f - 18f;
			float num2 = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			float num3 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 30f;
			float num4 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f;
			if (!_isCapturingModifier && _bindingCaptureLayer == BindingLayer.Modified && BindingStore.GetModifierBinding(_scheme).Kind == BindingKind.None)
			{
				_bindingCaptureMissingModifier = true;
			}
			bool flag = Time.unscaledTime - _bindingCaptureEnterTime > 0.25f;
			if (_bindingCaptureMissingModifier)
			{
				_util.Label("Please set a", num2, num);
				_util.Label("modifier button first!", num2, num + line);
				if (flag && _util.SimpleButtonRaw("Back", num2, num4))
				{
					_bindingDupConfirmActive = false;
					_isCapturingModifier = false;
					_bindingCaptureMissingModifier = false;
					_page = Page.Bindings;
				}
				return;
			}
			bool flag2 = !_isCapturingModifier && _bindingCaptureLayer == BindingLayer.Modified;
			BindingInput input = (flag2 ? BindingStore.GetModifierBinding(_scheme) : default(BindingInput));
			bool flag3 = !flag2 || BindingEvaluator.IsDown(input);
			if (flag2 && !flag3)
			{
				_util.Label("Hold modifier to bind:", num2, num);
				_util.Label(text, num2, num + line);
				_util.Label("Then press button.", num2, num + line * 2f);
			}
			else
			{
				_util.Label("Press a button for:", num2, num);
				_util.Label(text, num2, num + line);
			}
			if (_bindingDupConfirmActive)
			{
				bool flag4 = _bindingDupConflicts != null && _bindingDupConflicts.Count > 0;
				if (flag4)
				{
					_util.Label("Also used by:", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num + line * 4f);
					List<string> dupConflictsTextLines = GetDupConflictsTextLines(_bindingDupConflicts, 28);
					float num5 = num + line * 5f;
					if (dupConflictsTextLines != null)
					{
						for (int i = 0; i < dupConflictsTextLines.Count; i++)
						{
							_util.Label(dupConflictsTextLines[i], ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num5 + line * (float)i);
						}
						num5 += line * (float)Mathf.Max(1, dupConflictsTextLines.Count);
					}
				}
				if (!string.IsNullOrWhiteSpace(_bindingDupAxisConflict))
				{
					float num6 = num + line * 6f;
					if (flag4)
					{
						num6 = num + line * (5f + (float)Mathf.Max(1, GetDupConflictsTextLines(_bindingDupConflicts, 28)?.Count ?? 1));
					}
					_util.Label(_bindingDupAxisConflict, ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num6);
				}
				if (flag4)
				{
					_util.Label("Enter=Keep  Esc=Try", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num + line * 7f);
				}
				if (_scheme == BindingScheme.Keyboard)
				{
					Keyboard current = Keyboard.current;
					if (current != null)
					{
						if (current.enterKey != null && ((ButtonControl)current.enterKey).wasPressedThisFrame)
						{
							ApplyPendingBinding(replaceDuplicates: false);
							return;
						}
						if (current.escapeKey != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame)
						{
							_bindingDupConfirmActive = false;
							_bindingDupAxisConflict = null;
							_bindingDupConflicts = null;
							return;
						}
					}
				}
				float num7 = num3 - 12f;
				float num8 = num3;
				float num9 = num4;
				if (flag && _util.SimpleButtonRaw("Keep Both", num2, num7))
				{
					ApplyPendingBinding(replaceDuplicates: false);
				}
				else if (flag && _util.SimpleButtonRaw("Replace", num2, num8))
				{
					ApplyPendingBinding(replaceDuplicates: true);
				}
				else if (flag && _util.SimpleButtonRaw("Try Another", num2, num9))
				{
					_bindingDupConfirmActive = false;
					_bindingDupAxisConflict = null;
					_bindingDupConflicts = null;
				}
				return;
			}
			if (!_bindingDupConfirmActive)
			{
				if (flag && _util.SimpleButtonRaw("Clear", num2, num3))
				{
					if (_isCapturingModifier)
					{
						BindingStore.SetModifierBinding(_scheme, new BindingInput
						{
							Kind = BindingKind.None,
							Code = 0
						});
					}
					else
					{
						BindingStore.SetBinding(_scheme, _bindingCaptureLayer, _bindingCaptureAction, new BindingInput
						{
							Kind = BindingKind.None,
							Code = 0
						});
					}
					_bindingDupConfirmActive = false;
					_isCapturingModifier = false;
					_bindingCaptureMissingModifier = false;
					_page = Page.Bindings;
					return;
				}
				if (flag && _util.SimpleButtonRaw("Cancel", num2, num4))
				{
					_bindingDupConfirmActive = false;
					_isCapturingModifier = false;
					_bindingCaptureMissingModifier = false;
					_page = Page.Bindings;
					return;
				}
			}
			if ((flag2 && !flag3) || (flag && (Object)(object)_util.M != (Object)null && ((ScreenProgram)_util.M).mouseButton && (_util.M.MouseOver((int)num2 - 32, (int)num3, 64, 8) || _util.M.MouseOver((int)num2 - 32, (int)num4, 64, 8))) || !InputCapture.TryCaptureNextBinding(_scheme, _bindingCaptureAction, _bindingCaptureLayer, out var input2) || (flag2 && input2.Kind == input.Kind && input2.Code == input.Code))
			{
				return;
			}
			if (_isCapturingModifier)
			{
				BindingStore.SetModifierBinding(_scheme, input2);
				_bindingDupConfirmActive = false;
				_isCapturingModifier = false;
				_bindingCaptureMissingModifier = false;
				_page = Page.Bindings;
				return;
			}
			BindingLayer bindingCaptureLayer = _bindingCaptureLayer;
			string axisConflictForButton = GetAxisConflictForButton(_bindingCaptureAction);
			if (TryFindDuplicateBindings(input2, _bindingCaptureAction, bindingCaptureLayer, out var conflicts) || !string.IsNullOrWhiteSpace(axisConflictForButton))
			{
				_bindingDupConfirmActive = true;
				_bindingDupPendingCaptured = input2;
				_bindingDupPendingLayer = bindingCaptureLayer;
				_bindingDupConflicts = conflicts ?? new List<BindingConflict>();
				_bindingDupAxisConflict = axisConflictForButton;
			}
			else
			{
				ApplyBindingNow(input2, bindingCaptureLayer);
				_bindingDupConfirmActive = false;
				_bindingDupAxisConflict = null;
				_isCapturingModifier = false;
				_page = Page.Bindings;
			}
		}

		private void DrawAxisCapture(Rect p, float center, ref float y, float line, float sectionGap)
		{
			BindingCaptureHeartbeatTime = Time.unscaledTime;
			_util.Label("Binds", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, y);
			y += line;
			float num = ((Rect)(ref p)).y + ((Rect)(ref p)).height / 2f - 18f;
			_util.Label("Move an axis for:", ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num);
			_util.Label(_axisCaptureAction.ToString(), ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f, num + line);
			float num2 = ((Rect)(ref p)).x + ((Rect)(ref p)).width / 2f;
			float num3 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 30f;
			float num4 = ((Rect)(ref p)).y + ((Rect)(ref p)).height - 18f;
			bool flag = Time.unscaledTime - _axisCaptureEnterTime > 0.25f;
			BindingInput input;
			BindingInput input2;
			if (flag && _util.SimpleButtonRaw("Clear", num2, num3))
			{
				AxisBindingStore.ClearAxisBinding(_scheme, _axisCaptureAction);
				_page = Page.Bindings;
			}
			else if (flag && _util.SimpleButtonRaw("Cancel", num2, num4))
			{
				_page = Page.Bindings;
			}
			else if (flag && AxisCapture.TryCaptureNextAxis(_scheme, out input))
			{
				AxisBindingStore.SetAxisBinding(_scheme, _axisCaptureAction, input);
				_page = Page.Bindings;
			}
			else if (flag && InputCapture.TryCaptureNextBinding(_scheme, BindAction.InteractOk, BindingLayer.Normal, out input2))
			{
				if (_scheme == BindingScheme.Wheel && input2.Kind == BindingKind.Pov)
				{
					int num5 = Mathf.Clamp(input2.Code, 0, 3);
					BindingInput bindingInput = default(BindingInput);
					bindingInput.Kind = BindingKind.WheelDpadAxis;
					bindingInput.Code = ((num5 != 1 && num5 != 3) ? 1 : 0);
					input2 = bindingInput;
				}
				AxisBindingStore.SetAxisBinding(_scheme, _axisCaptureAction, input2);
				_page = Page.Bindings;
			}
		}

		private void ApplyPendingBinding(bool replaceDuplicates)
		{
			if (!_bindingDupConfirmActive)
			{
				return;
			}
			if (replaceDuplicates && _bindingDupConflicts != null)
			{
				foreach (BindingConflict bindingDupConflict in _bindingDupConflicts)
				{
					BindingStore.SetBinding(_scheme, bindingDupConflict.Layer, bindingDupConflict.Action, new BindingInput
					{
						Kind = BindingKind.None,
						Code = 0
					});
				}
			}
			if (replaceDuplicates)
			{
				ClearAxisConflictForButton(_bindingCaptureAction);
			}
			ApplyBindingNow(_bindingDupPendingCaptured, _bindingDupPendingLayer);
			_bindingDupConfirmActive = false;
			_bindingDupAxisConflict = null;
			_isCapturingModifier = false;
			_page = Page.Bindings;
		}

		private void ClearAxisConflictForButton(BindAction action)
		{
			switch (action)
			{
			case BindAction.Drive:
				AxisBindingStore.ClearAxisBinding(_scheme, AxisAction.Throttle);
				break;
			case BindAction.Brake:
				AxisBindingStore.ClearAxisBinding(_scheme, AxisAction.Brake);
				break;
			case BindAction.SteerLeft:
			case BindAction.SteerRight:
				AxisBindingStore.ClearAxisBinding(_scheme, AxisAction.Steering);
				break;
			}
		}

		private string GetAxisConflictForButton(BindAction action)
		{
			if (action == BindAction.Drive && HasAxis(AxisAction.Throttle))
			{
				return "Axis: Throttle";
			}
			if (action == BindAction.Brake && HasAxis(AxisAction.Brake))
			{
				return "Axis: Brake";
			}
			if ((action == BindAction.SteerLeft || action == BindAction.SteerRight) && HasAxis(AxisAction.Steering))
			{
				return "Axis: Steering";
			}
			return null;
			bool HasAxis(AxisAction a)
			{
				return AxisBindingStore.GetAxisBinding(_scheme, a).Kind != BindingKind.None;
			}
		}

		private void ApplyBindingNow(BindingInput captured, BindingLayer targetLayer)
		{
			BindingStore.SetBinding(_scheme, targetLayer, _bindingCaptureAction, captured);
		}

		private static bool SameBinding(BindingInput a, BindingInput b)
		{
			if (a.Kind == b.Kind)
			{
				return a.Code == b.Code;
			}
			return false;
		}

		private bool TryFindDuplicateBindings(BindingInput captured, BindAction targetAction, BindingLayer targetLayer, out List<BindingConflict> conflicts)
		{
			conflicts = null;
			BindAction[] allBindableActions = AllBindableActions;
			foreach (BindAction bindAction in allBindableActions)
			{
				if (IsDuplicateAllowed(bindAction, targetAction) || bindAction == targetAction)
				{
					continue;
				}
				BindingInput binding = BindingStore.GetBinding(_scheme, targetLayer, bindAction);
				if (binding.Kind != 0 && SameBinding(binding, captured))
				{
					if (conflicts == null)
					{
						conflicts = new List<BindingConflict>();
					}
					conflicts.Add(new BindingConflict
					{
						Layer = targetLayer,
						Action = bindAction
					});
				}
			}
			if (conflicts != null)
			{
				return conflicts.Count > 0;
			}
			return false;
		}

		private static bool IsDuplicateAllowed(BindAction a, BindAction b)
		{
			if (a == b)
			{
				return true;
			}
			if ((a == BindAction.Back && b == BindAction.Brake) || (a == BindAction.Brake && b == BindAction.Back))
			{
				return true;
			}
			if ((a == BindAction.MoveUp && b == BindAction.Drive) || (a == BindAction.Drive && b == BindAction.MoveUp))
			{
				return true;
			}
			if ((a == BindAction.MoveLeft && b == BindAction.SteerLeft) || (a == BindAction.SteerLeft && b == BindAction.MoveLeft))
			{
				return true;
			}
			if ((a == BindAction.MoveRight && b == BindAction.SteerRight) || (a == BindAction.SteerRight && b == BindAction.MoveRight))
			{
				return true;
			}
			return false;
		}

		private static List<string> GetDupConflictsTextLines(List<BindingConflict> conflicts, int maxCharsPerLine)
		{
			if (conflicts == null || conflicts.Count == 0)
			{
				return null;
			}
			List<string> list = new List<string>();
			for (int i = 0; i < conflicts.Count; i++)
			{
				string actionLabel = BindingStore.GetActionLabel(conflicts[i].Action);
				if (!string.IsNullOrWhiteSpace(actionLabel) && !list.Contains(actionLabel))
				{
					list.Add(actionLabel);
				}
			}
			return WrapCommaList(list, maxCharsPerLine);
		}

		private static List<string> WrapCommaList(List<string> items, int maxCharsPerLine)
		{
			if (items == null || items.Count == 0)
			{
				return null;
			}
			maxCharsPerLine = Mathf.Max(8, maxCharsPerLine);
			List<string> list = new List<string>();
			string text = string.Empty;
			for (int i = 0; i < items.Count; i++)
			{
				string text2 = TrimItem(items[i]);
				if (string.IsNullOrEmpty(text2))
				{
					continue;
				}
				if (string.IsNullOrEmpty(text))
				{
					text = text2;
					continue;
				}
				string text3 = text + ", " + text2;
				if (text3.Length > maxCharsPerLine)
				{
					list.Add(text);
					text = text2;
				}
				else
				{
					text = text3;
				}
			}
			if (!string.IsNullOrEmpty(text))
			{
				list.Add(text);
			}
			return list;
			string TrimItem(string s)
			{
				s = (s ?? string.Empty).Trim();
				if (s.Length <= maxCharsPerLine)
				{
					return s;
				}
				if (maxCharsPerLine <= 3)
				{
					return s.Substring(0, maxCharsPerLine);
				}
				return s.Substring(0, maxCharsPerLine - 3) + "...";
			}
		}

		private static string LayerLabel(BindingLayer layer)
		{
			if (layer != 0)
			{
				return "Modif.";
			}
			return "Press";
		}

		private static bool IsLayerSupported(BindAction action, BindingLayer layer)
		{
			return true;
		}

		private static int NextPageIndex(int index, int count)
		{
			if (count <= 0)
			{
				return 0;
			}
			int num = index + 1;
			if (num >= count)
			{
				num = 0;
			}
			return num;
		}

		private static int PrevPageIndex(int index, int count)
		{
			if (count <= 0)
			{
				return 0;
			}
			int num = index - 1;
			if (num < 0)
			{
				num = count - 1;
			}
			return num;
		}
	}
	public static class BindingEvaluator
	{
		private const float AxisPressThreshold = 0.35f;

		private static int _axisCacheFrame = -1;

		private static Gamepad _axisCacheGamepad;

		private static float _lt;

		private static float _rt;

		private static float _lsx;

		private static float _lsy;

		private static float _rsx;

		private static float _rsy;

		private static float _plt;

		private static float _prt;

		private static float _plsx;

		private static float _plsy;

		private static float _prsx;

		private static float _prsy;

		public static void BeginFrame()
		{
			int frameCount = Time.frameCount;
			Gamepad current = Gamepad.current;
			if (_axisCacheFrame != frameCount || _axisCacheGamepad != current)
			{
				_plt = _lt;
				_prt = _rt;
				_plsx = _lsx;
				_plsy = _lsy;
				_prsx = _rsx;
				_prsy = _rsy;
				_axisCacheGamepad = current;
				if (current == null)
				{
					_lt = (_rt = (_lsx = (_lsy = (_rsx = (_rsy = 0f)))));
					_axisCacheFrame = frameCount;
					return;
				}
				_lt = SafeReadAxis((InputControl<float>)(object)current.leftTrigger);
				_rt = SafeReadAxis((InputControl<float>)(object)current.rightTrigger);
				_lsx = SafeReadAxis((InputControl<float>)(object)((Vector2Control)current.leftStick).x);
				_lsy = SafeReadAxis((InputControl<float>)(object)((Vector2Control)current.leftStick).y);
				_rsx = SafeReadAxis((InputControl<float>)(object)((Vector2Control)current.rightStick).x);
				_rsy = SafeReadAxis((InputControl<float>)(object)((Vector2Control)current.rightStick).y);
				_axisCacheFrame = frameCount;
			}
		}

		private static float SafeReadAxis(InputControl<float> c)
		{
			if (c == null)
			{
				return 0f;
			}
			try
			{
				return c.ReadValue();
			}
			catch
			{
				return 0f;
			}
		}

		public static float GetAxisValue(BindingInput input)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			if (input.Kind == BindingKind.GamepadDpadAxis)
			{
				Gamepad current = Gamepad.current;
				if (current == null)
				{
					return 0f;
				}
				Vector2 val = ((InputControl<Vector2>)(object)current.dpad).ReadValue();
				if (input.Code != 0)
				{
					return val.y;
				}
				return val.x;
			}
			if (input.Kind == BindingKind.WheelDpadAxis)
			{
				if (!WheelInterop.TryGetPov8Vector(out var v))
				{
					return 0f;
				}
				Vector2 val2 = -v;
				if (input.Code != 0)
				{
					return val2.y;
				}
				return val2.x;
			}
			if (input.Kind == BindingKind.WheelAxis)
			{
				return WheelInterop.GetWheelRawAxisValue(input.Code);
			}
			if (input.Kind != BindingKind.GamepadAxis)
			{
				return 0f;
			}
			BeginFrame();
			return input.Code switch
			{
				0 => _lt, 
				1 => _rt, 
				2 => _lsx, 
				3 => _lsy, 
				4 => _rsx, 
				5 => _rsy, 
				_ => 0f, 
			};
		}

		private static float GetPrevAxisValue(BindingInput input)
		{
			if (input.Kind != BindingKind.GamepadAxis)
			{
				return 0f;
			}
			BeginFrame();
			return input.Code switch
			{
				0 => _plt, 
				1 => _prt, 
				2 => _plsx, 
				3 => _plsy, 
				4 => _prsx, 
				5 => _prsy, 
				_ => 0f, 
			};
		}

		internal static float GetPrevAxisValueForCapture(BindingInput input)
		{
			return GetPrevAxisValue(input);
		}

		public static bool IsDown(BindingInput input)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (input.Kind == BindingKind.None)
			{
				return false;
			}
			if (input.Kind == BindingKind.Button || input.Kind == BindingKind.Pov)
			{
				return WheelInterop.IsBindingDownForCurrentFrame(input);
			}
			if (input.Kind == BindingKind.Key)
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return false;
				}
				Key val = (Key)Mathf.Max(0, input.Code);
				if (current[val] != null)
				{
					return ((ButtonControl)current[val]).isPressed;
				}
				return false;
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				Mouse current2 = Mouse.current;
				if (current2 == null)
				{
					return false;
				}
				return input.Code switch
				{
					0 => current2.leftButton.isPressed, 
					1 => current2.rightButton.isPressed, 
					2 => current2.middleButton.isPressed, 
					_ => false, 
				};
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				if (TryGetGamepadButtonControl(Gamepad.current, input.Code, out var control))
				{
					return control.isPressed;
				}
				return false;
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				return GetAxisValue(input) > 0.35f;
			}
			if (input.Kind == BindingKind.WheelAxis)
			{
				return Mathf.Abs(GetAxisValue(input)) > 0.35f;
			}
			if (input.Kind == BindingKind.WheelDpadAxis)
			{
				return Mathf.Abs(GetAxisValue(input)) > 0.35f;
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				Gamepad current3 = Gamepad.current;
				if (current3 == null)
				{
					return false;
				}
				return Mathf.Clamp(input.Code, 0, 3) switch
				{
					0 => current3.dpad.up.isPressed, 
					1 => current3.dpad.right.isPressed, 
					2 => current3.dpad.down.isPressed, 
					_ => current3.dpad.left.isPressed, 
				};
			}
			return false;
		}

		public static bool WasPressedThisFrame(BindingInput input)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (input.Kind == BindingKind.None)
			{
				return false;
			}
			if (input.Kind == BindingKind.Button || input.Kind == BindingKind.Pov)
			{
				return WheelInterop.IsBindingPressedThisFrameForCurrentFrame(input);
			}
			if (input.Kind == BindingKind.Key)
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return false;
				}
				Key val = (Key)Mathf.Max(0, input.Code);
				if (current[val] != null)
				{
					return ((ButtonControl)current[val]).wasPressedThisFrame;
				}
				return false;
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				Mouse current2 = Mouse.current;
				if (current2 == null)
				{
					return false;
				}
				return input.Code switch
				{
					0 => current2.leftButton.wasPressedThisFrame, 
					1 => current2.rightButton.wasPressedThisFrame, 
					2 => current2.middleButton.wasPressedThisFrame, 
					_ => false, 
				};
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				if (TryGetGamepadButtonControl(Gamepad.current, input.Code, out var control))
				{
					return control.wasPressedThisFrame;
				}
				return false;
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				float prevAxisValue = GetPrevAxisValue(input);
				float axisValue = GetAxisValue(input);
				if (prevAxisValue <= 0.35f)
				{
					return axisValue > 0.35f;
				}
				return false;
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				Gamepad current3 = Gamepad.current;
				if (current3 == null)
				{
					return false;
				}
				return Mathf.Clamp(input.Code, 0, 3) switch
				{
					0 => current3.dpad.up.wasPressedThisFrame, 
					1 => current3.dpad.right.wasPressedThisFrame, 
					2 => current3.dpad.down.wasPressedThisFrame, 
					_ => current3.dpad.left.wasPressedThisFrame, 
				};
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				float prevAxisValue2 = GetPrevAxisValue(input);
				float axisValue2 = GetAxisValue(input);
				if (prevAxisValue2 <= 0.35f)
				{
					return axisValue2 > 0.35f;
				}
				return false;
			}
			return false;
		}

		public static bool WasReleasedThisFrame(BindingInput input)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (input.Kind == BindingKind.None)
			{
				return false;
			}
			if (input.Kind == BindingKind.Button || input.Kind == BindingKind.Pov)
			{
				return WheelInterop.IsBindingReleasedThisFrameForCurrentFrame(input);
			}
			if (input.Kind == BindingKind.Key)
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return false;
				}
				Key val = (Key)Mathf.Max(0, input.Code);
				if (current[val] != null)
				{
					return ((ButtonControl)current[val]).wasReleasedThisFrame;
				}
				return false;
			}
			if (input.Kind == BindingKind.MouseButton)
			{
				Mouse current2 = Mouse.current;
				if (current2 == null)
				{
					return false;
				}
				return input.Code switch
				{
					0 => current2.leftButton.wasReleasedThisFrame, 
					1 => current2.rightButton.wasReleasedThisFrame, 
					2 => current2.middleButton.wasReleasedThisFrame, 
					_ => false, 
				};
			}
			if (input.Kind == BindingKind.GamepadButton)
			{
				if (TryGetGamepadButtonControl(Gamepad.current, input.Code, out var control))
				{
					return control.wasReleasedThisFrame;
				}
				return false;
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				float prevAxisValue = GetPrevAxisValue(input);
				float axisValue = GetAxisValue(input);
				if (prevAxisValue > 0.35f)
				{
					return axisValue <= 0.35f;
				}
				return false;
			}
			if (input.Kind == BindingKind.GamepadDpad)
			{
				Gamepad current3 = Gamepad.current;
				if (current3 == null)
				{
					return false;
				}
				return Mathf.Clamp(input.Code, 0, 3) switch
				{
					0 => current3.dpad.up.wasReleasedThisFrame, 
					1 => current3.dpad.right.wasReleasedThisFrame, 
					2 => current3.dpad.down.wasReleasedThisFrame, 
					_ => current3.dpad.left.wasReleasedThisFrame, 
				};
			}
			if (input.Kind == BindingKind.GamepadAxis)
			{
				float prevAxisValue2 = GetPrevAxisValue(input);
				float axisValue2 = GetAxisValue(input);
				if (prevAxisValue2 > 0.35f)
				{
					return axisValue2 <= 0.35f;
				}
				return false;
			}
			return false;
		}

		internal static bool TryGetGamepadButtonControl(Gamepad g, int code, out ButtonControl control)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected I4, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			control = null;
			if (g == null)
			{
				return false;
			}
			GamepadButton val = (GamepadButton)code;
			switch (val - 4)
			{
			default:
				if ((int)val != 32)
				{
					if ((int)val == 33)
					{
						control = g.rightTrigger;
						return true;
					}
					return false;
				}
				control = g.leftTrigger;
				return true;
			case 2:
				control = g.buttonSouth;
				return true;
			case 0:
				control = g.buttonNorth;
				return true;
			case 3:
				control = g.buttonWest;
				return true;
			case 1:
				control = g.buttonEast;
				return true;
			case 8:
				control = g.startButton;
				return true;
			case 9:
				control = g.selectButton;
				return true;
			case 6:
				control = g.leftShoulder;
				return true;
			case 7:
				control = g.rightShoulder;
				return true;
			case 4:
				control = g.leftStickButton;
				return true;
			case 5:
				control = g.rightStickButton;
				return true;
			}
		}
	}
	internal static class DefaultPreset
	{
		private const string PrefKeyPresetInstalled = "SebBinds_PresetInstalled";

		internal static bool IsInstalled()
		{
			return PlayerPrefs.GetInt("SebBinds_PresetInstalled", 0) != 0;
		}

		internal static void MarkInstalled()
		{
			PlayerPrefs.SetInt("SebBinds_PresetInstalled", 1);
			PlayerPrefs.Save();
		}

		internal static bool TryInstallFromInputManager(sInputManager input)
		{
			return TryInstallFromInputManager(input, null, forceReinstall: false);
		}

		internal static bool TryInstallFromInputManager(sInputManager input, bool? forceOnController, bool forceReinstall)
		{
			if (!forceReinstall && IsInstalled())
			{
				return false;
			}
			if ((Object)(object)input == (Object)null)
			{
				return false;
			}
			PlayerInput component = ((Component)input).GetComponent<PlayerInput>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.actions == (Object)null)
			{
				return false;
			}
			bool flag;
			if (forceOnController.HasValue)
			{
				flag = forceOnController.Value;
			}
			else
			{
				flag = false;
				try
				{
					flag = input.OnController();
				}
				catch
				{
				}
			}
			bool flag2 = false;
			flag2 |= SetFromActionIfUnset(component, flag, "Click", BindAction.InteractOk);
			flag2 |= SetFromActionIfUnset(component, flag, "Break", BindAction.Back);
			flag2 |= SetFromActionIfUnset(component, flag, "Pause", BindAction.Pause);
			flag2 |= SetFromActionIfUnset(component, flag, "Inventory", BindAction.MapItems);
			flag2 |= SetFromActionIfUnset(component, flag, "Map", BindAction.Jobs);
			flag2 |= SetFromActionIfUnset(component, flag, "ChangeCamera", BindAction.Camera);
			flag2 |= SetFromActionIfUnset(component, flag, "Reset", BindAction.ResetVehicle);
			flag2 |= SetFromActionIfUnset(component, flag, "Headlights", BindAction.Headlights);
			flag2 |= SetFromActionIfUnset(component, flag, "Horn", BindAction.Horn);
			if (TrySetRadioFromAction(component, flag))
			{
				flag2 = true;
			}
			else if (flag)
			{
				flag2 |= SetIfUnset(BindAction.RadioScanToggle, new BindingInput
				{
					Kind = BindingKind.GamepadDpad,
					Code = 0
				});
				flag2 |= SetIfUnset(BindAction.RadioScanRight, new BindingInput
				{
					Kind = BindingKind.GamepadDpad,
					Code = 1
				});
				flag2 |= SetIfUnset(BindAction.RadioPower, new BindingInput
				{
					Kind = BindingKind.GamepadDpad,
					Code = 2
				});
				flag2 |= SetIfUnset(BindAction.RadioScanLeft, new BindingInput
				{
					Kind = BindingKind.GamepadDpad,
					Code = 3
				});
			}
			if (BindingStore.GetModifierBinding().Kind == BindingKind.None)
			{
				BindingInput modifierBinding = default(BindingInput);
				modifierBinding.Kind = BindingKind.None;
				modifierBinding.Code = 0;
				BindingStore.SetModifierBinding(modifierBinding);
			}
			if (flag2)
			{
				MarkInstalled();
				return true;
			}
			return false;
		}

		private static bool IsUnset(BindAction action)
		{
			BindingInput binding = BindingStore.GetBinding(BindingLayer.Normal, action);
			BindingInput binding2 = BindingStore.GetBinding(BindingLayer.Modified, action);
			if (binding.Kind == BindingKind.None)
			{
				return binding2.Kind == BindingKind.None;
			}
			return false;
		}

		private static bool SetIfUnset(BindAction target, BindingInput input)
		{
			if (!IsUnset(target))
			{
				return false;
			}
			BindingStore.SetBinding(BindingLayer.Normal, target, input);
			return true;
		}

		private static bool SetFromActionIfUnset(PlayerInput pi, bool onController, string actionName, BindAction target)
		{
			if (!IsUnset(target))
			{
				return false;
			}
			if ((Object)(object)pi == (Object)null || (Object)(object)pi.actions == (Object)null)
			{
				return false;
			}
			InputAction val = pi.actions[actionName];
			if (val == null)
			{
				return false;
			}
			if (TryPickBindingInput(val, onController, out var input))
			{
				BindingStore.SetBinding(BindingLayer.Normal, target, input);
				return true;
			}
			return false;
		}

		private static bool TrySetRadioFromAction(PlayerInput pi, bool onController)
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			InputAction val = pi.actions["Radio"];
			if (val == null)
			{
				return false;
			}
			bool flag = false;
			for (int i = 0; i < val.bindings.Count; i++)
			{
				InputBinding val2 = val.bindings[i];
				if (!((InputBinding)(ref val2)).isPartOfComposite)
				{
					continue;
				}
				string effectivePath = ((InputBinding)(ref val2)).effectivePath;
				if (!string.IsNullOrWhiteSpace(effectivePath) && (!onController || effectivePath.StartsWith("<Gamepad>/", StringComparison.OrdinalIgnoreCase)) && (onController || effectivePath.StartsWith("<Keyboard>/", StringComparison.OrdinalIgnoreCase) || effectivePath.StartsWith("<Gamepad>/", StringComparison.OrdinalIgnoreCase)) && TryParsePathToInput(effectivePath, out var input))
				{
					switch ((((InputBinding)(ref val2)).name ?? string.Empty).ToLowerInvariant())
					{
					case "up":
						flag |= SetIfUnset(BindAction.RadioScanToggle, input);
						flag = true;
						break;
					case "right":
						flag |= SetIfUnset(BindAction.RadioScanRight, input);
						flag = true;
						break;
					case "down":
						flag |= SetIfUnset(BindAction.RadioPower, input);
						flag = true;
						break;
					case "left":
						flag |= SetIfUnset(BindAction.RadioScanLeft, input);
						flag = true;
						break;
					}
				}
			}
			return flag;
		}

		private static bool TryPickBindingInput(InputAction action, bool onController, out BindingInput input)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < action.bindings.Count; i++)
			{
				InputBinding val = action.bindings[i];
				if (((InputBinding)(ref val)).isComposite || ((InputBinding)(ref val)).isPartOfComposite)
				{
					continue;
				}
				string effectivePath = ((InputBinding)(ref val)).effectivePath;
				if (string.IsNullOrWhiteSpace(effectivePath))
				{
					continue;
				}
				if (onController)
				{
					if (!effectivePath.StartsWith("<Gamepad>/", StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
				}
				else if (!effectivePath.StartsWith("<Keyboard>/", StringComparison.OrdinalIgnoreCase) && !effectivePath.StartsWith("<Mouse>/", StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				if (TryParsePathToInput(effectivePath, out input))
				{
					return true;
				}
			}
			for (int j = 0; j < action.bindings.Count; j++)
			{
				InputBinding val2 = action.bindings[j];
				if (!((InputBinding)(ref val2)).isComposite && !((InputBinding)(ref val2)).isPartOfComposite)
				{
					string effectivePath2 = ((InputBinding)(ref val2)).effectivePath;
					if (!string.IsNullOrWhiteSpace(effectivePath2) && TryParsePathToInput(effectivePath2, out input))
					{
						return true;
					}
				}
			}
			input = default(BindingInput);
			return false;
		}

		private static bool TryParsePathToInput(string path, out BindingInput input)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected I4, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected I4, but got Unknown
			input = default(BindingInput);
			if (string.IsNullOrWhiteSpace(path))
			{
				return false;
			}
			string text = path.Trim();
			if (text.StartsWith("<Keyboard>/", StringComparison.OrdinalIgnoreCase))
			{
				if (TryParseKeyName(text.Substring("<Keyboard>/".Length), out var key))
				{
					input = new BindingInput
					{
						Kind = BindingKind.Key,
						Code = (int)key
					};
					return true;
				}
				return false;
			}
			if (text.StartsWith("<Mouse>/", StringComparison.OrdinalIgnoreCase))
			{
				switch (text.Substring("<Mouse>/".Length).ToLowerInvariant())
				{
				case "leftbutton":
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 0
					};
					return true;
				case "rightbutton":
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 1
					};
					return true;
				case "middlebutton":
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 2
					};
					return true;
				default:
					return false;
				}
			}
			if (LooksLikeGamepadPath(text) && text.IndexOf("/dpad/", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				int code = text.Substring(text.IndexOf("/dpad/", StringComparison.OrdinalIgnoreCase) + "/dpad/".Length).ToLowerInvariant() switch
				{
					"up" => 0, 
					"right" => 1, 
					"down" => 2, 
					_ => 3, 
				};
				input = new BindingInput
				{
					Kind = BindingKind.GamepadDpad,
					Code = code
				};
				return true;
			}
			if (LooksLikeGamepadPath(text))
			{
				int num = text.IndexOf(">/", StringComparison.Ordinal);
				if (num < 0)
				{
					return false;
				}
				if (TryParseGamepadButtonName(text.Substring(num + 2), out var button))
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadButton,
						Code = (int)button
					};
					return true;
				}
				return false;
			}
			return false;
		}

		private static bool TryParseGamepadButtonName(string name, out GamepadButton button)
		{
			button = (GamepadButton)0;
			if (string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			return name.Trim().ToLowerInvariant() switch
			{
				"buttonsouth" => Set<GamepadButton>((GamepadButton)6, out button), 
				"buttoneast" => Set<GamepadButton>((GamepadButton)5, out button), 
				"buttonwest" => Set<GamepadButton>((GamepadButton)7, out button), 
				"buttonnorth" => Set<GamepadButton>((GamepadButton)4, out button), 
				"start" => Set<GamepadButton>((GamepadButton)12, out button), 
				"select" => Set<GamepadButton>((GamepadButton)13, out button), 
				"leftshoulder" => Set<GamepadButton>((GamepadButton)10, out button), 
				"rightshoulder" => Set<GamepadButton>((GamepadButton)11, out button), 
				"lefttrigger" => Set<GamepadButton>((GamepadButton)32, out button), 
				"righttrigger" => Set<GamepadButton>((GamepadButton)33, out button), 
				"leftstickpress" => Set<GamepadButton>((GamepadButton)8, out button), 
				"rightstickpress" => Set<GamepadButton>((GamepadButton)9, out button), 
				_ => false, 
			};
		}

		private static bool LooksLikeGamepadPath(string path)
		{
			if (string.IsNullOrWhiteSpace(path))
			{
				return false;
			}
			int num = path.IndexOf('<');
			int num2 = path.IndexOf('>');
			if (num < 0 || num2 < 0 || num2 <= num)
			{
				return false;
			}
			string text = path.Substring(num + 1, num2 - num - 1);
			if (text.IndexOf("gamepad", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (string.Equals(text, "XInputController", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (text.IndexOf("controller", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			return false;
		}

		private static bool TryParseKeyName(string name, out Key key)
		{
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			key = (Key)0;
			if (string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			string text = name.Trim();
			string text2 = text.ToLowerInvariant();
			switch (text2)
			{
			case "space":
				return Set<Key>((Key)1, out key);
			case "escape":
			case "esc":
				return Set<Key>((Key)60, out key);
			case "enter":
			case "return":
				return Set<Key>((Key)2, out key);
			case "tab":
				return Set<Key>((Key)3, out key);
			case "backspace":
				return Set<Key>((Key)65, out key);
			case "leftshift":
				return Set<Key>((Key)51, out key);
			case "rightshift":
				return Set<Key>((Key)52, out key);
			case "leftctrl":
			case "leftcontrol":
				return Set<Key>((Key)55, out key);
			case "rightctrl":
			case "rightcontrol":
				return Set<Key>((Key)56, out key);
			case "leftalt":
				return Set<Key>((Key)53, out key);
			case "rightalt":
				return Set<Key>((Key)54, out key);
			default:
			{
				if (text2.Length == 1 && text2[0] >= 'a' && text2[0] <= 'z' && Enum.TryParse<Key>(text2.ToUpperInvariant(), out Key result))
				{
					return Set<Key>(result, out key);
				}
				if (text2.Length == 1 && text2[0] >= '0' && text2[0] <= '9' && Enum.TryParse<Key>("Digit" + text2, out Key result2))
				{
					return Set<Key>(result2, out key);
				}
				switch (text2)
				{
				case "uparrow":
					return Set<Key>((Key)63, out key);
				case "downarrow":
					return Set<Key>((Key)64, out key);
				case "leftarrow":
					return Set<Key>((Key)61, out key);
				case "rightarrow":
					return Set<Key>((Key)62, out key);
				default:
				{
					if (text2.StartsWith("f", StringComparison.Ordinal) && text2.Length <= 3 && Enum.TryParse<Key>(text2.ToUpperInvariant(), out Key result3))
					{
						return Set<Key>(result3, out key);
					}
					if (Enum.TryParse<Key>(text, ignoreCase: true, out Key result4))
					{
						return Set<Key>(result4, out key);
					}
					return false;
				}
				}
			}
			}
		}

		private static bool Set<T>(T v, out T output)
		{
			output = v;
			return true;
		}
	}
	internal static class InputCapture
	{
		internal static bool TryCaptureNextBinding(BindingScheme scheme, BindAction forAction, BindingLayer forLayer, out BindingInput input)
		{
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected I4, but got Unknown
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Expected I4, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected I4, but got Unknown
			if (scheme == BindingScheme.Wheel)
			{
				return WheelInterop.TryCaptureNextBinding(out input);
			}
			Gamepad current = Gamepad.current;
			if (scheme == BindingScheme.Controller && current != null)
			{
				BindingEvaluator.BeginFrame();
				if (current.dpad.up.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadDpad,
						Code = 0
					};
					return true;
				}
				if (current.dpad.right.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadDpad,
						Code = 1
					};
					return true;
				}
				if (current.dpad.down.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadDpad,
						Code = 2
					};
					return true;
				}
				if (current.dpad.left.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.GamepadDpad,
						Code = 3
					};
					return true;
				}
				GamepadButton[] array = new GamepadButton[12];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				GamepadButton[] array2 = (GamepadButton[])(object)array;
				foreach (GamepadButton val in array2)
				{
					if (BindingEvaluator.TryGetGamepadButtonControl(current, (int)val, out var control) && control.wasPressedThisFrame)
					{
						input = new BindingInput
						{
							Kind = BindingKind.GamepadButton,
							Code = (int)val
						};
						return true;
					}
				}
			}
			Mouse current2 = Mouse.current;
			if (scheme == BindingScheme.Keyboard && current2 != null)
			{
				if (current2.leftButton.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 0
					};
					return true;
				}
				if (current2.rightButton.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 1
					};
					return true;
				}
				if (current2.middleButton.wasPressedThisFrame)
				{
					input = new BindingInput
					{
						Kind = BindingKind.MouseButton,
						Code = 2
					};
					return true;
				}
			}
			Keyboard current3 = Keyboard.current;
			if (scheme == BindingScheme.Keyboard && current3 != null)
			{
				Enumerator<KeyControl> enumerator = current3.allKeys.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						KeyControl current4 = enumerator.Current;
						if (current4 != null && ((ButtonControl)current4).wasPressedThisFrame)
						{
							input = new BindingInput
							{
								Kind = BindingKind.Key,
								Code = (int)current4.keyCode
							};
							return true;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
			}
			input = default(BindingInput);
			return false;
		}
	}
	internal static class KeyboardDefaults
	{
		internal static void EnsureDefaults()
		{
			SetIfUnset(BindAction.InteractOk, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 19
			});
			SetIfUnset(BindAction.Back, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 1
			});
			SetIfUnset(BindAction.Brake, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 33
			});
			SetIfUnset(BindAction.MapItems, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 51
			});
			SetIfUnset(BindAction.Jobs, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 3
			});
			SetIfUnset(BindAction.Pause, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 60
			});
			SetIfUnset(BindAction.MoveUp, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 37
			});
			SetIfUnset(BindAction.MoveLeft, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 15
			});
			SetIfUnset(BindAction.MoveDown, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 33
			});
			SetIfUnset(BindAction.MoveRight, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 18
			});
			SetIfUnset(BindAction.SteerLeft, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 15
			});
			SetIfUnset(BindAction.SteerRight, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 18
			});
			SetIfUnset(BindAction.Drive, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 37
			});
			SetIfUnset(BindAction.Camera, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 17
			});
			SetIfUnset(BindAction.LookLeft, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 40
			});
			SetIfUnset(BindAction.LookRight, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 38
			});
			SetIfUnset(BindAction.ResetVehicle, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 32
			});
			SetIfUnset(BindAction.Headlights, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 22
			});
			SetIfUnset(BindAction.RadioPower, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 64
			});
			SetIfUnset(BindAction.RadioScanLeft, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 61
			});
			SetIfUnset(BindAction.RadioScanRight, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 62
			});
			SetIfUnset(BindAction.RadioScanToggle, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 63
			});
			SetIfUnset(BindAction.Horn, new BindingInput
			{
				Kind = BindingKind.Key,
				Code = 31
			});
			if (BindingStore.GetModifierBinding(BindingScheme.Keyboard).Kind == BindingKind.None)
			{
				BindingStore.SetModifierBinding(BindingScheme.Keyboard, new BindingInput
				{
					Kind = BindingKind.None,
					Code = 0
				});
			}
		}

		private static void SetIfUnset(BindAction action, BindingInput input)
		{
			BindingInput binding = BindingStore.GetBinding(BindingScheme.Keyboard, BindingLayer.Normal, action);
			BindingInput binding2 = BindingStore.GetBinding(BindingScheme.Keyboard, BindingLayer.Modified, action);
			if (binding.Kind == BindingKind.None && binding2.Kind == BindingKind.None)
			{
				BindingStore.SetBinding(BindingScheme.Keyboard, BindingLayer.Normal, action, input);
			}
		}
	}
	[BepInPlugin("shibe.easydeliveryco.sebbinds", "SebBinds", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "shibe.easydeliveryco.sebbinds";

		public const string PluginName = "SebBinds";

		public const string PluginVersion = "1.0.3";

		internal static ManualLogSource Log;

		internal static sInputManager LastInputManager;

		private static ConfigEntry<bool> _debugLogging;

		private static readonly BindingScheme[] SchemesControllerKeyboard = new BindingScheme[2]
		{
			BindingScheme.Controller,
			BindingScheme.Keyboard
		};

		private static readonly BindingScheme[] SchemesControllerKeyboardWheel = new BindingScheme[3]
		{
			BindingScheme.Controller,
			BindingScheme.Keyboard,
			BindingScheme.Wheel
		};

		private static int _defaultsEnsuredForInputInstanceId;

		private static float _rese