From 02e8f8ea8b6b421cfc152f22edef12e7dd9139d7 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 14 Jan 2024 09:29:09 -0800 Subject: [PATCH] disassemble quests during Save Files --- src/ProxyCommands.cc | 14 +++++++++++++- src/ProxyServer.cc | 8 -------- src/ProxyServer.hh | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ProxyCommands.cc b/src/ProxyCommands.cc index 73c78947..f0a1aa0a 100644 --- a/src/ProxyCommands.cc +++ b/src/ProxyCommands.cc @@ -1240,7 +1240,19 @@ static HandlerResult S_13_A7(shared_ptr ses, uint16_ if (sf->remaining_bytes == 0) { if (ses->config.check_flag(Client::Flag::PROXY_SAVE_FILES)) { ses->log.info("Writing file %s => %s", sf->basename.c_str(), sf->output_filename.c_str()); - sf->write(); + string data = join(sf->blocks); + if (sf->is_download && (ends_with(sf->basename, ".bin") || ends_with(sf->basename, ".dat") || ends_with(sf->basename, ".pvr"))) { + data = decode_dlq_data(data); + } + save_file(sf->output_filename, data); + if (ends_with(sf->basename, ".bin")) { + try { + auto disassembly = disassemble_quest_script(data.data(), data.size(), ses->version(), ses->language(), false); + save_file(sf->output_filename + ".txt", disassembly); + } catch (const exception& e) { + ses->log.warning("Failed to disassemble quest file: %s", e.what()); + } + } } else { ses->log.info("Download complete for file %s", sf->basename.c_str()); } diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index b9599102..3667016e 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -675,14 +675,6 @@ ProxyServer::LinkedSession::SavingFile::SavingFile( is_download(is_download), remaining_bytes(remaining_bytes) {} -void ProxyServer::LinkedSession::SavingFile::write() const { - string data = join(this->blocks); - if (is_download && (ends_with(this->basename, ".bin") || ends_with(this->basename, ".dat"))) { - data = decode_dlq_data(data); - } - save_file(this->output_filename, data); -} - void ProxyServer::LinkedSession::dispatch_on_timeout( evutil_socket_t, short, void* ctx) { reinterpret_cast(ctx)->on_timeout(); diff --git a/src/ProxyServer.hh b/src/ProxyServer.hh index 8ad98496..b30cba38 100644 --- a/src/ProxyServer.hh +++ b/src/ProxyServer.hh @@ -108,8 +108,6 @@ public: const std::string& output_filename, size_t remaining_bytes, bool is_download); - - void write() const; }; std::unordered_map saving_files;