From fc60219a4ecabf2eb90d71a47d57ba42bc8589db Mon Sep 17 00:00:00 2001 From: SDraw Date: Sun, 26 Feb 2023 21:49:51 +0300 Subject: [PATCH] Fully working animation override fix --- ml_amt/Main.cs | 49 +++++++++++++++++++++++++++++++--------- ml_amt/Settings.cs | 4 ++-- ml_amt/resources/menu.js | 4 ++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 4b6f999..3a1ea73 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -75,16 +75,16 @@ public override void OnInitializeMelon() null ); - // AAS overriding "fix" + // AAS overriding fix HarmonyInstance.Patch( - typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation), BindingFlags.Instance), - new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAnimationOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), - null + typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.SetOverrideAnimation)), + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); HarmonyInstance.Patch( typeof(CVRAnimatorManager).GetMethod(nameof(CVRAnimatorManager.RestoreOverrideAnimation)), - new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnAnimationOverrideRestore_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), - null + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Prefix), BindingFlags.Static | BindingFlags.NonPublic)), + new HarmonyLib.HarmonyMethod(typeof(AvatarMotionTweaker).GetMethod(nameof(OnOverride_Postfix), BindingFlags.Static | BindingFlags.NonPublic)) ); MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer()); @@ -256,14 +256,41 @@ Vector3 ____colliderCenter return false; } - static bool OnAnimationOverride_Prefix() + static void OnOverride_Prefix(ref CVRAnimatorManager __instance) { - return !Settings.OverrideFix; + try + { + if(Settings.OverrideFix) + { + if(__instance.animator != null) + { + __instance.animator.enabled = false; + __instance.animator.WriteDefaultValues(); + } + } + } + catch(System.Exception l_exception) + { + MelonLoader.MelonLogger.Error(l_exception); + } } - - static bool OnAnimationOverrideRestore_Prefix() + static void OnOverride_Postfix(ref CVRAnimatorManager __instance) { - return !Settings.OverrideFix; + try + { + if(Settings.OverrideFix) + { + if(__instance.animator != null) + { + __instance.animator.enabled = true; + __instance.animator.Update(0f); + } + } + } + catch(System.Exception l_exception) + { + MelonLoader.MelonLogger.Error(l_exception); + } } } } diff --git a/ml_amt/Settings.cs b/ml_amt/Settings.cs index c01f273..8a2cb9b 100644 --- a/ml_amt/Settings.cs +++ b/ml_amt/Settings.cs @@ -36,7 +36,7 @@ enum ModSetting static bool ms_followHips = true; static bool ms_collisionScale = true; static bool ms_massCenter = true; - static bool ms_overrideFix = false; + static bool ms_overrideFix = true; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -73,7 +73,7 @@ internal static void Init() ms_category.CreateEntry(ModSetting.FollowHips.ToString(), true), ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), true), ms_category.CreateEntry(ModSetting.MassCenter.ToString(), true), - ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), false) + ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), true) }; Load(); diff --git a/ml_amt/resources/menu.js b/ml_amt/resources/menu.js index 8e1e71c..9298fff 100644 --- a/ml_amt/resources/menu.js +++ b/ml_amt/resources/menu.js @@ -265,9 +265,9 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
-
Prevent Unity animation override (chairs, etc.):
+
Fix animation overrides (chairs, etc.):
-
+
`;