📜 ⬆️ ⬇️

Notes localizer. The case of the problem of saving in games

“My game is not saved! What to do?!!!"
crazyLooker
"I keep everything."
vampire
“Saves don't work, what the fuck?”
zombie
“Everything works, someone just has crooked hands :)”
dante
From the game forums ...

Sometimes these squabbles stretch over several pages, and if the participants of the verbal battles met in real life, they probably would not have been without a massacre.
What is the secret that for some people everything works, and for others, an honestly purchased license disk pleases with the inability to keep the results achieved so hard?

Everything is very simple. Russian language and Windows. All modern games, according to the rules of working with user data, make saving the results in the user directory. This is usually the “My Documents” folder which is located in the user's personal directory. This is where the problem begins, and even two. First of all, in the Russian version of Windows, the name of the folder “My Documents” is in Russian, unlike the English version of “My Documents”. Secondly, the user creating his profile in Windows could write it using Russian or other Cyrillic characters. That, in principle, is quite logical if it is the native language.
As a result, our game "Blablabla Game" will try to save achievements in this folder "Documents and Settings \ Vasya Pupkin \ My Documents \ Blablabla Game \ Saves"
The problem is that Western game developers often do not even realize that the way in which they are going to save the file may contain some characters other than the standard ASCII set.
Digging inside the code.
The user directory is usually obtained using the SHGetKnownFolderPath function. If you are lucky and the developer used the Unicode version of the function, then the output will be the correct Unicode string. But then, the fun begins. Because the developers work with this line completely without taking into account the coding of the text, often considering that these are ordinary English letters.
Unicode characters contain 2 bytes per character. Here is the string in hexadecimal representation:

FEFF 0022 0043 003A-005C 0044 006F 0063-0075 006D 0065 006E-0074 0073 0020 0061 ?"C:\Documents a
006E 0064 0020 0053-0065 0074 0074 0069-006E 0067 0073 005C-0412 0430 0441 044F nd Settings\
0020 043F 0443 043F-043A 0438 043D 005C-041C 043E 0438 0020-0414 043E 043A 0443 \
043C 0435 043D 0442-044B 0022 0020 000D-000A 0000 0000 0000 0000 0000 0000 0000 " ♪◙

')
The error lies in the subsequent processing of this line. Often, developers, apparently using the old code, convert a 2-byte Unicode string to one-byte ASCII for further work. And often do it with an error. For example, without coding.
.text:00A3BBE0 mov edx, [esp+unicodeSrc]
.text:00A3BBE4 mov al, [edx]
.text:00A3BBE6 test al, al
.text:00A3BBE8 mov ecx, [esp+ansiiDest]
.text:00A3BBEC jz short loc_A3BC0F
.text:00A3BBF3 loc_A3BBF3:
.text:00A3BBF3 cmp esi, 1
.text:00A3BBF6 jle short loc_A3BC0E
.text:00A3BBFC add edx, 2
.text:00A3BBFF mov [ecx], al
.text:00A3BC02 mov al, [edx];!!!! !!!!
.text:00A3BC04 add ecx, 1
.text:00A3BC07 sub esi, 1
.text:00A3BC0A test al, al
.text:00A3BC0C jnz short loc_A3BBF3


What does this code do? It just takes the first byte of the Unicode string and saves it, completely spitting on the specifics of the encodings. And if for the English code 0065 - the letter “S”, the output is the same “S” 65, then for the Russian letter “n” 0414
there will be only 14 which is the service code and cannot be used in file names.
Further, such a broken line goes hand in hand, and of course when the time comes to save the file, it cannot be created due to incorrect characters in the path name.
This is just one of the cases. There are many examples of the misuse of Unicode.

So the request to the developers is to use Unicode correctly, then you yourself have to spend a lot of time looking for your own mistakes if the product is brought to the market of another country.

I would advise users if you do not want problems with games - create Windows profiles without using Russian letters, and redirect the My Documents folder to another, English-language one.

Source: https://habr.com/ru/post/278829/


All Articles