From 19032650a32810e766d21174e0b262d5baf443ea Mon Sep 17 00:00:00 2001 From: SDraw Date: Fri, 28 Jul 2023 01:26:14 +0300 Subject: [PATCH] AMT fix --- README.md | 2 +- ml_amt/Main.cs | 19 +++++++++++++++++++ ml_amt/MotionTweaker.cs | 17 +++++++++++++++-- ml_amt/README.md | 5 +---- ml_amt/Utils.cs | 3 --- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9f85e30..47d03d7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Merged set of MelonLoader mods for ChilloutVR. **Table for game build 2022r171:** | Full name | Short name | Latest version | Available in [CVRMA](https://github.com/knah/CVRMelonAssistant) | |:---------:|:----------:|:--------------:| :----------------------------------------------------------------| -| [Avatar Motion Tweaker](/ml_amt/README.md) | ml_amt | - | ✔ Yes
:warning:Broken | +| [Avatar Motion Tweaker](/ml_amt/README.md) | ml_amt | 1.2.9 [:arrow_down:](../../releases/latest/download/ml_amt.dll)| ✔ Yes
:hourglass_flowing_sand: Update review | | [Desktop Head Tracking](/ml_dht/README.md)| ml_dht | - | ✔ Yes
:warning:Broken | | [Desktop Reticle Switch](/ml_drs/README.md)| ml_drs | 1.0.1 [:arrow_down:](../../releases/latest/download/ml_drs.dll)| ✔ Yes
:hourglass_flowing_sand: Update review | | [Extended Game Notifications](/ml_egn/README.md) | ml_egn | 1.0.3 [:arrow_down:](../../releases/latest/download/ml_egn.dll)| ✔ Yes
:hourglass_flowing_sand: Update review | diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 9b23677..56779f5 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -35,6 +35,11 @@ namespace ml_amt null, new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnCalibrate_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); + HarmonyInstance.Patch( + typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance), + null, + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) + ); // Fixes Fixes.AnimatorOverrideControllerFix.Init(HarmonyInstance); @@ -107,5 +112,19 @@ namespace ml_amt MelonLoader.MelonLogger.Error(l_exception); } } + + static void OnPlayspaceScale_Postfix() => ms_instance?.OnPlayspaceScale(); + void OnPlayspaceScale() + { + try + { + if(m_localTweaker != null) + m_localTweaker.OnPlayspaceScale(); + } + catch(Exception l_exception) + { + MelonLoader.MelonLogger.Error(l_exception); + } + } } } diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index d2db517..1c2bc7e 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -196,9 +196,17 @@ namespace ml_amt BodySystem.TrackingLeftLegEnabled = false; BodySystem.TrackingRightLegEnabled = false; BodySystem.TrackingLocomotionEnabled = true; + + IKSystem.Instance.applyOriginalHipRotation = true; } } + internal void OnPlayspaceScale() + { + if((m_vrIk != null) && Settings.MassCenter) + m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale(); + } + // IK events void OnIKPreUpdate() { @@ -239,15 +247,20 @@ namespace ml_amt } bool l_solverActive = !Mathf.Approximately(m_vrIk.solver.IKPositionWeight, 0f); - if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (PlayerSetup.Instance.avatarUpright <= PlayerSetup.Instance.avatarProneLimit)) && m_inVR && !BodySystem.isCalibratedAsFullBody && !ModSupporter.SkipHipsOverride()) + if(l_locomotionOverride && l_solverActive && m_followHips && (!m_moving || (PlayerSetup.Instance.avatarUpright <= PlayerSetup.Instance.avatarCrouchLimit)) && m_inVR && !BodySystem.isCalibratedAsFullBody && !ModSupporter.SkipHipsOverride()) { m_vrIk.solver.plantFeet = false; - IKSystem.VrikRootController.enabled = false; + if(IKSystem.VrikRootController != null) + IKSystem.VrikRootController.enabled = false; PlayerSetup.Instance._avatar.transform.localPosition = m_hipsToPlayer; } if(m_locomotionOverride && !l_locomotionOverride) + { m_vrIk.solver.Reset(); + if(IKSystem.VrikRootController != null) + IKSystem.VrikRootController.enabled = true; + } m_locomotionOverride = l_locomotionOverride; } diff --git a/ml_amt/README.md b/ml_amt/README.md index 4de548c..7732bdf 100644 --- a/ml_amt/README.md +++ b/ml_amt/README.md @@ -37,7 +37,4 @@ Available additional parameters for AAS animator: * Note: Can be set as local-only (not synced) if starts with `#` character. Additional mod's behaviour: -* Overrides and fixes IK behaviour in 4PT mode (head, hands and hips). - -# NOTE -This is testing update for game build r171, not ready for massive usage yet! \ No newline at end of file +* Overrides and fixes IK behaviour in 4PT mode (head, hands and hips). \ No newline at end of file diff --git a/ml_amt/Utils.cs b/ml_amt/Utils.cs index 2117d9b..729c2b5 100644 --- a/ml_amt/Utils.cs +++ b/ml_amt/Utils.cs @@ -13,7 +13,6 @@ namespace ml_amt static readonly FieldInfo ms_groundedRaw = typeof(MovementSystem).GetField("_isGroundedRaw", BindingFlags.NonPublic | BindingFlags.Instance); static readonly FieldInfo ms_hasToes = typeof(IKSolverVR).GetField("hasToes", BindingFlags.NonPublic | BindingFlags.Instance); static MethodInfo ms_getSineKeyframes = typeof(IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static); - static FieldInfo ms_cohtmlView = typeof(CohtmlControlledViewDisposable).GetField("_view", BindingFlags.NonPublic | BindingFlags.Instance); public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); @@ -47,8 +46,6 @@ namespace ml_amt return l_result; } - public static void ExecuteScript(this CohtmlControlledViewDisposable p_instance, string p_script) => ((cohtml.Net.View)ms_cohtmlView.GetValue(p_instance))?.ExecuteScript(p_script); - // Engine extensions public static Matrix4x4 GetMatrix(this Transform p_transform, bool p_pos = true, bool p_rot = true, bool p_scl = false) {