SDK Packets Reference
Low-level packet construction and parsing — the NPacketWriter typed send methods, the send pipeline, PacketBuffer codecs, and packet events.
Low-level packet construction and parsing in base-api, plus the typed send methods on NClient.getPacketWriter(). Read SDK Client Reference first for the thread-affinity contract; interaction-level packets are documented there and in SDK Game Reference. Source of truth: docs/sdk-packets-reference.md in the n3Client repository.
Purpose
Two consumers exist:
- The interaction APIs —
NpcAPI.interact,WidgetAPI.interact, movement clicks, etc. — call one typedNPacketWritermethod per action. Most SDK work never leaves this layer. - Custom packet authors — build an
NClientPacket, fill anNPacketBuffer(Jagex-encoded accessors), wrap it in anNPacketBufferNode, and hand it toNPacketWriter.addNode. Thedev.n3u.packetspackage supplies the buffer implementation, a byte pool, and the server-packet map reader used for analysis.
Send pipeline (base-api/src/main/java/dev/n3u/api/)
NClient.newClientPacket(id, length) → NClientPacket (id + length)
NClient.getPacketBufferNode(packet, cipher) → NPacketBufferNode (buffer + packet pair)
fill NPacketBuffer (extends NBuffer) → Jagex-encoded fields
NPacketWriter.addNode(node) → queued for the connection (Isaac-encrypted)NPacketBufferNode.getPacketBuffer() / .getClientPacket() are the only accessors (NPacketBufferNode.java). NIsaacCipher marks the cipher used for encryption; obtain it from NPacketWriter.getIsaacCipher().
NPacketWriter — typed send methods
From base-api/src/main/java/dev/n3u/api/NPacketWriter.java (extracted 2026-11-06):
- Meta:
addNode(NPacketBufferNode),getIsaacCipher(),getServerPacket(),getServerPacketLength(),getServerPacketBuffer() - Input:
clickPacket(3)— used by theSTATIC/RANDOM/CONTROLLEDstrategies (base-api/src/main/java/dev/n3u/services/ClickManager.java:270-381, fallbackdefaultStaticClickPacket:396-399); theNONEstrategy sends no click packet - Widgets:
widgetActionPacket(4),widgetActionSubOpPacket(5),widgetDragPacket(6),widgetTargetOnGameObjectPacket(7),widgetTargetOnNpcPacket(5),widgetTargetOnPlayerPacket(5),widgetOnWidgetPacket(6),widgetOnGroundItemPacket(7),resumeCountDialoguePacket(1),resumeStringDialoguePacket(1),resumeObjectDialoguePacket(1),resumePauseWidgetPacket(2) - World:
walkPacket(3),setHeadingPacket(1),objectActionPacket(5),groundItemActionPacket(5),playerActionPacket(3),npcActionPacket(3) - Items:
itemActionPacket(3),itemOnItemPacket(4),itemOnGameObjectPacket(6),itemOnPlayerPacket(4),itemOnNpcPacket(4) - Chat:
chatPacket(2)
Two further declarations in the file — resumeNameDialoguePacket(String) (NPacketWriter.java:219) and interfaceClosePacket() (:237) — are commented out in source and therefore not callable; they are listed here only so a reader grepping the interface understands why they appear without being usable.
Consumers: the api interaction facades (verified calls: npcActionPacket at api/src/main/java/dev/n3u/api/entities/NpcAPI.java:71-72, widgetActionPacket at api/src/main/java/dev/n3u/api/widgets/WidgetAPI.java:80-82), ClickManager, and WalkerPath step logic.
dev.n3u.packets — buffer and parsing utilities
PacketBuffer (base-api/src/main/java/dev/n3u/packets/PacketBuffer.java)
Read/write families for every Jagex encoding; method pairs include:
- Bytes/booleans:
readByte+Add/Neg/Subvariants,writeByte+ variants,readBoolean+ variants,readBytes(3),writeBytes(3),writeBuffer(1) - Shorts/ints/longs: little-endian (
*LE), byte-order-inverted (*ME,*IME), length-prefixed (readLengthByte/Short/Int),readMedium(+Hlm/Mhl),readLong,readUnsignedInt(LE/ME/IME),readLargeSmart,readFloat - Varints:
readVarInt,readZigzagVarInt,writeVarInt,writeZigzagVarInt - Strings:
readCESU8/writeCESU8,readStringCp1252NullTerminated(OrNull),readStringCp1252NullCircumfixed, matching writers - Crypto:
encryptRsa(2),decryptRsa(3),xteaDecrypt(3) - Lifecycle:
toPacketBufferNode(1),dispose()— calldisposewhen done (the buffer participates in pooling viaByteBufferPool)
Supporting types
| Class | Role |
|---|---|
ByteBufferPool | allocate(0/1) hands out Netty ByteBufs, release(1) returns them — reuse instead of allocating |
PacketMapReader | Server-packet analysis: get() lists entries, get(1) one MapEntry, getId(1), prettify(1), analyze(1) → PacketDefinition, createBuffer(2), fillMaps() |
types/PacketDefinition, types/PacketEntry, types/MapEntry | Descriptions of server packet layouts; MapEntry.appliesTo(1) filters revisions/contexts |
Click records (dev.n3u.services.ClickPacket)
ClickPacket records interaction type, x/y and a timestamp (ClickPacket.java:18-24); ClickType colors each family (MOVEMENT, ACTOR, OBJECT, ITEM, GROUND_ITEM, WIDGET, GENERIC) for the visualization overlay, which drains the queue via ClickManager.releaseClicks() (api/src/main/java/dev/n3u/services/mouse/ClickVisualizationOverlay.java:49).
Events
dev.n3u.events.PacketReceived / PacketSent are posted for pipeline observation (see SDK Client Reference).
Worked example — inspecting a custom buffer round-trip
import dev.n3u.Static;
import dev.n3u.api.NClient;
import dev.n3u.api.NPacketBuffer;
import dev.n3u.api.NPacketBufferNode;
import dev.n3u.api.NPacketWriter;
public void sendCustomPacket(int id)
{
NClient client = Static.getClient();
Static.invoke(() -> { // packet work belongs on the client thread
NPacketWriter writer = client.getPacketWriter();
NPacketBufferNode node = client.getPacketBufferNode(
client.newClientPacket(id, 4), writer.getIsaacCipher());
NPacketBuffer buf = node.getPacketBuffer();
buf.writeInt(0x10203040); // Jagex-encoded write
writer.addNode(node); // queue for send
});
}Expected result: one packet with the given id and a 4-byte payload is queued. Failure handling: a mismatch between declared length and bytes written is not validated by the interface surface shown here — treat the declared length as a hard contract (inference from newClientPacket(id, length); no validation method exists on NPacketBufferNode). The client performs no packet-id validation on this surface — newClientPacket(int, int) at base-api/src/main/java/dev/n3u/api/NClient.java:19 is a bare interface declaration; server-side handling is outside this repository and not documented here, so there is no client-side ack to observe beyond downstream server state.
Thread affinity
All packet construction shown here happens on the client thread; the interaction facades enforce this themselves by wrapping sends in Static.invoke. PacketMapReader and PacketBuffer parsing of captured data are pure byte manipulation and thread-agnostic.
Tests
No automated tests cover the packets package (git ls-files "base-api/src/test/java" is empty; api/src/test/java holds widget/pathfinder/UI tests only — run 2026-11-06). The repository tracks a follow-up for round-trip tests per encoding family (Add/Neg/Sub, ME/IME, varint, CP1252 strings) plus pool release discipline.
Known limits
- Wire formats live in injected gamepack code; this page documents the call surface, not byte layouts. Packet ids and field order can change with game updates — never hardcode an id without re-verifying against the current client.
PacketMapReader's map data is derived from the loaded packet definitions;analyzeoutput is only as current as those definitions.- RSA/XTEA helpers require key material the login pipeline owns; outside the login flow they are rarely used directly (open question: key sourcing lives in injected code).
SDK Game Reference
The game, entities, and threaded packages — world-state facades, actor/tile interaction, sailing, and tick-blocking helpers for worker-thread automation.
SDK Pathfinder Reference
The pathfinder module — blocking Walker, WalkerPath teleport-and-steps plans, five algorithms, collision/transport/teleport data, strategic pathing, and boat pathing.