From d3db894acf98151d1947951491843b0ad8a287f3 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sat, 29 Jul 2023 16:49:06 -0500 Subject: [PATCH] [DesktopVRIK] Fixed an issue where tracking status would update a frame late --- DesktopVRIK/HarmonyPatches.cs | 15 ++++++++++ DesktopVRIK/IK/IKHandlers/IKHandler.cs | 15 ++-------- DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs | 28 ++++++++++++----- DesktopVRIK/IK/IKManager.cs | 30 ++++++++++++------- DesktopVRIK/Properties/AssemblyInfo.cs | 2 +- DesktopVRIK/format.json | 6 ++-- 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/DesktopVRIK/HarmonyPatches.cs b/DesktopVRIK/HarmonyPatches.cs index fbfaa5f..8d2a085 100644 --- a/DesktopVRIK/HarmonyPatches.cs +++ b/DesktopVRIK/HarmonyPatches.cs @@ -120,4 +120,19 @@ internal class PlayerSetupPatches DesktopVRIK.Logger.Error(e); } } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.Update))] + private static void Postfix_PlayerSetup_Update() + { + try + { + IKManager.Instance?.OnPlayerUpdate(); + } + catch (Exception e) + { + DesktopVRIK.Logger.Error($"Error during the patched method {nameof(Postfix_PlayerSetup_Update)}"); + DesktopVRIK.Logger.Error(e); + } + } } \ No newline at end of file diff --git a/DesktopVRIK/IK/IKHandlers/IKHandler.cs b/DesktopVRIK/IK/IKHandlers/IKHandler.cs index 8435a43..8c7fe11 100644 --- a/DesktopVRIK/IK/IKHandlers/IKHandler.cs +++ b/DesktopVRIK/IK/IKHandlers/IKHandler.cs @@ -80,11 +80,12 @@ internal abstract class IKHandler Update_PelvisWeight(); Update_LocomotionWeight(); - ResetSolverIfNeeded(); Update_IKPositionWeight(); } + public virtual void UpdateTracking() { } + protected virtual void Update_HeadWeight() { // There is no Head tracking setting @@ -153,17 +154,5 @@ internal abstract class IKHandler return isTracking && hasTarget ? 1f : 0f; } - private void ResetSolverIfNeeded() - { - if (_wasTrackingLocomotion == BodySystem.TrackingLocomotionEnabled) - return; - - _wasTrackingLocomotion = BodySystem.TrackingLocomotionEnabled; - if (ModSettings.EntryResetFootstepsOnIdle.Value) - VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference); - - _solver.Reset(); - } - #endregion } \ No newline at end of file diff --git a/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs b/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs index 09ee809..52bdcb7 100644 --- a/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs +++ b/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs @@ -1,6 +1,7 @@ using ABI_RC.Core.Player; using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.MovementSystem; +using NAK.DesktopVRIK.IK.VRIKHelpers; using RootMotion.FinalIK; using UnityEngine; @@ -31,11 +32,16 @@ internal class IKHandlerDesktop : IKHandler _vrik.transform.localPosition = Vector3.zero; _vrik.transform.localRotation = Quaternion.identity; - UpdateBodySystemTracking(); - base.UpdateWeights(); } + public override void UpdateTracking() + { + BodySystem.TrackingEnabled = ShouldTrackAll(); + BodySystem.TrackingLocomotionEnabled = BodySystem.TrackingEnabled && ShouldTrackLocomotion(); + ResetSolverIfNeeded(); + } + #endregion #region VRIK Solver Events @@ -85,12 +91,6 @@ internal class IKHandlerDesktop : IKHandler #endregion #region Private Methods - - private void UpdateBodySystemTracking() - { - BodySystem.TrackingEnabled = ShouldTrackAll(); - BodySystem.TrackingLocomotionEnabled = ShouldTrackLocomotion(); - } private bool ShouldTrackAll() { @@ -111,5 +111,17 @@ internal class IKHandlerDesktop : IKHandler return !(isMoving || isCrouching || isProne || isFlying || isSitting || !isGrounded || !isStanding); } + private void ResetSolverIfNeeded() + { + if (_wasTrackingLocomotion == BodySystem.TrackingLocomotionEnabled) + return; + + _wasTrackingLocomotion = BodySystem.TrackingLocomotionEnabled; + if (ModSettings.EntryResetFootstepsOnIdle.Value) + VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference); + + _solver.Reset(); + } + #endregion } \ No newline at end of file diff --git a/DesktopVRIK/IK/IKManager.cs b/DesktopVRIK/IK/IKManager.cs index f37e87d..4e66e4d 100644 --- a/DesktopVRIK/IK/IKManager.cs +++ b/DesktopVRIK/IK/IKManager.cs @@ -1,6 +1,7 @@ using ABI.CCK.Components; using ABI_RC.Core.Player; using ABI_RC.Core.Savior; +using ABI_RC.Systems.IK.SubSystems; using NAK.DesktopVRIK.IK.IKHandlers; using NAK.DesktopVRIK.IK.VRIKHelpers; using RootMotion.FinalIK; @@ -25,6 +26,7 @@ public class IKManager : MonoBehaviour // Player Info internal Transform _desktopCamera; internal Transform _vrCamera; + private bool _isEmotePlaying; // Avatar Info private Animator _animator; @@ -60,10 +62,10 @@ public class IKManager : MonoBehaviour private void Update() { - if (!_isAvatarInitialized) + if (_ikHandler == null) return; - _ikHandler?.UpdateWeights(); + _ikHandler.UpdateWeights(); } #endregion @@ -126,39 +128,47 @@ public class IKManager : MonoBehaviour public bool OnPlayerScaled(float scaleDifference) { - if (!_isAvatarInitialized) + if (_ikHandler == null) return false; - _ikHandler?.OnPlayerScaled(scaleDifference); + _ikHandler.OnPlayerScaled(scaleDifference); return true; } public void OnPlayerSeatedStateChanged(bool isSitting) { - if (!_isAvatarInitialized) + if (_ikHandler == null) return; - _ikHandler?.Reset(); + _ikHandler.Reset(); } public bool OnPlayerHandleMovementParent(CVRMovementParent movementParent) { - if (!_isAvatarInitialized) + if (_ikHandler == null) return false; - _ikHandler?.OnPlayerHandleMovementParent(movementParent, GetPlayerPosition()); + _ikHandler.OnPlayerHandleMovementParent(movementParent, GetPlayerPosition()); return true; } public bool OnPlayerTeleported() { - if (!_isAvatarInitialized) + if (_ikHandler == null) return false; - _ikHandler?.Reset(); + _ikHandler.Reset(); return true; } + public void OnPlayerUpdate() + { + if (_ikHandler == null) + return; + + _ikHandler.UpdateTracking(); + } + #endregion #region IK Initialization diff --git a/DesktopVRIK/Properties/AssemblyInfo.cs b/DesktopVRIK/Properties/AssemblyInfo.cs index 015203f..438a0d5 100644 --- a/DesktopVRIK/Properties/AssemblyInfo.cs +++ b/DesktopVRIK/Properties/AssemblyInfo.cs @@ -28,6 +28,6 @@ using System.Reflection; namespace NAK.DesktopVRIK.Properties; internal static class AssemblyInfoParams { - public const string Version = "4.2.2"; + public const string Version = "4.2.3"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/DesktopVRIK/format.json b/DesktopVRIK/format.json index fa495ea..632be3b 100644 --- a/DesktopVRIK/format.json +++ b/DesktopVRIK/format.json @@ -1,7 +1,7 @@ { "_id": 117, "name": "DesktopVRIK", - "modversion": "4.2.2", + "modversion": "4.2.3", "gameversion": "2023r171", "loaderversion": "0.6.1", "modtype": "Mod", @@ -17,8 +17,8 @@ "requirements": [ "BTKUILib" ], - "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r15/DesktopVRIK.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r17/DesktopVRIK.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRIK/", - "changelog": "- Reverted to old way of setting up head ik target. This fixes horrid armatures being bent and broken.", + "changelog": "- Fixed an issue where tracking status would update a frame late.", "embedcolor": "#9b59b6" } \ No newline at end of file