From e610a56734f72f114c2233efc65c93f9223db358 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Mon, 8 Mar 2021 19:34:38 +0300 Subject: [PATCH] kernel32: Implement GetUserDefaultGeoName(). Fixes crash on launch in Outriders demo. Signed-off-by: Paul Gofman Signed-off-by: Alexandre Julliard --- dlls/kernel32/kernel32.spec | 1 + dlls/kernelbase/kernelbase.spec | 1 + dlls/kernelbase/locale.c | 50 +++++++++++++++++++++++++++++++++ include/winnls.h | 1 + 4 files changed, 53 insertions(+) diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index ee2e3f8ad31..5dee1d9b906 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -763,6 +763,7 @@ @ stdcall -import GetOEMCP() @ stdcall -import GetOverlappedResult(long ptr ptr long) @ stdcall -import GetOverlappedResultEx(long ptr ptr long long) +@ stdcall -import GetUserDefaultGeoName(ptr long) @ stdcall -import GetUserPreferredUILanguages(long ptr ptr ptr) @ stdcall GetPackageFamilyName(long ptr ptr) kernelbase.GetPackageFamilyName @ stdcall GetPackageFullName(long ptr ptr) kernelbase.GetPackageFullName diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 543961d2ce6..a0cd5f82a18 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -741,6 +741,7 @@ @ stub GetUILanguageInfo # @ stub GetUnicodeStringToEightBitSizeRoutine # @ stub GetUnicodeStringToEightBitStringRoutine +@ stdcall GetUserDefaultGeoName(ptr long) @ stdcall GetUserDefaultLCID() @ stdcall GetUserDefaultLangID() @ stdcall GetUserDefaultLocaleName(ptr long) diff --git a/dlls/kernelbase/locale.c b/dlls/kernelbase/locale.c index b746feca639..7126dc74d01 100644 --- a/dlls/kernelbase/locale.c +++ b/dlls/kernelbase/locale.c @@ -5740,6 +5740,12 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetUserGeoID( GEOID id ) const WCHAR *name = geoinfo->kind == LOCATION_NATION ? L"Nation" : L"Region"; swprintf( bufferW, ARRAY_SIZE(bufferW), L"%u", geoinfo->id ); RegSetValueExW( hkey, name, 0, REG_SZ, (BYTE *)bufferW, (lstrlenW(bufferW) + 1) * sizeof(WCHAR) ); + + if (geoinfo->kind == LOCATION_NATION || geoinfo->kind == LOCATION_BOTH) + lstrcpyW( bufferW, geoinfo->iso2W ); + else + swprintf( bufferW, ARRAY_SIZE(bufferW), L"%03u", geoinfo->uncode ); + RegSetValueExW( hkey, L"Name", 0, REG_SZ, (BYTE *)bufferW, (lstrlenW(bufferW) + 1) * sizeof(WCHAR) ); RegCloseKey( hkey ); } return TRUE; @@ -5877,3 +5883,47 @@ INT WINAPI DECLSPEC_HOTPATCH WideCharToMultiByte( UINT codepage, DWORD flags, LP TRACE( "cp %d %s -> %s, ret = %d\n", codepage, debugstr_wn(src, srclen), debugstr_an(dst, ret), ret ); return ret; } + + +/*********************************************************************** + * GetUserDefaultGeoName (kernelbase.@) + */ +INT WINAPI GetUserDefaultGeoName(LPWSTR geo_name, int count) +{ + const struct geoinfo *geoinfo; + WCHAR buffer[32]; + LSTATUS status; + DWORD size; + HKEY key; + + TRACE( "geo_name %p, count %d.\n", geo_name, count ); + + if (count && !geo_name) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + if (!(status = RegOpenKeyExW( intl_key, L"Geo", 0, KEY_ALL_ACCESS, &key ))) + { + size = sizeof(buffer); + status = RegQueryValueExW( key, L"Name", NULL, NULL, (BYTE *)buffer, &size ); + RegCloseKey( key ); + } + if (status) + { + if ((geoinfo = get_geoinfo_ptr( GetUserGeoID( GEOCLASS_NATION ))) && geoinfo->id != 39070) + lstrcpyW( buffer, geoinfo->iso2W ); + else + lstrcpyW( buffer, L"001" ); + } + size = lstrlenW( buffer ) + 1; + if (count < size) + { + if (!count) + return size; + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + return 0; + } + lstrcpyW( geo_name, buffer ); + return size; +} diff --git a/include/winnls.h b/include/winnls.h index 07a31cfde88..04838cfa8d7 100644 --- a/include/winnls.h +++ b/include/winnls.h @@ -946,6 +946,7 @@ WINBASEAPI INT WINAPI GetTimeFormatA(LCID,DWORD,const SYSTEMTIME*,LPCSTR WINBASEAPI INT WINAPI GetTimeFormatEx(LPCWSTR,DWORD,const SYSTEMTIME*,LPCWSTR,LPWSTR,INT); WINBASEAPI INT WINAPI GetTimeFormatW(LCID,DWORD,const SYSTEMTIME*,LPCWSTR,LPWSTR,INT); #define GetTimeFormat WINELIB_NAME_AW(GetTimeFormat) +WINBASEAPI INT WINAPI GetUserDefaultGeoName(LPWSTR,int); WINBASEAPI LANGID WINAPI GetUserDefaultLangID(void); WINBASEAPI LCID WINAPI GetUserDefaultLCID(void); WINBASEAPI INT WINAPI GetUserDefaultLocaleName(LPWSTR,int);