From 3207e78657fac6e46387e1cb7f77f7a4519e9c11 Mon Sep 17 00:00:00 2001 From: Jadis0x <49281043+jadis0x@users.noreply.github.com> Date: Sat, 13 Apr 2024 17:50:56 +0300 Subject: [PATCH] added unity debug hook for testing --- lib/ClientHelper.cpp | 4 +-- user/hooks/hooks.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++ user/hooks/hooks.hpp | 7 ++++- user/main.cpp | 13 +++----- 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/lib/ClientHelper.cpp b/lib/ClientHelper.cpp index 7fd0fd2..6338d01 100644 --- a/lib/ClientHelper.cpp +++ b/lib/ClientHelper.cpp @@ -1,7 +1,6 @@ #include "pch-il2cpp.h" #include "ClientHelper.h" -#include bool IsSinglePlayer() { @@ -16,4 +15,5 @@ bool IsOnline() bool IsHost() { return app::BoltNetwork_get_IsServer(NULL); -} \ No newline at end of file +} + diff --git a/user/hooks/hooks.cpp b/user/hooks/hooks.cpp index d266bc3..11f8e42 100644 --- a/user/hooks/hooks.cpp +++ b/user/hooks/hooks.cpp @@ -3,6 +3,9 @@ #include "../features/menu.hpp" #include "../main.h" +#include +#include "helpers.h" + #pragma warning(push, 0) //important cuz dx11 throws so much warnings #include #pragma warning(pop) @@ -31,6 +34,29 @@ } */ +void hDebug_Log(app::Object* message, MethodInfo* method) { + std::cout << "Debug_Log hooked\n"; + + std::cout << il2cppi_to_string(app::Object_ToString(message, nullptr)) << "\n"; + + app::Debug_2_Log(message, method); +} + +void hDebug_LogError(app::Object* message, MethodInfo* method) { + std::cout << "Debug.LogError hooked\n"; + + std::cout << il2cppi_to_string(app::Object_ToString(message, nullptr)) << "\n"; + + app::Debug_2_LogError(message, method); +} + +void hDebug_LogWarning(app::Object* message, MethodInfo* method) { + std::cout << "Debug_LogWarning hooked\n"; + + std::cout << il2cppi_to_string(app::Object_ToString(message, nullptr)) << "\n"; + + app::Debug_2_LogWarning(message, method); +} void CreateHooks() { /* @@ -40,6 +66,52 @@ void CreateHooks() { //We can store the original pointer to the original function into test_org if we want to call the org later --> trampoline hook //original_sum can be NULL if we don't want to trampoline hook */ + + // Create the hook for Debug_Log + MH_STATUS status_Debug_Log = MH_CreateHook((LPVOID*)app::Debug_2_Log, &hDebug_Log, reinterpret_cast(&app::Debug_2_Log)); + if (status_Debug_Log != MH_OK) { + std::cout << "Failed to create Debug_Log hook: " << MH_StatusToString(status_Debug_Log) << std::endl; + return; + } + else { + std::cout << "FMH_CreateHook: Debug_Log\n"; + } + + // Enable the hook for Debug_Log + MH_STATUS enable_status_Debug_Log = MH_EnableHook((LPVOID*)app::Debug_2_Log); + if (enable_status_Debug_Log != MH_OK) { + std::cout << "Failed to enable Debug_Log hook: " << MH_StatusToString(enable_status_Debug_Log) << std::endl; + return; + } + + // Create the hook for Debug_Error + MH_STATUS status_Debug_Error = MH_CreateHook((LPVOID*)app::Debug_2_LogError, &hDebug_LogError, reinterpret_cast(&app::Debug_2_LogError)); + if (status_Debug_Error != MH_OK) { + std::cout << "Failed to create Debug_LogError hook: " << MH_StatusToString(status_Debug_Error) << std::endl; + return; + } + + // Enable the hook for Debug_Log + MH_STATUS enable_status_Debug_Error = MH_EnableHook((LPVOID*)app::Debug_2_LogError); + if (enable_status_Debug_Log != MH_OK) { + std::cout << "Failed to enable Debug_Error hook: " << MH_StatusToString(enable_status_Debug_Error) << std::endl; + return; + } + + + // Create the hook for Debug_Warning + MH_STATUS status_Debug_Warning = MH_CreateHook((LPVOID*)app::Debug_2_LogWarning, &hDebug_LogWarning, reinterpret_cast(&app::Debug_2_LogWarning)); + if (status_Debug_Error != MH_OK) { + std::cout << "Failed to create Debug_LogError hook: " << MH_StatusToString(status_Debug_Warning) << std::endl; + return; + } + + // Enable the hook for Debug_Log + MH_STATUS enable_status_Debug_Warning = MH_EnableHook((LPVOID*)app::Debug_2_LogWarning); + if (enable_status_Debug_Log != MH_OK) { + std::cout << "Failed to enable Debug_Warning hook: " << MH_StatusToString(enable_status_Debug_Warning) << std::endl; + return; + } } typedef HRESULT(__stdcall* D3D11PresentHook) (IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags); diff --git a/user/hooks/hooks.hpp b/user/hooks/hooks.hpp index 5939352..c16fb14 100644 --- a/user/hooks/hooks.hpp +++ b/user/hooks/hooks.hpp @@ -12,4 +12,9 @@ bool HookDX11(); void CreateHooks(); bool InitializeHooks(); -void DisableHooks(); \ No newline at end of file +void DisableHooks(); + +void hDebug_Log(app::Object* message, MethodInfo* method); +void hDebug_LogError(app::Object* message, MethodInfo* method); +void hDebug_LogException(app::Exception* exception, MethodInfo* method); +void hDebug_LogWarning(app::Object* message, MethodInfo* method); \ No newline at end of file diff --git a/user/main.cpp b/user/main.cpp index 7610edd..e18db04 100644 --- a/user/main.cpp +++ b/user/main.cpp @@ -13,7 +13,7 @@ #include #include "wrapper.h" -#include "object.h" +#include "ClientHelper.h" #include "hooks/hooks.hpp" @@ -49,6 +49,9 @@ void Run() CreateThread(0, 0, EjectThread, 0, 0, 0); //Unhooking return; } + + CreateHooks(); + if (HookDX11()) { il2cppi_log_write("DirectX11 hooked"); } @@ -58,18 +61,12 @@ void Run() return; } - Wrapper* wrapper = new Wrapper(); while (true) { - if (GetAsyncKeyState(VK_F1) & 0x8000) { - - - } - if (GetAsyncKeyState(VK_END) & 0x8000 || should_unhook) break; - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + std::this_thread::sleep_for(std::chrono::milliseconds(2000)); } CreateThread(0, 0, EjectThread, 0, 0, 0); } \ No newline at end of file