Save file format: Difference between revisions

From Arx Libertatis Wiki
Jump to navigation Jump to search
(Created page with "This page describes the save format used by Arx Fatalis as well as Arx Libertatis extensions. All integers are encoded in little-endian byte order. == Save file container (.sav)...")
 
(Document the .sav container format.)
Line 1: Line 1:
This page describes the save format used by Arx Fatalis as well as Arx Libertatis extensions. All integers are encoded in little-endian byte order.
This page describes the save format used by Arx Fatalis as well as Arx Libertatis extensions. All integers are encoded in little-endian byte order. Types are the same as in <code>platform/Platform.h</code> - <b>s</b> (signed integer) / <b>u</b> (unsigned integer) / <b>f</b> (float), followed by the number of bits.


== Save file container (.sav) ==
== Arx save file container (.sav) ==
 
Save files are stored in a generic container that maps names (arbitrary strings) to chunks of data. Arx Libertatis adds two extensions to the vanilla Arx Fatalis .sav format.


=== Header ===
=== Header ===


<pre>
The file header starts at byte position 0 - there is no magic number.
</pre>
 
{| class="wikitable"
! Type
! Description
|-
| <b>u32</b>
| File table offset
|}
 
The file table offset is the location of the file table (in bytes) relative to the first byte after the header. Add 4 bytes to get the offset relative to the start of the file.


=== File table ===
=== File table ===
The file table starts with a file table header:
==== File table header ====
{| class="wikitable"
! Type
! Description
|-
| <b>u32</b>
| Format version
|-
| <b>u32</b>
| Number of file entries
|}
Currently, the following version numbers are defined.
{| class="wikitable"
! Name
! Value
! Description
|-
| <code>SAV_VERSION_LEGACY</code>
| <code>0x00010000</code>
| Legacy version
|-
| <code>SAV_VERSION_RELEASE</code>
| <code>0x00010001</code>
| Current Arx Fatalis version
|-
| <code>SAV_VERSION_DEFLATE</code>
| <code>0x00020000</code>
| Added support for different compression algorithms (Arx Libertatis extension)
|-
| <code>SAV_VERSION_NOEXT</code>
| <code>0x00020001</code>
| Removed ".sav" suffix from internal filenames (Arx Libertatis extension)
|}
The file table is followed by the specified number of file entries. For save files with version <code>SAV_VERSION_LEGACY</code> the first file entry should be ignored.
==== File table entry ====
{| class="wikitable"
! Type
! Description
|-
| null-terminated string
| File name
|}
Each file table entry is preceded by a null-terminated string - the file name. Versions older than <code>SAV_VERSION_NOEXT</code> store file names case-insensitively and append ".sav". When loading such versions, the filename should be converted to lowercase and the ".sav" extension removed.
For versions older than <code>SAV_VERSION_DEFLATE</code>:
{| class="wikitable"
! Type
! Description
|-
| <b>u32</b>
| Stored (compressed) file size - This can be ignored and calculated from chunk sizes.
|-
| <b>u32</b>
| Number of chunks - 0 means 1!
|-
| <b>u32</b>
| Useless data. This can be safely ignored
|}
For <code>SAV_VERSION_DEFLATE</code> and newer:
{| class="wikitable"
! Type
! Description
|-
| <b>u32</b>
| Uncompressed file size
|-
| <b>u32</b>
| Number of chunks
|-
| <b>u32</b>
| Compression algorithm
|}
Currently, the following version numbers are defined.
{| class="wikitable"
! Value
! Name
! Description
|-
| <code>0</code>
| <code>Stored</code>
| No compression. Data is stored as-is.
|-
| <code>1</code>
| <code>ImplodeCrypt</code>
| Data is compressed using the PKWARE implode library. The result is bitwise negated.
|-
| <code>2</code>
| <code>Deflate</code>
| Data is compressed using the ZLIB deflate format.
|}
Code to decompress PKWARE implode-encoded data can be found in blast.c in the contrib directory of the zlib tarball.
Versions older than SAV_VERSION_DEFLATE always use the <code>ImplodeCrypt</code> algorithm. To allow changing save files without not decompressing all data, the value <code>0xffffffff</code> may be used to indicate that the uncompressed size is not known if (and only if) the compression algorithm is <code>ImplodeCrypt</code>.
The rest of the file entry is a list of as many chunk offsets as specified. For versions older than <code>SAV_VERSION_DEFLATE</code>, the actual number of chunks is always 1 or more, even if the file entry says 0. The concatenation of the chunks referenced by these offsets makes up the compressed file data.
===== Chunk offsets =====
{| class="wikitable"
! Type
! Description
|-
| <b>u32</b>
| Chunk size
|-
| <b>u32</b>
| Chunk offset
|}
The chunk offset is the location of the chunk data (in bytes) relative to the first byte after the header. Add 4 bytes to get the offset relative to the start of the file. The chunk size is given in bytes. There is no guarantee that all parts of the .sav file are used in chunks or the file table.


