Volt

RakNet

The RakNet library provides low-level access to outgoing game packets.

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

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.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) -> ()) -> ()

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
data`bufferstring
prioritynumberRakNet send priority
reliabilitynumberRakNet reliability mode
ordering_channelnumberOrdering channel used for ordered traffic

RakNetPacket:SetData

ParameterTypeDescription
data`bufferstring

Returns

All raknet functions and RakNetPacket methods documented here 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 custom packet payload using the provided priority, reliability, and ordering channel. Payload data may be supplied as a buffer, a string, or an array of byte values.

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)

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: Replacing Packet Data

local function rewritePacket(packet)
    local bytes = packet.AsArray

    if #bytes > 0 then
        bytes[1] = 0x01
        packet:SetData(bytes)
    end
end

raknet.add_send_hook(rewritePacket)

Example: Sending a Packet

local payload = { 0x01, 0x02, 0x03, 0x04 }

raknet.send(payload, 0, 0, 0)

Notes

  • Hooks run before the packet is sent
  • RakNetPacket:Block() prevents the current packet from being transmitted
  • RakNetPacket:SetData() replaces the packet payload in-place
  • 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

On this page