ClientScript

From RuneWiki
Jump to navigationJump to search
Cleanup

This article requires cleaning up to adhere to our quality standards. You can help RuneWiki by improving it.


Introduction

ClientScript is an bytecode scripting language made by Jagex. It is used to automate certain interface actions in RuneScape. There are two versions: 1 and 2.

ClientScript1

No information is currently known about version 1 of ClientScript.

ClientScript2 (CS2)

File Format

The runtime loads the last two bytes of the file, which contain the footer length, after these bytes are read it seeks to the following position of the file:

(file.length - 2) - (data_length + 12)

Then it reads the script footer:

Script length in instructions - DWord; Integer variable count - Word
String variable count - Word
Integer Argument Count - Word
String Argument Count - Word

And a resource table:

Resource table length in nodelists - [[Byte]]
For each nodelist: 
    List length in entries - [[Word]]
    For each node:
        Key - [[DWord]]
        Value - [[DWord]]

Then it seeks to the file start and reads the script name as a null terminated string, after this the opcodes and operands:

For each instruction:
     Opcode - Word
     For opcode 3:
         Operand - String
     For opcode's 21 , 38 , 39 and opcode's > 100
         Operand - Word
     For all other opcode's
         Operand - Byte

Script Architecture

The ClientScript2 system uses a stack and a variable pool for storage. There are two stacks:

  • The integer stack
  • The string stack

There are also three variable pools:

  • The integer variable pool - Used for arguments and local variables , size set in footer
  • The string variable pool - Used for arguments and local variables , size set in footer
  • The integer array pool - Used for arrays with a length up to 5000 , fixed-size : 5

Basic instruction set

  • 0 - Push Operand onto Integer Stack
  • 1 - Push Client configuration onto Integer Stack
  • 2 - Pop a value from the Integer Stack to the client configuration array
  • 3 - Push String Operand onto String Stack
  • NO OPCODES EXIST IN RUNESCAPE #508 HERE
  • 6 - Jump to position given as operand
  • 7 - Branch if not equal - Stack values , operand jump
  • 8 - Branch if equal - Stack values , operand jump
  • 9 - Branch if smaller than - Stack values , operand jump
  • 10 - Branch if bigger than - Stack values , operand jump
  • 21 - Return , stops script execution or if script is called by gosub, go back to call point
  • 25 - Push Varbit value
  • 27 - Pop Varbit value
  • 31 - Branch if smaller than or equal - Stack values , operand jump
  • 32 - Branch if bigger than or equal - Stack values , operand jump
  • 33 - Push Integer Variable onto Integer Stack
  • 34 - Pop Integer Variable off the Integer Stack
  • 35 - Push String Variable onto the String Stack
  • 36 - Pop String Variable off the String Stack
  • 37 - Merge String Stack from stSC to stSC-operand
  • 38 - Decrease StackCounter(SC) by one
  • 39 - Decrease String StackCounter(stSC) by one
  • 40 - Gosub - Excecutes the script given as operand, the arguments of the script are popped from the stacks
  • 42 - Push secondary client configuration onto integer stack
  • 43 - Pop secondary client configuration off integer stack
  • 44 - Define array - Defines the array given in the first 16 bytes of the operand, and pops the size from the integer stack, also this sets all array values to -1 or zero depending on the second 16 bytes of the operand
  • 45 - Push array value of the array given as operand and slot from the stack onto the integer stack
  • 46 - Pop array value of the array given as operand and slot from the stack off the integer stack
  • 47 - Push static string variable onto string stack
  • 48 - Pop static string variable value off string stack
  • 51 - Switch branch

Advanced Instruction Set

These are the instructions to manipulate interfaces and players, there are around 3000 instructions in this category.