From 3342d663f6e32e2cec0e225200c1c95134d2c8c4 Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 20 Feb 2024 20:26:12 +0100 Subject: [PATCH] RECEIVED_CLONE_REMOVE player ped removal protection (#2732) --- src/function_types.hpp | 2 ++ src/gta_pointers.hpp | 2 ++ src/hooking/hooking.cpp | 2 ++ src/hooking/hooking.hpp | 4 +++- src/hooks/protections/received_clone_remove.cpp | 16 ++++++++++++++++ src/pointers.cpp | 9 +++++++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/hooks/protections/received_clone_remove.cpp diff --git a/src/function_types.hpp b/src/function_types.hpp index cecba6a4..234643a8 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -208,4 +208,6 @@ namespace big::functions using remove_player_from_sender_list = bool (*)(void* list, uint64_t* rockstar_id); using get_ped_seat = CGetPedSeatReturnClass*(*)(PVOID seat_info, CPed* ped); + + using received_clone_remove = void (*)(CNetworkObjectMgr*, CNetGamePlayer*, CNetGamePlayer*, int16_t, uint32_t); } diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index f99c9c49..e6aec9f4 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -360,6 +360,8 @@ namespace big bool* m_is_social_club_overlay_active; functions::get_ped_seat m_get_ped_seat; + + functions::received_clone_remove m_received_clone_remove; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/hooking/hooking.cpp b/src/hooking/hooking.cpp index 3ed5ce35..d3537f1a 100644 --- a/src/hooking/hooking.cpp +++ b/src/hooking/hooking.cpp @@ -138,6 +138,8 @@ namespace big detour_hook_helper::add("RBS", g_pointers->m_gta.m_read_bits_single); + detour_hook_helper::add("RCR", g_pointers->m_gta.m_received_clone_remove); + g_hooking = this; } diff --git a/src/hooking/hooking.hpp b/src/hooking/hooking.hpp index 92b14f9b..9587f0ac 100644 --- a/src/hooking/hooking.hpp +++ b/src/hooking/hooking.hpp @@ -1,10 +1,10 @@ #pragma once #include "MinHook.h" - #include "detour_hook.hpp" #include "vmt_hook.hpp" #include "vtable_hook.hpp" +#include #include // cannot stub this class CPlayerGamerDataNode; @@ -176,6 +176,8 @@ namespace big static bool read_bits_single(void* data, int* out_value, int size, int offset); + static void received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token); + static bool sync_reader_serialize_dword(void* _this, uint32_t* dword, int size); static bool sync_reader_serialize_word(void* _this, uint16_t* word, int size); static bool sync_reader_serialize_byte(void* _this, uint8_t* byte, int size); diff --git a/src/hooks/protections/received_clone_remove.cpp b/src/hooks/protections/received_clone_remove.cpp new file mode 100644 index 00000000..e7d4ab23 --- /dev/null +++ b/src/hooks/protections/received_clone_remove.cpp @@ -0,0 +1,16 @@ +#include "hooking/hooking.hpp" +#include "util/notify.hpp" + +namespace big +{ + void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token) + { + if (dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) + { + notify::crash_blocked(src, "player ped removal"); + return; + } + + g_hooking->get_original()(mgr, src, dst, object_id, ownership_token); + } +} \ No newline at end of file diff --git a/src/pointers.cpp b/src/pointers.cpp index 73d40d5c..7f783bfe 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1754,6 +1754,15 @@ namespace big { g_pointers->m_gta.m_get_ped_seat = ptr.add(1).rip().as(); } + }, + // RECEIVED_CLONE_REMOVE + { + "RCR", + "48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 48 89 78 20 41 54 41 56 41 57 48 83 EC 50 4C 8B F2 4D 8B E0", + [](memory::handle ptr) + { + g_pointers->m_gta.m_received_clone_remove = ptr.as(); + } } >(); // don't leave a trailing comma at the end