diff --git a/Shared/Constants.cs b/Shared/Constants.cs index 8506fdf..7100594 100644 --- a/Shared/Constants.cs +++ b/Shared/Constants.cs @@ -9,6 +9,7 @@ public static class Constants { public const int MaxPacketSize = 256; public const int MaxClients = 4; public static int HeaderSize { get; } = Marshal.SizeOf(); + public static int PacketDataSize { get; } = MaxPacketSize - HeaderSize; public const int CostumeNameSize = 0x20; // dictionary of packet types to packet diff --git a/Shared/Packet/PacketAttribute.cs b/Shared/Packet/PacketAttribute.cs index cbce796..a411749 100644 --- a/Shared/Packet/PacketAttribute.cs +++ b/Shared/Packet/PacketAttribute.cs @@ -1,6 +1,6 @@ namespace Shared.Packet; -[AttributeUsage(AttributeTargets.Struct)] +[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true)] public class PacketAttribute : Attribute { public PacketType Type { get; } public PacketAttribute(PacketType type) { diff --git a/Shared/Packet/PacketType.cs b/Shared/Packet/PacketType.cs index a354f24..12cb7a1 100644 --- a/Shared/Packet/PacketType.cs +++ b/Shared/Packet/PacketType.cs @@ -10,5 +10,6 @@ public enum PacketType { Disconnect, Costume, Shine, + Capture, Command } \ No newline at end of file diff --git a/Shared/Packet/Packets/CapPacket.cs b/Shared/Packet/Packets/CapPacket.cs index 1601733..3a67290 100644 --- a/Shared/Packet/Packets/CapPacket.cs +++ b/Shared/Packet/Packets/CapPacket.cs @@ -4,7 +4,8 @@ using System.Text; namespace Shared.Packet.Packets; -public class CapPacket : IPacket { +[Packet(PacketType.Cap)] +public struct CapPacket : IPacket { public const int NameSize = 0x30; public Vector3 Position; public Quaternion Rotation; diff --git a/Shared/Packet/Packets/CapturePacket.cs b/Shared/Packet/Packets/CapturePacket.cs index b51aace..549108f 100644 --- a/Shared/Packet/Packets/CapturePacket.cs +++ b/Shared/Packet/Packets/CapturePacket.cs @@ -3,7 +3,8 @@ using System.Text; namespace Shared.Packet.Packets; -public class CapturePacket : IPacket { +[Packet(PacketType.Capture)] +public struct CapturePacket : IPacket { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.CostumeNameSize)] public string ModelName; public bool IsCaptured; diff --git a/Shared/Packet/Packets/CommandPacket.cs b/Shared/Packet/Packets/CommandPacket.cs deleted file mode 100644 index 8d30f5c..0000000 --- a/Shared/Packet/Packets/CommandPacket.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Shared.Packet.Packets; - -[Packet(PacketType.Command)] -public struct CommandPacket : IPacket { - //todo: implement something for this - public void Serialize(Span data) { - - } - - public void Deserialize(Span data) { - - } -} \ No newline at end of file diff --git a/Shared/Packet/Packets/MovementFlags.cs b/Shared/Packet/Packets/MovementFlags.cs deleted file mode 100644 index 30c0898..0000000 --- a/Shared/Packet/Packets/MovementFlags.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Shared.Packet.Packets; - -[Flags] -public enum MovementFlags : byte { - IsFlat, - IsCapThrown, - IsSeeker -} \ No newline at end of file diff --git a/Shared/Packet/Packets/TagPacket.cs b/Shared/Packet/Packets/TagPacket.cs index b94fbf4..695ecb7 100644 --- a/Shared/Packet/Packets/TagPacket.cs +++ b/Shared/Packet/Packets/TagPacket.cs @@ -2,7 +2,8 @@ namespace Shared.Packet.Packets; -public class TagPacket : IPacket { +[Packet(PacketType.Tag)] +public struct TagPacket : IPacket { public bool IsIt = false; public void Serialize(Span data) { MemoryMarshal.Write(data, ref IsIt); diff --git a/Shared/Packet/Packets/UnhandledPacket.cs b/Shared/Packet/Packets/UnhandledPacket.cs new file mode 100644 index 0000000..db33369 --- /dev/null +++ b/Shared/Packet/Packets/UnhandledPacket.cs @@ -0,0 +1,14 @@ +namespace Shared.Packet.Packets; + +[Packet(PacketType.Unknown)] // empty like boss +[Packet(PacketType.Command)] +public struct UnhandledPacket : IPacket { + public byte[] Data = new byte[Constants.PacketDataSize]; + public void Serialize(Span data) { + Data.CopyTo(data); + } + + public void Deserialize(Span data) { + data.CopyTo(Data); + } +} \ No newline at end of file