Skip to content

Commit

Permalink
Fully working animation override fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Feb 26, 2023
1 parent 3940802 commit fc60219
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
49 changes: 38 additions & 11 deletions ml_amt/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
}
}
4 changes: 2 additions & 2 deletions ml_amt/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MelonLoader.MelonPreferences_Entry> ms_entries = null;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions ml_amt/resources/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
</div>
<div class ="row-wrapper">
<div class ="option-caption">Prevent Unity animation override (chairs, etc.): </div>
<div class ="option-caption">Fix animation overrides (chairs, etc.): </div>
<div class ="option-input">
<div id="OverrideFix" class ="inp_toggle no-scroll" data-current="false"></div>
<div id="OverrideFix" class ="inp_toggle no-scroll" data-current="true"></div>
</div>
</div>
`;
Expand Down

0 comments on commit fc60219

Please sign in to comment.