refactor: make window hook into a bool command (#1824)
This commit is contained in:
parent
ddb12d6e2b
commit
17d3ad7658
34
src/backend/commands/system/window_hook.cpp
Normal file
34
src/backend/commands/system/window_hook.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include "backend/bool_command.hpp"
|
||||||
|
#include "memory/byte_patch.hpp"
|
||||||
|
#include "pointers.hpp"
|
||||||
|
|
||||||
|
namespace big
|
||||||
|
{
|
||||||
|
class window_hook : bool_command
|
||||||
|
{
|
||||||
|
using bool_command::bool_command;
|
||||||
|
|
||||||
|
memory::byte_patch* m_window_hook_patch;
|
||||||
|
|
||||||
|
virtual void refresh() override
|
||||||
|
{
|
||||||
|
static auto patch = (m_window_hook_patch = memory::byte_patch::make(g_pointers->m_gta.m_window_hook.as<void*>(), std::to_array({0xC3, 0x90, 0x90, 0x90}))
|
||||||
|
.get(),
|
||||||
|
true);
|
||||||
|
|
||||||
|
if (m_toggle)
|
||||||
|
{
|
||||||
|
m_window_hook_patch->apply();
|
||||||
|
UnhookWindowsHookEx(*g_pointers->m_gta.m_window_hook.add(45).rip().as<HHOOK*>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowsHookExA(13, g_pointers->m_gta.m_window_hook.add(18).rip().as<HOOKPROC>(), GetModuleHandleA("GTA5.exe"), 0);
|
||||||
|
m_window_hook_patch->restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window_hook g_window_hook("windowhook", "GTA Window Hook", "Only enable this if you know what you are doing, this will prevent AHK scripts from working.",
|
||||||
|
g.debug.window_hook);
|
||||||
|
}
|
@ -78,9 +78,6 @@ namespace big
|
|||||||
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch, std::vector{0x90, 0x90})->apply();
|
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch, std::vector{0x90, 0x90})->apply();
|
||||||
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch_2, std::vector{0xB0, 0x01})->apply();
|
memory::byte_patch::make(g_pointers->m_sc.m_read_attribute_patch_2, std::vector{0xB0, 0x01})->apply();
|
||||||
|
|
||||||
// window hook: pt1
|
|
||||||
memory::byte_patch::make(g_pointers->m_gta.m_window_hook.as<void*>(), std::to_array({0xC3, 0x90, 0x90, 0x90}))->apply();
|
|
||||||
|
|
||||||
// Prevent the game from crashing when flooded with outgoing events
|
// Prevent the game from crashing when flooded with outgoing events
|
||||||
memory::byte_patch::make(g_pointers->m_gta.m_free_event_error, std::vector{0x90, 0x90, 0x90, 0x90, 0x90})->apply();
|
memory::byte_patch::make(g_pointers->m_gta.m_free_event_error, std::vector{0x90, 0x90, 0x90, 0x90, 0x90})->apply();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,9 @@ namespace big
|
|||||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(logs, metric_logs, packet_logs, script_hook_logs, script_event)
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE(logs, metric_logs, packet_logs, script_hook_logs, script_event)
|
||||||
} logs{};
|
} logs{};
|
||||||
|
|
||||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(debug, logs)
|
bool window_hook = false;
|
||||||
|
|
||||||
|
NLOHMANN_DEFINE_TYPE_INTRUSIVE(debug, logs, window_hook)
|
||||||
} debug{};
|
} debug{};
|
||||||
|
|
||||||
struct tunables
|
struct tunables
|
||||||
|
@ -139,8 +139,6 @@ namespace big
|
|||||||
{
|
{
|
||||||
m_swapchain_hook.enable();
|
m_swapchain_hook.enable();
|
||||||
m_og_wndproc = WNDPROC(SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, LONG_PTR(&hooks::wndproc)));
|
m_og_wndproc = WNDPROC(SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, LONG_PTR(&hooks::wndproc)));
|
||||||
// window hook: pt2
|
|
||||||
UnhookWindowsHookEx(*g_pointers->m_gta.m_window_hook.add(45).rip().as<HHOOK*>());
|
|
||||||
|
|
||||||
for (const auto& detour_hook_helper : m_detour_hook_helpers)
|
for (const auto& detour_hook_helper : m_detour_hook_helpers)
|
||||||
{
|
{
|
||||||
@ -161,8 +159,6 @@ namespace big
|
|||||||
detour_hook_helper->m_detour_hook->disable();
|
detour_hook_helper->m_detour_hook->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// window hook: pt2
|
|
||||||
SetWindowsHookExA(13, g_pointers->m_gta.m_window_hook.add(18).rip().as<HOOKPROC>(), GetModuleHandleA("GTA5.exe"), 0);
|
|
||||||
SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_og_wndproc));
|
SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_og_wndproc));
|
||||||
m_swapchain_hook.disable();
|
m_swapchain_hook.disable();
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ namespace big
|
|||||||
{
|
{
|
||||||
if (ImGui::BeginTabItem("DEBUG_TAB_MISC"_T.data()))
|
if (ImGui::BeginTabItem("DEBUG_TAB_MISC"_T.data()))
|
||||||
{
|
{
|
||||||
|
components::command_checkbox<"windowhook">("Disable GTA Window Hook");
|
||||||
|
|
||||||
ImGui::Text("Fiber Pool Usage %d/%d", g_fiber_pool->get_used_fibers(), g_fiber_pool->get_total_fibers());
|
ImGui::Text("Fiber Pool Usage %d/%d", g_fiber_pool->get_used_fibers(), g_fiber_pool->get_total_fibers());
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
Reference in New Issue
Block a user