Ultima IX Internal Formats

Here is a description of various data files used by Ultima IX. This compiles information from the sources given in the links, as well as information discovered by various contributors and the Forgotten World Team.

=Definitions= These are definitions for byte formats used on this page:
 * char - An 8-bit (1-byte) character code in Windows-1252 encoding.
 * charz - As with char, but a nul character (code 0) terminates a string.
 * cstring - A uint32 string length followed by that many chars.
 * cstringz - A uint32 string length followed by that many chars, with a NUL (code 0) character as the last character.
 * float32 - A 32-bit floating point value in IEEE-754's binary32 format, in little-endian byte order; this is the same floating-point format used natively on X86 machines.
 * uint8 - Unsigned 8-bit (1-byte) integer, between 0 and 255 (2^8-1).
 * uint16 - Unsigned 16-bit (2-byte) integer, between 0 and 65535 (2^16-1), in little-endian byte order.
 * uint32 - Unsigned 32-bit (4-byte) integer, between 0 and 4294967295 (2^32-1), in little-endian byte order.
 * vec3 - A 3-D vector stored as three float32 for x, y, and z.

=Files= This is a hierarchical index of the files in Ultima 9 and what is known about them. This assumes that everything is installed from the CD, using a custom install.
 * 00000409.016, 00000409.256 - Installation background images in BMP format. No use to the game.
 * autorun.exe, autorun.ico, eahelp.hlp, FinalSetup.exe, ip.cfg, ip.exe, Uninst.isu - Installation files with no use to the game.
 * clcd16.dll, clcd32.dll, clokspl.exe, ConfigINI.exe, dplayerx.dll, drvmgt.dll, Dsetup.dll, secdrv.sys - Executable files with limited apparent applicability.
 * D3D.TXT, Eula.txt, keymap.new, options.new, OPTIONS.TXT, PATCH.TXT, PERFORM.TXT, Readme.txt - Text files with no use to the game.
 * Default.kmp - Keymap in INI format.
 * Options.ini - Game options in INI format.
 * u9.exe - Main executable.
 * EREG/ - Electronic registration files; no use to the game.
 * Movies/ - The game's movies files in a normal but unknown movie format. Renaming to AVI allows playing in Windows Media Player.
 * runtime/ - Data that can be modified during the game.
 * nonfixed.%d, where %d is between 0 and 239.
 * npc.flx - Contains a single record, which is a list of NPCs. Since "u9game0.sav" appears to be used for initial state and it also has a list of NPCs, it's not clear whether this is used by the game.
 * savegame/ - Save files, as well as what looks to be temporary unpacked files used while playing.
 * savegame/u9game%d.sav, where %d is a number between 1 and infinity - The packed savegames, using the Savegame file format.
 * sound/ - Speech, sound effects, and music files.
 * sound/music.flx
 * sound/sfx.flx
 * sound/sfxassoc.flx
 * sound/sfxcat.flx
 * sound/sfxenv.flx
 * sound/sfxtmpl.flx
 * sound/Speech.flx
 * static/ - Data that cannot be modified during the game.
 * static/activity.flx
 * static/anim.flx - Animations for the NPCs and books, using the Animation FLX record format.
 * static/ankh.pal - Palette used in 8-bit rendering mode and in the pictures in the savegames, using the Palette file format.
 * static/areas.flx
 * static/bitmap16.flx, static/bitmapC.flx, static/bitmapsh.flx
 * static/books-en.flx - Books and stores files, using the Book FLX record format.
 * static/dimension.dat
 * static/fixed.%d, where %d is 0 to 239 - Immovable objects within the region, using the Fixed file format.
 * static/highway.dat
 * static/Mbrk.br, static/Mbrk.fn, static/Mbrk.ns, static/Mbrk.vl
 * static/misctext.flx - Miscellaneous text strings, in the Wide String FLX record format.
 * static/registry.txt - Appears to be a list of bone names and numbers.
 * static/rgbccube.dat, static/shade.tbl, static/shadegry.tbl, static/yiqccube.dat - Used in 8-bit rendering mode.
 * static/sappear.flx - 3D mesh data, in the Mesh FLX record format.
 * static/sdInfo.flx, static/sdInfo16.flx, static/sdInfoC.flx
 * static/spaces.flx
 * static/Tbrk.br, static/Tbrk.fn, static/Tbrk.ns, static/Tbrk.vl
 * static/terrain.%d, where %d is 0 to 239 - Terrain height map information, in the Terrain file format.
 * static/text.dat
 * static/text.flx - Text strings, in the Wide String FLX format.
 * static/Texture8.9, static/Texture8.14, static/texture16.9, static/texture16.14 - Textures where each panel is a 16x16 segment from the terrain for the given region. This may be used for the low-detail terrain rendering.
 * static/Tnbrk.br, static/Tnbrk.fn, static/Tnbrk.ns, static/Tnbrk.vl
 * static/treedat.flx
 * static/triggers.flx
 * static/typename.flx - Type name and icons, in the Type Name FLX format.
 * static/types.dat
 * static/u9game0.sav - Initial save state used when starting a new game, using the Savegame file format.

