bvschaik / citybuilding-tools

Tools for the Citybuilding games made by Impressions Games/BreakAway Games

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bag filter "pink F81F as transparent", extracted images are not correct

Telariust opened this issue · comments

Hello, Bianca van Schaik!

The games in the series use compressed (new) and uncompressed (old, type=0) images.
Compression is based on transparency.
In the old images, transparency was implemented through a crutch with pink (F81F).
SGReader, when extracting and saving images, corrects them as the Game already shows them, and not as they actually are.
And when trying to save them back to the Game (via C3Modder) there are compatibility issues.
Even worse, it turned out that the "pink as transparent" filter, which should only be applied to old images, is applied to all.
That is, the filter cuts out pink from new images, too, in which pink can already be used for its intended purpose, because transparency is implemented in a normal way, and not through a pink crutch.

The bug came from LibSG.
Here is the filter that needs to be commented out in sgimage.(c/cpp)
if (color == 0xf81f) {return;}

if (color == 0xf81f) {

Need .exe v1.2 release, plz!

my research here, if interest
steamcommunity.com/sharedfiles/filedetails/?id=2770842807

Can simply recompile the program by disabling the filter, but that's not interesting.
True adherents of the HEX-editor will always find a reason to open a HEX-editor!
Let's look for "F81F" in SGReader_v1.1.exe. "F81F" - 49 matches;
However, remember that all numeric values ​​are stored in little endian byte order, that is, backwards.
"1FF8" - 62 matches;
Let's replace "1FF8" with "1111", creating 62 candidates.
Most of them did not start at all, there are about 15 left.
The test was carried out on a standard EN font.
When we see a pink background instead of a transparent one, it means it has been found.
Surprisingly, the very first candidate turned out to be the desired one, but the rest had to be checked for anyone.
So, the filter is at offset 0x228C.
Now the question is how to turn it off? We look at neighboring bytes:
3D 1F F8 74 1A
In human translation it says:
..0x3D (CMP AX,0x1FF8) - subtract the value 0xF8F1 from the value in the EAX register;
..0x74 (JZ 0x1A) conditional jump if the flag is zero (Z=1), 26 (0x1A) bytes ahead;
We want the jump to never take place. For example, like this:
3D 00 00 72 1A
..0x72 (JB 0x1A) conditional jump, if the first is less than the second, 26 (0x1A) bytes ahead;
Since it cannot be less than zero, the condition will never be fulfilled.
sgreader_v1.1.exe_off_F81F_0x228C.zip