From 1cf40e1082a97403385388304a0ade95138b928f Mon Sep 17 00:00:00 2001 From: Blu3train Date: Fri, 21 Apr 2023 18:40:02 +0200 Subject: [PATCH 1/2] DMM engine hooks --- texthook/engine/engine.cc | 97 ++++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 2 + texthook/engine/match32.cc | 4 ++ 3 files changed, 103 insertions(+) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index 61d5140..f282db9 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21728,6 +21728,103 @@ bool InsertNamcoPS2Hook() } #endif // 0 +bool DmmFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + StringCharReplacer(text, len, "\\n", 2, ' '); + StringCharReplacer(text, len, "\\k", 2, ' '); + + if (cpp_strnstr(text, "{W", *len)) { + StringFilterBetween(text, len, "{", 1, "}", 1); + } + return true; +} + +bool InsertDmm1Hook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/r76933 + * https://vndb.org/v18717 + */ + bool found = false; + const BYTE pattern[] = { + 0x8A, 0x02, + 0x42, + 0x84, 0xC0, + 0x75, 0xF9, + 0x2B, 0xD6, + 0x8D, 0xBB, XX4, + 0x8A, 0x47, 0x01, + 0x47, + 0x84, 0xC0, + 0x75, 0xF8, + 0x8B, 0xCA, + 0xC1, 0xE9, 0x02, // <-- + 0xF3, 0xA5, + 0x8B, 0xCA + }; + enum { addr_offset = 25 }; + + for (auto addr : Util::SearchMemory(pattern, sizeof(pattern), PAGE_EXECUTE, processStartAddress, processStopAddress)) + { + HookParam hp = {}; + hp.address = addr+addr_offset; + hp.offset = pusha_esi_off - 4; + hp.codepage = 65001; + hp.type = USING_STRING | NO_CONTEXT; + hp.filter_fun = DmmFilter; + ConsoleOutput("Textractor: INSERT DMM1"); + NewHook(hp, "DMM1"); + found = true; + } + if (!found) ConsoleOutput("Textractor:DMM1: pattern not found"); + return found; +} + +bool InsertDmm2Hook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/r76933 + */ + bool found = false; + const BYTE pattern[] = { + 0x52, + 0xFF, 0x71, 0x24, + 0x50, + 0xFF, 0xB7, 0x38, 0x02, 0x00, 0x00, + 0xE8, 0x17, 0x66, 0xFF, 0xFF, + 0x5F, // <-- + 0xB0, 0x01, + 0x5E, + 0xC3, + 0x51 + }; + enum { addr_offset = 16 }; + + for (auto addr : Util::SearchMemory(pattern, sizeof(pattern), PAGE_EXECUTE, processStartAddress, processStopAddress)) + { + HookParam hp = {}; + hp.address = addr+addr_offset; + hp.offset = pusha_ebp_off - 4; + hp.codepage = 65001; + hp.type = USING_STRING | NO_CONTEXT; + hp.filter_fun = DmmFilter; + ConsoleOutput("Textractor: INSERT DMM2"); + NewHook(hp, "DMM2"); + found = true; + } + if (!found) ConsoleOutput("Textractor:DMM2: pattern not found"); + return found; +} + +bool InsertDmmHooks() +{ return InsertDmm1Hook() || InsertDmm2Hook();} + } // namespace Engine // EOF diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index e8e401e..ff308d1 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -170,6 +170,8 @@ bool InsertWaffleHook(); // WAFFLE: cg.pak bool InsertCircusHook1(); bool InsertCircusHook2(); +bool InsertDmmHooks(); // DMM: Data/Exi_UT2.sdat + } // namespace Engine // EOF diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c7..c27a881 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -370,6 +370,10 @@ bool DetermineEngineByFile3() bool DetermineEngineByFile4() { + if (Util::CheckFile(L"Data/Exi_UT2.sdat")) { + if (InsertDmmHooks()) + return true; + } if (Util::CheckFile(L"EAGLS.dll")) { // jichi 3/24/2014: E.A.G.L.S //ConsoleOutput("vnreng: IGNORE EAGLS"); InsertEaglsHook(); From 82a885102da464553da34e7b0fd9fb4b53f0b59c Mon Sep 17 00:00:00 2001 From: Blu3train Date: Fri, 21 Apr 2023 23:22:15 +0200 Subject: [PATCH 2/2] DMM engine hooks fix --- texthook/engine/engine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index f282db9..135f31b 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21735,7 +21735,7 @@ bool DmmFilter(LPVOID data, DWORD *size, HookParam *, BYTE) StringCharReplacer(text, len, "\\n", 2, ' '); StringCharReplacer(text, len, "\\k", 2, ' '); - if (cpp_strnstr(text, "{W", *len)) { + if (cpp_strnstr(text, "{", *len)) { StringFilterBetween(text, len, "{", 1, "}", 1); } return true;