From 435bccd6dad64fdb23b7edc0692e6bf4a5663c38 Mon Sep 17 00:00:00 2001 From: ALittlePatate Date: Sat, 13 Apr 2024 17:18:31 +0200 Subject: [PATCH] fix: Debug_Log hooks, returns System.String tho, wtf --- user/hooks/hooks.cpp | 78 +++++++++++--------------------------------- 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/user/hooks/hooks.cpp b/user/hooks/hooks.cpp index 11f8e42..d6c6164 100644 --- a/user/hooks/hooks.cpp +++ b/user/hooks/hooks.cpp @@ -34,28 +34,13 @@ } */ -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); +typedef void(__stdcall* TDebug_2_Log)(app::Object *, MethodInfo *); +TDebug_2_Log oDebug_2_Log = NULL; +TDebug_2_Log oDebug_2_Warning = NULL; +TDebug_2_Log oDebug_2_Error = NULL; +void __stdcall hDebug_Log(app::Object* message, MethodInfo* method) { + std::string log = il2cppi_to_string(app::Object_ToString(message, nullptr)); + std::cout << log << "\n"; } void CreateHooks() { @@ -67,49 +52,24 @@ void CreateHooks() { //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)); + MH_STATUS status_Debug_Log = MH_CreateHook((LPVOID*)app::Debug_2_Log, &hDebug_Log, reinterpret_cast(&oDebug_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"; + status_Debug_Log = MH_CreateHook((LPVOID*)app::Debug_2_LogError, &hDebug_Log, reinterpret_cast(&oDebug_2_Error)); + if (status_Debug_Log != MH_OK) { + std::cout << "Failed to create Debug_LogError hook: " << MH_StatusToString(status_Debug_Log) << std::endl; + return; } - - // Enable the hook for Debug_Log - MH_STATUS enable_status_Debug_Log = MH_EnableHook((LPVOID*)app::Debug_2_Log); + status_Debug_Log = MH_CreateHook((LPVOID*)app::Debug_2_LogWarning, &hDebug_Log, reinterpret_cast(&oDebug_2_Warning)); + if (status_Debug_Log != MH_OK) { + std::cout << "Failed to create Debug_LogWarning hook: " << MH_StatusToString(status_Debug_Log) << std::endl; + return; + } + MH_STATUS enable_status_Debug_Log = MH_EnableHook(MH_ALL_HOOKS); 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; + std::cout << "Failed to enable Debug_Warning hook: " << MH_StatusToString(enable_status_Debug_Log) << std::endl; return; } }