memory

The memory namespace contains functions that allow addons to access the game client memory in multiple ways.

You can also make use of the ffi library to access memory with more features such as casting to actual C style structures.

Functions exposed by this namespace are accessed via the prefix: hook.memory.

Functions

get_base

Returns the base address of a loaded module.

1number hook.memory.get_base(name);
Parameter NameTypeDescription
namestring[Optional] The name of the module.
Returns
(number) The base address of of the module on success, 0 otherwise.

If name is nil or an empty string, then the game.dll module is used by default.


get_size

Returns the size of a loaded module.

1number hook.memory.get_size(name);
Parameter NameTypeDescription
namestring[Optional] The name of the module.
Returns
(number) The size of of the module on success, 0 otherwise.

If name is nil or an empty string, then the game.dll module is used by default.


protect

1boolean, number hook.memory.protect(addr, size, protection);

Sets the memory protection of the given address.

Parameter NameTypeDescription
addrnumberThe address to change the protection of.
sizenumberThe size of the region to change.
protectionnumberThe new protection value to change to.
Returns
(boolean, number) The return value from VirtualProtect and the previous protection value.

unprotect

1boolean, number hook.memory.unprotect(addr, size);

Sets the memory protection of the given address to PAGE_EXECUTE_READWRITE.

Parameter NameTypeDescription
addrnumberThe address to change the protection of.
sizenumberThe size of the region to change.
Returns
(boolean, number) The return value from VirtualProtect and the previous protection value.

alloc

Allocates memory within the process and returns the address to where it was allocated at. (Uses VirtualAlloc to allocate memory.)

1number|nil hook.memory.alloc(size);
Parameter NameTypeDescription
sizenumberThe size of the region to allocate.
Returns
(number | nil) The address of the allocated memory on success, nil otherwise.

dealloc

Deallocates memory that was previously allocated via alloc.

1boolean hook.memory.dealloc(addr);
Parameter NameTypeDescription
addrnumberThe address of the memory to deallocate.
Returns
(boolean) The return value from VirtualFree.

find

Scans for a pattern of bytes within the given module.

1number hook.memory.find(name, pattern, offset, count);
Parameter NameTypeDescription
namestring[Optional] The name of the module to scan within.
patternstringThe pattern to scan for.
offsetnumberThe offset from the found address to be added to the return.
countnumberThe count of the result to use if the pattern is found more than once.
Returns
(number) The address where the pattern was found on success, 0 otherwise.

If name is nil or an empty string, then the game.dll module is used by default.

1number hook.memory.find(base, size, pattern, offset, count);
Parameter NameTypeDescription
basenumberThe address to start scanning at.
sizenumberThe size to scan within.
patternstringThe pattern to scan for.
offsetnumberThe offset from the found address to be added to the return.
countnumberThe count of the result to use if the pattern is found more than once.
Returns
(number) The address where the pattern was found on success, 0 otherwise.

If base and size are both 0, then the game.dll module is used by default.


read_int8

Reads a value from memory. (int8)

1number hook.memory.read_int8(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_int16

Reads a value from memory. (int16)

1number hook.memory.read_int16(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_int32

Reads a value from memory. (int32)

1number hook.memory.read_int32(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_int64

Reads a value from memory. (int64)

1number hook.memory.read_int64(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_uint8

Reads a value from memory. (uint8)

1number hook.memory.read_uint8(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_uint16

Reads a value from memory. (uint16)

1number hook.memory.read_uint16(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_uint32

Reads a value from memory. (uint32)

1number hook.memory.read_uint32(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_uint64

Reads a value from memory. (uint64)

1number hook.memory.read_uint64(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_float

Reads a value from memory. (float)

1number hook.memory.read_float(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_double

Reads a value from memory. (double)

1number hook.memory.read_double(addr);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
Returns
(number) The read value on success, 0 otherwise.

read_array

Reads an array of bytes from memory.

1table|nil hook.memory.read_array(addr, size);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
sizenumberThe size of data to read.
Returns
(table | nil) The read array on success, nil otherwise.

read_string

Reads a string from memory.

1string|nil hook.memory.read_string(addr, size);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
sizenumberThe size of data to read.
Returns
(string | nil) The read string on success, nil otherwise.

read_literal

Reads a string literal from memory.

1string|nil hook.memory.read_literal(addr, size);
Parameter NameTypeDescription
addrnumberThe address to read the value from.
sizenumberThe size of data to read.
Returns
(string | nil) The read string literal on success, nil otherwise.

write_int8

Writes a value to memory. (int8)

1hook.memory.write_int8(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_int16

Writes a value to memory. (int16)

1hook.memory.write_int16(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_int32

Writes a value to memory. (int32)

1hook.memory.write_int32(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_int64

Writes a value to memory. (int64)

1hook.memory.write_int64(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_uint8

Writes a value to memory. (uint8)

1hook.memory.write_uint8(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_uint16

Writes a value to memory. (uint16)

1hook.memory.write_uint16(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_uint32

Writes a value to memory. (uint32)

1hook.memory.write_uint32(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_uint64

Writes a value to memory. (uint64)

1hook.memory.write_uint64(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_float

Writes a value to memory. (float)

1hook.memory.write_float(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_double

Writes a value to memory. (double)

1hook.memory.write_double(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuenumberThe value to write.
Returns
None.

write_array

Writes an array of values to memory.

1hook.memory.write_array(addr, value);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
valuetableThe array of values to write.
Returns
None.

write_string

Writes a string to memory.

1hook.memory.write_string(addr, str, size);
Parameter NameTypeDescription
addrnumberThe address to write the value to.
strstringThe string value to write.
sizenumber[Optional] The length of the string to write.
Returns
None.

If size is not given, then the length of the string is automatically determined.