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: TeamTofuShop/segatools#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>
This commit is contained in:
2025-03-14 11:53:31 +00:00
committed by Dniel97
parent 70c3e2fe0f
commit 61f95c3f2e
14 changed files with 64 additions and 2 deletions

View File

@ -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. */

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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));
}

View File

@ -7,6 +7,7 @@ struct gfx_config {
bool windowed;
bool framed;
int monitor;
bool dpiAware;
};
void gfx_hook_init(const struct gfx_config *cfg);