Cache format

From Old School RuneScape Wiki
Jump to navigation Jump to search

This page describes the technical information about the RuneScape:Cache. The information is currently work-in-progress.

Legacy cache format

[edit | edit source]

This cache format was used for builds 244 through 377.

There are 5 files as shown in the table below. The main data Cache is separated into Archives, then individual Files. The archives and files are defined by Index Files which allow individual files to be accessed individually.

File Contents
main_file_cache.dat Actual game data
main_file_cache.idx0 Subarchives index
main_file_cache.idx1 Model index
main_file_cache.idx2 Animation index
main_file_cache.idx3 Sound index
main_file_cache.idx4 Map index

Index files

[edit | edit source]

Index files (.idx) can be thought of as large Tables of Contents like you would see in a book. The index files are a series of bytes which tell where individual files are within the main data cache so that they can be retrieved and used. Without them, the main data cache is essentially an unorganized blob of bytes. By dividing the total number of bytes in an Index by 6, you can determine to the total amount of files within.

Index Format
Each index entry is 6 bytes
Each index entry is 6 bytes
Information Type Description
File Size Medium (3 bytes) The size of the file that this Index points to
Offset Medium (3 bytes) The first Sector of the file that this Index points to
Example: Two indexes are highlighted in main_file_cache.idx0. The second Index shows that this file is 51,973 bytes in size

and starts at the second Sector in the data file.

Data files

[edit | edit source]

The main data cache file (main_file_cache.dat) contains all the game files including models, textures, and maps, as a series of Sectors. A Sector is a 520 byte block of data that includes an 8 byte header and 512 bytes data. Multiple Sectors make up a single file, so the header of the Sector tells you which file it belongs to. Files can be extracted by combining all of the Sector's data for that file, then decompressing as required.

Sector Format
Information Type Description
File ID Unsigned Short The file that this Sector belongs to
Chunk ID Unsigned Short Which chunk of the file the data of the Sector is
Next Sector ID Medium (3 bytes) The next sector of data belonging to this file. A sector ID of 0 indicates end of file
Type ID Unsigned Byte The type of file this Sector belongs to. It is equal to the idx number + 1
Data 512 bytes The raw data that this Section contains

Example

[edit | edit source]

An Index file defined a file with size 1,561 bytes at Sector 668. The starting position of the data buffer can be found by multiplying the starting Sector by 520, position 347,360 in this case. By looping through the Sectors and copying the data bits until reaching the end of file (EOF) Next Sector ID, the total data for file 4 is obtained.

Sector Example
Sector 0 Sector 1 Sector 2 Sector 3
File ID 4 4 4 4
Chunk ID 0 1 2 3
Next Sector ID 669 670 671 0
Type ID 1 1 1 1
Data 512 bytes 512 bytes 512 bytes 25 bytes + 487 bytes 0

Other files

[edit | edit source]

flo.dat

[edit | edit source]

This file defines the floors used in game.

map_index

[edit | edit source]

This file defines the map coordinates and which map files are used.

Map Index Format
Information Type Description
X Coordinate Unsigned Byte X coordinate of map region
Y Coordinate Unsigned Byte Y coordinate of map region
File ID Unsigned Byte The File ID's containing the map data
Member's Flag Unsigned Byte 0 if Member's region, 1 if F2P

Utility methods

[edit | edit source]

getMedium

[edit | edit source]
public static int getMedium(ByteBuffer buf) {
		return ((buf.get() & 0xFF) << 16) | ((buf.get() & 0xFF) << 8) | (buf.get() & 0xFF);
	}