From 61f95c3f2e9afc55df5e0cb232250183edb6b582 Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Fri, 14 Mar 2025 11:53:31 +0000 Subject: [PATCH] GFX: add dpi-awareness switch for all games (#64) Pretty simple, adds a new config setting to the gfx category, which defaults to enabled to disable DPI scaling if a scale higher than 100% is used, causing game windows to appear stretched and blurry. Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/64 Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> --- carolhook/dllmain.c | 2 -- dist/carol/segatools.ini | 2 ++ dist/chuni/segatools.ini | 2 ++ dist/chusan/segatools.ini | 2 ++ dist/cxb/segatools.ini | 2 ++ dist/diva/segatools.ini | 3 +++ dist/fgo/segatools.ini | 2 ++ dist/idz/segatools.ini | 3 +++ dist/mercury/segatools.ini | 3 +++ dist/mu3/segatools.ini | 3 +++ doc/config/common.md | 32 ++++++++++++++++++++++++++++++++ gfxhook/config.c | 1 + gfxhook/gfx.c | 8 ++++++++ gfxhook/gfx.h | 1 + 14 files changed, 64 insertions(+), 2 deletions(-) diff --git a/carolhook/dllmain.c b/carolhook/dllmain.c index 762b33d..35fc7f0 100644 --- a/carolhook/dllmain.c +++ b/carolhook/dllmain.c @@ -74,8 +74,6 @@ static DWORD CALLBACK carol_pre_startup(void) HMODULE dbghelp; dprintf("--- Begin carol_pre_startup ---\n"); - if ( !SetProcessDPIAware() ) - dprintf("Failed to set process DPI awareness level!\n"); /* Pin the D3D shader compiler. This makes startup much faster. */ diff --git a/dist/carol/segatools.ini b/dist/carol/segatools.ini index e75f1cd..b760c6f 100644 --- a/dist/carol/segatools.ini +++ b/dist/carol/segatools.ini @@ -72,6 +72,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/chuni/segatools.ini b/dist/chuni/segatools.ini index 3e87cb0..3f32f5b 100644 --- a/dist/chuni/segatools.ini +++ b/dist/chuni/segatools.ini @@ -64,6 +64,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; LED settings diff --git a/dist/chusan/segatools.ini b/dist/chusan/segatools.ini index 7ff4d0a..1fb1371 100644 --- a/dist/chusan/segatools.ini +++ b/dist/chusan/segatools.ini @@ -90,6 +90,8 @@ windowed=1 framed=0 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; LED settings diff --git a/dist/cxb/segatools.ini b/dist/cxb/segatools.ini index 40589de..436ef01 100644 --- a/dist/cxb/segatools.ini +++ b/dist/cxb/segatools.ini @@ -83,6 +83,8 @@ windowed=1 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0 =primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/diva/segatools.ini b/dist/diva/segatools.ini index e8db667..744a55f 100644 --- a/dist/diva/segatools.ini +++ b/dist/diva/segatools.ini @@ -69,6 +69,9 @@ enable=1 windowed=1 ; Add a frame to the game window if running windowed. framed=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/fgo/segatools.ini b/dist/fgo/segatools.ini index 4e846ee..6ceac0a 100644 --- a/dist/fgo/segatools.ini +++ b/dist/fgo/segatools.ini @@ -92,6 +92,8 @@ enable=1 windowed=0 ; Add a frame to the game window if running windowed. framed=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 [touch] ; WinTouch emulation setting. diff --git a/dist/idz/segatools.ini b/dist/idz/segatools.ini index e617de2..47778e9 100644 --- a/dist/idz/segatools.ini +++ b/dist/idz/segatools.ini @@ -97,6 +97,9 @@ windowed=0 framed=1 ; Select the monitor to run the game on. (Fullscreen only, 0=primary screen) monitor=0 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; ----------------------------------------------------------------------------- ; Custom IO settings diff --git a/dist/mercury/segatools.ini b/dist/mercury/segatools.ini index 5e10634..3199a20 100644 --- a/dist/mercury/segatools.ini +++ b/dist/mercury/segatools.ini @@ -76,6 +76,9 @@ dipsw1=1 [gfx] ; Enables the graphics hook. enable=1 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + ; Hooks related to the touch boards [touch] diff --git a/dist/mu3/segatools.ini b/dist/mu3/segatools.ini index 43fef6e..61d8cfe 100644 --- a/dist/mu3/segatools.ini +++ b/dist/mu3/segatools.ini @@ -72,6 +72,9 @@ dipsw1=1 [gfx] ; Enables the graphics hook. enable=1 +; Enable DPI awareness for the game process, preventing Windows from stretching the game window if a DPI scaling higher than 100% is used +dpiAware=1 + [unity] ; Enable Unity hook. This will allow you to run custom .NET code before the game diff --git a/doc/config/common.md b/doc/config/common.md index 89c48c6..8ef48eb 100644 --- a/doc/config/common.md +++ b/doc/config/common.md @@ -342,6 +342,38 @@ Nu chassis DIP switch settings: - `111`: 1920x1080 - Switch 8: Game-specific. Not used in any shipping game. +## `[gfx]` + +### `enable` + +Default: `1` + +Enables graphic hooks. + +### `windowed` + +Default: `0` + +Force the game to run windowed. + +### `framed` + +Default: `0` + +Add a frame to the game window if running windowed. + +### `monitor` + +Default: `0` + +Select the monitor to run the game on. (Fullscreen only, 0 = primary screen) + +### `dpiAware` + +Default: `1` + +Sets the game to be DPI-aware. This prevents Windows automatically scaling the game window by your desktop's scaling factor, which may cause blurry graphics. + ## `[hwmon]` Configure stub implementation of the platform hardware monitor driver. The diff --git a/gfxhook/config.c b/gfxhook/config.c index 98db059..5c49625 100644 --- a/gfxhook/config.c +++ b/gfxhook/config.c @@ -14,4 +14,5 @@ void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename) cfg->windowed = GetPrivateProfileIntW(L"gfx", L"windowed", 0, filename); cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename); cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename); + cfg->dpiAware = GetPrivateProfileIntW(L"gfx", L"dpiAware", 1, filename); } diff --git a/gfxhook/gfx.c b/gfxhook/gfx.c index 0acc1ae..5d7b8cd 100644 --- a/gfxhook/gfx.c +++ b/gfxhook/gfx.c @@ -67,6 +67,14 @@ void gfx_hook_init(const struct gfx_config *cfg) return; } + if (cfg->dpiAware) { + if (SetProcessDPIAware()) { + dprintf("Gfx: Game process set to DPI aware.\n"); + } else { + dprintf("Gfx: Failed to set process DPI aware\n"); + } + } + memcpy(&gfx_config, cfg, sizeof(*cfg)); hook_table_apply(NULL, "user32.dll", gfx_hooks, _countof(gfx_hooks)); } diff --git a/gfxhook/gfx.h b/gfxhook/gfx.h index 9a7e27c..6f3c1b2 100644 --- a/gfxhook/gfx.h +++ b/gfxhook/gfx.h @@ -7,6 +7,7 @@ struct gfx_config { bool windowed; bool framed; int monitor; + bool dpiAware; }; void gfx_hook_init(const struct gfx_config *cfg);