diff --git a/src/backend/commands/system/window_hook.cpp b/src/backend/commands/system/window_hook.cpp new file mode 100644 index 00000000..2015d8d2 --- /dev/null +++ b/src/backend/commands/system/window_hook.cpp @@ -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(), 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()); + } + else + { + SetWindowsHookExA(13, g_pointers->m_gta.m_window_hook.add(18).rip().as(), 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); +} diff --git a/src/byte_patch_manager.cpp b/src/byte_patch_manager.cpp index 1871377c..14ee3a7d 100644 --- a/src/byte_patch_manager.cpp +++ b/src/byte_patch_manager.cpp @@ -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_2, std::vector{0xB0, 0x01})->apply(); - // window hook: pt1 - memory::byte_patch::make(g_pointers->m_gta.m_window_hook.as(), std::to_array({0xC3, 0x90, 0x90, 0x90}))->apply(); - // 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(); } diff --git a/src/core/settings.hpp b/src/core/settings.hpp index 60ecb570..79b42c8e 100644 --- a/src/core/settings.hpp +++ b/src/core/settings.hpp @@ -120,7 +120,9 @@ namespace big NLOHMANN_DEFINE_TYPE_INTRUSIVE(logs, metric_logs, packet_logs, script_hook_logs, script_event) } logs{}; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(debug, logs) + bool window_hook = false; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE(debug, logs, window_hook) } debug{}; struct tunables diff --git a/src/hooking.cpp b/src/hooking.cpp index 4c521f52..6b195173 100644 --- a/src/hooking.cpp +++ b/src/hooking.cpp @@ -139,8 +139,6 @@ namespace big { m_swapchain_hook.enable(); 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()); for (const auto& detour_hook_helper : m_detour_hook_helpers) { @@ -161,8 +159,6 @@ namespace big detour_hook_helper->m_detour_hook->disable(); } - // window hook: pt2 - SetWindowsHookExA(13, g_pointers->m_gta.m_window_hook.add(18).rip().as(), GetModuleHandleA("GTA5.exe"), 0); SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast(m_og_wndproc)); m_swapchain_hook.disable(); diff --git a/src/views/debug/view_debug_misc.cpp b/src/views/debug/view_debug_misc.cpp index ace434ec..e7bdde93 100644 --- a/src/views/debug/view_debug_misc.cpp +++ b/src/views/debug/view_debug_misc.cpp @@ -19,6 +19,8 @@ namespace big { 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::SameLine();