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] 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