mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-27 21:53:05 +00:00
Better player packet
This commit is contained in:
parent
217dc2765e
commit
15960a8d5a
1 changed files with 9 additions and 10 deletions
|
@ -15,26 +15,25 @@ public struct PlayerPacket : IPacket {
|
|||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
|
||||
public float[] AnimationBlendWeights = Array.Empty<float>();
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ActSize)]
|
||||
public string Act = "";
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = SubActSize)]
|
||||
public string SubAct = "";
|
||||
public ushort Act;
|
||||
public ushort SubAct;
|
||||
|
||||
public PlayerPacket() {
|
||||
Position = default;
|
||||
Rotation = default;
|
||||
Act = 0;
|
||||
SubAct = 0;
|
||||
}
|
||||
|
||||
public short Size => 0x64;
|
||||
public short Size => 0x38;
|
||||
|
||||
public void Serialize(Span<byte> data) {
|
||||
int offset = 0;
|
||||
MemoryMarshal.Write(data[..(offset += Marshal.SizeOf<Vector3>())], ref Position);
|
||||
MemoryMarshal.Write(data[offset..(offset += Marshal.SizeOf<Quaternion>())], ref Rotation);
|
||||
AnimationBlendWeights.CopyTo(MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]));
|
||||
Encoding.UTF8.GetBytes(Act).CopyTo(data[offset..(offset += ActSize)]);
|
||||
Encoding.UTF8.GetBytes(SubAct).CopyTo(data[offset..(offset + SubActSize)]);
|
||||
MemoryMarshal.Write(data[offset++..++offset], ref Act);
|
||||
MemoryMarshal.Write(data[offset++..++offset], ref SubAct);
|
||||
}
|
||||
|
||||
public void Deserialize(Span<byte> data) {
|
||||
|
@ -42,7 +41,7 @@ public struct PlayerPacket : IPacket {
|
|||
Position = MemoryMarshal.Read<Vector3>(data[..(offset += Marshal.SizeOf<Vector3>())]);
|
||||
Rotation = MemoryMarshal.Read<Quaternion>(data[offset..(offset += Marshal.SizeOf<Quaternion>())]);
|
||||
AnimationBlendWeights = MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]).ToArray();
|
||||
Act = Encoding.UTF8.GetString(data[offset..(offset += ActSize)]).TrimEnd('\0');
|
||||
SubAct = Encoding.UTF8.GetString(data[offset..(offset + SubActSize)]).TrimEnd('\0');
|
||||
Act = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
|
||||
SubAct = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue