Decompiled source of ReBinds v1.2.0

ReBinds.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using ReBinds;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(VehicleControlMod), "Ducks Can Drive - ReBinds", "1.0.0", "WiredStudio", null)]
[assembly: MelonGame("Joseph Cook", "Ducks Can Drive")]
[assembly: AssemblyTitle("Rebinding")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rebinding")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f748d1bd-e1ab-457e-a6c3-96adde081421")]
[assembly: AssemblyFileVersion("1.1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.2")]
namespace ReBinds;

public static class Bindings
{
	[CompilerGenerated]
	private sealed class <get_AllBindings>d__10 : IEnumerable<MelonPreferences_Entry<KeyCode>>, IEnumerable, IEnumerator<MelonPreferences_Entry<KeyCode>>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private MelonPreferences_Entry<KeyCode> <>2__current;

		private int <>l__initialThreadId;

		MelonPreferences_Entry<KeyCode> IEnumerator<MelonPreferences_Entry<KeyCode>>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <get_AllBindings>d__10(int <>1__state)
		{
			this.<>1__state = <>1__state;
			<>l__initialThreadId = Environment.CurrentManagedThreadId;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = ForwardKey;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>2__current = BackwardKey;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<>2__current = LeftKey;
				<>1__state = 3;
				return true;
			case 3:
				<>1__state = -1;
				<>2__current = RightKey;
				<>1__state = 4;
				return true;
			case 4:
				<>1__state = -1;
				<>2__current = DriftKey;
				<>1__state = 5;
				return true;
			case 5:
				<>1__state = -1;
				<>2__current = HonkKey;
				<>1__state = 6;
				return true;
			case 6:
				<>1__state = -1;
				<>2__current = RestartKey;
				<>1__state = 7;
				return true;
			case 7:
				<>1__state = -1;
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}

		[DebuggerHidden]
		IEnumerator<MelonPreferences_Entry<KeyCode>> IEnumerable<MelonPreferences_Entry<KeyCode>>.GetEnumerator()
		{
			if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
			{
				<>1__state = 0;
				return this;
			}
			return new <get_AllBindings>d__10(0);
		}

		[DebuggerHidden]
		IEnumerator IEnumerable.GetEnumerator()
		{
			return ((IEnumerable<MelonPreferences_Entry<KeyCode>>)this).GetEnumerator();
		}
	}

	private static MelonPreferences_Category category;

	public static MelonPreferences_Entry<KeyCode> ForwardKey;

	public static MelonPreferences_Entry<KeyCode> BackwardKey;

	public static MelonPreferences_Entry<KeyCode> LeftKey;

	public static MelonPreferences_Entry<KeyCode> RightKey;

	public static MelonPreferences_Entry<KeyCode> DriftKey;

	public static MelonPreferences_Entry<KeyCode> HonkKey;

	public static MelonPreferences_Entry<KeyCode> RestartKey;

	public static IEnumerable<MelonPreferences_Entry<KeyCode>> AllBindings
	{
		[IteratorStateMachine(typeof(<get_AllBindings>d__10))]
		get
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <get_AllBindings>d__10(-2);
		}
	}

	public static void Initialize()
	{
		category = MelonPreferences.CreateCategory("KeyBindings", "Vehicle Control Key Bindings");
		ForwardKey = category.CreateEntry<KeyCode>("Forward", (KeyCode)119, "Forward", (string)null, false, false, (ValueValidator)null, (string)null);
		BackwardKey = category.CreateEntry<KeyCode>("Backward", (KeyCode)115, "Backward", (string)null, false, false, (ValueValidator)null, (string)null);
		LeftKey = category.CreateEntry<KeyCode>("Left", (KeyCode)97, "Left", (string)null, false, false, (ValueValidator)null, (string)null);
		RightKey = category.CreateEntry<KeyCode>("Right", (KeyCode)100, "Right", (string)null, false, false, (ValueValidator)null, (string)null);
		DriftKey = category.CreateEntry<KeyCode>("Drift", (KeyCode)32, "Drift (Jump)", (string)null, false, false, (ValueValidator)null, (string)null);
		HonkKey = category.CreateEntry<KeyCode>("Honk", (KeyCode)104, "Honk (Quack)", (string)null, false, false, (ValueValidator)null, (string)null);
		RestartKey = category.CreateEntry<KeyCode>("Restart", (KeyCode)114, "Restart", (string)null, false, false, (ValueValidator)null, (string)null);
	}
}
public class VehicleControlMod : MelonMod
{
	[CompilerGenerated]
	private sealed class <WaitForMenuAndAddButton>d__25 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public VehicleControlMod <>4__this;

