Layout of Daggerfall savetree.dat Files
	-- Glen Wright


Acknowledgements:
The Quest Hacking guides on Dave Humphrey's Unofficial Elder Scrolls Pages and
DaggerWeb (the hacking guide is now on Michael Schneider's site) started me 
looking into the format of the QBN files. I reached a point where I decided 
that a better understanding of the save file and its relation to the QBN 
files was required. My effort has gone in that direction, and I hope that 
what I find here will help those working on the QBN files. Further, I'd like 
to thank the many people that figured out most of the information for the 
character records and for the item records. A lot of what is in here is 
taken directly from what they found.


Notes:
All numbers given in this document are in hexadecimal. Numbers written as 
XX XX XX are in the same byte order as they would appear in the savetree.dat 
file. Numbers written as XXXX are short words, and the two bytes are reversed
from their order in the file. Numbers written as XXXXXXXX are long words, and
the four bytes are reversed from their order in the file.



Level One: Base Structure

Savetree.dat has a 13 byte (hex, remember) header record. This is followed by
a variable number of variable sized records( there does not appear to be any 
counts of records, or any offsets, or any other information useful to 
extracting records). The variable records have a long word header, which is 
the size of the record excluding the four bytes of the record size. There are 
special records which are 0 size, used to break the save file into the 
following sections:
	*  13 byte header 
	*  Town record (zero length if not in town) 
	*  Monster, character, and item records 
	*  0-sized record 
	*  Quest records 
	*  0-sized record 
	*  Dungeon info (Note: this size must be multiplied by 27!) 
	*  0-sized record  
	*  End-of-file 



Level Two: Record Structure

With the exception of the Town record and the Dungeon info, each record has a 
1-byte record type at the beginning. This record type is followed by a 
46 byte common structure that contains all sorts of interesting data, most 
of it uninterpretable by myself. The parts that are fairly clear are:
	06 
	  0c bytes of location data  
	1e 
	  04 byte object ID  
	25 
	  01 byte quest ID  
	26 
	  04 byte parent object ID  
	42 
	  04 byte parent record type  

I don't know much about the location data, but I have a suspicion that it is 
interpreted as 6 short words, where each pair of short words represent the 
X, Y, or Z position of the object in question. Some records don't have a 
location that makes sense, and some are contained within other records 
(e.g. objects carried by the character).

The object ID appears to be a unique long word for every item.Records that 
are carried by the character have a special ID of 0064XXXX. Some special 
records have an ID of 0001XXXX. Usually, though, the most significant two 
bytes are a common value thoughout a savetree file.

The parent object ID is the unique ID of the record this record belongs to.

The parent record type is (you guessed it!) the record type byte that the 
parent object ID references.

The Quest ID associates the record with a particular quest. Every quest that 
the character is involved in has a unique ID, which is at the beginning of 
each saved QBN record. These appear to start counting at 1.


Level Three: Record Contents

I have identified a number of record types and some of their contents, although
the rest of the records remain a mystery to me.

Record Types  
  Hex Type   Item Description     
	02   Item Records   
	03   Character Record - one per save file   
	04   Character Record parent - unknown purpose   
	05   Character Record parent - unknown purpose   
	06   Unknown   
	08   Unknown   
	09   Spells and Spell Effects   
	0a   Guild Membership Records   
	0e   QBN Records - slight differences between these records and the QBN 
	     files, but still recognizable.   
	10   Parent for QBN records   
	12   Parent for QBN records   
	16   Spellcasting creatures - spell list head   
	17   Control Setting Records - detail, volume   
	18   Location Names, possibly logbook entries   
	19   Unknown, 1 per save file   
	1f   Potion mixing records   
	20   Unknown, Linked to TOWN record structure   
	21   Unknown, usually in dungeon saves   
	22   Creature record   
	24   Possibly items on store shelves   
	27   Mystery Record - referenced, but doesn't exist in file   
	28   Location names - possibly for quests   
	29   Location names - possibly for quests   
	2b   Mystery Record - referenced, but doesn't exist in file   
	2c   Creature record   
	2d   NPC records   
	2e   Generic NPC Records   
	33   Dungeon record? Huge, mostly zero filled   
	34   Container Records   
	40   Unknown Records, all are part of a 'container'   
	41   Unknown, Possibly quest information    
	
Record Contents


There are a few special fields that need interpretation. Time stamps are 
recorded in minutes of game time since one year previous to your character's 
start in Privateer's Hold. Tamriel has 12 months per year, 30 days per month, 
24 hours per day, and 60 minutes per hour.


Record type: spell (09)  
	Offset   Description   Field Type   Count     
	  0000   effects        BYTE        0x06   
	  0006   category  	BYTE   	    0x02   
	  0008   cost   	BYTE        0x06   
	  000e   Duration   	BYTE        0x09   
	  0017   Probability 	BYTE        0x09   
	  0020   Strength1   	BYTE        0x05   
	  0025   Strength2   	BYTE        0x05   
	  002a   Strength3   	BYTE        0x05   
	  002f   Name   	CHAR        0x14   
	  0047   ??????   	BYTE        0x03    

**NOTE: each spell can have 3 effects. Each effect is recorded as two bytes in
the 'effects' field, an entry of FF FF indicates there is no effect. Each 
effect has its own 3-byte probability (base + chance/level) and a 3-byte 
duration (same). The strength for each effect is (low, high, low per level, 
high per level, and level) taken straight from the spell creation window.

Record type Guild (0a)  
	Offset   Description   Field Type   Count     
	0000      level   	SHORT       0x01   
	0003      guildID   	SHORT       0x01   
	0005      Timestamp   	LONG        0x02   
	000D      Other        

Record type: Character (03, ...)  
	Offset Description   Field Type   Count     
	0000   	name   		CHAR   	0x20   
	0020   	curstat   	SHORT   0x08   
	0030   	basstat   	SHORT   0x08   
	0040   	gender   	BYTE  	0x01   
	0041   	transportation  SHORT   0x01   
	0043   	race   		BYTE    0x01   
	0044   	armor   	BYTE    0x07   
	0058   	start sum   	LONG    0x01   
	0070   	opponent   	LONG    0x01   
	007c   	health   	SHORT   0x02   
	0080   	portrait   	BYTE    0x01   
	0082   	level   	BYTE    0x01   
	0083   	reflex   	BYTE    0x01   
	0085   	gold  		LONG    0x01   
	008d   	mana   		SHORT   0x02   
	0091   	reputation   	SHORT   0x05   
	009d   	Skills   	SHORT+LONG   0x23   
	016f   	Equipped   	LONG   0x1b   
	01fd   	Timestamp   	LONG   0x05   
	0230   	resist   	BYTE   0x01   
	0231   	immune   	BYTE   0x01   
	0232   	low tolerance   BYTE   0x01   
	0233   	crit weakness   BYTE   0x01   
	0234   	flags   	SHORT   1   
	0236   	rapid heal   	BYTE    1   
	0237   	regen health   	BYTE    1   
	0238   	unknown   	BYTE    1   
	0239   	spell absorb   	BYTE    1   
	023a   	hit/phobia   	BYTE    1   
	023b   	forb material   SHORT   1   
	023d   	crit weakness   BYTE    1   
	023e   	forbidden armor SHORT   1   
	0240   	C/lass Primary  BYTE    3   
	0243   	Class Major   	BYTE    3   
	0246   	Class Minor   	BYTE    6   
	024c   	Class Name   	CHAR    18   
	0264   	HP/Level   	SHORT   01   
	026a   	Start stats   	SHORT   08    	

Record type: Item (02)  
	Offset  Description   Field Type   Count     
	0000   	Name   		CHAR   	    20   
	0020   	category   	SHORT       02   
	0024   	Value   	LONG        02   
	002c   	Hits   		SHORT       03   
	0032   	Picture   	SHORT       02   
	0036   	Material   	BYTE        01   
	0037   	Construction   	BYTE        01   
	0038   	Colour   	BYTE        01   
	0039   	Weight   	LONG        01   
	003d   	Enchant Pts   	SHORT       01   
	003f   	Message   	SHORT       01   
	0041   	Magic   	SHORT       18    

Record type: "Destination" (28. 29)  
	Offset   Description   Field Type   Count     
	0000      Questor   	SHORT        1   
	0002      LINK   	LONG         1   
	0006      Destination   CHAR         20    
**NOTE: This record can have multiple entries of Questor, LINK, and 
Destination. I don't know what provides the count or the terminating sentinel.

Record type: Unknown (6)  
	Offset   Description   Field Type   Count     
	0000      Unknown       SHORT        10   
	0020      Location      SHORT        6    
**NOTE: This record type is referenced by what I think are the dungeon 
descriptions.

Record type: Item Group (34)  
	Offset   Description   Field Type   Count     
	0000      Unknown       unknown   unknown    
**NOTE: All items owned by the character have a `parent link' back to a type 
34 record. This appears to be the grouping of an item: whether it is on the 
character, in the cart, weapon list, etc. The type of group is determined by 
a value in the header for the record.


Other Goofy Things

The Town and Dungeon records don't have an identifying type byte. I don't know
much about them, but Ive been using the following fields to dump these records,
which are in themselves a list of records of some type.

	TOWN (1a bytes) : 1*SHORT, 0x10*BYTE, 2*BYTE, 1*LONG, 2*BYTE
	
	DUNGEON(27 bytes): 2*SHORT, 1f*BYTE, 1*LONG

The long values look to be record ID's, much as found in the common headers of 
all the other record types.

The records for Potions aren't simply enchanted items. In fact, the potion is a 
linked record of "glass bottle", indicating that the bottle itself isn't the 
magic, the contents are! The potion contains both a list of the ingredients that 
went into the mixture, and a spell effect list.

The 'epoch' for the time stamps is 12AM, 1st of Morning Star, 3E 404.


SAVEVARS.DAT

My small contribution to the savevars.dat file is that the current game date is saved at offset 0x3c9.



If you have any problems, suggestions or comments on this page or website, please feel free to use the Contact Form to send a message to the WebMaster.
This document was last modified on: Saturday, 19 February 2011, at 09:55:52 and has been accessed 3156 times ( dagger/dfsgh.txt ).
/text.shtml