From a3b15d870187d40696f8bbde42cfc0e06af233b4 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Sun, 30 Apr 2023 00:28:20 +0200 Subject: [PATCH] Minori engine hooks --- texthook/engine/engine.cc | 122 +++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 1 + texthook/engine/match32.cc | 4 ++ 3 files changed, 127 insertions(+) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c2c7abc..45de08a 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21728,6 +21728,128 @@ bool InsertNamcoPS2Hook() } #endif // 0 +bool Minori1EngFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + StringCharReplacer(text, len, "\\n", 2, ' '); + StringFilter(text, len, "\\a", 2); + StringFilter(text, len, "\\v", 2); + CharReplacer(text, len, '\xC4', '-'); + CharReplacer(text, len, '\x93', '"'); + CharReplacer(text, len, '\x94', '"'); + CharReplacer(text, len, '\x92', '\''); + StringCharReplacer(text, len, "\\I", 2, '\''); + StringCharReplacer(text, len, "\\P", 2, '\''); + + return true; +} + +bool Minori1JapFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + StringFilter(text, len, "\\a", 2); + StringFilter(text, len, "\\v", 2); + StringFilter(text, len, "\\N", 2); + + if (cpp_strnstr(text, "{", *len)) { + StringFilterBetween(text, len, "{", 1, "}", 1); + } + + return true; +} + +bool InsertMinori1Hook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/v19644 + * https://vndb.org/v12562 + */ + const BYTE bytes[] = { + 0x84, 0xC0, // test al,al << hook here + 0x0F, 0x85, XX4, // jne trinoline_en_AA.exe+243E1 + 0x68, XX4, // push trinoline_en_AA.exe+118BF8 << alt eng hook + 0x33, 0xFF // xor edi,edi + }; + enum { alt_addr_offset = 8 }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Minori1: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr; + hp.offset = pusha_edx_off -4; + hp.codepage = 932; + hp.type = USING_STRING; + hp.filter_fun = Minori1JapFilter; + ConsoleOutput("vnreng: INSERT Minori1"); + NewHook(hp, "Minori1"); + + const BYTE bytes2[] = { + 0x84, 0xC0, // test al,al + 0x0F, 0x85, XX4, // jne trinoline_en_AA.exe+243E1 + 0x68, XX4, // push trinoline_en_AA.exe+118BF8 + 0x33, 0xFF // xor edi,edi + }; + ULONG addr2 = MemDbg::findBytes(bytes2, sizeof(bytes2), processStartAddress, processStartAddress + range); + if (addr) { + HookParam hp = {}; + hp.address = addr + alt_addr_offset; + hp.offset = pusha_edx_off -4; + hp.type = USING_STRING; + hp.filter_fun = Minori1EngFilter; + ConsoleOutput("vnreng: INSERT Minori1eng"); + NewHook(hp, "Minori1eng"); + } + + return true; +} + +bool InsertMinori2Hook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/v35 + */ + const BYTE bytes[] = { + 0x80, 0x38, 0x00, // cmp byte ptr [eax],00 + 0x0F, 0x84, XX4, // je WindRP.exe+2832A + 0xB8, 0x20, 0x03, 0x00, 0x00, // mov eax,00000320 + 0x89, 0x44, 0x24, 0x10, // mov [esp+10],eax + 0x89, 0x44, 0x24, 0x14, // mov [esp+14],eax + 0x8B, 0x47, 0x20 // mov eax,[edi+20] + }; + enum { addr_offset = 0 }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Minori2: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr + addr_offset; + hp.offset = pusha_eax_off -4; + hp.index = 0; + hp.length_offset = 1; + hp.type = NO_CONTEXT | DATA_INDIRECT; + ConsoleOutput("vnreng: INSERT Minori2"); + NewHook(hp, "Minori2"); + return true; +} + +bool InsertMinoriHooks() +{ return InsertMinori1Hook() || InsertMinori2Hook();} + } // namespace Engine // EOF diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b2..620916c 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -165,6 +165,7 @@ void InsertRealliveHook(); // RealLive: RealLive*.exe void InsertStuffScriptHook(); // Stuff: *.mpk bool InsertTinkerBellHook(); // TinkerBell: arc00.dat bool InsertWaffleHook(); // WAFFLE: cg.pak +bool InsertMinoriHooks(); // Minori: *.paz // CIRCUS: avdata/ bool InsertCircusHook1(); diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c7..297720c 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -370,6 +370,10 @@ bool DetermineEngineByFile3() bool DetermineEngineByFile4() { + if (Util::CheckFile(L"*.paz")) { + if (InsertMinoriHooks()) + return true; + } if (Util::CheckFile(L"EAGLS.dll")) { // jichi 3/24/2014: E.A.G.L.S //ConsoleOutput("vnreng: IGNORE EAGLS"); InsertEaglsHook();