Skip to content

Commit

Permalink
Merge pull request #3 from lonelyicer/dev
Browse files Browse the repository at this point in the history
feat: legacy protocol supported
  • Loading branch information
lonelyicer authored Sep 14, 2024
2 parents 38c33ee + e2d8cb6 commit 908eddc
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 220 deletions.
81 changes: 81 additions & 0 deletions VRCFTPicoModule/Data/BlendShapeIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
namespace VRCFTPicoModule.Data;

public class BlendShape
{
public enum Index
{
EyeLookDown_L = 0,
NoseSneer_L = 1,
EyeLookIn_L = 2,
BrowInnerUp = 3,
BrowDown_R = 4,
MouthClose = 5,
MouthLowerDown_R = 6,
JawOpen = 7,
MouthUpperUp_R = 8,
MouthShrugUpper = 9,
MouthFunnel = 10,
EyeLookIn_R = 11,
EyeLookDown_R = 12,
NoseSneer_R = 13,
MouthRollUpper = 14,
JawRight = 15,
BrowDown_L = 16,
MouthShrugLower = 17,
MouthRollLower = 18,
MouthSmile_L = 19,
MouthPress_L = 20,
MouthSmile_R = 21,
MouthPress_R = 22,
MouthDimple_R = 23,
MouthLeft = 24,
JawForward = 25,
EyeSquint_L = 26,
MouthFrown_L = 27,
EyeBlink_L = 28,
CheekSquint_L = 29,
BrowOuterUp_L = 30,
EyeLookUp_L = 31,
JawLeft = 32,
MouthStretch_L = 33,
MouthPucker = 34,
EyeLookUp_R = 35,
BrowOuterUp_R = 36,
CheekSquint_R = 37,
EyeBlink_R = 38,
MouthUpperUp_L = 39,
MouthFrown_R = 40,
EyeSquint_R = 41,
MouthStretch_R = 42,
CheekPuff = 43,
EyeLookOut_L = 44,
EyeLookOut_R = 45,
EyeWide_R = 46,
EyeWide_L = 47,
MouthRight = 48,
MouthDimple_L = 49,
MouthLowerDown_L = 50,
TongueOut = 51,
PP = 52,
CH = 53,
o = 54,
O = 55,
I = 56,
u = 57,
RR = 58,
XX = 59,
aa = 60,
i = 61,
FF = 62,
U = 63,
TH = 64,
kk = 65,
SS = 66,
e = 67,
DD = 68,
E = 69,
nn = 70,
sil = 71
};
}

35 changes: 35 additions & 0 deletions VRCFTPicoModule/Data/DataPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Runtime.InteropServices;

namespace VRCFTPicoModule.Data
{
public class DataPacket
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DataPackHeader
{
public byte startCode1;
public byte startCode2;
public byte trackingType;
public byte subType;
public byte multiPack;
public byte currentIndex;
public ushort version;
public ulong timeStamp;
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DataPackBody
{
public long timeStamp;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 72)]
public float[] blendShapeWeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public float[] videoInputValid;
public float laughingProb;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public float[] emotionProb;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public float[] reserved;
}
}
}
22 changes: 22 additions & 0 deletions VRCFTPicoModule/Data/LegacyDataPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Runtime.InteropServices;

namespace VRCFTPicoModule.Data
{
public class LegacyDataPacket
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DataPackBody
{
public Int64 timestamp;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 72)]
public float[] blendShapeWeight;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public float[] videoInputValid;
public float laughingProb;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
public float[] emotionProb;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
public float[] reserved;
};
}
}
24 changes: 24 additions & 0 deletions VRCFTPicoModule/Utils/DataPacketHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;

namespace VRCFTPicoModule.Utils
{
public static class DataPacketHelpers
{
public static T ByteArrayToStructure<T>(byte[] bytes, int offset = 0) where T : struct
{
int size = Marshal.SizeOf(typeof(T));
IntPtr ptr = Marshal.AllocHGlobal(size);

try
{
Marshal.Copy(bytes, offset, ptr, size);
return (T)Marshal.PtrToStructure(ptr, typeof(T))!;
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
}
}
Loading

0 comments on commit 908eddc

Please sign in to comment.