From 233f92cfeab355feebc4c0d6fc3e42c44bd54769 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 11 May 2023 15:37:34 -0300 Subject: TProtocol: Add, and match `send_chara_data_v2()` Sorry for the long wait, was busy doing other things. --- context.h | 207 ++++++++++++++++++++++++++++++++--------- include/pso/TPlyCharData.h | 19 +++- include/pso/TPlyDispData.h | 96 ++++++++++++------- include/pso/TPlyGuildCardTag.h | 11 +++ include/pso/TPlyInventory.h | 40 ++++++-- include/pso/TProtocol.h | 2 + include/pso/packet_classes.h | 38 ++++++++ src/pso/TProtocol.cpp | 29 ++++++ 8 files changed, 355 insertions(+), 87 deletions(-) diff --git a/context.h b/context.h index 0030535..cfc430d 100644 --- a/context.h +++ b/context.h @@ -251,6 +251,13 @@ public: \ } #endif +// pso/TPlyDispData.h +#define bswap16(var) bswap_16(as(u16 *, var)) +#define bswap32(var) bswap_32(as(u32 *, var)) + +#define bswap16_ref(var) bswap16(&var) +#define bswap32_ref(var) bswap32(&var) + // pso/forward.h // Class forward. class TTcpSocket; @@ -527,6 +534,42 @@ TMenuListEntry(QuestListEntry, char short_description[112]; ); +class TBlockedSenders { +public: + packet_header header; + u32 blocked_senders[30]; +public: + void bswap() { + header.bswap(); + for (int i = 0; i < 30; ++i) { + bswap_32(&blocked_senders[i]); + } + }; +}; + +class TPlyJoinData { +public: + packet_header header; + TPlyCharData char_data; + TPlyChallenge challenge; + TPlyChoiceSearchConfig choice_search_config; + char info_board[172]; + u32 blocked_senders[30]; + u32 auto_reply_enabled; + char auto_reply[512]; +public: + void bswap() { + header.bswap(); + char_data.bswap(); + challenge.bswap(); + choice_search_config.bswap(); + for (int i = 0; i < 30; ++i) { + bswap_32(&blocked_senders[i]); + } + bswap_32(&auto_reply_enabled); + }; +}; + template class TSendAction { public: @@ -686,7 +729,6 @@ struct vec2f { // pso/TPlyDispData.h struct stats { void bswap(); - stats &assign(const stats &src); short atp; short mst; @@ -698,8 +740,21 @@ struct stats { }; struct player_stats { - void bswap(); - player_stats &assign(const player_stats &src); + void bswap() { + bswap16(&stats.atp); + bswap16(&stats.mst); + bswap16(&stats.evp); + bswap16(&stats.hp); + bswap16(&stats.dfp); + bswap16(&stats.ata); + bswap16(&stats.lck); + bswap16(&mbr_0xe); + bswap32(&proportions); + bswap32(&mbr_0x14); + bswap32(&level); + bswap32(&exp); + bswap32(&meseta); + }; struct stats stats; short mbr_0xe; @@ -711,8 +766,21 @@ struct player_stats { }; struct disp_data_part2 { - void bswap(); - disp_data_part2 &assign(const disp_data_part2 &src); + void bswap() { + bswap_32(&name_colour); + bswap_32(&name_colour_checksum); + bswap_32(&v1_flags); + for (int i = 0; i < 8; ++i) { + bswap_16(&appearance_data[i]); + } + + bswap32(&proportions.x); + bswap32(&proportions.y); + }; + bool is_valid() { + // TODO: Actually decompile it. + return false; + }; char name[16]; u32 smth[2]; @@ -725,19 +793,36 @@ struct disp_data_part2 { u8 v2_flags; u8 version; u32 v1_flags; - u16 costume; - u16 skin; - u16 face; - u16 head; - u16 hair; - u16 hair_r; - u16 hair_g; - u16 hair_b; + union { + struct { + u16 costume; + u16 skin; + u16 face; + u16 head; + u16 hair; + u16 hair_r; + u16 hair_g; + u16 hair_b; + } appearance; + u16 appearance_data[8]; + }; vec2f proportions; }; // pso/TPlyGuildCardTag.h struct gc_tag { + gc_tag() { init(); }; + ~gc_tag() {}; + void init() { + tag0 = 0; + tag1 = 0; + tag2 = 0; + }; + void bswap() { + bswap_16(&tag2); + }; + + u8 tag0; u8 tag1; u16 tag2; @@ -745,12 +830,28 @@ struct gc_tag { // pso/TPlyInventory.h struct TItemData { - void init(); - void bswap(); - TItemData &assign(const TItemData &src); + void init() { + data1.data_u8[0] = 0; + data1.data_u8[1] = 0; + data1.data_u8[2] = 0; + data1.data_u8[3] = 0; + data1.data_u8[4] = 0; + data1.data_u8[5] = 0; + data2.data_u32 = 0; + for (int i = 0; i < 3; ++i) { + data1.data_u8_pair[3+i][0] = 0; + data1.data_u8_pair[3+i][1] = 0; + } + id = -1; + }; + void bswap() { + bswap_32(&data2.data_u32); + bswap_32(&id); + }; union { u8 data_u8[12]; + u8 data_u8_pair[6][2]; u16 data_u16[6]; u32 data_u32[3]; } data1; @@ -898,9 +999,22 @@ enum object_flags { // Class defs. class TPlyCharData { public: - TPlyCharData() {}; - void bswap() {}; - TPlyCharData &assign(const TPlyCharData &src); + TPlyCharData() { + for (int i = 0; i < 30; ++i) { + m_inventory.m_items[i].init(); + } + }; + + ~TPlyCharData() {}; + void bswap() { + for (int i = 0; i < 30; ++i) { + m_inventory.m_items[i].bswap(); + } + m_disp_data.m_disp_part2.bswap(); + m_disp_data.m_stats.bswap(); + m_disp_data.m_config.bswap(); + }; + void some_stub() {}; public: TPlyInventory m_inventory; TPlyDispData m_disp_data; @@ -919,33 +1033,29 @@ public: } config; }; -// pso/TPlyDispData.h -class TPlyDispConfigSmthTag { -public: - //TPlyDispConfigSmthTag(); - //~TPlyDispConfigSmthTag(); - - void bswap(); - TPlyDispConfigSmthTag &assign(const TPlyDispConfigSmthTag &src); -public: - gc_tag m_tag; -}; - class TPlyDispConfigSmth { public: - void bswap(); - TPlyDispConfigSmth &assign(const TPlyDispConfigSmth &src); + TPlyDispConfigSmth() { m_mbr_0x0 = 0; }; + void bswap() { + bswap_32(&m_mbr_0x0); + for (int i = 0; i < 4; ++i) { + m_tags[i].bswap(); + m_tags1[i].bswap(); + } + }; public: u32 m_mbr_0x0; - TPlyDispConfigSmthTag m_tags[4]; - TPlyDispConfigSmthTag m_tags1[4]; + gc_tag m_tags[4]; + gc_tag m_tags1[4]; }; class TPlyDispConfig { public: - void bswap(); - TPlyDispConfig &assign(const TPlyDispConfig &src); -private: + void bswap() { + m_smth.bswap(); + m_smth1.bswap(); + }; +public: TPlyDispConfigSmth m_smth; TPlyDispConfigSmth m_smth1; }; @@ -953,7 +1063,6 @@ private: class TPlyDispData { public: void bswap(); - TPlyDispData &assign(const TPlyDispData &src); public: player_stats m_stats; disp_data_part2 m_disp_part2; @@ -992,11 +1101,20 @@ public: // pso/TPlyInventory.h class TPlyInventoryItem { public: - void init(); - void bswap(); - TPlyInventoryItem &assign(const TPlyInventoryItem &src); + void init() { + m_present[0] = 0; + m_present[1] = -1; + m_flags = 0; + m_present[3] = 0; + m_present[2] = 0; + m_data.init(); + }; + void bswap() { + bswap_32(&m_flags); + m_data.bswap(); + }; public: - u8 m_present[4]; + char m_present[4]; u32 m_flags; TItemData m_data; }; @@ -1004,7 +1122,6 @@ public: class TPlyInventory { public: void bswap(); - TPlyInventory &assign(const TPlyInventory &src); public: u8 m_num_items; u8 m_hp_materials_used; @@ -1714,4 +1831,6 @@ public: void send_game_list(); // 0x1F void send_text_list(); + // 0x61 + void send_chara_data_v2(TPlyCharData &char_data, TPlyChallenge &challenge, TPlyChoiceSearchConfig &choice_search_config, TBlockedSenders &blocked_senders, TPlyText<512> &auto_reply, char *info_board); }; diff --git a/include/pso/TPlyCharData.h b/include/pso/TPlyCharData.h index 0b0c421..652e74a 100644 --- a/include/pso/TPlyCharData.h +++ b/include/pso/TPlyCharData.h @@ -9,9 +9,22 @@ class TPlyCharData { public: - TPlyCharData() {}; - void bswap() {}; - TPlyCharData &assign(const TPlyCharData &src); + TPlyCharData() { + for (int i = 0; i < 30; ++i) { + m_inventory.m_items[i].init(); + } + }; + + ~TPlyCharData() {}; + void bswap() { + for (int i = 0; i < 30; ++i) { + m_inventory.m_items[i].bswap(); + } + m_disp_data.m_disp_part2.bswap(); + m_disp_data.m_stats.bswap(); + m_disp_data.m_config.bswap(); + }; + void some_stub() {}; public: TPlyInventory m_inventory; TPlyDispData m_disp_data; diff --git a/include/pso/TPlyDispData.h b/include/pso/TPlyDispData.h index 679e329..daca8d9 100644 --- a/include/pso/TPlyDispData.h +++ b/include/pso/TPlyDispData.h @@ -7,9 +7,14 @@ #include #include +#define bswap16(var) bswap_16(as(u16 *, var)) +#define bswap32(var) bswap_32(as(u32 *, var)) + +#define bswap16_ref(var) bswap16(&var) +#define bswap32_ref(var) bswap32(&var) + struct stats { void bswap(); - stats &assign(const stats &src); short atp; short mst; @@ -21,8 +26,21 @@ struct stats { }; struct player_stats { - void bswap(); - player_stats &assign(const player_stats &src); + void bswap() { + bswap16(&stats.atp); + bswap16(&stats.mst); + bswap16(&stats.evp); + bswap16(&stats.hp); + bswap16(&stats.dfp); + bswap16(&stats.ata); + bswap16(&stats.lck); + bswap16(&mbr_0xe); + bswap32(&proportions); + bswap32(&mbr_0x14); + bswap32(&level); + bswap32(&exp); + bswap32(&meseta); + }; struct stats stats; short mbr_0xe; @@ -34,8 +52,21 @@ struct player_stats { }; struct disp_data_part2 { - void bswap(); - disp_data_part2 &assign(const disp_data_part2 &src); + void bswap() { + bswap_32(&name_colour); + bswap_32(&name_colour_checksum); + bswap_32(&v1_flags); + for (int i = 0; i < 8; ++i) { + bswap_16(&appearance_data[i]); + } + + bswap32(&proportions.x); + bswap32(&proportions.y); + }; + bool is_valid() { + // TODO: Actually decompile it. + return false; + }; char name[16]; u32 smth[2]; @@ -48,43 +79,45 @@ struct disp_data_part2 { u8 v2_flags; u8 version; u32 v1_flags; - u16 costume; - u16 skin; - u16 face; - u16 head; - u16 hair; - u16 hair_r; - u16 hair_g; - u16 hair_b; + union { + struct { + u16 costume; + u16 skin; + u16 face; + u16 head; + u16 hair; + u16 hair_r; + u16 hair_g; + u16 hair_b; + } appearance; + u16 appearance_data[8]; + }; vec2f proportions; }; -class TPlyDispConfigSmthTag { -public: - //TPlyDispConfigSmthTag(); - //~TPlyDispConfigSmthTag(); - - void bswap(); - TPlyDispConfigSmthTag &assign(const TPlyDispConfigSmthTag &src); -public: - gc_tag m_tag; -}; - class TPlyDispConfigSmth { public: - void bswap(); - TPlyDispConfigSmth &assign(const TPlyDispConfigSmth &src); + TPlyDispConfigSmth() { m_mbr_0x0 = 0; }; + void bswap() { + bswap_32(&m_mbr_0x0); + for (int i = 0; i < 4; ++i) { + m_tags[i].bswap(); + m_tags1[i].bswap(); + } + }; public: u32 m_mbr_0x0; - TPlyDispConfigSmthTag m_tags[4]; - TPlyDispConfigSmthTag m_tags1[4]; + gc_tag m_tags[4]; + gc_tag m_tags1[4]; }; class TPlyDispConfig { public: - void bswap(); - TPlyDispConfig &assign(const TPlyDispConfig &src); -private: + void bswap() { + m_smth.bswap(); + m_smth1.bswap(); + }; +public: TPlyDispConfigSmth m_smth; TPlyDispConfigSmth m_smth1; }; @@ -92,7 +125,6 @@ private: class TPlyDispData { public: void bswap(); - TPlyDispData &assign(const TPlyDispData &src); public: player_stats m_stats; disp_data_part2 m_disp_part2; diff --git a/include/pso/TPlyGuildCardTag.h b/include/pso/TPlyGuildCardTag.h index 7bcdb71..f17b566 100644 --- a/include/pso/TPlyGuildCardTag.h +++ b/include/pso/TPlyGuildCardTag.h @@ -6,6 +6,17 @@ #include struct gc_tag { + gc_tag() { init(); }; + ~gc_tag() {}; + void init() { + tag0 = 0; + tag1 = 0; + tag2 = 0; + }; + void bswap() { + bswap_16(&tag2); + }; + u8 tag0; u8 tag1; u16 tag2; diff --git a/include/pso/TPlyInventory.h b/include/pso/TPlyInventory.h index 3256717..eb9564b 100644 --- a/include/pso/TPlyInventory.h +++ b/include/pso/TPlyInventory.h @@ -6,12 +6,28 @@ #include struct TItemData { - void init(); - void bswap(); - TItemData &assign(const TItemData &src); + void init() { + data1.data_u8[0] = 0; + data1.data_u8[1] = 0; + data1.data_u8[2] = 0; + data1.data_u8[3] = 0; + data1.data_u8[4] = 0; + data1.data_u8[5] = 0; + data2.data_u32 = 0; + for (int i = 0; i < 3; ++i) { + data1.data_u8_pair[3+i][0] = 0; + data1.data_u8_pair[3+i][1] = 0; + } + id = -1; + }; + void bswap() { + bswap_32(&data2.data_u32); + bswap_32(&id); + }; union { u8 data_u8[12]; + u8 data_u8_pair[6][2]; u16 data_u16[6]; u32 data_u32[3]; } data1; @@ -25,11 +41,20 @@ struct TItemData { class TPlyInventoryItem { public: - void init(); - void bswap(); - TPlyInventoryItem &assign(const TPlyInventoryItem &src); + void init() { + m_present[0] = 0; + m_present[1] = -1; + m_flags = 0; + m_present[3] = 0; + m_present[2] = 0; + m_data.init(); + }; + void bswap() { + bswap_32(&m_flags); + m_data.bswap(); + }; public: - u8 m_present[4]; + char m_present[4]; u32 m_flags; TItemData m_data; }; @@ -37,7 +62,6 @@ public: class TPlyInventory { public: void bswap(); - TPlyInventory &assign(const TPlyInventory &src); public: u8 m_num_items; u8 m_hp_materials_used; diff --git a/include/pso/TProtocol.h b/include/pso/TProtocol.h index b970998..98976b7 100644 --- a/include/pso/TProtocol.h +++ b/include/pso/TProtocol.h @@ -264,6 +264,8 @@ public: void send_game_list(); // 0x1F void send_text_list(); + // 0x61 + void send_chara_data_v2(TPlyCharData &char_data, TPlyChallenge &challenge, TPlyChoiceSearchConfig &choice_search_config, TBlockedSenders &blocked_senders, TPlyText<512> &auto_reply, char *info_board); }; #endif diff --git a/include/pso/packet_classes.h b/include/pso/packet_classes.h index 268ac40..e0a78bd 100644 --- a/include/pso/packet_classes.h +++ b/include/pso/packet_classes.h @@ -7,8 +7,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -83,6 +85,42 @@ union game_command_union { u8 bytes[1024]; }; +class TBlockedSenders { +public: + packet_header header; + u32 blocked_senders[30]; +public: + void bswap() { + header.bswap(); + for (int i = 0; i < 30; ++i) { + bswap_32(&blocked_senders[i]); + } + }; +}; + +class TPlyJoinData { +public: + packet_header header; + TPlyCharData char_data; + TPlyChallenge challenge; + TPlyChoiceSearchConfig choice_search_config; + char info_board[172]; + u32 blocked_senders[30]; + u32 auto_reply_enabled; + char auto_reply[512]; +public: + void bswap() { + header.bswap(); + char_data.bswap(); + challenge.bswap(); + choice_search_config.bswap(); + for (int i = 0; i < 30; ++i) { + bswap_32(&blocked_senders[i]); + } + bswap_32(&auto_reply_enabled); + }; +}; + template class TSendAction { public: diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp index 1a992e3..3b7cbd3 100644 --- a/src/pso/TProtocol.cpp +++ b/src/pso/TProtocol.cpp @@ -24,6 +24,35 @@ void copy_packet(struct packet *pkt) { } +void TProtocol::send_chara_data_v2(TPlyCharData &char_data, TPlyChallenge &challenge, TPlyChoiceSearchConfig &choice_search_config, TBlockedSenders &blocked_senders, TPlyText<512> &auto_reply, char *info_board) { + if (m_connected) { + char_data.m_disp_data.m_disp_part2.is_valid(); + m_character_data = char_data; + TPlyJoinData tmp; + memset(&tmp, 0, sizeof(tmp)); + + + tmp.header.command = 0x61; + tmp.header.flags = 3; + tmp.header.size = sizeof(tmp); + tmp.char_data = m_character_data; + tmp.challenge = challenge; + tmp.choice_search_config = choice_search_config; + strncpy(tmp.info_board, info_board, sizeof(tmp.info_board)); + for (int i = 0; i < blocked_senders.header.flags; ++i) { + tmp.blocked_senders[i] = blocked_senders.blocked_senders[i]; + } + tmp.auto_reply_enabled = auto_reply.header.flags; + strncpy(tmp.auto_reply, auto_reply.text, sizeof(tmp.auto_reply)-1); + const int packet_size = strlen(tmp.auto_reply) + offsetof(TPlyJoinData, auto_reply) + sizeof(packet_header); + + tmp.header.size = packet_size & ~3; + tmp.char_data.some_stub(); + tmp.bswap(); + send(as(u8 *, &tmp), packet_size & ~3); + } +} + void TProtocol::send_text_list() { if (m_connected) { packet_header tmp; -- cgit v1.2.3-13-gbd6f