From ecb2f58a697d2f4c7249cc45857ca88f96af5dbd Mon Sep 17 00:00:00 2001 From: RedBigz Date: Sun, 17 Nov 2024 19:04:17 +1000 Subject: [PATCH] Fix vehicles rotating camera position when entered at a nonzero angle and exited out --- TABGVR/Patches/CameraMovementPatch.cs | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 TABGVR/Patches/CameraMovementPatch.cs diff --git a/TABGVR/Patches/CameraMovementPatch.cs b/TABGVR/Patches/CameraMovementPatch.cs new file mode 100644 index 0000000..2b69a5b --- /dev/null +++ b/TABGVR/Patches/CameraMovementPatch.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using HarmonyLib; + +namespace TABGVR.Patches; + +[HarmonyPatch(typeof(CameraMovement))] +public class CameraMovementPatch +{ + [HarmonyPatch(nameof(CameraMovement.LateUpdate))] + [HarmonyTranspiler] + public static IEnumerable LateUpdate(IEnumerable instructions) + { + var instructionsList = instructions.ToArray(); + + foreach (var instruction in instructions.Select((value, i) => new { i, value })) + { + // instruction.value.opcode == OpCodes.Ldarg_0 && + // instructionsList[instruction.i + 1].operand is FieldInfo fieldInfo && + // fieldInfo == typeof(CameraMovement).GetField(nameof(CameraMovement.sitting)) + + if (instruction.i is >= 144 and <= 196) + { + instruction.value.opcode = OpCodes.Nop; + instruction.value.operand = null; + } + + yield return instruction.value; + } + } + + [HarmonyPatch(nameof(CameraMovement.ResetVehicleCamera))] + [HarmonyPrefix] + public static bool ResetVehicleCameraPatch() => false; +} \ No newline at end of file