Czi - themeldingwars/Documentation GitHub Wiki

CZI - Color Zone Index Maps

CZI files or Color Zone Index Maps are used to define the masked areas of a texture that the game's Atlas Builder uses to apply colors like war paints to only certain areas of a texture.

A variation is used for pattern maps too (.czip files).

Format

Little endian. The whole file is a header, a table of mip levels, and then one compressed block per mip level.

Header

Field Type Notes
magic char[4] CZIM
version int32 3
width int32 Should match the texture this is paired with
height int32 Should match the texture this is paired with
patternFlags uint8
unknown uint8
numMipLevels int32 Should match the mip count of the paired texture

MipInfo

numMipLevels of these, one per level:

Field Type Notes
offset int32 Offset of this level in the decompressed data, i.e. the sum of all preceding size values
size int32 Decompressed size of this level

CompressedBlock

numMipLevels of these, in the same order:

Field Type Notes
length int32 Compressed length
data byte[length] zlib stream, inflates to MipInfo.size bytes

Each block is a complete zlib stream: a 2 byte header (78 9C when written by our tooling), the deflate data, and a big endian Adler-32 of the uncompressed bytes. Levels are compressed independently, so a single level can be replaced without touching the others as long as the MipInfo offsets after it are fixed up.

Reference

  • Czi.bt - 010 Editor template
  • C# reader / writer in FauFau: FauFau/Formats/Czi.cs. Note that this lives on the CZI branch, it has not been merged into master.

Notes

  • The width and height should match the texture this is paired with.
  • It should have the same number of mip levels as the texture it is paired with too.
  • Creating a blank mask is just a header with numMipLevels of 0, with levels appended afterwards.
  • patternFlags and the byte after it have not been decoded. The related SDB table is dbvisualrecords::CziPattern, which carries DisplayFlags, TypeFlags, Style, CziTextureId and CziAssetId per pattern, so that is where to look for what the values in the file are supposed to line up with. See also Warpaints and Warpaint Pattern Usage.