From 3f33b94e8fe4143f647a925dc4e89d5cf7b87a55 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 2 Jun 2026 08:53:31 -0700 Subject: [PATCH] more work on ItemMagEdit --- CMakeLists.txt | 2 +- README.md | 2 +- notes/ar-codes.txt | 4 + src/ItemParameterTable.hh | 20 + src/Items.cc | 8 +- src/Items.hh | 2 +- src/MagEvolutionTable.cc | 306 ----- src/MagEvolutionTable.hh | 58 - src/MagMetadataTable.cc | 580 +++++++++ src/MagMetadataTable.hh | 78 ++ src/Main.cc | 35 + src/ServerState.cc | 73 +- src/ServerState.hh | 14 +- system/blueburst/ItemMagEdit.prs | 1 - system/tables/ItemMagEdit-bb-v4.prs | Bin 776 -> 0 bytes system/tables/ItemMagEdit-dc-11-2000.prs | Bin 515 -> 0 bytes system/tables/ItemMagEdit-dc-v1.prs | Bin 639 -> 0 bytes system/tables/ItemMagEdit-dc-v2.prs | 1 - system/tables/ItemMagEdit-gc-ep3-nte.prs | 1 - system/tables/ItemMagEdit-gc-ep3.prs | 1 - system/tables/ItemMagEdit-gc-nte.prs | Bin 754 -> 0 bytes system/tables/ItemMagEdit-gc-v3.prs | Bin 743 -> 0 bytes system/tables/ItemMagEdit-pc-nte.prs | 1 - system/tables/ItemMagEdit-pc-v2.prs | Bin 748 -> 0 bytes system/tables/ItemMagEdit-xb-v3.prs | Bin 749 -> 0 bytes .../tables/mag-metadata-table-dc-11-2000.json | 604 +++++++++ system/tables/mag-metadata-table-v1.json | 606 +++++++++ system/tables/mag-metadata-table-v2.json | 792 ++++++++++++ system/tables/mag-metadata-table-v3.json | 918 ++++++++++++++ system/tables/mag-metadata-table-v4.json | 1126 +++++++++++++++++ tests/game-tables.test.sh | 56 + .../mag-metadata-table-bb-v4.expected.bin | Bin 0 -> 1920 bytes ...mag-metadata-table-dc-11-2000.expected.bin | Bin 0 -> 1568 bytes .../mag-metadata-table-dc-v1.expected.bin | Bin 0 -> 1600 bytes .../mag-metadata-table-dc-v2.expected.bin | Bin 0 -> 2080 bytes ...mag-metadata-table-gc-ep3-nte.expected.bin | Bin 0 -> 1664 bytes .../mag-metadata-table-gc-ep3.expected.bin | Bin 0 -> 1664 bytes .../mag-metadata-table-gc-nte.expected.bin | Bin 0 -> 2080 bytes .../mag-metadata-table-gc-v3.expected.bin | Bin 0 -> 1664 bytes .../mag-metadata-table-pc-nte.expected.bin | Bin 0 -> 2080 bytes .../mag-metadata-table-pc-v2.expected.bin | Bin 0 -> 2080 bytes .../mag-metadata-table-xb-v3.expected.bin | Bin 0 -> 1664 bytes 42 files changed, 4873 insertions(+), 416 deletions(-) delete mode 100644 src/MagEvolutionTable.cc delete mode 100644 src/MagEvolutionTable.hh create mode 100644 src/MagMetadataTable.cc create mode 100644 src/MagMetadataTable.hh delete mode 120000 system/blueburst/ItemMagEdit.prs delete mode 100644 system/tables/ItemMagEdit-bb-v4.prs delete mode 100644 system/tables/ItemMagEdit-dc-11-2000.prs delete mode 100644 system/tables/ItemMagEdit-dc-v1.prs delete mode 120000 system/tables/ItemMagEdit-dc-v2.prs delete mode 120000 system/tables/ItemMagEdit-gc-ep3-nte.prs delete mode 120000 system/tables/ItemMagEdit-gc-ep3.prs delete mode 100644 system/tables/ItemMagEdit-gc-nte.prs delete mode 100644 system/tables/ItemMagEdit-gc-v3.prs delete mode 120000 system/tables/ItemMagEdit-pc-nte.prs delete mode 100644 system/tables/ItemMagEdit-pc-v2.prs delete mode 100644 system/tables/ItemMagEdit-xb-v3.prs create mode 100644 system/tables/mag-metadata-table-dc-11-2000.json create mode 100644 system/tables/mag-metadata-table-v1.json create mode 100644 system/tables/mag-metadata-table-v2.json create mode 100644 system/tables/mag-metadata-table-v3.json create mode 100644 system/tables/mag-metadata-table-v4.json create mode 100644 tests/game-tables/mag-metadata-table-bb-v4.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-dc-11-2000.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-dc-v1.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-dc-v2.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-gc-ep3-nte.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-gc-ep3.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-gc-nte.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-gc-v3.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-pc-nte.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-pc-v2.expected.bin create mode 100644 tests/game-tables/mag-metadata-table-xb-v3.expected.bin diff --git a/CMakeLists.txt b/CMakeLists.txt index 874aaaa8..cadde791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ set(SOURCES src/LevelTable.cc src/Lobby.cc src/Loggers.cc - src/MagEvolutionTable.cc + src/MagMetadataTable.cc src/Main.cc src/Map.cc src/Menu.cc diff --git a/README.md b/README.md index db0bfc30..85a28a7b 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Some of the more likely useful files are: * **src/ItemCreator.hh/cc**: Reverse-engineered item generator from Episodes 1&2 (used for all versions) * **src/ItemParameterTable.cc**: Format of many structures in ItemPMT.prs (see BinaryItemParameterTableT) * **src/Map.hh/cc**: Map file (.dat/.evt) structure, listing of object/enemy types and parameters, and reverse-engineered Challenge Mode random enemy generation algorithm -* **src/MagEvolutionTable.cc**: Format of ItemMagEdit.prs +* **src/MagMetadataTable.cc**: Format of ItemMagEdit.prs * **src/QuestScript.cc**: Complete listing of all quest opcodes on all versions, along with their arguments and behavior * **src/RareItemSet.hh/cc**: Format of ItemRT files (rare item drop tables) * **src/SaveFileFormats.hh**: Definitions of save file structures for all versions diff --git a/notes/ar-codes.txt b/notes/ar-codes.txt index 02042bcc..c5dc71f7 100644 --- a/notes/ar-codes.txt +++ b/notes/ar-codes.txt @@ -1130,3 +1130,7 @@ Rappy size modifier Disable HP reduction warning sound in Challenge mode 3OE1 => 04076A28 4E800020 + +Mag invincibility effect sparkliness modifier +(Default 003C; smaller values are more sparkly) +3OE1 => 801131C4 3860XXXX diff --git a/src/ItemParameterTable.hh b/src/ItemParameterTable.hh index 355e3eae..6f4c7f72 100644 --- a/src/ItemParameterTable.hh +++ b/src/ItemParameterTable.hh @@ -142,6 +142,26 @@ public: uint16_t feed_table = 0; uint8_t photon_blast = 0; uint8_t activation = 0; + // Internally, when a mag effect is about to activate, the game computes a byte with the following flags: + // 01 = HP low (causes effect in mag's on_low_hp if eligible, priority 2) + // 02 = died (causes effect in mag's on_death if eligible, priority 3) + // 04 = synchro < 30 (causes effect 5, priority 7) + // 08 = synchro > 100 (causes effect 4, priority 8) + // 10 = TODO (3OE1:80112B24) (causes effect 3, priority 6) + // 20 = player leveled up (causes effect 2, priority 5) + // 40 = PB meter filled (causes effect in mag's on_pb_full if eligible, priority 1) + // 80 = entered boss arena (causes effect in mag's on_boss if eligible, priority 4) + // Values for on_* trigger fields: + // 0 = no effect + // 1 = TODO (used internally; not synced via 6x61; possibly just cancel previous effect?) + // 2 = TODO (used internally; seems to be effect 1, but delayed by 45 frames?) + // 3 = TODO (used internally; seems to be effect 1, but delayed by 90 frames?) + // 4 = Shifta + Deband (level = (IQ / 40) + 1; delayed by 90 frames) + // 5 = TODO (used internally; seems to be effect 1, but delayed by 90 frames?) + // 6 = Resta (not synced via 6x61; level = (IQ / 40) + 1; delayed by 90 frames) + // 7 = Reverser (not synced via 6x61; delayed by 90 frames) + // 8 = invincibility (duration = (((IQ + synchro) / 3) + 40) * 30 frames, but this is capped at 30 seconds, so in + // practice it's always just 30 seconds regardless of IQ and synchro) uint8_t on_pb_full = 0; uint8_t on_low_hp = 0; uint8_t on_death = 0; diff --git a/src/Items.cc b/src/Items.cc index 26230c6b..c037421c 100644 --- a/src/Items.cc +++ b/src/Items.cc @@ -131,7 +131,7 @@ void player_use_item(std::shared_ptr c, size_t item_index, std::shared_p } else if ((primary_identifier & 0xFFFF0000) == 0x030C0000) { // Non-combo mag cells auto& mag = player->inventory.items[player->inventory.find_equipped_item(EquipSlot::MAG)]; - uint8_t evolution_number = s->mag_evolution_table(c->version())->get_evolution_number(mag.data.data1[1]); + uint8_t evolution_number = s->mag_metadata_table(c->version())->get_evolution_number(mag.data.data1[1]); if (evolution_number < 4) { switch (item.data.data1[2]) { case 0x00: // Cell of MAG 502 @@ -268,7 +268,7 @@ void apply_mag_feed_result( ItemData& mag_item, const ItemData& fed_item, std::shared_ptr item_parameter_table, - std::shared_ptr mag_evolution_table, + std::shared_ptr mag_metadata_table, uint8_t char_class, uint8_t section_id, bool version_has_rare_mags) { @@ -314,7 +314,7 @@ void apply_mag_feed_result( uint8_t mag_level = mag_item.compute_mag_level(); mag_item.data1[2] = mag_level; - uint8_t evolution_number = mag_evolution_table->get_evolution_number(mag_item.data1[1]); + uint8_t evolution_number = mag_metadata_table->get_evolution_number(mag_item.data1[1]); uint8_t mag_number = mag_item.data1[1]; // Note: Sega really did just hardcode all these rules into the client. There is no data file describing these @@ -489,7 +489,7 @@ void player_feed_mag(std::shared_ptr c, size_t mag_item_index, size_t fe player->inventory.items[mag_item_index].data, player->inventory.items[fed_item_index].data, s->item_parameter_table(c->version()), - s->mag_evolution_table(c->version()), + s->mag_metadata_table(c->version()), player->disp.visual.sh.char_class, player->disp.visual.sh.section_id, !is_v1_or_v2(c->version())); diff --git a/src/Items.hh b/src/Items.hh index 308dda02..ddc06695 100644 --- a/src/Items.hh +++ b/src/Items.hh @@ -19,7 +19,7 @@ void apply_mag_feed_result( ItemData& mag_item, const ItemData& fed_item, std::shared_ptr item_parameter_table, - std::shared_ptr mag_evolution_table, + std::shared_ptr mag_metadata_table, uint8_t char_class, uint8_t section_id, bool version_has_rare_mags); diff --git a/src/MagEvolutionTable.cc b/src/MagEvolutionTable.cc deleted file mode 100644 index b007a6d6..00000000 --- a/src/MagEvolutionTable.cc +++ /dev/null @@ -1,306 +0,0 @@ -#include "MagEvolutionTable.hh" - -#include "CommonFileFormats.hh" - -template -struct MotionReferenceTables { - // It seems that there are two definition tables, but only the first is used on any version of PSO. On v3 and later, - // the two offsets point to the same table, but on v2 they don't and the second table contains different data. - // TODO: Figure out what the deal is with the different v2 tables. - U32T ref_table; - U32T unused_ref_table; -} __packed_ws_be__(MotionReferenceTables, 0x08); - -template -struct ColorEntry { - // Colors are specified as 4 floats, each in the range [0, 1], for each color channel. The default colors are: - // alpha red green blue color (see StaticGameData.cc) - // 00 => 1.0 1.0 0.2 0.1 red - // 01 => 1.0 0.2 0.2 1.0 blue - // 02 => 1.0 1.0 0.9 0.1 yellow - // 03 => 1.0 0.1 1.0 0.1 green - // 04 => 1.0 0.8 0.1 1.0 purple - // 05 => 1.0 0.1 0.1 0.2 black - // 06 => 1.0 0.9 1.0 1.0 white - // 07 => 1.0 0.1 0.9 1.0 cyan - // 08 => 1.0 0.5 0.3 0.2 brown - // 09 => 1.0 1.0 0.4 0.0 orange (v3+) - // 0A => 1.0 0.502 0.545 0.977 light-blue (v3+) - // 0B => 1.0 0.502 0.502 0.0 olive (v3+) - // 0C => 1.0 0.0 0.941 0.714 turquoise (v3+) - // 0D => 1.0 0.8 0.098 0.392 fuchsia (v3+) - // 0E => 1.0 0.498 0.498 0.498 grey (v3+) - // 0F => 1.0 0.996 0.996 0.832 cream (v3+) - // 10 => 1.0 0.996 0.498 0.784 pink (v3+) - // 11 => 1.0 0.0 0.498 0.322 dark-green (v3+) - // If a mag's color index is invalid (>= 0x12), it is reassigned at equip time using the following logic: - // - Set base_index to player->visual.skin if player is an android, or player->visual.costume otherwise - // - If (base_index % 9) < 7 (that is, if their costume or body color is one of the colored slots on the character - // creation screen), then set the mag color to either (base_index % 9) or (base_index % 9) + 9, with equal - // probability. - // - If (base_index % 9) >= 7 (that is, if their costume or body color is one of the last two blank-colored slots - // on the character creation screen), then set the mag color to any of the available colors, chosen at random. - F32T alpha; - F32T red; - F32T green; - F32T blue; - ColorEntry(const VectorXYZTF& c) : alpha(c.t), red(c.x), green(c.y), blue(c.z) {} - operator VectorXYZTF() const { - return VectorXYZTF{this->red.load(), this->green.load(), this->blue.load(), this->alpha.load()}; - } -} __packed_ws_be__(ColorEntry, 0x10); - -template -struct UnknownA3EntryT { - uint8_t flags; - uint8_t unknown_a2; - U16T unknown_a3; - U16T unknown_a4; - U16T unknown_a5; - UnknownA3EntryT(const MagEvolutionTable::UnknownA3Entry& e) - : flags(e.flags), - unknown_a2(e.unknown_a2), - unknown_a3(e.unknown_a3), - unknown_a4(e.unknown_a4), - unknown_a5(e.unknown_a5) {} - operator MagEvolutionTable::UnknownA3Entry() const { - return MagEvolutionTable::UnknownA3Entry{ - this->flags, this->unknown_a2, this->unknown_a3, this->unknown_a4, this->unknown_a5}; - } -} __packed_ws_be__(UnknownA3EntryT, 0x08); - -struct HeaderV1 { - parray unknown_a1 = {0x0F, 0xF0, 0x00, 0x00}; - le_uint32_t unknown_a2 = 0x00000003; - le_uint16_t unknown_a3 = 0x00C8; - le_uint16_t unknown_a4 = 0x0078; - // unknown_a5 added in V2 - le_float unknown_a6 = 0.25; - le_float unknown_a7 = 0.1; - le_uint32_t unknown_a8 = 0x00000C00; -} __packed_ws__(HeaderV1, 0x18); - -template -struct HeaderV2V3V4 { - parray unknown_a1 = {0x0F, 0xF0, 0x00, 0x00}; - U32T unknown_a2 = 0x00000003; - U16T unknown_a3 = 0x00C8; - U16T unknown_a4 = 0x0078; - parray unknown_a5 = {0xC8, 0x00, 0x00, 0x00}; - F32T unknown_a6 = 0.25; - F32T unknown_a7 = 0.1; - U32T unknown_a8 = 0x00000C00; -} __packed_ws_be__(HeaderV2V3V4, 0x1C); - -// Fields: -// 112K / V1 / V2 / V3 / BB R -// 0018 / 0018 / 001C / 001C / 001C motion_tables.ref_table // -> MotionReference[NumMags] -// 0228 / 0228 / 02D4 / 001C / 001C motion_tables.unused_ref_table // -> MotionReference[NumMags] -// 0438 / 0438 / 05BC / 0340 / 0400 * motion_tables; // -> MotionReferenceTables -// 0440 / 0440 / 0594 / 0348 / 0408 * unknown_a2; // -> (uint8_t[2])[NumMags] (references into unknown_a3) -// 0498 / 0498 / 0608 / 03CE / 04AE * unknown_a3; // -> UnknownA3Entry[max(unknown_a2) + 1] -// 0510 / 0520 / 06B0 / 0476 / 0556 * unknown_a4; // -> uint8_t[NumMags] -// 053C / 054C / 06EC / 04BC / 05AC * color_table; // -> ColorEntry[NumColors] -// ---- / ---- / 077C / 05DC / 06CC * evolution_number_table; // -> uint8_t[NumMags] - -template -struct RootV1 { - U32T motion_tables; - U32T unknown_a2; - U32T unknown_a3; - U32T unknown_a4; - U32T color_table; -} __packed_ws_be__(RootV1, 0x14); - -template -struct RootV2V3V4 : RootV1 { - U32T evolution_number_table; -} __packed_ws_be__(RootV2V3V4, 0x18); - -static uint8_t get_v1_mag_evolution_number(uint8_t data1_1) { - static const std::array v1_evolution_number_table{ - /* 00 */ 0, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, - /* 10 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, 3, 4, 3, 3, - /* 20 */ 3, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4}; - if (data1_1 >= v1_evolution_number_table.size()) { - throw std::runtime_error("invalid mag number"); - } - return v1_evolution_number_table[data1_1]; -} - -template -class BinaryMagEvolutionTableT : public MagEvolutionTable { -public: - explicit BinaryMagEvolutionTableT(std::shared_ptr data) - : data(data), r(*data), root(&r.pget(this->r.pget_u32l(this->data->size() - 0x10))) {} - virtual ~BinaryMagEvolutionTableT() = default; - - template - const ParsedT& add_to_vector_cache(std::vector& cache, size_t base_offset, size_t index) const { - while (cache.size() <= index) { - cache.emplace_back(this->r.pget(base_offset + sizeof(RawT) * cache.size())); - } - return cache[index]; - } - - virtual size_t num_mags() const { - return NumMags; - } - - virtual size_t num_motion_entries(bool use_second_table) const { - const auto& tables = this->r.pget>(this->root->motion_tables); - return get_rel_array_count( - this->all_start_offsets(), use_second_table ? tables.unused_ref_table : tables.ref_table); - } - - virtual const MotionReference& get_motion_reference(bool use_second_table, size_t index) const { - if (index >= this->num_motion_entries(use_second_table)) { - throw std::logic_error("Invalid motion reference index"); - } - const auto& tables = this->r.pget>(this->root->motion_tables); - uint32_t array_offset = use_second_table ? tables.unused_ref_table : tables.ref_table; - return this->r.pget(array_offset + sizeof(MotionReference) * index); - } - - virtual std::pair get_unknown_a2(size_t index) const { - if (index >= this->num_mags()) { - throw std::logic_error("Invalid unknown_a2 index"); - } - uint32_t base_offset = this->root->unknown_a2 + (index * 2); - return std::make_pair(this->r.pget_u8(base_offset), this->r.pget_u8(base_offset + 1)); - } - - virtual size_t num_unknown_a3_entries() const { - return get_rel_array_count>(this->all_start_offsets(), this->root->unknown_a3); - } - - virtual const UnknownA3Entry& get_unknown_a3(size_t index) const { - if (index >= this->num_unknown_a3_entries()) { - throw std::logic_error("Invalid unknown_a2 index"); - } - return this->add_to_vector_cache>(this->unknown_a3_entries, this->root->unknown_a3, index); - } - - virtual uint8_t get_unknown_a4(size_t index) const { - if (index >= this->num_mags()) { - throw std::logic_error("Invalid unknown_a4 index"); - } - return this->r.pget_u8(this->root->unknown_a2 + index); - } - - virtual size_t num_colors() const { - return NumColors; - } - - virtual const VectorXYZTF& get_color_rgba(size_t index) const { - if (index >= NumColors) { - throw std::runtime_error("invalid mag color index"); - } - return this->add_to_vector_cache>(this->colors, this->root->color_table, index); - } - - virtual uint8_t get_evolution_number(uint8_t data1_1) const { - if (data1_1 >= this->num_mags()) { - throw std::logic_error("Invalid unknown_a4 index"); - } - if constexpr (requires { this->root->evolution_number_table; }) { - return this->r.pget_u8(this->root->evolution_number_table + data1_1); - } else { - return get_v1_mag_evolution_number(data1_1); - } - } - - const std::set& all_start_offsets() const { - if (this->start_offsets.empty()) { - this->start_offsets = all_relocation_offsets_for_rel_file(r.pgetv(0, r.size()), r.size()); - } - return this->start_offsets; - } - -protected: - std::shared_ptr data; - phosg::StringReader r; - const RootT* root; - mutable std::set start_offsets; - mutable std::vector unknown_a3_entries; - mutable std::vector colors; -}; - -class MagEvolutionTableDCNTE : public MagEvolutionTable { -public: - MagEvolutionTableDCNTE() = default; - virtual ~MagEvolutionTableDCNTE() = default; - - virtual size_t num_mags() const { - return 0x2C; - } - - virtual size_t num_motion_entries(bool) const { - return 0; - } - virtual const MotionReference& get_motion_reference(bool, size_t) const { - throw std::runtime_error("Mag tables not available on DC NTE"); - } - - virtual std::pair get_unknown_a2(size_t) const { - throw std::runtime_error("Mag tables not available on DC NTE"); - } - - virtual size_t num_unknown_a3_entries() const { - return 0; - } - virtual const UnknownA3Entry& get_unknown_a3(size_t) const { - throw std::runtime_error("Mag tables not available on DC NTE"); - } - - virtual uint8_t get_unknown_a4(size_t) const { - throw std::runtime_error("Mag tables not available on DC NTE"); - } - - virtual size_t num_colors() const { - return 0; - } - virtual const VectorXYZTF& get_color_rgba(size_t) const { - throw std::runtime_error("Mag tables not available on DC NTE"); - } - - virtual uint8_t get_evolution_number(uint8_t data1_1) const { - return get_v1_mag_evolution_number(data1_1); - } -}; - -using MagEvolutionTableDC112000 = BinaryMagEvolutionTableT, 0x28, 0x09, false>; -using MagEvolutionTableV1 = BinaryMagEvolutionTableT, 0x28, 0x09, false>; -using MagEvolutionTableV2 = BinaryMagEvolutionTableT, RootV2V3V4, 0x3A, 0x09, false>; -using MagEvolutionTableGCNTE = BinaryMagEvolutionTableT, RootV2V3V4, 0x3A, 0x09, true>; -using MagEvolutionTableGC = BinaryMagEvolutionTableT, RootV2V3V4, 0x43, 0x12, true>; -using MagEvolutionTableXB = BinaryMagEvolutionTableT, RootV2V3V4, 0x43, 0x12, false>; -using MagEvolutionTableV4 = BinaryMagEvolutionTableT, RootV2V3V4, 0x53, 0x12, false>; - -std::shared_ptr MagEvolutionTable::create( - std::shared_ptr data, Version version) { - switch (version) { - case Version::DC_NTE: - return std::make_shared(); - case Version::DC_11_2000: - return std::make_shared(data); - case Version::DC_V1: - return std::make_shared(data); - case Version::DC_V2: - case Version::PC_NTE: - case Version::PC_V2: - return std::make_shared(data); - case Version::GC_NTE: - return std::make_shared(data); - case Version::GC_V3: - case Version::GC_EP3: - case Version::GC_EP3_NTE: - return std::make_shared(data); - case Version::XB_V3: - return std::make_shared(data); - case Version::BB_V4: - return std::make_shared(data); - default: - throw std::logic_error("Cannot create mag evolution table for this version"); - } -} diff --git a/src/MagEvolutionTable.hh b/src/MagEvolutionTable.hh deleted file mode 100644 index 8a8a454c..00000000 --- a/src/MagEvolutionTable.hh +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include "WindowsPlatform.hh" - -#include - -#include -#include - -#include "CommonFileFormats.hh" -#include "Text.hh" -#include "Types.hh" -#include "Version.hh" - -class MagEvolutionTable { -public: - struct MotionReference { - struct Side { - // This specifies which entry in ItemMagMotion.dat is used. The file is just a list of 0x64-byte structures. - // 0xFF = no TItemMagSub is created - uint8_t motion_table_entry = 0xFF; - parray unknown_a1 = 0; - } __packed_ws__(Side, 0x06); - parray sides; // [0] = right side, [1] = left side - } __packed_ws__(MotionReference, 0x0C); - - struct UnknownA3Entry { - uint8_t flags; - uint8_t unknown_a2; - uint16_t unknown_a3; - uint16_t unknown_a4; - uint16_t unknown_a5; - }; - - virtual ~MagEvolutionTable() = default; - - static std::shared_ptr create(std::shared_ptr data, Version version); - - virtual size_t num_mags() const = 0; - - virtual size_t num_motion_entries(bool use_second_table) const = 0; - virtual const MotionReference& get_motion_reference(bool use_second_table, size_t index) const = 0; - - virtual std::pair get_unknown_a2(size_t index) const = 0; - - virtual size_t num_unknown_a3_entries() const = 0; - virtual const UnknownA3Entry& get_unknown_a3(size_t index) const = 0; - - virtual uint8_t get_unknown_a4(size_t index) const = 0; - - virtual size_t num_colors() const = 0; - virtual const VectorXYZTF& get_color_rgba(size_t index) const = 0; - - virtual uint8_t get_evolution_number(uint8_t data1_1) const = 0; - -protected: - MagEvolutionTable() = default; -}; diff --git a/src/MagMetadataTable.cc b/src/MagMetadataTable.cc new file mode 100644 index 00000000..5236d954 --- /dev/null +++ b/src/MagMetadataTable.cc @@ -0,0 +1,580 @@ +#include "MagMetadataTable.hh" + +#include "CommonFileFormats.hh" + +MagMetadataTable::MotionReferences MagMetadataTable::MotionReferences::from_json(const phosg::JSON& json) { + auto parse_side = [](Side& side, const phosg::JSON& side_json) -> void { + side.eff_1 = side_json.at("Eff1").as_int(); + side.eff_2 = side_json.at("Eff2").as_int(); + side.eff_3 = side_json.at("Eff3").as_int(); + side.eff_4_8 = side_json.at("Eff48").as_int(); + side.eff_5 = side_json.at("Eff5").as_int(); + side.eff_6_7 = side_json.at("Eff67").as_int(); + }; + MagMetadataTable::MotionReferences ret; + parse_side(ret.sides[0], json.at("Left")); + parse_side(ret.sides[1], json.at("Right")); + return ret; +} + +phosg::JSON MagMetadataTable::MotionReferences::json() const { + auto serialize_side = [](const Side& side) -> phosg::JSON { + return phosg::JSON::dict({ + {"Eff1", side.eff_1}, + {"Eff2", side.eff_2}, + {"Eff3", side.eff_3}, + {"Eff48", side.eff_4_8}, + {"Eff5", side.eff_5}, + {"Eff67", side.eff_6_7}, + }); + }; + return phosg::JSON::dict({{"Left", serialize_side(this->sides[0])}, {"Right", serialize_side(this->sides[1])}}); +} + +MagMetadataTable::UnknownA3Entry MagMetadataTable::UnknownA3Entry::from_json(const phosg::JSON& json) { + return UnknownA3Entry{ + .flags = static_cast(json.get_int("Flags")), + .unknown_a2 = static_cast(json.get_int("UnknownA2")), + .unknown_a3 = static_cast(json.get_int("UnknownA3")), + .unknown_a4 = static_cast(json.get_int("UnknownA4")), + .unknown_a5 = static_cast(json.get_int("UnknownA5")), + }; +} + +phosg::JSON MagMetadataTable::UnknownA3Entry::json() const { + return phosg::JSON::dict({ + {"Flags", this->flags}, + {"UnknownA2", this->unknown_a2}, + {"UnknownA3", this->unknown_a3}, + {"UnknownA4", this->unknown_a4}, + {"UnknownA5", this->unknown_a5}, + }); +} + +static VectorXYZTF color_for_json(const phosg::JSON& json) { + return VectorXYZTF{ + .x = json.get_float(0), + .y = json.get_float(1), + .z = json.get_float(2), + .t = json.get_float(3), + }; +} + +static phosg::JSON json_for_color(const VectorXYZTF& color) { + return phosg::JSON::list({color.x.load(), color.y.load(), color.z.load(), color.t.load()}); +} + +template +struct MotionReferenceTables { + // It seems that there are two definition tables, but only the first is used on any version of PSO. On v3 and later, + // the two offsets point to the same table, but on v2 they don't and the second table contains different data. + // TODO: Figure out what the deal is with the different v2 tables. + U32T first_ref_table; + U32T second_ref_table; +} __packed_ws_be__(MotionReferenceTables, 0x08); + +template +struct ColorEntry { + // Colors are specified as 4 floats, each in the range [0, 1], for each color channel. The default colors are: + // alpha red green blue color (see StaticGameData.cc) + // 00 => 1.0 1.0 0.2 0.1 red + // 01 => 1.0 0.2 0.2 1.0 blue + // 02 => 1.0 1.0 0.9 0.1 yellow + // 03 => 1.0 0.1 1.0 0.1 green + // 04 => 1.0 0.8 0.1 1.0 purple + // 05 => 1.0 0.1 0.1 0.2 black + // 06 => 1.0 0.9 1.0 1.0 white + // 07 => 1.0 0.1 0.9 1.0 cyan + // 08 => 1.0 0.5 0.3 0.2 brown + // 09 => 1.0 1.0 0.4 0.0 orange (v3+) + // 0A => 1.0 0.502 0.545 0.977 light-blue (v3+) + // 0B => 1.0 0.502 0.502 0.0 olive (v3+) + // 0C => 1.0 0.0 0.941 0.714 turquoise (v3+) + // 0D => 1.0 0.8 0.098 0.392 fuchsia (v3+) + // 0E => 1.0 0.498 0.498 0.498 grey (v3+) + // 0F => 1.0 0.996 0.996 0.832 cream (v3+) + // 10 => 1.0 0.996 0.498 0.784 pink (v3+) + // 11 => 1.0 0.0 0.498 0.322 dark-green (v3+) + // If a mag's color index is invalid (>= 0x12), it is reassigned at equip time using the following logic: + // - Set base_index to player->visual.sh.skin if player is an android, or player->visual.costume otherwise + // - If (base_index % 9) < 7 (that is, if their costume or body color is one of the colored slots on the character + // creation screen), then set the mag color to either (base_index % 9) or (base_index % 9) + 9, with equal + // probability. + // - If (base_index % 9) >= 7 (that is, if their costume or body color is one of the last two blank-colored slots + // on the character creation screen), then set the mag color to any of the available colors, chosen at random. + F32T alpha; + F32T red; + F32T green; + F32T blue; + ColorEntry(const VectorXYZTF& c) : alpha(c.t), red(c.x), green(c.y), blue(c.z) {} + operator VectorXYZTF() const { + return VectorXYZTF{this->red.load(), this->green.load(), this->blue.load(), this->alpha.load()}; + } +} __packed_ws_be__(ColorEntry, 0x10); + +template +struct UnknownA3EntryT { + uint8_t flags; + uint8_t unknown_a2; + S16T unknown_a3; + S16T unknown_a4; + S16T unknown_a5; + UnknownA3EntryT(const MagMetadataTable::UnknownA3Entry& e) + : flags(e.flags), + unknown_a2(e.unknown_a2), + unknown_a3(e.unknown_a3), + unknown_a4(e.unknown_a4), + unknown_a5(e.unknown_a5) {} + operator MagMetadataTable::UnknownA3Entry() const { + return MagMetadataTable::UnknownA3Entry{ + this->flags, this->unknown_a2, this->unknown_a3, this->unknown_a4, this->unknown_a5}; + } +} __packed_ws_be__(UnknownA3EntryT, 0x08); + +class JSONMagMetadataTable : public MagMetadataTable { +public: + explicit JSONMagMetadataTable(const phosg::JSON& json) { + for (const auto& mag_json : json.at("Mags").as_list()) { + const auto& unknown_a2_json = mag_json->at("UnknownA2").as_list(); + auto& mag = this->mags.emplace_back(); + mag.first_motion_refs = MotionReferences::from_json(mag_json->at("MotionRefs1")); + mag.second_motion_refs = MotionReferences::from_json(mag_json->at("MotionRefs2")); + mag.unknown_a2 = std::make_pair(unknown_a2_json.at(0)->as_int(), unknown_a2_json.at(1)->as_int()); + mag.render_flags = mag_json->at("RenderFlags").as_int(); + mag.evolution_number = mag_json->at("EvolutionNumber").as_int(); + } + for (const auto& a3_json : json.at("UnknownA3").as_list()) { + this->unknown_a3.emplace_back(UnknownA3Entry::from_json(*a3_json)); + } + for (const auto& color_json : json.at("Colors").as_list()) { + this->colors.emplace_back(color_for_json(*color_json)); + } + } + + virtual ~JSONMagMetadataTable() = default; + + virtual size_t num_mags() const { + return this->mags.size(); + } + + virtual size_t num_motion_entries(bool) const { + return this->mags.size(); + } + virtual const MotionReferences& get_motion_references(bool use_second_table, size_t data1_1) const { + const auto& mag = this->mags.at(data1_1); + return use_second_table ? mag.second_motion_refs : mag.first_motion_refs; + } + + virtual std::pair get_unknown_a2(size_t data1_1) const { + return this->mags.at(data1_1).unknown_a2; + } + + virtual size_t num_unknown_a3_entries() const { + return this->unknown_a3.size(); + } + virtual const UnknownA3Entry& get_unknown_a3(size_t index) const { + return this->unknown_a3.at(index); + } + + virtual uint8_t get_render_flags(size_t data1_1) const { + return this->mags.at(data1_1).render_flags; + } + + virtual size_t num_colors() const { + return this->colors.size(); + } + virtual const VectorXYZTF& get_color_rgba(size_t index) const { + return this->colors.at(index); + } + + virtual uint8_t get_evolution_number(uint8_t data1_1) const { + return this->mags.at(data1_1).evolution_number; + } + +protected: + struct Mag { + MotionReferences first_motion_refs; + MotionReferences second_motion_refs; + std::pair unknown_a2 = std::make_pair(0, 0); + uint8_t render_flags = 0; + uint8_t evolution_number = 0; + }; + std::vector mags; + std::vector unknown_a3; + std::vector colors; +}; + +struct HeaderV1 { + parray unknown_a1 = {0x0F, 0xF0, 0x00, 0x00}; + le_uint32_t unknown_a2 = 0x00000003; + le_uint16_t unknown_a3 = 0x00C8; + le_uint16_t unknown_a4 = 0x0078; + // unknown_a5 added in V2 + le_float unknown_a6 = 0.25; // 3E800000 + le_float unknown_a7 = 0.099999994; // 3DCCCCCC + le_uint32_t unknown_a8 = 0x00000C00; +} __packed_ws__(HeaderV1, 0x18); + +template +struct HeaderV2V3V4 { + parray unknown_a1 = {0x0F, 0xF0, 0x00, 0x00}; + U32T unknown_a2 = 0x00000003; + U16T unknown_a3 = 0x00C8; + U16T unknown_a4 = 0x0078; + parray unknown_a5 = {0xC8, 0x00, 0x00, 0x00}; + F32T unknown_a6 = 0.25; // 3E800000 + F32T unknown_a7 = 0.099999994; // 3DCCCCCC + U32T unknown_a8 = 0x00000C00; +} __packed_ws_be__(HeaderV2V3V4, 0x1C); + +// Fields: +// 112K / V1 / V2 / V3 / BB R +// 0018 / 0018 / 001C / 001C / 001C motion_tables.first_ref_table // -> MotionReferences[NumMags] +// 0228 / 0228 / 02D4 / 001C / 001C motion_tables.second_ref_table // -> MotionReferences[NumMags] +// 0438 / 0438 / 05BC / 0340 / 0400 * motion_tables; // -> MotionReferenceTables +// 0440 / 0440 / 0594 / 0348 / 0408 * unknown_a2; // -> (uint8_t[2])[NumMags] (references into unknown_a3) +// 0498 / 0498 / 0608 / 03CE / 04AE * unknown_a3; // -> UnknownA3Entry[max(unknown_a2) + 1] +// 0510 / 0520 / 06B0 / 0476 / 0556 * render_flags; // -> uint8_t[NumMags] +// 053C / 054C / 06EC / 04BC / 05AC * color_table; // -> ColorEntry[NumColors] +// ---- / ---- / 077C / 05DC / 06CC * evolution_number_table; // -> uint8_t[NumMags] + +template +struct RootV1 { + U32T motion_tables; + U32T unknown_a2; + U32T unknown_a3; + U32T render_flags; + U32T color_table; +} __packed_ws_be__(RootV1, 0x14); + +template +struct RootV2V3V4 : RootV1 { + U32T evolution_number_table; +} __packed_ws_be__(RootV2V3V4, 0x18); + +static uint8_t get_v1_mag_evolution_number(uint8_t data1_1) { + static const std::array v1_evolution_number_table{ + /* 00 */ 0, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, + /* 10 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 2, 3, 4, 3, 3, + /* 20 */ 3, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4}; + if (data1_1 >= v1_evolution_number_table.size()) { + throw std::runtime_error("invalid mag number"); + } + return v1_evolution_number_table[data1_1]; +} + +template +class BinaryMagMetadataTableT : public MagMetadataTable { +public: + explicit BinaryMagMetadataTableT(std::shared_ptr data) + : data(data), r(*data), root(&r.pget(this->r.pget>(this->data->size() - 0x10))) {} + virtual ~BinaryMagMetadataTableT() = default; + + template + const ParsedT& add_to_vector_cache(std::vector& cache, size_t base_offset, size_t index) const { + while (cache.size() <= index) { + cache.emplace_back(this->r.pget(base_offset + sizeof(RawT) * cache.size())); + } + return cache[index]; + } + + virtual size_t num_mags() const { + return NumMags; + } + + virtual size_t num_motion_entries(bool use_second_table) const { + const auto& tables = this->r.pget>(this->root->motion_tables); + return get_rel_array_count( + this->all_start_offsets(), use_second_table ? tables.second_ref_table : tables.first_ref_table); + } + + virtual const MotionReferences& get_motion_references(bool use_second_table, size_t index) const { + if (index >= this->num_motion_entries(use_second_table)) { + throw std::logic_error("Invalid motion reference index"); + } + const auto& tables = this->r.pget>(this->root->motion_tables); + uint32_t array_offset = use_second_table ? tables.second_ref_table : tables.first_ref_table; + return this->r.pget(array_offset + sizeof(MotionReferences) * index); + } + + virtual std::pair get_unknown_a2(size_t index) const { + if (index >= this->num_mags()) { + throw std::logic_error("Invalid unknown_a2 index"); + } + uint32_t base_offset = this->root->unknown_a2 + (index * 2); + return std::make_pair(this->r.pget_u8(base_offset), this->r.pget_u8(base_offset + 1)); + } + + virtual size_t num_unknown_a3_entries() const { + return get_rel_array_count>(this->all_start_offsets(), this->root->unknown_a3); + } + + virtual const UnknownA3Entry& get_unknown_a3(size_t index) const { + if (index >= this->num_unknown_a3_entries()) { + throw std::logic_error("Invalid unknown_a2 index"); + } + return this->add_to_vector_cache>(this->unknown_a3_entries, this->root->unknown_a3, index); + } + + virtual uint8_t get_render_flags(size_t index) const { + if (index >= this->num_mags()) { + throw std::logic_error("Invalid render_flags index"); + } + return this->r.pget_u8(this->root->render_flags + index); + } + + virtual size_t num_colors() const { + return NumColors; + } + + virtual const VectorXYZTF& get_color_rgba(size_t index) const { + if (index >= NumColors) { + throw std::runtime_error("invalid mag color index"); + } + return this->add_to_vector_cache>(this->colors, this->root->color_table, index); + } + + virtual uint8_t get_evolution_number(uint8_t data1_1) const { + if (data1_1 >= this->num_mags()) { + throw std::logic_error("Invalid evolution_number index"); + } + if constexpr (requires { this->root->evolution_number_table; }) { + return this->r.pget_u8(this->root->evolution_number_table + data1_1); + } else { + return get_v1_mag_evolution_number(data1_1); + } + } + + const std::set& all_start_offsets() const { + if (this->start_offsets.empty()) { + this->start_offsets = all_relocation_offsets_for_rel_file(r.pgetv(0, r.size()), r.size()); + } + return this->start_offsets; + } + + static std::string serialize(const MagMetadataTable& table) { + RELFileWriter rel; + RootT root; + + rel.template put(HeaderT()); + + MotionReferenceTables motion_ref_tables; + motion_ref_tables.first_ref_table = rel.w.size(); + bool alias_motion_ref_tables = true; + for (size_t z = 0; z < table.num_motion_entries(false); z++) { + const auto& refs = table.get_motion_references(false, z); + rel.template put(refs); + if (refs != table.get_motion_references(true, z)) { + alias_motion_ref_tables = false; + } + } + + if (alias_motion_ref_tables) { + motion_ref_tables.second_ref_table = motion_ref_tables.first_ref_table; + } else { + motion_ref_tables.second_ref_table = rel.w.size(); + for (size_t z = 0; z < table.num_motion_entries(true); z++) { + rel.template put(table.get_motion_references(true, z)); + } + } + + root.motion_tables = rel.w.size(); + rel.template put>(motion_ref_tables); + rel.relocations.emplace(root.motion_tables); + rel.relocations.emplace(root.motion_tables + 4); + + root.unknown_a2 = rel.w.size(); + for (size_t z = 0; z < table.num_mags(); z++) { + auto [left, right] = table.get_unknown_a2(z); + rel.template put(left); + rel.template put(right); + } + + root.unknown_a3 = rel.w.size(); + for (size_t z = 0; z < table.num_unknown_a3_entries(); z++) { + rel.template put>(table.get_unknown_a3(z)); + } + + root.render_flags = rel.w.size(); + for (size_t z = 0; z < table.num_mags(); z++) { + rel.template put(table.get_render_flags(z)); + } + + rel.align(4); + root.color_table = rel.w.size(); + for (size_t z = 0; z < table.num_colors(); z++) { + rel.template put>(table.get_color_rgba(z)); + } + + if constexpr (requires { root.evolution_number_table; }) { + root.evolution_number_table = rel.w.size(); + for (size_t z = 0; z < table.num_mags(); z++) { + rel.template put(table.get_evolution_number(z)); + } + } + + rel.align(4); + uint32_t root_offset = rel.template put(root); + for (size_t z = 1; z <= sizeof(RootT) / 4; z++) { + rel.relocations.emplace(rel.w.size() - (z * 4)); + } + + return rel.finalize(root_offset); + } + +protected: + std::shared_ptr data; + phosg::StringReader r; + const RootT* root; + mutable std::set start_offsets; + mutable std::vector unknown_a3_entries; + mutable std::vector colors; +}; + +class MagMetadataTableDCNTE : public MagMetadataTable { +public: + MagMetadataTableDCNTE() = default; + virtual ~MagMetadataTableDCNTE() = default; + + virtual size_t num_mags() const { + return 0x2C; + } + + virtual size_t num_motion_entries(bool) const { + return 0; + } + virtual const MotionReferences& get_motion_references(bool, size_t) const { + throw std::runtime_error("Mag tables not available on DC NTE"); + } + + virtual std::pair get_unknown_a2(size_t) const { + throw std::runtime_error("Mag tables not available on DC NTE"); + } + + virtual size_t num_unknown_a3_entries() const { + return 0; + } + virtual const UnknownA3Entry& get_unknown_a3(size_t) const { + throw std::runtime_error("Mag tables not available on DC NTE"); + } + + virtual uint8_t get_render_flags(size_t) const { + throw std::runtime_error("Mag tables not available on DC NTE"); + } + + virtual size_t num_colors() const { + return 0; + } + virtual const VectorXYZTF& get_color_rgba(size_t) const { + throw std::runtime_error("Mag tables not available on DC NTE"); + } + + virtual uint8_t get_evolution_number(uint8_t data1_1) const { + return get_v1_mag_evolution_number(data1_1); + } +}; + +using MagMetadataTableDC112000 = BinaryMagMetadataTableT, 0x2C, 0x09, false>; +using MagMetadataTableV1 = BinaryMagMetadataTableT, 0x2C, 0x09, false>; +using MagMetadataTableV2 = BinaryMagMetadataTableT, RootV2V3V4, 0x3A, 0x09, false>; +using MagMetadataTableGCNTE = BinaryMagMetadataTableT, RootV2V3V4, 0x3A, 0x09, true>; +using MagMetadataTableGC = BinaryMagMetadataTableT, RootV2V3V4, 0x43, 0x12, true>; +using MagMetadataTableXB = BinaryMagMetadataTableT, RootV2V3V4, 0x43, 0x12, false>; +using MagMetadataTableV4 = BinaryMagMetadataTableT, RootV2V3V4, 0x53, 0x12, false>; + +std::shared_ptr MagMetadataTable::from_binary( + std::shared_ptr data, Version version) { + switch (version) { + case Version::DC_NTE: + return std::make_shared(); + case Version::DC_11_2000: + return std::make_shared(data); + case Version::DC_V1: + return std::make_shared(data); + case Version::DC_V2: + case Version::PC_NTE: + case Version::PC_V2: + return std::make_shared(data); + case Version::GC_NTE: + return std::make_shared(data); + case Version::GC_V3: + case Version::GC_EP3: + case Version::GC_EP3_NTE: + return std::make_shared(data); + case Version::XB_V3: + return std::make_shared(data); + case Version::BB_V4: + return std::make_shared(data); + default: + throw std::logic_error("Cannot create mag metadata table for this version"); + } +} + +std::shared_ptr MagMetadataTable::from_json(const phosg::JSON& json) { + return std::make_shared(json); +} + +phosg::JSON MagMetadataTable::json() const { + if (this->num_motion_entries(true) != this->num_motion_entries(false)) { + throw std::runtime_error("Motion entry counts differ across tables"); + } + if (this->num_motion_entries(false) != this->num_mags()) { + throw std::runtime_error(std::format("Motion entry count {} does not match mag count {}", + this->num_motion_entries(false), this->num_mags())); + } + + auto mags_json = phosg::JSON::list(); + for (size_t z = 0; z < this->num_mags(); z++) { + auto mag_json = phosg::JSON::dict(); + mag_json.emplace("MotionRefs1", this->get_motion_references(false, z).json()); + mag_json.emplace("MotionRefs2", this->get_motion_references(true, z).json()); + auto unknown_a2 = this->get_unknown_a2(z); + mag_json.emplace("UnknownA2", phosg::JSON::list({unknown_a2.first, unknown_a2.second})); + mag_json.emplace("RenderFlags", this->get_render_flags(z)); + mag_json.emplace("EvolutionNumber", this->get_evolution_number(z)); + mags_json.emplace_back(std::move(mag_json)); + } + + auto unknown_a3_json = phosg::JSON::list(); + for (size_t z = 0; z < this->num_unknown_a3_entries(); z++) { + unknown_a3_json.emplace_back(this->get_unknown_a3(z).json()); + } + + auto colors_json = phosg::JSON::list(); + for (size_t z = 0; z < this->num_colors(); z++) { + colors_json.emplace_back(json_for_color(this->get_color_rgba(z))); + } + + return phosg::JSON::dict({ + {"Mags", std::move(mags_json)}, + {"UnknownA3", std::move(unknown_a3_json)}, + {"Colors", std::move(colors_json)}, + }); +} + +std::string MagMetadataTable::serialize_binary(Version version) const { + switch (version) { + case Version::DC_NTE: + throw std::runtime_error("DC NTE does not have a an ItemMagEdit format"); + case Version::DC_11_2000: + return MagMetadataTableDC112000::serialize(*this); + case Version::DC_V1: + return MagMetadataTableV1::serialize(*this); + case Version::DC_V2: + case Version::PC_NTE: + case Version::PC_V2: + return MagMetadataTableV2::serialize(*this); + case Version::GC_NTE: + return MagMetadataTableGCNTE::serialize(*this); + case Version::GC_V3: + case Version::GC_EP3: + case Version::GC_EP3_NTE: + return MagMetadataTableGC::serialize(*this); + case Version::XB_V3: + return MagMetadataTableXB::serialize(*this); + case Version::BB_V4: + return MagMetadataTableV4::serialize(*this); + default: + throw std::logic_error("Cannot create item parameter table for this version"); + } +} diff --git a/src/MagMetadataTable.hh b/src/MagMetadataTable.hh new file mode 100644 index 00000000..44b1f358 --- /dev/null +++ b/src/MagMetadataTable.hh @@ -0,0 +1,78 @@ +#pragma once + +#include "WindowsPlatform.hh" + +#include + +#include +#include + +#include "CommonFileFormats.hh" +#include "Text.hh" +#include "Types.hh" +#include "Version.hh" + +class MagMetadataTable { +public: + struct MotionReferences { + // These entries specify which entry in ItemMagMotion.dat is used. The file is just a list of 0x64-byte structures. + // 0xFF = no TItemMagSub is created + struct Side { + uint8_t eff_1; + uint8_t eff_2; + uint8_t eff_3; + uint8_t eff_4_8; + uint8_t eff_5; + uint8_t eff_6_7; + + bool operator==(const Side&) const = default; + bool operator!=(const Side&) const = default; + } __packed_ws__(Side, 6); + parray sides; // [0] = right side, [1] = left side + + bool operator==(const MotionReferences&) const = default; + bool operator!=(const MotionReferences&) const = default; + + static MotionReferences from_json(const phosg::JSON& json); + phosg::JSON json() const; + } __packed_ws__(MotionReferences, 0x0C); + + struct UnknownA3Entry { + uint8_t flags; + uint8_t unknown_a2; + int16_t unknown_a3; + int16_t unknown_a4; + int16_t unknown_a5; + + static UnknownA3Entry from_json(const phosg::JSON& json); + phosg::JSON json() const; + }; + + virtual ~MagMetadataTable() = default; + + virtual size_t num_mags() const = 0; + + virtual size_t num_motion_entries(bool use_second_table) const = 0; + virtual const MotionReferences& get_motion_references(bool use_second_table, size_t index) const = 0; + + virtual std::pair get_unknown_a2(size_t index) const = 0; + + virtual size_t num_unknown_a3_entries() const = 0; + virtual const UnknownA3Entry& get_unknown_a3(size_t index) const = 0; + + virtual uint8_t get_render_flags(size_t index) const = 0; + + virtual size_t num_colors() const = 0; + virtual const VectorXYZTF& get_color_rgba(size_t index) const = 0; + + virtual uint8_t get_evolution_number(uint8_t data1_1) const = 0; + + static std::shared_ptr from_binary(std::shared_ptr data, Version version); + static std::shared_ptr from_json(const phosg::JSON& json); + + phosg::JSON json() const; + std::string serialize_binary(Version version) const; + +protected: + MagMetadataTable() = default; +}; diff --git a/src/Main.cc b/src/Main.cc index 8416c5cd..de8b13bc 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -2396,6 +2396,41 @@ Action a_encode_item_parameter_table( write_output_data(args, data, nullptr); }); +Action a_decode_mag_metadata_table( + "decode-mag-metadata-table", "\ + decode-mag-metadata-table [INPUT-FILENAME [OUTPUT-FILENAME]] [OPTIONS...]\n\ + Converts an ItemMagEdit file into a JSON mag metadata file. A version\n\ + option is required. Expects compressed input (a .prs file) by default; use\n\ + --decompressed if the input is not compressed.\n", + +[](phosg::Arguments& args) { + auto input_data = read_input_data(args); + if (!args.get("decompressed")) { + input_data = prs_decompress(input_data); + } + auto data = std::make_shared(std::move(input_data)); + auto table = MagMetadataTable::from_binary(data, get_cli_version(args, Version::BB_V4)); + auto json = table->json(); + auto serialized = json.serialize(phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::SORT_DICT_KEYS); + write_output_data(args, serialized, nullptr); + }); + +Action a_encode_mag_metadata_table( + "encode-mag-metadata-table", "\ + encode-mag-metadata-table [INPUT-FILENAME [OUTPUT-FILENAME]] [OPTIONS...]\n\ + Converts a JSON mag metadata file into an ItemMagEdit file compatible with\n\ + the game client. A version option is required. By default the output will\n\ + be compressed, as the client expects; use --decompressed to get\n\ + uncompressed output.\n", + +[](phosg::Arguments& args) { + auto json = phosg::JSON::parse(read_input_data(args)); + auto table = MagMetadataTable::from_json(json); + std::string data = table->serialize_binary(get_cli_version(args, Version::BB_V4)); + if (!args.get("decompressed")) { + data = prs_compress_optimal(data); + } + write_output_data(args, data, nullptr); + }); + Action a_decode_level_table( "decode-level-table", nullptr, +[](phosg::Arguments& args) { diff --git a/src/ServerState.cc b/src/ServerState.cc index 74c97c6f..c9e03e29 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -489,15 +489,19 @@ std::shared_ptr ServerState::item_parameter_table_for_ return this->item_parameter_table(is_v1(version) ? Version::PC_V2 : version); } -std::shared_ptr ServerState::mag_evolution_table(Version version) const { - if (is_v1(version)) { - return this->mag_evolution_table_v1; +std::shared_ptr ServerState::mag_metadata_table(Version version) const { + if (version == Version::DC_NTE) { + return this->mag_metadata_table_dc_nte; + } else if (version == Version::DC_11_2000) { + return this->mag_metadata_table_dc_11_2000; + } else if (is_v1(version)) { + return this->mag_metadata_table_v1; } else if (is_v2(version)) { - return this->mag_evolution_table_v2; + return this->mag_metadata_table_v2; } else if (!is_v4(version)) { - return this->mag_evolution_table_v3; + return this->mag_metadata_table_v3; } else { - return this->mag_evolution_table_v4; + return this->mag_metadata_table_v4; } } @@ -2156,25 +2160,32 @@ void ServerState::load_item_definitions() { auto json = phosg::JSON::parse(phosg::load_file("system/tables/translation-table.json")); auto new_item_translation_table = std::make_shared(json, new_item_parameter_tables); - config_log.info_f("Loading v1 mag evolution table"); - auto mag_data_v1 = std::make_shared(prs_decompress(phosg::load_file("system/tables/ItemMagEdit-dc-v1.prs"))); - auto new_table_v1 = MagEvolutionTable::create(mag_data_v1, Version::DC_V1); - config_log.info_f("Loading v2 mag evolution table"); - auto mag_data_v2 = std::make_shared(prs_decompress(phosg::load_file("system/tables/ItemMagEdit-dc-v2.prs"))); - auto new_table_v2 = MagEvolutionTable::create(mag_data_v2, Version::DC_V2); - config_log.info_f("Loading v3 mag evolution table"); - auto mag_data_v3 = std::make_shared(prs_decompress(phosg::load_file("system/tables/ItemMagEdit-xb-v3.prs"))); - auto new_table_v3 = MagEvolutionTable::create(mag_data_v3, Version::XB_V3); - config_log.info_f("Loading v4 mag evolution table"); - auto mag_data_v4 = std::make_shared(prs_decompress(phosg::load_file("system/tables/ItemMagEdit-bb-v4.prs"))); - auto new_table_v4 = MagEvolutionTable::create(mag_data_v4, Version::BB_V4); + config_log.info_f("Creating DC NTE mag metadata table"); + auto new_table_dc_nte = MagMetadataTable::from_binary(nullptr, Version::DC_NTE); + config_log.info_f("Loading DC 11/2000 mag metadata table"); + auto new_table_11_2000 = MagMetadataTable::from_json(phosg::JSON::parse(phosg::load_file( + "system/tables/mag-metadata-table-dc-11-2000.json"))); + config_log.info_f("Loading v1 mag metadata table"); + auto new_table_v1 = MagMetadataTable::from_json(phosg::JSON::parse(phosg::load_file( + "system/tables/mag-metadata-table-v1.json"))); + config_log.info_f("Loading v2 mag metadata table"); + auto new_table_v2 = MagMetadataTable::from_json(phosg::JSON::parse(phosg::load_file( + "system/tables/mag-metadata-table-v2.json"))); + config_log.info_f("Loading v3 mag metadata table"); + auto new_table_v3 = MagMetadataTable::from_json(phosg::JSON::parse(phosg::load_file( + "system/tables/mag-metadata-table-v3.json"))); + config_log.info_f("Loading v4 mag metadata table"); + auto new_table_v4 = MagMetadataTable::from_json(phosg::JSON::parse(phosg::load_file( + "system/tables/mag-metadata-table-v4.json"))); this->item_parameter_tables = std::move(new_item_parameter_tables); this->item_translation_table = std::move(new_item_translation_table); - this->mag_evolution_table_v1 = std::move(new_table_v1); - this->mag_evolution_table_v2 = std::move(new_table_v2); - this->mag_evolution_table_v3 = std::move(new_table_v3); - this->mag_evolution_table_v4 = std::move(new_table_v4); + this->mag_metadata_table_dc_nte = std::move(new_table_dc_nte); + this->mag_metadata_table_dc_11_2000 = std::move(new_table_11_2000); + this->mag_metadata_table_v1 = std::move(new_table_v1); + this->mag_metadata_table_v2 = std::move(new_table_v2); + this->mag_metadata_table_v3 = std::move(new_table_v3); + this->mag_metadata_table_v4 = std::move(new_table_v4); } void ServerState::load_ep3_cards() { @@ -2230,20 +2241,13 @@ void ServerState::generate_bb_stream_file() { config_log.info_f("Generating BB stream file"); auto sf = std::make_shared(); - auto add_file = [&](const std::string& filename, const void* data = nullptr, size_t size = 0) -> void { + auto add_file = [&](const std::string& filename, const void* data, size_t size) -> void { auto& e = sf->entries.emplace_back(); e.offset = sf->data.size(); e.filename = filename; - if (!data) { - std::string file_data = phosg::load_file("system/blueburst/" + filename); - e.size = file_data.size(); - e.checksum = phosg::crc32(file_data.data(), file_data.size()); - sf->data += file_data; - } else { - e.size = size; - e.checksum = phosg::crc32(data, size); - sf->data.append(reinterpret_cast(data), size); - } + e.size = size; + e.checksum = phosg::crc32(data, size); + sf->data.append(reinterpret_cast(data), size); config_log.debug_f( "[BBStreamFile] Added file {} at offset {:08X} ({:08X} bytes) with checksum {:08X}; total size is now {:08X}", filename, e.offset, e.size, e.checksum, sf->data.size()); @@ -2251,6 +2255,7 @@ void ServerState::generate_bb_stream_file() { auto level_table_data = prs_compress_optimal(this->level_table_v4->serialize_binary_v4()); auto pmt_data = prs_compress_optimal(this->item_parameter_table(Version::BB_V4)->serialize_binary(Version::BB_V4)); + auto mag_data = prs_compress_optimal(this->mag_metadata_table(Version::BB_V4)->serialize_binary(Version::BB_V4)); const auto& bps = *this->battle_params; add_file("BattleParamEntry.dat", &bps.get_table(true, Episode::EP1), sizeof(BattleParamsIndex::Table)); @@ -2260,7 +2265,7 @@ void ServerState::generate_bb_stream_file() { add_file("BattleParamEntry_lab_on.dat", &bps.get_table(false, Episode::EP2), sizeof(BattleParamsIndex::Table)); add_file("BattleParamEntry_ep4_on.dat", &bps.get_table(false, Episode::EP4), sizeof(BattleParamsIndex::Table)); add_file("PlyLevelTbl.prs", level_table_data.data(), level_table_data.size()); - add_file("ItemMagEdit.prs"); + add_file("ItemMagEdit.prs", mag_data.data(), mag_data.size()); add_file("ItemPMT.prs", pmt_data.data(), pmt_data.size()); this->bb_stream_file = sf; diff --git a/src/ServerState.hh b/src/ServerState.hh index 6df13a72..3dabb2e1 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -24,7 +24,7 @@ #include "ItemTranslationTable.hh" #include "LevelTable.hh" #include "Lobby.hh" -#include "MagEvolutionTable.hh" +#include "MagMetadataTable.hh" #include "Menu.hh" #include "Quest.hh" #include "TeamIndex.hh" @@ -221,10 +221,12 @@ struct ServerState : public std::enable_shared_from_this { std::array, NUM_VERSIONS> item_stack_limits_tables; size_t bb_max_bank_items = 200; size_t bb_max_bank_meseta = 999999; - std::shared_ptr mag_evolution_table_v1; - std::shared_ptr mag_evolution_table_v2; - std::shared_ptr mag_evolution_table_v3; - std::shared_ptr mag_evolution_table_v4; + std::shared_ptr mag_metadata_table_dc_nte; + std::shared_ptr mag_metadata_table_dc_11_2000; + std::shared_ptr mag_metadata_table_v1; + std::shared_ptr mag_metadata_table_v2; + std::shared_ptr mag_metadata_table_v3; + std::shared_ptr mag_metadata_table_v4; std::shared_ptr text_index; std::array, NUM_VERSIONS> item_name_indexes; std::shared_ptr word_select_table; @@ -371,7 +373,7 @@ struct ServerState : public std::enable_shared_from_this { std::shared_ptr level_table(Version version) const; std::shared_ptr item_parameter_table(Version version) const; std::shared_ptr item_parameter_table_for_encode(Version version) const; - std::shared_ptr mag_evolution_table(Version version) const; + std::shared_ptr mag_metadata_table(Version version) const; std::shared_ptr item_stack_limits(Version version) const; std::shared_ptr item_name_index_opt(Version version) const; // Returns null if missing std::shared_ptr item_name_index(Version version) const; // Throws if missing diff --git a/system/blueburst/ItemMagEdit.prs b/system/blueburst/ItemMagEdit.prs deleted file mode 120000 index cd864f3d..00000000 --- a/system/blueburst/ItemMagEdit.prs +++ /dev/null @@ -1 +0,0 @@ -../tables/ItemMagEdit-bb-v4.prs \ No newline at end of file diff --git a/system/tables/ItemMagEdit-bb-v4.prs b/system/tables/ItemMagEdit-bb-v4.prs deleted file mode 100644 index fb63980a736b08ac2d5a8ffbf902691575ee7b5a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 776 zcmWlV%}*0~9EYdxBSYH(Dj-z1qX@q2YC*skq%E^-i;Bj#lB{0X1z(~U4w`6Uw3w;~ z4<0<}X%f+@*=6fN-Ge6Gq-a$_>I)m(m{{NIMqyB?L;213WBmg@&*#bGcd8s`;@n7a zhu$+pe8YWc<%&}|;B1kd2JqZ$w%g4YVHD9J)6WR;<>4jCgVrehfVJI})J;5mR6tc#3HD+^a$`l5s?i{lC?h~l9)6NaAxEhMZ6Ym@ zv7TyptRrbYeuTLqqlwDL&{(dZ zc#eowGF4(_g3@aul>TQm_2xH;Xf~7WYv5ii*Ej%6wPj-r3y)(tWvFC@dE+xbYHM3s zF6$AhP%!rt?F+GYh4-#4BiM|q1&z#vps0d^<>%`rLTqao3LJG>_qY&NrWeQ9T|M+U zoS1Zl-o+4LC8K-v@AKNw$L%7zWZH(Xm)bFVKf3h-q{V&Z=_dvaVzt$l1ovm5twGKt z$Z>|BRV0+#5zIPrTHYxd&0ezbx5rCL%UoW)tRMeYQYvvPr9qNz8$SK#;*JmDalcWk zT=;*zk@0c`B^cbzvCeQebgMUp`OdX&iQ}FH0 zCm%*X*F5$gV8g?m3tv6D1lI8SEp~g5-I+LW4>!D4A23T^JEp3A{u?)%UuODJB3f6oI6Z;y4Nl R4A}U@)4`SS*tmiX_YH7-s@(tp diff --git a/system/tables/ItemMagEdit-dc-11-2000.prs b/system/tables/ItemMagEdit-dc-11-2000.prs deleted file mode 100644 index 71995612d28441aa81ea1dbeb84f1a9b6def8c50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 515 zcmWN|Pe_w-9LMqBv%k;w?9ZcFv*qRegw1VTZaS%!dJN^*ueK7l)!O1!s8f4y09+;55`0~ zuz=IlR?1b8>wc zmMqvhILP&(89}aJ$+YCUFd1mIJBjN#n9cE~O@U`d-VrL~k?S6&UwWfptov#+WO)1e zjtaqIEr7iu4cwQSKTj^+X1}>+gu^*mn{SG+OWfVWZWmi9;*seoZa?lzQ2GQV$TtM5;hff jYk diff --git a/system/tables/ItemMagEdit-dc-v1.prs b/system/tables/ItemMagEdit-dc-v1.prs deleted file mode 100644 index b94de46e56950a943d0e0a7ecf9aa6f0ab6b96a4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 639 zcmWlVKTH#G9L0Za@7imx*B;1!u=FS*q9Q8)ltSAB0ks$%FmW?th;e0ca5zYj#OOj8 z{Ii@1rjx|PL1P>+Dd0dz7YrtZG)PDX(>4%GfxGXsE^qw2&wKUW9Ah@0$$qdW-XpDV z6*IleoktKZ>5%5Zagro)?_q^9O#Lwokw?a$N)EILWQXMp^?yD~76Io-@!?{OPNGdF zzlvU}7Z9Xp3DbtYRFPCuQ!h$xu};NhsuggF6dB~rx@Y70_IY&i{74+9I9#BE6qRrzDRMS7^+bA1jeMgzDl`(q zhUlljCmjJ72GNL_>>JF(GXV$eYhd_gftGC%9~1+PYiPhd1x4M7|Gp6J!hbAk*~n(N z(>9&uNBLA%)KRYON$V*p*Rqw&9MaKIwQwijY+c?eKzwU=B)~q90n2t~kvuDc)3soe zFuv=_7mmELmCF$?D3&dCzl=>SVN#gG?dJ`HaOcu`oT=ViurB?lHWyezWGtO142!gK-O?=D9$M4cB1*`qg7Rzit^)M~;)mUAP zCf29oFq%+ij6X(*!MO-;bTnRkV+T9tY(h81;Ld$WEc7~u7u}q^AO3B;GW`5UBg)UE dmy4r3ZIATUzbK&eXUVo>Z}%lOT`AMU*gu)5N2LG& diff --git a/system/tables/ItemMagEdit-dc-v2.prs b/system/tables/ItemMagEdit-dc-v2.prs deleted file mode 120000 index 84d5c062..00000000 --- a/system/tables/ItemMagEdit-dc-v2.prs +++ /dev/null @@ -1 +0,0 @@ -ItemMagEdit-pc-v2.prs \ No newline at end of file diff --git a/system/tables/ItemMagEdit-gc-ep3-nte.prs b/system/tables/ItemMagEdit-gc-ep3-nte.prs deleted file mode 120000 index 80054eb8..00000000 --- a/system/tables/ItemMagEdit-gc-ep3-nte.prs +++ /dev/null @@ -1 +0,0 @@ -ItemMagEdit-gc-v3.prs \ No newline at end of file diff --git a/system/tables/ItemMagEdit-gc-ep3.prs b/system/tables/ItemMagEdit-gc-ep3.prs deleted file mode 120000 index 80054eb8..00000000 --- a/system/tables/ItemMagEdit-gc-ep3.prs +++ /dev/null @@ -1 +0,0 @@ -ItemMagEdit-gc-v3.prs \ No newline at end of file diff --git a/system/tables/ItemMagEdit-gc-nte.prs b/system/tables/ItemMagEdit-gc-nte.prs deleted file mode 100644 index fbeb4c75f93dfb1dceef66abb01afb2879bfdfd2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 754 zcmWlWT}V>_9L4XpySur&yWOd&rP=N@)6&#Z%lx{VUwvbRk3morSVTc!P!BVfeNa7E z1cAn_Ou=4yD2N_H>RJX83nZeFmWCfAa}>6 zjX|f@Fo82kCxiQN2pSE7Wd(uleGD^piqsrHJGty=Bgux1A>vRHr03EmGKEk|`64O< zv=$Y1@N|f7O^=%8&GDaOi0y~5keJZi>Q80S*XhDRp4BW z?IPuvv5mO!4swQTsrOiNKWdH;vz+F9KOC?-T*>{jJox=hUKXYw#K)R~uYRI&@5IFPc;67TBIIeupMk?D+)Z9`^tC~o z(~DI_=TA-^0Y9zY^CCRbZXshccO{!(J5!dtF9|r`buC+OXm`RI=l{;dE0?*Ce{B~T gR{}26QT-8fU5n$Ev5qa0dg+^558De7yqRJC0}y75ZU6uP diff --git a/system/tables/ItemMagEdit-gc-v3.prs b/system/tables/ItemMagEdit-gc-v3.prs deleted file mode 100644 index b71efbe8874bae7f92e3a042ea454edc4a350eb6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 743 zcmWmAO-K}R9LDk4-Pv*6*==Xl%(u)@GwoH&m+WPCoy@E(tT2cOwulaP=@3yJYOHAu zJah=5cP6lmg6L2N*+FUx1FhTKSCm9Kv5~6qk&3fY*VQe zTSY2{vY8YfjpQ>RX>(FKlok?oY^QP=D^*&86(VIpsi90A)wDoH%?rv#b#~N%Hy3MV z%5kEOg!nr0#_K71IJpzG5#s))d*AdXs(awhckk%M;&WIT-6MG5@80sv@LRt*meqwN_l8PA~yv9W%{PZGK;0=iFd1f-LPZp?(~r zXWm(??ZdYZQH(Wb=!CR*5019axF`ke=UXg(?q1SD?$WnaVb&aF!;G&w!JdyW_XtOb bS6<_uwzCBOTNey);sLf8LXix~!Eyfpl!%Sg diff --git a/system/tables/ItemMagEdit-pc-nte.prs b/system/tables/ItemMagEdit-pc-nte.prs deleted file mode 120000 index 84d5c062..00000000 --- a/system/tables/ItemMagEdit-pc-nte.prs +++ /dev/null @@ -1 +0,0 @@ -ItemMagEdit-pc-v2.prs \ No newline at end of file diff --git a/system/tables/ItemMagEdit-pc-v2.prs b/system/tables/ItemMagEdit-pc-v2.prs deleted file mode 100644 index 24a28fd14611c414b3bb41029fca6d702e094372..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 748 zcmWNNOGp%P9LN9r(phI`ch*;CrjDAaSy`!BYCAic_OP(fyQI`5$V+6f zhbguM^B_nh)In(t1B;D1NDta@@v-^Xh}KbOe&6=;y?o)r=ld=2#2K^Yn{0~pEgA?M zneIg+b4?|Hduaj%@zZV>1p6~sMI2M839THtA+=DdiV8{*QC>x_cBy1RrAYY-_R)3@ zRU{RnQKbSjbWzB(aX3OrRBkRWxOgcK2UOaI{UV79Wb$zEk(3TaB`^FU6)QMFB^-{E zRD`1{Nodwc10UGrB`4Zc;&4)=G6j2RCx_i6Wuiu<3{;D>ML`W^&!9S6gKMjZI)!p@ zaGb)20~DS(L_Hg)MbuUjTXVVw6IZK)a5zpi4PpoO_ELnr_EQBBa+a3X*LRo!%GZz` zAihR6_(CeyP;=%2+R>R*iLCNk+^b>lhmzGG&f>8KuNLFecHrFxKDEXWgnIy~qe#K; z`B7$p9IKe*lYx=}6pcbc5;B(@jwDD!mb@$sMJP*-ZDD4s zhWeqvtPoh-Cda&yx%zi?)X@+a8Te;;x;Rd5&Y3p$z=pYR7I&gx z!y{Vl&&k29c(0^qWLB9OlI2p-awfYziGH;YIk#C+3*x^PRHk_D#~ZpAmg2?TlkhKu zF6zw=_}juW@w~CJy09+34I`iZkZzzqVTZCj6N3C_HjS zyHPWwnS3h_Up>xR%Ov ch(fnz?bgHGHR$j}UQQqWQH!yN>9#WVALp`%5&!@I diff --git a/system/tables/ItemMagEdit-xb-v3.prs b/system/tables/ItemMagEdit-xb-v3.prs deleted file mode 100644 index 13e844d27766d800bfa617fa43891f74914daf32..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 749 zcmWO2%}W$<9LMqBK03Rz53_2fR_dggJ-V6NlkTjeZCVy)dFixJ6m+tPs7p*SMbNQB zL>(ru3=gppR0ku2HI}ek2|+~4U@5IwN3Csko&A3DA9(ZPUFp{uvsL6-f?b(6p@hcz z(aJoD3~<-&r2%}k+r3`-70Z7B2b--owS+54ibyeq*4(Y1zIbkiAtu>SfasGCSb2jrPwn< z$^8l?-|eF_xnlyFw-fv4@(gCKHV(kyINCmlO{njuSqj*XR?d>Ew)Vh*lX-&v(e!|TWxYm_r0!5 zJ~V`HNmMW~eG}I+cF0q{IKs}{4>xNtK8+)TaO^}6Gh!_vo@+9)#Ij3-jz#NDQtK`1`sC5kU%FseD|^^Gm5H zyiB@Zg{bMdJQH%RD2g$A=MFDr?`5w_x1gFV=YsxL@0VV_Y<`k$ml9}AnK9}?=sT8G zTr(#p`94X3E0vt+ytTrL^?_3eo&ReioYvsC8+Lgmx5q#k3zv;|zBfOamxGIJ_=`E? dU_dhXfV~>$QpXSDEFgFH~*zgmmQzlJh((()FDWfPAzaUavSm}`X z2`N%gA<=j<^Pbm!U^yaEW_R9vGxNQ9=dSw!zyJVE_<%~%D79Lx4R8QxOl(eiI93#= zQ|Vw?miOiTN~N+_*>kyEyRKcc**s<*Gnq`Irco?34&#y}O-K`oL}E5E8;{3l;xnmK zY9qCgOeWWp>%6AHU?>?%91jiIoep~}7MqXFN2AfX=$yynDSOIpw_A0qKA&&Px8?PE zH@%zLZ1ymFn9Jo3atE1AW+$_gPN%oi+aea{W3^hV)~dx~IkFrT3Wce{R6d`d%ufaa zfnuQO_xl(83!zY`7%B#X!G+*69En7hBg^4%cqzPu{MEoJ@>l#Te9k8)CyOVGz5Q`? z_lnlS<3{6g7Y`2)PY+M){2oU+?r}y&*49SWIA zd@bTx|10KqgV%Y-q#yIOi+6@|Ub9|tKH?sV=OXT>_+4<^KdxA_pU>wuD9-Oyy?M;Bun&?0I*iVA0`6XgvLM-e8$!6dgJQmt<5*io(%_?cDRptNaF0PjJ z9NCMD3*_KGoaJBIYB#6niAy#0zGQW!9M#i(oP>IPeU0Py#zYSGC26RQ2B=q8cJ=A$ zBkMyxsh%hM@bF%}yvW`|VP*xzBv6NBoqGad>|C|LR!DW8EQ375e4VZlN>HY{_1ERqu_ z@BfyZPO41VRXn-%-tT_h>fyU{zlah<^h|en-w%TzxTFkGC|D6_ofK$o3AD}%9LL#q zwr$(qvbQkM4(%wVcGa%uc}Lz+qtQ5Q9DWjf6zIMQf!5V(dNq@-*Xt+slUl8ITszJS za)J+nHNl2pQ_vDL1*SIVvn*H=_`bjI?{_+#z0O`iur4T<%V*`YQmJ%WIyH5rQt4HC zuIqN)F6@KC0QUZRU(dN%ES?w7wN55^{%`AcyM53;c-!+?pgr^W&F?PiH~Y?`7s>}5 z0rCMrJ^;uEV1ax{zjHoJ=VRuBIk$Jo2c(2PyHx6LKFreQdCl_7%7$mM_rjQ>E1+pR?)6((^{w;|xv#M*dVJ2<@Hx-{ufxbul4c{VisTIXH zA<;|tJA8wiLTM0}kidO~~)Cc2<&^nc}8#__2ooEJZlN6jcEOIeD444t&3aN8lW zY*2#h;o+&`zP#cR1S5TKPW5OQw=s{$V|Z|{O8fsjnzqI5?By}zzRYpqHXbjIvACNktFu#lQFgkAo`NR&apW#2er& z8w>_-f;TRgYtOakbUJsPyJ)me`+^`G2nV@b?lgCr&1O%sCxt?xSLo&Q`EI_;drFej zm-^h_+3^MZzDy=_o;gpa(`V_kP$)DE4HZQhD1%5OGLDSH;qWLtDwoR-<%de8a$mVG zl}gv8>teAuEl%yeeLfzKNAqZIxBJoksH*CbdQ`9159^1qSgaXqMx)V2w2??8nu%sS z9&f~7`KeT@ooXkO$&2I#_*bzj@Gqm6e9p7ktTk(`*T=tFEA}ot?{GY={A#s&Ts^k< zYmWT1=G1DPPOZZ^Tluo>zc$~_w?9|5aX#XE4OsJ+0q#Q&0QaE>0P7Dx4*>K4Ko7t> z^x%7k9v}(m0e}Vo=mD_%_W3{$0Q3OZ=k{?uK+i47)PuvZ-lJ{)>;3vaf14h*^|a^T z(%;U1yPw3usiJjG@SW#(r;A(C*~KBinDQ_)y6*OP@r6jb_00rzKWa)ylttO$E(&aC zV)WIt&v+J5l1f${@h_cdtgw97$p1!MMxEIa^50>nW_<+y3yY0DDwPZyGWbL}Dw^^0 zU)E2h@e8*k3ZlS%3}lFy1ZW+R=!B729vt>sI6nt$ESDNTM_0bqw`$DJ=W}py&KmVi ztF3BQopD)D>%YuegVk6+E5@t`i^T%Z*ZOUlXo&F*qu?OYFg6jyTYVzIyf&+d@%6f3 LjAe)YxzXbvtHKVD literal 0 HcmV?d00001 diff --git a/tests/game-tables/mag-metadata-table-dc-v2.expected.bin b/tests/game-tables/mag-metadata-table-dc-v2.expected.bin new file mode 100644 index 0000000000000000000000000000000000000000..57dbb0723a50b0dcdaf27bf51bf8a1a590138053 GIT binary patch literal 2080 zcmb_dw{jaX6nqyL#Y_%^n3G85NM$iAQykg9;2C{`3m1}0k4rcD3zhx=7cMxiT&Q&E zLWL`}=LNtcLCN%pWA7377Qo&+0Ji|Wzlby<`buw67_O_mUhjZhL9?y~I$Y!(6+2*WP>#TJaiRNiuQIrK`A(cw4rdE^5*e?AlIH*NR~(ldGM7Cd<|2RV zNxATb$n%=xIhVcaZ?EN$N6?#PPzRh`DOj2T=u;DtlTa*)_HJt znf@8h_qqP>nwR@Fffs*Q&2v{|6?dymL^9YVpdj>Z+;1@qyTgeSM>EVb$YZ$B=k=+& zs$1+#<_`oz138G9Ijb;th3I`h-e4R=QOcR^sQ)yGnqJnv&)XkR&!eBk2HL+Mw)_1J z=Woq7wSjP@@(i*Y&&3H8GJl`d;c!zwXDyqVM48%7o zDcH}bsa6DywL>G%(J-)9EInPICN3`x zj#bs`RfkxX<+j{zwOaeFeV@;_=i9T}?UVLNP17c{2`n`QQ<5Z2OVgQ5W+AhXPN(P7 z^SNAZJGY(9X1B6iyr!Zkx}tMDHs7fk2=hsQdkX!*7H_p=PKV z3=x;cYNUSB+;_>)ud=>c{kqzXphu8U@JDtu-XXWvJ zJfpj!v+%ghb~3`{a(S*iXYn67>d7N#e0+0re3NsY<*UM40gHU`xvIeVzxV}{Qzjx7 zdw`!seAoYqd2jGKFPZ#_`Ps#u;heuYuecxa4#oE(-Y5TG;2Be-{5j&R*|`TM4K5NI zd5A6JaJsNd6w~S(pXtGrKOn2JYI6`P7z#%$Hd(8(iA)@<-&}4VX7Up51t9WaXwPNl z#|u^*ee(xE)6e2t6gPhY6oI(2mv8%Z}#VUqXns9zzu$odwZKK`*sBcg|1K7UPbC`Su2|l4(!-|irR!8VSICN3`x zj#bs`RfkxX<+j{zwOaeFeV@;_=i9T}?UVLNP17c{2`n`QQ<5Z2OVgQ5W+AhXPN(P7 z^SNAZJGY(9X1B6iyr!Zkx}tMDHs7fk2=hsQdkX!*7H_p=PKV z3=x;cYNUSB+;_>)ud=>c{kqzXphu8U@JDtu-XXWvJ zJfpj!v+%ghb~3`{a(S*iXYn67>d7N#e0+0re3NsY<*UM40gHU`xvIeVzxV}{Qzjx7 zdw`!seAoYqd2jGKFPZ#_`Ps#u;heuYuecxa4#oE(-Y5TG;2Be-{5j&R*|`TM4K5NI zd5A6JaJsNd6w~S(pXtGrKOn2JYI6`P7z#%$Hd(8(iA)@<-&}4VX7Up51t9WaXwPNl z#|u^*ee(xE)6e2t6gPhY6oI(2mv8%Z}#VUqXns9zzu$odwZKK`*sBcg|1K7UPbC`Su2|l4(!-|irR!8VSx`FwsizsqYXiqcRToKH?p1OpS9OlCE+nog%z(ktO`xD{?0hS4;d(P*?2?L;Dx zcBEY{mru*5l}hELa#AXl4oU~bVsXE?FLH4`KA-R0ckcCi&%9@rWi40>wOVbyHgB3{ z-K@uAv9;J*B9W*k>hXAdE&hO~QmM_z4hV#1O|IW zpM~c=o{IsmR;!EEMOQ!6s24-c)YQ(-)DG8-)T_c=fs1jpi z9Q!;t zyIlVapZBT$@0#cP7QdSzME=U_iFZxsJz~>~Lqc$D>||`)>+|EpQEc}N3fTdS8DUwK zRgag-BGH&Rkb}6DixP8}`PPXyGV3QxZXSL62O%AU<#%b`{z*vLiEZTV&xGtd<87+{ zhCZ)jm3RzOJ&-Fp{hNE%w>r=QR*QatezHQN{l&g-@p_ju+8;3{OR_}&Cj)sfj!j`M)zWd=1~o8Oti|Sw zIjo~`dwWaubm904IUaKrX_ek^e*zRCp7&@U2+?pZXxJGIZ$p1WM?^@kh(z9@xtBP| Sxc(i1o-O>%5d9PQ0KWk<4C9Ib literal 0 HcmV?d00001 diff --git a/tests/game-tables/mag-metadata-table-gc-v3.expected.bin b/tests/game-tables/mag-metadata-table-gc-v3.expected.bin new file mode 100644 index 0000000000000000000000000000000000000000..9ee14b84e2582694986ebad653fba70a93c13194 GIT binary patch literal 1664 zcmb_cw{9Cj5SICN3`x zj#bs`RfkxX<+j{zwOaeFeV@;_=i9T}?UVLNP17c{2`n`QQ<5Z2OVgQ5W+AhXPN(P7 z^SNAZJGY(9X1B6iyr!Zkx}tMDHs7fk2=hsQdkX!*7H_p=PKV z3=x;cYNUSB+;_>)ud=>c{kqzXphu8U@JDtu-XXWvJ zJfpj!v+%ghb~3`{a(S*iXYn67>d7N#e0+0re3NsY<*UM40gHU`xvIeVzxV}{Qzjx7 zdw`!seAoYqd2jGKFPZ#_`Ps#u;heuYuecxa4#oE(-Y5TG;2Be-{5j&R*|`TM4K5NI zd5A6JaJsNd6w~S(pXtGrKOn2JYI6`P7z#%$Hd(8(iA)@<-&}4VX7Up51t9WaXwPNl z#|u^*ee(xE)6e2t6gPhY6oI(2mv8%Z}#VUqXns9zzu$odwZKK`*sBcg|1K7UPbC`Su2|l4(!-|irR!8VS9?y~I$Y!(6+2*WP>#TJaiRNiuQIrK`A(cw4rdE^5*e?AlIH*NR~(ldGM7Cd<|2RV zNxATb$n%=xIhVcaZ?EN$N6?#PPzRh`DOj2T=u;DtlTa*)_HJt znf@8h_qqP>nwR@Fffs*Q&2v{|6?dymL^9YVpdj>Z+;1@qyTgeSM>EVb$YZ$B=k=+& zs$1+#<_`oz138G9Ijb;th3I`h-e4R=QOcR^sQ)yGnqJnv&)XkR&!eBk2HL+Mw)_1J z=Woq7wSjP@@(i*Y&&3H8GJl`d;c!zwXDyqVM48%7o zDcH}bsa6DywL>G%(J-)9EInP9?y~I$Y!(6+2*WP>#TJaiRNiuQIrK`A(cw4rdE^5*e?AlIH*NR~(ldGM7Cd<|2RV zNxATb$n%=xIhVcaZ?EN$N6?#PPzRh`DOj2T=u;DtlTa*)_HJt znf@8h_qqP>nwR@Fffs*Q&2v{|6?dymL^9YVpdj>Z+;1@qyTgeSM>EVb$YZ$B=k=+& zs$1+#<_`oz138G9Ijb;th3I`h-e4R=QOcR^sQ)yGnqJnv&)XkR&!eBk2HL+Mw)_1J z=Woq7wSjP@@(i*Y&&3H8GJl`d;c!zwXDyqVM48%7o zDcH}bsa6DywL>G%(J-)9EInP6!Asg^7sCH%8jX}B97pT_ZP;oa=*a=7$90GI%v2X9eHy48NaUjY|@!NlRF z!EH@*yS1UMs%lGZHJi=D=Ap;qIq)1{&PPfaMNF-JhtMPbzCBEYG`D(tJ*Xz~2dLR&J z1R8$7zwWQ+a=GK&aXz0v${%I3+5PN(CX?CA?8&zLK6bmkZExFbwiDY)sZ?4hEfkBz z`Qm&i6e@?x!C-JLxE6^-%8_z799|3mV#i{!&Ddr%8r_I)Ab&fwjr^_P7JuhXr?cK! zAD@qFbXK$%9ygm$M|Po5SS&0G{+OekjyY3PJ3CW5obyM%COs?JGGAU-lQ{p^e!=97 ziEPU~!1p45*Z*qs-r#j!GWp%+dzX8LbN*((^83hVD1R^VdGg;y0yjy@*O6z7m3v^& z;G!U?LtB8&?!YcF8KQ4Ih6__(pQ@>v*+wjXAQ%#CLQ&a3CJxqb4yOk*83kVjLhxaT z7b^Kt$ci}n-wl9h z_Z({$00*o9;jQs#)L6YUApD5+Kvh(QJ|qBaR`5bWL$x57D1sb$*M@Q7Ja*fZpliag=N!)yKKW}W4+j^69_DyVGz!C+7oO7#YV_e}5ZUNJuR z2i0D$#eAwq{OjxMD&Ub~S95u8YZ%sO!uihvHT-jEq28jt(EvW9elyc5T)u(=pHRgR Rae>qUHgs46BBs%o