From 8165f240dc5141c937c43d2077d4318d6a03a724 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Fri, 9 Feb 2024 00:40:12 -0800 Subject: [PATCH] don't expect mask_key from Ep3 NTE --- src/CommandFormats.hh | 11 ++++++----- src/Episode3/Server.cc | 18 ++++++++++++++---- src/ReceiveSubcommands.cc | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index 35ebcbf7..a6826c0e 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -6336,11 +6336,12 @@ struct G_SetMapState_Ep3_CAx13 { // 6xB3x14 / CAx14: Set player deck during setup struct G_SetPlayerDeck_Ep3_CAx14 { - G_CardServerDataCommandHeader header = {0xB3, sizeof(G_SetPlayerDeck_Ep3_CAx14) / 4, 0, 0x14, 0, 0, 0, 0, 0}; - le_uint16_t client_id = 0; - uint8_t is_cpu_player = 0; - uint8_t unused2 = 0; - Episode3::DeckEntry entry; + /* 00 */ G_CardServerDataCommandHeader header = {0xB3, sizeof(G_SetPlayerDeck_Ep3_CAx14) / 4, 0, 0x14, 0, 0, 0, 0, 0}; + /* 10 */ le_uint16_t client_id = 0; + /* 12 */ uint8_t is_cpu_player = 0; + /* 13 */ uint8_t unused2 = 0; + /* 14 */ Episode3::DeckEntry entry; + /* 6C */ } __packed__; // 6xB3x15 / CAx15: Hard-reset server state diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index c46b9220..d6fcabad 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -1692,18 +1692,23 @@ void Server::update_battle_state_flags_and_send_6xB4x03_if_needed(bool always_se bool Server::update_registration_phase() { // Returns true if the battle can begin + auto log = this->log_stack("update_registration_phase: "); + if (this->setup_phase != SetupPhase::REGISTRATION) { + log.debug("setup_phase is not REGISTRATION"); return false; } if (this->map_and_rules->num_players == 0) { this->registration_phase = RegistrationPhase::AWAITING_NUM_PLAYERS; + log.debug("registration_phase set to AWAITING_NUM_PLAYERS"); this->update_battle_state_flags_and_send_6xB4x03_if_needed(); return false; } if (this->map_and_rules->num_players != this->num_clients_present) { this->registration_phase = RegistrationPhase::AWAITING_PLAYERS; + log.debug("registration_phase set to AWAITING_PLAYERS"); this->update_battle_state_flags_and_send_6xB4x03_if_needed(); return false; } @@ -1717,12 +1722,14 @@ bool Server::update_registration_phase() { if (num_team0_registered_players != this->map_and_rules->num_team0_players) { this->registration_phase = RegistrationPhase::AWAITING_DECKS; + log.debug("registration_phase set to AWAITING_DECKS"); this->update_battle_state_flags_and_send_6xB4x03_if_needed(); return false; } this->registration_phase = RegistrationPhase::REGISTERED; this->update_battle_state_flags_and_send_6xB4x03_if_needed(); + log.debug("battle can begin"); return true; } @@ -1768,10 +1775,13 @@ void Server::on_server_data_input(shared_ptr sender_c, const string& dat throw runtime_error("unknown CAx subsubcommand"); } - string unmasked_data = data; - set_mask_for_ep3_game_command(unmasked_data.data(), unmasked_data.size(), 0); - - (this->*handler)(sender_c, unmasked_data); + if (this->options.is_trial() || !header.mask_key) { + (this->*handler)(sender_c, data); + } else { + string unmasked_data = data; + set_mask_for_ep3_game_command(unmasked_data.data(), unmasked_data.size(), 0); + (this->*handler)(sender_c, unmasked_data); + } } void Server::handle_CAx0B_mulligan_hand(shared_ptr, const string& data) { diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 86792bcc..74f87a00 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -960,7 +960,7 @@ static void on_ep3_battle_subs(shared_ptr c, uint8_t command, uint8_t fl } } - if (!(s->ep3_behavior_flags & Episode3::BehaviorFlag::DISABLE_MASKING)) { + if (!(s->ep3_behavior_flags & Episode3::BehaviorFlag::DISABLE_MASKING) && (c->version() != Version::GC_EP3_NTE)) { set_mask_for_ep3_game_command(data.data(), data.size(), (random_object() % 0xFF) + 1); }