From 7076dc0655c745ce98744d1ac39e40f3ad921963 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Fri, 10 Nov 2023 19:30:51 +0100 Subject: [PATCH 1/2] Silkys2 engine hook --- texthook/engine/engine.cc | 46 ++++++++++++++++++++++++++++++++++++++ texthook/engine/engine.h | 2 +- texthook/engine/match32.cc | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index c2c7abc..88a667e 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -12268,6 +12268,52 @@ bool InsertSilkysHook() return true; } +bool Silkys2Filter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + + WideStringCharReplacer(text, len, L"\\i", 2, L'\''); + + return true; +} + +bool InsertSilkys2Hook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/r89173 + */ + const BYTE bytes[] = { + 0x75, 0x10, // jne doukyuusei.exe+A5F7E + 0x56, // push esi + 0x57, // push edi + 0xE8, XX4 // call doukyuusei.exe+A6120 << hook here + }; + enum { addr_offset = sizeof(bytes) - 5 }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Silkys2: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr + addr_offset; + hp.offset = pusha_edi_off -4; + hp.index = 0; + hp.filter_fun = Silkys2Filter; + hp.type = USING_UNICODE | USING_STRING | NO_CONTEXT; + ConsoleOutput("vnreng: INSERT Silkys2"); + NewHook(hp, "Silkys2"); + return true; +} + +bool InsertSilkysHooks() +{ return InsertSilkysHook() || InsertSilkys2Hook();} + /** jichi 6/1/2014 Eushully * Insert to the last GetTextExtentPoint32A * diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b2..016ffa0 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -141,7 +141,7 @@ bool InsertElfHook(); // elf: Silky.exe bool InsertScenarioPlayerHook();// sol-fa-soft: *.iar && *.sec5 bool InsertSiglusHook(); // SiglusEngine: SiglusEngine.exe bool InsertSideBHook(); // SideB: Copyright side-B -bool InsertSilkysHook(); // SilkysPlus +bool InsertSilkysHooks(); // SilkysPlus bool InsertSyuntadaHook(); // Syuntada: dSoh.dat bool InsertSystem43Hook(); // System43@AliceSoft: AliceStart.ini bool InsertSystemAoiHook(); // SystemAoi: *.vfs diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c7..d57f15f 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -163,7 +163,7 @@ bool DetermineEngineByFile1() // jichi 6/9/2015: Skip Silkys Sakura if ( // Almost the same as Silkys except mes.arc is replaced by Script.arc Util::CheckFile(L"data.arc") && Util::CheckFile(L"effect.arc") && Util::CheckFile(L"Script.arc")) { - InsertSilkysHook(); + InsertSilkysHooks(); return true; } if (Util::CheckFile(L"data\\pack\\*.cpz")) { From 9e0977d31ea4db0bbb1a90c566d5fe01ec5e159a Mon Sep 17 00:00:00 2001 From: Blu3train Date: Fri, 10 Nov 2023 19:39:59 +0100 Subject: [PATCH 2/2] code formatting adjustment --- texthook/engine/engine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index 88a667e..5ead5fb 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -12286,10 +12286,10 @@ bool InsertSilkys2Hook() * https://vndb.org/r89173 */ const BYTE bytes[] = { - 0x75, 0x10, // jne doukyuusei.exe+A5F7E + 0x75, 0x10, // jne doukyuusei.exe+A5F7E 0x56, // push esi 0x57, // push edi - 0xE8, XX4 // call doukyuusei.exe+A6120 << hook here + 0xE8, XX4 // call doukyuusei.exe+A6120 << hook here }; enum { addr_offset = sizeof(bytes) - 5 };