Introduce CustomEventHandler for more flexible invocation

This commit is contained in:
Sardelka9515
2023-02-15 11:38:02 +08:00
parent e4f432b593
commit e5f426690f
14 changed files with 182 additions and 73 deletions

View File

@ -19,21 +19,11 @@ namespace RageCoop.Core
public override PacketType Type => PacketType.CustomEvent;
public int Hash { get; set; }
public byte[] Payload;
public object[] Args;
protected override void Serialize(NetOutgoingMessage m)
{
m.Write((byte)Flags);
m.Write(Hash);
if (Args != null)
{
lock (SharedWriter)
{
SharedWriter.Reset();
CustomEvents.WriteObjects(SharedWriter, Args);
Payload = SharedWriter.ToByteArray(SharedWriter.Position);
}
}
m.Write(Payload);
}
@ -42,14 +32,6 @@ namespace RageCoop.Core
Flags = (CustomEventFlags)m.ReadByte();
Hash = m.ReadInt32();
Payload = m.ReadBytes(m.LengthBytes - m.PositionInBytes);
fixed (byte* p = Payload)
{
lock (SharedReader)
{
SharedReader.Initialise(p, Payload.Length);
Args = CustomEvents.ReadObjects(SharedReader);
}
}
}
}
}