From ccda1feae42f199adff7f79334e0324dac1e39fb Mon Sep 17 00:00:00 2001 From: Yimura Date: Sun, 7 Feb 2021 17:08:25 +0100 Subject: [PATCH] wip(Hooks): Received event protections --- BigBaseV2/src/function_types.hpp | 7 ++- BigBaseV2/src/gta/net_game_event.hpp | 4 +- BigBaseV2/src/hooking.cpp | 15 +++-- BigBaseV2/src/hooking.hpp | 8 ++- BigBaseV2/src/hooks/get_event_data.cpp | 2 +- BigBaseV2/src/hooks/get_label_text.cpp | 2 +- BigBaseV2/src/hooks/received_event.cpp | 62 +++++++++++++++++++ .../src/hooks/send_net_info_to_lobby.cpp | 2 - BigBaseV2/src/pointers.cpp | 15 +++++ BigBaseV2/src/pointers.hpp | 3 + 10 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 BigBaseV2/src/hooks/received_event.cpp diff --git a/BigBaseV2/src/function_types.hpp b/BigBaseV2/src/function_types.hpp index c8e1b039..e2854e76 100644 --- a/BigBaseV2/src/function_types.hpp +++ b/BigBaseV2/src/function_types.hpp @@ -11,11 +11,16 @@ namespace big::functions using fix_vectors_t = void(*)(rage::scrNativeCallContext*); using error_screen = void(char* entryHeader, char* entryLine1, int instructionalKey, char* entryLine2, BOOL p4, Any p5, Any* p6, Any* p7, BOOL background); - using increment_stat_event = bool(uint64_t net_event_struct, int64_t sender, int64_t a3); using get_event_data = bool(int32_t eventGroup, int32_t eventIndex, int64_t* args, uint32_t argCount); using get_label_text = const char*(void* unk, const char* label); using get_player_name = char*(Player player); using get_net_player = int(Player player); + using increment_stat_event = bool(uint64_t net_event_struct, int64_t sender, int64_t a3); + + using read_bitbuf_dword = bool(rage::datBitBuffer* buffer, uint32_t* read, int bits); + using received_event = bool(rage::netEventMgr* event_manager, CNetGamePlayer* source_player, CNetGamePlayer* target_player, uint16_t event_id, int event_index, int event_handled_bitset, rage::datBitBuffer* buffer); + using send_event_ack = void(rage::netEventMgr* event_manager, CNetGamePlayer* source_player, CNetGamePlayer* target_player, int event_index, int event_handled_bitset); + using script_event_handler = bool(void* events, CNetGamePlayer* sourcePlayer, CNetGamePlayer* targetPlayer); using set_session_weather = void(char a1, int a2, int a3, int64_t a4); using spectate_player = bool(bool toggle, Ped player); diff --git a/BigBaseV2/src/gta/net_game_event.hpp b/BigBaseV2/src/gta/net_game_event.hpp index 14658657..b7d0e18d 100644 --- a/BigBaseV2/src/gta/net_game_event.hpp +++ b/BigBaseV2/src/gta/net_game_event.hpp @@ -123,10 +123,10 @@ namespace rage return false; } - inline bool ReadArray(PVOID array, int size) + /*inline bool ReadArray(PVOID array, int size) { return big::g_pointers->m_read_bitbuf_array(this, array, size, 0); - } + }*/ public: void* m_data; //0x0000 diff --git a/BigBaseV2/src/hooking.cpp b/BigBaseV2/src/hooking.cpp index 30b8e1d9..a0b8a3c2 100644 --- a/BigBaseV2/src/hooking.cpp +++ b/BigBaseV2/src/hooking.cpp @@ -39,10 +39,11 @@ namespace big m_run_script_threads_hook("Script hook", g_pointers->m_run_script_threads, &hooks::run_script_threads), m_convert_thread_to_fiber_hook("ConvertThreadToFiber", memory::module("kernel32.dll").get_export("ConvertThreadToFiber").as(), &hooks::convert_thread_to_fiber), - m_get_event_data("Get Event Data", g_pointers->m_get_event_data, &hooks::get_event_data), - m_get_label_text("Get Label Text", g_pointers->m_get_label_text, &hooks::get_label_text), + m_get_event_data_hook("Get Event Data", g_pointers->m_get_event_data, &hooks::get_event_data), + m_get_label_text_hook("Get Label Text", g_pointers->m_get_label_text, &hooks::get_label_text), m_error_screen_hook("Disable Warning/Error Screen", g_pointers->m_error_screen, &hooks::error_screen), m_increment_stat_hook("Increment Stat Event", g_pointers->m_increment_stat_event, &hooks::increment_stat_event), + m_received_event_hook("Received Event", g_pointers->m_received_event, &hooks::received_event), m_script_event_hook("Script Event Handler", g_pointers->m_script_event_handler, &hooks::script_event_handler), m_send_net_info_to_lobby_hook("Send Net Info to Lobby", g_pointers->m_send_net_info_to_lobby, &hooks::send_net_info_to_lobby) { @@ -70,10 +71,11 @@ namespace big m_convert_thread_to_fiber_hook.enable(); // New hooks enable - m_get_event_data.enable(); - m_get_label_text.enable(); + m_get_event_data_hook.enable(); + m_get_label_text_hook.enable(); m_error_screen_hook.enable(); m_increment_stat_hook.enable(); + //m_received_event_hook.enable(); m_script_event_hook.enable(); m_send_net_info_to_lobby_hook.enable(); @@ -92,10 +94,11 @@ namespace big m_swapchain_hook.disable(); // New hooks disable - m_get_event_data.disable(); - m_get_label_text.disable(); + m_get_event_data_hook.disable(); + m_get_label_text_hook.disable(); m_error_screen_hook.disable(); m_increment_stat_hook.disable(); + //m_received_event_hook.disable(); m_script_event_hook.disable(); m_send_net_info_to_lobby_hook.disable(); } diff --git a/BigBaseV2/src/hooking.hpp b/BigBaseV2/src/hooking.hpp index 96cf1df4..b05f072d 100644 --- a/BigBaseV2/src/hooking.hpp +++ b/BigBaseV2/src/hooking.hpp @@ -1,7 +1,7 @@ #pragma once #include "common.hpp" #include "detour_hook.hpp" -#include "gta/fwddec.hpp" +//#include "gta/fwddec.hpp" #include "script_hook.hpp" #include "vmt_hook.hpp" @@ -28,6 +28,7 @@ namespace big static bool increment_stat_event(uint64_t net_event_struct, CNetGamePlayer* sender, int64_t a3); static bool script_event_handler(std::int64_t NetEventStruct, CNetGamePlayer* net_game_player); static bool send_net_info_to_lobby(rage::netPlayerData* local_player, int64_t a2, int64_t a3, DWORD* a4); + static bool received_event(rage::netEventMgr* event_manager, CNetGamePlayer* source_player, CNetGamePlayer* target_player, uint16_t event_id, int event_index, int event_handled_bitset, rage::datBitBuffer* buffer); }; struct minhook_keepalive @@ -58,10 +59,11 @@ namespace big detour_hook m_convert_thread_to_fiber_hook; // New Detour Hook Definitions - detour_hook m_get_event_data; - detour_hook m_get_label_text; + detour_hook m_get_event_data_hook; + detour_hook m_get_label_text_hook; detour_hook m_error_screen_hook; detour_hook m_increment_stat_hook; + detour_hook m_received_event_hook; detour_hook m_script_event_hook; detour_hook m_send_net_info_to_lobby_hook; }; diff --git a/BigBaseV2/src/hooks/get_event_data.cpp b/BigBaseV2/src/hooks/get_event_data.cpp index 9fd65e51..4d437198 100644 --- a/BigBaseV2/src/hooks/get_event_data.cpp +++ b/BigBaseV2/src/hooks/get_event_data.cpp @@ -8,7 +8,7 @@ namespace big { bool hooks::get_event_data(int32_t eventGroup, int32_t eventIndex, int64_t* args, uint32_t argCount) { - bool result = g_hooking->m_get_event_data.get_original()(eventGroup, eventIndex, args, argCount); + bool result = g_hooking->m_get_event_data_hook.get_original()(eventGroup, eventIndex, args, argCount); Player player = (Player)args[1]; if (result && player < 32) diff --git a/BigBaseV2/src/hooks/get_label_text.cpp b/BigBaseV2/src/hooks/get_label_text.cpp index 4d32fad5..46655020 100644 --- a/BigBaseV2/src/hooks/get_label_text.cpp +++ b/BigBaseV2/src/hooks/get_label_text.cpp @@ -10,6 +10,6 @@ namespace big if (auto text = g_custom_text->get_text(rage::joaat(label))) return text; - return g_hooking->m_get_label_text.get_original()(unk, label); + return g_hooking->m_get_label_text_hook.get_original()(unk, label); } } \ No newline at end of file diff --git a/BigBaseV2/src/hooks/received_event.cpp b/BigBaseV2/src/hooks/received_event.cpp new file mode 100644 index 00000000..d09add8b --- /dev/null +++ b/BigBaseV2/src/hooks/received_event.cpp @@ -0,0 +1,62 @@ +#include "hooking.hpp" +#include "gta/enums.hpp" +#include "gta/net_game_event.hpp" + +namespace big +{ + bool hooks::received_event( + rage::netEventMgr* event_manager, + CNetGamePlayer* source_player, + CNetGamePlayer* target_player, + uint16_t event_id, + int event_index, + int event_handled_bitset, + rage::datBitBuffer* buffer + ) + { + if (event_id > 91) return false; + + switch (event_id) + { + case RockstarEvent::GAME_CLOCK_EVENT: + { + uint32_t hour, min, sec; + buffer->Seek(21); + buffer->ReadDword(&hour, 6); + buffer->ReadDword(&min, 7); + buffer->ReadDword(&sec, 7); + + if (hour > 23 || min > 59 || sec > 59) + { + g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); + + return false; + } + buffer->Seek(0); + + return true; + } + case RockstarEvent::GAME_WEATHER_EVENT: + { + uint32_t propagate, target, weather; + + buffer->ReadDword(&propagate, 1); + buffer->ReadDword(&weather, 5); + if (!propagate) + buffer->ReadDword(&target, 9); + + if (weather > 12 || !propagate) + { + g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); + + return false; + } + buffer->Seek(0); + + return true; + } + } + + return true; + } +} \ No newline at end of file diff --git a/BigBaseV2/src/hooks/send_net_info_to_lobby.cpp b/BigBaseV2/src/hooks/send_net_info_to_lobby.cpp index 5f85380d..fb68036f 100644 --- a/BigBaseV2/src/hooks/send_net_info_to_lobby.cpp +++ b/BigBaseV2/src/hooks/send_net_info_to_lobby.cpp @@ -13,8 +13,6 @@ namespace big strcpy(name, sName->c_str()); memcpy(local_player->m_name, name, sizeof(name)); } - // const char name[20] = "How dare you!"; - // memcpy(local_player->m_name, name, sizeof(name)); if (spoof["ip_address"]["enabled"]) { diff --git a/BigBaseV2/src/pointers.cpp b/BigBaseV2/src/pointers.cpp index 850dada1..4594944a 100644 --- a/BigBaseV2/src/pointers.cpp +++ b/BigBaseV2/src/pointers.cpp @@ -142,6 +142,21 @@ namespace big { m_get_label_text = ptr.sub(19).as(); }); + + main_batch.add("Received Event", "66 41 83 F9 ? 0F 83", [this](memory::handle ptr) + { + m_received_event = ptr.as(); + }); + + main_batch.add("Read BitBuffer WORD/DWORD", "E8 ? ? ? ? 84 C0 74 1C 48 8D 96 ? ? ? ? 44 8D 43 08 48 8B CF E8", [this](memory::handle ptr) + { + m_read_bitbuf_dword = ptr.as(); + }); + + main_batch.add("Received Event Ack", "4C 0F 45 C9 8B 44 24 60", [this](memory::handle ptr) + { + m_send_event_ack = ptr.as(); + }); main_batch.run(memory::module(nullptr)); diff --git a/BigBaseV2/src/pointers.hpp b/BigBaseV2/src/pointers.hpp index 2076a724..810e2bd6 100644 --- a/BigBaseV2/src/pointers.hpp +++ b/BigBaseV2/src/pointers.hpp @@ -44,8 +44,11 @@ namespace big functions::get_player_name* m_get_player_name{}; functions::get_net_player* m_get_net_game_player{}; functions::increment_stat_event* m_increment_stat_event{}; + functions::read_bitbuf_dword* m_read_bitbuf_dword{}; + functions::received_event* m_received_event{}; functions::script_event_handler* m_script_event_handler{}; functions::set_session_weather* m_set_session_weather{}; + functions::send_event_ack* m_send_event_ack{}; functions::spectate_player* m_spectate_player{}; functions::sync_local_time* m_sync_local_time{}; functions::trigger_script_event* m_trigger_script_event{};