Skip to content

Commit

Permalink
use client's language when generating download quests
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Nov 2, 2023
1 parent 983c6e1 commit 482bc5f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
14 changes: 10 additions & 4 deletions src/Quest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ string encode_download_quest_data(const string& compressed_data, size_t decompre
return data;
}

shared_ptr<VersionedQuest> VersionedQuest::create_download_quest() const {
shared_ptr<VersionedQuest> VersionedQuest::create_download_quest(uint8_t override_language) const {
// The download flag needs to be set in the bin header, or else the client
// will ignore it when scanning for download quests in an offline game. To set
// this flag, we need to decompress the quest's .bin file, set the flag, then
Expand All @@ -795,21 +795,27 @@ shared_ptr<VersionedQuest> VersionedQuest::create_download_quest() const {
if (decompressed_bin.size() < sizeof(PSOQuestHeaderDC)) {
throw runtime_error("bin file is too small for header");
}
reinterpret_cast<PSOQuestHeaderDC*>(data_ptr)->is_download = 0x01;
if (override_language != 0xFF) {
reinterpret_cast<PSOQuestHeaderDC*>(data_ptr)->language = override_language;
}
break;
case QuestScriptVersion::PC_V2:
if (decompressed_bin.size() < sizeof(PSOQuestHeaderPC)) {
throw runtime_error("bin file is too small for header");
}
reinterpret_cast<PSOQuestHeaderPC*>(data_ptr)->is_download = 0x01;
if (override_language != 0xFF) {
reinterpret_cast<PSOQuestHeaderPC*>(data_ptr)->language = override_language;
}
break;
case QuestScriptVersion::GC_NTE:
case QuestScriptVersion::GC_V3:
case QuestScriptVersion::XB_V3:
if (decompressed_bin.size() < sizeof(PSOQuestHeaderGC)) {
throw runtime_error("bin file is too small for header");
}
reinterpret_cast<PSOQuestHeaderGC*>(data_ptr)->is_download = 0x01;
if (override_language != 0xFF) {
reinterpret_cast<PSOQuestHeaderGC*>(data_ptr)->language = override_language;
}
break;
case QuestScriptVersion::BB_V4:
throw invalid_argument("PSOBB does not support download quests");
Expand Down
2 changes: 1 addition & 1 deletion src/Quest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct VersionedQuest {
std::string bin_filename() const;
std::string dat_filename() const;

std::shared_ptr<VersionedQuest> create_download_quest() const;
std::shared_ptr<VersionedQuest> create_download_quest(uint8_t override_language = 0xFF) const;
std::string encode_qst() const;
};

Expand Down
12 changes: 3 additions & 9 deletions src/QuestScript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,7 @@ std::string disassemble_quest_script(const void* data, size_t size, QuestScriptV
code_offset = header.code_offset;
function_table_offset = header.function_table_offset;
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
if (header.is_download) {
lines.emplace_back(string_printf(".is_download_quest"));
}
lines.emplace_back(string_printf(".language %hhu", header.language));
lines.emplace_back(".name " + JSON(header.name.decode(language)).serialize());
lines.emplace_back(".short_desc " + JSON(header.short_description.decode(language)).serialize());
lines.emplace_back(".long_desc " + JSON(header.long_description.decode(language)).serialize());
Expand All @@ -850,9 +848,7 @@ std::string disassemble_quest_script(const void* data, size_t size, QuestScriptV
code_offset = header.code_offset;
function_table_offset = header.function_table_offset;
lines.emplace_back(string_printf(".quest_num %hu", header.quest_number.load()));
if (header.is_download) {
lines.emplace_back(string_printf(".is_download_quest"));
}
lines.emplace_back(string_printf(".language %hhu", header.language));
lines.emplace_back(".name " + JSON(header.name.decode(language)).serialize());
lines.emplace_back(".short_desc " + JSON(header.short_description.decode(language)).serialize());
lines.emplace_back(".long_desc " + JSON(header.long_description.decode(language)).serialize());
Expand All @@ -866,9 +862,7 @@ std::string disassemble_quest_script(const void* data, size_t size, QuestScriptV
code_offset = header.code_offset;
function_table_offset = header.function_table_offset;
lines.emplace_back(string_printf(".quest_num %hhu", header.quest_number));
if (header.is_download) {
lines.emplace_back(string_printf(".is_download_quest"));
}
lines.emplace_back(string_printf(".language %hhu", header.language));
lines.emplace_back(string_printf(".episode %hhu", header.episode));
lines.emplace_back(".name " + JSON(header.name.decode(language)).serialize());
lines.emplace_back(".short_desc " + JSON(header.short_description.decode(language)).serialize());
Expand Down
6 changes: 3 additions & 3 deletions src/QuestScript.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PSOQuestHeaderDC { // Same format for DC v1 and v2
/* 0004 */ le_uint32_t function_table_offset;
/* 0008 */ le_uint32_t size;
/* 000C */ le_uint32_t unused;
/* 0010 */ uint8_t is_download;
/* 0010 */ uint8_t language;
/* 0011 */ uint8_t unknown1;
/* 0012 */ le_uint16_t quest_number; // 0xFFFF for challenge quests
/* 0014 */ pstring<TextEncoding::MARKED, 0x20> name;
Expand All @@ -43,7 +43,7 @@ struct PSOQuestHeaderPC {
/* 0004 */ le_uint32_t function_table_offset;
/* 0008 */ le_uint32_t size;
/* 000C */ le_uint32_t unused;
/* 0010 */ uint8_t is_download;
/* 0010 */ uint8_t language;
/* 0011 */ uint8_t unknown1;
/* 0012 */ le_uint16_t quest_number; // 0xFFFF for challenge quests
/* 0014 */ pstring<TextEncoding::UTF16, 0x20> name;
Expand All @@ -59,7 +59,7 @@ struct PSOQuestHeaderGC {
/* 0004 */ le_uint32_t function_table_offset;
/* 0008 */ le_uint32_t size;
/* 000C */ le_uint32_t unused;
/* 0010 */ uint8_t is_download;
/* 0010 */ uint8_t language;
/* 0011 */ uint8_t unknown1;
/* 0012 */ uint8_t quest_number;
/* 0013 */ uint8_t episode; // 1 = Ep2. Apparently some quests have 0xFF here, which means ep1 (?)
Expand Down
2 changes: 1 addition & 1 deletion src/ReceiveCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ static void on_10(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
if (vq->version == QuestScriptVersion::GC_EP3) {
send_open_quest_file(c, q->name, vq->bin_filename(), vq->bin_contents, QuestFileType::EPISODE_3);
} else {
vq = vq->create_download_quest();
vq = vq->create_download_quest(c->language());
send_open_quest_file(c, q->name, vq->bin_filename(), vq->bin_contents, QuestFileType::DOWNLOAD);
send_open_quest_file(c, q->name, vq->dat_filename(), vq->dat_contents, QuestFileType::DOWNLOAD);
}
Expand Down

0 comments on commit 482bc5f

Please sign in to comment.