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

FunctionDescription
raknet.add_send_hookRegister a callback that runs before a packet is sent
raknet.remove_send_hookRemove a callback registered with raknet.add_send_hook
raknet.sendSend a packet with a payload, priority, reliability, and ordering channel
raknet.is_enabledReturn whether the RakNet setting is enabled

Packet API

Methods

MethodDescription
RakNetPacket:SetDataReplace the packet payload
RakNetPacket:BlockPrevent the packet from being sent

Properties

PropertyTypeDescription
RakNetPacket.AsBufferbufferPacket data as a buffer
RakNetPacket.AsStringstringPacket data as a string
RakNetPacket.AsArray{number}Packet data as an array of bytes
RakNetPacket.PacketIdnumberPacket identifier
RakNetPacket.PrioritynumberPacket priority
RakNetPacket.ReliabilitynumberPacket reliability
RakNetPacket.OrderingChannelnumberPacket ordering channel
RakNetPacket.SizenumberPacket payload size in bytes

Hook Syntax

raknet.add_send_hook(hook: (packet: RakNetPacket) -> ()) -> ()
raknet.remove_send_hook(hook: (packet: RakNetPacket) -> ()) -> ()
raknet.is_enabled() -> boolean

Send 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

ParameterTypeDescription
hook(packet: RakNetPacket) -> ()Callback fired before a packet is sent

raknet.remove_send_hook

ParameterTypeDescription
hook(packet: RakNetPacket) -> ()Previously registered send hook

raknet.send

ParameterTypeDescription
databuffer, string, or {number} (byte array)Packet payload to send
prioritynumber?RakNet send priority from 0 through 3; defaults to 2
reliabilitynumber?RakNet reliability mode from 0 through 7; defaults to 3
ordering_channelnumber?Ordering channel from 0 through 31

RakNetPacket:SetData

ParameterTypeDescription
databuffer, 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 RakNetPacket only inside its hook callback
  • RakNetPacket:Block() prevents the current packet from being transmitted
  • RakNetPacket: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