From 4830f5a41eb352802b062d57267cd695128b24ff Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 30 Jan 2024 21:10:50 -0800 Subject: [PATCH] fix battle area number normalization and add more structs/enums --- src/CommandFormats.hh | 47 ++++++++++++++++++++------------ src/ItemCreator.cc | 2 +- src/PlayerSubordinates.cc | 28 ++++++++++++++++++- src/PlayerSubordinates.hh | 8 ++++-- system/quests/battle/b88001.json | 2 +- system/quests/battle/b88002.json | 2 +- system/quests/battle/b88003.json | 2 +- system/quests/battle/b88004.json | 2 +- system/quests/battle/b88005.json | 2 +- system/quests/battle/b88006.json | 2 +- system/quests/battle/b88007.json | 2 +- system/quests/battle/b88008.json | 2 +- 12 files changed, 72 insertions(+), 29 deletions(-) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index f1c8d117..832fa1bf 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -4531,19 +4531,21 @@ struct G_DropItem_PC_V3_BB_6x5F : G_DropItem_DC_6x5F { // 6x60: Request for item drop (handled by the server on BB) struct G_StandardDropItemRequest_DC_6x60 { - G_UnusedHeader header; - uint8_t floor = 0; - uint8_t rt_index = 0; - le_uint16_t entity_id = 0; - le_float x = 0.0f; - le_float z = 0.0f; - le_uint16_t section = 0; - le_uint16_t ignore_def = 0; + /* 00 */ G_UnusedHeader header; + /* 04 */ uint8_t floor = 0; + /* 05 */ uint8_t rt_index = 0; + /* 06 */ le_uint16_t entity_id = 0; + /* 08 */ le_float x = 0.0f; + /* 0C */ le_float z = 0.0f; + /* 10 */ le_uint16_t section = 0; + /* 12 */ le_uint16_t ignore_def = 0; + /* 14 */ } __packed__; struct G_StandardDropItemRequest_PC_V3_BB_6x60 : G_StandardDropItemRequest_DC_6x60 { - uint8_t effective_area = 0; - parray unused; + /* 14 */ uint8_t effective_area = 0; + /* 15 */ parray unused; + /* 18 */ } __packed__; // 6x61: Activate MAG effect @@ -5013,9 +5015,19 @@ struct G_SetChallengeModeData_6x7C { struct G_SetBattleModeData_6x7D { G_UnusedHeader header; - uint8_t unknown_a1 = 0; // Must be < 7; used in jump table - parray unused; - parray unknown_a2; + // Values for what (0-6; values 7 and above are not valid): + // 0 = Unknown (params[0] and [1] are used) + // 1 = Does nothing + // 2 = Unknown (no params are used) + // 3 = Set player meseta score (params[0] = client ID, [1] = score) + // 4 = Unknown (params[0] = client ID) + // 5 = Unknown (no params are used) + // 6 = Unknown (all params are used) + uint8_t what = 0; + uint8_t unknown_a1 = 0; // Only used when what == 0 + uint8_t unused = 0; + uint8_t is_alive = 0; // Only used when what == 3 + parray params; } __packed__; // 6x7E: Unknown (not valid on Episode 3) @@ -5302,10 +5314,11 @@ struct G_Unknown_6xA1 { // server on BB) struct G_SpecializableItemDropRequest_6xA2 : G_StandardDropItemRequest_PC_V3_BB_6x60 { - le_float param3 = 0.0f; - le_uint32_t param4 = 0; - le_uint32_t param5 = 0; - le_uint32_t param6 = 0; + /* 18 */ le_float param3 = 0.0f; + /* 1C */ le_uint32_t param4 = 0; + /* 20 */ le_uint32_t param5 = 0; + /* 24 */ le_uint32_t param6 = 0; + /* 28 */ } __packed__; // 6xA3: Olga Flow boss actions (not valid on pre-V3 or Episode 3) diff --git a/src/ItemCreator.cc b/src/ItemCreator.cc index 88b7f8b1..f9abfc24 100644 --- a/src/ItemCreator.cc +++ b/src/ItemCreator.cc @@ -117,7 +117,7 @@ uint8_t ItemCreator::normalize_area_number(uint8_t area) const { } } else { - return this->restrictions->box_drop_area; + return this->restrictions->box_drop_area - 1; } } diff --git a/src/PlayerSubordinates.cc b/src/PlayerSubordinates.cc index a24e0564..2783906f 100644 --- a/src/PlayerSubordinates.cc +++ b/src/PlayerSubordinates.cc @@ -715,7 +715,7 @@ BattleRules::BattleRules(const JSON& json) { this->tool_mode = json.get_enum("ToolMode", this->tool_mode); this->trap_mode = json.get_enum("TrapMode", this->trap_mode); this->unused_F817 = json.get_int("UnusedF817", this->unused_F817); - this->respawn_mode = json.get_int("RespawnMode", this->respawn_mode); + this->respawn_mode = json.get_enum("RespawnMode", this->respawn_mode); this->replace_char = json.get_int("ReplaceChar", this->replace_char); this->drop_weapon = json.get_int("DropWeapon", this->drop_weapon); this->is_teams = json.get_int("IsTeams", this->is_teams); @@ -917,6 +917,32 @@ BattleRules::MesetaMode enum_for_name(const char* name) } } +template <> +const char* name_for_enum(BattleRules::RespawnMode v) { + switch (v) { + case BattleRules::RespawnMode::ALLOW: + return "ALLOW"; + case BattleRules::RespawnMode::FORBID: + return "FORBID"; + case BattleRules::RespawnMode::LIMIT_LIVES: + return "LIMIT_LIVES"; + default: + throw invalid_argument("invalid BattleRules::MesetaDropMode value"); + } +} +template <> +BattleRules::RespawnMode enum_for_name(const char* name) { + if (!strcmp(name, "ALLOW")) { + return BattleRules::RespawnMode::ALLOW; + } else if (!strcmp(name, "FORBID")) { + return BattleRules::RespawnMode::FORBID; + } else if (!strcmp(name, "LIMIT_LIVES")) { + return BattleRules::RespawnMode::LIMIT_LIVES; + } else { + throw invalid_argument("invalid BattleRules::MesetaDropMode name"); + } +} + static PlayerInventoryItem make_template_item(bool equipped, uint64_t first_data, uint64_t second_data) { return PlayerInventoryItem(ItemData(first_data, second_data), equipped); } diff --git a/src/PlayerSubordinates.hh b/src/PlayerSubordinates.hh index 11bf4a44..77f20655 100644 --- a/src/PlayerSubordinates.hh +++ b/src/PlayerSubordinates.hh @@ -577,6 +577,11 @@ struct BattleRules { FORBID_ALL = 1, CLEAR_AND_ALLOW = 2, }; + enum class RespawnMode : uint8_t { + ALLOW = 0, + FORBID = 1, + LIMIT_LIVES = 2, + }; // Set by quest opcode F812, but values are remapped. // F812 00 => FORBID_ALL @@ -608,8 +613,7 @@ struct BattleRules { // F818 00 => 01 // F818 01 => 00 // F818 02 => 02 - // TODO: Define an enum class for this field. - /* 06 */ uint8_t respawn_mode = 0; + /* 06 */ RespawnMode respawn_mode = RespawnMode::ALLOW; // Set by quest opcode F819. /* 07 */ uint8_t replace_char = 0; // Set by quest opcode F81A, but value is inverted. diff --git a/system/quests/battle/b88001.json b/system/quests/battle/b88001.json index 7811fb9a..bc35cd74 100644 --- a/system/quests/battle/b88001.json +++ b/system/quests/battle/b88001.json @@ -10,7 +10,7 @@ "MagMode": "ALLOW", "ToolMode": "ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 0, + "RespawnMode": "ALLOW", "ReplaceChar": 0, "DropWeapon": 1, "IsTeams": 1, diff --git a/system/quests/battle/b88002.json b/system/quests/battle/b88002.json index 2f325969..7f170aca 100644 --- a/system/quests/battle/b88002.json +++ b/system/quests/battle/b88002.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 0, + "RespawnMode": "ALLOW", "ReplaceChar": 1, "DropWeapon": 1, "IsTeams": 0, diff --git a/system/quests/battle/b88003.json b/system/quests/battle/b88003.json index e9eb5b01..bc08153d 100644 --- a/system/quests/battle/b88003.json +++ b/system/quests/battle/b88003.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 2, + "RespawnMode": "LIMIT_LIVES", "ReplaceChar": 1, "DropWeapon": 0, "IsTeams": 0, diff --git a/system/quests/battle/b88004.json b/system/quests/battle/b88004.json index 145b0fce..245e6fcc 100644 --- a/system/quests/battle/b88004.json +++ b/system/quests/battle/b88004.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 2, + "RespawnMode": "LIMIT_LIVES", "ReplaceChar": 1, "DropWeapon": 1, "IsTeams": 0, diff --git a/system/quests/battle/b88005.json b/system/quests/battle/b88005.json index eb27be15..051168ae 100644 --- a/system/quests/battle/b88005.json +++ b/system/quests/battle/b88005.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 1, + "RespawnMode": "FORBID", "ReplaceChar": 0, "DropWeapon": 1, "IsTeams": 1, diff --git a/system/quests/battle/b88006.json b/system/quests/battle/b88006.json index 2efd38ed..41d5b3e3 100644 --- a/system/quests/battle/b88006.json +++ b/system/quests/battle/b88006.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 2, + "RespawnMode": "LIMIT_LIVES", "ReplaceChar": 1, "DropWeapon": 1, "IsTeams": 1, diff --git a/system/quests/battle/b88007.json b/system/quests/battle/b88007.json index ee2473df..da53e917 100644 --- a/system/quests/battle/b88007.json +++ b/system/quests/battle/b88007.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 2, + "RespawnMode": "LIMIT_LIVES", "ReplaceChar": 1, "DropWeapon": 1, "IsTeams": 0, diff --git a/system/quests/battle/b88008.json b/system/quests/battle/b88008.json index 07cc2881..1e37f1be 100644 --- a/system/quests/battle/b88008.json +++ b/system/quests/battle/b88008.json @@ -5,7 +5,7 @@ "MagMode": "FORBID_ALL", "ToolMode": "CLEAR_AND_ALLOW", "TrapMode": "ALL_PLAYERS", - "RespawnMode": 2, + "RespawnMode": "LIMIT_LIVES", "ReplaceChar": 1, "DropWeapon": 0, "IsTeams": 0,