== Saved structures ==
== Saved structures ==


TODO
TODO

Revision as of 13:30, 25 November 2011

This page describes the save format used by Arx Fatalis as well as Arx Libertatis extensions. All integers are encoded in little-endian byte order. Types are the same as in platform/Platform.h - s (signed integer) / u (unsigned integer) / f (float), followed by the number of bits.

Arx save file container (.sav)

Save files are stored in a generic container that maps names (arbitrary strings) to chunks of data. Arx Libertatis adds two extensions to the vanilla Arx Fatalis .sav format.

Header

The file header starts at byte position 0 - there is no magic number.

Type Description
u32 File table offset

The file table offset is the location of the file table (in bytes) relative to the first byte after the header. Add 4 bytes to get the offset relative to the start of the file.

File table

The file table starts with a file table header:

File table header

Type Description
u32 Format version
u32 Number of file entries

Currently, the following version numbers are defined.

Name Value Description
SAV_VERSION_LEGACY 0x00010000 Legacy version
SAV_VERSION_RELEASE 0x00010001 Current Arx Fatalis version
SAV_VERSION_DEFLATE 0x00020000 Added support for different compression algorithms (Arx Libertatis extension)
SAV_VERSION_NOEXT 0x00020001 Removed ".sav" suffix from internal filenames (Arx Libertatis extension)

The file table is followed by the specified number of file entries. For save files with version SAV_VERSION_LEGACY the first file entry should be ignored.

File table entry

Type Description
null-terminated string File name

Each file table entry is preceded by a null-terminated string - the file name. Versions older than SAV_VERSION_NOEXT store file names case-insensitively and append ".sav". When loading such versions, the filename should be converted to lowercase and the ".sav" extension removed.

For versions older than SAV_VERSION_DEFLATE:

Type Description
u32 Stored (compressed) file size - This can be ignored and calculated from chunk sizes.
u32 Number of chunks - 0 means 1!
u32 Useless data. This can be safely ignored

For SAV_VERSION_DEFLATE and newer:

Type Description
u32 Uncompressed file size
u32 Number of chunks
u32 Compression algorithm

Currently, the following version numbers are defined.

Value Name Description
0 Stored No compression. Data is stored as-is.
1 ImplodeCrypt Data is compressed using the PKWARE implode library. The result is bitwise negated.
2 Deflate Data is compressed using the ZLIB deflate format.

Code to decompress PKWARE implode-encoded data can be found in blast.c in the contrib directory of the zlib tarball.

Versions older than SAV_VERSION_DEFLATE always use the ImplodeCrypt algorithm. To allow changing save files without not decompressing all data, the value 0xffffffff may be used to indicate that the uncompressed size is not known if (and only if) the compression algorithm is ImplodeCrypt.

The rest of the file entry is a list of as many chunk offsets as specified. For versions older than SAV_VERSION_DEFLATE, the actual number of chunks is always 1 or more, even if the file entry says 0. The concatenation of the chunks referenced by these offsets makes up the compressed file data.

Chunk offsets
Type Description
u32 Chunk size
u32 Chunk offset

The chunk offset is the location of the chunk data (in bytes) relative to the first byte after the header. Add 4 bytes to get the offset relative to the start of the file. The chunk size is given in bytes. There is no guarantee that all parts of the .sav file are used in chunks or the file table.

Saved structures

TODO