improve renpy detection

This commit is contained in:
Akash Mozumdar 2021-03-08 08:41:50 -07:00
parent acc85f3a86
commit 1bab6956a8
2 changed files with 72 additions and 24 deletions

View File

@ -16896,30 +16896,34 @@ bool InsertAdobeFlash10Hook()
*/ */
bool InsertRenpyHook() bool InsertRenpyHook()
{ {
for (int pythonMinorVersion = 0; pythonMinorVersion <= 8; ++pythonMinorVersion) wchar_t python[] = L"python2X.dll", libpython[] = L"libpython2.X.dll";
{ for (wchar_t* name : { python, libpython })
wchar_t python[] = L"python2X.dll"; {
python[7] = L'0' + pythonMinorVersion; wchar_t* pos = wcschr(name, L'X');
if (HMODULE module = GetModuleHandleW(python)) for (int pythonMinorVersion = 0; pythonMinorVersion <= 8; ++pythonMinorVersion)
{ {
wcscpy_s(spDefault.exportModule, python); *pos = L'0' + pythonMinorVersion;
HookParam hp = {}; if (HMODULE module = GetModuleHandleW(name))
hp.address = (DWORD)GetProcAddress(module, "PyUnicodeUCS2_Format"); {
if (!hp.address) wcscpy_s(spDefault.exportModule, name);
{ HookParam hp = {};
ConsoleOutput("Textractor: Ren'py failed: failed to find PyUnicodeUCS2_Format"); hp.address = (DWORD)GetProcAddress(module, "PyUnicodeUCS2_Format");
return false; if (!hp.address)
} {
hp.offset = 4; ConsoleOutput("Textractor: Ren'py failed: failed to find PyUnicodeUCS2_Format");
hp.index = 0xc; return false;
hp.length_offset = 0; }
hp.split = pusha_ebx_off - 4; hp.offset = 4;
hp.type = USING_STRING | USING_UNICODE | NO_CONTEXT | DATA_INDIRECT | USING_SPLIT; hp.index = 0xc;
//hp.filter_fun = [](void* str, auto, auto, auto) { return *(wchar_t*)str != L'%'; }; hp.length_offset = 0;
NewHook(hp, "Ren'py"); hp.split = pusha_ebx_off - 4;
return true; hp.type = USING_STRING | USING_UNICODE | NO_CONTEXT | DATA_INDIRECT | USING_SPLIT;
} //hp.filter_fun = [](void* str, auto, auto, auto) { return *(wchar_t*)str != L'%'; };
} NewHook(hp, "Ren'py");
return true;
}
}
}
ConsoleOutput("Textractor: Ren'py failed: failed to find python2X.dll"); ConsoleOutput("Textractor: Ren'py failed: failed to find python2X.dll");
return false; return false;
} }

View File

@ -154,6 +154,48 @@ namespace Engine
return false; return false;
} }
/** Artikash 8/10/2018: Ren'py
*
* Sample games: https://vndb.org/v19843 https://vndb.org/v12038 and many more OELVNs
*
* Uses CPython, and links to python27.dll. PyUicodeUCS2_Format is the function used to process text.
* first argument. offset 0x18 from that is a wchar_t* to the actual string
* ebx seems to work well as the split param, not sure why
*/
bool InsertRenpyHook()
{
wchar_t python[] = L"python2X.dll", libpython[] = L"libpython2.X.dll";
for (wchar_t* name : { python, libpython })
{
wchar_t* pos = wcschr(name, L'X');
for (int pythonMinorVersion = 0; pythonMinorVersion <= 8; ++pythonMinorVersion)
{
*pos = L'0' + pythonMinorVersion;
if (HMODULE module = GetModuleHandleW(name))
{
wcscpy_s(spDefault.exportModule, name);
HookParam hp = {};
hp.address = (DWORD)GetProcAddress(module, "PyUnicodeUCS2_Format");
if (!hp.address)
{
ConsoleOutput("Textractor: Ren'py failed: failed to find PyUnicodeUCS2_Format");
return false;
}
hp.offset = -0x20; // rcx
hp.index = 0x18;
hp.length_offset = 0;
//hp.split = pusha_ebx_off - 4;
hp.type = USING_STRING | USING_UNICODE | NO_CONTEXT | DATA_INDIRECT /* | USING_SPLIT*/;
//hp.filter_fun = [](void* str, auto, auto, auto) { return *(wchar_t*)str != L'%'; };
NewHook(hp, "Ren'py");
return true;
}
}
}
ConsoleOutput("Textractor: Ren'py failed: failed to find python2X.dll");
return false;
}
bool UnsafeDetermineEngineType() bool UnsafeDetermineEngineType()
{ {
if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true; if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true;
@ -168,6 +210,8 @@ namespace Engine
return true; return true;
} }
if (Util::CheckFile(L"*.py") && InsertRenpyHook()) return true;
for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll" }) if (HMODULE module = GetModuleHandleW(monoName)) if (InsertMonoHooks(module)) return true; for (const wchar_t* monoName : { L"mono.dll", L"mono-2.0-bdwgc.dll" }) if (HMODULE module = GetModuleHandleW(monoName)) if (InsertMonoHooks(module)) return true;
for (std::wstring DXVersion : { L"d3dx9", L"d3dx10" }) for (std::wstring DXVersion : { L"d3dx9", L"d3dx10" })