using System.Numerics; using System.Runtime.InteropServices; using System.Text; namespace Shared.Packet.Packets; [Packet(PacketType.Player)] public struct PlayerPacket : IPacket { public const int ActSize = 0x20; public const int SubActSize = 0x10; public Vector3 Position; public Quaternion Rotation; public float[] AnimationBlendWeights = Array.Empty(); public ushort Act; public ushort SubAct; public PlayerPacket() { Position = default; Rotation = default; Act = 0; SubAct = 0; } public short Size => 0x38; public void Serialize(Span data) { int offset = 0; MemoryMarshal.Write(data[..(offset += Marshal.SizeOf())], ref Position); MemoryMarshal.Write(data[offset..(offset += Marshal.SizeOf())], ref Rotation); AnimationBlendWeights.CopyTo(MemoryMarshal.Cast(data[offset..(offset += 4 * 6)])); MemoryMarshal.Write(data[offset++..++offset], ref Act); MemoryMarshal.Write(data[offset++..++offset], ref SubAct); } public void Deserialize(ReadOnlySpan data) { int offset = 0; Position = MemoryMarshal.Read(data[..(offset += Marshal.SizeOf())]); Rotation = MemoryMarshal.Read(data[offset..(offset += Marshal.SizeOf())]); AnimationBlendWeights = MemoryMarshal.Cast(data[offset..(offset += 4 * 6)]).ToArray(); Act = MemoryMarshal.Read(data[offset++..++offset]); SubAct = MemoryMarshal.Read(data[offset++..++offset]); } }