2022-03-13 11:14:01 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Shared.Packet.Packets;
|
|
|
|
|
|
|
|
|
|
[Packet(PacketType.Game)]
|
|
|
|
|
public struct GamePacket : IPacket {
|
2022-04-27 05:06:27 +00:00
|
|
|
|
private const int StageSize = 0x38;
|
|
|
|
|
public bool Is2d = false;
|
|
|
|
|
public byte ScenarioNum = 0;
|
2022-03-13 11:14:01 +00:00
|
|
|
|
public string Stage = "";
|
2022-03-13 21:27:53 +00:00
|
|
|
|
|
2022-04-27 05:06:27 +00:00
|
|
|
|
public GamePacket() { }
|
2022-03-13 21:27:53 +00:00
|
|
|
|
|
2022-04-27 20:17:02 +00:00
|
|
|
|
public short Size => 0x3C;
|
2022-03-13 11:14:01 +00:00
|
|
|
|
public void Serialize(Span<byte> data) {
|
2022-04-27 20:17:02 +00:00
|
|
|
|
MemoryMarshal.Write(data, ref Is2d);
|
2022-04-05 20:07:02 +00:00
|
|
|
|
MemoryMarshal.Write(data[1..], ref ScenarioNum);
|
2022-03-13 11:14:01 +00:00
|
|
|
|
Encoding.UTF8.GetBytes(Stage).CopyTo(data[2..(2 + StageSize)]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 04:29:34 +00:00
|
|
|
|
public void Deserialize(ReadOnlySpan<byte> data) {
|
2022-03-13 11:14:01 +00:00
|
|
|
|
Is2d = MemoryMarshal.Read<bool>(data);
|
|
|
|
|
ScenarioNum = MemoryMarshal.Read<byte>(data[1..]);
|
|
|
|
|
Stage = Encoding.UTF8.GetString(data[2..(2 + StageSize)]).TrimEnd('\0');
|
|
|
|
|
}
|
|
|
|
|
}
|