Difference between revisions of "Data Types"

From RuneWiki
Jump to navigationJump to search
 
(10 intermediate revisions by 7 users not shown)
Line 3: Line 3:
 
RuneScape uses a number of standard and non-standard data types.
 
RuneScape uses a number of standard and non-standard data types.
  
== Endianness or byte order ==
+
== Byte Order ==
You probally know the LE or littleendian variants of datatypes, the only difference is the byte order,
+
 
intel and amd (x86) pc's use a little endian order natively while rs uses mostly bigendian values, where a little endian stores the short value 10011001 11011011 as 11011011 10011001 a big endian stores it as 10011001 110011011, winterlove called little endian big endian values so be aware.  
+
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.
 +
 
 +
=== Big Endian ===
 +
 
 +
In big endian order, the most significant byte (MSB) is stored first and the least significant byte (LSB) is stored last.
 +
 
 +
=== Little Endian ===
 +
 
 +
In little endian order, the least significant byte (LSB) is stored first and the most significant byte (MSB) is stored last.
 +
 
 +
=== Byte order in RuneScape ===
 +
 
 +
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 [[Server:Winterlove|Winterlove]]'s server where little endian data types are incorrectly named as big endian types.
  
 
== Standard data types ==
 
== Standard data types ==
Line 14: Line 26:
 
! Official name
 
! Official name
 
! Datatype name
 
! Datatype name
! JaGeX name
+
! Jagex name
 
! Encoding
 
! Encoding
 
|-
 
|-
Line 21: Line 33:
 
| 1,1b
 
| 1,1b
 
|-
 
|-
| WORD
+
| [[Word|WORD]]
 
| short
 
| short
 
| 2,2b
 
| 2,2b
 
|-
 
|-
| DWORD
+
| [[DWord|DWORD]]
 
| int,int32
 
| int,int32
 
| 4,4b
 
| 4,4b
 
|-
 
|-
| QWORD
+
| [[QWord|QWORD]]
 
| long,int64
 
| long,int64
 
| 8,8b
 
| 8,8b
Line 43: Line 55:
 
| WORD length then text bytes
 
| WORD length then text bytes
 
|}
 
|}
Note that jagex used a newline character as string terminator for a while, nowadays they use the
+
 
null character \0 or 0 to support multiline strings
+
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.
  
 
== Non Standard Data Types ==
 
== Non Standard Data Types ==
  
 
{| border=2
 
{| border=2
! winterLove name
+
! Winterlove's name
! JaGeX name
+
! Jagex name
 
! Read transformation
 
! Read transformation
 
! Write transformation
 
! Write transformation
Line 83: Line 96:
 
| (value[0] << 24) + (value[1] << 16) + value[2]
 
| (value[0] << 24) + (value[1] << 16) + value[2]
 
| putbyte(value >> 24);putbyte(value >> 16);putbyte(value);
 
| putbyte(value >> 24);putbyte(value >> 16);putbyte(value);
 +
|-
 +
| [[RS String|RS_String]]
 +
| jstr
 +
| Old engine: read until newline delimiter ("\n") <br />New engine: read until null byte (value 0).
 +
| Old engine: write and finish with newline delimiter ("\n") <br />New engine: write and finish with null byte (value 0).
 
|}
 
|}
  
Additionally, RuneScape also uses two additional integers (named int 1 and int 2).
+
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)

Latest revision as of 21:19, 29 March 2010

Introduction

RuneScape uses a number of standard and non-standard data types.

Byte Order

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.

Big Endian

In big endian order, the most significant byte (MSB) is stored first and the least significant byte (LSB) is stored last.

Little Endian

In little endian order, the least significant byte (LSB) is stored first and the most significant byte (MSB) is stored last.

Byte order in RuneScape

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.

Standard data types

These datatypes can also be read/written by a DataWriter/DataReader implementation (DataStreams and Buffers)

Naming conventions:

Official name Datatype name Jagex name Encoding
Byte byte 1,1b
WORD short 2,2b
DWORD int,int32 4,4b
QWORD long,int64 8,8b
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.

Non Standard Data Types

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[0] < 128) ? (((value[0] - 128)<<8)+value[1]) : value[0] if(value < 128) putword(value+32768) else putbyte(value);
SpaceSaverB smart ((value[0]<<8)+value[1]) - 49152 if(i < 64 && i >= -64) putbyte(i + 64) else if(i < 16384 && i >= -16384) putword(i + 49152);
tribyte / RGBColour / 3Byte / int3 3 (value[0] << 24) + (value[1] << 16) + value[2] putbyte(value >> 24);putbyte(value >> 16);putbyte(value);
RS_String jstr 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)