Skip to content
Stjepan Bakrac edited this page May 22, 2020 · 7 revisions

Warning

Writing to memory can be dangerous. It can corrupt internal game state and crash your game, or worse. This goes for any kind of memory editing, whether through this library or via FFI or other means. Proceed with caution.

This library handles memory interactions (both reading and writing). Despite being a low level feature it is a high-level library which works off of custom defined types. If you want a low level library to access memory you can use LuaJIT's native ffi library.

local memory = require('memory')

Dependency Required

To use this library, you must include memory in the manifest.xml file for your package:

<dependency>memory</dependency>

Tables

The memory table has an entry for each value defined in the types.lua file, and this can be adjusted dynamically. If you need a memory structure that is not defined in the files you can define it by simple assignment:

local struct = require('struct')

memory.some_new_structure = struct.struct({signature = 'signature here'}, {
    some_int_field    = {0x000, struct.uint32},      -- could be a type indicator
    some_float_field  = {0x01C, struct.float},       -- could be the value
    some_bool_field   = {0x088, struct.boolean},     -- could be a flag indicating whether the mechanism is active
    some_string_field = {0x0A0, struct.string(0x20), -- could be a comment about the last status
})

The resulting structure can be used as you would any Lua table:

if memory.some_new_structure.some_bool_field then
    print(('Type: %u, value: %f'):format(
        memory.some_new_structure.some_int_field,
        memory.some_new_structure.some_float_field
    ))
    memory.some_new_structure.some_string_field = 'has been checked'
end
Clone this wiki locally