diff --git a/BadAnimatorFix/BadAnimatorFixManager.cs b/BadAnimatorFix/BadAnimatorFixManager.cs index fea5268..80ec252 100644 --- a/BadAnimatorFix/BadAnimatorFixManager.cs +++ b/BadAnimatorFix/BadAnimatorFixManager.cs @@ -7,8 +7,8 @@ namespace NAK.BadAnimatorFix; public static class BadAnimatorFixManager { private static List _animatorFixers = new List(); + 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(out _)) - { animator.gameObject.AddComponent(); - } } } - 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(); } -} +} \ No newline at end of file diff --git a/BadAnimatorFix/BadAnimatorFixer.cs b/BadAnimatorFix/BadAnimatorFixer.cs index c1b648f..1a5593d 100644 --- a/BadAnimatorFix/BadAnimatorFixer.cs +++ b/BadAnimatorFix/BadAnimatorFixer.cs @@ -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); diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs index f74567c..0710cb0 100644 --- a/BadAnimatorFix/Main.cs +++ b/BadAnimatorFix/Main.cs @@ -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 diff --git a/BadAnimatorFix/Properties/AssemblyInfo.cs b/BadAnimatorFix/Properties/AssemblyInfo.cs index 6814221..582d499 100644 --- a/BadAnimatorFix/Properties/AssemblyInfo.cs +++ b/BadAnimatorFix/Properties/AssemblyInfo.cs @@ -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"; } \ No newline at end of file diff --git a/BadAnimatorFix/format.json b/BadAnimatorFix/format.json index 385b7e6..957ad0f 100644 --- a/BadAnimatorFix/format.json +++ b/BadAnimatorFix/format.json @@ -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" } \ No newline at end of file