From 41f8db5dcf48c8a15f9f6db24ee6a91c952cfaad Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:10:37 -0500 Subject: [PATCH 01/12] Initial commit --- .gitattributes | 2 + .gitignore | 398 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 21 +++ README.md | 2 + 4 files changed, 423 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..426d76d --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4480281 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 NotAKidoS + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c6fb5e2 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# BadAnimatorFix + A bad fix for a neiche issue. Is it really even a fix? From 83c101f5eeaad4bc81d595fddc751b547f9bf6aa Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:17:36 -0500 Subject: [PATCH 02/12] i dont know what im doing implement shit fix for shit problem --- BadAnimatorFix/BadAnimatorFix.cs | 72 +++++++++++++++++++++++ BadAnimatorFix/BadAnimatorFix.csproj | 70 ++++++++++++++++++++++ BadAnimatorFix/BadAnimatorFix.sln | 25 ++++++++ BadAnimatorFix/HarmonyPatches.cs | 63 ++++++++++++++++++++ BadAnimatorFix/Main.cs | 47 +++++++++++++++ BadAnimatorFix/Properties/AssemblyInfo.cs | 30 ++++++++++ BadAnimatorFix/format.json | 23 ++++++++ 7 files changed, 330 insertions(+) create mode 100644 BadAnimatorFix/BadAnimatorFix.cs create mode 100644 BadAnimatorFix/BadAnimatorFix.csproj create mode 100644 BadAnimatorFix/BadAnimatorFix.sln create mode 100644 BadAnimatorFix/HarmonyPatches.cs create mode 100644 BadAnimatorFix/Main.cs create mode 100644 BadAnimatorFix/Properties/AssemblyInfo.cs create mode 100644 BadAnimatorFix/format.json diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs new file mode 100644 index 0000000..15a4bb2 --- /dev/null +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -0,0 +1,72 @@ +using UnityEngine; +using UnityEngine.Playables; + +namespace NAK.Melons.BadAnimatorFix; + +public class BadAnimatorFix : MonoBehaviour +{ + private float stateLimit = 20f; + private Animator animator; + private Playable playable; + + private void Start() + { + animator = GetComponent(); + playable = animator.playableGraph.GetRootPlayable(0); + } + + private void Update() + { + if (!BadAnimatorFixMod.EntryEnabled.Value) return; + if (playable.IsValid() && GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value) + { + RewindAnimator(); + BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); + } + } + + private double GetTime() + { + return PlayableExtensions.IsValid(playable) ? PlayableExtensions.GetTime(playable) : -1; + } + + private void RewindAnimator() + { + PlayableExtensions.SetTime(playable, 0); + for (int i = 0; i < animator.layerCount; i++) + { + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); + AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(i); + // 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; + // Rewind state, with 10f as buffer, to account for reasonable use of ExitTime + float offset = 10f + (stateInfo.normalizedTime % 1f); + animator.Play(stateInfo.fullPathHash, i, offset); + } + } + + private float GetNormalizedTime() + { + float time = 0f; + for (int i = 0; i < animator.layerCount; i++) + { + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); + time += stateInfo.normalizedTime; + } + return time; + } + + private float GetMaxNormalizedTime() + { + float time = 0f; + for (int i = 0; i < animator.layerCount; i++) + { + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); + if (time < stateInfo.normalizedTime) + time = stateInfo.normalizedTime; + } + return time; + } +} diff --git a/BadAnimatorFix/BadAnimatorFix.csproj b/BadAnimatorFix/BadAnimatorFix.csproj new file mode 100644 index 0000000..e4c8455 --- /dev/null +++ b/BadAnimatorFix/BadAnimatorFix.csproj @@ -0,0 +1,70 @@ + + + + + netstandard2.1 + enable + latest + false + + + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Aura2_Core.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\UIExpansionKit.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.Postprocessing.Runtime.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Unity.TextMeshPro.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.VRModule.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll + + + + + + + + + diff --git a/BadAnimatorFix/BadAnimatorFix.sln b/BadAnimatorFix/BadAnimatorFix.sln new file mode 100644 index 0000000..83f9cfb --- /dev/null +++ b/BadAnimatorFix/BadAnimatorFix.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BadAnimatorFix", "BadAnimatorFix.csproj", "{36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36FB9A18-B03E-45F6-9EF5-A276D2FFFC2B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {61C931D9-0377-4934-BF85-FCEB9A40547E} + EndGlobalSection +EndGlobal diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs new file mode 100644 index 0000000..11bac03 --- /dev/null +++ b/BadAnimatorFix/HarmonyPatches.cs @@ -0,0 +1,63 @@ +using ABI.CCK.Components; +using ABI_RC.Core.InteractionSystem; +using HarmonyLib; +using UnityEngine; + +namespace NAK.Melons.BadAnimatorFix.HarmonyPatches; + +internal class AnimatorPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(CVRAvatar), "Start")] + private static void Post_CVRAvatar_Start(CVRAvatar __instance) + { + if (!BadAnimatorFixMod.EntryCVRAvatar.Value) return; + AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(CVRSpawnable), "Start")] + private static void Post_CVRSpawnable_Start(CVRSpawnable __instance) + { + if (!BadAnimatorFixMod.EntryCVRSpawnable.Value) return; + AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(CVRWorld), "Start")] + private static void Post_CVRWorld_Start(CVRWorld __instance) + { + if (!BadAnimatorFixMod.EntryCVRWorld.Value) return; + AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); + } + + //Set QM stuff + [HarmonyPostfix] + [HarmonyPatch(typeof(CVR_MenuManager), "Start")] + private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor) + { + if (!BadAnimatorFixMod.EntryMenus.Value) return; + AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); + } + + //Set MM stuff + [HarmonyPostfix] + [HarmonyPatch(typeof(ViewManager), "Start")] + private static void Postfix_ViewManager_Start(ref ViewManager __instance) + { + if (!BadAnimatorFixMod.EntryMenus.Value) return; + AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); + } + + private static void AddBadAnimatorFixComponentIfAnimatorExists(GameObject gameObject) + { + if (!BadAnimatorFixMod.EntryEnabled.Value) return; + Animator[] animators = gameObject.GetComponentsInChildren(); + foreach (Animator animator in animators.Where(a => a.gameObject.GetComponent() == null)) + { + if (animator.runtimeAnimatorController != null) + animator.gameObject.AddComponent(); + } + } +} + diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs new file mode 100644 index 0000000..14463ac --- /dev/null +++ b/BadAnimatorFix/Main.cs @@ -0,0 +1,47 @@ +using MelonLoader; + +namespace NAK.Melons.BadAnimatorFix; + +public class BadAnimatorFixMod : MelonMod +{ + internal static MelonLogger.Instance Logger; + public const string SettingsCategory = "BadAnimatorFix"; + public static readonly MelonPreferences_Category CategoryBadAnimatorFix = MelonPreferences.CreateCategory(SettingsCategory); + + public static readonly MelonPreferences_Entry EntryEnabled = + CategoryBadAnimatorFix.CreateEntry("Enabled", true, description: "Toggle BadAnimatorFix entirely. Requires avatar/spawnable/world reload."); + + public static readonly MelonPreferences_Entry EntryCVRAvatar = + CategoryBadAnimatorFix.CreateEntry("Add to CVRAvatar", true, description: "Should BadAnimatorFix run for CVRAvatar? Requires avatar reload."); + + public static readonly MelonPreferences_Entry EntryCVRSpawnable = + CategoryBadAnimatorFix.CreateEntry("Add to CVRSpawnable", false, description: "Should BadAnimatorFix run for CVRSpawnable? Requires spawnable reload."); + + public static readonly MelonPreferences_Entry EntryCVRWorld = + CategoryBadAnimatorFix.CreateEntry("Add to CVRWorld", false, description: "Should BadAnimatorFix run for CVRWorld? Requires world reload."); + + public static readonly MelonPreferences_Entry EntryMenus = + CategoryBadAnimatorFix.CreateEntry("Add to Menus", false, description: "Should BadAnimatorFix run for QM & MM? Requires game restart."); + + public static readonly MelonPreferences_Entry EntryPlayableTimeLimit = + CategoryBadAnimatorFix.CreateEntry("Playable Time Limit", 600f, description: "How long in seconds can a Playable play for before rewinding its states."); + + public override void OnInitializeMelon() + { + Logger = LoggerInstance; + ApplyPatches(typeof(HarmonyPatches.AnimatorPatches)); + } + + private void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + Logger.Msg($"Failed while patching {type.Name}!"); + Logger.Error(e); + } + } +} \ No newline at end of file diff --git a/BadAnimatorFix/Properties/AssemblyInfo.cs b/BadAnimatorFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4b98794 --- /dev/null +++ b/BadAnimatorFix/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using MelonLoader; +using NAK.Melons.BadAnimatorFix.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.Melons.BadAnimatorFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.Melons.BadAnimatorFix))] + +[assembly: MelonInfo( + typeof(NAK.Melons.BadAnimatorFix.BadAnimatorFixMod), + nameof(NAK.Melons.BadAnimatorFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/BadAnimatorFix" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace NAK.Melons.BadAnimatorFix.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/BadAnimatorFix/format.json b/BadAnimatorFix/format.json new file mode 100644 index 0000000..7d05f54 --- /dev/null +++ b/BadAnimatorFix/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "TrackedControllerFix", + "modversion": "1.0.0", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.", + "searchtags": [ + "vr", + "quest", + "controller", + "tracking" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/releases/download/v1.0.0/TrackedControllerFix.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/", + "changelog": "Initial Release", + "embedcolor": "3498db" +} \ No newline at end of file From 1acf58d16143c9f004703bb158d050de2fd04a30 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:17:53 -0500 Subject: [PATCH 03/12] idk --- BadAnimatorFix/BadAnimatorFix.cs | 47 ++++++--------------- BadAnimatorFix/BadAnimatorFix.csproj | 3 +- BadAnimatorFix/BadAnimatorFixManager.cs | 54 +++++++++++++++++++++++++ BadAnimatorFix/HarmonyPatches.cs | 6 +-- BadAnimatorFix/Main.cs | 16 ++++++++ 5 files changed, 88 insertions(+), 38 deletions(-) create mode 100644 BadAnimatorFix/BadAnimatorFixManager.cs diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs index 15a4bb2..5fb5e76 100644 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -5,34 +5,30 @@ namespace NAK.Melons.BadAnimatorFix; public class BadAnimatorFix : MonoBehaviour { - private float stateLimit = 20f; + private float stateLimit = 50f; private Animator animator; private Playable playable; - private void Start() + void Start() { animator = GetComponent(); playable = animator.playableGraph.GetRootPlayable(0); + BadAnimatorFixManager.Add(this); } - private void Update() + void OnDestroy() { - if (!BadAnimatorFixMod.EntryEnabled.Value) return; - if (playable.IsValid() && GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value) - { - RewindAnimator(); - BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); - } + BadAnimatorFixManager.Remove(this); } - private double GetTime() + public double GetTime() { return PlayableExtensions.IsValid(playable) ? PlayableExtensions.GetTime(playable) : -1; } - private void RewindAnimator() + public void AttemptRewindAnimator() { - PlayableExtensions.SetTime(playable, 0); + bool rewound = false; for (int i = 0; i < animator.layerCount; i++) { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); @@ -42,31 +38,14 @@ public class BadAnimatorFix : MonoBehaviour // Skip if anim doesn't loop, or hasn't looped enough if (stateInfo.normalizedTime <= stateLimit) continue; // Rewind state, with 10f as buffer, to account for reasonable use of ExitTime + rewound = true; float offset = 10f + (stateInfo.normalizedTime % 1f); animator.Play(stateInfo.fullPathHash, i, offset); } - } - - private float GetNormalizedTime() - { - float time = 0f; - for (int i = 0; i < animator.layerCount; i++) + if (rewound) { - AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); - time += stateInfo.normalizedTime; + PlayableExtensions.SetTime(playable, 0); + BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); } - return time; } - - private float GetMaxNormalizedTime() - { - float time = 0f; - for (int i = 0; i < animator.layerCount; i++) - { - AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); - if (time < stateInfo.normalizedTime) - time = stateInfo.normalizedTime; - } - return time; - } -} +} \ No newline at end of file diff --git a/BadAnimatorFix/BadAnimatorFix.csproj b/BadAnimatorFix/BadAnimatorFix.csproj index e4c8455..040f29a 100644 --- a/BadAnimatorFix/BadAnimatorFix.csproj +++ b/BadAnimatorFix/BadAnimatorFix.csproj @@ -6,6 +6,7 @@ enable latest false + True @@ -13,7 +14,7 @@ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + ..\..\FuckCohtml\FuckMetrics\ManagedLibs\Assembly-CSharp.dll C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll diff --git a/BadAnimatorFix/BadAnimatorFixManager.cs b/BadAnimatorFix/BadAnimatorFixManager.cs new file mode 100644 index 0000000..b4c4d66 --- /dev/null +++ b/BadAnimatorFix/BadAnimatorFixManager.cs @@ -0,0 +1,54 @@ +using ABI_RC.Core.IO; + +namespace NAK.Melons.BadAnimatorFix; + +public static class BadAnimatorFixManager +{ + public static List badAnimatorFixes = new List(); + private static int currentIndex = 0; + + public static void Add(BadAnimatorFix bad) + { + if (!badAnimatorFixes.Contains(bad)) + { + badAnimatorFixes.Add(bad); + } + } + + public static void Remove(BadAnimatorFix bad) + { + if (badAnimatorFixes.Contains(bad)) + { + badAnimatorFixes.Remove(bad); + } + } + + // Runs every 5 seconds to see if an animator has played longer than PlayableTimeLimit + public static void CheckNextAnimator() + { + if (badAnimatorFixes.Count == 0) return; + + if (currentIndex >= badAnimatorFixes.Count) currentIndex = 0; + + BadAnimatorFix currentAnimatorFix = badAnimatorFixes[currentIndex]; + if (currentAnimatorFix.GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value) + { + currentAnimatorFix.AttemptRewindAnimator(); + } + + currentIndex++; + } + + public static void ToggleJob(bool enable) + { + var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "CheckNextAnimator").Job; + if (enable && job == null) + { + SchedulerSystem.AddJob(new SchedulerSystem.Job(BadAnimatorFixManager.CheckNextAnimator), 0f, 5f, -1); + } + else if (!enable && job != null) + { + SchedulerSystem.RemoveJob(job); + } + } +} diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs index 11bac03..c281f64 100644 --- a/BadAnimatorFix/HarmonyPatches.cs +++ b/BadAnimatorFix/HarmonyPatches.cs @@ -2,6 +2,7 @@ using ABI_RC.Core.InteractionSystem; using HarmonyLib; using UnityEngine; +using ABI_RC.Core.IO; namespace NAK.Melons.BadAnimatorFix.HarmonyPatches; @@ -51,7 +52,7 @@ internal class AnimatorPatches private static void AddBadAnimatorFixComponentIfAnimatorExists(GameObject gameObject) { - if (!BadAnimatorFixMod.EntryEnabled.Value) return; + //if (!BadAnimatorFixMod.EntryEnabled.Value) return; Animator[] animators = gameObject.GetComponentsInChildren(); foreach (Animator animator in animators.Where(a => a.gameObject.GetComponent() == null)) { @@ -59,5 +60,4 @@ internal class AnimatorPatches animator.gameObject.AddComponent(); } } -} - +} \ No newline at end of file diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs index 14463ac..eba99a7 100644 --- a/BadAnimatorFix/Main.cs +++ b/BadAnimatorFix/Main.cs @@ -1,4 +1,6 @@ using MelonLoader; +using System.Collections; +using ABI_RC.Core.Player; namespace NAK.Melons.BadAnimatorFix; @@ -29,7 +31,21 @@ public class BadAnimatorFixMod : MelonMod public override void OnInitializeMelon() { Logger = LoggerInstance; + EntryEnabled.OnEntryValueChangedUntyped.Subscribe(OnEnabled); ApplyPatches(typeof(HarmonyPatches.AnimatorPatches)); + MelonCoroutines.Start(WaitForLocalPlayer()); + } + + private IEnumerator WaitForLocalPlayer() + { + while (PlayerSetup.Instance == null) + yield return null; + BadAnimatorFixManager.ToggleJob(EntryEnabled.Value); + } + + private void OnEnabled(object arg1, object arg2) + { + BadAnimatorFixManager.ToggleJob(EntryEnabled.Value); } private void ApplyPatches(Type type) From 38445efae3f5ee218c670439f0ca0202e5bf8a9b Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 18:33:36 -0500 Subject: [PATCH 04/12] not really sure --- BadAnimatorFix/BadAnimatorFix.cs | 57 ++++++++++++------------- BadAnimatorFix/BadAnimatorFixManager.cs | 40 ++++++++++------- BadAnimatorFix/HarmonyPatches.cs | 25 ++++------- BadAnimatorFix/Main.cs | 20 ++++----- BadAnimatorFix/format.json | 18 ++++---- 5 files changed, 77 insertions(+), 83 deletions(-) diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs index 5fb5e76..f1cb6f6 100644 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -2,50 +2,49 @@ using UnityEngine.Playables; namespace NAK.Melons.BadAnimatorFix; - public class BadAnimatorFix : MonoBehaviour { - private float stateLimit = 50f; - private Animator animator; - private Playable playable; + private const float StateLimit = 20f; - void Start() + private Animator animator; + + private void Start() { animator = GetComponent(); - playable = animator.playableGraph.GetRootPlayable(0); - BadAnimatorFixManager.Add(this); } - void OnDestroy() - { - BadAnimatorFixManager.Remove(this); - } - - public double GetTime() - { - return PlayableExtensions.IsValid(playable) ? PlayableExtensions.GetTime(playable) : -1; - } + private void OnEnable() => BadAnimatorFixManager.Add(this); + private void OnDisable() => BadAnimatorFixManager.Remove(this); public void AttemptRewindAnimator() { + if (animator == null) return; + bool rewound = false; - for (int i = 0; i < animator.layerCount; i++) + for (int layerIndex = 0; layerIndex < animator.layerCount; layerIndex++) { - AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(i); - AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(i); - // 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; - // Rewind state, with 10f as buffer, to account for reasonable use of ExitTime - rewound = true; - float offset = 10f + (stateInfo.normalizedTime % 1f); - animator.Play(stateInfo.fullPathHash, i, offset); + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); + AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex); + + bool shouldSkipState = !stateInfo.loop || transitionInfo.fullPathHash != 0; + if (shouldSkipState) continue; + + bool shouldRewindState = stateInfo.normalizedTime >= StateLimit; + if (shouldRewindState) + { + float rewindOffset = (stateInfo.normalizedTime % 1f) + 10f; + animator.Play(stateInfo.fullPathHash, layerIndex, rewindOffset); + rewound = true; + } } + if (rewound) { - PlayableExtensions.SetTime(playable, 0); - BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); + var rootPlayable = animator.playableGraph.GetRootPlayable(0); + PlayableExtensions.SetTime(rootPlayable, 0); + + if (BadAnimatorFixMod.EntryLogging.Value) + BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); } } } \ No newline at end of file diff --git a/BadAnimatorFix/BadAnimatorFixManager.cs b/BadAnimatorFix/BadAnimatorFixManager.cs index b4c4d66..c912296 100644 --- a/BadAnimatorFix/BadAnimatorFixManager.cs +++ b/BadAnimatorFix/BadAnimatorFixManager.cs @@ -1,50 +1,58 @@ using ABI_RC.Core.IO; +using UnityEngine; +using UnityEngine.SceneManagement; namespace NAK.Melons.BadAnimatorFix; public static class BadAnimatorFixManager { - public static List badAnimatorFixes = new List(); + private static List badAnimatorFixes = new List(); private static int currentIndex = 0; + private static float checkInterval = 5f; public static void Add(BadAnimatorFix bad) { if (!badAnimatorFixes.Contains(bad)) - { badAnimatorFixes.Add(bad); - } } public static void Remove(BadAnimatorFix bad) { if (badAnimatorFixes.Contains(bad)) - { badAnimatorFixes.Remove(bad); + } + + public static void OnSceneInitialized(string sceneName) + { + // Get all the animators in the loaded world + var allAnimators = SceneManager.GetSceneByName(sceneName).GetRootGameObjects() + .SelectMany(x => x.GetComponentsInChildren(true)); + + foreach (var animator in allAnimators) + { + // Ignore objects that have our "fix", this shouldn't be needed but eh + if (!animator.TryGetComponent(out _)) + { + animator.gameObject.AddComponent(); + } } } - // Runs every 5 seconds to see if an animator has played longer than PlayableTimeLimit - public static void CheckNextAnimator() + private static void CheckNextAnimator() { if (badAnimatorFixes.Count == 0) return; - - if (currentIndex >= badAnimatorFixes.Count) currentIndex = 0; + currentIndex = (currentIndex + 1) % badAnimatorFixes.Count; BadAnimatorFix currentAnimatorFix = badAnimatorFixes[currentIndex]; - if (currentAnimatorFix.GetTime() > BadAnimatorFixMod.EntryPlayableTimeLimit.Value) - { - currentAnimatorFix.AttemptRewindAnimator(); - } - - currentIndex++; - } + currentAnimatorFix.AttemptRewindAnimator(); + } public static void ToggleJob(bool enable) { var job = SchedulerSystem.Instance.activeJobs.FirstOrDefault(pair => pair.Job.Method.Name == "CheckNextAnimator").Job; if (enable && job == null) { - SchedulerSystem.AddJob(new SchedulerSystem.Job(BadAnimatorFixManager.CheckNextAnimator), 0f, 5f, -1); + SchedulerSystem.AddJob(new SchedulerSystem.Job(CheckNextAnimator), 0f, checkInterval, -1); } else if (!enable && job != null) { diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs index c281f64..6e8b98a 100644 --- a/BadAnimatorFix/HarmonyPatches.cs +++ b/BadAnimatorFix/HarmonyPatches.cs @@ -2,11 +2,10 @@ using ABI_RC.Core.InteractionSystem; using HarmonyLib; using UnityEngine; -using ABI_RC.Core.IO; namespace NAK.Melons.BadAnimatorFix.HarmonyPatches; -internal class AnimatorPatches +internal static class AnimatorPatches { [HarmonyPostfix] [HarmonyPatch(typeof(CVRAvatar), "Start")] @@ -24,24 +23,16 @@ internal class AnimatorPatches AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); } - [HarmonyPostfix] - [HarmonyPatch(typeof(CVRWorld), "Start")] - private static void Post_CVRWorld_Start(CVRWorld __instance) - { - if (!BadAnimatorFixMod.EntryCVRWorld.Value) return; - AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); - } - - //Set QM stuff + // Set QM stuff [HarmonyPostfix] [HarmonyPatch(typeof(CVR_MenuManager), "Start")] - private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor) + private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance) { if (!BadAnimatorFixMod.EntryMenus.Value) return; AddBadAnimatorFixComponentIfAnimatorExists(__instance.gameObject); } - //Set MM stuff + // Set MM stuff [HarmonyPostfix] [HarmonyPatch(typeof(ViewManager), "Start")] private static void Postfix_ViewManager_Start(ref ViewManager __instance) @@ -52,12 +43,12 @@ internal class AnimatorPatches private static void AddBadAnimatorFixComponentIfAnimatorExists(GameObject gameObject) { - //if (!BadAnimatorFixMod.EntryEnabled.Value) return; - Animator[] animators = gameObject.GetComponentsInChildren(); - foreach (Animator animator in animators.Where(a => a.gameObject.GetComponent() == null)) + Animator[] animators = gameObject.GetComponentsInChildren(true); + foreach (Animator animator in animators) { + if (animator.gameObject.GetComponent() != null) continue; if (animator.runtimeAnimatorController != null) animator.gameObject.AddComponent(); } } -} \ No newline at end of file +} diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs index eba99a7..a854527 100644 --- a/BadAnimatorFix/Main.cs +++ b/BadAnimatorFix/Main.cs @@ -1,6 +1,4 @@ using MelonLoader; -using System.Collections; -using ABI_RC.Core.Player; namespace NAK.Melons.BadAnimatorFix; @@ -17,30 +15,28 @@ public class BadAnimatorFixMod : MelonMod CategoryBadAnimatorFix.CreateEntry("Add to CVRAvatar", true, description: "Should BadAnimatorFix run for CVRAvatar? Requires avatar reload."); public static readonly MelonPreferences_Entry EntryCVRSpawnable = - CategoryBadAnimatorFix.CreateEntry("Add to CVRSpawnable", false, description: "Should BadAnimatorFix run for CVRSpawnable? Requires spawnable reload."); + CategoryBadAnimatorFix.CreateEntry("Add to CVRSpawnable", true, description: "Should BadAnimatorFix run for CVRSpawnable? Requires spawnable reload."); public static readonly MelonPreferences_Entry EntryCVRWorld = - CategoryBadAnimatorFix.CreateEntry("Add to CVRWorld", false, description: "Should BadAnimatorFix run for CVRWorld? Requires world reload."); + CategoryBadAnimatorFix.CreateEntry("Add to CVRWorld", true, description: "Should BadAnimatorFix run for CVRWorld? Requires world reload."); public static readonly MelonPreferences_Entry EntryMenus = - CategoryBadAnimatorFix.CreateEntry("Add to Menus", false, description: "Should BadAnimatorFix run for QM & MM? Requires game restart."); + CategoryBadAnimatorFix.CreateEntry("Add to Menus", true, description: "Should BadAnimatorFix run for QM & MM? Requires game restart."); - public static readonly MelonPreferences_Entry EntryPlayableTimeLimit = - CategoryBadAnimatorFix.CreateEntry("Playable Time Limit", 600f, description: "How long in seconds can a Playable play for before rewinding its states."); + public static readonly MelonPreferences_Entry EntryLogging = + CategoryBadAnimatorFix.CreateEntry("Logging", false, description: "Toggle to log each rewind if successful. Only needed for debugging."); public override void OnInitializeMelon() { Logger = LoggerInstance; EntryEnabled.OnEntryValueChangedUntyped.Subscribe(OnEnabled); ApplyPatches(typeof(HarmonyPatches.AnimatorPatches)); - MelonCoroutines.Start(WaitForLocalPlayer()); } - private IEnumerator WaitForLocalPlayer() + public override void OnSceneWasInitialized(int buildIndex, string sceneName) { - while (PlayerSetup.Instance == null) - yield return null; - BadAnimatorFixManager.ToggleJob(EntryEnabled.Value); + if (!EntryCVRWorld.Value) return; + BadAnimatorFixManager.OnSceneInitialized(sceneName); } private void OnEnabled(object arg1, object arg2) diff --git a/BadAnimatorFix/format.json b/BadAnimatorFix/format.json index 7d05f54..e7f5445 100644 --- a/BadAnimatorFix/format.json +++ b/BadAnimatorFix/format.json @@ -1,23 +1,23 @@ { "_id": -1, - "name": "TrackedControllerFix", + "name": "BadAnimatorFix", "modversion": "1.0.0", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "Allows your controllers to track while the SteamVR overlay is open. This also fixes Quest/Touch controllers feeling slow during fast movements.", + "description": "This mod occasionally rewinds animation states that have loop enabled.\n\nUnity seems to have a weird quirk where animations with loop cause performance issues after running for a long long time.\nYou'll only start to notice this after a few hours to a few days of idling.\n\nDisable loop on your 2-frame toggle clips! They cycle insanely fast and heavily contribute to this issue.", "searchtags": [ - "vr", - "quest", - "controller", - "tracking" + "bad", + "fix", + "animator", + "loop" ], "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/releases/download/v1.0.0/TrackedControllerFix.dll", - "sourcelink": "https://github.com/NotAKidOnSteam/TrackedControllerFix/", + "downloadlink": "https://github.com/NotAKidOnSteam/BadAnimatorFix/releases/download/v1.0.0/BadAnimatorFix.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/BadAnimatorFix/", "changelog": "Initial Release", - "embedcolor": "3498db" + "embedcolor": "7F3F99" } \ No newline at end of file From 7b5ad71060dfb63042c281d3a774e04c092f71a6 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:09:08 -0500 Subject: [PATCH 05/12] wasd --- BadAnimatorFix/BadAnimatorFix.cs | 7 +++++++ BadAnimatorFix/BadAnimatorFixManager.cs | 5 +++++ BadAnimatorFix/HarmonyPatches.cs | 8 ++++++++ BadAnimatorFix/Main.cs | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs index f1cb6f6..e021481 100644 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -2,6 +2,7 @@ using UnityEngine.Playables; namespace NAK.Melons.BadAnimatorFix; + public class BadAnimatorFix : MonoBehaviour { private const float StateLimit = 20f; @@ -44,7 +45,13 @@ public class BadAnimatorFix : MonoBehaviour PlayableExtensions.SetTime(rootPlayable, 0); if (BadAnimatorFixMod.EntryLogging.Value) + { BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); + } + } + else if (BadAnimatorFixMod.EntryLogging.Value) + { + BadAnimatorFixMod.Logger.Msg($"Animator did not meet criteria to rewind {animator}."); } } } \ No newline at end of file diff --git a/BadAnimatorFix/BadAnimatorFixManager.cs b/BadAnimatorFix/BadAnimatorFixManager.cs index c912296..6497ca4 100644 --- a/BadAnimatorFix/BadAnimatorFixManager.cs +++ b/BadAnimatorFix/BadAnimatorFixManager.cs @@ -22,6 +22,11 @@ public static class BadAnimatorFixManager badAnimatorFixes.Remove(bad); } + public static void OnPlayerLoaded() + { + ToggleJob(BadAnimatorFixMod.EntryEnabled.Value); + } + public static void OnSceneInitialized(string sceneName) { // Get all the animators in the loaded world diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs index 6e8b98a..293aa0c 100644 --- a/BadAnimatorFix/HarmonyPatches.cs +++ b/BadAnimatorFix/HarmonyPatches.cs @@ -2,11 +2,19 @@ using ABI_RC.Core.InteractionSystem; using HarmonyLib; using UnityEngine; +using ABI_RC.Core.Player; namespace NAK.Melons.BadAnimatorFix.HarmonyPatches; internal static class AnimatorPatches { + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), "Start")] + private static void Post_PlayerSetup_Start() + { + BadAnimatorFixManager.OnPlayerLoaded(); + } + [HarmonyPostfix] [HarmonyPatch(typeof(CVRAvatar), "Start")] private static void Post_CVRAvatar_Start(CVRAvatar __instance) diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs index a854527..c25f91f 100644 --- a/BadAnimatorFix/Main.cs +++ b/BadAnimatorFix/Main.cs @@ -24,7 +24,7 @@ public class BadAnimatorFixMod : MelonMod CategoryBadAnimatorFix.CreateEntry("Add to Menus", true, description: "Should BadAnimatorFix run for QM & MM? Requires game restart."); public static readonly MelonPreferences_Entry EntryLogging = - CategoryBadAnimatorFix.CreateEntry("Logging", false, description: "Toggle to log each rewind if successful. Only needed for debugging."); + CategoryBadAnimatorFix.CreateEntry("Debugging", false, description: "Toggle to log each rewind if successful. Only needed for debugging."); public override void OnInitializeMelon() { From 9cc62a961cfdcff1998b18515b42061417a4242c Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:50:57 -0500 Subject: [PATCH 06/12] touch --- BadAnimatorFix/BadAnimatorFix.cs | 50 +++++++++++++++----------------- BadAnimatorFix/HarmonyPatches.cs | 7 +++-- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs index e021481..7d47f5f 100644 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -19,39 +19,37 @@ public class BadAnimatorFix : MonoBehaviour public void AttemptRewindAnimator() { - if (animator == null) return; - bool rewound = false; - for (int layerIndex = 0; layerIndex < animator.layerCount; layerIndex++) + + if (animator != null && animator.isActiveAndEnabled) { - AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); - AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex); - - bool shouldSkipState = !stateInfo.loop || transitionInfo.fullPathHash != 0; - if (shouldSkipState) continue; - - bool shouldRewindState = stateInfo.normalizedTime >= StateLimit; - if (shouldRewindState) + for (int layerIndex = 0; layerIndex < animator.layerCount; layerIndex++) { - float rewindOffset = (stateInfo.normalizedTime % 1f) + 10f; - animator.Play(stateInfo.fullPathHash, layerIndex, rewindOffset); - rewound = true; + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); + AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex); + + // Skip if state doesn't loop or if mid-transition + if (!stateInfo.loop || transitionInfo.fullPathHash != 0) continue; + + // Skip if state hasn't looped enough + if (stateInfo.normalizedTime > StateLimit) + { + float rewindOffset = (stateInfo.normalizedTime % 1f) + 10f; + animator.Play(stateInfo.fullPathHash, layerIndex, rewindOffset); + rewound = true; + } + } + + if (rewound) + { + PlayableExtensions.SetTime(animator.playableGraph.GetRootPlayable(0), 0); } } - if (rewound) + if (BadAnimatorFixMod.EntryLogging.Value) { - var rootPlayable = animator.playableGraph.GetRootPlayable(0); - PlayableExtensions.SetTime(rootPlayable, 0); - - if (BadAnimatorFixMod.EntryLogging.Value) - { - BadAnimatorFixMod.Logger.Msg($"Rewound animator and playable {animator}."); - } - } - else if (BadAnimatorFixMod.EntryLogging.Value) - { - BadAnimatorFixMod.Logger.Msg($"Animator did not meet criteria to rewind {animator}."); + string message = rewound ? $"Rewound animator and playable {animator}." : $"Animator did not meet criteria to rewind {animator}."; + BadAnimatorFixMod.Logger.Msg(message); } } } \ No newline at end of file diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs index 293aa0c..617e773 100644 --- a/BadAnimatorFix/HarmonyPatches.cs +++ b/BadAnimatorFix/HarmonyPatches.cs @@ -1,8 +1,8 @@ using ABI.CCK.Components; using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.Player; using HarmonyLib; using UnityEngine; -using ABI_RC.Core.Player; namespace NAK.Melons.BadAnimatorFix.HarmonyPatches; @@ -54,9 +54,10 @@ internal static class AnimatorPatches Animator[] animators = gameObject.GetComponentsInChildren(true); foreach (Animator animator in animators) { - if (animator.gameObject.GetComponent() != null) continue; - if (animator.runtimeAnimatorController != null) + if (!animator.TryGetComponent(out _)) + { animator.gameObject.AddComponent(); + } } } } From aa60163396d5ad46805274a8f90d1582aba30ae9 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:54:32 -0500 Subject: [PATCH 07/12] Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index c6fb5e2..1a8cbf3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ # BadAnimatorFix A bad fix for a neiche issue. Is it really even a fix? + +This mod occasionally rewinds animation states that have loop enabled. + +Unity seems to have a weird quirk where animations with loop cause performance issues after running for a long long time. +You'll only start to notice this after a few hours to a few days of idling. + +Disable loop on your 2-frame toggle clips! They cycle insanely fast and heavily contribute to this issue. + +--- + +Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation and is not affiliated with, supported by or approved by Alpha Blend Interactive. + +> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use. + +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. From 2e51a197d0108512b292c15535ce4e0e13ab1dfe Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:54:51 -0500 Subject: [PATCH 08/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a8cbf3..f34e8e9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # BadAnimatorFix - A bad fix for a neiche issue. Is it really even a fix? + A bad fix for a niche issue. Is it really even a fix? This mod occasionally rewinds animation states that have loop enabled. From 3a3cb1879c6d5041a366d29596b9605cc36bae36 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 20:50:21 -0500 Subject: [PATCH 09/12] touchups --- BadAnimatorFix/BadAnimatorFix.cs | 21 +++++++++------------ BadAnimatorFix/format.json | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs index 7d47f5f..494ce52 100644 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ b/BadAnimatorFix/BadAnimatorFix.cs @@ -27,17 +27,14 @@ public class BadAnimatorFix : MonoBehaviour { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex); - - // Skip if state doesn't loop or if mid-transition - if (!stateInfo.loop || transitionInfo.fullPathHash != 0) continue; - - // Skip if state hasn't looped enough - if (stateInfo.normalizedTime > StateLimit) - { - float rewindOffset = (stateInfo.normalizedTime % 1f) + 10f; - animator.Play(stateInfo.fullPathHash, layerIndex, rewindOffset); - rewound = true; - } + // 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; + // 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); + rewound = true; } if (rewound) @@ -45,7 +42,7 @@ public class BadAnimatorFix : MonoBehaviour PlayableExtensions.SetTime(animator.playableGraph.GetRootPlayable(0), 0); } } - + if (BadAnimatorFixMod.EntryLogging.Value) { string message = rewound ? $"Rewound animator and playable {animator}." : $"Animator did not meet criteria to rewind {animator}."; diff --git a/BadAnimatorFix/format.json b/BadAnimatorFix/format.json index e7f5445..df8fd08 100644 --- a/BadAnimatorFix/format.json +++ b/BadAnimatorFix/format.json @@ -6,7 +6,7 @@ "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "This mod occasionally rewinds animation states that have loop enabled.\n\nUnity seems to have a weird quirk where animations with loop cause performance issues after running for a long long time.\nYou'll only start to notice this after a few hours to a few days of idling.\n\nDisable loop on your 2-frame toggle clips! They cycle insanely fast and heavily contribute to this issue.", + "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.", "searchtags": [ "bad", "fix", From 1d2f6841b6cfcbc03e957a6af0e7bf0ef0bd99b0 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 20:51:04 -0500 Subject: [PATCH 10/12] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f34e8e9..267269d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ You'll only start to notice this after a few hours to a few days of idling. Disable loop on your 2-frame toggle clips! They cycle insanely fast and heavily contribute to this issue. +This mod also indirectly fixes your locomotion animations or other animations locking up after being AFK/Idle for days at a time. + --- Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. From 1dd668130f57d097fdec317c16777a6eb81e5232 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:03:19 -0500 Subject: [PATCH 11/12] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 267269d..17daa4c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,14 @@ Disable loop on your 2-frame toggle clips! They cycle insanely fast and heavily This mod also indirectly fixes your locomotion animations or other animations locking up after being AFK/Idle for days at a time. +# Note + +I haven't figured out exactly what's causing the performance drops over time, but I think it might be due to animation clips that have loop enabled for no reason. Unity's loop setting for animation clips is inconsistent, so clips created from the Project tab don't have loop, while those created from the Animation tab do. Depending on how creators make these clips for their avatars, they might unintentionally be more prone to this issue. + +Poking around existing communities and searching around, this issue or a similar one has been noted before, with the cause being short animations with loop enabled. + +Unity is weird. It is hard to debug this issue as it is avatar dependent and sometimes just does not occur without actually idling for hours to days. + --- Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. From 6f5414f63be06a72483d1a9c56384c2f7071f133 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:04:58 -0500 Subject: [PATCH 12/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 17daa4c..e5dc953 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ Disable loop on your 2-frame toggle clips! They cycle insanely fast and heavily This mod also indirectly fixes your locomotion animations or other animations locking up after being AFK/Idle for days at a time. -# Note +## Note I haven't figured out exactly what's causing the performance drops over time, but I think it might be due to animation clips that have loop enabled for no reason. Unity's loop setting for animation clips is inconsistent, so clips created from the Project tab don't have loop, while those created from the Animation tab do. Depending on how creators make these clips for their avatars, they might unintentionally be more prone to this issue. Poking around existing communities and searching around, this issue or a similar one has been noted before, with the cause being short animations with loop enabled. -Unity is weird. It is hard to debug this issue as it is avatar dependent and sometimes just does not occur without actually idling for hours to days. +Unity is weird. It is hard to debug this issue as it is avatar dependent and sometimes just does not occur without actually idling for hours to days. I can speed up the game or use EvaluateController() to attempt to force the issue sooner, but even so, it sometimes just does not occur. ---