From 2be920c50ebf3f481e13032eab26b3cf26b80ee8 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 5 Mar 2020 02:19:04 -0700 Subject: [PATCH] cleaner output for mono --- include/const.h | 1 + texthook/engine/engine.cc | 5 +++-- texthook/engine/match64.cc | 6 ++++-- texthook/texthook.cc | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/const.h b/include/const.h index 47569a4..4bc9ca8 100644 --- a/include/const.h +++ b/include/const.h @@ -30,4 +30,5 @@ enum HookParamType : unsigned HEX_DUMP = 0x4000, HOOK_ENGINE = 0x8000, HOOK_ADDITIONAL = 0x10000, + KNOWN_UNSTABLE = 0x20000, }; diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index 7e5cd9a..d4636b9 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -16734,10 +16734,12 @@ void InsertMonoHook(HMODULE h) HookParam hp = {}; hp.address = addr; hp.type = USING_UNICODE | FULL_STRING; + if (!loadedConfig) hp.type |= KNOWN_UNSTABLE; hp.offset = 4; char nameForUser[HOOK_NAME_SIZE] = {}; strncpy_s(nameForUser, name + 1, HOOK_NAME_SIZE - 1); if (char* end = strstr(nameForUser, " + 0x0")) *end = 0; + if (char* end = strstr(nameForUser, "{")) *end = 0; hp.text_fun = [](DWORD esp_base, HookParam*, BYTE, DWORD* data, DWORD* split, DWORD* len) { MonoString* string = (MonoString*)argof(1, esp_base); @@ -16750,8 +16752,7 @@ void InsertMonoHook(HMODULE h) __except (EXCEPTION_EXECUTE_HANDLER) {} }(addr); } - if (!loadedConfig) ConsoleOutput("Textractor: Mono Dynamic used brute force: if performance issues arise, please create a TextractorConfig.txt file" - "next to the main executable and put the name of a working hook inside it"); + if (!loadedConfig) ConsoleOutput("Textractor: Mono Dynamic used brute force: if performance issues arise, please specify the correct hook in the game configuration"); return true; failed: ConsoleOutput("Textractor: Mono Dynamic failed"); diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index df4df1e..fc61a31 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -98,11 +98,13 @@ namespace Engine HookParam hp = {}; hp.address = addr; hp.type = USING_STRING | USING_UNICODE | FULL_STRING; + if (!loadedConfig) hp.type |= KNOWN_UNSTABLE; hp.offset = -0x20; // rcx hp.padding = 20; char nameForUser[HOOK_NAME_SIZE] = {}; strncpy_s(nameForUser, name + 1, HOOK_NAME_SIZE - 1); if (char* end = strstr(nameForUser, " + 0x0")) *end = 0; + if (char* end = strstr(nameForUser, "{")) *end = 0; hp.length_fun = [](uintptr_t, uintptr_t data) { /* Artikash 6/18/2019: @@ -117,8 +119,8 @@ namespace Engine __except (EXCEPTION_EXECUTE_HANDLER) {} }(addr); } - if (!loadedConfig) ConsoleOutput("Textractor: Mono Dynamic used brute force: if performance issues arise, please create a TextractorConfig.txt file" - "next to the main executable and put the name of a working hook inside it"); + + if (!loadedConfig) ConsoleOutput("Textractor: Mono Dynamic used brute force: if performance issues arise, please specify the correct hook in the game configuration"); return true; failed: ConsoleOutput("Textractor: Mono Dynamic failed"); diff --git a/texthook/texthook.cc b/texthook/texthook.cc index 9fdaa81..a41a399 100644 --- a/texthook/texthook.cc +++ b/texthook/texthook.cc @@ -201,7 +201,7 @@ void TextHook::Send(uintptr_t dwDataBase) } __except (EXCEPTION_EXECUTE_HANDLER) { - if (!err) + if (!err && !(hp.type & KNOWN_UNSTABLE)) { err = true; ConsoleOutput("%s in %s", SEND_ERROR, hp.name); @@ -222,6 +222,7 @@ bool TextHook::InsertHookCode() else if (HMODULE moduleBase = GetModuleHandleW(hp.module)) address += (uint64_t)moduleBase; else return ConsoleOutput(MODULE_MISSING), false; + VirtualProtect(location, 10, PAGE_EXECUTE_READWRITE, DUMMY); void* original; MH_STATUS error; while ((error = MH_CreateHook(location, trampoline, &original)) != MH_OK)