RuneScape uses a number of standard and non-standard data types.
Data types that are two bytes or larger can be stored and ordered in a variety of different ways. Generally people either use big endian or little endian.
In big endian order, the most significant byte (MSB) is stored first and the least significant byte (LSB) is stored last.
In little endian order, the least significant byte (LSB) is stored first and the most significant byte (MSB) is stored last.
RuneScape uses both little and big-endian byte orders throughout the protocol (however, the 194 client only uses big-endian order), presumably to make reverse-engineering of the protocol harder. Some confusion has arisen over the byte order as the data types are named incorrectly in Winterlove's server where little endian data types are incorrectly named as big endian types.
These datatypes can also be read/written by a DataWriter/DataReader implementation (DataStreams and Buffers)
|Official name||Datatype name||Jagex name||Encoding|
|C style string||string,String,char *,char||str,strbyte||text bytes then '\n' or 10|
|Java style string||string,String,char *,char||strraw||WORD length then text bytes|
Note that Jagex used to use a new line character as string terminator, in more recent versions they use the null character \0 or 0 to support multi-line strings.
|Winterlove's name||Jagex name||Read transformation||Write transformation|
|Special A||Unknown||value - 128||value + 128|
|Special C||Unknown||0 - value||0 - value|
|Special S||Unknown||128 - value||128 - value|
|SpaceSaverA||smarts||(value < 128) ? (((value - 128)<<8)+value) : value||if(value < 128) putword(value+32768) else putbyte(value);|
|SpaceSaverB||smart||((value<<8)+value) - 49152||if(i < 64 && i >= -64) putbyte(i + 64) else if(i < 16384 && i >= -16384) putword(i + 49152);|
|tribyte / RGBColour / 3Byte / int3 / medium||3||(value << 24) + (value << 16) + value||putbyte(value >> 24);putbyte(value >> 16);putbyte(value);|
Old engine: read until newline delimiter ("\n")
New engine: read until null byte (value 0).
Old engine: write and finish with newline delimiter ("\n")
New engine: write and finish with null byte (value 0).
Additionally, RuneScape also uses two integers that are different from a big- or low endian order. Both byte orders are called middle endian. Their orders could be described as following:
Middle endian big int: C3 D4 A1 B2
Middle endian small int: B2 A1 D4 C3
(A1 smallest D4 biggest byte)
Whenever data is to be sent to the server or to the client using bits; the stream needs to be prepared by setting the bit position. The bit position can be calculated by grabbing the current buffer position and multiplying it by 8. This can be seen below.
int bitPos = bufferPos * 8;