0
0
Fork 0
mirror of https://github.com/Sanae6/SmoOnlineServer.git synced 2024-11-22 03:05:16 +00:00
SmoOnlineServer/Shared/Packet/Packets/PlayerPacket.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2022-02-04 09:45:38 +00:00
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
namespace Shared.Packet.Packets;
[Packet(PacketType.Player)]
public struct PlayerPacket : IPacket {
2022-03-13 11:14:01 +00:00
public const int ActSize = 0x20;
public const int SubActSize = 0x10;
2022-02-04 09:45:38 +00:00
2022-03-13 11:14:01 +00:00
public Vector3 Position;
public Quaternion Rotation;
2022-02-10 01:44:50 +00:00
public float[] AnimationBlendWeights = Array.Empty<float>();
2022-02-10 01:44:50 +00:00
2022-03-14 00:07:26 +00:00
public ushort Act;
public ushort SubAct;
2022-02-10 01:44:50 +00:00
2022-03-13 11:14:01 +00:00
public PlayerPacket() {
Position = default;
Rotation = default;
2022-03-14 00:07:26 +00:00
Act = 0;
SubAct = 0;
2022-03-13 11:14:01 +00:00
}
2022-03-14 00:07:26 +00:00
public short Size => 0x38;
2022-02-04 09:45:38 +00:00
public void Serialize(Span<byte> data) {
int offset = 0;
2022-03-13 11:14:01 +00:00
MemoryMarshal.Write(data[..(offset += Marshal.SizeOf<Vector3>())], ref Position);
MemoryMarshal.Write(data[offset..(offset += Marshal.SizeOf<Quaternion>())], ref Rotation);
2022-02-04 09:45:38 +00:00
AnimationBlendWeights.CopyTo(MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]));
2022-03-14 00:07:26 +00:00
MemoryMarshal.Write(data[offset++..++offset], ref Act);
MemoryMarshal.Write(data[offset++..++offset], ref SubAct);
2022-02-04 09:45:38 +00:00
}
public void Deserialize(ReadOnlySpan<byte> data) {
2022-02-04 09:45:38 +00:00
int offset = 0;
2022-03-13 11:14:01 +00:00
Position = MemoryMarshal.Read<Vector3>(data[..(offset += Marshal.SizeOf<Vector3>())]);
Rotation = MemoryMarshal.Read<Quaternion>(data[offset..(offset += Marshal.SizeOf<Quaternion>())]);
2022-02-04 09:45:38 +00:00
AnimationBlendWeights = MemoryMarshal.Cast<byte, float>(data[offset..(offset += 4 * 6)]).ToArray();
2022-03-14 00:07:26 +00:00
Act = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
SubAct = MemoryMarshal.Read<ushort>(data[offset++..++offset]);
2022-02-04 09:45:38 +00:00
}
2021-11-29 04:04:34 +00:00
}