		private float <timeout>5__1;

		private GameObject <settingsMenu>5__2;

		private Canvas <canvas>5__3;

		private GraphicRaycaster <raycaster>5__4;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <WaitForMenuAndAddButton>d__25(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<settingsMenu>5__2 = null;
			<canvas>5__3 = null;
			<raycaster>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<timeout>5__1 = Time.time + 5f;
				<settingsMenu>5__2 = null;
				<canvas>5__3 = null;
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if (Time.time < <timeout>5__1)
			{
				<settingsMenu>5__2 = <>4__this.FindInactiveGameObject("SettingsMenu");
				if ((Object)(object)<settingsMenu>5__2 != (Object)null)
				{
					<canvas>5__3 = <settingsMenu>5__2.GetComponentInParent<Canvas>();
					if ((Object)(object)<canvas>5__3 != (Object)null && ((Behaviour)<canvas>5__3).enabled)
					{
						<raycaster>5__4 = ((Component)<canvas>5__3).GetComponent<GraphicRaycaster>();
						if ((Object)(object)<raycaster>5__4 != (Object)null && ((Behaviour)<raycaster>5__4).enabled)
						{
							goto IL_0137;
						}
						<raycaster>5__4 = null;
					}
				}
				<>2__current = (object)new WaitForSeconds(0.2f);
				<>1__state = 2;
				return true;
			}
			goto IL_0137;
			IL_0137:
			if ((Object)(object)<settingsMenu>5__2 != (Object)null && (Object)(object)<canvas>5__3 != (Object)null)
			{
				<>4__this.AddControlsButton(<settingsMenu>5__2);
				<>4__this.buttonAdded = true;
			}
			else
			{
				<>4__this.CreateStandaloneButton();
				<>4__this.buttonAdded = true;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static AudioSource quackSource;

	private AudioClip quackClip;

	private bool hasTriedFindingClip = false;

	private bool audioSourceAttached = false;

	private bool showBindingsWindow = false;

	private string currentBindingAction = "";

	private KeyCode pendingKey;

	private bool conflictDetected = false;

	private string conflictingAction = "";

	private Vector2 scrollPos;

	private bool buttonAdded = false;

	private int findAttempts;

	private readonly float windowWidth = 450f;

	private readonly float windowHeight = 350f;

	private List<GraphicRaycaster> disabledRaycasters = new List<GraphicRaycaster>();

	private bool wasModalActive = false;

	private GUIStyle windowStyle;

	private GUIStyle labelStyle;

	private GUIStyle buttonStyle;

	private GUIStyle conflictBoxStyle;

	private GameObject controlsButton;

	private bool hasLoggedMissingQuack = false;

	public override void OnInitializeMelon()
	{
		Bindings.Initialize();
		((MelonBase)this).HarmonyInstance.PatchAll();
	}

	public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
	{
		quackSource = null;
		quackClip = null;
		hasTriedFindingClip = false;
		audioSourceAttached = false;
		hasLoggedMissingQuack = false;
		if (disabledRaycasters.Count > 0)
		{
			DisableModalMode();
		}
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (sceneName == "Menu")
		{
			buttonAdded = false;
			controlsButton = null;
			if (showBindingsWindow)
			{
				showBindingsWindow = false;
				DisableModalMode();
			}
			MelonCoroutines.Start(WaitForMenuAndAddButton());
		}
	}

	[IteratorStateMachine(typeof(<WaitForMenuAndAddButton>d__25))]
	private IEnumerator WaitForMenuAndAddButton()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WaitForMenuAndAddButton>d__25(0)
		{
			<>4__this = this
		};
	}

	private void EnableModalMode()
	{
		disabledRaycasters.Clear();
		GraphicRaycaster[] array = Resources.FindObjectsOfTypeAll<GraphicRaycaster>();
		GraphicRaycaster[] array2 = array;
		foreach (GraphicRaycaster val in array2)
		{
			if (((Behaviour)val).enabled)
			{
				((Behaviour)val).enabled = false;
				disabledRaycasters.Add(val);
			}
		}
	}

	private void DisableModalMode()
	{
		foreach (GraphicRaycaster disabledRaycaster in disabledRaycasters)
		{
			if ((Object)(object)disabledRaycaster != (Object)null)
			{
				((Behaviour)disabledRaycaster).enabled = true;
			}
		}
		disabledRaycasters.Clear();
	}

	private GameObject FindInactiveGameObject(string name)
	{
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject val in array)
		{
			if (((Object)val).name == name)
			{
				return val;
			}
		}
		return null;
	}

