From 892ff611b59bcdb406672779b3e4d8065594e793 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:31:42 -0600 Subject: [PATCH] [DesktopVRIK] Fixes for r173 --- DesktopVRIK/HarmonyPatches.cs | 25 ++++++++++- DesktopVRIK/IK/IKHandlers/IKHandler.cs | 7 ++-- DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs | 3 +- DesktopVRIK/IK/IKManager.cs | 41 +++++++++++++++++-- DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs | 4 +- DesktopVRIK/ModSettings.cs | 7 ---- DesktopVRIK/Properties/AssemblyInfo.cs | 2 +- DesktopVRIK/format.json | 6 +-- 8 files changed, 72 insertions(+), 23 deletions(-) diff --git a/DesktopVRIK/HarmonyPatches.cs b/DesktopVRIK/HarmonyPatches.cs index 77776a6..f1c9799 100644 --- a/DesktopVRIK/HarmonyPatches.cs +++ b/DesktopVRIK/HarmonyPatches.cs @@ -1,5 +1,6 @@ using ABI.CCK.Components; using ABI_RC.Core.Player; +using ABI_RC.Systems.IK; using HarmonyLib; using NAK.DesktopVRIK.IK; using UnityEngine; @@ -100,6 +101,26 @@ internal class PlayerSetupPatches } } + [HarmonyPrefix] + [HarmonyPatch(typeof(IKSystem), nameof(IKSystem.OffsetMovementParent))] + private static void Prefix_IKSystem_OffsetMovementParent(CVRMovementParent currentParent, ref IKSystem __instance, ref bool __runOriginal) + { + try + { + __runOriginal = true; + if (IKManager.Instance == null || !IKManager.Instance.IsAvatarInitialized()) + return; + + if (currentParent != null && currentParent._referencePoint != null) + __runOriginal = IKManager.Instance.OnPlayerHandleMovementParent(currentParent); + } + catch (Exception e) + { + DesktopVRIK.Logger.Error($"Error during the patched method {nameof(Prefix_IKSystem_OffsetMovementParent)}"); + DesktopVRIK.Logger.Error(e); + } + } + [HarmonyPrefix] [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.ResetIk))] private static void Prefix_PlayerSetup_ResetIk(ref PlayerSetup __instance, ref bool __runOriginal) @@ -112,9 +133,9 @@ internal class PlayerSetupPatches CVRMovementParent currentParent = __instance._movementSystem._currentParent; if (currentParent != null && currentParent._referencePoint != null) - IKManager.Instance.OnPlayerHandleMovementParent(currentParent); + __runOriginal = IKManager.Instance.OnPlayerHandleMovementParent(currentParent); else - IKManager.Instance.OnPlayerTeleported(); + __runOriginal = IKManager.Instance.OnPlayerTeleported(); } catch (Exception e) { diff --git a/DesktopVRIK/IK/IKHandlers/IKHandler.cs b/DesktopVRIK/IK/IKHandlers/IKHandler.cs index 85426b5..41fc869 100644 --- a/DesktopVRIK/IK/IKHandlers/IKHandler.cs +++ b/DesktopVRIK/IK/IKHandlers/IKHandler.cs @@ -1,4 +1,5 @@ -using ABI.CCK.Components; +using ABI_RC.Core.InteractionSystem; +using ABI.CCK.Components; using ABI_RC.Systems.IK.SubSystems; using NAK.DesktopVRIK.IK.VRIKHelpers; using RootMotion.FinalIK; @@ -143,10 +144,10 @@ internal abstract class IKHandler { _ikSimulatedRootAngle = _vrik.transform.eulerAngles.y; + _solver.Reset(); + if(ModSettings.EntryResetFootstepsOnIdle.Value) VRIKUtils.ResetToInitialFootsteps(_vrik, _locomotionData, _scaleDifference); - - _solver.Reset(); } #endregion diff --git a/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs b/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs index 6da0a63..120037f 100644 --- a/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs +++ b/DesktopVRIK/IK/IKHandlers/IKHandlerDesktop.cs @@ -107,10 +107,11 @@ internal class IKHandlerDesktop : IKHandler bool isProne = MovementSystem.Instance.prone; bool isFlying = MovementSystem.Instance.flying; bool isSitting = MovementSystem.Instance.sitting; + bool isSwimming = MovementSystem.Instance.GetSubmerged(); bool isStanding = PlayerSetup.Instance.avatarUpright >= Mathf.Max(PlayerSetup.Instance.avatarProneLimit, PlayerSetup.Instance.avatarCrouchLimit); - return !(isMoving || isCrouching || isProne || isFlying || isSitting || !isGrounded || !isStanding); + return !(isMoving || isCrouching || isProne || isFlying || isSwimming || isSitting || !isGrounded || !isStanding); } private void ResetSolverIfNeeded() diff --git a/DesktopVRIK/IK/IKManager.cs b/DesktopVRIK/IK/IKManager.cs index 1c06b0c..a04f3ee 100644 --- a/DesktopVRIK/IK/IKManager.cs +++ b/DesktopVRIK/IK/IKManager.cs @@ -2,6 +2,7 @@ using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using ABI_RC.Systems.IK.SubSystems; +using ABI_RC.Systems.MovementSystem; using NAK.DesktopVRIK.IK.IKHandlers; using NAK.DesktopVRIK.IK.VRIKHelpers; using RootMotion.FinalIK; @@ -29,7 +30,7 @@ public class IKManager : MonoBehaviour // Avatar Info private Animator _animator; - private Transform _hipTransform; + internal Transform _hipTransform; // Animator Info private int _animLocomotionLayer = -1; @@ -38,9 +39,9 @@ public class IKManager : MonoBehaviour private const string _ikposeLayerName = "IKPose"; // Pose Info - private HumanPoseHandler _humanPoseHandler; - private HumanPose _humanPose; - private HumanPose _humanPoseInitial; + internal HumanPoseHandler _humanPoseHandler; + internal HumanPose _humanPose; + internal HumanPose _humanPoseInitial; #endregion @@ -127,6 +128,8 @@ public class IKManager : MonoBehaviour if (_ikHandler == null) return false; + DesktopVRIK.Logger.Msg(scaleDifference); + _ikHandler.OnPlayerScaled(scaleDifference); return true; } @@ -204,6 +207,7 @@ public class IKManager : MonoBehaviour VRIKUtils.ApplyScaleToVRIK(_vrik, _ikHandler._locomotionData, 1f); _vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateGeneral); + _vrik.onPreSolverUpdate.AddListener(OnPreSolverUpdateDesktopSwimming); _vrik.onPostSolverUpdate.AddListener(OnPostSolverUpdateGeneral); } @@ -240,6 +244,35 @@ public class IKManager : MonoBehaviour #region VRIK Solver Events General + private void OnPreSolverUpdateDesktopSwimming() + { + if (_solver.IKPositionWeight < 0.9f) + return; + + Vector3 headPosition = _animator.GetBoneTransform(HumanBodyBones.Head).position; + + // rotate hips around head bone to simulate diving + if (MovementSystem.Instance._playerIsSubmerged) + { + const float maxAngleForward = 85f; + const float maxAngleBackward = -85f; + + float lookAngle = _desktopCamera.localEulerAngles.x; + if (lookAngle > 180) lookAngle -= 360; + + lookAngle = Mathf.Clamp(lookAngle, maxAngleBackward, maxAngleForward); + float multiplier = Mathf.Lerp(0f, 1f, (MovementSystem.Instance.movementVector.magnitude - 0.5f) * 2f); // blend in when moving w/ sprint + multiplier *= (-1f * MovementSystem.Instance.GetDepth()); // blend out when at surface + + _solver.IKPositionWeight = 1f - (-1f * multiplier); // disable IK completely when fast swimming (only applicable to DesktopVRIK) + _hipTransform.RotateAround(headPosition, _animator.transform.right, lookAngle * multiplier); + } + + // offset avatar hips so head bone is centered on avatar root + // this fixes animations becoming scrunched up once VRIK solves! + _hipTransform.position -= (headPosition - _animator.transform.position) with { y = 0f }; + } + private void OnPreSolverUpdateGeneral() { if (_solver.IKPositionWeight < 0.9f) diff --git a/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs b/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs index 81dc29d..7f0a839 100644 --- a/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs +++ b/DesktopVRIK/IK/VRIKHelpers/VRIKUtils.cs @@ -39,9 +39,9 @@ public static class VRIKUtils // hack, use parent transform instead as setting feet position moves root (root.parent), but does not work for VR var footsteps = vrik.solver.locomotion.footsteps; - footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft * scaleModifier), + footsteps[0].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosLeft), rootWorldRot * locomotionData.InitialFootRotLeft); - footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight * scaleModifier), + footsteps[1].Reset(rootWorldRot, root.TransformPoint(locomotionData.InitialFootPosRight), rootWorldRot * locomotionData.InitialFootRotRight); } diff --git a/DesktopVRIK/ModSettings.cs b/DesktopVRIK/ModSettings.cs index 8bb9016..ae0e33e 100644 --- a/DesktopVRIK/ModSettings.cs +++ b/DesktopVRIK/ModSettings.cs @@ -40,11 +40,4 @@ public static class ModSettings public static readonly MelonPreferences_Entry EntryProneThrusting = Category.CreateEntry("Prone Thrusting", false, description: "Allows Body Lean Weight to take effect while crouched or prone."); - - public static readonly MelonPreferences_Entry EntryNetIKPass = - Category.CreateEntry("Network IK Pass", true, description: "Should NetIK pass be applied? This fixes a bunch of small rotation errors after VRIK is run."); - - public static readonly MelonPreferences_Entry EntryIntegrationAMT = - Category.CreateEntry("AMT Integration", true, description: "Relies on AvatarMotionTweaker to handle VRIK Locomotion weights if available."); - } diff --git a/DesktopVRIK/Properties/AssemblyInfo.cs b/DesktopVRIK/Properties/AssemblyInfo.cs index 90a633e..0687004 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.7"; + public const string Version = "4.2.9"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/DesktopVRIK/format.json b/DesktopVRIK/format.json index ccbdfe5..4dbe4c1 100644 --- a/DesktopVRIK/format.json +++ b/DesktopVRIK/format.json @@ -1,8 +1,8 @@ { "_id": 117, "name": "DesktopVRIK", - "modversion": "4.2.7", - "gameversion": "2023r172", + "modversion": "4.2.9", + "gameversion": "2023r173", "loaderversion": "0.6.1", "modtype": "Mod", "author": "NotAKidoS", @@ -19,6 +19,6 @@ ], "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r22/DesktopVRIK.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopVRIK/", - "changelog": "- Fixed Prone Thrusting option ignoring set Body Leaning weight.\n- Potential fix for avatars feet randomly targeting far away while stutter-stepping.", + "changelog": "- Fixes for 2023r173.\n- Fixed ResetFootstepsOnIdle not working as intended.\n- Added swimming pitch control.\n- Added active body offset.", "embedcolor": "#9b59b6" } \ No newline at end of file