From 1b718a760ced7fa35385f09d8ac18d843f152264 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Sun, 17 Dec 2023 19:20:35 +0100 Subject: [PATCH] Anim3 engine hook --- texthook/engine/engine.cc | 50 ++++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 3 +++ texthook/engine/match32.cc | 4 +++ 3 files changed, 57 insertions(+) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c2c7abc6..bdc92b61 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -17073,6 +17073,56 @@ bool NoAsciiFilter(LPVOID data, DWORD *size, HookParam *, BYTE) return false; } +bool Anim3Filter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + + StringFilterBetween(text, len, "\x81\x40", 2, "@m", 2); // @r(2,はと) + StringFilterBetween(text, len, "\x81\x40", 2, "@n", 2); // @r(2,はと) + StringCharReplacer(text, len, "@b", 2, ' '); + StringCharReplacer(text, len, "\x81\x42", 2, '.'); + StringCharReplacer(text, len, "\x81\x48", 2, '?'); + StringCharReplacer(text, len, "\x81\x49", 2, '!'); + + return true; +} + +bool InsertAnim3Hook() +{ + //mod by Blu3train + /* + * Sample games: + * https://vndb.org/v17427 + * https://vndb.org/v18837 + */ + const BYTE bytes[] = { + 0xCC, // int 3 + 0x55, // push ebp << hook here + 0x8B, 0xEC, // mov ebp,esp + 0x81, 0xEC, XX4, // sub esp,00000830 + 0xA1, XX4, // mov eax,[musu_mama.exe+A91F0] + 0x33, 0xC5, // xor eax,ebp + 0x89, 0x45, 0xE8 // mov [ebp-18],eax + }; + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Anim3: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr + 1; + hp.offset = pusha_edx_off - 4; + hp.type = USING_STRING; + hp.filter_fun = Anim3Filter; + ConsoleOutput("vnreng: INSERT Anim3"); + NewHook(hp, "Anim3"); + + return true; +} + bool InsertMonoHooks() { HMODULE h = ::GetModuleHandleA("mono.dll"); diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b25..094c4f46 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -170,6 +170,9 @@ bool InsertWaffleHook(); // WAFFLE: cg.pak bool InsertCircusHook1(); bool InsertCircusHook2(); +// Anim engines +bool InsertAnim3Hook(); + } // namespace Engine // EOF diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c76..13ff4af2 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -435,6 +435,10 @@ bool DetermineEngineByFile4() return true; } + if (Util::CheckFile(L"voice\\*.pck")) { + return /*InsertAnimHook() || InsertAnim2Hook() ||*/ InsertAnim3Hook(); + } + // jichi 11/22/2015: 凍京NECRO 体験版 // Jazzinghen 23/05/2020: Add check for 凍京NECRO // ResEdit shows multiple potential strings: