From 98dc2af27861b8ec689d6196a4a492c50d178c5f Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 26 Sep 2023 10:46:46 -0700 Subject: [PATCH] support decompressed card text archives --- README.md | 1 + src/Episode3/DataIndexes.cc | 24 ++++++++++++++++-------- src/Episode3/DataIndexes.hh | 6 +++++- src/Main.cc | 4 ++-- src/ServerState.cc | 4 ++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fd89bafa..fb6b8007 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,7 @@ Episode 3 state and game data is stored in the system/ep3 directory. The files i * card-definitions.mnr: Compressed card definition list, sent to Episode 3 clients at connect time. Card stats and abilities can be changed by editing this file. * card-definitions.mnrd: Decompressed version of the above. If present, newserv will use this instead of the compressed version, since this is easier to edit. * card-text.mnr: Compressed card text archive. Generally only used for debugging. +* card-text.mnrd: Deompressed card text archive; same format as TextCardE.bin. Generally only used for debugging. * com-decks.json: COM decks used in tournaments. The default decks in this file come from logs from Sega's servers, so the file doesn't include every COM deck Sega ever made - the rest are probably lost to time. * maps-free/ and maps-quest/: Online free battle and quest maps (.mnm/.bin/.mnmd/.bind files). Free battle and quest files have exactly the same format; the only difference between the files in these directories is which section of the menu they will appear in on the client. newserv comes with all the original online and offline maps, including Story Mode quests. If you don't want the offline maps and quests to be playable online, delete the .bind files in both maps directories. * tournament-state.json: State of all active tournaments. This file is automatically written when any tournament changes state for any reason (e.g. a tournament is created/started/deleted or a match is resolved). diff --git a/src/Episode3/DataIndexes.cc b/src/Episode3/DataIndexes.cc index 9fde2274..51c0b10e 100644 --- a/src/Episode3/DataIndexes.cc +++ b/src/Episode3/DataIndexes.cc @@ -1817,13 +1817,22 @@ uint8_t Rules::max_def_dice() const { return this->def_dice_range & 0x0F; } -CardIndex::CardIndex(const string& filename, const string& decompressed_filename, const string& text_filename) { +CardIndex::CardIndex( + const string& filename, + const string& decompressed_filename, + const string& text_filename, + const string& decompressed_text_filename) { unordered_map> card_tags; unordered_map card_text; - if (!text_filename.empty()) { - try { - string data = prs_decompress(load_file(text_filename)); - StringReader r(data); + try { + string text_bin_data; + if (!decompressed_text_filename.empty() && isfile(decompressed_text_filename)) { + text_bin_data = load_file(decompressed_text_filename); + } else if (!text_filename.empty() && isfile(text_filename)) { + text_bin_data = prs_decompress(load_file(text_filename)); + } + if (!text_bin_data.empty()) { + StringReader r(text_bin_data); while (!r.eof()) { string card_id_str = r.get_cstr(); @@ -1905,10 +1914,9 @@ CardIndex::CardIndex(const string& filename, const string& decompressed_filename r.go((r.where() + 0x3FF) & (~0x3FF)); } - - } catch (const exception& e) { - static_game_data_log.warning("Failed to load card text: %s", e.what()); } + } catch (const exception& e) { + static_game_data_log.warning("Failed to load card text: %s", e.what()); } try { diff --git a/src/Episode3/DataIndexes.hh b/src/Episode3/DataIndexes.hh index e41d0cd6..2d5f485f 100644 --- a/src/Episode3/DataIndexes.hh +++ b/src/Episode3/DataIndexes.hh @@ -1304,7 +1304,11 @@ struct COMDeckDefinition { class CardIndex { public: - CardIndex(const std::string& filename, const std::string& decompressed_filename, const std::string& text_filename = ""); + CardIndex( + const std::string& filename, + const std::string& decompressed_filename, + const std::string& text_filename = "", + const std::string& deecompressed_text_filename = ""); struct CardEntry { CardDefinition def; diff --git a/src/Main.cc b/src/Main.cc index bd5c67bb..c516090c 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1642,7 +1642,7 @@ int main(int argc, char** argv) { } case Behavior::SHOW_EP3_CARDS: { - Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr"); + Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd"); auto card_ids = card_index.all_ids(); log_info("%zu card definitions", card_ids.size()); @@ -1664,7 +1664,7 @@ int main(int argc, char** argv) { case Behavior::SHOW_EP3_MAPS: { config_log.info("Collecting Episode 3 data"); Episode3::MapIndex map_index("system/ep3"); - Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr"); + Episode3::CardIndex card_index("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd"); auto map_ids = map_index.all_numbers(); log_info("%zu maps", map_ids.size()); diff --git a/src/ServerState.cc b/src/ServerState.cc index 3edcb6ff..1cf3e1c7 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -888,9 +888,9 @@ void ServerState::load_ep3_data() { config_log.info("Collecting Episode 3 maps"); this->ep3_map_index.reset(new Episode3::MapIndex("system/ep3")); config_log.info("Loading Episode 3 card definitions"); - this->ep3_card_index.reset(new Episode3::CardIndex("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr")); + this->ep3_card_index.reset(new Episode3::CardIndex("system/ep3/card-definitions.mnr", "system/ep3/card-definitions.mnrd", "system/ep3/card-text.mnr", "system/ep3/card-text.mnrd")); config_log.info("Loading Episode 3 trial card definitions"); - this->ep3_card_index_trial.reset(new Episode3::CardIndex("system/ep3/card-definitions-trial.mnr", "system/ep3/card-definitions-trial.mnrd", "system/ep3/card-text-trial.mnr")); + this->ep3_card_index_trial.reset(new Episode3::CardIndex("system/ep3/card-definitions-trial.mnr", "system/ep3/card-definitions-trial.mnrd", "system/ep3/card-text-trial.mnr", "system/ep3/card-text-trial.mnrd")); config_log.info("Loading Episode 3 COM decks"); this->ep3_com_deck_index.reset(new Episode3::COMDeckIndex("system/ep3/com-decks.json"));