From aa21927716341a67ca0462314d65d5eabaa7c3e7 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Wed, 31 May 2023 20:36:17 +0200 Subject: [PATCH 1/2] Kaleido ADV Workshop engine hooks --- 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..1a23c41 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21728,6 +21728,58 @@ bool InsertNamcoPS2Hook() } #endif // 0 +bool KaleidoFilter(LPVOID data, DWORD *size, HookParam *, BYTE) +{ + auto text = reinterpret_cast(data); + auto len = reinterpret_cast(size); + + // Unofficial eng TL with garbage newline spaces + StringCharReplacer(text, len, " \\n ", 4, ' '); + StringCharReplacer(text, len, " \\n", 3, ' '); + StringCharReplacer(text, len, "\\n", 2, ' '); + StringCharReplacer(text, len, "\xEF\xBC\x9F", 3, '?'); + + return true; +} + +bool InsertKaleidoHook() +{ + //by Blu3train + /* + * Sample games: + * https://vndb.org/v29889 + */ + const BYTE bytes[] = { + 0xFF, 0x75, 0xD4, // push [ebp-2C] + 0xE8, XX4, // call 5toubun.exe+1DD0 + 0x83, 0xC4, 0x0C, // add esp,0C + 0x8A, 0xC3, // mov al,bl + 0x8B, 0x4D, 0xF4, // mov ecx,[ebp-0C] + 0x64, 0x89, 0x0D, XX4, // mov fs:[00000000],ecx + 0x59 // pop ecx << hook here + }; + enum { addr_offset = sizeof(bytes) - 1 }; + + ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); + ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); + if (!addr) { + ConsoleOutput("vnreng:Kaleido: pattern not found"); + return false; + } + + HookParam hp = {}; + hp.address = addr + addr_offset; + hp.offset = pusha_esi_off -4; + hp.index = 0; + hp.split = 0x0C; + hp.split_index = 0; + hp.type = USING_STRING | USING_SPLIT ; + hp.filter_fun = KaleidoFilter; + ConsoleOutput("vnreng: INSERT Kaleido"); + NewHook(hp, "Kaleido"); + return true; +} + } // namespace Engine // EOF diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 5e167b2..14b5016 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 InsertKaleidoHook(); // Kaleido ADV Workshop: windata/script_body.bin // CIRCUS: avdata/ bool InsertCircusHook1(); diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index fffc4c7..a715cfa 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -370,6 +370,10 @@ bool DetermineEngineByFile3() bool DetermineEngineByFile4() { + if (Util::CheckFile(L"windata/script_body.bin")) { + if (InsertKaleidoHook()) + return true; + } if (Util::CheckFile(L"EAGLS.dll")) { // jichi 3/24/2014: E.A.G.L.S //ConsoleOutput("vnreng: IGNORE EAGLS"); InsertEaglsHook(); From 2ddc7830827c40a8e2fadf398d55dc82600d6433 Mon Sep 17 00:00:00 2001 From: Blu3train Date: Fri, 2 Jun 2023 10:42:39 +0200 Subject: [PATCH 2/2] Modified for compatibility with Japanese language --- 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 1a23c41..ca2bea8 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -21737,7 +21737,6 @@ bool KaleidoFilter(LPVOID data, DWORD *size, HookParam *, BYTE) StringCharReplacer(text, len, " \\n ", 4, ' '); StringCharReplacer(text, len, " \\n", 3, ' '); StringCharReplacer(text, len, "\\n", 2, ' '); - StringCharReplacer(text, len, "\xEF\xBC\x9F", 3, '?'); return true; } @@ -21748,6 +21747,7 @@ bool InsertKaleidoHook() /* * Sample games: * https://vndb.org/v29889 + * https://vndb.org/r56675 */ const BYTE bytes[] = { 0xFF, 0x75, 0xD4, // push [ebp-2C] @@ -21773,7 +21773,7 @@ bool InsertKaleidoHook() hp.index = 0; hp.split = 0x0C; hp.split_index = 0; - hp.type = USING_STRING | USING_SPLIT ; + hp.type = USING_UTF8 | USING_STRING | USING_SPLIT ; hp.filter_fun = KaleidoFilter; ConsoleOutput("vnreng: INSERT Kaleido"); NewHook(hp, "Kaleido");