From a8882ce187737a8add362202291051e60a78d54a Mon Sep 17 00:00:00 2001 From: RedBigz Date: Thu, 7 Nov 2024 19:39:35 +1000 Subject: [PATCH] Add rudimentary 1-hand gun aiming --- TABGVR/Patches/KinematicsPatch.cs | 59 +++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/TABGVR/Patches/KinematicsPatch.cs b/TABGVR/Patches/KinematicsPatch.cs index c762079..9135ce8 100644 --- a/TABGVR/Patches/KinematicsPatch.cs +++ b/TABGVR/Patches/KinematicsPatch.cs @@ -1,8 +1,7 @@ -using Epic.OnlineServices; -using Epic.OnlineServices.Presence; +using System.Collections; using HarmonyLib; using TABGVR.Player; -using UltimateIK; +using TABGVR.Player.Mundanities; using UnityEngine; namespace TABGVR.Patches; @@ -22,10 +21,10 @@ static void SetupConnection(Rigidbody joint) joint.isKinematic = false; arm.GetComponent().isKinematic = false; - + foreach (var animationObject in joint.GetComponents()) Object.Destroy(animationObject); foreach (var animationObject in arm.GetComponents()) Object.Destroy(animationObject); - + foreach (var collisionChecker in joint.GetComponents()) Object.Destroy(collisionChecker); foreach (var collisionChecker in arm.GetComponents()) Object.Destroy(collisionChecker); } @@ -35,10 +34,10 @@ static void UpdateConnection(Rigidbody joint, GameObject controller) var controllerRelativeToGameCamera = controller.transform.position - Controllers.Head.transform.position + Camera.current.transform.position; - if (Vector3.Distance(joint.position, controllerRelativeToGameCamera) < 0.1f) return; + // if (Vector3.Distance(joint.position, controllerRelativeToGameCamera) < 0.1f) return; joint.MovePosition(joint.position + controllerRelativeToGameCamera - - joint.transform.GetChild(0).position); + joint.transform.GetChild(0).position); } [HarmonyPatch(nameof(Holding.Start))] @@ -60,6 +59,52 @@ static void UpdatePostfix(Holding __instance) // $"KP {__instance.player} / Head: {Controllers.Head.transform.position} / Left: {Controllers.LeftHand.transform.position} / Right: {Controllers.RightHand.transform.position}"); UpdateConnection(__instance.rightHand, Controllers.RightHand); + UpdateConnection(__instance.leftHand, Controllers.LeftHand); + + var heldObject = Grenades.SelectedGrenade?.GetComponent() ?? __instance.heldObject; + if (!heldObject) return; + + // held will have hand positions which will be exploited here + var rightHold = heldObject.rightHandPos; + var leftHold = heldObject.leftHandPos; + + heldObject.gameObject.transform.rotation = Controllers.RightHand.transform.rotation * rightHold.localRotation * + Quaternion.Euler(90f, 0f, 0f); + + var toMove = (Controllers.RightHandFromGameCamera + + heldObject.gameObject.transform.position - rightHold.position); + + if (__instance.heldObject) + { + var rigidBody = heldObject.GetComponent(); + + rigidBody.isKinematic = false; + rigidBody.useGravity = false; + + rigidBody.MovePosition(toMove); + } + else heldObject.transform.position = toMove; + } + + [HarmonyPatch(nameof(Holding.ReachForPoint))] + [HarmonyPrefix] + static bool ReachForPointCanceller() => false; + + private static IEnumerator DoNothing() + { + yield break; } + + [HarmonyPatch(nameof(Holding.HoldweaponStill))] + [HarmonyPrefix] + private static bool HoldWeaponStillCanceller(ref IEnumerator __result) + { + __result = DoNothing(); + return false; + } + + [HarmonyPatch(typeof(PlayerIKHandler), nameof(PlayerIKHandler.LateUpdate))] + [HarmonyPrefix] + static bool IKCanceller() => false; } \ No newline at end of file