=FLX Format= This is an archive file used extensively throughout the game. The header for each flx files contains records throughout the file for what are essentially subfiles.

Directory entry format
=Map Files=

Terrain files
This is the format for the "static/terrain.%d" files, where %d is between 0 and 239 with some gaps for nonexistent regions. This contains the height map information for that region, and is present even if the region doesn't have any visible terrain. The terrain is cut into 16x16 point tiles, which are 8x8 world coordinates each. Each tile refers to a chunk, and it is possible for a chunk to be used by multiple tiles (such as if it's the bottom of the ocean). Curiously, there are always more chunks than tiles. This is the format of the header:

This is followed by the tile indices into the chunks:

The chunk data itself then follows:

Each tile is a bitmask with the following format:

Fixed Files
This is the format for the "static/fixed.%d" files, where %d is between 0 and 239 with some gaps for nonexistent regions. This contains the objects which cannot be moved or interacted with, such as trees or houses. The region is cut into 32x32 point blocks. The format of the block is not known, but they somehow map to pages, which store a sequence of fixed objects. This is the format of the header:

This is followed by some kind of value related to the tiles:

The pages themselves follow. Each is 1000h (4096) bytes long:

The fixed objects are 18h (24) bytes long:

=Graphics Files= The following sub-sections contain the record formats for graphics related FLX files along the file formats for other graphics based files.

Palette files
This is used with "static/ankh.pal", which is the master palette used in 8-bit mode and for the pictures in savegames.

Each color has the following format:

Texture8 FLX record format
This is the format for the items in the texture8.* files.

NOTE: len is the length of the item

Frame
The "depth" above means the bytes per pixel, which is 1 for "static/bitmaps8.flx" or 2 for "static/bitmaps16.flx". 16-bit pixels use this bitmask:

Sappear FLX record format
This is used for "static/sappear.flx". It defines the 3D meshes, aside from the terrain. Each record begins with this header:

Submesh format
At each submesh offset is a submesh header:

Following the header are the LOD levels.

Face format
Each triangle is 7Ch (124) bytes long, and has this format:

Point format
This is the format for a point in a face, which is 1Ch (28) bytes long:

Material format
This is the format for a material that is applied to a set of triangles. Each is 18h (24) bytes long:

Animation FLX record format
This is used by the "static/anim.flx" file. It contains all the body part animations for the NPCs, and animations for the books.

Parts for the Animation FLX record format
This is the format of a part.

Frames for the Animation FLX record format
This is the format of a frame within a part.

=Item Files=

Type name FLX record format
This is the record type used in "static/typename.flx". This includes the tooltip icon and text used with the inventory and examine features in the game. Each typename entry corresponds to an object type in types.dat.

Book FLX record format
The format for records in "static/books-en.flx" is as follows. This format is more than likely also used for the other languages as well.

The body format depends upon whether this is a book or a store record. A book has significant newlines. A line beginning with ` changes the font, and can be:


 * `p - Apparently the intent is for a new page, but it's always at the beginning of the book.
 * `f1 - Blue font.
 * `f2 - Red font.
 * `f3 - Black italic font.
 * `f5 - Gargish font.

`f4 is not used, but would probably be runic.

Stores have a line-oriented format. The first line is the name of the store. Subsequent lines may begin with "!", indicating that they are a comment. Otherwise they have the form '#(number) "(name)" $(price)', where (number) is the item number, (name) is the name to display (which is adjusted to fit the size of the GUI), and (price) is the price of the item.

Text and MiscText FLX record format
This is the format for records in "static/text.flx" and "static/misctext.flx". Each record is a UCS-2 string that is nul-terminated. It is possible, but unlikely, that it is in UTF-16.

NPC FLX record format
=Scripting Files=

Highway Database record format
Following the header are a bunch of highway points, which define the location of cross objects (patheggs in the U7 vernacular). Each Highway point has the following format.

Following the highway points is a unint32 containing the total number of bytes for the highway segments. After that are the highway segments, which have the following format.

Following each highway segment is a sequence of uint16's that define the exact route of highway point trigger IDs.

=Sound Files=

Sound FLX record format
This is used for "sounds/sfx.flx", "sounds/music.flx", "sounds/speech.flx", maybe others.

The format of the type 1 encoding was determined by Josef Drexler. These are the encoding methods:

=Miscellaneous Files=

Savegame files
This is used with the "savegame/u9game%d.sav" files, as well as "static/u9game0.sav". These contain packed savegame data. This is the basic format:

Header
The Header contains the Start.dat file, the title of the savegame, possibly some current camera data, and a low-res screenshot for the savegame.

Nonfixed Files
The remainder of the file are current state for all encountered nonfixed.# files as of that save.

=External Links=
 * U9Tools - a collection of tools that allow the user to extract and modify the contents of various Ultima IX data files.
 * U9Decode - Joseph Drexler's utility that allows the user to extract Ultima IX's music.
 * Paeron - Paeron's documentation, supplementing information from Tumbleweed.