From f563d5d873008adfe9260e38a97f9703ebdb7789 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Mon, 17 Jul 2023 09:05:39 -0700 Subject: [PATCH] split XB quest file header struct --- src/CommandFormats.hh | 4 ++-- src/ProxyCommands.cc | 7 ++++--- src/Quest.cc | 28 ++++++++++++++++++---------- src/SendCommands.cc | 7 +++++-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index 500fef08..999577d1 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -1015,7 +1015,7 @@ struct S_OpenFile_DC_44_A6 { le_uint32_t file_size = 0; } __packed__; -struct S_OpenFile_PC_V3_44_A6 { +struct S_OpenFile_PC_GC_44_A6 { ptext name; // Should begin with "PSO/" le_uint16_t type = 0; ptext filename; @@ -1025,7 +1025,7 @@ struct S_OpenFile_PC_V3_44_A6 { // Curiously, PSO XB expects an extra 0x18 bytes at the end of this command, but // those extra bytes are unused, and the client does not fail if they're // omitted. -struct S_OpenFile_XB_44_A6 : S_OpenFile_PC_V3_44_A6 { +struct S_OpenFile_XB_44_A6 : S_OpenFile_PC_GC_44_A6 { parray unused2; } __packed__; diff --git a/src/ProxyCommands.cc b/src/ProxyCommands.cc index 8bc2420d..aa2dcaca 100644 --- a/src/ProxyCommands.cc +++ b/src/ProxyCommands.cc @@ -1155,7 +1155,8 @@ static HandlerResult S_44_A6(shared_ptr, } constexpr on_command_t S_D_44_A6 = &S_44_A6; -constexpr on_command_t S_PGX_44_A6 = &S_44_A6; +constexpr on_command_t S_PG_44_A6 = &S_44_A6; +constexpr on_command_t S_X_44_A6 = &S_44_A6; constexpr on_command_t S_B_44_A6 = &S_44_A6; static HandlerResult S_13_A7(shared_ptr, @@ -1811,7 +1812,7 @@ static on_command_t handlers[0x100][6][2] = { /* 41 */ {{S_invalid, nullptr}, {S_DGX_41, nullptr}, {S_P_41, nullptr}, {S_DGX_41, nullptr}, {S_DGX_41, nullptr}, {S_B_41, nullptr}}, /* 42 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, /* 43 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, -/* 44 */ {{S_invalid, nullptr}, {S_D_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_B_44_A6, nullptr}}, +/* 44 */ {{S_invalid, nullptr}, {S_D_44_A6, nullptr}, {S_PG_44_A6, nullptr}, {S_PG_44_A6, nullptr}, {S_X_44_A6, nullptr}, {S_B_44_A6, nullptr}}, /* 45 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, /* 46 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, /* 47 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, @@ -1912,7 +1913,7 @@ static on_command_t handlers[0x100][6][2] = { /* A3 */ {{S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}}, /* A4 */ {{S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}}, /* A5 */ {{S_invalid, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}}, -/* A6 */ {{S_invalid, nullptr}, {S_D_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_PGX_44_A6, nullptr}, {S_B_44_A6, nullptr}}, +/* A6 */ {{S_invalid, nullptr}, {S_D_44_A6, nullptr}, {S_PG_44_A6, nullptr}, {S_PG_44_A6, nullptr}, {S_X_44_A6, nullptr}, {S_B_44_A6, nullptr}}, /* A7 */ {{S_invalid, nullptr}, {S_13_A7, nullptr}, {S_13_A7, nullptr}, {S_13_A7, nullptr}, {S_13_A7, nullptr}, {S_13_A7, nullptr}}, /* A8 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, /* A9 */ {{S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}, {S_invalid, nullptr}}, diff --git a/src/Quest.cc b/src/Quest.cc index 19b4c1db..807dd5dc 100644 --- a/src/Quest.cc +++ b/src/Quest.cc @@ -779,9 +779,11 @@ pair Quest::decode_qst_file(const string& filename) { if (signature == 0x58004400 || signature == 0x5800A600) { return decode_qst_t(f.get()); } else if ((signature & 0xFFFFFF00) == 0x3C004400 || (signature & 0xFFFFFF00) == 0x3C00A600) { - return decode_qst_t(f.get()); + return decode_qst_t(f.get()); } else if ((signature & 0xFF00FFFF) == 0x44003C00 || (signature & 0xFF00FFFF) == 0xA6003C00) { - return decode_qst_t(f.get()); + return decode_qst_t(f.get()); + } else if ((signature & 0xFF00FFFF) == 0x44005400 || (signature & 0xFF00FFFF) == 0xA6005400) { + return decode_qst_t(f.get()); } else { throw runtime_error("invalid qst file format"); } @@ -800,8 +802,7 @@ void add_command_header( template void add_open_file_command(StringWriter& w, const Quest& q, bool is_bin) { add_command_header( - w, q.is_dlq_encoded ? 0xA6 : 0x44, q.internal_id, - sizeof(S_OpenFile_DC_44_A6)); + w, q.is_dlq_encoded ? 0xA6 : 0x44, q.internal_id, sizeof(CmdT)); CmdT cmd; cmd.name = "PSO/" + encode_sjis(q.name); cmd.filename = q.file_basename + (is_bin ? ".bin" : ".dat"); @@ -850,8 +851,8 @@ string Quest::export_qst() const { w, this->file_basename + ".dat", *this->dat_contents(), this->is_dlq_encoded); break; case QuestScriptVersion::PC_V2: - add_open_file_command(w, *this, true); - add_open_file_command(w, *this, false); + add_open_file_command(w, *this, true); + add_open_file_command(w, *this, false); add_write_file_commands( w, this->file_basename + ".bin", *this->bin_contents(), this->is_dlq_encoded); add_write_file_commands( @@ -859,19 +860,26 @@ string Quest::export_qst() const { break; case QuestScriptVersion::GC_NTE: case QuestScriptVersion::GC_V3: - case QuestScriptVersion::XB_V3: - add_open_file_command(w, *this, true); - add_open_file_command(w, *this, false); + add_open_file_command(w, *this, true); + add_open_file_command(w, *this, false); add_write_file_commands( w, this->file_basename + ".bin", *this->bin_contents(), this->is_dlq_encoded); add_write_file_commands( w, this->file_basename + ".dat", *this->dat_contents(), this->is_dlq_encoded); break; case QuestScriptVersion::GC_EP3: - add_open_file_command(w, *this, true); + add_open_file_command(w, *this, true); add_write_file_commands( w, this->file_basename + ".bin", *this->bin_contents(), this->is_dlq_encoded); break; + case QuestScriptVersion::XB_V3: + add_open_file_command(w, *this, true); + add_open_file_command(w, *this, false); + add_write_file_commands( + w, this->file_basename + ".bin", *this->bin_contents(), this->is_dlq_encoded); + add_write_file_commands( + w, this->file_basename + ".dat", *this->dat_contents(), this->is_dlq_encoded); + break; case QuestScriptVersion::BB_V4: add_open_file_command(w, *this, true); add_open_file_command(w, *this, false); diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 375b97e4..752a01f1 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -303,7 +303,7 @@ void send_quest_buffer_overflow( } static const string filename = "m999999p_e.bin"; - send_quest_open_file_t( + send_quest_open_file_t( c, "BufferOverflow", filename, 0x18, QuestFileType::EPISODE_3); S_WriteFile_13_A7 cmd; @@ -2698,8 +2698,11 @@ void send_open_quest_file(shared_ptr c, const string& quest_name, break; case GameVersion::PC: case GameVersion::GC: + send_quest_open_file_t( + c, quest_name, basename, contents->size(), type); + break; case GameVersion::XB: - send_quest_open_file_t( + send_quest_open_file_t( c, quest_name, basename, contents->size(), type); break; case GameVersion::BB: