Packets use source generation to automatically implement Write and Read methods for supported types.
Excluding Properties
Use the [NetExclude] attribute to prevent specific properties from being serialized into the packet.
Manual Serialization
If you need conditional logic (e.g., only sending data if a boolean is true) or if you are using unsupported types, manually override the Write(PacketWriter writer) and Read(PacketReader reader) methods. When you manually override these, the source generator will not produce them for you.
Supported Types
| Type | Supported |
|---|
Primitives (int, bool, ulong, etc.) | ✅ |
Vectors & byte arrays (Vector2, Vector3, byte[]) | ✅ |
Generics (List<T>, Dictionary<K, V>) | ✅ |
Arrays (int[], bool[]) | ✅ |
| Classes & Structs | ✅ |
public partial class SPacketPlayerJoinLeave : ServerPacket
{
public uint Id { get; set; }
public string Username { get; set; }
public Vector2 Position { get; set; }
public bool Joined { get; set; }
public override void Write(PacketWriter writer)
{
writer.Write((uint)Id);
writer.Write((bool)Joined);
if (Joined)
{
writer.Write((string)Username);
writer.Write((Vector2)Position);
}
}
public override void Read(PacketReader reader)
{
Id = reader.ReadUInt();
Joined = reader.ReadBool();
if (Joined)
{
Username = reader.ReadString();
Position = reader.ReadVector2();
}
}
}