Repository navigation
[Memhack] Vector
The Memhack Vector struct represents a standard C++ vector in game memory.
It has the standard memhack base struct functions/fields.
Note: Element writes are supported via setIntAt / setIntList for int vectors. The vector size/capacity is read-only - growing or reallocating the vector is not supported. Writes that would require a different length fail.
| Field | Type | Offset | Description |
|---|---|---|---|
| head | pointer (untyped) | 0x0 | Pointer to the start of the vector data |
| next | pointer (untyped) | 0x4 | Pointer to the next available slot |
| capacity | pointer (untyped) | 0x8 | Pointer to the end of allocated capacity |
These are functions that draw from the data in the struct or set the data in the struct
- getHeadPtr
- getNextPtr
- getCapacityPtr
- getSize
- getPtrAt
- getPtrsRange
- getPtrsAll
- getIntSize
- getIntAt
- setIntAt
- getIntList
- setIntList
-
numberVector:getHeadPtr()
Returns the pointer to the start of the vector's data.
Example:
local vec = storage:_getVector()
local headPtr = vec:getHeadPtr()
LOG(string.format("Vector head: 0x%X", headPtr))-
numberVector:getNextPtr()
Returns the pointer to the next available slot in the vector.
Example:
local nextPtr = vec:getNextPtr()
LOG(string.format("Next slot: 0x%X", nextPtr))-
numberVector:getCapacityPtr()
Returns the pointer to the end of the vector's allocated capacity.
Example:
local capPtr = vec:getCapacityPtr()
LOG(string.format("Capacity end: 0x%X", capPtr))-
numberVector:getSize()
Returns the number of elements currently in the vector. Calculated as (next - head) / PTR_SIZE.
Example:
local size = vec:getSize()
LOG("Vector contains " .. size .. " elements")-
numberVector:getPtrAt(index)
| Argument name | Type | Description |
|---|---|---|
index |
number | 1-based index into the vector |
Returns the pointer at the specified index. Index is 1-based (Lua convention).
Example:
local ptr = vec:getPtrAt(1) -- Get first element pointer
LOG(string.format("Element 1 pointer: 0x%X", ptr))-
tableVector:getPtrsRange(startIdx, endIdx)
| Argument name | Type | Description |
|---|---|---|
startIdx |
number | Starting index (1-based, inclusive) |
endIdx |
number | Ending index (1-based, inclusive) |
Returns an array of pointers for the specified range. Both indices are 1-based and inclusive.
Example:
local ptrs = vec:getPtrsRange(1, 5) -- Get first 5 element pointers
for i, ptr in ipairs(ptrs) do
LOG(string.format("Element %d: 0x%X", i, ptr))
end-
tableVector:getPtrsAll()
Returns an array of all pointers in the vector.
Example:
local allPtrs = vec:getPtrsAll()
LOG("Vector has " .. #allPtrs .. " elements")Constant representing the size of a pointer in bytes (4 bytes for 32-bit).
-
numberVector:getIntSize()
Returns the number of int elements. Uses the same 4-byte stride as PTR_SIZE / INT_SIZE on this build ((next - head) / INT_SIZE). Used for int-backed vectors such as Pilot innate power lists.
-
numberVector:getIntAt(index)
| Argument name | Type | Description |
|---|---|---|
index |
number | 1-based index |
Reads the int at the given index.
-
booleanVector:setIntAt(index, value)
| Argument name | Type | Description |
|---|---|---|
index |
number | 1-based index |
value |
number | Int to write |
Writes an int at the index. Returns false if the index is out of range (< 1 or > getIntSize()). Does not grow the vector.
-
tableVector:getIntList()
Returns a 1-indexed Lua table of all int elements.
Example:
local power = pilot:getPower():getIntList()
-- Same result as pilot:getPowerList()-
booleanVector:setIntList(values)
| Argument name | Type | Description |
|---|---|---|
values |
table | 1-indexed list of ints |
Writes all ints. Requires #values to equal getIntSize(). Returns false if values is not a table or the size does not match. Does not grow or shrink the vector.
Example:
local vec = pilot:getPower()
local list = vec:getIntList()
list[1] = memhack.CORE_TYPE_SKILL_BONUS
vec:setIntList(list)-
number= 4
Constant representing the size of a pointer in bytes (4 bytes for 32-bit).
-
number= 4
Constant representing the size of an int element in bytes (same stride as PTR_SIZE on this build).