From 4cc81f48f3048ab63de52b71ca11c8df344853e4 Mon Sep 17 00:00:00 2001 From: QCDLZCLW3K <1329-33c17f40@users.noreply.dev.s-ul.net> Date: Thu, 19 May 2022 13:29:01 +0900 Subject: [PATCH] ddr: Fix windowed mode regressions --- src/main/ddrhook-util/gfx.c | 20 ++++++++++++++++++-- src/main/ddrhook-util/gfx.h | 3 +++ src/main/ddrhook-util/misc.c | 19 +++++++++++++++++++ src/main/ddrhook1/master.c | 2 ++ src/main/ddrhook2/dllmain.c | 10 ++++------ src/main/ddrhook2/master.c | 7 +++++++ 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/main/ddrhook-util/gfx.c b/src/main/ddrhook-util/gfx.c index 5748547..1a93c35 100644 --- a/src/main/ddrhook-util/gfx.c +++ b/src/main/ddrhook-util/gfx.c @@ -35,8 +35,9 @@ static BOOL STDCALL my_SetWindowPos( HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); static bool gfx_windowed; +static bool gfx_is_modern; -static const struct hook_symbol misc_user32_syms[] = { +static const struct hook_symbol gfx_user32_syms[] = { { .name = "ChangeDisplaySettingsExA", .patch = my_ChangeDisplaySettingsExA, @@ -121,6 +122,11 @@ static LONG STDCALL my_SetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong) static BOOL STDCALL my_SetWindowPos( HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) { + // Causes DDR A to have a really wide window + if (gfx_get_is_modern()) { + return true; + } + if (gfx_get_windowed()) { WINDOWPOS wp; @@ -138,7 +144,7 @@ static BOOL STDCALL my_SetWindowPos( void gfx_insert_hooks(HMODULE target) { hook_table_apply( - target, "user32.dll", misc_user32_syms, lengthof(misc_user32_syms)); + target, "user32.dll", gfx_user32_syms, lengthof(gfx_user32_syms)); log_info("Initialized d3d9 hooks"); } @@ -153,6 +159,16 @@ void gfx_set_windowed(void) gfx_windowed = true; } +bool gfx_get_is_modern(void) +{ + return gfx_is_modern; +} + +void gfx_set_is_modern(void) +{ + gfx_is_modern = true; +} + /* ------------------------------------------------------------------------- */ static void gfx_d3d9_patch_window(struct hook_d3d9_irp *irp) diff --git a/src/main/ddrhook-util/gfx.h b/src/main/ddrhook-util/gfx.h index 85611d7..ec79ad6 100644 --- a/src/main/ddrhook-util/gfx.h +++ b/src/main/ddrhook-util/gfx.h @@ -13,6 +13,9 @@ struct ddrhook1_d3d9_config { bool gfx_get_windowed(void); void gfx_set_windowed(void); +bool gfx_get_is_modern(void); +void gfx_set_is_modern(void); + void gfx_d3d9_calc_win_size_with_framed( HWND hwnd, DWORD x, DWORD y, DWORD width, DWORD height, LPWINDOWPOS wp); diff --git a/src/main/ddrhook-util/misc.c b/src/main/ddrhook-util/misc.c index cd0cc59..b74c8de 100644 --- a/src/main/ddrhook-util/misc.c +++ b/src/main/ddrhook-util/misc.c @@ -13,6 +13,7 @@ static LRESULT(STDCALL *real_SendMessageW)( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); + static HWND(STDCALL *real_CreateWindowExW)( DWORD dwExStyle, LPCWSTR lpClassName, @@ -30,6 +31,7 @@ static HWND(STDCALL *real_CreateWindowExW)( static SHORT STDCALL my_GetKeyState(int vk); static LRESULT STDCALL my_SendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); + static HWND STDCALL my_CreateWindowExA( DWORD dwExStyle, LPCSTR lpClassName, @@ -92,6 +94,23 @@ static HWND STDCALL my_CreateWindowExW( HINSTANCE hInstance, LPVOID lpParam) { + // This breaks DDR X, X2 and X3 + if (gfx_get_is_modern()) { + return real_CreateWindowExW( + dwExStyle, + lpClassName, + lpWindowName, + dwStyle, + X, + Y, + nWidth, + nHeight, + hWndParent, + hMenu, + hInstance, + lpParam); + } + if (gfx_get_windowed()) { /* use a different style */ dwStyle |= WS_OVERLAPPEDWINDOW; diff --git a/src/main/ddrhook1/master.c b/src/main/ddrhook1/master.c index 613e459..022267b 100644 --- a/src/main/ddrhook1/master.c +++ b/src/main/ddrhook1/master.c @@ -1,6 +1,7 @@ #include "ddrhook1/master.h" #include "ddrhook-util/dinput.h" +#include "ddrhook-util/gfx.h" #include "ddrhook-util/monitor.h" #include "hook/table.h" @@ -52,6 +53,7 @@ void ddrhook1_master_insert_hooks(HMODULE target) p3io_setupapi_insert_hooks(target); monitor_setupapi_insert_hooks(target); + gfx_insert_hooks(target); dinput_init(target); /* Insert dynamic loader hooks so that we can hook late-loaded modules */ diff --git a/src/main/ddrhook2/dllmain.c b/src/main/ddrhook2/dllmain.c index 02c1cc1..9804b8d 100644 --- a/src/main/ddrhook2/dllmain.c +++ b/src/main/ddrhook2/dllmain.c @@ -33,10 +33,6 @@ static bool my_dll_entry_main(void); bool standard_def; bool _15khz; -static const hook_d3d9_irp_handler_t ddrhook2_d3d9_handlers[] = { - gfx_d3d9_irp_handler, -}; - static bool my_dll_entry_init(char *sidcode, struct property_node *param) { int argc; @@ -87,6 +83,10 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) args_free(argc, argv); + #if AVS_VERSION >= 1508 + gfx_set_is_modern(); + #endif + iohook_push_handler(p3io_emu_dispatch_irp); iohook_push_handler(extio_dispatch_irp); iohook_push_handler(spike_dispatch_irp); @@ -97,8 +97,6 @@ static bool my_dll_entry_init(char *sidcode, struct property_node *param) iohook_push_handler(com4_dispatch_irp); } - hook_d3d9_init(ddrhook2_d3d9_handlers, lengthof(ddrhook2_d3d9_handlers)); - rs232_hook_init(); ddrhook2_master_insert_hooks(NULL); diff --git a/src/main/ddrhook2/master.c b/src/main/ddrhook2/master.c index 120f2dc..01ed02b 100644 --- a/src/main/ddrhook2/master.c +++ b/src/main/ddrhook2/master.c @@ -16,6 +16,11 @@ static HMODULE(STDCALL *real_LoadLibraryA)(const char *name); static HMODULE STDCALL my_LoadLibraryA(const char *name); + +static const hook_d3d9_irp_handler_t ddrhook2_d3d9_handlers[] = { + gfx_d3d9_irp_handler, +}; + static const struct hook_symbol master_kernel32_syms[] = { { .name = "LoadLibraryA", @@ -58,6 +63,8 @@ void ddrhook2_master_insert_hooks(HMODULE target) dinput_init(target); gfx_insert_hooks(target); + hook_d3d9_init(ddrhook2_d3d9_handlers, lengthof(ddrhook2_d3d9_handlers)); + /* Insert dynamic loader hooks so that we can hook late-loaded modules */ hook_table_apply(