From e29231356bbaefb754633ba44d9815589b1834fd Mon Sep 17 00:00:00 2001 From: James Osborne Date: Sat, 16 May 2026 03:13:58 -0400 Subject: [PATCH] Resend Dreamcast V2 patches after floor changes --- src/ReceiveSubcommands.cc | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 80a9676f..25208350 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -78,6 +79,42 @@ using SDF = SubcommandDefinition::Flag; extern const vector subcommand_definitions; +static asio::awaitable resend_selected_patch_menu_functions_after_dc_floor_load( + shared_ptr c, + const char* reason) { + if (c->version() != Version::DC_V2) { + co_return; + } + + auto l = c->lobby.lock(); + if (!l || !l->is_game()) { + co_return; + } + + if (!c->login || !c->login->account || + !c->check_flag(Client::Flag::HAS_SEND_FUNCTION_CALL) || + !c->check_flag(Client::Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE) || + c->login->account->auto_patches_enabled.empty()) { + co_return; + } + + auto s = c->require_server_state(); + unordered_set> functions_to_send; + for (const auto& patch_name : c->login->account->auto_patches_enabled) { + try { + functions_to_send.emplace(s->client_functions->get(patch_name, c->specific_version)); + } catch (const out_of_range&) { + c->log.warning_f("Client has selected patch {} enabled, but it is not available for specific_version {}", + patch_name, str_for_specific_version(c->specific_version)); + } + } + + if (!functions_to_send.empty()) { + c->log.info_f("Resending {} selected patch-menu function(s) after {}", functions_to_send.size(), reason); + co_await send_function_call_multi(c, functions_to_send); + } +} + static string json_escape_for_hardcore_ledger(const string& text) { @@ -1810,6 +1847,7 @@ static asio::awaitable on_change_floor_6x1F(shared_ptr c, Subcomma } } forward_subcommand(c, msg); + co_await resend_selected_patch_menu_functions_after_dc_floor_load(c, "6x1F floor command"); co_return; } @@ -1819,6 +1857,7 @@ static asio::awaitable on_change_floor_6x21(shared_ptr c, Subcomma c->floor = cmd.floor; } forward_subcommand(c, msg); + co_await resend_selected_patch_menu_functions_after_dc_floor_load(c, "6x21 floor command"); co_return; } @@ -2104,10 +2143,15 @@ static asio::awaitable on_movement_xz_with_floor(shared_ptr c, Sub } c->pos.x = cmd.pos.x; c->pos.z = cmd.pos.z; + bool floor_changed = false; if (cmd.floor >= 0 && c->floor != static_cast(cmd.floor)) { c->floor = cmd.floor; + floor_changed = true; } forward_subcommand(c, msg); + if (floor_changed) { + co_await resend_selected_patch_menu_functions_after_dc_floor_load(c, "movement floor change"); + } } template @@ -2117,10 +2161,15 @@ static asio::awaitable on_movement_xyz_with_floor(shared_ptr c, Su co_return; } c->pos = cmd.pos; + bool floor_changed = false; if (cmd.floor >= 0 && c->floor != static_cast(cmd.floor)) { c->floor = cmd.floor; + floor_changed = true; } forward_subcommand(c, msg); + if (floor_changed) { + co_await resend_selected_patch_menu_functions_after_dc_floor_load(c, "movement floor change"); + } } static asio::awaitable on_set_animation_state(shared_ptr c, SubcommandMessage& msg) {