mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
funny refactor
provides nothing over the previous version
This commit is contained in:
parent
b5fb7bdac6
commit
fea8d3e3c1
3 changed files with 132 additions and 92 deletions
|
@ -5,122 +5,95 @@ namespace NAK.Melons.AASBufferFix;
|
||||||
|
|
||||||
public class AASBufferFix : MonoBehaviour
|
public class AASBufferFix : MonoBehaviour
|
||||||
{
|
{
|
||||||
public PuppetMaster puppetMaster;
|
public bool isAcceptingAAS = true;
|
||||||
|
|
||||||
public bool isAcceptingAAS = false;
|
internal PuppetMaster puppetMaster;
|
||||||
|
|
||||||
public float[] aasBufferFloat = new float[0];
|
//outside buffers that dont get nuked on avatar load
|
||||||
public int[] aasBufferInt = new int[0];
|
private float[] aasBufferFloat = new float[0];
|
||||||
public byte[] aasBufferByte = new byte[0];
|
private int[] aasBufferInt = new int[0];
|
||||||
|
private byte[] aasBufferByte = new byte[0];
|
||||||
|
|
||||||
public int aasFootprint = -1;
|
//footprint is each parameter bit type count multiplied together
|
||||||
public int avatarFootprint = -1;
|
private int aasFootprint = -1;
|
||||||
|
private int avatarFootprint = 0;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
puppetMaster = GetComponent<PuppetMaster>();
|
puppetMaster = GetComponent<PuppetMaster>();
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public void OnAvatarInstantiated(Animator animator)
|
||||||
{
|
{
|
||||||
avatarFootprint = GenerateAvatarFootprint(animator);
|
//create the loaded avatar footprint
|
||||||
CheckForFootprintMatch();
|
avatarFootprint = Utils.GenerateAnimatorAASFootprint(animator);
|
||||||
|
|
||||||
|
//previous "bad data" now matches, apply buffered data
|
||||||
|
if (SyncDataMatchesExpected())
|
||||||
|
{
|
||||||
|
ApplyExternalAASBuffer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAvatarDestroyed()
|
public void OnAvatarDestroyed()
|
||||||
{
|
{
|
||||||
isAcceptingAAS = false;
|
|
||||||
//clear buffer
|
|
||||||
aasBufferFloat = new float[0];
|
|
||||||
aasBufferInt = new int[0];
|
|
||||||
aasBufferByte = new byte[0];
|
|
||||||
avatarFootprint = 0;
|
|
||||||
aasFootprint = -1;
|
aasFootprint = -1;
|
||||||
|
avatarFootprint = 0;
|
||||||
|
isAcceptingAAS = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckForFootprintMatch()
|
public void OnApplyAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte)
|
||||||
{
|
{
|
||||||
//only apply if avatar footprints match
|
//create the synced data footprint
|
||||||
if (aasFootprint == avatarFootprint)
|
aasFootprint = ((settingsFloat.Length * 32) + 1) * ((settingsInt.Length * 32) + 1) * ((settingsByte.Length * 8) + 1);
|
||||||
|
|
||||||
|
if (!SyncDataMatchesExpected())
|
||||||
|
{
|
||||||
|
if (avatarFootprint == 0)
|
||||||
|
{
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplyExternalAASBuffer()
|
||||||
{
|
{
|
||||||
isAcceptingAAS = true;
|
isAcceptingAAS = true;
|
||||||
puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte);
|
puppetMaster?.ApplyAdvancedAvatarSettings(aasBufferFloat, aasBufferInt, aasBufferByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ApplyExternalAAS(float[] settingsFloat, int[] settingsInt, byte[] settingsByte)
|
||||||
|
{
|
||||||
|
isAcceptingAAS = true;
|
||||||
|
puppetMaster?.ApplyAdvancedAvatarSettings(settingsFloat, settingsInt, settingsByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GenerateAvatarFootprint(Animator animator)
|
public void StoreExternalAASBuffer(float[] settingsFloat, int[] settingsInt, byte[] settingsByte)
|
||||||
{
|
{
|
||||||
int avatarFloatCount = 0;
|
Array.Resize(ref aasBufferFloat, settingsFloat.Length);
|
||||||
int avatarIntCount = 0;
|
Array.Resize(ref aasBufferInt, settingsInt.Length);
|
||||||
int avatarBoolCount = 0;
|
Array.Resize(ref aasBufferByte, settingsByte.Length);
|
||||||
|
Array.Copy(settingsFloat, aasBufferFloat, settingsFloat.Length);
|
||||||
foreach (AnimatorControllerParameter animatorControllerParameter in animator.parameters)
|
Array.Copy(settingsInt, aasBufferInt, settingsInt.Length);
|
||||||
{
|
Array.Copy(settingsByte, aasBufferByte, settingsByte.Length);
|
||||||
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
|
public bool SyncDataMatchesExpected()
|
||||||
avatarBoolCount = ((int)Math.Ceiling((double)avatarBoolCount / 8) * 8);
|
|
||||||
|
|
||||||
//create the footprint
|
|
||||||
return (avatarFloatCount + 1) * (avatarIntCount + 1) * (avatarBoolCount + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HashSet<string> coreParameters = new HashSet<string>
|
|
||||||
{
|
{
|
||||||
"MovementX",
|
return aasFootprint == avatarFootprint;
|
||||||
"MovementY",
|
}
|
||||||
"Grounded",
|
|
||||||
"Emote",
|
|
||||||
"GestureLeft",
|
|
||||||
"GestureRight",
|
|
||||||
"Toggle",
|
|
||||||
"Sitting",
|
|
||||||
"Crouching",
|
|
||||||
"CancelEmote",
|
|
||||||
"Prone",
|
|
||||||
"Flying"
|
|
||||||
};
|
|
||||||
}
|
}
|
|
@ -40,7 +40,7 @@ internal class HarmonyPatches
|
||||||
AASBufferFix externalBuffer = __instance.GetComponent<AASBufferFix>();
|
AASBufferFix externalBuffer = __instance.GetComponent<AASBufferFix>();
|
||||||
if (externalBuffer != null && !externalBuffer.isAcceptingAAS)
|
if (externalBuffer != null && !externalBuffer.isAcceptingAAS)
|
||||||
{
|
{
|
||||||
externalBuffer.StoreExternalAASBuffer(settingsFloat, settingsInt, settingsByte);
|
externalBuffer.OnApplyAAS(settingsFloat, settingsInt, settingsByte);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
67
AASBufferFix/Utils.cs
Normal file
67
AASBufferFix/Utils.cs
Normal file
|
@ -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<string> coreParameters = new HashSet<string>
|
||||||
|
{
|
||||||
|
"MovementX",
|
||||||
|
"MovementY",
|
||||||
|
"Grounded",
|
||||||
|
"Emote",
|
||||||
|
"GestureLeft",
|
||||||
|
"GestureRight",
|
||||||
|
"Toggle",
|
||||||
|
"Sitting",
|
||||||
|
"Crouching",
|
||||||
|
"CancelEmote",
|
||||||
|
"Prone",
|
||||||
|
"Flying"
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue