feat(Protections): Added version mismatch patch

This commit is contained in:
Yimura 2022-03-16 15:55:27 +01:00
parent bd8046c214
commit ed9d6cef25
5 changed files with 55 additions and 2 deletions

View File

@ -36,7 +36,9 @@ namespace big
// Network Player Mgr Shutdown
m_network_player_mgr_shutdown_hook("NPMS", g_pointers->m_network_player_mgr_shutdown, &hooks::network_player_mgr_shutdown),
m_net_array_handler_hook("net_array_handler", g_pointers->m_net_array_handler, &hooks::net_array_handler),
// Increment Stat Event
m_increment_stat_hook("ISE", g_pointers->m_increment_stat_event, &hooks::increment_stat_event),
// Is DLC Present
@ -88,6 +90,8 @@ namespace big
m_network_player_mgr_shutdown_hook.enable();
m_net_array_handler_hook.enable();
m_player_has_joined_hook.enable();
m_player_has_left_hook.enable();
@ -121,6 +125,8 @@ namespace big
m_player_has_joined_hook.disable();
m_player_has_left_hook.disable();
m_net_array_handler_hook.disable();
m_network_player_mgr_shutdown_hook.disable();
m_gta_thread_tick_hook.disable();

View File

@ -42,6 +42,8 @@ namespace big
static void network_player_mgr_shutdown(CNetworkPlayerMgr* _this);
static bool net_array_handler(__int64 netArrayHandlerBaseMgr, unsigned __int8* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, __int16 a5);
static void player_join(CNetworkObjectMgr* _this, CNetGamePlayer* net_player);
static void player_leave(CNetworkObjectMgr* _this, CNetGamePlayer* net_player);
@ -99,6 +101,8 @@ namespace big
detour_hook m_network_player_mgr_shutdown_hook;
detour_hook m_net_array_handler_hook;
detour_hook m_player_has_joined_hook;
detour_hook m_player_has_left_hook;

View File

@ -0,0 +1,35 @@
#include "hooking.hpp"
namespace big
{
// in this hook we rebuild how the game reads data from the datBitBuffer
// we specifically recreate what the game uses to "detect" the NET_ARRAY_ERROR
// then if we find such a crash we just return false;
bool hooks::net_array_handler(long long netArrayHandlerBaseMgr, unsigned char* a2, rage::datBitBuffer* datbitbuffer, unsigned int bytes_to_read, short a5)
{
if (g_running)
{
DWORD test = 0;
const auto bytes_start = datbitbuffer->m_bitsRead;
for (unsigned int i = datbitbuffer->m_bitsRead - bytes_start;
i < bytes_to_read;
i = datbitbuffer->m_bitsRead - bytes_start)
{
const auto bytes_read_before = datbitbuffer->m_bitsRead;
g_pointers->m_read_bitbuf_dword(datbitbuffer, &test, 1u);
if (bytes_read_before == datbitbuffer->m_bitsRead)
{
LOG(INFO) << "NET_ARRAY_ERROR caught, someones probably trying to crash us.";
return false;
}
}
datbitbuffer->Seek(bytes_start);
}
return g_hooking->m_net_array_handler_hook.get_original<decltype(&hooks::net_array_handler)>()(netArrayHandlerBaseMgr, a2, datbitbuffer, bytes_to_read, a5);
}
}

View File

@ -225,12 +225,14 @@ namespace big
m_network_player_mgr_shutdown = ptr.sub(0x17).as<PVOID>();
});
// FriendRegistry
main_batch.add("FR", "3B 0D ? ? ? ? 73 13 48 63 C9", [this](memory::handle ptr)
{
m_friend_registry = ptr.add(2).rip().as<FriendRegistry*>();
});
main_batch.add("GET_SCREEN_COORDS_FROM_WORLD_COORDS", "E8 ? ? ? ? 84 C0 74 19 F3 0F 10 44 24", [this](memory::handle ptr)
// GET_SCREEN_COORDS_FROM_WORLD_COORDS
main_batch.add("GSCFWC", "E8 ? ? ? ? 84 C0 74 19 F3 0F 10 44 24", [this](memory::handle ptr)
{
m_get_screen_coords_for_world_coords = ptr.add(1).rip().as<functions::get_screen_coords_for_world_coords*>();
});
@ -241,6 +243,11 @@ namespace big
m_get_gamplay_cam_coords = ptr.as<functions::get_gameplay_cam_coords*>();
});
// net array handler - version mismatch patch
main_batch.add("NAH", "44 8B E0 89 45 F4 48 8B 03 48 8B CB FF 90", [this](memory::handle ptr)
{
m_net_array_handler = ptr.sub(0x3C).as<PVOID>();
});
main_batch.run(memory::module(nullptr));

View File

@ -59,6 +59,7 @@ namespace big
PVOID m_gta_thread_kill{};
PVOID m_network_player_mgr_shutdown;
PVOID m_net_array_handler;
PVOID m_player_has_joined{};
PVOID m_player_has_left{};