Archive Format

From RuneWiki
Jump to navigationJump to search

Introduction

Since 194 all way up until 377, all the files in cache 0 have an archive-like format which contains a collection of named files (e.g. BADENC.TXT is a file which contains bad words in the wordenc archive).

Usage

These files are used by the client for a variety of purposes. Some, such as the DATA file contain data themselves (in this case the interfaces). Others, such as the MAP_INDEX file, contain information about where to locate the map and landscape files in the cache.

Format

tribyte uncompressedsize
tribyte compressedsize

If the uncompressed and compressed sizes are equal, the whole file is not compressed but the individual entries are compressed using bzip2. If they are not equal, the entire file is compressed using bzip2 but the individual entries are not.

Also note, the magic id at the start of the bzip2 entries are not included in the cache. If you use an existing API to read the files and want to add this back, you must append the four characters: BZh1 before you decompress.

short fileCount

Each file entry has the format:

int nameHash
tribyte uncompressedSize
tribyte compressedSize

When you are looping through the files, you need to keep track of the file offset yourself. This psuedocode demonstrates how:

<geshi lang=java>

int offset = buffer.getCurrentOffset() + numFiles * 10;
for(int i = 0; i < numFiles; i++) {
   // read values
   int thisFileOffset = offset;
   offset += thisFileCompressedSize;
}

</geshi>

To get a named file by its name, you should first hash the name using this method:

<geshi lang=java>

public static int hash(String name) {
   int hash = 0;
   name = name.toUpperCase();
   for(int j = 0; j < name.length(); j++) {
       hash = (hash * 61 + name.charAt(j)) - 32;
   }
   return hash;
}

</geshi>

Then, loop through the file entries you loaded earlier to find a matching hash. Read the compressed file size from the offset. If the whole file is not compressed, you should decompress the individual entry.