From bb84c63332be43f4d2b2b14b3fe9efefdb9ba17a Mon Sep 17 00:00:00 2001 From: Blu3train Date: Tue, 22 Aug 2023 19:32:27 +0200 Subject: [PATCH] YaneSDK engine hook --- texthook/engine/engine.cc | 61 ++++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 1 + texthook/engine/match32.cc | 4 +++ 3 files changed, 66 insertions(+) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c2c7abc..bce71f0 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21728,6 +21728,67 @@ bool InsertNamcoPS2Hook() } #endif // 0 +bool YaneSDKFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + static std::wstring prevText; + + if (!*len) + return false; + text[*len/sizeof(wchar_t)] = L'\0'; // clean text + + if (!prevText.compare(text)) + return false; + prevText = text; + + WideStringCharReplacer(text, len, L"[r]", 3, L' '); + WideStringFilter(text, len, L"[np]", 4); + + if (cpp_wcsnstr(text, L"'", *len/sizeof(wchar_t))) { // [桜木'さくらぎ] + WideStringFilterBetween(text, len, L"'", 1, L"]", 1); + } + WideCharFilter(text, len, L'['); + WideCharFilter(text, len, L']'); + + return true; +} + +bool InsertYaneSDKHook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/v21734 + * https://vndb.org/v21455 + * https://vndb.org/v20406 + */ + const BYTE bytes[] = { + 0x83, 0xF9, 0x08, // cmp ecx,08 << hook here + 0x8D, 0x45, 0x0C, // lea eax,[ebp+0C] + 0x8D, 0x4D, 0xBC, // lea ecx,[ebp-44] + 0x0F, 0x43, 0xC2, // cmovae eax,edx + 0x0F, 0xB7, 0x04, 0x70 // movzx eax,word ptr [eax+esi*2] + }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:YaneSDK: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr; + hp.offset = pusha_eax_off -4; + hp.index = 0; + hp.filter_fun = YaneSDKFilter; + hp.type = USING_UNICODE | USING_STRING | NO_CONTEXT; + ConsoleOutput("vnreng: INSERT YaneSDK"); + NewHook(hp, "YaneSDK"); + return true; +} + } // namespace Engine // EOF diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b2..0849318 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 InsertYaneSDKHook(); // YaneSDK: arc/evimage.dat 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..a621e55 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -370,6 +370,10 @@ bool DetermineEngineByFile3() bool DetermineEngineByFile4() { + if (Util::CheckFile(L"arc/evimage.dat")) { + if (InsertYaneSDKHook()) + return true; + } if (Util::CheckFile(L"EAGLS.dll")) { // jichi 3/24/2014: E.A.G.L.S //ConsoleOutput("vnreng: IGNORE EAGLS"); InsertEaglsHook();