2019-03-21 20:18:31 +01:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "function_types.hpp"
|
|
|
|
#include "logger.hpp"
|
|
|
|
#include "gta/array.hpp"
|
|
|
|
#include "gta/player.hpp"
|
|
|
|
#include "gta/script_thread.hpp"
|
|
|
|
#include "gui.hpp"
|
|
|
|
#include "hooking.hpp"
|
|
|
|
#include "memory/module.hpp"
|
|
|
|
#include "natives.hpp"
|
|
|
|
#include "pointers.hpp"
|
|
|
|
#include "renderer.hpp"
|
|
|
|
#include "script_mgr.hpp"
|
|
|
|
|
2019-06-23 22:00:18 +02:00
|
|
|
#include <MinHook.h>
|
2019-03-21 20:18:31 +01:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
hooking::hooking() :
|
2022-01-25 02:55:35 +01:00
|
|
|
// Swapchain
|
2019-03-21 20:18:31 +01:00
|
|
|
m_swapchain_hook(*g_pointers->m_swapchain, hooks::swapchain_num_funcs),
|
2021-07-23 21:15:55 +02:00
|
|
|
// SetCursorPos
|
|
|
|
m_set_cursor_pos_hook("SCP", memory::module("user32.dll").get_export("SetCursorPos").as<void*>(), &hooks::set_cursor_pos),
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2021-07-23 21:15:55 +02:00
|
|
|
// Script Hook
|
|
|
|
m_run_script_threads_hook("SH", g_pointers->m_run_script_threads, &hooks::run_script_threads),
|
|
|
|
// ConvertThreadToFibe
|
|
|
|
m_convert_thread_to_fiber_hook("CTTF", memory::module("kernel32.dll").get_export("ConvertThreadToFiber").as<void*>(), &hooks::convert_thread_to_fiber),
|
2021-05-18 23:03:42 +02:00
|
|
|
|
2022-01-25 02:55:35 +01:00
|
|
|
// GTA Thead Start
|
|
|
|
m_gta_thread_start_hook("GTS", g_pointers->m_gta_thread_start, &hooks::gta_thread_start),
|
2021-07-23 21:15:55 +02:00
|
|
|
// GTA Thread Kill
|
|
|
|
m_gta_thread_kill_hook("GTK", g_pointers->m_gta_thread_kill, &hooks::gta_thread_kill),
|
2021-05-19 16:19:38 +02:00
|
|
|
|
2022-01-31 18:27:35 +01:00
|
|
|
// Network Player Mgr Shutdown
|
|
|
|
m_network_player_mgr_shutdown_hook("NPMS", g_pointers->m_network_player_mgr_shutdown, &hooks::network_player_mgr_shutdown),
|
2022-03-16 15:55:27 +01:00
|
|
|
|
2022-05-13 18:26:15 +02:00
|
|
|
// Network Group Override
|
|
|
|
m_network_group_override("NGO", g_pointers->m_network_group_override, &hooks::network_group_override),
|
|
|
|
|
|
|
|
// Net Array Handler
|
|
|
|
m_net_array_handler_hook("NAH", g_pointers->m_net_array_handler, &hooks::net_array_handler),
|
2022-03-16 15:55:27 +01:00
|
|
|
|
2021-07-23 21:15:55 +02:00
|
|
|
// Increment Stat Event
|
|
|
|
m_increment_stat_hook("ISE", g_pointers->m_increment_stat_event, &hooks::increment_stat_event),
|
2021-12-06 16:39:46 +01:00
|
|
|
// Is DLC Present
|
|
|
|
m_is_dlc_present_hook("IDP", g_pointers->m_is_dlc_present, &hooks::is_dlc_present),
|
2021-05-25 14:44:35 +02:00
|
|
|
|
2021-07-23 21:15:55 +02:00
|
|
|
// Received Event
|
2021-07-24 14:49:31 +02:00
|
|
|
m_received_event_hook("RE", g_pointers->m_received_event, &hooks::received_event),
|
|
|
|
|
2021-12-18 19:24:30 +01:00
|
|
|
// Send NET Info to Lobby
|
2022-01-21 23:11:37 +01:00
|
|
|
m_send_net_info_to_lobby("SNITL", g_pointers->m_send_net_info_to_lobby, &hooks::send_net_info_to_lobby),
|
|
|
|
|
2022-01-25 02:55:35 +01:00
|
|
|
// Player Has Joined
|
|
|
|
m_player_has_joined_hook("PHJ", g_pointers->m_player_has_joined, &hooks::player_join),
|
|
|
|
// Player Has Left
|
2022-05-20 18:17:41 -04:00
|
|
|
m_player_has_left_hook("PHL", g_pointers->m_player_has_left, &hooks::player_leave),
|
|
|
|
// Receive Net Message
|
|
|
|
m_receive_net_message_hook("RNM", g_pointers->m_receive_net_message, &hooks::receive_net_message),
|
|
|
|
//Get Network Event Data
|
|
|
|
m_get_network_event_data_hook("GNED", g_pointers->m_get_network_event_data, &hooks::get_network_event_data)
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
|
|
|
m_swapchain_hook.hook(hooks::swapchain_present_index, &hooks::swapchain_present);
|
|
|
|
m_swapchain_hook.hook(hooks::swapchain_resizebuffers_index, &hooks::swapchain_resizebuffers);
|
|
|
|
|
|
|
|
g_hooking = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
hooking::~hooking()
|
|
|
|
{
|
|
|
|
if (m_enabled)
|
|
|
|
disable();
|
|
|
|
|
|
|
|
g_hooking = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hooking::enable()
|
|
|
|
{
|
|
|
|
m_swapchain_hook.enable();
|
|
|
|
m_og_wndproc = reinterpret_cast<WNDPROC>(SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&hooks::wndproc)));
|
|
|
|
m_set_cursor_pos_hook.enable();
|
|
|
|
|
|
|
|
m_run_script_threads_hook.enable();
|
|
|
|
m_convert_thread_to_fiber_hook.enable();
|
|
|
|
|
2022-01-21 23:11:37 +01:00
|
|
|
m_gta_thread_start_hook.enable();
|
2021-05-19 00:41:55 +02:00
|
|
|
m_gta_thread_kill_hook.enable();
|
|
|
|
|
2022-01-31 18:27:35 +01:00
|
|
|
m_network_player_mgr_shutdown_hook.enable();
|
|
|
|
|
2022-03-16 15:55:27 +01:00
|
|
|
m_net_array_handler_hook.enable();
|
|
|
|
|
2022-01-25 02:55:35 +01:00
|
|
|
m_player_has_joined_hook.enable();
|
|
|
|
m_player_has_left_hook.enable();
|
|
|
|
|
2021-05-25 14:44:35 +02:00
|
|
|
m_increment_stat_hook.enable();
|
|
|
|
|
2021-05-25 12:58:33 +02:00
|
|
|
m_received_event_hook.enable();
|
|
|
|
|
2021-12-18 19:24:30 +01:00
|
|
|
m_send_net_info_to_lobby.enable();
|
|
|
|
|
2022-05-20 18:17:41 -04:00
|
|
|
m_receive_net_message_hook.enable();
|
|
|
|
m_get_network_event_data_hook.enable();
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
m_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hooking::disable()
|
|
|
|
{
|
|
|
|
m_enabled = false;
|
|
|
|
|
2022-05-20 18:17:41 -04:00
|
|
|
m_get_network_event_data_hook.disable();
|
|
|
|
m_receive_net_message_hook.disable();
|
|
|
|
|
2021-12-18 19:24:30 +01:00
|
|
|
m_send_net_info_to_lobby.disable();
|
|
|
|
|
2021-05-25 12:58:33 +02:00
|
|
|
m_received_event_hook.disable();
|
|
|
|
|
2021-05-25 14:44:35 +02:00
|
|
|
m_increment_stat_hook.disable();
|
|
|
|
|
2022-01-25 02:55:35 +01:00
|
|
|
m_player_has_joined_hook.disable();
|
|
|
|
m_player_has_left_hook.disable();
|
|
|
|
|
2022-03-16 15:55:27 +01:00
|
|
|
m_net_array_handler_hook.disable();
|
|
|
|
|
2022-01-31 18:27:35 +01:00
|
|
|
m_network_player_mgr_shutdown_hook.disable();
|
|
|
|
|
2021-05-19 00:41:55 +02:00
|
|
|
m_gta_thread_kill_hook.disable();
|
2022-01-21 23:11:37 +01:00
|
|
|
m_gta_thread_start_hook.disable();
|
2021-05-19 00:41:55 +02:00
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
m_convert_thread_to_fiber_hook.disable();
|
|
|
|
m_run_script_threads_hook.disable();
|
|
|
|
|
|
|
|
m_set_cursor_pos_hook.disable();
|
|
|
|
SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_og_wndproc));
|
|
|
|
m_swapchain_hook.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
minhook_keepalive::minhook_keepalive()
|
|
|
|
{
|
|
|
|
MH_Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
minhook_keepalive::~minhook_keepalive()
|
|
|
|
{
|
|
|
|
MH_Uninitialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hooks::run_script_threads(std::uint32_t ops_to_execute)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (g_running)
|
|
|
|
{
|
|
|
|
g_script_mgr.tick();
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return g_hooking->m_run_script_threads_hook.get_original<functions::run_script_threads_t>()(ops_to_execute);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return false;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *hooks::convert_thread_to_fiber(void *param)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (IsThreadAFiber())
|
|
|
|
{
|
|
|
|
return GetCurrentFiber();
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return g_hooking->m_convert_thread_to_fiber_hook.get_original<decltype(&convert_thread_to_fiber)>()(param);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return nullptr;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hooks::swapchain_present(IDXGISwapChain *this_, UINT sync_interval, UINT flags)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (g_running)
|
|
|
|
{
|
|
|
|
g_renderer->on_present();
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return g_hooking->m_swapchain_hook.get_original<decltype(&swapchain_present)>(swapchain_present_index)(this_, sync_interval, flags);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return NULL;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hooks::swapchain_resizebuffers(IDXGISwapChain * this_, UINT buffer_count, UINT width, UINT height, DXGI_FORMAT new_format, UINT swapchain_flags)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (g_running)
|
|
|
|
{
|
|
|
|
g_renderer->pre_reset();
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
auto result = g_hooking->m_swapchain_hook.get_original<decltype(&swapchain_resizebuffers)>(swapchain_resizebuffers_index)
|
|
|
|
(this_, buffer_count, width, height, new_format, swapchain_flags);
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
if (SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
g_renderer->post_reset();
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return result;
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return g_hooking->m_swapchain_hook.get_original<decltype(&swapchain_resizebuffers)>(swapchain_resizebuffers_index)
|
|
|
|
(this_, buffer_count, width, height, new_format, swapchain_flags);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return NULL;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT hooks::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (g_running)
|
|
|
|
{
|
|
|
|
g_renderer->wndproc(hwnd, msg, wparam, lparam);
|
|
|
|
}
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return CallWindowProcW(g_hooking->m_og_wndproc, hwnd, msg, wparam, lparam);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return NULL;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL hooks::set_cursor_pos(int x, int y)
|
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
TRY_CLAUSE
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2020-02-22 18:37:42 -05:00
|
|
|
if (g_gui.m_opened)
|
|
|
|
return true;
|
2019-03-21 20:18:31 +01:00
|
|
|
|
2020-02-22 18:37:42 -05:00
|
|
|
return g_hooking->m_set_cursor_pos_hook.get_original<decltype(&set_cursor_pos)>()(x, y);
|
|
|
|
} EXCEPT_CLAUSE
|
|
|
|
return FALSE;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
}
|