Violet

Out Packet

On this page

Create and send custom packets to the server.

Important

Sending invalid or malformed packets can cause disconnection. Only use if you understand the packet structure.

Example Disclaimer

Examples use placeholder opcodes for demonstration only. Research actual packet structures for your game version.

Constructor

out_packet(opcode: number) -> OutPacket

Available on GMS and CW

Creates a new packet with the specified opcode.

lua
local packet = out_packet(0x100)

Encoding Methods

All methods return the packet object for method chaining.

packet:encode_1(value: number) -> OutPacket

Available on GMS and CW

Encodes 1 byte (0-255).


packet:encode_2(value: number) -> OutPacket

Available on GMS and CW

Encodes 2 bytes (0-65535).


packet:encode_4(value: number) -> OutPacket

Available on GMS and CW

Encodes 4 bytes (0-4294967295).


packet:encode_8(value: number) -> OutPacket

Available on GMS and CW

Encodes 8 bytes.


packet:encode_string(text: string) -> OutPacket

Available on GMS and CW

Encodes a string.


packet:encode_buffer(data: string | buffer) -> OutPacket

Available on GMS and CW

Encodes raw binary data. Accepts either a Lua string or a native Luau buffer — use the buffer form to forward bytes from in_packet:decode_buffer without a string round-trip.

lua
-- from a string
out_packet(0x100):encode_buffer("\x01\x02\x03"):send()

-- from a buffer (e.g. forwarded from on_packet_recv)
local buf = incoming:decode_buffer(32)
out_packet(0x100):encode_buffer(buf):send()

packet:encode_timestamp() -> OutPacket

Available on GMS and CW

Encodes the client's current update time as 4 bytes — the tick most packets carry as their timestamp field. Equivalent to encode_4(core.get_update_time()), and the same value the packet injector's {timestamp} variable expands to. Errors if the game is not loaded yet.

lua
out_packet(0x100)
    :encode_timestamp()
    :encode_4(item_id)
    :send()

packet:encode_hex(hex: string) -> OutPacket

Available on GMS and CW

Encodes bytes written as hex text, e.g. "05 00 1A FF" (whitespace optional). Errors on a non-hex character or an odd number of digits rather than skipping them, so a typo can't quietly become different bytes.

Handy for replaying a packet body captured from the monitor or from in_packet:to_string(). The opcode comes from out_packet(opcode), so pass the body only — a captured string includes the opcode as its first two bytes.

lua
-- replay a captured packet: "9E 00 01 00 05" -> opcode 0x9E, body "01 00 05"
out_packet(0x9E):encode_hex("01 00 05"):send()

Utility Methods

packet:to_string() -> string

Available on GMS and CW

Returns hexadecimal representation of packet contents.


packet:get_opcode() -> number

Available on GMS and CW

Returns the packet opcode.


packet:get_data() -> string

Available on GMS and CW

Returns hexadecimal representation of packet contents (alias of to_string()).


packet:send()

Available on GMS and CW

Sends the packet to the server.

Examples

Basic Usage

lua
-- Create and send packet
local packet = out_packet(0x100)  -- Use real opcode
packet:encode_1(5)
packet:encode_2(1000)
packet:send()

Method Chaining

lua
out_packet(0x200)
    :encode_1(10)
    :encode_2(500)
    :encode_4(100000)
    :encode_string("Hello")
    :send()