From 68a1fbdc2b01c29ca182f8fd0a0ca98769be0960 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 16 Mar 2025 03:16:02 +0300 Subject: [PATCH] engine: platform: win32: use widechar versions of LoadLibrary, which fixes loading engine if path contains non-latin characters --- engine/platform/sdl/vid_sdl.c | 4 ++-- engine/platform/win32/lib_win.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 72242a17..f3df1ff6 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -370,7 +370,7 @@ static void WIN_SetDPIAwareness( void ) BOOL ( __stdcall *pSetProcessDPIAware )( void ); BOOL bSuccess = FALSE; - if( ( hModule = LoadLibrary( "shcore.dll" ) ) ) + if( ( hModule = LoadLibraryW( L"shcore.dll" ) ) ) { if( ( pSetProcessDpiAwareness = (void*)GetProcAddress( hModule, "SetProcessDpiAwareness" ) ) ) { @@ -395,7 +395,7 @@ static void WIN_SetDPIAwareness( void ) { Con_Reportf( "%s: Trying SetProcessDPIAware...\n", __func__ ); - if( ( hModule = LoadLibrary( "user32.dll" ) ) ) + if( ( hModule = LoadLibraryW( L"user32.dll" ) ) ) { if( ( pSetProcessDPIAware = ( void* )GetProcAddress( hModule, "SetProcessDPIAware" ) ) ) { diff --git a/engine/platform/win32/lib_win.c b/engine/platform/win32/lib_win.c index 748cfac4..f46a80de 100644 --- a/engine/platform/win32/lib_win.c +++ b/engine/platform/win32/lib_win.c @@ -18,6 +18,14 @@ GNU General Public License for more details. #if XASH_LIB == LIB_WIN32 #include "lib_win.h" +static const wchar_t *FS_PathToWideChar( const char *path ) +{ + static wchar_t pathBuffer[MAX_PATH]; + MultiByteToWideChar( CP_UTF8, 0, path, -1, pathBuffer, MAX_PATH ); + return pathBuffer; +} + + static DWORD GetOffsetByRVA( DWORD rva, PIMAGE_NT_HEADERS nt_header ) { int i = 0; @@ -375,7 +383,7 @@ static void ListMissingModules( dll_user_t *hInst ) HMODULE hMod; const char *importName = (const char *)CALCULATE_ADDRESS( data, GetOffsetByRVA( importDesc->Name, peHeader ) ); - hMod = LoadLibraryEx( importName, NULL, LOAD_LIBRARY_AS_DATAFILE ); + hMod = LoadLibraryExW( FS_PathToWideChar( importName ), NULL, LOAD_LIBRARY_AS_DATAFILE ); if ( !hMod ) { Q_snprintf( buf, sizeof( buf ), "%s not found!", importName ); @@ -470,7 +478,7 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d else #endif { - hInst->hInstance = LoadLibrary( hInst->fullPath ); + hInst->hInstance = LoadLibraryW( FS_PathToWideChar( hInst->fullPath )); } if( !hInst->hInstance )