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 Name | Type | Description |
---|
name | string | [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 Name | Type | Description |
---|
name | string | [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 Name | Type | Description |
---|
addr | number | The address to change the protection of. |
size | number | The size of the region to change. |
protection | number | The 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 Name | Type | Description |
---|
addr | number | The address to change the protection of. |
size | number | The 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 Name | Type | Description |
---|
size | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
name | string | [Optional] The name of the module to scan within. |
pattern | string | The pattern to scan for. |
offset | number | The offset from the found address to be added to the return. |
count | number | The 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 Name | Type | Description |
---|
base | number | The address to start scanning at. |
size | number | The size to scan within. |
pattern | string | The pattern to scan for. |
offset | number | The offset from the found address to be added to the return. |
count | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The 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 Name | Type | Description |
---|
addr | number | The address to read the value from. |
size | number | The 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 Name | Type | Description |
---|
addr | number | The address to read the value from. |
size | number | The 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 Name | Type | Description |
---|
addr | number | The address to read the value from. |
size | number | The 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 Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_int16
Writes a value to memory. (int16)
1hook.memory.write_int16(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_int32
Writes a value to memory. (int32)
1hook.memory.write_int32(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_int64
Writes a value to memory. (int64)
1hook.memory.write_int64(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_uint8
Writes a value to memory. (uint8)
1hook.memory.write_uint8(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_uint16
Writes a value to memory. (uint16)
1hook.memory.write_uint16(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_uint32
Writes a value to memory. (uint32)
1hook.memory.write_uint32(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_uint64
Writes a value to memory. (uint64)
1hook.memory.write_uint64(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_float
Writes a value to memory. (float)
1hook.memory.write_float(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_double
Writes a value to memory. (double)
1hook.memory.write_double(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | number | The value to write. |
write_array
Writes an array of values to memory.
1hook.memory.write_array(addr, value);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
value | table | The array of values to write. |
write_string
Writes a string to memory.
1hook.memory.write_string(addr, str, size);
Parameter Name | Type | Description |
---|
addr | number | The address to write the value to. |
str | string | The string value to write. |
size | number | [Optional] The length of the string to write. |
If size
is not given, then the length of the string is automatically determined.