feat(Hooking): Added hook to prevent warnings/errors from the shop_controller script

This commit is contained in:
Yimura 2020-12-27 17:49:50 +01:00
parent 0f4d60bcf9
commit 6c16d9d317
No known key found for this signature in database
GPG Key ID: 54EFAD29393A6E78
6 changed files with 33 additions and 5 deletions

View File

@ -9,7 +9,7 @@ namespace big::functions
using get_native_handler_t = rage::scrNativeHandler(*)(rage::scrNativeRegistrationTable*, rage::scrNativeHash);
using fix_vectors_t = void(*)(rage::scrNativeCallContext*);
using disable_error_screen = void(char* entryHeader, char* entryLine1, int instructionalKey, char* entryLine2, BOOL p4, Any p5, Any* p6, Any* p7, BOOL background);
using error_screen = void(char* entryHeader, char* entryLine1, int instructionalKey, char* entryLine2, BOOL p4, Any p5, Any* p6, Any* p7, BOOL background);
using get_player_name = char*(Player player);
using sync_local_time_t = void(int h, int m);
}

View File

@ -37,8 +37,9 @@ namespace big
m_set_cursor_pos_hook("SetCursorPos", memory::module("user32.dll").get_export("SetCursorPos").as<void*>(), &hooks::set_cursor_pos),
m_run_script_threads_hook("Script hook", g_pointers->m_run_script_threads, &hooks::run_script_threads),
m_convert_thread_to_fiber_hook("ConvertThreadToFiber", memory::module("kernel32.dll").get_export("ConvertThreadToFiber").as<void*>(), &hooks::convert_thread_to_fiber)
m_convert_thread_to_fiber_hook("ConvertThreadToFiber", memory::module("kernel32.dll").get_export("ConvertThreadToFiber").as<void*>(), &hooks::convert_thread_to_fiber),
m_error_screen_hook("Disable Warning/Error Screen", g_pointers->m_error_screen, &hooks::error_screen)
{
m_swapchain_hook.hook(hooks::swapchain_present_index, &hooks::swapchain_present);
m_swapchain_hook.hook(hooks::swapchain_resizebuffers_index, &hooks::swapchain_resizebuffers);
@ -63,6 +64,9 @@ namespace big
m_run_script_threads_hook.enable();
m_convert_thread_to_fiber_hook.enable();
// New hooks enable
m_error_screen_hook.enable();
m_enabled = true;
}
@ -76,6 +80,9 @@ namespace big
m_set_cursor_pos_hook.disable();
SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(m_og_wndproc));
m_swapchain_hook.disable();
// New hooks disable
m_error_screen_hook.disable();
}
minhook_keepalive::minhook_keepalive()

View File

@ -20,6 +20,9 @@ namespace big
static LRESULT wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static BOOL set_cursor_pos(int x, int y);
// New Hook Definitions
static void error_screen(char* entryHeader, char* entryLine1, int instructionalKey, char* entryLine2, BOOL p4, Any p5, Any* p6, Any* p7, BOOL background);
};
struct minhook_keepalive
@ -48,6 +51,9 @@ namespace big
detour_hook m_run_script_threads_hook;
detour_hook m_convert_thread_to_fiber_hook;
// New Detour Hook Definitions
detour_hook m_error_screen_hook;
};
inline hooking *g_hooking{};

View File

@ -0,0 +1,15 @@
#include "hooking.hpp"
#include "natives.hpp"
#include "gta/joaat.hpp"
namespace big
{
void hooks::error_screen(char* entryHeader, char* entryLine1, int instructionalKey, char* entryLine2, BOOL p4, Any p5, Any* p6, Any* p7, BOOL background)
{
if (SCRIPT::GET_HASH_OF_THIS_SCRIPT_NAME() == RAGE_JOAAT("shop_controller"))
{
return;
}
return g_hooking->m_error_screen_hook.get_original<decltype(&error_screen)>()(entryHeader, entryLine1, instructionalKey, entryLine2, p4, p5, p6, p7, background);
}
}

View File

@ -83,9 +83,9 @@ namespace big
m_get_player_name = ptr.as<decltype(m_get_player_name)>();
});
main_batch.add("Disable Error Screen", "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC 60 4C 8B F2 48 8B 94 24 ? ? ? ? 33 DB", [this](memory::handle ptr)
main_batch.add("Warning/Error Screen", "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC 60 4C 8B F2 48 8B 94 24 ? ? ? ? 33 DB", [this](memory::handle ptr)
{
m_disable_error_screen = ptr.as<decltype(m_disable_error_screen)>();
m_error_screen = ptr.as<decltype(m_error_screen)>();
});
main_batch.run(memory::module(nullptr));

View File

@ -35,7 +35,7 @@ namespace big
PVOID m_model_spawn_bypass;
functions::disable_error_screen* m_disable_error_screen;
functions::error_screen* m_error_screen{};
functions::get_player_name* m_get_player_name{};
functions::sync_local_time_t* m_sync_local_time{};
};