refactor: make window hook into a bool command (#1824)

This commit is contained in:
Andreas Maerten 2023-07-23 22:52:30 +02:00 committed by GitHub
parent ddb12d6e2b
commit 17d3ad7658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 8 deletions

View 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);
}

View File

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

View File

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

View File

@ -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<HHOOK*>());
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<HOOKPROC>(), GetModuleHandleA("GTA5.exe"), 0);
SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_og_wndproc));
m_swapchain_hook.disable();

View File

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