From 001ce8d61681d4c4df97e857449d0cae59bb8ceb Mon Sep 17 00:00:00 2001 From: Blu3train Date: Sat, 28 Oct 2023 11:16:56 +0200 Subject: [PATCH] Kid engine hook --- texthook/engine/engine.cc | 52 ++++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 1 + texthook/engine/match32.cc | 4 +++ 3 files changed, 57 insertions(+) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c2c7abc..1bfe477 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21728,6 +21728,58 @@ bool InsertNamcoPS2Hook() } #endif // 0 +bool KidFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + static std::string prevText; + + if (LPSTR endText=cpp_strnstr(text, "\x02\x03", *len)) { + *endText = '\0'; + *len = endText - text; + } + CharReplacer(text, len, '\x01', ' '); + StringReplacer(text, len, "\x87\x4c", 2, "--", 2); + + if (prevText.find(text, 0, *len) != std::string::npos) // Check if the string is present in the previous one + return false; + prevText.assign(text, *len); + + return true; +} + +bool InsertKidHook() { + //by Blu3train + /* + * Sample games: + * https://vndb.org/r60521 + */ + const BYTE bytes[] = { + 0xBF, 0x01, 0x00, 0x00, 0x00, // mov edi,00000001 <- hook here + 0x8A, 0x08, // mov cl,[eax] + 0x40, // inc eax + 0xF6, 0xC1, 0x80 // test cl,-80 + }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Kid: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr; + hp.offset = pusha_eax_off -4; + hp.index = 0; + hp.type = USING_STRING; + hp.filter_fun = KidFilter; + ConsoleOutput("vnreng: INSERT Kid"); + NewHook(hp, "Kid"); + + return true; +} + } // namespace Engine // EOF diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b2..aa35065 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -156,6 +156,7 @@ bool InsertWillPlusHook(); // WillPlus: Rio.arc bool InsertWolfHook(); // Wolf: Data.wolf bool InsertYukaSystem2Hook(); // YukaSystem2: *.ykc bool InsertYurisHook(); // YU-RIS: *.ypf +bool InsertKidHook(); // Kid: resource string void InsertBrunsHook(); // Bruns: bruns.exe void InsertIronGameSystemHook();// IroneGameSystem: igs_sample.exe diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c7..8952cdb 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -370,6 +370,10 @@ bool DetermineEngineByFile3() bool DetermineEngineByFile4() { + if (Util::SearchResourceString(L" KID")) { + if (InsertKidHook()) + return true; + } if (Util::CheckFile(L"EAGLS.dll")) { // jichi 3/24/2014: E.A.G.L.S //ConsoleOutput("vnreng: IGNORE EAGLS"); InsertEaglsHook();