0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-30 23:23:07 +00:00

Better player packet

This commit is contained in:
Sanae 2022-03-13 18:07:26 -06:00
parent 217dc2765e
commit 15960a8d5a

View file

@ -15,26 +15,25 @@ public struct PlayerPacket : IPacket {
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public float[] AnimationBlendWeights = Array.Empty<float>(); public float[] AnimationBlendWeights = Array.Empty<float>();
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ActSize)] public ushort Act;
public string Act = ""; public ushort SubAct;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = SubActSize)]
public string SubAct = "";
public PlayerPacket() { public PlayerPacket() {
Position = default; Position = default;
Rotation = default; Rotation = default;
Act = 0;
SubAct = 0;
} }
public short Size => 0x64; public short Size => 0x38;
public void Serialize(Span<byte> data) { public void Serialize(Span<byte> data) {
int offset = 0; int offset = 0;
MemoryMarshal.Write(data[..(offset += Marshal.SizeOf<Vector3>())], ref Position); MemoryMarshal.Write(data[..(offset += Marshal.SizeOf<Vector3>())], ref Position);
MemoryMarshal.Write(data[offset..(offset += Marshal.SizeOf<Quaternion>())], ref Rotation); MemoryMarshal.Write(data[offset..(offset += Marshal.SizeOf<Quaternion>())], ref Rotation);
AnimationBlendWeights.CopyTo(MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)])); AnimationBlendWeights.CopyTo(MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]));
Encoding.UTF8.GetBytes(Act).CopyTo(data[offset..(offset += ActSize)]); MemoryMarshal.Write(data[offset++..++offset], ref Act);
Encoding.UTF8.GetBytes(SubAct).CopyTo(data[offset..(offset + SubActSize)]); MemoryMarshal.Write(data[offset++..++offset], ref SubAct);
} }
public void Deserialize(Span<byte> data) { public void Deserialize(Span<byte> data) {
@ -42,7 +41,7 @@ public struct PlayerPacket : IPacket {
Position = MemoryMarshal.Read<Vector3>(data[..(offset += Marshal.SizeOf<Vector3>())]); Position = MemoryMarshal.Read<Vector3>(data[..(offset += Marshal.SizeOf<Vector3>())]);
Rotation = MemoryMarshal.Read<Quaternion>(data[offset..(offset += Marshal.SizeOf<Quaternion>())]); Rotation = MemoryMarshal.Read<Quaternion>(data[offset..(offset += Marshal.SizeOf<Quaternion>())]);
AnimationBlendWeights = MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]).ToArray(); AnimationBlendWeights = MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]).ToArray();
Act = Encoding.UTF8.GetString(data[offset..(offset += ActSize)]).TrimEnd('\0'); Act = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
SubAct = Encoding.UTF8.GetString(data[offset..(offset + SubActSize)]).TrimEnd('\0'); SubAct = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
} }
} }