Extending GameFont files

Leoreth

Bofurin
Retired Moderator
Joined
Aug 23, 2009
Messages
38,039
Location
風鈴高等学校
I was running out of space for resources in my GameFont files. I have asked about it here before and people advised me that it should be possible to just plain out add icon boxes into the file and the game will recognise it, to extend the space for additional icons like some other mods have done (e.g. C2C). But whenever I try this the game has issues reading the font file, using the wrong icons in places and resulting in size errors for the game text.

I have attached the underlying bmp files for GameFont_75.tga before and after editing it, and here's an example for the resulting errors in the game:
Spoiler :
Civ4ScreenShot0077.JPG


My process to edit the files was this: open the *.tga file in DXTBmp, send the main colour channel to GIMP, add white boxes with GIMP, then import the main colour channel back into DXTBmp and save to TGA. Then open the extended fonts with GameFontEditor and move around the actual icons.

After that didn't work, I also tried to account for the magic cyan pixels in the file, adding them to the right of every non-empty icon box. But I'm still confused about what the cyan pixels are exactly needed for, because the original working fonts file I had did not have them everywhere, and I'm not sure if they need to come after every box or every non-empty box. I trial and errored multiple variations of this but all showed the above issues.

What am I doing wrong? Is something missing? I'd love to understand all of this a bit better.
 

Attachments

You can add more boxes. In fact from what I can tell, you can add infinite number of boxes, but you really need to know what you are doing because it is possible to mess up very badly.

First of all, there is an alpha channel. If you use something, which kills the alpha channel, then you break the file. The best tool of the job is GraphicConverter, which sadly is mac only. Don't let the name fool you. It's quite powerful, but at the same time as simple as paint to use. In this case it's the ability to split an image into two windows, one without alpha channel and the other is just the alpha channel, making it easy to edit either. I haven't found any windows software, which can do this.

I recommend just copy pasting existing boxes and then use GameFontEditor to edit or replace the icons. Doing it manually is way too prone to file making mistakes.

The game inserts padding icons, meaning if you add 2 boxes, you push the next line 16 addresses. However empty boxes doesn't count. This is for GameFont icons in text.

GameFont icons in city billboards (and signs?) uses a different approach. There is no padding. This means if you aren't careful, you can make icon 8500 display one thing in text and another thing on the billboard. Billboards can't display any icons placed after the symbols meaning if you add another row of boxes at the bottom, those icons become text only (no billboard).

The bullet char has an assumed index by the exe file and if you move it in your file, the bullet char will be displayed as some other character. The index assumed by the exe depends on how many entries you have in the xml files, which requires a GameFont icon (like religions).

GameFont is used as a font. Each icon is assigned a unicode index. The first is 8483 (decimal) and the next is 8484 etc. This means you can write GameFont yourself from just the numbers. In python it's "(u" %c" % (iID))" where iID is the number you want to write. Some xml classes have getChar(), but they really just return an int. Likewise you can use CvWString in C++ to assign specific numbers to characters. With this knowledge you can make a GameFont debug screen where you can see numbers and which icon the game assigns to said number. I have done so, but it's hardcoded hard into We The People.

Studying CvGameTextMgr::assignFontIds could help understanding or even modding how to access GameFont and how the addresses are assigned.

I think I wrote what you need to know to mess with the GameFont file, but due to the topic complexity, I'm not sure if what I wrote is enough to make you become an instant GameFont expert. It took me years to figure out how it all works.
 
Thanks for the insight, but I still find it difficult to apply this to my concrete situation. How does the outcome displayed in my screenshot actually come about? For example, see the larger size 5 in the food production minus food production equals food surplus display left of the food stored bar.

First of all, there is an alpha channel. If you use something, which kills the alpha channel, then you break the file. The best tool of the job is GraphicConverter, which sadly is mac only. Don't let the name fool you. It's quite powerful, but at the same time as simple as paint to use. In this case it's the ability to split an image into two windows, one without alpha channel and the other is just the alpha channel, making it easy to edit either. I haven't found any windows software, which can do this.

