Jump to content

OBD:Instance file format: Difference between revisions

Neo doesn't know where he got this sample data, so I'm replacing it with the data from Windows level 0
(added intro)
(Neo doesn't know where he got this sample data, so I'm replacing it with the data from Windows level 0)
Line 1: Line 1:
Oni's level data is broken into two kinds of files in Windows retail Oni. One type ends in ".dat" and is called an instance file. The other type ends in ".raw" and is simply called a raw file. Windows demo Oni and Mac retail/demo Oni use a third type which ends in ".sep", short for "separate". You can read about raw and separate files [[Raw|HERE]].
Oni's level data is broken into two kinds of files in Windows retail Oni. One type ends in ".dat" and is called an instance file. The other type ends in ".raw" and is simply called a raw file. Windows demo Oni and Mac retail/demo Oni use a third type which ends in ".sep", short for "separate". You can read about raw and separate files [[Raw|HERE]].


Note that ".dat" is a generic suffix originally used by Oni for all kinds of data, including [[persist.dat]]. The raw and separate files were created later in development and given unique suffixes to distinguish them from the main level .dat file. Therefore, the proper, specific name for the <u>level data format</u>, as opposed to the save-game format, film format, etc. is not ".dat file" or "DAT file", but "instance file".
Note that ".dat" is a generic suffix originally used by Oni for all kinds of data, including [[persist.dat]]. The only reason that any other suffixes exist at all is that raw and separate files were created later in development and given unique suffixes to distinguish them from the .dat files in the same folder. Therefore, the proper, specific name for the <u>level data format</u>, as opposed to the save-game format, film format, etc. is not ".dat file" or "DAT file", but "instance file". That being said, ".dat" has only been used by the community historically to refer to instance files, so you can reasonably assume that's what is meant when you see the suffix.


Instance files are the "main" type of data file in the sense that, when loading a level, Oni reads the instance file first, and this file serves as an index that allows it to find resources which are packed back-to-back into the raw and separate files. All instance files begin with a 64 byte header followed by 3 "descriptor" arrays, a data table and a name table. Among other things, the header contains the number of descriptors in each of the 3 arrays and the offset of the data and name tables (relative to the start of the file).
Instance files are the "main" type of data file in the sense that, when loading a level, Oni reads the instance file first, and this file serves as an index that allows it to find resources which are packed back-to-back into the raw and separate files. All instance files begin with a 64 byte header followed by 3 "descriptor" arrays, a data table and a name table. Among other things, the header contains the number of descriptors in each of the 3 arrays and the offset of the data and name tables (relative to the start of the file).


Here is a walkthrough of an instance file using the level0_Final.dat in English Windows Oni. Follow along in a hex editor for maximum learnage. Remember that this is small-endian data. First, here is how the file begins:
{{Table}}
{{Table}}
{{OBD_Table_Header}}
{{OBD_Table_Header}}
Line 10: Line 11:
{{OBDtr| 0x08 | int32  | | 31 33 52 56            | 'VR31'            | .dat version; .oni files use 'VR32' instead }}
{{OBDtr| 0x08 | int32  | | 31 33 52 56            | 'VR31'            | .dat version; .oni files use 'VR32' instead }}
{{OBDtr| 0x0C | int64  | | 40 00 14 00 10 00 08 00 | 0x0008001000140040 | signature }}
{{OBDtr| 0x0C | int64  | | 40 00 14 00 10 00 08 00 | 0x0008001000140040 | signature }}
{{OBDtr| 0x14 | int32  | | F9 05 00 00 | 1529     | instance descriptor count  }}
{{OBDtr| 0x14 | int32  | | 83 24 00 00 | 9347     | instance descriptor count  }}
{{OBDtr| 0x18 | int32  | | D5 01 00 00 | 469      | name descriptor count }}
{{OBDtr| 0x18 | int32  | | D4 1B 00 00 | 7124      | name descriptor count }}
{{OBDtr| 0x1C | int32  | | 32 00 00 00 | 50       | template descriptor count }}
{{OBDtr| 0x1C | int32  | | 38 00 00 00 | 56       | template descriptor count }}
{{OBDtr| 0x20 | int32  | | 80 89 00 00 | 0x008980 | data table offset }}
{{OBDtr| 0x20 | int32  | | A0 BC 03 00 | 0x03BCA0 | data table offset }}
{{OBDtr| 0x24 | int32  | | 20 6E 55 00 | 0x556E20 | data table size }}
{{OBDtr| 0x24 | int32  | | A0 35 25 00 | 0x2535A0 | data table size }}
{{OBDtr| 0x28 | int32  | | A0 F7 55 00 | 0x55F7A0 | name table offset }}
{{OBDtr| 0x28 | int32  | | 40 F2 28 00 | 0x28F240 | name table offset }}
{{OBDtr| 0x2C | int32  | | 35 1D 00 00 | 0x001D35 | name table size }}
{{OBDtr| 0x2C | int32  | | 04 4F 02 00 | 0x024F04 | name table size }}
{{OBDtr| 0x30 | int32  | | 00 00 00 00 |          | OniSplit only: raw table offset }}
{{OBDtr| 0x30 | int32  | | 00 00 00 00 |          | OniSplit only: raw table offset }}
{{OBDtr| 0x34 | int32  | | 00 00 00 00 |          | OniSplit only: raw table size }}
{{OBDtr| 0x34 | int32  | | 00 00 00 00 |          | OniSplit only: raw table size }}
Line 23: Line 24:
|}
|}


The template checksum tells us that this level data is in the .dat/.raw file scheme, as opposed to the .dat/.raw/.sep file scheme.


The version of the instance file is the format version. This is written in ASCII characters, but you have to read it backwards because it's been written to disk in small-endian. Get used to this, because you'll be doing a lot of backwards-ASCII-reading. Thus we get "VR31", which is probably "version 31". This is the format version of all instance files in all releases of Oni.
The signature is identical in all instance files.
Next we are told the size of some arrays which are coming up soon: the instance, name and template descriptors. For instance, the size of the instance descriptor array will be 0x2483, or 9,347 items, in length.


The "instance descriptors" array stores information about every instance contained in the file.  
The "instance descriptors" array stores information about every instance contained in the file.