SavefileCode
A new savefile format, with better versioning, that's easier to maintain. Left over from Nangband.
Contents:
General information
This document specifies a modular, savefile format, designed for use in any Angband or Angband derivative, though probably suitable for just about anything requiring a disc-based savefile format.
The savefile is constructed of a header, followed by a number of blocks, followed by a special "end block". Little endian is used for this savefile format.
Format
File header
The file header has a four-byte "magic number" (83.97.118.101). When a savefile is loaded, a check can be performed to see if the first four bytes are the "magic number" or the version number of an old savefile. This allows savefile compatibility to be kept intact between versions.
The magic number is followed by a byte version number: this is the version of the savefile format. This specification defines version 2 of the savefile format only. After this version number, there is a byte value for savefile status. 0 indicates death. No other status codes are specified in this document.
Finally, there are 64 bytes for a description of the savefile itself. It is envisaged that this would be automatically generated, including such information as character name and level, the current dungeon level being explored (Town, 50', etc.), or any other pieces of potentially useful and identifying information. This would ideally be used by a savefile selection menu to help differentiate between characters.
| Format of file header | |
|---|---|
byte | "Fake" major: 83 |
byte | "Fake" minor: 97 |
byte | "Fake" patch: 118 |
byte | "Fake" extra: 101 |
byte | Savefile format version: 2 |
byte | Savefile status |
64 bytes | Savefile description |
| 70 bytes total. | |
Data blocks
| Format of data block | |
|---|---|
u16b | Vendor |
u16b | Type |
u16b | Version |
u32b | Size |
u32b | Checksum |
| x | Data |
byte | 0 |
| 15 bytes (plus data) total. | |
The block format is as shown above. A few notes:
- "Vendor" is an ID corresponding to who created the block. This could be something representing a patch author, or a variant as a whole, etc.. In the traditional Angband development setting, this would be of use for e.g. patch authors who need to save data to the savefile but wish to retain backwards compatibility.
- "Type" is a vendor-defined numeric code indicating what the block stores.
- "Version" is the version of the block.
- "Size" is the size of the data segment of the block.
- "Checksum" is a checksum of some kind. (This will be updated as implementations are written using this specification.)
There is a 0 added to the end of each savefile block as an integrity measure.
Implementations
There is only one publically-available implementation at present, in Langband: however, this isn't a true implementation of this specification, as it has altered various aspects to better fits its engine/module model.
Andrew Sidwell has a private implementation under development, built on Vanilla 3.0.6, but this is not ready for release yet. An old version of can be found for reference here.
Notes
This specification is still in development.
The types referenced in this specification should be taken to meet the following values:
byterefers to an 8-bit unsigned valueu16bands16brefer, respectively, to unsigned and signed 16-bit valuesu32bands32brefer, respectively, to unsigned and signed 32-bit values
Credits
Listed in no particular order:
- Stig E Sandø: help during development of this spec
- Ben Harrison: writing the comments that sparked off this format
- Andrew Sidwell: main author
- Ross-Morgan Linial: help during development
