Skip to content

sqwishy/civ4-atlast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A couple tools for packing and unpacking GameFont.tga from Civilization IV.

  1. atlast.html, in this directory, is a standalone offline cloud-free web-scale web page for generating the text portion of the GameFont.tga atlas.

  2. Also here is the source code for a program written in Rust for packing and unpacking GameFont.tga. Unpacking means breaking the atlas down into individual .png files, while packing is just reassembling a GameFont.tga atlas from an index of those individual images.

    The idea is it's easier to edit a GameFont.tga by working with individual images and a manifest of the images and their ordering.

An example:

$ atlast.exe --unpack "C:\Games\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Mods\Realism Invictus\Assets\res\Fonts\GameFont.tga"
[0.000s] loading C:\Games\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Mods\Realism Invictus\Assets\res\Fonts\GameFont.tga to unpack to GameFont...
[0.002s] found 658 images over 14 rows
[0.000s] saving to GameFont...
[0.149s] writing GameFont\index.html
[0.001s] done unpacking to GameFont

This creates a directory called GameFont and unpacks the atlas into it, also writing an index.html file used as a listing of the atlas images. You can "preview" the atlas by opening the index.html file in your browser, or edit it with a text file to modify the listing. The index.html is used later to pack a GameFont.tga.

Patching GameFont.tga with a custom font from atlast.html

$ atlast.exe --unpack custom-GameFont-text-altas.tga --output GameFont --patch-index
[0.000s] loading custom-GameFont-text-altas.tga to unpack to GameFont...
[0.001s] found 181 images over 4 rows
[0.000s] saving to GameFont...
[0.037s] patching GameFont\index.html
[0.002s] matched 181 <img>s
[0.000s] done unpacking to GameFont

Using custom-GameFont-text-atlas.tga generated by atlast.html from the paragraph above, we can unpack it to the directory created from the unpack before. But this .tga only contains the text portion, the first 181 images. This way, we replace the original text with our own.

Instead of overwriting the index.html, the --patch-index option says that when each image is written we look for a corresponding img tag in index.html (with a matching src attribute) and update it's baseline marker data. Without this, and unpacking the images from our generated atlas alone, could cause the printable characters to appear vertically misaligned in game.

$ atlast.exe --pack GameFont --size 2046x540 --output "C:\Games\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Mods\Realism Invictus\Assets\res\Fonts\GameFont.tga"
[0.000s] packing images under GameFont to C:\Games\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Mods\Realism Invictus\Assets\res\Fonts\GameFont.tga
[0.001s] loading 658 images...
[0.059s] packed 2046x540
[0.004s] written to C:\Games\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Mods\Realism Invictus\Assets\res\Fonts\GameFont.tga

Repack the images specified in GameFont/index.html to the game's GameFont.tga at the path specified. The size option ensures the image is exactly that size. I've found this important for the GameFont_75.tga file as it seems to need to be a very specific size to work, even if it's mostly empty/transparent.

usage / atlast.exe --help

usage: atlast [options]
  options can include:
  --unpack [GameFont.tga]    unpack GameFont.tga to a directory
  --pack [GameFont/]         opposite of unpack, write GameFont.tga using unpacked files
  -n, --dry-run              read but don't write files
  -n, --dry-run              read but don't write files
  --output ...               when used with --unpack, sets the output directory
                             when used with --pack, sets the output .tga file
  --skip-index               with --unpack, do not write index.html
  --patch-index              with --unpack, only update matching images in index.html
  --size [WIDTH]x[HEIGHT]    with --pack, sets .tga file dimensions

examples:

  atlast --unpack
    Read `GameFont.tga` and write each glyph as a .png file in the
    `GameFont` directory with an `index.html` needed for repacking.

  atlast --unpack GameFont_75.tga
    Unpack `GameFont_75.tga` to the `GameFont_75` directory.

  atlast --unpack SpecialGameFont.tga --output GameFont_75 --patch-index
    Unpack `SpecialGameFont.tga` to the `GameFont_75` directory. Instead of overwriting
    `GameFont_75/index.html`, only update `<img>` elements with paths that match the image files
    unpacked from the .tga file. This could be useful if you're unpacking a .tga that contains just
    the text portion of the atlas and want to update just the descent/baseline markers for those
    images in the html file.

  atlast --pack --output SexyLettuce.tga
    Read the `index.html` in the `GameFont` directory and pack the
    images listed there into an atlas named `SexyLettuce.tga`.

The index.html is used as a manifest for repacking GameFont.tga and contains information about
descent/baseline markers.