From 2ed97974e01fe2732e87db78d2d2c7e5d9965ffc Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 11 May 2024 22:31:09 -0700 Subject: [PATCH] add CallProtectedHandler on BB --- src/ReceiveSubcommands.cc | 15 +++----- src/SendCommands.cc | 7 ++-- .../CallProtectedHandler.4OEU.patch.s | 4 +-- .../CallProtectedHandler.59NL.patch.s | 36 +++++++++++++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 system/client-functions/CallProtectedHandler/CallProtectedHandler.59NL.patch.s diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 0f55a4f2..9a4dca84 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -1422,17 +1422,10 @@ static void on_player_revivable(shared_ptr c, uint8_t command, uint8_t f 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)); - } - } + // TODO: We might need to send different versions of the command here to + // different clients in certain crossplay scenarios, so just using + // echo_to_lobby would not suffice. Figure out a way to handle this. + send_protected_command(c, c_data, sizeof(v3_cmd), true); } } diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 29ffa454..1bf4f650 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -508,7 +508,8 @@ bool send_protected_command(std::shared_ptr c, const void* data, size_t case Version::GC_V3: case Version::XB_V3: case Version::GC_EP3_NTE: - case Version::GC_EP3: { + case Version::GC_EP3: + case Version::BB_V4: { auto s = c->require_server_state(); if (!s->enable_v3_v4_protected_subcommands || c->config.check_flag(Client::Flag::NO_SEND_FUNCTION_CALL) || @@ -2489,9 +2490,7 @@ void send_remove_conditions(shared_ptr c) { cmd.unknown_a1 = z; cmd.unknown_a2 = 0; } - if (send_protected_command(c, &cmds, sizeof(cmds), true)) { - send_command_excluding_client(c->require_lobby(), c, 0x60, 0x00, &cmds, sizeof(cmds)); - } + send_protected_command(c, &cmds, sizeof(cmds), true); } void send_remove_conditions(Channel& ch, uint16_t client_id) { diff --git a/system/client-functions/CallProtectedHandler/CallProtectedHandler.4OEU.patch.s b/system/client-functions/CallProtectedHandler/CallProtectedHandler.4OEU.patch.s index 40d11b07..a09729c8 100644 --- a/system/client-functions/CallProtectedHandler/CallProtectedHandler.4OEU.patch.s +++ b/system/client-functions/CallProtectedHandler/CallProtectedHandler.4OEU.patch.s @@ -7,8 +7,8 @@ reloc0: .offsetof start start: .include CallProtectedHandlerXB - .data 0x007237E8 - .data 0x002DE000 + .data 0x007237E8 # should_allow_protected_commands + .data 0x002DE000 # handle_6x(void* data @ ecx, uint32_t size @ eax) size: .data 0x00000000 data: diff --git a/system/client-functions/CallProtectedHandler/CallProtectedHandler.59NL.patch.s b/system/client-functions/CallProtectedHandler/CallProtectedHandler.59NL.patch.s new file mode 100644 index 00000000..2329293b --- /dev/null +++ b/system/client-functions/CallProtectedHandler/CallProtectedHandler.59NL.patch.s @@ -0,0 +1,36 @@ +.meta hide_from_patches_menu +.meta name="CallProtectedHandler" +.meta description="" + +entry_ptr: +reloc0: + .offsetof start +start: + jmp get_data_addr +resume: + xchg ebx, [esp] + + mov edx, [ebx] + mov dword [edx], 1 + + mov edx, [ebx + 4] + push dword [ebx + 8] + lea ecx, [ebx + 0x0C] + push ecx + call edx # RcvPsoData2(data, size) + add esp, 8 + + mov edx, [ebx] + mov dword [edx], 0 + + pop ebx + ret + +get_data_addr: + call resume + + .data 0x00AAECF0 # should_allow_protected_commands + .data 0x00800860 # RcvPsoData2(void* data @ stack, uint32_t size @ stack) +size: + .data 0x00000000 +data: