NAK_CVR_Mods/AASBufferFix/HarmonyPatches.cs
NotAKidoS 9332b06d06 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...
2023-02-12 04:42:07 -06:00

69 lines
No EOL
2.6 KiB
C#

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)
{
AASBufferHelper externalBuffer = __instance.AddComponentIfMissing<AASBufferHelper>();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PuppetMaster), "AvatarInstantiated")]
private static void Postfix_PuppetMaster_AvatarInstantiated(ref PuppetMaster __instance, ref Animator ____animator)
{
AASBufferHelper externalBuffer = __instance.GetComponent<AASBufferHelper>();
if (externalBuffer != null) externalBuffer.OnAvatarInstantiated(____animator);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PuppetMaster), "AvatarDestroyed")]
private static void Postfix_PuppetMaster_AvatarDestroyed(ref PuppetMaster __instance)
{
AASBufferHelper externalBuffer = __instance.GetComponent<AASBufferHelper>();
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)
{
AASBufferHelper externalBuffer = __instance.GetComponent<AASBufferHelper>();
if (externalBuffer != null && !externalBuffer.GameHandlesAAS)
{
externalBuffer.OnReceiveAAS(settingsFloat, settingsInt, settingsByte);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(CVRAnimatorManager), "ApplyAdvancedAvatarSettingsFromBuffer")]
private static bool Prefix_CVRAnimatorManager_ApplyAdvancedAvatarSettingsFromBuffer(ref Animator ____animator)
{
AASBufferHelper externalBuffer = ____animator.GetComponentInParent<AASBufferHelper>();
if (externalBuffer != null && !externalBuffer.GameHandlesAAS)
{
//dont apply if stable buffer no exist
return false;
}
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;
}
}