source-sdk-2013 icon indicating copy to clipboard operation
source-sdk-2013 copied to clipboard

vgui_controls: Restore default locale initialization in VGui_InitInterfacesList

Open copperpixel opened this issue 2 months ago • 1 comments

Description

Moved from https://github.com/ValveSoftware/source-sdk-2013/pull/1241

Some time between SDK update in 2015 and 2025 this piece of code was removed which caused some Unicode functions to not work properly in non-English alphabet languages.

An example of this being an issue is in the PR linked above; it contains code which will find a match case-insensitivily in two wide strings (wszFilterBuf and wszDisplayText):

			// Find a match
			bool bMatch = false;
			const wchar_t *pwchLetter = wszDisplayText;
			while ( *pwchLetter != L'\0' )
			{
				const wchar_t *pwchSearch = pwchLetter;
				const wchar_t *pwchTest = wszFilterBuf;
				while ( *pwchTest != L'\0' )
				{
					if ( *pwchSearch == L'\0' )
						break;
					if ( towlower( *pwchSearch ) != towlower( *pwchTest ) )
						break;
					++pwchSearch; ++pwchTest;
				}
				if ( *pwchTest == L'\0' )
				{
					bMatch = true;
					break;
				}
				++pwchLetter;
			}

Without setting the locales, passing a Polish accent character like Ł into towlower fails to convert it to lowercase version ł, returning uppercase Ł instead.

This makes the if ( towlower( *pwchSearch ) != towlower( *pwchTest ) ) statement incorrectly fail when comparing Ł and ł, Ą and ą, etc.

Restoring behavior from old SDK versions fixes this.

copperpixel avatar Oct 31 '25 19:10 copperpixel

This issue can also be observed in Team Fortress 2 here:

https://github.com/ValveSoftware/source-sdk-2013/blob/2d3a6efb50bba856a44e73d4f0098ed4a726699c/src/game/shared/econ/econ_item_view.cpp#L1917-L1949

DoesItemPassSearchFilter is used for the filter field in the backpack menu and Mann Co. Store.

copperpixel avatar Nov 30 '25 00:11 copperpixel