Skip to content

Circus engine hooks #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions texthook/engine/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5673,6 +5673,89 @@ bool InsertCircusHook2() // jichi 10/2/2013: Change return type to bool
return false;
}

bool InsertCircusHook3()
{
//mod by Blu3train
/*
* Sample games:
* https://vndb.org/v20218
*/
const BYTE bytes[] = {
0xCC, // int 3
0x81, 0xEC, XX4, // sub esp,000004E0 << hook here
0xA1, XX4, // mov eax,[DSIF.EXE+AD288]
0x33, 0xC4, // xor eax,esp
0x89, 0x84, 0x24, XX4, // mov [esp+000004DC],eax
0x8B, 0x84, 0x24, XX4, // mov eax,[esp+000004E4]
0x53, // push ebx
0x55, // push ebp
0x56, // push esi
0x8B, 0xB4, 0x24, XX4 // mov esi,[esp+000004F4]
};
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR);
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range);
if (!addr) {
ConsoleOutput("vnreng:Circus3: pattern not found");
return false;
}

HookParam hp = {};
hp.address = addr + 1;
hp.offset = pusha_esi_off - 4;
hp.split = pusha_ecx_off - 4;
hp.type = USING_STRING | USING_SPLIT;
ConsoleOutput("vnreng: INSERT Circus3");
NewHook(hp, "Circus3");

return true;
}

bool CircusFilter(LPVOID data, DWORD *size, HookParam *, BYTE)
{
auto text = reinterpret_cast<LPSTR>(data);
auto len = reinterpret_cast<size_t *>(size);

//ConsoleOutput("debug:Circus: -%.*s-", *len, text);
if (*len <= 1 || cpp_strnstr(text, "\\", *len) || (text[0] == '&' && text[1] == 'n'))
return false;

CharReplacer(text, len, '\n', ' ');

return true;
}

bool InsertCircusHook4()
{
//mod by Blu3train
/*
* Sample games:
* https://vndb.org/r46909
*/
const BYTE bytes[] = {
0x83, 0xF8, 0xFF, // cmp eax,-01 << hook here
0x0F, 0x84, XX4, // je DST.exe+1BCF0
0x8B, 0x0D, XX4 // mov ecx,[DST.exe+A41F0]
};
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR);
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range);
if (!addr) {
ConsoleOutput("vnreng:Circus4: pattern not found");
return false;
}

HookParam hp = {};
hp.address = addr;
hp.offset = pusha_edx_off - 4;
hp.split = 4 * 4; //arg4
hp.padding = 0x40;
hp.type = USING_STRING | USING_SPLIT;
hp.filter_fun = CircusFilter;
ConsoleOutput("vnreng: INSERT Circus4");
NewHook(hp, "Circus4");

return true;
}

/********************************************************************************************
ShinaRio hook:
Game folder contains rio.ini.
Expand Down
2 changes: 2 additions & 0 deletions texthook/engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ bool InsertWaffleHook(); // WAFFLE: cg.pak
// CIRCUS: avdata/
bool InsertCircusHook1();
bool InsertCircusHook2();
bool InsertCircusHook3();
bool InsertCircusHook4();

} // namespace Engine

Expand Down
4 changes: 2 additions & 2 deletions texthook/engine/match32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ bool DetermineEngineByFile1()
return true;
}
if (Util::CheckFile(L"AdvData\\GRP\\NAMES.DAT")) {
InsertCircusHook2();
return true;
if (InsertCircusHook2() || InsertCircusHook3() || InsertCircusHook4())
return true;
}
if (Util::CheckFile(L"*.noa") || Util::CheckFile(L"data\\*.noa")) {
InsertCotophaHook();
Expand Down