Skip to content

Memory Module

STBrian edited this page Nov 9, 2026 · 1 revision

The Memory submodule provides direct access to process memory: reading and writing primitives, floats, and strings, allocating dynamic memory in either the plugin heap or the game heap, and calling native functions via foreign function interface (FFI).

Functions

Core.Memory.readU32 Reads an unsigned 32-bit integer
Core.Memory.readS32 Reads a signed 32-bit integer
Core.Memory.readU16 Reads an unsigned 16-bit integer
Core.Memory.readS16 Reads a signed 16-bit integer
Core.Memory.readU8 Reads an unsigned 8-bit integer
Core.Memory.readS8 Reads a signed 8-bit integer
Core.Memory.readFloat Reads a 32-bit single-precision float
Core.Memory.readDouble Reads a 64-bit double-precision float
Core.Memory.readString Reads a string of given length from memory
Core.Memory.writeU32 Writes an unsigned 32-bit integer
Core.Memory.writeS32 Writes a signed 32-bit integer
Core.Memory.writeU16 Writes an unsigned 16-bit integer
Core.Memory.writeS16 Writes a signed 16-bit integer
Core.Memory.writeU8 Writes an unsigned 8-bit integer
Core.Memory.writeS8 Writes a signed 8-bit integer
Core.Memory.writeFloat Writes a 32-bit single-precision float
Core.Memory.writeDouble Writes a 64-bit double-precision float
Core.Memory.writeString Writes a string of given size to memory
Core.Memory.malloc Allocates a memory block and returns its address
Core.Memory.free Frees memory allocated with malloc
Core.Memory.call Invokes a native C function at a memory address

Core.Memory.readU32

Reads an unsigned 32-bit integer from the specified memory address. Returns nil if memory reading failed.

Core.Memory.readU32(offset: integer) -> integer?

Core.Memory.readS32

Reads a signed 32-bit integer from the specified memory address. Returns nil if reading failed.

Core.Memory.readS32(offset: integer) -> integer?

Core.Memory.readU16

Reads an unsigned 16-bit integer from the specified memory address. Returns nil if reading failed.

Core.Memory.readU16(offset: integer) -> integer?

Core.Memory.readS16

Reads a signed 16-bit integer from the specified memory address. Returns nil if reading failed.

Core.Memory.readS16(offset: integer) -> integer?

Core.Memory.readU8

Reads an unsigned 8-bit integer (byte) from the specified memory address. Returns nil if reading failed.

Core.Memory.readU8(offset: integer) -> integer?

Core.Memory.readS8

Reads a signed 8-bit integer from the specified memory address. Returns nil if reading failed.

Core.Memory.readS8(offset: integer) -> integer?

Core.Memory.readFloat

Reads a 32-bit single precision floating point number from the specified memory address. Returns nil if reading failed.

Core.Memory.readFloat(offset: integer) -> number?

Core.Memory.readDouble

Reads a 64-bit double precision floating point number from the specified memory address. Returns nil if reading failed.

Core.Memory.readDouble(offset: integer) -> number?

Core.Memory.readString

Reads a string of size bytes from the specified memory address. Returns nil if reading failed.

Core.Memory.readString(offset: integer, size: integer) -> string?

Core.Memory.writeU32

Writes an unsigned 32-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeU32(offset: integer, value: integer) -> boolean

Core.Memory.writeS32

Writes a signed 32-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeS32(offset: integer, value: integer) -> boolean

Core.Memory.writeU16

Writes an unsigned 16-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeU16(offset: integer, value: integer) -> boolean

Core.Memory.writeS16

Writes a signed 16-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeS16(offset: integer, value: integer) -> boolean

Core.Memory.writeU8

Writes an unsigned 8-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeU8(offset: integer, value: integer) -> boolean

Core.Memory.writeS8

Writes a signed 8-bit integer to the specified memory address. Returns true on success.

Core.Memory.writeS8(offset: integer, value: integer) -> boolean

Core.Memory.writeFloat

Writes a single-precision float to the specified memory address. Returns true on success.

Core.Memory.writeFloat(offset: integer, value: number) -> boolean

Core.Memory.writeDouble

Writes a double-precision float to the specified memory address. Returns true on success.

Core.Memory.writeDouble(offset: integer, value: number) -> boolean

Core.Memory.writeString

Writes a string of size bytes into the specified memory address. Returns true on success.

Core.Memory.writeString(offset: integer, s: string, size: integer) -> boolean

Core.Memory.malloc

Allocates a block of memory of size bytes and returns the pointer address. If useGameHeap is true, allocates inside the game heap; otherwise allocates inside the plugin framework heap. Returns nil on allocation failure.

Core.Memory.malloc(size: integer, useGameHeap: boolean?) -> integer?

Core.Memory.free

Frees a block of memory previously allocated with Core.Memory.malloc. Set useGameHeap to true if the memory was allocated on the game heap.

Core.Memory.free(offset: integer, useGameHeap: boolean?)

Core.Memory.call

Invokes a native function at address foffset with libffi type signatures.

Core.Memory.call(foffset: integer, argstype: string, returntype: string, ...: any) -> number
  • foffset: Address of the native function.
  • argstype: String where each character represents an argument type:
    • c, b: signed 8-bit int
    • B: unsigned 8-bit int
    • ?: boolean
    • h: signed 16-bit int
    • H: unsigned 16-bit int
    • i, l: signed 32-bit int
    • I, L: unsigned 32-bit int
    • P: pointer address
    • f: 32-bit float
  • returntype: Single character representing the return type (same characters as above, or empty string "" for void).
  • ...: Arguments to pass to the function.

Example

-- Call a function with signature: float calculate(int a, float b)
local res = Core.Memory.call(0x00412340, "if", "f", 10, 3.14)

Clone this wiki locally