The online racing simulator
#1 - PoVo
Compiling Unicode characters in C++ (Visual Studio 2010)
Hi,

I'm currently using CInSim with Visual Studio. I was wondering, how should I use Unicode characters like ąčęėįšųž in IS_MTC and IS_MST?

Here's my "test" message:
Send(ginfo->players[i].UCID, "^3> ^7Char test \u0105 \u012F");

Here's the function:
void Send(byte UCID, char* Message)
{
struct IS_MTC pack_mtc;
memset(&pack_mtc, 0, sizeof(struct IS_MTC));
pack_mtc.Size = sizeof(struct IS_MTC);
pack_mtc.Type = ISP_MTC;
pack_mtc.UCID = UCID;
strcpy(pack_mtc.Msg, Message);
insim.send_packet(&pack_mtc);
}

Compiling with chars like "\u0105" output this:
warning C4566: character represented by universal-character-name '\u0105' cannot be represented in the current code page (1252)

When I run the application, the characters in LFS come up as "?"

Any ideas? Thanks.
You need to convert them to a supported charset, which in LFS's case are:
Quote from morpha :
J -> Japanese CP932
S -> Simplified Chinese CP936
K -> Korean CP949
H -> Traditional Chinese CP950
E -> Central European CP1250
C -> Cyrillic CP1251
L -> Latin 1 CP1252
G -> Greek CP1253
T -> Turkish CP1254
B -> Baltic CP1257


And obviously, if they aren't found in the currently selected charset (default is Latin 1), you have to indicate the charset switch to LFS by prefixing the characters in question with their respective CP escape sequence, i.e. "^J" for Japanese / CP932.

Your test message translates to
^3> ^7Char test ^Bà á

which in-game displays "> Char test ąį". (colours obviously omitted)

Implementing Unicode to CP conversion is tricky, especially if you want it both ways (from LFS to Unicode, from Unicode to LFS). You can use pyinsim and InSim.NET for reference since they both implement this functionality, but I don't know of an existing, public solution for C/C++.

If you only need this for static strings, you could simply use Python with pyinsim's strmanip (it works stand-alone) and convert all your strings with that.
#3 - PoVo
Great! Never knew about the "^B" etc. codes.

This helped me a bunch!

Thanks!

FGED GREDG RDFGDR GSFDG