RakNet
The RakNet library provides low-level access to outgoing game packets.
The library is disabled by default. Enable RakNet Library under Settings → Client before using any of these functions.
Interacting with RakNet is unsafe and can lead to account terminations, broken game behavior, disconnects, or other unintended side effects. Do not use this library unless you understand the risks and know exactly what you are doing.
Overview
RakNet allows you to:
- Inspect outgoing packets before they are sent
- Modify or block packets in a send hook
- Send custom packet payloads manually
- Work with packet data as a buffer, string, or byte array
Functions
| Function | Description |
|---|---|
raknet.add_send_hook | Register a callback that runs before a packet is sent |
raknet.remove_send_hook | Remove a callback registered with raknet.add_send_hook |
raknet.send | Send a packet with a payload, priority, reliability, and ordering channel |
raknet.is_enabled | Return whether the RakNet setting is enabled |
Packet API
Methods
| Method | Description |
|---|---|
RakNetPacket:SetData | Replace the packet payload |
RakNetPacket:Block | Prevent the packet from being sent |
Properties
| Property | Type | Description |
|---|---|---|
RakNetPacket.AsBuffer | buffer | Packet data as a buffer |
RakNetPacket.AsString | string | Packet data as a string |
RakNetPacket.AsArray | {number} | Packet data as an array of bytes |
RakNetPacket.PacketId | number | Packet identifier |
RakNetPacket.Priority | number | Packet priority |
RakNetPacket.Reliability | number | Packet reliability |
RakNetPacket.OrderingChannel | number | Packet ordering channel |
RakNetPacket.Size | number | Packet payload size in bytes |
Hook Syntax
raknet.add_send_hook(hook: (packet: RakNetPacket) -> ()) -> ()
raknet.remove_send_hook(hook: (packet: RakNetPacket) -> ()) -> ()
raknet.is_enabled() -> booleanSend Syntax
raknet.send(
data: buffer | string | {number},
priority?: number,
reliability?: number,
ordering_channel?: number
) -> ()Packet Method Syntax
RakNetPacket:SetData(data: buffer | string | {number}) -> ()
RakNetPacket:Block() -> ()Parameters
raknet.add_send_hook
| Parameter | Type | Description |
|---|---|---|
hook | (packet: RakNetPacket) -> () | Callback fired before a packet is sent |
raknet.remove_send_hook
| Parameter | Type | Description |
|---|---|---|
hook | (packet: RakNetPacket) -> () | Previously registered send hook |
raknet.send
| Parameter | Type | Description |
|---|---|---|
data | buffer, string, or {number} (byte array) | Packet payload to send |
priority | number? | RakNet send priority from 0 through 3; defaults to 2 |
reliability | number? | RakNet reliability mode from 0 through 7; defaults to 3 |
ordering_channel | number? | Ordering channel from 0 through 31 |
RakNetPacket:SetData
| Parameter | Type | Description |
|---|---|---|
data | buffer, string, or {number} (byte array) | New packet payload |
Returns
raknet.is_enabled() returns the current RakNet-library setting and can be called while the library is disabled. The other functions and packet methods do not return a value.
Description
raknet.add_send_hook lets you intercept outgoing packets before they are sent. Inside a hook, you can inspect packet metadata, read its payload in multiple formats, replace the payload with RakNetPacket:SetData, or stop transmission entirely with RakNetPacket:Block.
raknet.send sends a non-empty custom packet payload using the provided priority, reliability, and ordering channel. Payload data may be supplied as a buffer, a string, or a table of byte values. Some packet identifiers are not accepted.
Because this library operates at the packet level, mistakes can be difficult to debug and may have immediate consequences. Keep hooks minimal, validate payloads carefully, and avoid modifying traffic unless absolutely necessary.
Example: Logging Outgoing Packets
local function packetLogger(packet)
print("Outgoing packet:")
print(" Size:", packet.Size)
print(" Priority:", packet.Priority)
print(" Reliability:", packet.Reliability)
print(" Ordering channel:", packet.OrderingChannel)
end
raknet.add_send_hook(packetLogger)
-- Remove the exact same callback when finished
raknet.remove_send_hook(packetLogger)Example: Blocking a Packet
local function blockLargePackets(packet)
if packet.Size > 512 then
warn("Blocked packet larger than 512 bytes")
packet:Block()
end
end
raknet.add_send_hook(blockLargePackets)Example: Reading and Reapplying Packet Data
local function rewritePacket(packet)
-- This round trip leaves the bytes unchanged. Only modify a payload when
-- you know the exact schema for that packet identifier.
local bytes = packet.AsBuffer
packet:SetData(bytes)
end
raknet.add_send_hook(rewritePacket)Payloads passed to raknet.send must match the packet format expected by the game.
Notes
- Hooks run before the packet is sent
- Use a
RakNetPacketonly inside its hook callback RakNetPacket:Block()prevents the current packet from being transmittedRakNetPacket:SetData()replaces the packet payload- Packet data can be read and written as a
buffer,string, or byte array - Invalid payloads or incorrect metadata can disconnect clients or break protocol behavior