Decompiled source of EDCOMouseSteering v1.0.3

EDCOMouseSteering.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("EDCOMouseSteering")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+870cb149272273aea5435e7204aeb2c357dcc64d")]
[assembly: AssemblyProduct("EDCOMouseSteering")]
[assembly: AssemblyTitle("EDCOMouseSteering")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EDCOMouseSteering
{
	[BepInPlugin("EDCOMouseSteering", "EDCOMouseSteering", "1.0.0")]
	public class EdcoMouseSteering : BaseUnityPlugin
	{
		private float _sensitivity = 1f;

		private InputActionAsset _customAsset;

		private InputActionMap _customMap;

		private InputAction _toggleMouseSteering;

		private InputAction _lookAction;

		private InputAction _decreaseSensitivity;

		private InputAction _increaseSensitivity;

		private bool _isInitialized;

		public static EdcoMouseSteering Instance { get; private set; }

		public ILogSource PluginLogger => (ILogSource)(object)((BaseUnityPlugin)this).Logger;

		public bool MouseSteeringEnabled { get; private set; }

		public float MouseSteeringValue { get; private set; }

		private void Awake()
		{
			if (!Object.op_Implicit((Object)(object)Instance))
			{
				Instance = this;
			}
		}

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!_isInitialized)
			{
				try
				{
					InitializeInputAndPatches();
					_isInitialized = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)"EDCOMouseSteering: Ввод и Harmony-патчи успешно инициализированы!");
				}
				catch (TypeLoadException)
				{
					return;
				}
			}
			if (_lookAction != null)
			{
				Vector2 val = _lookAction.ReadValue<Vector2>();
				if (val != Vector2.zero && MouseSteeringEnabled && !PauseSystem.paused)
				{
					MouseSteeringValue = Mathf.Clamp(MouseSteeringValue + val.x / 25f * _sensitivity * Time.deltaTime * 10f, -1f, 1f);
				}
			}
		}

		private void InitializeInputAndPatches()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			_customAsset = ScriptableObject.CreateInstance<InputActionAsset>();
			_customMap = InputActionSetupExtensions.AddActionMap(_customAsset, "ModInputMap");
			_toggleMouseSteering = InputActionSetupExtensions.AddAction(_customMap, "ToggleMouseSteering", (InputActionType)0, "<Mouse>/leftButton", (string)null, (string)null, (string)null, (string)null);
			_lookAction = InputActionSetupExtensions.AddAction(_customMap, "MouseLook", (InputActionType)0, (string)null, (string)null, (string)null, (string)null, (string)null);
			InputActionSetupExtensions.AddBinding(_lookAction, "<Mouse>/delta", (string)null, (string)null, (string)null);
			_decreaseSensitivity = InputActionSetupExtensions.AddAction(_customMap, "DecreaseSensitivity", (InputActionType)0, "<Keyboard>/minus", (string)null, (string)null, (string)null, (string)null);
			_increaseSensitivity = InputActionSetupExtensions.AddAction(_customMap, "IncreaseSensitivity", (InputActionType)0, "<Keyboard>/equals", (string)null, (string)null, (string)null, (string)null);
			_toggleMouseSteering.performed += OnToggleMouseSteering;
			_decreaseSensitivity.performed += OnDecreaseSensitivity;
			_increaseSensitivity.performed += OnIncreaseSensitivity;
			_customAsset.Enable();
			new Harmony("com.flyen256.mousesteering").PatchAll();
		}

		private void OnDestroy()
		{
			if (_toggleMouseSteering != null)
			{
				_toggleMouseSteering.performed -= OnToggleMouseSteering;
			}
			if (_decreaseSensitivity != null)
			{
				_decreaseSensitivity.performed -= OnDecreaseSensitivity;
			}
			if (_increaseSensitivity != null)
			{
				_increaseSensitivity.performed -= OnIncreaseSensitivity;
			}
			if (Object.op_Implicit((Object)(object)_customAsset))
			{
				_customAsset.Disable();
				Object.Destroy((Object)(object)_customAsset);
			}
		}

		private void OnToggleMouseSteering(CallbackContext context)
		{
			if (!PauseSystem.paused)
			{
				MouseSteeringEnabled = !MouseSteeringEnabled;
				MouseSteeringValue = 0f;
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Mouse steering toggled: {MouseSteeringEnabled}");
			}
		}

		private void OnIncreaseSensitivity(CallbackContext context)
		{
			_sensitivity += 0.05f;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Sensitivity increased: {_sensitivity:F2}");
		}

		private void OnDecreaseSensitivity(CallbackContext context)
		{
			_sensitivity = Mathf.Max(0.01f, _sensitivity - 0.05f);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Sensitivity decreased: {_sensitivity:F2}");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "EDCOMouseSteering";

		public const string PLUGIN_NAME = "EDCOMouseSteering";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace EDCOMouseSteering.Patches
{
	[HarmonyPatch(typeof(sCameraRotate), "Update")]
	public class CameraRotateUpdatePrefix
	{
		public static bool Prefix(sCameraRotate __instance, ref sCarController ___car, ref Vector3 ___rotation, ref Vector3 ___targetRotation)
		{
			//IL_0034: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006f: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			EdcoMouseSteering instance = EdcoMouseSteering.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !instance.MouseSteeringEnabled)
			{
				return true;
			}
			if (PauseSystem.paused)
			{
				Cursor.lockState = (CursorLockMode)0;
				return true;
			}
			Cursor.lockState = (CursorLockMode)1;
			Vector3 linearVelocity = ___car.rb.linearVelocity;
			float num = ((Vector3)(ref linearVelocity)).magnitude / 10f;
			if (___car.GuyActive)
			{
				num = 0.5f;
			}
			___targetRotation = Vector3.Lerp(___targetRotation, Vector3.zero, Time.deltaTime * num);
			___rotation = Vector3.Lerp(___rotation, ___targetRotation, Time.deltaTime * 4f);
			__instance.target.localEulerAngles = Vector3.right * ___rotation.y;
			__instance.pivot.localEulerAngles = Vector3.up * ___rotation.x;
			return false;
		}
	}
	[HarmonyPatch(typeof(sCarController), "Move")]
	public class CarControllerMovePrefix
	{
		public static void Prefix(sCarController __instance)
		{
			EdcoMouseSteering instance = EdcoMouseSteering.Instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.MouseSteeringEnabled)
			{
				__instance.input.x = EdcoMouseSteering.Instance.MouseSteeringValue;
			}
		}
	}
	[HarmonyPatch(typeof(sCarController), "SetInput", new Type[] { typeof(Vector2) })]
	public static class CarControllerSetInputPostfix
	{
		public static void Postfix(ref Vector2 ___input, ref Vector2 ___targetInput)
		{
			EdcoMouseSteering instance = EdcoMouseSteering.Instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.MouseSteeringEnabled)
			{
				___targetInput.x = ___input.x;
			}
		}
	}
	[HarmonyPatch(typeof(sInputManager), "GetInput")]
	public static class InputManagerGetInputPostfix
	{
		public static void Postfix(sInputManager __instance)
		{
			//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)
			EdcoMouseSteering instance = EdcoMouseSteering.Instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.MouseSteeringEnabled)
			{
				__instance.driveInput = new Vector2(instance.MouseSteeringValue, __instance.driveInput.y);
			}
		}
	}
}