From 6a488abde8b852d1bece55dcba40d8bb11646d3f Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 03:14:30 -0600 Subject: [PATCH 01/30] 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..1e4c8a6 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# AASBufferFix + we From b5fb7bdac6e3b2a7557c67fa7996447af30687ea Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 03:25:21 -0600 Subject: [PATCH 02/30] bruh --- AASBufferFix/AASBufferFix.cs | 126 ++++++++++++++++++++++++ AASBufferFix/AASBufferFix.csproj | 52 ++++++++++ AASBufferFix/AASBufferFix.sln | 25 +++++ AASBufferFix/HarmonyPatches.cs | 61 ++++++++++++ AASBufferFix/Main.cs | 11 +++ AASBufferFix/Properties/AssemblyInfo.cs | 30 ++++++ AASBufferFix/format.json | 23 +++++ 7 files changed, 328 insertions(+) create mode 100644 AASBufferFix/AASBufferFix.cs create mode 100644 AASBufferFix/AASBufferFix.csproj create mode 100644 AASBufferFix/AASBufferFix.sln create mode 100644 AASBufferFix/HarmonyPatches.cs create mode 100644 AASBufferFix/Main.cs create mode 100644 AASBufferFix/Properties/AssemblyInfo.cs create mode 100644 AASBufferFix/format.json diff --git a/AASBufferFix/AASBufferFix.cs b/AASBufferFix/AASBufferFix.cs new file mode 100644 index 0000000..fd6a7f6 --- /dev/null +++ b/AASBufferFix/AASBufferFix.cs @@ -0,0 +1,126 @@ +using ABI_RC.Core.Player; +using UnityEngine; + +namespace NAK.Melons.AASBufferFix; + +public class AASBufferFix : MonoBehaviour +{ + public PuppetMaster puppetMaster; + + public bool isAcceptingAAS = false; + + public float[] aasBufferFloat = new float[0]; + public int[] aasBufferInt = new int[0]; + public byte[] aasBufferByte = new byte[0]; + + public int aasFootprint = -1; + public int avatarFootprint = -1; + + public void Start() + { + puppetMaster = GetComponent(); + } + + public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + //resize buffer if size changed, only should happen on first new avatar load + if (aasBufferFloat.Length == settingsFloat.Length) + aasBufferFloat = new float[settingsFloat.Length]; + + if (aasBufferInt.Length == settingsInt.Length) + aasBufferInt = new int[settingsInt.Length]; + + if (aasBufferByte.Length == settingsByte.Length) + aasBufferByte = new byte[settingsByte.Length]; + + aasBufferFloat = settingsFloat; + aasBufferInt = settingsInt; + aasBufferByte = settingsByte; + + //haha shit lazy implementation + aasFootprint = ((aasBufferFloat.Length * 32) + 1) * ((aasBufferInt.Length * 32) + 1) * ((aasBufferByte.Length * 8) + 1); + + CheckForFootprintMatch(); + } + + public void OnAvatarInstantiated(Animator animator) + { + avatarFootprint = GenerateAvatarFootprint(animator); + CheckForFootprintMatch(); + } + + public void OnAvatarDestroyed() + { + isAcceptingAAS = false; + //clear buffer + aasBufferFloat = new float[0]; + aasBufferInt = new int[0]; + aasBufferByte = new byte[0]; + avatarFootprint = 0; + aasFootprint = -1; + } + + public void CheckForFootprintMatch() + { + //only apply if avatar footprints match + if (aasFootprint == avatarFootprint) + { + isAcceptingAAS = true; + puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); + } + } + + public int GenerateAvatarFootprint(Animator animator) + { + int avatarFloatCount = 0; + int avatarIntCount = 0; + int avatarBoolCount = 0; + + foreach (AnimatorControllerParameter animatorControllerParameter in animator.parameters) + { + if (animatorControllerParameter.name.Length > 0 && animatorControllerParameter.name[0] != '#' && !coreParameters.Contains(animatorControllerParameter.name)) + { + AnimatorControllerParameterType type = animatorControllerParameter.type; + switch (type) + { + case AnimatorControllerParameterType.Float: + avatarFloatCount += 32; + break; + case (AnimatorControllerParameterType)2: + break; + case AnimatorControllerParameterType.Int: + avatarIntCount += 32; + break; + case AnimatorControllerParameterType.Bool: + avatarBoolCount++; + break; + default: + //we dont count triggers + break; + } + } + } + + //bool to byte + avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8) * 8); + + //create the footprint + return (avatarFloatCount + 1) * (avatarIntCount + 1) * (avatarBoolCount + 1); + } + + private static HashSet coreParameters = new HashSet + { + "MovementX", + "MovementY", + "Grounded", + "Emote", + "GestureLeft", + "GestureRight", + "Toggle", + "Sitting", + "Crouching", + "CancelEmote", + "Prone", + "Flying" + }; +} \ No newline at end of file diff --git a/AASBufferFix/AASBufferFix.csproj b/AASBufferFix/AASBufferFix.csproj new file mode 100644 index 0000000..c432ed3 --- /dev/null +++ b/AASBufferFix/AASBufferFix.csproj @@ -0,0 +1,52 @@ + + + + + net472 + 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 + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\BTKUILib.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll + + + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AssetBundleModule.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 + + + ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll + + + + + + + + + diff --git a/AASBufferFix/AASBufferFix.sln b/AASBufferFix/AASBufferFix.sln new file mode 100644 index 0000000..2216422 --- /dev/null +++ b/AASBufferFix/AASBufferFix.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}") = "AASBufferFix", "AASBufferFix.csproj", "{9C6339E8-657C-4A1F-9324-12BFB2558BBB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C6339E8-657C-4A1F-9324-12BFB2558BBB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C6339E8-657C-4A1F-9324-12BFB2558BBB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C6339E8-657C-4A1F-9324-12BFB2558BBB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C6339E8-657C-4A1F-9324-12BFB2558BBB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D2EEA814-859D-4EE4-ADC8-DDDD36383310} + EndGlobalSection +EndGlobal diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs new file mode 100644 index 0000000..e2d8dd6 --- /dev/null +++ b/AASBufferFix/HarmonyPatches.cs @@ -0,0 +1,61 @@ +using ABI_RC.Core; +using ABI_RC.Core.Base; +using ABI_RC.Core.Player; +using HarmonyLib; +using UnityEngine; + +namespace NAK.Melons.AASBufferFix.HarmonyPatches; + +[HarmonyPatch] +internal class HarmonyPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(PuppetMaster), "Start")] + private static void Postfix_PuppetMaster_Start(ref PuppetMaster __instance) + { + AASBufferFix externalBuffer = __instance.AddComponentIfMissing(); + externalBuffer.puppetMaster = __instance; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PuppetMaster), "AvatarInstantiated")] + private static void Postfix_PuppetMaster_AvatarInstantiated(ref PuppetMaster __instance, ref Animator ____animator) + { + AASBufferFix externalBuffer = __instance.GetComponent(); + if (externalBuffer != null) externalBuffer.OnAvatarInstantiated(____animator); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(PuppetMaster), "AvatarDestroyed")] + private static void Postfix_PuppetMaster_AvatarDestroyed(ref PuppetMaster __instance) + { + AASBufferFix externalBuffer = __instance.GetComponent(); + if (externalBuffer != null) externalBuffer.OnAvatarDestroyed(); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(PuppetMaster), "ApplyAdvancedAvatarSettings")] + private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettings(float[] settingsFloat, int[] settingsInt, byte[] settingsByte, ref PuppetMaster __instance) + { + AASBufferFix externalBuffer = __instance.GetComponent(); + if (externalBuffer != null && !externalBuffer.isAcceptingAAS) + { + externalBuffer.StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + return false; + } + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(CVRAnimatorManager), "ApplyAdvancedAvatarSettingsFromBuffer")] + private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator) + { + AASBufferFix externalBuffer = ____animator.GetComponentInParent(); + if (externalBuffer != null && !externalBuffer.isAcceptingAAS) + { + //dont apply if stable buffer no exist + return false; + } + return true; + } +} \ No newline at end of file diff --git a/AASBufferFix/Main.cs b/AASBufferFix/Main.cs new file mode 100644 index 0000000..6501c23 --- /dev/null +++ b/AASBufferFix/Main.cs @@ -0,0 +1,11 @@ +using MelonLoader; + +namespace NAK.Melons.AASBufferFix; + +public class AASBufferFixMod : MelonMod +{ + public override void OnInitializeMelon() + { + + } +} \ No newline at end of file diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..94530b5 --- /dev/null +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using AASBufferFix.Properties; +using MelonLoader; +using System.Reflection; + + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.Melons.AASBufferFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.Melons.AASBufferFix))] + +[assembly: MelonInfo( + typeof(NAK.Melons.AASBufferFix.AASBufferFixMod), + nameof(NAK.Melons.AASBufferFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/AASBufferFix" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] + +namespace AASBufferFix.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/AASBufferFix/format.json b/AASBufferFix/format.json new file mode 100644 index 0000000..59301c3 --- /dev/null +++ b/AASBufferFix/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "AASBufferFix", + "modversion": "1.0.0", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Fixes two AAS buffer issues. Remote avatars with AAS will no longer experience wardrobe malfunctions on initialization.\n\nAAS will not be applied unless the synced data matches what is expected of the loaded avatar.", + "searchtags": [ + "aas", + "sync", + "naked", + "buffer" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.0/AASBufferFix.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", + "changelog": "- Initial Release", + "embedcolor": "9b59b6" +} \ No newline at end of file From d4295b4c6586131eb0039cc6c46b2537f1b87cbb Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 03:29:13 -0600 Subject: [PATCH 03/30] Update README.md --- README.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e4c8a6..b0d81f5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ # AASBufferFix - we + +Fixes two issues with the Avatar Advanced Settings buffers when loading remote avatars: + +https://feedback.abinteractive.net/p/aas-is-still-synced-while-loading-an-avatar + +https://feedback.abinteractive.net/p/aas-buffer-is-nuked-on-remote-load + +Avatars will no longer load in naked or transition to the wrong state on load. + +AAS will also not be updated unless the expected data matches what is received. + +--- + +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 + +> I am not affiliated with ABI in any official capacity, these mods are not endorsed or outright permitted by ABI and are subject to scrutiny. + +> Neither I nor these mods are in any way affiliated with Alpha Blend Interactive and/or ChilloutVR. Using these modifications might cause issues with the performance, security or stability of the game. Use at your own risk. + +> Any modifications that are not approved can get your ABI account terminated and such this modification is following the "modding guidelines" at the best it could be. +> They reserve the right to punish users using my mod. +> If you are scared of using modifications in your game do not install mods. + +> I do not affiliate ABI and the mod is not supported by ABI. + +> Me and this modification are in no affiliation with ABI and not supported by ABI. + +> This mod is not affiliated with Alpha Blend Interactive. The mod comes with no warranty. Use at your own risk, as I am not responsible for any misuse. + +> I'm not affiliated with Alpha Blend Interactive and this mod is not officially supported by the game. + +> When releasing mods to the public, it is required to state, that the mod authors and modification are in no affiliation with ABI and not supported by ABI. :trollface: + +> i ran out of places to steal disclaimers from From fea8d3e3c16e496790dbff66b42e9fafbd6b239f Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 04:39:44 -0600 Subject: [PATCH 04/30] funny refactor provides nothing over the previous version --- AASBufferFix/AASBufferFix.cs | 155 ++++++++++++++------------------- AASBufferFix/HarmonyPatches.cs | 2 +- AASBufferFix/Utils.cs | 67 ++++++++++++++ 3 files changed, 132 insertions(+), 92 deletions(-) create mode 100644 AASBufferFix/Utils.cs diff --git a/AASBufferFix/AASBufferFix.cs b/AASBufferFix/AASBufferFix.cs index fd6a7f6..6f1fbd1 100644 --- a/AASBufferFix/AASBufferFix.cs +++ b/AASBufferFix/AASBufferFix.cs @@ -5,122 +5,95 @@ namespace NAK.Melons.AASBufferFix; public class AASBufferFix : MonoBehaviour { - public PuppetMaster puppetMaster; + public bool isAcceptingAAS = true; - public bool isAcceptingAAS = false; + internal PuppetMaster puppetMaster; - public float[] aasBufferFloat = new float[0]; - public int[] aasBufferInt = new int[0]; - public byte[] aasBufferByte = new byte[0]; + //outside buffers that dont get nuked on avatar load + private float[] aasBufferFloat = new float[0]; + private int[] aasBufferInt = new int[0]; + private byte[] aasBufferByte = new byte[0]; - public int aasFootprint = -1; - public int avatarFootprint = -1; + //footprint is each parameter bit type count multiplied together + private int aasFootprint = -1; + private int avatarFootprint = 0; public void Start() { puppetMaster = GetComponent(); } - public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) - { - //resize buffer if size changed, only should happen on first new avatar load - if (aasBufferFloat.Length == settingsFloat.Length) - aasBufferFloat = new float[settingsFloat.Length]; - - if (aasBufferInt.Length == settingsInt.Length) - aasBufferInt = new int[settingsInt.Length]; - - if (aasBufferByte.Length == settingsByte.Length) - aasBufferByte = new byte[settingsByte.Length]; - - aasBufferFloat = settingsFloat; - aasBufferInt = settingsInt; - aasBufferByte = settingsByte; - - //haha shit lazy implementation - aasFootprint = ((aasBufferFloat.Length * 32) + 1) * ((aasBufferInt.Length * 32) + 1) * ((aasBufferByte.Length * 8) + 1); - - CheckForFootprintMatch(); - } - public void OnAvatarInstantiated(Animator animator) { - avatarFootprint = GenerateAvatarFootprint(animator); - CheckForFootprintMatch(); + //create the loaded avatar footprint + avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); + + //previous "bad data" now matches, apply buffered data + if (SyncDataMatchesExpected()) + { + ApplyExternalAASBuffer(); + } } public void OnAvatarDestroyed() { - isAcceptingAAS = false; - //clear buffer - aasBufferFloat = new float[0]; - aasBufferInt = new int[0]; - aasBufferByte = new byte[0]; - avatarFootprint = 0; aasFootprint = -1; + avatarFootprint = 0; + isAcceptingAAS = false; } - public void CheckForFootprintMatch() + public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { - //only apply if avatar footprints match - if (aasFootprint == avatarFootprint) - { - isAcceptingAAS = true; - puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); - } - } + //create the synced data footprint + aasFootprint = ((settingsFloat.Length * 32) + 1) * ((settingsInt.Length * 32) + 1) * ((settingsByte.Length * 8) + 1); - public int GenerateAvatarFootprint(Animator animator) - { - int avatarFloatCount = 0; - int avatarIntCount = 0; - int avatarBoolCount = 0; - - foreach (AnimatorControllerParameter animatorControllerParameter in animator.parameters) + if (!SyncDataMatchesExpected()) { - if (animatorControllerParameter.name.Length > 0 && animatorControllerParameter.name[0] != '#' && !coreParameters.Contains(animatorControllerParameter.name)) + if (avatarFootprint == 0) { - AnimatorControllerParameterType type = animatorControllerParameter.type; - switch (type) - { - case AnimatorControllerParameterType.Float: - avatarFloatCount += 32; - break; - case (AnimatorControllerParameterType)2: - break; - case AnimatorControllerParameterType.Int: - avatarIntCount += 32; - break; - case AnimatorControllerParameterType.Bool: - avatarBoolCount++; - break; - default: - //we dont count triggers - break; - } + //we are receiving synced data, but the avatar has not loaded on our end + //we can only assume the data is correct, and store it for later + StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + return; } + + //avatar is loaded on our screen, but wearer is syncing bad data + //we will need to wait until it has loaded on their end + + //there is also a chance the avatar is hidden, so the animator returned 1 on initialization + //(this was only one encounter during testing, someone being hidden by safety on world load) + } + else + { + //synced data matches what we expect + ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); } - - //bool to byte - avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8) * 8); - - //create the footprint - return (avatarFloatCount + 1) * (avatarIntCount + 1) * (avatarBoolCount + 1); } - private static HashSet coreParameters = new HashSet + public void ApplyExternalAASBuffer() { - "MovementX", - "MovementY", - "Grounded", - "Emote", - "GestureLeft", - "GestureRight", - "Toggle", - "Sitting", - "Crouching", - "CancelEmote", - "Prone", - "Flying" - }; + isAcceptingAAS = true; + puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); + } + + public void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + isAcceptingAAS = true; + puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); + } + + public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + Array.Resize(ref aasBufferFloat, settingsFloat.Length); + Array.Resize(ref aasBufferInt, settingsInt.Length); + Array.Resize(ref aasBufferByte, settingsByte.Length); + Array.Copy(settingsFloat, aasBufferFloat, settingsFloat.Length); + Array.Copy(settingsInt, aasBufferInt, settingsInt.Length); + Array.Copy(settingsByte, aasBufferByte, settingsByte.Length); + } + + public bool SyncDataMatchesExpected() + { + return aasFootprint == avatarFootprint; + } } \ No newline at end of file diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs index e2d8dd6..6db6cfa 100644 --- a/AASBufferFix/HarmonyPatches.cs +++ b/AASBufferFix/HarmonyPatches.cs @@ -40,7 +40,7 @@ internal class HarmonyPatches AASBufferFix externalBuffer = __instance.GetComponent(); if (externalBuffer != null && !externalBuffer.isAcceptingAAS) { - externalBuffer.StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + externalBuffer.OnApplyAAS(settingsFloat, settingsInt, settingsByte); return false; } return true; diff --git a/AASBufferFix/Utils.cs b/AASBufferFix/Utils.cs new file mode 100644 index 0000000..73eaa82 --- /dev/null +++ b/AASBufferFix/Utils.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NAK.Melons.AASBufferFix; + +public class Utils +{ + public static int GenerateAnimatorAASFootprint(Animator animator) + { + int avatarFloatCount = 0; + int avatarIntCount = 0; + int avatarBoolCount = 0; + + foreach (AnimatorControllerParameter animatorControllerParameter in animator.parameters) + { + if (animatorControllerParameter.name.Length > 0 && animatorControllerParameter.name[0] != '#' && !coreParameters.Contains(animatorControllerParameter.name)) + { + AnimatorControllerParameterType type = animatorControllerParameter.type; + switch (type) + { + case AnimatorControllerParameterType.Float: + avatarFloatCount++; + break; + case (AnimatorControllerParameterType)2: + break; + case AnimatorControllerParameterType.Int: + avatarIntCount++; + break; + case AnimatorControllerParameterType.Bool: + avatarBoolCount++; + break; + default: + //we dont count triggers + break; + } + } + } + + //bool to byte + avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8) * 8); + avatarFloatCount *= 32; + avatarIntCount *= 32; + + //create the footprint + return (avatarFloatCount + 1) * (avatarIntCount + 1) * (avatarBoolCount + 1); + } + + private static HashSet coreParameters = new HashSet + { + "MovementX", + "MovementY", + "Grounded", + "Emote", + "GestureLeft", + "GestureRight", + "Toggle", + "Sitting", + "Crouching", + "CancelEmote", + "Prone", + "Flying" + }; +} From 29a32b64535b7725281fd9311efa7a1346d17c02 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 04:41:31 -0600 Subject: [PATCH 05/30] do we really need to multiply by bit count? --- AASBufferFix/AASBufferFix.cs | 2 +- AASBufferFix/Utils.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/AASBufferFix/AASBufferFix.cs b/AASBufferFix/AASBufferFix.cs index 6f1fbd1..3fd085e 100644 --- a/AASBufferFix/AASBufferFix.cs +++ b/AASBufferFix/AASBufferFix.cs @@ -45,7 +45,7 @@ public class AASBufferFix : MonoBehaviour public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { //create the synced data footprint - aasFootprint = ((settingsFloat.Length * 32) + 1) * ((settingsInt.Length * 32) + 1) * ((settingsByte.Length * 8) + 1); + aasFootprint = (settingsFloat.Length + 1) * ((settingsInt.Length) + 1) * ((settingsByte.Length) + 1); if (!SyncDataMatchesExpected()) { diff --git a/AASBufferFix/Utils.cs b/AASBufferFix/Utils.cs index 73eaa82..e946b26 100644 --- a/AASBufferFix/Utils.cs +++ b/AASBufferFix/Utils.cs @@ -41,9 +41,7 @@ public class Utils } //bool to byte - avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8) * 8); - avatarFloatCount *= 32; - avatarIntCount *= 32; + avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8)); //create the footprint return (avatarFloatCount + 1) * (avatarIntCount + 1) * (avatarBoolCount + 1); From b9d48d0b11a7dd20678c7591ff3bf75fa822e04a Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 04:43:44 -0600 Subject: [PATCH 06/30] do we need to exist after doing our job? --- AASBufferFix/{AASBufferFix.cs => AASBufferHelper.cs} | 4 +++- AASBufferFix/HarmonyPatches.cs | 10 +++++----- AASBufferFix/Main.cs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) rename AASBufferFix/{AASBufferFix.cs => AASBufferHelper.cs} (97%) diff --git a/AASBufferFix/AASBufferFix.cs b/AASBufferFix/AASBufferHelper.cs similarity index 97% rename from AASBufferFix/AASBufferFix.cs rename to AASBufferFix/AASBufferHelper.cs index 3fd085e..a71098c 100644 --- a/AASBufferFix/AASBufferFix.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace NAK.Melons.AASBufferFix; -public class AASBufferFix : MonoBehaviour +public class AASBufferHelper : MonoBehaviour { public bool isAcceptingAAS = true; @@ -74,12 +74,14 @@ public class AASBufferFix : MonoBehaviour { isAcceptingAAS = true; puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); + Destroy(this); } public void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { isAcceptingAAS = true; puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); + Destroy(this); } public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs index 6db6cfa..42029c0 100644 --- a/AASBufferFix/HarmonyPatches.cs +++ b/AASBufferFix/HarmonyPatches.cs @@ -13,7 +13,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PuppetMaster), "Start")] private static void Postfix_PuppetMaster_Start(ref PuppetMaster __instance) { - AASBufferFix externalBuffer = __instance.AddComponentIfMissing(); + AASBufferHelper externalBuffer = __instance.AddComponentIfMissing(); externalBuffer.puppetMaster = __instance; } @@ -21,7 +21,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PuppetMaster), "AvatarInstantiated")] private static void Postfix_PuppetMaster_AvatarInstantiated(ref PuppetMaster __instance, ref Animator ____animator) { - AASBufferFix externalBuffer = __instance.GetComponent(); + AASBufferHelper externalBuffer = __instance.GetComponent(); if (externalBuffer != null) externalBuffer.OnAvatarInstantiated(____animator); } @@ -29,7 +29,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PuppetMaster), "AvatarDestroyed")] private static void Postfix_PuppetMaster_AvatarDestroyed(ref PuppetMaster __instance) { - AASBufferFix externalBuffer = __instance.GetComponent(); + AASBufferHelper externalBuffer = __instance.GetComponent(); if (externalBuffer != null) externalBuffer.OnAvatarDestroyed(); } @@ -37,7 +37,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PuppetMaster), "ApplyAdvancedAvatarSettings")] private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettings(float[] settingsFloat, int[] settingsInt, byte[] settingsByte, ref PuppetMaster __instance) { - AASBufferFix externalBuffer = __instance.GetComponent(); + AASBufferHelper externalBuffer = __instance.GetComponent(); if (externalBuffer != null && !externalBuffer.isAcceptingAAS) { externalBuffer.OnApplyAAS(settingsFloat, settingsInt, settingsByte); @@ -50,7 +50,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(CVRAnimatorManager), "ApplyAdvancedAvatarSettingsFromBuffer")] private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator) { - AASBufferFix externalBuffer = ____animator.GetComponentInParent(); + AASBufferHelper externalBuffer = ____animator.GetComponentInParent(); if (externalBuffer != null && !externalBuffer.isAcceptingAAS) { //dont apply if stable buffer no exist diff --git a/AASBufferFix/Main.cs b/AASBufferFix/Main.cs index 6501c23..c81ebb8 100644 --- a/AASBufferFix/Main.cs +++ b/AASBufferFix/Main.cs @@ -6,6 +6,6 @@ public class AASBufferFixMod : MelonMod { public override void OnInitializeMelon() { - + //boobs } } \ No newline at end of file From 0fe0aa5355dd5c11d9382863fb98c1514e4ee72d Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 04:51:40 -0600 Subject: [PATCH 07/30] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b0d81f5..8a451dc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ https://feedback.abinteractive.net/p/aas-buffer-is-nuked-on-remote-load Avatars will no longer load in naked or transition to the wrong state on load. AAS will also not be updated unless the expected data matches what is received. + +The avatar will stay in the default animator state until AAS data is received that is deemed correct. --- From 69522cc029266689fb89cff1d7645e6146a97ef4 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 05:16:19 -0600 Subject: [PATCH 08/30] default value got me again --- AASBufferFix/AASBufferHelper.cs | 15 ++++++++++----- AASBufferFix/Properties/AssemblyInfo.cs | 2 +- AASBufferFix/format.json | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/AASBufferFix/AASBufferHelper.cs b/AASBufferFix/AASBufferHelper.cs index a71098c..a00586d 100644 --- a/AASBufferFix/AASBufferHelper.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -5,7 +5,7 @@ namespace NAK.Melons.AASBufferFix; public class AASBufferHelper : MonoBehaviour { - public bool isAcceptingAAS = true; + public bool isAcceptingAAS = false; internal PuppetMaster puppetMaster; @@ -41,11 +41,11 @@ public class AASBufferHelper : MonoBehaviour avatarFootprint = 0; isAcceptingAAS = false; } - + public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { //create the synced data footprint - aasFootprint = (settingsFloat.Length + 1) * ((settingsInt.Length) + 1) * ((settingsByte.Length) + 1); + aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); if (!SyncDataMatchesExpected()) { @@ -60,8 +60,13 @@ public class AASBufferHelper : MonoBehaviour //avatar is loaded on our screen, but wearer is syncing bad data //we will need to wait until it has loaded on their end - //there is also a chance the avatar is hidden, so the animator returned 1 on initialization - //(this was only one encounter during testing, someone being hidden by safety on world load) + //there is also a chance the avatar is hidden, so the avatar footprint returned 1 on initialization + //(this was only one encounter during testing, someone being hidden by safety on world load) (x, 1) + //these avatars do attempt to sync AAS, but the avatar footprint will never match + + //there is also a chance the avatar is an old avatar before AAS, so they do not sync any data + //and have an avatar footprint of 1 (-1, 1) + //these avatars do not seem to attempt AAS syncing, so it isnt much of a problem } else { diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs index 94530b5..d9fb19f 100644 --- a/AASBufferFix/Properties/AssemblyInfo.cs +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ using System.Reflection; namespace AASBufferFix.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.0"; + public const string Version = "1.0.1"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/AASBufferFix/format.json b/AASBufferFix/format.json index 59301c3..2d74952 100644 --- a/AASBufferFix/format.json +++ b/AASBufferFix/format.json @@ -1,12 +1,12 @@ { "_id": -1, "name": "AASBufferFix", - "modversion": "1.0.0", + "modversion": "1.0.1", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "Fixes two AAS buffer issues. Remote avatars with AAS will no longer experience wardrobe malfunctions on initialization.\n\nAAS will not be applied unless the synced data matches what is expected of the loaded avatar.", + "description": "Fixes two AAS buffer issues. Remote avatars with AAS will no longer experience wardrobe malfunctions on initialization. (only affects avatar load)\n\nAAS will not be applied unless the synced data matches what is expected of the loaded avatar.", "searchtags": [ "aas", "sync", @@ -16,7 +16,7 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.0/AASBufferFix.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.1/AASBufferFix.dll", "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", "changelog": "- Initial Release", "embedcolor": "9b59b6" From 27a05545ed196a40e04cd17a91179142c472f5d5 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:09:06 -0600 Subject: [PATCH 09/30] dont destroy self --- AASBufferFix/AASBufferHelper.cs | 2 -- AASBufferFix/Properties/AssemblyInfo.cs | 2 +- AASBufferFix/format.json | 8 ++++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/AASBufferFix/AASBufferHelper.cs b/AASBufferFix/AASBufferHelper.cs index a00586d..1b0364c 100644 --- a/AASBufferFix/AASBufferHelper.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -79,14 +79,12 @@ public class AASBufferHelper : MonoBehaviour { isAcceptingAAS = true; puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); - Destroy(this); } public void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { isAcceptingAAS = true; puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); - Destroy(this); } public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs index d9fb19f..2797515 100644 --- a/AASBufferFix/Properties/AssemblyInfo.cs +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ using System.Reflection; namespace AASBufferFix.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.1"; + public const string Version = "1.0.3"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/AASBufferFix/format.json b/AASBufferFix/format.json index 2d74952..7fa27a9 100644 --- a/AASBufferFix/format.json +++ b/AASBufferFix/format.json @@ -1,7 +1,7 @@ { - "_id": -1, + "_id": 126, "name": "AASBufferFix", - "modversion": "1.0.1", + "modversion": "1.0.3", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.1/AASBufferFix.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.3/AASBufferFix.dll", "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", - "changelog": "- Initial Release", + "changelog": "- Initial Release\n- Fixed extremely rare condition where AAS would be applied before ready.\n- Don't destroy helper on first load...'", "embedcolor": "9b59b6" } \ No newline at end of file From 870a29ca9ff186133a595b6d1579aa67688d0075 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 1 Feb 2023 10:55:44 -0600 Subject: [PATCH 10/30] another pointless refactor --- AASBufferFix/AASBufferHelper.cs | 176 ++++++++++++++++++-------------- AASBufferFix/HarmonyPatches.cs | 5 +- 2 files changed, 99 insertions(+), 82 deletions(-) diff --git a/AASBufferFix/AASBufferHelper.cs b/AASBufferFix/AASBufferHelper.cs index 1b0364c..3c1eda9 100644 --- a/AASBufferFix/AASBufferHelper.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -1,104 +1,122 @@ using ABI_RC.Core.Player; using UnityEngine; -namespace NAK.Melons.AASBufferFix; - -public class AASBufferHelper : MonoBehaviour +namespace NAK.Melons.AASBufferFix { - public bool isAcceptingAAS = false; - - internal PuppetMaster puppetMaster; - - //outside buffers that dont get nuked on avatar load - private float[] aasBufferFloat = new float[0]; - private int[] aasBufferInt = new int[0]; - private byte[] aasBufferByte = new byte[0]; - - //footprint is each parameter bit type count multiplied together - private int aasFootprint = -1; - private int avatarFootprint = 0; - - public void Start() + public class AASBufferHelper : MonoBehaviour { - puppetMaster = GetComponent(); - } + //public stuff + public bool GameHandlesAAS { get; private set; } - public void OnAvatarInstantiated(Animator animator) - { - //create the loaded avatar footprint - avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); + //internal references + private PuppetMaster _puppetMaster; - //previous "bad data" now matches, apply buffered data - if (SyncDataMatchesExpected()) + //outside aas buffers + private float[] _aasBufferFloat = new float[0]; + private int[] _aasBufferInt = new int[0]; + private byte[] _aasBufferByte = new byte[0]; + + //calculated footprints + private int _aasFootprint = -1; + private int _avatarFootprint = 0; + + private void Start() => _puppetMaster = GetComponent(); + + public void OnAvatarInstantiated(Animator animator) { - ApplyExternalAASBuffer(); - } - } - public void OnAvatarDestroyed() - { - aasFootprint = -1; - avatarFootprint = 0; - isAcceptingAAS = false; - } - - public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) - { - //create the synced data footprint - aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); + ///MelonLoader.MelonLogger.Msg("[OnInit] Remote avatar initialized. Generating avatar animator footprint."); - if (!SyncDataMatchesExpected()) - { - if (avatarFootprint == 0) + _avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); + + // avatar does not contain proper AAS + // this is likely because the avatar was made before AAS, or is blocked/hidden + if (_avatarFootprint == 1) { - //we are receiving synced data, but the avatar has not loaded on our end - //we can only assume the data is correct, and store it for later + ///MelonLoader.MelonLogger.Msg("[OnInit] Avatar does not contain valid AAS."); + // we will let the game handle this by setting IsAcceptingAAS to true + GameHandlesAAS = true; + return; + } + + ///MelonLoader.MelonLogger.Msg($"[OnInit] Avatar footprint is : {_avatarFootprint}"); + + //check if we received expected AAS while we loaded the avatar, and if so, apply it now + if (SyncDataMatchesExpected()) + { + ///MelonLoader.MelonLogger.Msg("[OnInit] Valid buffered AAS found. Applying AAS immediatly."); + ApplyExternalAASBuffer(); + return; + } + + //we loaded avatar faster than wearer + ///MelonLoader.MelonLogger.Msg("[OnInit] Remote avatar initialized faster than wearer. Waiting on valid AAS before applying."); + } + + public void OnAvatarDestroyed() + { + GameHandlesAAS = false; + _aasFootprint = -1; + _avatarFootprint = 0; + } + + public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + //avatar is still loading on our side, we must assume AAS data is correct and store it until we load + //there is also a chance it errored + if (_avatarFootprint == 0) + { + ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar is still loading on our end."); + // Calculate AAS footprint to compare against later. + _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); return; } - //avatar is loaded on our screen, but wearer is syncing bad data - //we will need to wait until it has loaded on their end + //avatar is loaded on our end, and is not blocked by filter + //this does run if it is manually hidden or distance hidden - //there is also a chance the avatar is hidden, so the avatar footprint returned 1 on initialization - //(this was only one encounter during testing, someone being hidden by safety on world load) (x, 1) - //these avatars do attempt to sync AAS, but the avatar footprint will never match + ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar is loaded on our side and is not blocked. Comparing for expected values."); + ///MelonLoader.MelonLogger.Msg($"[OnSync] Avatar Footprint is : {_avatarFootprint}"); - //there is also a chance the avatar is an old avatar before AAS, so they do not sync any data - //and have an avatar footprint of 1 (-1, 1) - //these avatars do not seem to attempt AAS syncing, so it isnt much of a problem + // Calculate AAS footprint to compare against. + _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); + + //if it matches, apply the settings and let game take over + if (SyncDataMatchesExpected()) + { + ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar values matched and have been applied."); + ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); + return; + } + + //if it did not match, that means the avatar we see on our side is different than what the remote user is wearing and syncing + ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar loaded is different than wearer. The wearer is likely still loading the avatar!"); + StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); } - else + + private void ApplyExternalAASBuffer() { - //synced data matches what we expect - ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); + GameHandlesAAS = true; + _puppetMaster?.ApplyAdvancedAvatarSettings(_aasBufferFloat, _aasBufferInt, _aasBufferByte); } - } - public void ApplyExternalAASBuffer() - { - isAcceptingAAS = true; - puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte); - } + private void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + GameHandlesAAS = true; + _puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); + } - public void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) - { - isAcceptingAAS = true; - puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); - } + private void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + Array.Resize(ref _aasBufferFloat, settingsFloat.Length); + Array.Resize(ref _aasBufferInt, settingsInt.Length); + Array.Resize(ref _aasBufferByte, settingsByte.Length); + Array.Copy(settingsFloat, _aasBufferFloat, settingsFloat.Length); + Array.Copy(settingsInt, _aasBufferInt, settingsInt.Length); + Array.Copy(settingsByte, _aasBufferByte, settingsByte.Length); + } - public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) - { - Array.Resize(ref aasBufferFloat, settingsFloat.Length); - Array.Resize(ref aasBufferInt, settingsInt.Length); - Array.Resize(ref aasBufferByte, settingsByte.Length); - Array.Copy(settingsFloat, aasBufferFloat, settingsFloat.Length); - Array.Copy(settingsInt, aasBufferInt, settingsInt.Length); - Array.Copy(settingsByte, aasBufferByte, settingsByte.Length); - } - - public bool SyncDataMatchesExpected() - { - return aasFootprint == avatarFootprint; + private bool SyncDataMatchesExpected() => _aasFootprint == _avatarFootprint; } } \ No newline at end of file diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs index 42029c0..6fa05ca 100644 --- a/AASBufferFix/HarmonyPatches.cs +++ b/AASBufferFix/HarmonyPatches.cs @@ -14,7 +14,6 @@ internal class HarmonyPatches private static void Postfix_PuppetMaster_Start(ref PuppetMaster __instance) { AASBufferHelper externalBuffer = __instance.AddComponentIfMissing(); - externalBuffer.puppetMaster = __instance; } [HarmonyPostfix] @@ -38,7 +37,7 @@ internal class HarmonyPatches private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettings(float[] settingsFloat, int[] settingsInt, byte[] settingsByte, ref PuppetMaster __instance) { AASBufferHelper externalBuffer = __instance.GetComponent(); - if (externalBuffer != null && !externalBuffer.isAcceptingAAS) + if (externalBuffer != null && !externalBuffer.GameHandlesAAS) { externalBuffer.OnApplyAAS(settingsFloat, settingsInt, settingsByte); return false; @@ -51,7 +50,7 @@ internal class HarmonyPatches private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator) { AASBufferHelper externalBuffer = ____animator.GetComponentInParent(); - if (externalBuffer != null && !externalBuffer.isAcceptingAAS) + if (externalBuffer != null && !externalBuffer.GameHandlesAAS) { //dont apply if stable buffer no exist return false; From 9e9c2880ae03ff553964d874979601abb82cf95d Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 1 Feb 2023 19:15:17 -0600 Subject: [PATCH 11/30] bump --- AASBufferFix/Properties/AssemblyInfo.cs | 2 +- AASBufferFix/format.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs index 2797515..0f06601 100644 --- a/AASBufferFix/Properties/AssemblyInfo.cs +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ using System.Reflection; namespace AASBufferFix.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.3"; + public const string Version = "1.0.4"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/AASBufferFix/format.json b/AASBufferFix/format.json index 7fa27a9..97d5894 100644 --- a/AASBufferFix/format.json +++ b/AASBufferFix/format.json @@ -1,12 +1,12 @@ { "_id": 126, "name": "AASBufferFix", - "modversion": "1.0.3", + "modversion": "1.0.4", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "Fixes two AAS buffer issues. Remote avatars with AAS will no longer experience wardrobe malfunctions on initialization. (only affects avatar load)\n\nAAS will not be applied unless the synced data matches what is expected of the loaded avatar.", + "description": "Fixes two issues with the Avatar Advanced Settings buffers when loading remote avatars. In simple terms, it means 'fewer wardrobe malfunctions'.\n\nEmpty buffer (all 0/false) will no longer be applied on load.\nReceived AAS data is ignored until the wearer has loaded into the expected avatar.\n(The avatar will sit in its default state until the wearer has loaded and started syncing correct AAS)\n\nPlease view the GitHub README for links to relevant feedback posts.", "searchtags": [ "aas", "sync", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.3/AASBufferFix.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.4/AASBufferFix.dll", "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", - "changelog": "- Initial Release\n- Fixed extremely rare condition where AAS would be applied before ready.\n- Don't destroy helper on first load...'", + "changelog": "- Initial Release", "embedcolor": "9b59b6" } \ No newline at end of file From 7f8dbce9f4300b912b64302ab3238016d4a45d0b Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Thu, 9 Feb 2023 21:28:42 -0600 Subject: [PATCH 12/30] namespace --- AASBufferFix/AASBufferFix.csproj | 12 ++++++------ AASBufferFix/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AASBufferFix/AASBufferFix.csproj b/AASBufferFix/AASBufferFix.csproj index c432ed3..5a31a95 100644 --- a/AASBufferFix/AASBufferFix.csproj +++ b/AASBufferFix/AASBufferFix.csproj @@ -16,22 +16,22 @@ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll - ..\..\..\..\..\..\..\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\Assembly-CSharp-firstpass.dll - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\BTKUILib.dll + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\BTKUILib.dll - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.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 - ..\..\..\..\..\..\..\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.AnimationModule.dll - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AssetBundleModule.dll + C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AssetBundleModule.dll C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll @@ -40,7 +40,7 @@ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll - ..\..\..\..\..\..\..\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.PhysicsModule.dll diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs index 0f06601..7b40838 100644 --- a/AASBufferFix/Properties/AssemblyInfo.cs +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using AASBufferFix.Properties; +using NAK.Melons.AASBufferFix.Properties; using MelonLoader; using System.Reflection; @@ -22,7 +22,7 @@ using System.Reflection; [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] -namespace AASBufferFix.Properties; +namespace NAK.Melons.AASBufferFix.Properties; internal static class AssemblyInfoParams { public const string Version = "1.0.4"; From 495a3b33fdca2a685260f293db441f0324d15a0f Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Thu, 9 Feb 2023 22:58:03 -0600 Subject: [PATCH 13/30] Update README.md --- README.md | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8a451dc..b74e5cd 100644 --- a/README.md +++ b/README.md @@ -17,22 +17,9 @@ The avatar will stay in the default animator state until AAS data is received th 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 -> I am not affiliated with ABI in any official capacity, these mods are not endorsed or outright permitted by ABI and are subject to scrutiny. +> This mod is an independent creation and is not affiliated with, supported by or approved by Alpha Blend Interactive. -> Neither I nor these mods are in any way affiliated with Alpha Blend Interactive and/or ChilloutVR. Using these modifications might cause issues with the performance, security or stability of the game. Use at your own risk. +> 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. -> Any modifications that are not approved can get your ABI account terminated and such this modification is following the "modding guidelines" at the best it could be. -> They reserve the right to punish users using my mod. -> If you are scared of using modifications in your game do not install mods. +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. -> I do not affiliate ABI and the mod is not supported by ABI. - -> Me and this modification are in no affiliation with ABI and not supported by ABI. - -> This mod is not affiliated with Alpha Blend Interactive. The mod comes with no warranty. Use at your own risk, as I am not responsible for any misuse. - -> I'm not affiliated with Alpha Blend Interactive and this mod is not officially supported by the game. - -> When releasing mods to the public, it is required to state, that the mod authors and modification are in no affiliation with ABI and not supported by ABI. :trollface: - -> i ran out of places to steal disclaimers from From 9332b06d063b9b4b8f94db94cda6f0ab1523d18c Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sun, 12 Feb 2023 04:42:07 -0600 Subject: [PATCH 14/30] Don't send AAS while switching avatar. Don't send AAS while switching avatar. This should mean I am less likely to load into the wrong states while switching if others load me faster. This does mean though that it is more likely that remote users will apply null buffers forcing all 0/false instead of garbage aas, but its at least kind of a mitigation. There is a possibility syncing garbage data is better than syncing nothing at all, as that does give the chance to apply settings that don't immediatly load in naked. This just requires testing... --- AASBufferFix/AASBufferHelper.cs | 80 ++++++++++++++----------- AASBufferFix/HarmonyPatches.cs | 13 +++- AASBufferFix/Main.cs | 5 +- AASBufferFix/Properties/AssemblyInfo.cs | 8 +-- AASBufferFix/Utils.cs | 7 +-- AASBufferFix/format.json | 8 +-- 6 files changed, 69 insertions(+), 52 deletions(-) diff --git a/AASBufferFix/AASBufferHelper.cs b/AASBufferFix/AASBufferHelper.cs index 3c1eda9..6a0864d 100644 --- a/AASBufferFix/AASBufferHelper.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -1,10 +1,13 @@ -using ABI_RC.Core.Player; +using ABI.CCK.Components; +using ABI_RC.Core.Player; using UnityEngine; namespace NAK.Melons.AASBufferFix { public class AASBufferHelper : MonoBehaviour { + ///public bool DebuggingFlag = false; + //public stuff public bool GameHandlesAAS { get; private set; } @@ -24,33 +27,38 @@ namespace NAK.Melons.AASBufferFix public void OnAvatarInstantiated(Animator animator) { - - ///MelonLoader.MelonLogger.Msg("[OnInit] Remote avatar initialized. Generating avatar animator footprint."); - - _avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); - - // avatar does not contain proper AAS - // this is likely because the avatar was made before AAS, or is blocked/hidden - if (_avatarFootprint == 1) + //check if avatar uses Avatar Advanced Settings + ///SendDebug("[OnInit] Remote avatar initialized. Checking for AAS..."); + CVRAvatar avatar = animator.GetComponent(); + if (avatar != null && !avatar.avatarUsesAdvancedSettings) { - ///MelonLoader.MelonLogger.Msg("[OnInit] Avatar does not contain valid AAS."); - // we will let the game handle this by setting IsAcceptingAAS to true GameHandlesAAS = true; return; } - ///MelonLoader.MelonLogger.Msg($"[OnInit] Avatar footprint is : {_avatarFootprint}"); + //check if AAS footprint is valid + ///SendDebug("[OnInit] Avatar uses AAS. Generating AAS footprint..."); + _avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); + if (_avatarFootprint == 1) + { + // we will let the game handle this by setting GameHandlesAAS to true + ///SendDebug("[OnInit] Avatar does not contain valid AAS. It is likely hidden or blocked."); + GameHandlesAAS = true; + return; + } + + ///SendDebug($"[OnInit] Avatar footprint is : {_avatarFootprint}"); //check if we received expected AAS while we loaded the avatar, and if so, apply it now if (SyncDataMatchesExpected()) { - ///MelonLoader.MelonLogger.Msg("[OnInit] Valid buffered AAS found. Applying AAS immediatly."); + ///SendDebug("[OnInit] Valid buffered AAS found. Applying buffer..."); ApplyExternalAASBuffer(); return; } //we loaded avatar faster than wearer - ///MelonLoader.MelonLogger.Msg("[OnInit] Remote avatar initialized faster than wearer. Waiting on valid AAS before applying."); + ///SendDebug("[OnInit] Remote avatar initialized faster than wearer. Waiting on valid AAS..."); } public void OnAvatarDestroyed() @@ -60,38 +68,36 @@ namespace NAK.Melons.AASBufferFix _avatarFootprint = 0; } - public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + public void OnReceiveAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) { - //avatar is still loading on our side, we must assume AAS data is correct and store it until we load - //there is also a chance it errored - if (_avatarFootprint == 0) - { - ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar is still loading on our end."); - // Calculate AAS footprint to compare against later. - _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); - StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); - return; - } - - //avatar is loaded on our end, and is not blocked by filter - //this does run if it is manually hidden or distance hidden - - ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar is loaded on our side and is not blocked. Comparing for expected values."); - ///MelonLoader.MelonLogger.Msg($"[OnSync] Avatar Footprint is : {_avatarFootprint}"); - // Calculate AAS footprint to compare against. _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); //if it matches, apply the settings and let game take over if (SyncDataMatchesExpected()) { - ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar values matched and have been applied."); + ///SendDebug("[OnSync] Avatar values matched and have been applied."); ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); return; } + //avatar is still loading on our side, we must assume AAS data is correct and store it until we load + //there is also a chance it errored + //if (_avatarFootprint == 0) + //{ + // ///SendDebug("[OnSync] Avatar is still loading on our end."); + // StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + // return; + //} + + //avatar is loaded on our end, and is not blocked by filter + //this does run if it is manually hidden or distance hidden + + ///SendDebug("[OnSync] Avatar is loaded on our side and is not blocked. Comparing for expected values."); + ///SendDebug($"[OnSync] Avatar Footprint is : {_avatarFootprint}"); + //if it did not match, that means the avatar we see on our side is different than what the remote user is wearing and syncing - ///MelonLoader.MelonLogger.Msg("[OnSync] Avatar loaded is different than wearer. The wearer is likely still loading the avatar!"); + ///SendDebug("[OnSync] Avatar loaded is different than wearer. The wearer is likely still loading the avatar!"); StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); } @@ -118,5 +124,11 @@ namespace NAK.Melons.AASBufferFix } private bool SyncDataMatchesExpected() => _aasFootprint == _avatarFootprint; + + ///private void SendDebug(string message) + ///{ + /// if (!DebuggingFlag) return; + /// AASBufferFix.Logger.Msg(message); + ///} } } \ No newline at end of file diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs index 6fa05ca..c94feaf 100644 --- a/AASBufferFix/HarmonyPatches.cs +++ b/AASBufferFix/HarmonyPatches.cs @@ -39,7 +39,7 @@ internal class HarmonyPatches AASBufferHelper externalBuffer = __instance.GetComponent(); if (externalBuffer != null && !externalBuffer.GameHandlesAAS) { - externalBuffer.OnApplyAAS(settingsFloat, settingsInt, settingsByte); + externalBuffer.OnReceiveAAS(settingsFloat, settingsInt, settingsByte); return false; } return true; @@ -47,7 +47,7 @@ internal class HarmonyPatches [HarmonyPrefix] [HarmonyPatch(typeof(CVRAnimatorManager), "ApplyAdvancedAvatarSettingsFromBuffer")] - private static bool Prefix_PuppetMaster_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator) + private static bool Prefix_CVRAnimatorManager_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator) { AASBufferHelper externalBuffer = ____animator.GetComponentInParent(); if (externalBuffer != null && !externalBuffer.GameHandlesAAS) @@ -57,4 +57,13 @@ internal class HarmonyPatches } return true; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerSetup), "SendAdvancedAvatarSettings")] + private static bool Prefix_PlayerSetup_SendAdvancedAvatarSettings(ref PlayerSetup __instance) + { + //dont sync wrong settings to remote users + if (__instance.avatarIsLoading) return false; + return true; + } } \ No newline at end of file diff --git a/AASBufferFix/Main.cs b/AASBufferFix/Main.cs index c81ebb8..6dea0d2 100644 --- a/AASBufferFix/Main.cs +++ b/AASBufferFix/Main.cs @@ -2,10 +2,11 @@ namespace NAK.Melons.AASBufferFix; -public class AASBufferFixMod : MelonMod +public class AASBufferFix : MelonMod { + ///public static MelonLogger.Instance Logger; public override void OnInitializeMelon() { - //boobs + ///Logger = LoggerInstance; } } \ No newline at end of file diff --git a/AASBufferFix/Properties/AssemblyInfo.cs b/AASBufferFix/Properties/AssemblyInfo.cs index 7b40838..67c5476 100644 --- a/AASBufferFix/Properties/AssemblyInfo.cs +++ b/AASBufferFix/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using NAK.Melons.AASBufferFix.Properties; -using MelonLoader; +using MelonLoader; +using NAK.Melons.AASBufferFix.Properties; using System.Reflection; @@ -11,7 +11,7 @@ using System.Reflection; [assembly: AssemblyProduct(nameof(NAK.Melons.AASBufferFix))] [assembly: MelonInfo( - typeof(NAK.Melons.AASBufferFix.AASBufferFixMod), + typeof(NAK.Melons.AASBufferFix.AASBufferFix), nameof(NAK.Melons.AASBufferFix), AssemblyInfoParams.Version, AssemblyInfoParams.Author, @@ -25,6 +25,6 @@ using System.Reflection; namespace NAK.Melons.AASBufferFix.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.4"; + public const string Version = "1.0.5"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/AASBufferFix/Utils.cs b/AASBufferFix/Utils.cs index e946b26..b66e042 100644 --- a/AASBufferFix/Utils.cs +++ b/AASBufferFix/Utils.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; +using UnityEngine; namespace NAK.Melons.AASBufferFix; diff --git a/AASBufferFix/format.json b/AASBufferFix/format.json index 97d5894..60d8234 100644 --- a/AASBufferFix/format.json +++ b/AASBufferFix/format.json @@ -1,12 +1,12 @@ { "_id": 126, "name": "AASBufferFix", - "modversion": "1.0.4", + "modversion": "1.0.5", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", - "description": "Fixes two issues with the Avatar Advanced Settings buffers when loading remote avatars. In simple terms, it means 'fewer wardrobe malfunctions'.\n\nEmpty buffer (all 0/false) will no longer be applied on load.\nReceived AAS data is ignored until the wearer has loaded into the expected avatar.\n(The avatar will sit in its default state until the wearer has loaded and started syncing correct AAS)\n\nPlease view the GitHub README for links to relevant feedback posts.", + "description": "Fixes two issues with the Avatar Advanced Settings buffers when loading remote avatars. In simple terms, it means 'fewer wardrobe malfunctions'.\n\nEmpty buffer (all 0/false) will no longer be applied on load.\nReceived AAS data is ignored until the wearer has loaded into the expected avatar.\n(The avatar will sit in its default state until the wearer has loaded and started syncing correct AAS)\nAAS will no longer be sent while switching avatar.\n\nPlease view the GitHub README for links to relevant feedback posts.", "searchtags": [ "aas", "sync", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.4/AASBufferFix.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.5/AASBufferFix.dll", "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", - "changelog": "- Initial Release", + "changelog": "- Don't send AAS while switching avatar. This *should* mean using this mod makes you less likely to show naked for others.\nThis isn't perfect though, as remote users without this mod still have a null buffer applied on avatar load.'", "embedcolor": "9b59b6" } \ No newline at end of file From 78bdb0ca0866c2ae64b34dd2172445a29aeb26ef Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sun, 12 Feb 2023 05:11:54 -0600 Subject: [PATCH 15/30] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b74e5cd..c868e54 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Avatars will no longer load in naked or transition to the wrong state on load. AAS will also not be updated unless the expected data matches what is received. The avatar will stay in the default animator state until AAS data is received that is deemed correct. + +You will no longer sync garbage AAS while switching avatar. --- From 38d4d4c83cfc71be01a11154cd4398595bd97ae2 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Sun, 12 Feb 2023 05:12:32 -0600 Subject: [PATCH 16/30] Update format.json --- AASBufferFix/format.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AASBufferFix/format.json b/AASBufferFix/format.json index 60d8234..15cec8d 100644 --- a/AASBufferFix/format.json +++ b/AASBufferFix/format.json @@ -18,6 +18,6 @@ ], "downloadlink": "https://github.com/NotAKidOnSteam/AASBufferFix/releases/download/v1.0.5/AASBufferFix.dll", "sourcelink": "https://github.com/NotAKidOnSteam/AASBufferFix/", - "changelog": "- Don't send AAS while switching avatar. This *should* mean using this mod makes you less likely to show naked for others.\nThis isn't perfect though, as remote users without this mod still have a null buffer applied on avatar load.'", + "changelog": "- Don't send AAS while switching avatar.\n\nPlease read the changelog for [v1.0.5](https://github.com/NotAKidOnSteam/AASBufferFix/releases/tag/v1.0.5) for better understanding of why syncing nothing may be worse than syncing garbage AAS.", "embedcolor": "9b59b6" } \ No newline at end of file From 819a00b27b07110381caf08258be9161cc942444 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:57:18 -0600 Subject: [PATCH 17/30] cleanup --- AASBufferFix/AASBufferHelper.cs | 229 ++++++++++++++++---------------- AASBufferFix/HarmonyPatches.cs | 5 +- 2 files changed, 116 insertions(+), 118 deletions(-) diff --git a/AASBufferFix/AASBufferHelper.cs b/AASBufferFix/AASBufferHelper.cs index 6a0864d..aec0fbd 100644 --- a/AASBufferFix/AASBufferHelper.cs +++ b/AASBufferFix/AASBufferHelper.cs @@ -2,133 +2,132 @@ using ABI_RC.Core.Player; using UnityEngine; -namespace NAK.Melons.AASBufferFix +namespace NAK.Melons.AASBufferFix; + +public class AASBufferHelper : MonoBehaviour { - public class AASBufferHelper : MonoBehaviour + ///public bool DebuggingFlag = false; + + //public stuff + public bool GameHandlesAAS { get; private set; } + + //internal references + private PuppetMaster _puppetMaster; + + //outside aas buffers + private float[] _aasBufferFloat = new float[0]; + private int[] _aasBufferInt = new int[0]; + private byte[] _aasBufferByte = new byte[0]; + + //calculated footprints + private int _aasFootprint = -1; + private int _avatarFootprint = 0; + + private void Start() => _puppetMaster = GetComponent(); + + public void OnAvatarInstantiated(Animator animator) { - ///public bool DebuggingFlag = false; - - //public stuff - public bool GameHandlesAAS { get; private set; } - - //internal references - private PuppetMaster _puppetMaster; - - //outside aas buffers - private float[] _aasBufferFloat = new float[0]; - private int[] _aasBufferInt = new int[0]; - private byte[] _aasBufferByte = new byte[0]; - - //calculated footprints - private int _aasFootprint = -1; - private int _avatarFootprint = 0; - - private void Start() => _puppetMaster = GetComponent(); - - public void OnAvatarInstantiated(Animator animator) - { - //check if avatar uses Avatar Advanced Settings - ///SendDebug("[OnInit] Remote avatar initialized. Checking for AAS..."); - CVRAvatar avatar = animator.GetComponent(); - if (avatar != null && !avatar.avatarUsesAdvancedSettings) - { - GameHandlesAAS = true; - return; - } - - //check if AAS footprint is valid - ///SendDebug("[OnInit] Avatar uses AAS. Generating AAS footprint..."); - _avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); - if (_avatarFootprint == 1) - { - // we will let the game handle this by setting GameHandlesAAS to true - ///SendDebug("[OnInit] Avatar does not contain valid AAS. It is likely hidden or blocked."); - GameHandlesAAS = true; - return; - } - - ///SendDebug($"[OnInit] Avatar footprint is : {_avatarFootprint}"); - - //check if we received expected AAS while we loaded the avatar, and if so, apply it now - if (SyncDataMatchesExpected()) - { - ///SendDebug("[OnInit] Valid buffered AAS found. Applying buffer..."); - ApplyExternalAASBuffer(); - return; - } - - //we loaded avatar faster than wearer - ///SendDebug("[OnInit] Remote avatar initialized faster than wearer. Waiting on valid AAS..."); - } - - public void OnAvatarDestroyed() - { - GameHandlesAAS = false; - _aasFootprint = -1; - _avatarFootprint = 0; - } - - public void OnReceiveAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) - { - // Calculate AAS footprint to compare against. - _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); - - //if it matches, apply the settings and let game take over - if (SyncDataMatchesExpected()) - { - ///SendDebug("[OnSync] Avatar values matched and have been applied."); - ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); - return; - } - - //avatar is still loading on our side, we must assume AAS data is correct and store it until we load - //there is also a chance it errored - //if (_avatarFootprint == 0) - //{ - // ///SendDebug("[OnSync] Avatar is still loading on our end."); - // StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); - // return; - //} - - //avatar is loaded on our end, and is not blocked by filter - //this does run if it is manually hidden or distance hidden - - ///SendDebug("[OnSync] Avatar is loaded on our side and is not blocked. Comparing for expected values."); - ///SendDebug($"[OnSync] Avatar Footprint is : {_avatarFootprint}"); - - //if it did not match, that means the avatar we see on our side is different than what the remote user is wearing and syncing - ///SendDebug("[OnSync] Avatar loaded is different than wearer. The wearer is likely still loading the avatar!"); - StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); - } - - private void ApplyExternalAASBuffer() + //check if avatar uses Avatar Advanced Settings + ///SendDebug("[OnInit] Remote avatar initialized. Checking for AAS..."); + CVRAvatar avatar = animator.GetComponent(); + if (avatar != null && !avatar.avatarUsesAdvancedSettings) { GameHandlesAAS = true; - _puppetMaster?.ApplyAdvancedAvatarSettings(_aasBufferFloat, _aasBufferInt, _aasBufferByte); + return; } - private void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + //check if AAS footprint is valid + ///SendDebug("[OnInit] Avatar uses AAS. Generating AAS footprint..."); + _avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator); + if (_avatarFootprint == 1) { + // we will let the game handle this by setting GameHandlesAAS to true + ///SendDebug("[OnInit] Avatar does not contain valid AAS. It is likely hidden or blocked."); GameHandlesAAS = true; - _puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); + return; } - private void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + ///SendDebug($"[OnInit] Avatar footprint is : {_avatarFootprint}"); + + //check if we received expected AAS while we loaded the avatar, and if so, apply it now + if (SyncDataMatchesExpected()) { - Array.Resize(ref _aasBufferFloat, settingsFloat.Length); - Array.Resize(ref _aasBufferInt, settingsInt.Length); - Array.Resize(ref _aasBufferByte, settingsByte.Length); - Array.Copy(settingsFloat, _aasBufferFloat, settingsFloat.Length); - Array.Copy(settingsInt, _aasBufferInt, settingsInt.Length); - Array.Copy(settingsByte, _aasBufferByte, settingsByte.Length); + ///SendDebug("[OnInit] Valid buffered AAS found. Applying buffer..."); + ApplyExternalAASBuffer(); + return; } - private bool SyncDataMatchesExpected() => _aasFootprint == _avatarFootprint; - - ///private void SendDebug(string message) - ///{ - /// if (!DebuggingFlag) return; - /// AASBufferFix.Logger.Msg(message); - ///} + //we loaded avatar faster than wearer + ///SendDebug("[OnInit] Remote avatar initialized faster than wearer. Waiting on valid AAS..."); } + + public void OnAvatarDestroyed() + { + GameHandlesAAS = false; + _aasFootprint = -1; + _avatarFootprint = 0; + } + + public void OnReceiveAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + // Calculate AAS footprint to compare against. + _aasFootprint = (settingsFloat.Length + 1) * (settingsInt.Length + 1) * (settingsByte.Length + 1); + + //if it matches, apply the settings and let game take over + if (SyncDataMatchesExpected()) + { + ///SendDebug("[OnSync] Avatar values matched and have been applied."); + ApplyExternalAAS(settingsFloat, settingsInt, settingsByte); + return; + } + + //avatar is still loading on our side, we must assume AAS data is correct and store it until we load + //there is also a chance it errored + //if (_avatarFootprint == 0) + //{ + // ///SendDebug("[OnSync] Avatar is still loading on our end."); + // StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + // return; + //} + + //avatar is loaded on our end, and is not blocked by filter + //this does run if it is manually hidden or distance hidden + + ///SendDebug("[OnSync] Avatar is loaded on our side and is not blocked. Comparing for expected values."); + ///SendDebug($"[OnSync] Avatar Footprint is : {_avatarFootprint}"); + + //if it did not match, that means the avatar we see on our side is different than what the remote user is wearing and syncing + ///SendDebug("[OnSync] Avatar loaded is different than wearer. The wearer is likely still loading the avatar!"); + StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte); + } + + private void ApplyExternalAASBuffer() + { + GameHandlesAAS = true; + _puppetMaster?.ApplyAdvancedAvatarSettings(_aasBufferFloat, _aasBufferInt, _aasBufferByte); + } + + private void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + GameHandlesAAS = true; + _puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte); + } + + private void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte) + { + Array.Resize(ref _aasBufferFloat, settingsFloat.Length); + Array.Resize(ref _aasBufferInt, settingsInt.Length); + Array.Resize(ref _aasBufferByte, settingsByte.Length); + Array.Copy(settingsFloat, _aasBufferFloat, settingsFloat.Length); + Array.Copy(settingsInt, _aasBufferInt, settingsInt.Length); + Array.Copy(settingsByte, _aasBufferByte, settingsByte.Length); + } + + private bool SyncDataMatchesExpected() => _aasFootprint == _avatarFootprint; + + ///private void SendDebug(string message) + ///{ + /// if (!DebuggingFlag) return; + /// AASBufferFix.Logger.Msg(message); + ///} } \ No newline at end of file diff --git a/AASBufferFix/HarmonyPatches.cs b/AASBufferFix/HarmonyPatches.cs index c94feaf..ad559c2 100644 --- a/AASBufferFix/HarmonyPatches.cs +++ b/AASBufferFix/HarmonyPatches.cs @@ -13,7 +13,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PuppetMaster), "Start")] private static void Postfix_PuppetMaster_Start(ref PuppetMaster __instance) { - AASBufferHelper externalBuffer = __instance.AddComponentIfMissing(); + __instance.AddComponentIfMissing(); } [HarmonyPostfix] @@ -63,7 +63,6 @@ internal class HarmonyPatches private static bool Prefix_PlayerSetup_SendAdvancedAvatarSettings(ref PlayerSetup __instance) { //dont sync wrong settings to remote users - if (__instance.avatarIsLoading) return false; - return true; + return !__instance.avatarIsLoading; } } \ No newline at end of file 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 18/30] 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 19/30] 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 20/30] 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 21/30] 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 22/30] 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 23/30] 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 24/30] 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 25/30] 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 26/30] 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 27/30] 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 28/30] 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 29/30] 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. --- From 5d24c8857c1cde0b8997e4c54f53e86097cb2a88 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:02:35 -0500 Subject: [PATCH 30/30] Revert "Merged BadAnimatorFix repo" This reverts commit d1f1b9c3a855d05e8a6ce6de07932568122bcfae, reversing changes made to 819a00b27b07110381caf08258be9161cc942444. --- BadAnimatorFix/BadAnimatorFix.cs | 52 ----------------- BadAnimatorFix/BadAnimatorFix.csproj | 71 ----------------------- BadAnimatorFix/BadAnimatorFix.sln | 25 -------- BadAnimatorFix/BadAnimatorFixManager.cs | 67 --------------------- BadAnimatorFix/HarmonyPatches.cs | 63 -------------------- BadAnimatorFix/Main.cs | 59 ------------------- BadAnimatorFix/Properties/AssemblyInfo.cs | 30 ---------- BadAnimatorFix/format.json | 23 -------- README.md | 26 --------- 9 files changed, 416 deletions(-) delete mode 100644 BadAnimatorFix/BadAnimatorFix.cs delete mode 100644 BadAnimatorFix/BadAnimatorFix.csproj delete mode 100644 BadAnimatorFix/BadAnimatorFix.sln delete mode 100644 BadAnimatorFix/BadAnimatorFixManager.cs delete mode 100644 BadAnimatorFix/HarmonyPatches.cs delete mode 100644 BadAnimatorFix/Main.cs delete mode 100644 BadAnimatorFix/Properties/AssemblyInfo.cs delete mode 100644 BadAnimatorFix/format.json diff --git a/BadAnimatorFix/BadAnimatorFix.cs b/BadAnimatorFix/BadAnimatorFix.cs deleted file mode 100644 index 494ce52..0000000 --- a/BadAnimatorFix/BadAnimatorFix.cs +++ /dev/null @@ -1,52 +0,0 @@ -using UnityEngine; -using UnityEngine.Playables; - -namespace NAK.Melons.BadAnimatorFix; - -public class BadAnimatorFix : MonoBehaviour -{ - private const float StateLimit = 20f; - - private Animator animator; - - private void Start() - { - animator = GetComponent(); - } - - private void OnEnable() => BadAnimatorFixManager.Add(this); - private void OnDisable() => BadAnimatorFixManager.Remove(this); - - public void AttemptRewindAnimator() - { - bool rewound = false; - - if (animator != null && animator.isActiveAndEnabled) - { - for (int layerIndex = 0; layerIndex < animator.layerCount; layerIndex++) - { - AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex); - AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex); - // 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) - { - 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}."; - BadAnimatorFixMod.Logger.Msg(message); - } - } -} \ No newline at end of file diff --git a/BadAnimatorFix/BadAnimatorFix.csproj b/BadAnimatorFix/BadAnimatorFix.csproj deleted file mode 100644 index 040f29a..0000000 --- a/BadAnimatorFix/BadAnimatorFix.csproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - - netstandard2.1 - enable - latest - false - True - - - - - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll - - - ..\..\FuckCohtml\FuckMetrics\ManagedLibs\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 deleted file mode 100644 index 83f9cfb..0000000 --- a/BadAnimatorFix/BadAnimatorFix.sln +++ /dev/null @@ -1,25 +0,0 @@ - -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/BadAnimatorFixManager.cs b/BadAnimatorFix/BadAnimatorFixManager.cs deleted file mode 100644 index 6497ca4..0000000 --- a/BadAnimatorFix/BadAnimatorFixManager.cs +++ /dev/null @@ -1,67 +0,0 @@ -using ABI_RC.Core.IO; -using UnityEngine; -using UnityEngine.SceneManagement; - -namespace NAK.Melons.BadAnimatorFix; - -public static class BadAnimatorFixManager -{ - 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 OnPlayerLoaded() - { - ToggleJob(BadAnimatorFixMod.EntryEnabled.Value); - } - - 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(); - } - } - } - - private static void CheckNextAnimator() - { - if (badAnimatorFixes.Count == 0) return; - currentIndex = (currentIndex + 1) % badAnimatorFixes.Count; - - BadAnimatorFix currentAnimatorFix = badAnimatorFixes[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(CheckNextAnimator), 0f, checkInterval, -1); - } - else if (!enable && job != null) - { - SchedulerSystem.RemoveJob(job); - } - } -} diff --git a/BadAnimatorFix/HarmonyPatches.cs b/BadAnimatorFix/HarmonyPatches.cs deleted file mode 100644 index 617e773..0000000 --- a/BadAnimatorFix/HarmonyPatches.cs +++ /dev/null @@ -1,63 +0,0 @@ -using ABI.CCK.Components; -using ABI_RC.Core.InteractionSystem; -using ABI_RC.Core.Player; -using HarmonyLib; -using UnityEngine; - -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) - { - 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); - } - - // Set QM stuff - [HarmonyPostfix] - [HarmonyPatch(typeof(CVR_MenuManager), "Start")] - private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance) - { - 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) - { - Animator[] animators = gameObject.GetComponentsInChildren(true); - foreach (Animator animator in animators) - { - if (!animator.TryGetComponent(out _)) - { - animator.gameObject.AddComponent(); - } - } - } -} diff --git a/BadAnimatorFix/Main.cs b/BadAnimatorFix/Main.cs deleted file mode 100644 index c25f91f..0000000 --- a/BadAnimatorFix/Main.cs +++ /dev/null @@ -1,59 +0,0 @@ -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", true, description: "Should BadAnimatorFix run for CVRSpawnable? Requires spawnable reload."); - - public static readonly MelonPreferences_Entry EntryCVRWorld = - 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", true, description: "Should BadAnimatorFix run for QM & MM? Requires game restart."); - - public static readonly MelonPreferences_Entry EntryLogging = - CategoryBadAnimatorFix.CreateEntry("Debugging", 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)); - } - - public override void OnSceneWasInitialized(int buildIndex, string sceneName) - { - if (!EntryCVRWorld.Value) return; - BadAnimatorFixManager.OnSceneInitialized(sceneName); - } - - private void OnEnabled(object arg1, object arg2) - { - BadAnimatorFixManager.ToggleJob(EntryEnabled.Value); - } - - 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 deleted file mode 100644 index 4b98794..0000000 --- a/BadAnimatorFix/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index df8fd08..0000000 --- a/BadAnimatorFix/format.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_id": -1, - "name": "BadAnimatorFix", - "modversion": "1.0.0", - "gameversion": "2022r170", - "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 *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", - "animator", - "loop" - ], - "requirements": [ - "None" - ], - "downloadlink": "https://github.com/NotAKidOnSteam/BadAnimatorFix/releases/download/v1.0.0/BadAnimatorFix.dll", - "sourcelink": "https://github.com/NotAKidOnSteam/BadAnimatorFix/", - "changelog": "Initial Release", - "embedcolor": "7F3F99" -} \ No newline at end of file diff --git a/README.md b/README.md index 8e4424e..c868e54 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -<<<<<<< HEAD # AASBufferFix Fixes two issues with the Avatar Advanced Settings buffers when loading remote avatars: @@ -15,28 +14,6 @@ The avatar will stay in the default animator state until AAS data is received th You will no longer sync garbage AAS while switching avatar. -======= -# BadAnimatorFix - A bad fix for a niche 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. - -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. 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. - ->>>>>>> BadAnimatorFix/main --- Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. @@ -47,7 +24,4 @@ https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games > 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. -<<<<<<< HEAD -======= ->>>>>>> BadAnimatorFix/main