Decompiled source of BetterVehicleControls v1.0.6

BepInEx/plugins/BetterVehicleControls/BetterVehicleControls.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterVehicleControls")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+72e1985d69a1cbef0e2bc13184cbe8a2b850b522")]
[assembly: AssemblyProduct("BetterVehicleControls")]
[assembly: AssemblyTitle("BetterVehicleControls")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BetterVehicleControls
{
	[BepInPlugin("Dev1A3.BetterVehicleControls", "BetterVehicleControls", "1.0.0")]
	internal class PluginLoader : BaseUnityPlugin
	{
		internal const string modGUID = "Dev1A3.BetterVehicleControls";

		internal const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Dev1A3.BetterVehicleControls");

		private static bool initialized;

		internal static ManualLogSource logSource;

		public static PluginLoader Instance { get; private set; }

		private void Awake()
		{
			if (!initialized)
			{
				initialized = true;
				Instance = this;
				logSource = ((BaseUnityPlugin)this).Logger;
				FixesConfig.InitConfig();
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				harmony.PatchAll(executingAssembly);
			}
		}

		public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
		{
			config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
		}
	}
	internal class FixesConfig
	{
		internal static ConfigEntry<bool> AutoSwitchDriveReverse;

		internal static ConfigEntry<bool> AutoSwitchFromParked;

		internal static ConfigEntry<bool> AutoSwitchToParked;

		internal static ConfigEntry<bool> RecenterWheel;

		internal static ConfigEntry<bool> VanillaControls;

		internal static ConfigEntry<bool> ScrollableGears;

		internal static ConfigEntry<float> ChanceToStartIgnition;

		internal static void InitConfig()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			PluginLoader.Instance.BindConfig(ref AutoSwitchDriveReverse, "Settings", "Automatic Gearbox", defaultValue: false, "Should the gear automatically switch between drive & reverse when pressing the forward/backwards buttons?");
			PluginLoader.Instance.BindConfig(ref AutoSwitchFromParked, "Settings", "Automatic Handbrake Release", defaultValue: false, "Should the gear automatically switch to drive/reverse from parked?");
			PluginLoader.Instance.BindConfig(ref AutoSwitchToParked, "Settings", "Automatic Handbrake Pull", defaultValue: false, "Should the gear automatically switch to parked when the key is taken from the ignition?");
			PluginLoader.Instance.BindConfig(ref RecenterWheel, "Settings", "Automatically Center Wheel", defaultValue: true, "Should the wheel be automatically re-centered?");
			PluginLoader.Instance.BindConfig(ref VanillaControls, "Settings", "Vanilla Controls", defaultValue: true, "Should the controls be the same as vanilla? (This prevents Automatic Gearbox from working)");
			PluginLoader.Instance.BindConfig(ref ScrollableGears, "Settings", "Mouse Scroll Wheel", defaultValue: true, "Should you be able to change the gear with the mouse scroll wheel?");
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0f, 101f);
			ChanceToStartIgnition = ((BaseUnityPlugin)PluginLoader.Instance).Config.Bind<float>("Settings", "Ignition Chance", 0f, new ConfigDescription("What should the success chance for the ignition be? If set to 0 this will increase the chance each time the ignition is used. (Vanilla: 0)", (AcceptableValueBase)(object)val, Array.Empty<object>()));
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BetterVehicleControls";

		public const string PLUGIN_NAME = "BetterVehicleControls";

		public const string PLUGIN_VERSION = "1.0.6";
	}
}
namespace BetterVehicleControls.Patches
{
	[HarmonyPatch]
	internal static class Patches_PlayerController
	{
		[HarmonyPatch(typeof(PlayerControllerB), "ScrollMouse_performed")]
		[HarmonyPrefix]
		public static bool ScrollMouse(PlayerControllerB __instance, ref CallbackContext context, bool ___throwingObject)
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected I4, but got Unknown
			if (!FixesConfig.ScrollableGears.Value)
			{
				return true;
			}
			if (__instance.inTerminalMenu)
			{
				return true;
			}
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (__instance.isGrabbingObjectAnimation || __instance.quickMenuManager.isMenuOpen || ___throwingObject || __instance.isTypingChat || __instance.twoHanded || __instance.activatingItem)
			{
				return true;
			}
			if (__instance.jetpackControls || __instance.disablingJetpackControls)
			{
				return true;
			}
			if (__instance.inSpecialInteractAnimation && !__instance.inVehicleAnimation)
			{
				return true;
			}
			VehicleController val = ((IEnumerable<VehicleController>)Object.FindObjectsByType<VehicleController>((FindObjectsSortMode)0)).FirstOrDefault((Func<VehicleController, bool>)((VehicleController x) => x.localPlayerInControl));
			if ((Object)(object)val != (Object)null && val.localPlayerInControl)
			{
				int num = (int)val.gear;
				float num2 = ((CallbackContext)(ref context)).ReadValue<float>();
				if (num2 == 1f)
				{
					if (num < 3)
					{
						val.ShiftToGearAndSync(num + 1);
					}
				}
				else if (num2 == -1f && num > 1)
				{
					val.ShiftToGearAndSync(num - 1);
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class Patches_VehicleController
	{
		[HarmonyPatch(typeof(VehicleController), "TryIgnition")]
		[HarmonyPrefix]
		public static void TryIgnition(ref float ___chanceToStartIgnition)
		{
			if (FixesConfig.ChanceToStartIgnition.Value > 0f)
			{
				___chanceToStartIgnition = FixesConfig.ChanceToStartIgnition.Value;
			}
		}

		[HarmonyPatch(typeof(VehicleController), "RemoveKeyFromIgnition")]
		[HarmonyPostfix]
		public static void RemoveKeyFromIgnition(VehicleController __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			if (FixesConfig.AutoSwitchToParked.Value && __instance.localPlayerInControl)
			{
				int num = 3;
				if ((int)__instance.gear != num)
				{
					__instance.ShiftToGearAndSync(num);
				}
			}
		}

		[HarmonyPatch(typeof(VehicleController), "GetVehicleInput")]
		[HarmonyPostfix]
		public static void GetVehicleInput(VehicleController __instance, ref float ___steeringWheelAnimFloat)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Invalid comparison between Unknown and I4
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Invalid comparison between Unknown and I4
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Invalid comparison between Unknown and I4
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Invalid comparison between Unknown and I4
			if (!__instance.localPlayerInControl)
			{
				return;
			}
			if (!FixesConfig.VanillaControls.Value)
			{
				if (__instance.testingVehicleInEditor)
				{
					__instance.brakePedalPressed = __instance.input.actions.FindAction("Jump", false).ReadValue<float>() > 0f;
				}
				else
				{
					__instance.brakePedalPressed = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Jump", false).ReadValue<float>() > 0f;
				}
				if (FixesConfig.AutoSwitchDriveReverse.Value)
				{
					__instance.drivePedalPressed = __instance.moveInputVector.y > 0.1f || __instance.moveInputVector.y < -0.1f;
					if (__instance.drivePedalPressed && (int)__instance.gear != 3)
					{
						int num = ((__instance.moveInputVector.y > 0.1f) ? 1 : 2);
						if ((int)__instance.gear != num)
						{
							__instance.ShiftToGearAndSync(num);
						}
					}
				}
				else
				{
					__instance.drivePedalPressed = ((int)__instance.gear != 2 && __instance.moveInputVector.y > 0.1f) || ((int)__instance.gear != 1 && __instance.moveInputVector.y < -0.1f);
				}
			}
			if (FixesConfig.AutoSwitchFromParked.Value && (__instance.drivePedalPressed || (FixesConfig.VanillaControls.Value && __instance.brakePedalPressed)) && (int)__instance.gear == 3)
			{
				int num2 = ((__instance.moveInputVector.y > 0.1f) ? 1 : 2);
				__instance.ShiftToGearAndSync(num2);
			}
			if (__instance.moveInputVector.x == 0f && FixesConfig.RecenterWheel.Value)
			{
				__instance.steeringInput = 0f;
				__instance.steeringAnimValue = __instance.steeringInput;
				___steeringWheelAnimFloat = __instance.steeringAnimValue;
			}
		}

		[HarmonyPatch(typeof(VehicleController), "Start")]
		[HarmonyPostfix]
		public static void PlaceObject(VehicleController __instance)
		{
			Transform val = ((Component)__instance).transform.Find("Triggers/RightShelfPlacementCollider");
			if ((Object)(object)val != (Object)null)
			{
				InteractTrigger component = ((Component)val).GetComponent<InteractTrigger>();
				component.holdInteraction = true;
				component.timeToHold = 0.35f;
			}
			Transform val2 = ((Component)__instance).transform.Find("Triggers/LeftShelfPlacementCollider");
			if ((Object)(object)val2 != (Object)null)
			{
				InteractTrigger component2 = ((Component)val2).GetComponent<InteractTrigger>();
				component2.holdInteraction = true;
				component2.timeToHold = 0.35f;
			}
			Transform val3 = ((Component)__instance).transform.Find("Triggers/CenterShelfPlacementCollider");
			if ((Object)(object)val3 != (Object)null)
			{
				InteractTrigger component3 = ((Component)val3).GetComponent<InteractTrigger>();
				component3.holdInteraction = true;
				component3.timeToHold = 0.35f;
			}
		}

		[HarmonyPatch(typeof(PlaceableObjectsSurface), "PlaceObject")]
		[HarmonyPrefix]
		public static bool PlaceObject(PlayerControllerB playerWhoTriggered)
		{
			return !playerWhoTriggered.isGrabbingObjectAnimation;
		}
	}
}