Decompiled source of EasyVehicle v1.0.0

EasyVehicle.dll

Decompiled 3 months ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EasyVehicle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyVehicle")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b90fdeb1-f84a-4412-82f8-a18afd58b42b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EasyVehicle;

internal static class Config
{
	public static KeyControl tpKey = Keyboard.current.vKey;

	private static bool loadedConfig = false;

	private static string keyDisplayNames;

	public static void Bind()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (!loadedConfig)
		{
			keyDisplayNames = string.Join(", ", ((IEnumerable<KeyControl>)(object)Keyboard.current.allKeys).Select((KeyControl x) => ((InputControl)x).displayName));
			tpKey = BindKey("按键配置/KeyConfig", "第三人称按键/TP Key", Keyboard.current.vKey, "参考按键对应字符串/Reference: " + keyDisplayNames);
			VehicleComponent.upDis = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("第三人称配置/TP Config", "视角向上偏移/Up Offset", 4f, "  ").Value;
			VehicleComponent.breakDis = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<float>("第三人称配置/TP Config", "视角向后偏移/Up Offset", 7f, "  ").Value;
			loadedConfig = true;
		}
	}

	private static KeyControl BindKey(string section, string key, KeyControl defaultValue, string configDescription = null)
	{
		try
		{
			ConfigEntry<string> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>(section, key, ((InputControl)defaultValue).displayName, configDescription);
			KeyControl val2 = Keyboard.current.FindKeyOnCurrentKeyboardLayout(val.Value);
			if (val2 != null)
			{
				return val2;
			}
			Plugin.Log.LogWarning((object)("EasyVehicle按键设置失败!" + key + ":" + val.Value));
			return defaultValue;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("EasyVehicle按键设置失败!" + ex.Message));
			return defaultValue;
		}
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerB_Patch
{
	[HarmonyPatch("LookClamped")]
	[HarmonyPostfix]
	private static void LookClampedPostfix(PlayerControllerB __instance, Vector2 lookInput)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		VehicleComponent.CameraUpdate(lookInput);
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void UpdatePostfix(PlayerControllerB __instance)
	{
		if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController && !__instance.inSpecialInteractAnimation && !__instance.isPlayerDead && VehicleComponent.TPEnable)
		{
			VehicleComponent.CameraToPlayer();
		}
	}

	[HarmonyPatch("KillPlayer")]
	[HarmonyPostfix]
	private static void KillPlayerPostfix(PlayerControllerB __instance, Vector3 bodyVelocity, bool spawnBody = true, CauseOfDeath causeOfDeath = 0, int deathAnimation = 0, Vector3 positionOffset = default(Vector3))
	{
		if ((Object)(object)__instance == (Object)(object)GameNetworkManager.Instance.localPlayerController && VehicleComponent.TPEnable)
		{
			VehicleComponent.CameraToSpectate();
		}
	}
}
[BepInPlugin("qh3.EasyVehicle", "EasyVehicle", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	private static readonly Harmony harmony = new Harmony("qh3.EasyVehicle");

	internal static ManualLogSource Log = Logger.CreateLogSource("qh3.InfiniEasyVehicleteJump");

	private void Awake()
	{
		Log.LogInfo((object)"Loading EasyVehicle");
		Instance = this;
		harmony.PatchAll(typeof(VehicleController_Patch));
		harmony.PatchAll(typeof(PlayerControllerB_Patch));
	}
}
internal static class VehicleComponent
{
	private static Camera TPCamera;

	private static Transform CameraPivot;

	private static VehicleController currVehicle;

	private static bool state = false;

	private static float cameraHorizontal;

	private static float cameraUp;

	public static float breakDis = 7f;

	public static float upDis = 4f;

	public static bool TPEnable => state;

	public static void ShiftCamera(VehicleController controller)
	{
		state = !state;
		ResetCamera(controller);
		if (state)
		{
			((Behaviour)TPCamera).enabled = true;
			StartOfRound.Instance.SwitchCamera(TPCamera);
		}
		else
		{
			((Behaviour)TPCamera).enabled = false;
			StartOfRound.Instance.SwitchCamera(StartOfRound.Instance.localPlayerController.gameplayCamera);
		}
	}

	public static void CameraToPlayer()
	{
		if (state && Object.op_Implicit((Object)(object)TPCamera))
		{
			state = false;
			((Behaviour)TPCamera).enabled = false;
			StartOfRound.Instance.SwitchCamera(StartOfRound.Instance.localPlayerController.gameplayCamera);
		}
	}

	public static void CameraToSpectate()
	{
		if (state && Object.op_Implicit((Object)(object)TPCamera))
		{
			state = false;
			((Behaviour)TPCamera).enabled = false;
			StartOfRound.Instance.SwitchCamera(StartOfRound.Instance.spectateCamera);
		}
	}

	private static void ResetCamera(VehicleController controller)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		currVehicle = controller;
		if ((Object)(object)TPCamera == (Object)null)
		{
			TPCamera = new GameObject("VehicleTPCamera").AddComponent<Camera>();
			CameraPivot = new GameObject("VehicleTPCameraPivot").transform;
			TPCamera.CopyFrom(StartOfRound.Instance.localPlayerController.gameplayCamera);
		}
		CameraPivot.position = ((Component)controller).transform.position;
		((Component)TPCamera).transform.SetParent(CameraPivot);
		((Component)TPCamera).transform.SetLocalPositionAndRotation(Vector3.back * breakDis + Vector3.up * upDis, Quaternion.identity);
		cameraHorizontal = StartOfRound.Instance.localPlayerController.ladderCameraHorizontal;
		cameraUp = Traverse.Create((object)StartOfRound.Instance.localPlayerController).Field<float>("cameraUp").Value;
	}

	public static void CameraUpdate(Vector2 lookInput)
	{
		//IL_0029: 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)
		//IL_0034: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)currVehicle) && Object.op_Implicit((Object)(object)CameraPivot) && state)
		{
			lookInput *= 2f;
			cameraHorizontal += lookInput.x;
			cameraUp -= lookInput.y;
			((Component)CameraPivot).transform.position = ((Component)currVehicle).transform.position;
			((Component)CameraPivot).transform.localEulerAngles = new Vector3(cameraUp, cameraHorizontal, ((Component)TPCamera).transform.localEulerAngles.z);
		}
	}
}
[HarmonyPatch(typeof(VehicleController))]
internal class VehicleController_Patch
{
	[HarmonyPatch("GetVehicleInput")]
	[HarmonyPostfix]
	private static void GetVehicleInputPostfix(VehicleController __instance)
	{
		if (((NetworkBehaviour)__instance).IsOwner)
		{
			__instance.steeringInput = __instance.moveInputVector.x * 3f;
			if (__instance.moveInputVector.y > 0.1f)
			{
				__instance.ShiftToGearAndSync(1);
				__instance.drivePedalPressed = true;
				__instance.brakePedalPressed = false;
			}
			else if (__instance.moveInputVector.y < -0.1f)
			{
				__instance.ShiftToGearAndSync(2);
				__instance.drivePedalPressed = true;
				__instance.brakePedalPressed = false;
			}
			else
			{
				__instance.ShiftToGearAndSync(3);
				__instance.drivePedalPressed = false;
				__instance.brakePedalPressed = false;
			}
		}
	}

	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	private static void UpdatePostfix(VehicleController __instance)
	{
		Config.Bind();
		if ((Object)(object)StartOfRound.Instance.localPlayerController == (Object)(object)__instance.currentDriver && ((ButtonControl)Config.tpKey).wasPressedThisFrame)
		{
			VehicleComponent.ShiftCamera(__instance);
		}
	}
}