Jump to content

OBD:Instance file format: Difference between revisions

added instance descriptor format for "..."; some wording tweaks
m (thoroughly commented out OniX, for consistency, but it shall return soon)
(added instance descriptor format for "..."; some wording tweaks)
Line 33: Line 33:
{{OBDtr| 0x08 | uint32  | | 31 33 52 56 | '13RV'    | .dat version (meant to be read as "VR31")<br>OniSplit's .oni files use '23RV' ("VR32") instead<!--<br>OniX's [[Oni (folder)|GDFX]] uses '33RV' ("VR33") to signify that the new data versioning system is in use--> }}
{{OBDtr| 0x08 | uint32  | | 31 33 52 56 | '13RV'    | .dat version (meant to be read as "VR31")<br>OniSplit's .oni files use '23RV' ("VR32") instead<!--<br>OniX's [[Oni (folder)|GDFX]] uses '33RV' ("VR33") to signify that the new data versioning system is in use--> }}
{{OBDtr| 0x0C | uint16  | | 40 00      | 64        | size of this header }}
{{OBDtr| 0x0C | uint16  | | 40 00      | 64        | size of this header }}
{{OBDtr| 0x0E | uint16  | | 14 00      | 20        | size of instance descriptor }}
{{OBDtr| 0x0E | uint16  | | 14 00      | 20        | size of instance descriptor (32 in Windows alpha 6) }}
{{OBDtr| 0x10 | uint16  | | 10 00      | 16        | size of template descriptor }}
{{OBDtr| 0x10 | uint16  | | 10 00      | 16        | size of template descriptor }}
{{OBDtr| 0x12 | uint16  | | 08 00      | 8        | size of name descriptor }}
{{OBDtr| 0x12 | uint16  | | 08 00      | 8        | size of name descriptor }}
Line 64: Line 64:


==Instance descriptors==
==Instance descriptors==
The instance descriptor array tells Oni where to find the data and the name of every instance (resource) indexed by the .dat file. The descriptors start at 0x40 in the .dat file, but below is a descriptor found at 0x017B50 in the file which makes a better example. In the table below, we use offsets relative to the start of this descriptor.
The instance descriptor array tells Oni where to find the data and the name of every instance (resource) indexed by the .dat file. The descriptors start at 0x40 in the .dat file, but below is a descriptor found at 0x017B50 in the file which makes a better example. In the table below, we use offsets relative to the start of this descriptor. We also show the alternate structure in the Windows alpha 6, the oldest known version of Oni and the only one with an observed difference in the instance descriptor format.


{| class="wikitable"
{| class="wikitable"
Line 73: Line 73:
! width=10% | Value
! width=10% | Value
! width=35% | Description (retail<!--, OniX-->)
! width=35% | Description (retail<!--, OniX-->)
! width=35% | Description (...)
|- align=center
|- align=center
| 0x00
| 0x00
Line 79: Line 78:
| 54 42 55 53
| 54 42 55 53
| 'SUBT'
| 'SUBT'
|colspan="2" align=left | template tag
|align=left | template tag
|- align=center
|- align=center
| 0x04
| 0x04
Line 85: Line 84:
| C8 30 22 00
| C8 30 22 00
| 0x2230C8
| 0x2230C8
|colspan="2" align=left | data offset (relative to data table)
|align=left | data offset (relative to data table)
|- align=center
|- align=center
| 0x08
| 0x08
Line 91: Line 90:
| 01 CB 00 00
| 01 CB 00 00
| 0xCB01
| 0xCB01
|colspan="2" align=left | name offset (relative to name table)
|align=left | name offset (relative to name table)
|- align=center
|- align=center
| 0x0C
| 0x0C
Line 97: Line 96:
| C0 09 00 00
| C0 09 00 00
| 2496
| 2496
|colspan="2" align=left | data size
|align=left | data size
|- align=center valign=top
|- align=center
| 0x10
| 0x10
| int32
| int32
| 00 00 00 00
| 00 00 30 00
| 0
| 0x300000
| align=left | flags
|align=left | flags
| align=left | alt. flags
|}
|}


