wip(Hooks): Received event protections

This commit is contained in:
Yimura 2021-02-07 17:08:25 +01:00
parent cc626fd950
commit ccda1feae4
No known key found for this signature in database
GPG Key ID: 54EFAD29393A6E78
10 changed files with 104 additions and 16 deletions

View File

@ -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);

View File

@ -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

View File

@ -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<void*>(), &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();
}

View File

@ -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;
};

View File

@ -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<decltype(&hooks::get_event_data)>()(eventGroup, eventIndex, args, argCount);
bool result = g_hooking->m_get_event_data_hook.get_original<decltype(&hooks::get_event_data)>()(eventGroup, eventIndex, args, argCount);
Player player = (Player)args[1];
if (result && player < 32)

View File

@ -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<decltype(&get_label_text)>()(unk, label);
return g_hooking->m_get_label_text_hook.get_original<decltype(&get_label_text)>()(unk, label);
}
}

View File

@ -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;
}
}

View File

@ -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"])
{

View File

@ -142,6 +142,21 @@ namespace big
{
m_get_label_text = ptr.sub(19).as<decltype(m_get_label_text)>();
});
main_batch.add("Received Event", "66 41 83 F9 ? 0F 83", [this](memory::handle ptr)
{
m_received_event = ptr.as<decltype(m_received_event)>();
});
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<decltype(m_read_bitbuf_dword)>();
});
main_batch.add("Received Event Ack", "4C 0F 45 C9 8B 44 24 60", [this](memory::handle ptr)
{
m_send_event_ack = ptr.as<decltype(m_send_event_ack)>();
});
main_batch.run(memory::module(nullptr));

View File

@ -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{};