summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-03-15 17:13:33 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2023-03-15 17:19:42 -0300
commitb025d4874b171c675dc18889c3900c83194863e6 (patch)
tree2a3e49d2ca29d8fe46e2713b5e5b8ca1ed3de265
parentd164c4385eeebed9f461a8314f45a227fb0dca20 (diff)
TProtocol: Add `flex_packet`, and make use of it in `packet`
This will be needed later on.
-rw-r--r--context.h28
-rw-r--r--include/pso/TProtocol.h26
-rw-r--r--src/pso/TProtocol.cpp2
3 files changed, 35 insertions, 21 deletions
diff --git a/context.h b/context.h
index 24f7b2d..d7d27e8 100644
--- a/context.h
+++ b/context.h
@@ -510,6 +510,17 @@ TMenuListEntry(QuestListEntry,
char short_description[112];
);
+// pso/TProtocol.h
+// NOTE: This is only here because of the ordering of this.
+// In Reality, the definition of `_packet` is above `flex_packet`.
+struct _packet;
+
+template<size_t n = 0>
+union flex_packet {
+ struct _packet pkt;
+ u8 bytes[(n) ? n : sizeof(packet_header)];
+};
+
// TMainTask.cpp
// Const defs.
static const int tl_object_count = 20;
@@ -775,20 +786,17 @@ struct extended_game_command {
};
// pso/TProtocol.h
-struct packet {
- union {
- struct {
- packet_header header;
- u8 data[0x7c00-sizeof(packet_header)];
- } pkt;
- u8 bytes[0x7c00];
- };
-
+struct _packet {
void bswap() {
- pkt.header.bswap();
+ header.bswap();
};
+
+ packet_header header;
+ u8 data[];
};
+struct packet : public flex_packet<0x7c00> {};
+
struct recv_packet_handlers {
#define o(name, ...) recv_packet_handler(name) name;
RECV_PACKET_HANDLERS;
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<size_t n = 0>
+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) \
diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp
index 408214b..e9b3226 100644
--- a/src/pso/TProtocol.cpp
+++ b/src/pso/TProtocol.cpp
@@ -150,7 +150,7 @@ void TProtocol::recv_generate_id(packet &pkt) {
void TProtocol::recv_pso_data_long(packet &pkt) {
TRecvPsoData &tmp = as(TRecvPsoData &, pkt);
- pkt.bswap();
+ pkt.pkt.bswap();
tmp.data.recv_pso_data_buf(tmp.header.size - 4);
};