This descriptor tells us that a resource of '''type''' SUBT (a subtitle file for Oni; there are only two of these, one containing all speech subtitles, and one for help messages) has '''data''' that can be found 0x2230C8 bytes into the data table, which we learned from the file header starts at 0x03BCA0. Its '''name''' can be found 0xCB01 bytes into the name table that starts, according to the file header, at 0x28F240. The '''data's size''' is 0x09C0, or 2,496 bytes. Before we proceed, let's expand upon the '''flags''' field.
{{Divhide|Windows alpha 6}}
{| class="wikitable"
|- bgcolor="#E9E9E9"
! width=5% | Offset
! width=5% | Type
! width=10% | Raw Hex
! width=10% | Value
! width=35% | Description (alpha 6)
|- align=center
| 0x00
| int64
| 68 6C 04 00
| 0x46C68
|align=left | template checksum
|- align=center
| 0x08
| tag
| 54 42 55 53
| 'SUBT'
|align=left | template tag
|- align=center
| 0x0C
| int32
| E8 37 18 00
| 0x1837E8
|align=left | data offset (relative to data table)
|- align=center
| 0x10
| int32
| 4E C5 00 00
| 0xC54E
|align=left | name offset (relative to name table)
|- align=center
| 0x14
| int32
| 20 08 00 00
| 2080
|align=left | data size
|- align=center
| 0x18
| int32
| 00 00 30 00
| 0x300000
|align=left | flags
|- align=center
| 0x1C
| int32
| EA 5F A6 39
| {{LocaleDate|2000|08|25}}<br>08:00:42 AM
|align=left | creation date (seconds since 1/1/1900)
|}
{{Divhide|end}}
The retail version of this instance descriptor tells us that a resource of '''type''' SUBT (a subtitle file for Oni; there are only two of these, one containing all speech subtitles, and one for help messages) has '''data''' that can be found 0x2230C8 bytes into the data table, which we learned from the file header starts at 0x03BCA0. Its '''name''' can be found 0xCB01 bytes into the name table that starts, according to the file header, at 0x28F240. The '''data's size''' is 0x09C0, or 2,496 bytes. Before we proceed, let's expand upon the '''flags''' field.


;Flags - data usage
;Flags - data usage
Line 122: Line 172:


<!--;Flags - Tool mode (OniX)
<!--;Flags - Tool mode (OniX)
These bits have been moved to the upper half of the flags byte (on disk they are cleared altogether in the GDFX data, but this is their location in memory):
These bits have been moved to the upper half of the first byte (on disk they are cleared altogether in the GDFX data, but this is their location in memory):
:0x'''10''' 00 00 00 - touched (unsaved data)
:0x'''10''' 00 00 00 - touched (unsaved data)
:0x'''20''' 00 00 00 - "in batch file"
:0x'''20''' 00 00 00 - "in batch file"
Line 181: Line 231:
The '''template checksum''' is used to prevent loading of instance files that are not compatible with the current engine version. The '''tag''' is the same kind of number-written-as-backwards-ASCII that we discussed in the "Backwards and garbage data" section; in this case, 'EGRT' means [[TRGE]]. The field for the '''number of resources''' using this template is unused. The number should be correct for each template, but Oni never uses it for anything.
The '''template checksum''' is used to prevent loading of instance files that are not compatible with the current engine version. The '''tag''' is the same kind of number-written-as-backwards-ASCII that we discussed in the "Backwards and garbage data" section; in this case, 'EGRT' means [[TRGE]]. The field for the '''number of resources''' using this template is unused. The number should be correct for each template, but Oni never uses it for anything.


You might wonder how Oni knows how to read each type of data, such as a SUBT or an ABNA. The simple answer is that this information is hard-coded into Oni. In fact, the information on each instance type, as stored in Oni's code, is actually the real "template". The file data only gives the tag and checksum that refer to a certain template. Which types of data fields are encountered in which order is already known by Oni. These hardcoded templates also tell Oni which parts of the file data are reserved for pointers.
You might wonder how Oni knows how to read each type of data, such as a SUBT or an ABNA. The simple answer is that this information is hard-coded into Oni. In fact, the information on each instance type, as stored in Oni's code, is actually the real "template". The file data merely gives the tag and checksum that identify the template in use so that Oni knows how to read the following data fields. These hardcoded templates also tell Oni which parts of the file data are reserved for pointers.


That's because an instance may have pointers to other related instances, but pointers are only valid in memory; they cannot be stored on disk. They must be set when the level data is loaded into memory and the address in RAM has been determined. So one type of data field in Oni's templates is a raw pointer; on Macs and the Windows demo, there is an additional "separate offset" type. The pointer and offset are 32 bits in length, as one must expect since Oni was compiled for 32-bit PCs.
That's because an instance may have pointers to other related instances, but pointers are only valid in memory; they cannot be stored meaningfully on disk. They must be set at runtime when the level data is loaded into memory and an address in RAM has been assigned. Thus one type of data field in Oni's templates is a "raw data" pointer; on Macs and the Windows demo, there is an additional "separate data" pointer. These pointers are 32 bits in length, as one must expect since Oni was compiled for 32-bit PCs.


Incidentally, the templates in Oni's code have not just the familiar four-character tags attached to them, but also a descriptive string, e.g. "BSP Tree Node Array". This is the source of the names on the [[OBD:File types|File types]] page.
Incidentally, the templates in Oni's code have not just the familiar four-character tags attached to them, but also a descriptive string, e.g. "BSP Tree Node Array". These strings were typed into the source code where each template structure was defined, and eventually extracted by modders. This is the source of the names on [[OBD:File types]].


==Data table==
==Data table==
Line 198: Line 248:
{{OBDtr| 0x00 | res_id  | | 01 00 00 00 | 0  | instance ID }}
{{OBDtr| 0x00 | res_id  | | 01 00 00 00 | 0  | instance ID }}
{{OBDtr| 0x04 | lev_id  | | 01 00 00 00 | 0  | file ID }}
{{OBDtr| 0x04 | lev_id  | | 01 00 00 00 | 0  | file ID }}
{{OBDtr| 0x08 | ...    | | ...        | ... | [[OBD:File_types|type-specific data]]... }}
{{OBDtr| 0x08 | ...    | | ...        | ... | [[OBD:File types|type-specific data]]... }}
|}
|}