From b025d4874b171c675dc18889c3900c83194863e6 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 15 Mar 2023 17:13:33 -0300 Subject: TProtocol: Add `flex_packet`, and make use of it in `packet` This will be needed later on. --- include/pso/TProtocol.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'include/pso') diff --git a/include/pso/TProtocol.h b/include/pso/TProtocol.h index f8943e2..d19b37d 100644 --- a/include/pso/TProtocol.h +++ b/include/pso/TProtocol.h @@ -26,20 +26,26 @@ extern TPlyMeetUserExtension meet_user_settings; extern u32 game_variations[16][2]; extern void copy_packet(struct packet *pkt); -struct packet { - union { - struct { - packet_header header; - u8 data[0x7c00-sizeof(packet_header)]; - } pkt; - u8 bytes[0x7c00]; - }; - +// NOTE: Having this outside of `flex_packet` is required in some cases. +// This is because some of the senders allocate a different sized +// packet from what `TProtocol` uses, but also call `_packet::bswap()`. +struct _packet { void bswap() { - pkt.header.bswap(); + header.bswap(); }; + + packet_header header; + u8 data[]; }; +template +union flex_packet { + struct _packet pkt; + u8 bytes[(n) ? n : sizeof(packet_header)]; +}; + +struct packet : public flex_packet<0x7c00> {}; + #define RECV_PACKET_HANDLERS \ o(handle_unused_login, void) \ o(handle_03_recv_regist, u8 state) \ -- cgit v1.2.3-13-gbd6f