High quality resource

From LBA File Information
Revision as of 10:08, 10 February 2013 by Zink (talk | contribs)
Jump to navigation Jump to search
High quality resource
Extension

HQR

Occurence

LBA1 & LBA2

Programs supporting this format

High Quality Resources, also called package files, resource files or archives are containers for other smaller files. Their purpose is identical to zip, rar or tar.gz archives: to keep large amounts of files in a more efficient way (easier to copy and using less space by using compression).

All resource package formats (HQR, VOX, ILE and OBL) share the same format, they differ only in purpose.

  • HQR - stands for High Quality Resource - these files are of general usage. They contain various types of files, like images, text strings, 3D objects.
  • VOX - contain voices that you hear in the game. In LBA 1 these archives contain VOC files, in LBA 2 - WAV files. Note that VOX extension also means "Dialogic ADPCM" according to some programs, but the files used in LBA 1 are not Dialogic ADPCM format despite the identical extension.
  • ILE - contain 3D islands for LBA 2.
  • OBL - contain 3D objects for appropriate islands (LBA 2 only).

Types of entries

There are four kinds of entries, that are stored inside resource files:

  • Normal entries - contain "physical" data that can be extracted to a file.
  • Hidden entries - also contain data, but are not specified in the header. They are placed in the gaps between normal entries. Entries of this kind are present only in VOX files. They are used to split long speech data into smaller pieces (probably because the engine isn't able to play big files at once).
  • Repeated entries - do not contain data, but just references (addresses) to normal entries. This method is a kind of compression - two or more files that contain identical data can be stored as one copy of the data that is just referenced many times. This allows saving disk space without changing the resource file structure.
  • Blank entries - do not contain data, but empty addresses (of zero value). They are probably entries that have been deleted at the alpha/beta stage of the game and they were left in the header to keep the resource file structure unchanged.

Specification

See also: HQR compression

--------------------------------------------------------------------
 LBA High Quality Resource (HQR) file format
 Author: Kazimierz Król (zink)
 Based on HQR format description written by el-muerte.
 Revision: 1.0
--------------------------------------------------------------------

This format applies to HQR, VOX, ILE and OBL files from LBA 1 and 2.

Resource files are containers for other files, like .zip archives (they can be compressed too). But unlike the .zip files, the files inside them (called "entries") don't have names (the names are not kept inside the resource files). The game recognizes which entry is which by their position inside the resource file, so all programs that allow replacing the entries have to keep the rest of the entries in the same order as in the original file.


At the beginning of the file there is an offset block. This block consists the offsets (addresses) to the entries that are placed further in the file. Addresses are 4-bytes long numbers (DWORDs) in Intel notation. There are 3 types of the addresses:

Normal addresses - are not distinguished by anything special.

Blank addresses - are addresses equal to 0x00000000. Such address means that there is no data associated with it (i.e. it is an empty slot for a file). Such addresses cannot be removed from the resource file, because the structure would then change. Blank addresses are still entries.

Repeated addresses - are addresses equal to one of the previous normal addresses. In case that two or more identical entries (with identical data) need to exist in the same resource file, data of only first of them will be actually kept, and the rest will be just references (addresses) to the same block of data. The game sees repeated addresses as regular normal addresses, and access the data in normal way.


At the end of the offset block there is one additional address which is equal to the file size in bytes.


Each of the addresses (except for blank addresses) points to a block of data (actually start of its header). The header is always 10 bytes long and its format is following:

 - first four bytes is the original size of the data block (uncompressed) as DWORD.
 - next four bytes is the compressed (actual) size of the data block as DWORD.
 - next two bytes is the compression type as WORD. 0 is for no compression, 0x0001 for compression type 1 and 0x0002 for compression type 2.

After the header there is the data block, which length is equal to the "compressed size" value in the header.

If the compression type value is 0x01 or 0x02, then the data after the header is compressed. For more information about the compression, see the LBA_Compression_EN.txt file


Hidden entries
----------------

 There is also a kind of entries called "hidden entries". These entries are special, because they don't have addresses pointing to them in the address block. They can be found by comparing one entry ofset and length with the next entry offset. If the offset + length + 10 is not equal to the next entry offset, then it is sign that a hidden entry exists between the two entries. 
 
 Hidden entries appear in VOX resources only. They are used to split one large voice sample into smaller pieces, probably because the engine can't play large samples. Thus no hidden entry can occur as the first entry in a resource, but only as gorups: one normal plus several hidden after it.
 
 The normal entry and the hidden ones within the same group have the first byte of the data (in the uncompressed stage) modified. All entries in the gorup (including the normal one) have the first byte changed to 0x01, and the last hidden entry of the group has the first byte changed to 0x00.
 These changes probably indicate to the game that after the normal entry there are also some hidden ones, and the 0x00 byte indicates the last one, so the game doesn't have to do the offset/length computations. What if a normal ehtry will have its regular first byte of 0x01? That's not possible. Hidden entries are used in VOX files ONLY, and there are only two kids of files stored inside them: .voc files for LBA 1, which have the text "Creative" at the beginning, and .wav files for LBA 2, which have the text "RIFF" at the beginning, so no entry with byte 0x01 at the data beginning is normally possible.

Information provided by: El Muerte, Zink