Introduce CustomEventHandler for more flexible invocation
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user