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
|
public static class BadAnimatorFixManager
|
||||||
{
|
{
|
||||||
private static List<BadAnimatorFixer> _animatorFixers = new List<BadAnimatorFixer>();
|
private static List<BadAnimatorFixer> _animatorFixers = new List<BadAnimatorFixer>();
|
||||||
|
private static readonly float _checkInterval = 5f;
|
||||||
private static int _currentIndex = 0;
|
private static int _currentIndex = 0;
|
||||||
private static float _checkInterval = 5f;
|
|
||||||
|
|
||||||
public static void Add(BadAnimatorFixer bad)
|
public static void Add(BadAnimatorFixer bad)
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ public static class BadAnimatorFixManager
|
||||||
|
|
||||||
public static void OnPlayerLoaded()
|
public static void OnPlayerLoaded()
|
||||||
{
|
{
|
||||||
ToggleJob(BadAnimatorFix.EntryEnabled.Value);
|
SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, _checkInterval, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OnSceneInitialized(string sceneName)
|
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
|
// Ignore objects that have our "fix", this shouldn't be needed but eh
|
||||||
if (!animator.TryGetComponent<BadAnimatorFixer>(out _))
|
if (!animator.TryGetComponent<BadAnimatorFixer>(out _))
|
||||||
{
|
|
||||||
animator.gameObject.AddComponent<BadAnimatorFixer>();
|
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 (!BadAnimatorFix.EntryEnabled.Value)
|
||||||
if (enable && job == null)
|
return;
|
||||||
{
|
|
||||||
SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, _checkInterval, -1);
|
if (_animatorFixers.Count == 0)
|
||||||
}
|
return;
|
||||||
else if (!enable && job != null)
|
|
||||||
{
|
|
||||||
SchedulerSystem.RemoveJob(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CheckNextAnimator()
|
|
||||||
{
|
|
||||||
if (_animatorFixers.Count == 0) return;
|
|
||||||
_currentIndex = (_currentIndex + 1) % _animatorFixers.Count;
|
_currentIndex = (_currentIndex + 1) % _animatorFixers.Count;
|
||||||
|
_animatorFixers[_currentIndex].AttemptRewindAnimator();
|
||||||
BadAnimatorFixer currentAnimatorFix = _animatorFixers[_currentIndex];
|
|
||||||
currentAnimatorFix.AttemptRewindAnimator();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ public class BadAnimatorFixer : MonoBehaviour
|
||||||
// Skip if mid-transition
|
// Skip if mid-transition
|
||||||
if (transitionInfo.fullPathHash != 0) continue;
|
if (transitionInfo.fullPathHash != 0) continue;
|
||||||
// Skip if anim doesn't loop, or hasn't looped enough
|
// 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
|
// Rewind state, with 10f as buffer, to account for reasonable use of ExitTime
|
||||||
float offset = 10f + (stateInfo.normalizedTime % 1f);
|
float offset = 10f + (stateInfo.normalizedTime % 1f);
|
||||||
animator.Play(stateInfo.fullPathHash, layerIndex, offset);
|
animator.Play(stateInfo.fullPathHash, layerIndex, offset);
|
||||||
|
|
|
@ -27,7 +27,6 @@ public class BadAnimatorFix : MelonMod
|
||||||
public override void OnInitializeMelon()
|
public override void OnInitializeMelon()
|
||||||
{
|
{
|
||||||
Logger = LoggerInstance;
|
Logger = LoggerInstance;
|
||||||
EntryEnabled.OnEntryValueChanged.Subscribe(OnEntryEnabledChanged);
|
|
||||||
ApplyPatches(typeof(HarmonyPatches.AnimatorPatches));
|
ApplyPatches(typeof(HarmonyPatches.AnimatorPatches));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +38,6 @@ public class BadAnimatorFix : MelonMod
|
||||||
BadAnimatorFixManager.OnSceneInitialized(sceneName);
|
BadAnimatorFixManager.OnSceneInitialized(sceneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEntryEnabledChanged(bool newValue, bool oldValue)
|
|
||||||
{
|
|
||||||
BadAnimatorFixManager.ToggleJob(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ApplyPatches(Type type)
|
private void ApplyPatches(Type type)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -27,6 +27,6 @@ using System.Reflection;
|
||||||
namespace NAK.BadAnimatorFix.Properties;
|
namespace NAK.BadAnimatorFix.Properties;
|
||||||
internal static class AssemblyInfoParams
|
internal static class AssemblyInfoParams
|
||||||
{
|
{
|
||||||
public const string Version = "1.0.2";
|
public const string Version = "1.0.3";
|
||||||
public const string Author = "NotAKidoS";
|
public const string Author = "NotAKidoS";
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"_id": 152,
|
"_id": 152,
|
||||||
"name": "BadAnimatorFix",
|
"name": "BadAnimatorFix",
|
||||||
"modversion": "1.0.2",
|
"modversion": "1.0.3",
|
||||||
"gameversion": "2023r171",
|
"gameversion": "2023r171",
|
||||||
"loaderversion": "0.6.1",
|
"loaderversion": "0.6.1",
|
||||||
"modtype": "Mod",
|
"modtype": "Mod",
|
||||||
"author": "NotAKidoS",
|
"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": [
|
"searchtags": [
|
||||||
"bad",
|
"bad",
|
||||||
"fix",
|
"fix",
|
||||||
|
@ -16,8 +16,8 @@
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"None"
|
"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/",
|
"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"
|
"embedcolor": "#e25352"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue