# DoorBench files

All numbers are little-endian. The records are defined in `engine/src/dbdef.pas`.

## Pack (.DBP)

A 64-byte header (`TPackHead`), the chunks, then the directory: one 12-byte `TDirEntry`
(offset, length, CRC-32) for each chunk, in order of kind, then number. A chunk is at
most 16,384 bytes.

| Kind | Chunks |
|---|---|
| 0 about | one: `TAboutHead`, then name, version, author, base name |
| 1 schema | one for each record type: `TSchemaHead`, fields, field names. 0 world, 1 player, 2 mail, 3 news, then the tables |
| 2 text | 60 texts each: an index of 2-byte places, then the texts |
| 3 code | one for each function: `TCodeHead`, instructions |
| 4 place | `TPlaceHead`, title, prompt, choices (`TChoice`, label, refusal) |
| 5 screen | `TScreenHead`, cells (count, character, attribute), fields |
| 6 rows | fixed tables: as many whole rows as fit. The first byte of a row says it is there |
| 7 settings | name, least, most, usual, help for each |
| 8 debug | names and line numbers; not in a release pack |

Texts have their length first. In a text, character 1 and the one after it are a colour
(32 + number).

## Saves

`WORLD.DAT` `PLAYERS.DAT` `MAIL.DAT` `NEWS.DAT` `T<id>.DAT`: a 64-byte header (`DBS1`,
game id, table id, record length), then records: change counter (4), CRC-32 of the
counter and everything after the CRC (4), in use (1), the fields. A record of zeros was
never written. Owned tables have a fixed number of records for each player's place.

A player's id is 2048 x a number that is never used again + their place in the file.

`SCHEMA.DAT`: the layout the saves have. `JOURNAL.DAT`: a step that has happened but may
not be in the files yet; `JOURNAL.NEW`: one that has not happened. `DB.LCK`: the lock, a
folder holding OWNER (host, process, token). `DB.BRK`: held while a dead lock is broken.
`MAINT.RUN`: maintenance is running. `UPDATE.RUN`: an update is part way through its swap.
`BK<n>`: backups; DONE in one says it is whole. 91 and up were made before updates.