	private void AddControlsButton(GameObject settingsMenu)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Expected O, but got Unknown
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Expected O, but got Unknown
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Expected O, but got Unknown
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		Transform val = settingsMenu.transform;
		Transform val2 = FindButtonPanel(settingsMenu.transform);
		if ((Object)(object)val2 != (Object)null)
		{
			val = val2;
		}
		if ((Object)(object)val.Find("ControlsButton") != (Object)null)
		{
			return;
		}
		controlsButton = new GameObject("ControlsButton", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button)
		});
		controlsButton.transform.SetParent(val, false);
		RectTransform component = controlsButton.GetComponent<RectTransform>();
		component.sizeDelta = new Vector2(240f, 60f);
		component.anchorMin = new Vector2(0f, 0f);
		component.anchorMax = new Vector2(0f, 0f);
		component.pivot = new Vector2(0f, 0f);
		component.anchoredPosition = new Vector2(10f, 10f);
		Image component2 = controlsButton.GetComponent<Image>();
		((Graphic)component2).color = new Color(0.2f, 0.2f, 0.2f, 1f);
		((Graphic)component2).raycastTarget = true;
		Button component3 = controlsButton.GetComponent<Button>();
		((Selectable)component3).targetGraphic = (Graphic)(object)component2;
		GameObject val3 = new GameObject("Text", new Type[2]
		{
			typeof(RectTransform),
			typeof(Text)
		});
		val3.transform.SetParent(controlsButton.transform, false);
		Text component4 = val3.GetComponent<Text>();
		Button componentInChildren = ((Component)val).GetComponentInChildren<Button>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			Text componentInChildren2 = ((Component)componentInChildren).GetComponentInChildren<Text>();
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				component4.font = componentInChildren2.font;
				component4.fontSize = componentInChildren2.fontSize;
				((Graphic)component4).color = ((Graphic)componentInChildren2).color;
				component4.fontStyle = componentInChildren2.fontStyle;
				component4.alignment = componentInChildren2.alignment;
			}
			else
			{
				SetDefaultTextStyle(component4);
			}
		}
		else
		{
			SetDefaultTextStyle(component4);
		}
		component4.text = "Controls";
		component4.horizontalOverflow = (HorizontalWrapMode)1;
		component4.verticalOverflow = (VerticalWrapMode)1;
		RectTransform component5 = val3.GetComponent<RectTransform>();
		component5.anchorMin = Vector2.zero;
		component5.anchorMax = Vector2.one;
		component5.sizeDelta = Vector2.zero;
		((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
		{
			showBindingsWindow = true;
		});
	}

	private void SetDefaultTextStyle(Text txt)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		txt.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		if ((Object)(object)txt.font == (Object)null)
		{
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			if (array.Length != 0)
			{
				txt.font = array[0];
			}
		}
		txt.fontSize = 24;
		((Graphic)txt).color = Color.white;
		txt.alignment = (TextAnchor)4;
	}

	private Transform FindButtonPanel(Transform root)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		foreach (Transform item in root)
		{
			Transform val = item;
			if ((((Object)val).name.Contains("Panel") || ((Object)val).name.Contains("Content") || ((Object)val).name.Contains("Buttons")) && (Object)(object)((Component)val).GetComponentInChildren<Button>() != (Object)null)
			{
				return val;
			}
			Transform val2 = FindButtonPanel(val);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		return null;
	}

	private void CreateStandaloneButton()
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: 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_00c7: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Expected O, but got Unknown
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Expected O, but got Unknown
		Canvas val = Object.FindObjectOfType<Canvas>();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		controlsButton = new GameObject("ControlsButton", new Type[3]
		{
			typeof(RectTransform),
			typeof(Image),
			typeof(Button)
		});
		controlsButton.transform.SetParent(((Component)val).transform, false);
		RectTransform component = controlsButton.GetComponent<RectTransform>();
		component.sizeDelta = new Vector2(240f, 60f);
		component.anchorMin = new Vector2(0f, 0f);
		component.anchorMax = new Vector2(0f, 0f);
		component.pivot = new Vector2(0f, 0f);
		component.anchoredPosition = new Vector2(10f, 10f);
		Image component2 = controlsButton.GetComponent<Image>();
		((Graphic)component2).color = Color.gray;
		Button component3 = controlsButton.GetComponent<Button>();
		((Selectable)component3).targetGraphic = (Graphic)(object)component2;
		GameObject val2 = new GameObject("Text", new Type[2]
		{
			typeof(RectTransform),
			typeof(Text)
		});
		val2.transform.SetParent(controlsButton.transform, false);
		Text component4 = val2.GetComponent<Text>();
		component4.text = "Controls";
		component4.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		if ((Object)(object)component4.font == (Object)null)
		{
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			if (array.Length != 0)
			{
				component4.font = array[0];
			}
		}
		component4.fontSize = 24;
		component4.alignment = (TextAnchor)4;
		((Graphic)component4).color = Color.white;
		RectTransform component5 = val2.GetComponent<RectTransform>();
		component5.anchorMin = Vector2.zero;
		component5.anchorMax = Vector2.one;
		component5.sizeDelta = Vector2.zero;
		((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
		{
			showBindingsWindow = true;
		});
	}

	public override void OnUpdate()
	{
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		if ((Object)(object)quackSource == (Object)null && !hasTriedFindingClip)
		{
			GameObject val = FindInactiveGameObject("Quack");
			if ((Object)(object)val != (Object)null)
			{
				quackSource = val.GetComponent<AudioSource>();
			}
			if ((Object)(object)quackSource == (Object)null)
			{
				AudioClip[] array = Resources.FindObjectsOfTypeAll<AudioClip>();
				AudioClip[] array2 = array;
				foreach (AudioClip val2 in array2)
				{
					if (((Object)val2).name.Equals("quack", StringComparison.OrdinalIgnoreCase) || ((Object)val2).name.ToLower().Contains("quack"))
					{
						quackClip = val2;
						GameObject val3 = new GameObject("TempHonkSource");
						quackSource = val3.AddComponent<AudioSource>();
						quackSource.clip = quackClip;
						quackSource.playOnAwake = false;
						quackSource.spatialBlend = 1f;
						break;
					}
				}
			}
			hasTriedFindingClip = true;
			if ((Object)(object)quackSource == (Object)null && !hasLoggedMissingQuack)
			{
				hasLoggedMissingQuack = true;
			}
		}
		if ((Object)(object)quackSource != (Object)null && !audioSourceAttached)
		{
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				((Component)quackSource).transform.SetParent(((Component)main).transform);
				((Component)quackSource).transform.localPosition = Vector3.zero;
				quackSource.spatialBlend = 1f;
				audioSourceAttached = true;
			}
			else
			{
				quackSource.spatialBlend = 0f;
				audioSourceAttached = true;
			}
		}
		if (Input.GetKeyDown(Bindings.HonkKey.Value) && (Object)(object)quackSource != (Object)null)
		{
			quackSource.pitch = Random.Range(0.8f, 1.2f);
			quackSource.Play();
		}
		if (Input.GetKeyDown(Bindings.RestartKey.Value))
		{
			RestartGame();
		}
		if (showBindingsWindow != wasModalActive)
		{
			if (showBindingsWindow)
			{
				EnableModalMode();
			}
			else
			{
				DisableModalMode();
			}
			wasModalActive = showBindingsWindow;
		}
	}

	private void RestartGame()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Scene activeScene = SceneManager.GetActiveScene();
		string name = ((Scene)(ref activeScene)).name;
		SceneManager.LoadScene(name);
	}

	public override void OnGUI()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if (showBindingsWindow)
		{
			if (windowStyle == null || (Object)(object)windowStyle.normal.background == (Object)null)
			{
				CreateStyles();
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((float)(Screen.width / 2) - windowWidth / 2f, (float)(Screen.height / 2) - windowHeight / 2f, windowWidth, windowHeight);
			GUI.Box(val, "Key Bindings", windowStyle);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 10f, ((Rect)(ref val)).y + 30f, ((Rect)(ref val)).width - 20f, ((Rect)(ref val)).height - 40f));
			DrawBindingsContent();
			GUILayout.EndArea();
		}
	}

	private void CreateStyles()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_0094: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		windowStyle = new GUIStyle();
		windowStyle.normal.background = MakeTex(2, 2, new Color(0.1f, 0.1f, 0.1f, 0.95f));
		windowStyle.normal.textColor = Color.white;
		windowStyle.fontSize = 20;
		windowStyle.fontStyle = (FontStyle)1;
		windowStyle.alignment = (TextAnchor)1;
		windowStyle.padding = new RectOffset(10, 10, 10, 10);
		labelStyle = new GUIStyle(GUI.skin.label);
		labelStyle.normal.textColor = Color.white;
		labelStyle.fontSize = 16;
		buttonStyle = new GUIStyle(GUI.skin.button);
		buttonStyle.normal.background = MakeTex(2, 2, new Color(0.3f, 0.3f, 0.3f, 1f));
		buttonStyle.hover.background = MakeTex(2, 2, new Color(0.5f, 0.5f, 0.5f, 1f));
		buttonStyle.active.background = MakeTex(2, 2, new Color(0.2f, 0.2f, 0.2f, 1f));
		buttonStyle.normal.textColor = Color.white;
		buttonStyle.fontSize = 14;
		conflictBoxStyle = new GUIStyle(GUI.skin.box);
		conflictBoxStyle.normal.background = MakeTex(2, 2, new Color(0.8f, 0.2f, 0.2f, 0.8f));
		conflictBoxStyle.normal.textColor = Color.white;
		conflictBoxStyle.fontSize = 14;
		conflictBoxStyle.alignment = (TextAnchor)4;
	}

	private Texture2D MakeTex(int width, int height, Color col)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		Color[] array = (Color[])(object)new Color[width * height];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = col;
		}
		Texture2D val = new Texture2D(width, height);
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	private void DrawBindingsContent()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Invalid comparison between Unknown and I4
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		if (conflictDetected)
		{
			GUILayout.Box($"Warning: {pendingKey} is already used for {conflictingAction}. Override?", conflictBoxStyle, Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Yes", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				AssignKey(currentBindingAction, pendingKey, overrideConflict: true);
				conflictDetected = false;
				currentBindingAction = "";
			}
			if (GUILayout.Button("No", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				conflictDetected = false;
				currentBindingAction = "";
			}
			GUILayout.EndHorizontal();
		}
		else if (!string.IsNullOrEmpty(currentBindingAction))
		{
			if (currentBindingAction == "Restart")
			{
				GUILayout.Label("This will restart the current level.", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			}
			GUILayout.Label("Press any key for " + currentBindingAction + "...", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) });
			if (Event.current.isKey && (int)Event.current.keyCode > 0)
			{
				pendingKey = Event.current.keyCode;
				MelonPreferences_Entry<KeyCode> val = Bindings.AllBindings.FirstOrDefault((Func<MelonPreferences_Entry<KeyCode>, bool>)((MelonPreferences_Entry<KeyCode> b) => b.Value == pendingKey && ((MelonPreferences_Entry)b).DisplayName != currentBindingAction));
				if (val != null)
				{
					conflictingAction = ((MelonPreferences_Entry)val).DisplayName;
					conflictDetected = true;
				}
				else
				{
					AssignKey(currentBindingAction, pendingKey, overrideConflict: false);
					currentBindingAction = "";
				}
			}
		}
		else
		{
			scrollPos = GUILayout.BeginScrollView(scrollPos, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(windowWidth - 20f),
				GUILayout.Height(200f)
			});
			DrawBindingRow("Forward", Bindings.ForwardKey.Value);
			DrawBindingRow("Backward", Bindings.BackwardKey.Value);
			DrawBindingRow("Left", Bindings.LeftKey.Value);
			DrawBindingRow("Right", Bindings.RightKey.Value);
			DrawBindingRow("Drift", Bindings.DriftKey.Value);
			DrawBindingRow("Honk", Bindings.HonkKey.Value);
			DrawBindingRow("Restart", Bindings.RestartKey.Value);
			GUILayout.EndScrollView();
			if (GUILayout.Button("Close", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
			{
				showBindingsWindow = false;
			}
		}
	}

	private void DrawBindingRow(string action, KeyCode currentKey)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(action + ":", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) });
		if (GUILayout.Button(((object)(KeyCode)(ref currentKey)).ToString(), buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(150f),
			GUILayout.Height(30f)
		}))
		{
			currentBindingAction = action;
			conflictDetected = false;
		}
		GUILayout.EndHorizontal();
	}

	private void AssignKey(string action, KeyCode key, bool overrideConflict)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		if (overrideConflict)
		{
			MelonPreferences_Entry<KeyCode> val = Bindings.AllBindings.FirstOrDefault((Func<MelonPreferences_Entry<KeyCode>, bool>)((MelonPreferences_Entry<KeyCode> b) => b.Value == key && ((MelonPreferences_Entry)b).DisplayName != action));
			if (val != null)
			{
				val.Value = (KeyCode)0;
			}
		}
		switch (action)
		{
		default:
			return;
		case "Forward":
			Bindings.ForwardKey.Value = key;
			break;
		case "Backward":
			Bindings.BackwardKey.Value = key;
			break;
		case "Left":
			Bindings.LeftKey.Value = key;
			break;
		case "Right":
			Bindings.RightKey.Value = key;
			break;
		case "Drift":
			Bindings.DriftKey.Value = key;
			break;
		case "Honk":
			Bindings.HonkKey.Value = key;
			break;
		case "Restart":
			Bindings.RestartKey.Value = key;
			break;
		}
		MelonPreferences.Save();
	}
}
[HarmonyPatch]
public static class InputPatches
{
	[HarmonyPatch(typeof(Input), "GetAxis", new Type[] { typeof(string) })]
	[HarmonyPrefix]
	public static bool GetAxisPrefix(string axisName, ref float __result)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		if (axisName == "Horizontal")
		{
			float num = 0f;
			if (Input.GetKey(Bindings.LeftKey.Value))
			{
				num -= 1f;
			}
			if (Input.GetKey(Bindings.RightKey.Value))
			{
				num += 1f;
			}
			__result = num;
			return false;
		}
		if (axisName == "Vertical")
		{
			float num2 = 0f;
			if (Input.GetKey(Bindings.ForwardKey.Value))
			{
				num2 += 1f;
			}
			if (Input.GetKey(Bindings.BackwardKey.Value))
			{
				num2 -= 1f;
			}
			__result = num2;
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Input), "GetButton", new Type[] { typeof(string) })]
	[HarmonyPrefix]
	public static bool GetButtonPrefix(string buttonName, ref bool __result)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (buttonName == "Jump")
		{
			__result = Input.GetKey(Bindings.DriftKey.Value);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Input), "GetButtonDown", new Type[] { typeof(string) })]
	[HarmonyPrefix]
	public static bool GetButtonDownPrefix(string buttonName, ref bool __result)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (buttonName == "Jump")
		{
			__result = Input.GetKeyDown(Bindings.DriftKey.Value);
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Input), "GetButtonUp", new Type[] { typeof(string) })]
	[HarmonyPrefix]
	public static bool GetButtonUpPrefix(string buttonName, ref bool __result)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (buttonName == "Jump")
		{
			__result = Input.GetKeyUp(Bindings.DriftKey.Value);
			return false;
		}
		return true;
	}
}