From 6d73cae91b33604cbe5e1d9d97677b6c7201e0de Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 28 Mar 2024 22:50:57 -0700 Subject: [PATCH] fix desyncs if protected commands aren't supported by client --- src/ReceiveSubcommands.cc | 25 ++++++++++++++----------- src/SendCommands.cc | 4 +++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 9c17fdaa..92a13750 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -1418,17 +1418,20 @@ static void on_player_revivable(shared_ptr c, uint8_t command, uint8_t f if (player_cheats_enabled && c->config.check_flag(Client::Flag::INFINITE_HP_ENABLED)) { G_UseMedicalCenter_6x31 v2_cmd = {0x31, 0x01, c->lobby_client_id}; G_RevivePlayer_V3_BB_6xA1 v3_cmd = {0xA1, 0x01, c->lobby_client_id}; - for (auto lc : l->clients) { - if (!lc) { - continue; - } - bool use_v3 = !is_v1_or_v2(lc->version()) || (lc->version() == Version::GC_NTE); - const void* data = use_v3 ? static_cast(&v3_cmd) : static_cast(&v2_cmd); - size_t size = use_v3 ? sizeof(v3_cmd) : sizeof(v2_cmd); - if (lc == c) { - send_protected_command(lc, data, size, false); - } else { - send_command(lc, 0x60, 0x00, data, size); + static_assert(sizeof(v2_cmd) == sizeof(v3_cmd), "Command sizes do not match"); + + const void* c_data = (!is_v1_or_v2(c->version()) || (c->version() == Version::GC_NTE)) + ? static_cast(&v3_cmd) + : static_cast(&v2_cmd); + if (send_protected_command(c, c_data, sizeof(v3_cmd), false)) { + for (auto lc : l->clients) { + if (!lc || (lc == c)) { + continue; + } + const void* lc_data = (!is_v1_or_v2(lc->version()) || (lc->version() == Version::GC_NTE)) + ? static_cast(&v3_cmd) + : static_cast(&v2_cmd); + send_command(lc, 0x60, 0x00, lc_data, sizeof(v3_cmd)); } } } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 50e8972a..70ca9b23 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -2417,7 +2417,9 @@ void send_remove_conditions(shared_ptr c) { cmd.unknown_a1 = z; cmd.unknown_a2 = 0; } - send_protected_command(c, &cmds, sizeof(cmds), true); + if (send_protected_command(c, &cmds, sizeof(cmds), true)) { + send_command_excluding_client(c->require_lobby(), c, 0x60, 0x00, &cmds, sizeof(cmds)); + } } void send_remove_conditions(Channel& ch, uint16_t client_id) {