Data Types
The RuneScape client and server communicate through a binary protocol for optimal bandiwdth usage. A value transmitted over the RS protocol will not exceed the bounds of the type of data it is encoded as. Because the client is written in Java, it expects Big-Endian integers by default.
Normal Types
Numbers
The numbers used in the RuneScape protocol are integers. Minimums and maximums represent the inclusive total range of values.
Name | Bytes | Signed Minimum | Signed Maximum | Unsigned Maximum |
---|---|---|---|---|
Byte |
1 | -128 | 127 | 255 |
Short |
2 | -32,768 | 32,767 | 65,535 |
Triple |
3 | -8,388,608 | 8,388,607 | 16,777,215 |
Int |
4 | -2,147,483,648 | 2,147,483,647 | 4,294,967,295 |
Long |
8 | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,615 |
Strings
Huffman Encoding
Chat messages are encoded using Huffman Encoding.
Arrays
Endianness
Numbers and Strings in the RuneScape protocol may be encoded in different formats when transmitted across the wire. The client must know what endianness to expect in order to properly decode the source value. This is done by Jagex during client code generation using a map generated beforehand and alters network code as part of the obfuscation process to prevent decoding of the data. Because game data is not encrypted in transit, only obscured, it does not alter the minimum or maximum value the number truly represents and serves no other function.
Example
Using an Int type as an example, with four bytes, A = 0, B = 2, C = 3, D = 4 to represent the original byte offset.
Endian | Bytes |
---|---|
Big | A B C D |
Little | D C B A |
Middle Big | B A D C |
Middle Little | C D A B |
Big Endian
The default Endianness of numbers in Java, also known as "network order" in TCP. Data is stored left (MSB) to right (LSB).
Little Endian
The reverse of Big Endian. Data is stored right (LSB) to left (MSB).
Middle Big
Only applies to Int types.
Middle Little
Like Middle Big, this will only apply to Int types.
Value Transformations
Numbers in the RuneScape protocol may have transformations applied to them which can obscure the byte values of the data. Currently, the protocol supports 3: Addition, subtraction, and negation. The client must know what transformation that was applied to the value in order to properly decode the source value.
Obscurity
This is done to prevent decoding of the data, because game data is not encrypted, but instead obscured, in transit as it does not alter the minimum or maximum value the number truly represents and serves no other function.
Reciprocity
Like endianness transformations, data transformations applied to values must be decoded using a reciprocal operation to the one that was applied. These transformations apply to only a specific byte, at index 0.
The Writer applies the value transformation after endianness transformation and the Reader will apply value transformation before the endianness transformation.
For your convenience, a table below shows the proper reciprocal operations to apply for a written value in order to read the original value.
Operation | Writer | Reader |
---|---|---|
Add |
v += 128 | v += 128 |
Subtract |
v = 128 - v | v = 128 - v |
Negate |
v = -v | v = -v |