Ever since I first added it, the Windows version of Star Wars Chess had a bizarre problem: the pieces at the bottom faced the wrong way, as in the first screenshot.
Everything else seemed to work fine except this one annoying issue, and I was never able to figure it out.
Flash forward to today, when a helpful user on the discord asked if the INI files might be the issue. The game, being from the Windows 3.1 era, uses a ton of INI files to describe various things about the configuration.
Eventually the user pointed out that if they modified the file CM.INI and changed one of the letters in another emulator, they could get all the pieces to face forward just like in DREAMM.
This definitely warranted an investigation.
The entries in question look like this:
[chesssets]
WHTBTM_=WhiteOnBottom 3 P S 68 142 2
WHTTOP_=WhiteOnTop 3 P S 68 142 2
2DSET_=Setup 2 P S 37 45 1
FACING_=FrontFacing 3 P S 68 142 2
To read information from the INI files, the game uses the GetPrivateProfileString API, which is a Swiss army knife for fetching information. With certain parameters, it can be used to query the list of values in a section, and the game would use this to get the list of entries in thechesssets` section.
What became apparent, after much debugging, was that it presumed the order of the entries matched that in the INI files. Unfortunately, I was using a std::map to store the entries, which meant I lost the original order and instead would return them in alphabetical order.
So when it defaulted to item index 1, instead of picking the WHTTOP_ item, it ended with the FACING_ item. And the FrontFacing item would show all pieces as front-facing.
So in a furious bit of rewriting, I ripped out the std::maps and just used std::vector instead, searching for items manually instead of using find() on the map. Slightly slower but this API isn't exactly a high-frequency thing.
And sure enough, I can finally close the book on a bug that's plagued me for a couple of years now.