I recommend just copy pasting existing boxes and then use GameFontEditor to edit or replace the icons. Doing it manually is way too prone to file making mistakes.
I tried to use GameFontEditor as much as possible (I don't have a Mac unfortunately), but since it only allows interaction with existing boxes you have to add boxes manually. And so far I did nothing but copy pasting empty boxes in the BMP with GIMP. Since empty boxes are black in the alpha map it should not even matter at that point. The only reason there should be an issue at this stage can be a magic cyan pixel, some special rules for the number of boxes the file is expected to have, or DLL code that needs to be suggested, as far as I can tell. As I mentioned above, it's not just that there is a mismatch in the used icons, even the text fonts seem to be messed up.
 
I can't answer that, but I have been thinking of making a standalone BTS version of the GameFont debug output in We The People. I guess now would be a good idea to look into it, at least the python only part. The Billboard is a dll mod.

And before you ask, yes the code for this is in the released WTP. However the domestic advisor will not show the button to enable this unless you are using a debug dll. Easily accessible to mod creators and not affecting the players :)
 

Attachments

  • billboard.jpg
    billboard.jpg
    42.7 KB · Views: 212
  • GameFont.jpg
    GameFont.jpg
    191.8 KB · Views: 203
And I released a BTS version of the python part of the GameFont display: https://forums.civfanatics.com/threads/gamefont-display.648571/

The big question is if it helps to solve the problem, but at least I got around to do what I had planned to do for quite a while now, which is to release this tool as a standalone tool, or rather modcomp as people can add it to their own mods.
 
That looks really useful! I solved my own problem yesterday by using another mod's extended fonts file and then relying on GameFontEditor to move over my own icons. Tedious but reliable.
 
Thanks! I ended up using Xyth's file from History Rewritten ... I didn't even need that much extra space but still finally ran into the limits of the vanilla layout.
 
The game inserts padding icons, meaning if you add 2 boxes, you push the next line 16 addresses. However empty boxes doesn't count. This is for GameFont icons in text.

GameFont icons in city billboards (and signs?) uses a different approach. There is no padding. This means if you aren't careful, you can make icon 8500 display one thing in text and another thing on the billboard. Billboards can't display any icons placed after the symbols meaning if you add another row of boxes at the bottom, those icons become text only (no billboard).
So I do have to follow up on this after all. Turns out that I didn't pay enough attention to how the billboard looks. While the icons are correct in all other locations, in the billboard instead of the defense symbol (the tower), a globe symbol is displayed instead.

I looked into CvGameTextMgr::assignFontIds as you suggested, and it seems that the method that the functions constructing the billboard just use FontSymbols.DEFENSE_CHAR and the like, am I right in my assumption that those are incorrect in my case?

I'm also wondering what I can do to fix this. You mention that there is no padding, does that mean that the existence of empty boxes influences how the billboard uses icons? My experiments support this, as adding/removing empty boxes moves the displayed icon two squares to the right or left respectively. The problem is that the globe is nine squares off from the defense icon, so I cannot fix the problem this way, and it seems wrong regardless.

Actually messing with assignFontIds just messes up all icons. Do the cyan dots in the game font file play a role here? Adding or removing them does not seem to have any effect. I am at a loss.
 
I made a billboard gamefont debug display in We The People. Last in CvGameTextMgr::buildCityBillboardIconString() I added this:
PHP:
szBuffer.append(CvWString::format(L"\n\n\n"));
for (int i = 0; i <= 80; i += 10)
{
    for (int j = 0; j < 10; ++j)
    {
        int iChar = iGameFontDebugChar + i + j;
        szBuffer.append(CvWString::format(L"%d: %c ", iChar, iChar));
    }
    szBuffer.append(CvWString::format(L"\n"));
}
iGameFontDebugChar is the address of the first character you want to display. Use this together with the GameFont debug modcomp I released recently. Go through all the GameFont addresses and make sure each address points to the same icon. Yes it's a bit of work and yes it's slow if you have to recompile each time, but it's also not quick to code a python interface to set iGameFontDebugChar at runtime.

Alternatively you can just use WTP. Compile a debug DLL, open the domestic advisor, click the rightmost button (it's debug GameFont or something and is only present when using debug DLLs). Here there will be a list like the modcomp. Click on a line and if you close the DA while in the debug tab and clicked a line, that line will be iGameFontDebugChar. You should be able to use a BTS gamefont file with Colonization.

You mention that there is no padding, does that mean that the existence of empty boxes influences how the billboard uses icons?
It was either that or that or it skips empty boxes, meaning you can change the offset by copy pasting stuff into boxes you aren't using. I can't remember this for certain (haven't touched this since last year), but it was something like that.
 
I'll give it a try, thanks.
 
Back
Top Bottom