mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[BadAnimatorFix] Don't touch non-loop states.
This commit is contained in:
parent
935639a2f3
commit
ab4276e880
5 changed files with 16 additions and 34 deletions
|
@ -7,8 +7,8 @@ namespace NAK.BadAnimatorFix;
|
|||
public static class BadAnimatorFixManager
|
||||
{
|
||||
private static List<BadAnimatorFixer> _animatorFixers = new List<BadAnimatorFixer>();
|
||||
private static readonly float _checkInterval = 5f;
|
||||
private static int _currentIndex = 0;
|
||||
private static float _checkInterval = 5f;
|
||||
|
||||
public static void Add(BadAnimatorFixer bad)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@ public static class BadAnimatorFixManager
|
|||
|
||||
public static void OnPlayerLoaded()
|
||||
{
|
||||
ToggleJob(BadAnimatorFix.EntryEnabled.Value);
|
||||
SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, _checkInterval, -1);
|
||||
}
|
||||
|
||||
public static void OnSceneInitialized(string sceneName)
|
||||
|
@ -37,31 +37,19 @@ public static class BadAnimatorFixManager
|
|||
{
|
||||
// Ignore objects that have our "fix", this shouldn't be needed but eh
|
||||
if (!animator.TryGetComponent<BadAnimatorFixer>(out _))
|
||||
{
|
||||
animator.gameObject.AddComponent<BadAnimatorFixer>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ToggleJob(bool enable)
|
||||
private static void CheckNextAnimator()
|
||||
{
|
||||
var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == nameof(CheckNextAnimator)).Job;
|
||||
if (enable && job == null)
|
||||
{
|
||||
SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, _checkInterval, -1);
|
||||
}
|
||||
else if (!enable && job != null)
|
||||
{
|
||||
SchedulerSystem.RemoveJob(job);
|
||||
}
|
||||
}
|
||||
if (!BadAnimatorFix.EntryEnabled.Value)
|
||||
return;
|
||||
|
||||
if (_animatorFixers.Count == 0)
|
||||
return;
|
||||
|
||||
static void CheckNextAnimator()
|
||||
{
|
||||
if (_animatorFixers.Count == 0) return;
|
||||
_currentIndex = (_currentIndex + 1) % _animatorFixers.Count;
|
||||
|
||||
BadAnimatorFixer currentAnimatorFix = _animatorFixers[_currentIndex];
|
||||
currentAnimatorFix.AttemptRewindAnimator();
|
||||
_animatorFixers[_currentIndex].AttemptRewindAnimator();
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ public class BadAnimatorFixer : MonoBehaviour
|
|||
// Skip if mid-transition
|
||||
if (transitionInfo.fullPathHash != 0) continue;
|
||||
// Skip if anim doesn't loop, or hasn't looped enough
|
||||
if (stateInfo.normalizedTime < StateLimit) continue;
|
||||
if (!stateInfo.loop || stateInfo.normalizedTime < StateLimit) continue;
|
||||
// Rewind state, with 10f as buffer, to account for reasonable use of ExitTime
|
||||
float offset = 10f + (stateInfo.normalizedTime % 1f);
|
||||
animator.Play(stateInfo.fullPathHash, layerIndex, offset);
|
||||
|
|
|
@ -27,7 +27,6 @@ public class BadAnimatorFix : MelonMod
|
|||
public override void OnInitializeMelon()
|
||||
{
|
||||
Logger = LoggerInstance;
|
||||
EntryEnabled.OnEntryValueChanged.Subscribe(OnEntryEnabledChanged);
|
||||
ApplyPatches(typeof(HarmonyPatches.AnimatorPatches));
|
||||
}
|
||||
|
||||
|
@ -39,11 +38,6 @@ public class BadAnimatorFix : MelonMod
|
|||
BadAnimatorFixManager.OnSceneInitialized(sceneName);
|
||||
}
|
||||
|
||||
private void OnEntryEnabledChanged(bool newValue, bool oldValue)
|
||||
{
|
||||
BadAnimatorFixManager.ToggleJob(newValue);
|
||||
}
|
||||
|
||||
private void ApplyPatches(Type type)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -27,6 +27,6 @@ using System.Reflection;
|
|||
namespace NAK.BadAnimatorFix.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.2";
|
||||
public const string Version = "1.0.3";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"_id": 152,
|
||||
"name": "BadAnimatorFix",
|
||||
"modversion": "1.0.2",
|
||||
"modversion": "1.0.3",
|
||||
"gameversion": "2023r171",
|
||||
"loaderversion": "0.6.1",
|
||||
"modtype": "Mod",
|
||||
"author": "NotAKidoS",
|
||||
"description": "This mod occasionally rewinds animation states that have loop enabled.\n\nUnity seems to have a weird quirk where *sometimes* animations with loop cause performance issues after running for a long time.\nYou'll only start to notice this after a few hours to a few days of idling.\n\nIf you don't happen to be AFK for long periods of time, you probably don't need this mod. This issue seems to be primarily caused by one-two frame animation clips meant for toggles with loop needlessly enabled.",
|
||||
"description": "This mod periodically rewinds looping animation states.\nIt resolves issues with locomotion animations freezing after extended AFK periods.\nIf you aren't AFK frequently, this mod might not be essential for you.",
|
||||
"searchtags": [
|
||||
"bad",
|
||||
"fix",
|
||||
|
@ -16,8 +16,8 @@
|
|||
"requirements": [
|
||||
"None"
|
||||
],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r17/BadAnimatorFix.dll",
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r18/BadAnimatorFix.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/BadAnimatorFix/",
|
||||
"changelog": "- Fixes for 2023r171.\n- Removed speculative menu fix option. It is no longer needed as menu clips no longer loop.",
|
||||
"changelog": "- No longer rewinds states without loop specifically enabled.\n- Removed performance improvement claim, which has seemingly been fixed in 2021.\n- Fixed not being able to disable mod with the Enabled button.",
|
||||
"embedcolor": "#e25352"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue