Packets Guide
Packets are short for "network packets" and define how data is packaged and sent over the network from the OSRS client to the server where it is processed. There are a huge number of packets on both the client and server side (250+ I think), but most people are interested in the client -> server packets for creating automation scripts and other tools of that nature.
This guide will walk you through:
- The creation of a packet
- How a packet is processed
- Example code
- Table of different packet types
The Packet Creation Pipeline
When you click on an NPC, Object, Widget, Interface, or Dialogue (or most things in the game), a packet will ultimately be created to process the click on the server side. The following section details an example sequence of events the client executes for orchestrating the creation of a network packet.
Identify the Action
The client determines you are trying to "Attack NPC" (MenuAction.NPC_FIRST_OPTION). This particular click gets routed to the doAction function, a single function which handles menu action clicks for players, NPC's, game objects, interfaces, and chat dialogues in the game. It finally grabs the specific ClientPacket for the action you performed (OPNPC1) and stores it in an object.
Initialize the Node
The client creates a new PacketBufferNode. This class is used as a container to store the data that will be sent over the network. It includes references to the PacketWriter used to write to the TCP connection and the PacketBuffer used to write the data.
Encrypt the Opcode
The client takes the opcode (a numerical value representing an enum for actions you can take in game) from the ClientPacket, encrypts it using the IsaacCipher, and writes that encrypted opcode as the very first byte(s) of the PacketBuffer. This essentially encodes the "type" of the packet being sent so that the server knows how to process it. Opcodes coninside with the MenuAction enum in RuneLite and are an effective way to identify the type of packet being sent from the obfuscated source code.
I believe the packet's payload length is also encrypted into the PacketBuffer (however, I have not verified this).
Write the Payload
The client uses the PacketBuffer to write the specific details (params) of the action. Each packet will contain a different set of params. This makes sense since each packet is different and requires different data to be sent. i.e. You don't need to send the ID of a nearby tree if you are withdrawing an item from your bank, but you would need to send the ID of the nearby tree if you are clicking on it to examine or chop it down.
For example, the OPNPC1 packet for clicking the first menu action on a Goblin ("Attack") includes the:
- NPC Index
- CtrlDown (1 if you are holding down control to invert walk/run)
- Subop (extra parameter for highlighting the index of a submenu if OSRS chooses to include submenus for NPC's). A sub-menu example would be something like the additional teleport options that pop out when you hover over "Rub" on a ring of dueling.
Queue
The client finally calls the addNode() method to put the packet in the outgoing queue where it will be sent on the next game tick by the PacketWriter.
Example Code
// 1. Grab the specific ClientPacket we want to send (e.g., Object Click)
ClientPacket objectClickPacket = client.getObjectClickPacket();
// 2. Create the PacketBufferNode.
// The client automatically uses the IsaacCipher to encrypt the opcode during this step.
PacketBufferNode packetNode = client.preparePacket(objectClickPacket, client.getIsaacCipher());
// 3. Get the buffer so we can write our payload data
PacketBuffer buffer = packetNode.getPacketBuffer();
// 4. Write the payload data into the buffer.
// The order AND data types (Int, Short, Byte) MUST perfectly match what the server expects.
buffer.writeInt(9730); // Example: The ID of the object (e.g., a tree)
buffer.writeShort(3200); // Example: The X coordinate
buffer.writeShort(3200); // Example: The Y coordinate
buffer.writeByte(0); // Example: Control/Shift click status
// 5. Add the finished node to the outgoing queue to be sent to Jagex
client.addNode(packetNode);Packet Types
| Packet Type | Params | Example | Description |
|---|---|---|---|
| EVENT_MOUSE_CLICK | mouseX, mouseY, 0, mouseInfo | Clicking anywhere on the game canvas | Sent to notify the server that the mouse was clicked. It includes information about the x/y coordinate that was clicked and which mouse button (left/right) was clicked. |
| IF_BUTTONT | sourceSlot, sourceItemId, sourceWidgetId, destinationItemId, destinationWidgetId, destinationSlot | Using high level alchemy on an item in your inventory WIDGET_ON_WIDGET | Interface button target, This packet is sent when an interface element is used on another interface element. |
| IF_BUTTONX | widgetId, slot, itemId, opCode | Clicking "eat" on a shark in your inventory | A standard interface button click. Equipping gear, eating food, withdrawing items all use this packet. |
| IF_SUBOP | widgetId, slot, itemId, menuIndex, subActionIndex | Clicking "Ferox Enclave" in the pop out menu of the ring of dueling's "Rub" option | Sent when a sub menu is clicked. Sub menus include things like max/skill cape teleports, jewelry teleports, etc... Anything that an additional menu pops up when you hover your mouse |
| MOVE_GAMECLICK | 5, ctrlDown, worldPointX, worldPointY | Moving to a new tile | Sent when your player moves, simple as that. |
| OPLOC1-5 | worldPointX, worldPointY, subop, objectId, ctrlDown | Mining a rock or examining a tree | Game object clicks. There are 5 of these 1 for each menu action on a game object. i.e. Mine, Walk Here, Cancel, Examine etc... |
| OPLOCT | objectId, ctrlDown, worldPointX, worldPointY, slot, itemId, widgetId | Filling up a bucket from a fountain | Operaction location target. Sent when using a widget in your inventory on a game object. |
| OPNPC1-5 | npcIndex, ctrlDown, subop | Attacking a Goblin | Sent when you click on a menu action for an NPC. There are 5 of these for 5 potential options on NPC's like Attack, Talk-To, Bank, Examine, etc... |
| OPNPCT | npcIndex, itemId, widgetId, slot, ctrlDown | Using fire strike on a Varrock guard | Sent when you use a widget on an NPC like casting a spell on an NPC or giving a quest NPC food. |
| OPOBJ1-5 | subop ctrlDown, worldPointX, worldPointY, objectId | Picking up a twisted bow from the ground | Sent when you interact with an item on the ground e.g. TileItem. |
| OPOBJT | slot, objectId, worldPointY, widgetId, worldPointX, itemId, ctrlDown | Using telekenetic grab on an item on the ground. | Sent when using a widget targeting a ground item. |
| OPPLAYER1-8 | ctrlDown, playerIndex | Following or trading with a player | Sent when you perform 1 of 8 menu actions on another player. |
| OPPLAYERT | itemId, slot, ctrlDown, widgetId, playerIndex | Using neutralizing potion on a player in ToA's monkey room. | Sent when using a widget targeting another player. i.e. using an item on another player |
| RESUME_COUNTDIALOG | var0 | Withdrawing X items from the bank and the bank asking what to set X's value to | Sent when the game needs a numerical input from you like withdrawing x items. |
| RESUME_OBJDIALOG | var0 | Selecting searched item in the G.E. | Sent when the game needs an item selection from you. This is most commonly used with the grand exchange when players click on an item they searched for to buy or sell. |
| RESUME_NAMEDIALOG | length, string | Adding a friend or joining a chat | Sent when the game needs a string input from your chatbox. |
| RESUME_PAUSEBUTTON | var1, var0 | Continuing dialogue with an NPC | Sent when the game pauses the conversation dialogue between you and an NPC. You must "Click here to continue" to send this packet and continue to the next dialogue node in the tree |
| OPHELD | destChildIndex, selectedChildIndex, selectedId, destId, selectedItemId, destItemId | Doing that humpty dumpty quest puzzle | Sent when a drag and drop action occurs in the client. I don't have many great examples of this packet. |
| SET_HEADING | orientation | Changing your sailing boat's heading | Sent when you change the direction your sailboat is facing |