1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-28 00:10:51 +01:00

jbhook1: If gfx.vertical is set, rotate error messages too

By hooking CreateProcessA, we can adjust the commandline to
disable any rotation, which displays the error box at the correct
place on screen (no additional x/y adjustment is needed)
This commit is contained in:
Will Toohey 2023-06-20 12:35:28 +10:00 committed by icex2
parent 9ce47e7050
commit 3bff7f8a5e

View File

@ -47,6 +47,29 @@ my_mwindow_create(HINSTANCE, void *, const char *, DWORD, DWORD, BOOL);
static HWND(CDECL *real_mwindow_create)( static HWND(CDECL *real_mwindow_create)(
HINSTANCE, void *, const char *, DWORD, DWORD, BOOL); HINSTANCE, void *, const char *, DWORD, DWORD, BOOL);
static BOOL STDCALL my_CreateProcessA(
LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
static BOOL(STDCALL *real_CreateProcessA)(
LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
static const struct hook_symbol init_hook_syms[] = { static const struct hook_symbol init_hook_syms[] = {
{ {
.name = "mwindow_create", .name = "mwindow_create",
@ -55,6 +78,17 @@ static const struct hook_symbol init_hook_syms[] = {
}, },
}; };
static const struct hook_symbol kernel32_hook_syms[] = {
{
.name = "CreateProcessA",
.patch = my_CreateProcessA,
.link = (void **) &real_CreateProcessA,
},
};
// so our CreateProcessA hook can check
static bool vertical;
/** /**
* This seems to be a good entry point to intercept before the game calls * This seems to be a good entry point to intercept before the game calls
* anything important (very close to the start of WinMain). * anything important (very close to the start of WinMain).
@ -107,6 +141,7 @@ static HWND CDECL my_mwindow_create(
jbhook1_log_gftools_init(); jbhook1_log_gftools_init();
fullscreen = !config_gfx.windowed; fullscreen = !config_gfx.windowed;
vertical = config_gfx.vertical;
if (config_gfx.vertical) { if (config_gfx.vertical) {
DWORD tmp = window_width; DWORD tmp = window_width;
@ -175,9 +210,53 @@ BOOL WINAPI DllMain(HMODULE mod, DWORD reason, void *ctx)
/* Actual hooks for game specific stuff */ /* Actual hooks for game specific stuff */
hook_table_apply(
NULL,
"kernel32.dll",
kernel32_hook_syms,
lengthof(kernel32_hook_syms));
acp_hook_init(); acp_hook_init();
adapter_hook_init(); adapter_hook_init();
} }
return TRUE; return TRUE;
} }
static BOOL STDCALL my_CreateProcessA(
LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)
{
LPSTR rot_arg;
// de-rotate the error window if needed. In theory this should parse the
// commandline properly, in practice this works on all the .exe jubeats.
if (vertical && lpCommandLine) {
if ((rot_arg = strstr(lpCommandLine, " -R90 "))) { // jubeat 01
memcpy(rot_arg, " -R0 ", strlen(" -R0 "));
} else if ((rot_arg =
strstr(lpCommandLine, " -rot:90 "))) { // jubeat 02
memcpy(rot_arg, " -rot:0 ", strlen(" -rot:0 "));
}
}
return real_CreateProcessA(
lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags,
lpEnvironment,
lpCurrentDirectory,
lpStartupInfo,
lpProcessInformation);
}