[Memhack] Storage - Redacted-Rice/ITB-RedactedRiceExts GitHub Wiki

Memhack Storage

The Memhack Storage struct represents the game's Pilot and skill storage system. This is a wrapper around a memhack vector that of type StorageObject accounts for 3 unusable entries at the beginning.

It has the standard memhack base struct functions/fields.

Table of Contents

Data

Field Type Offset Description
vector Vector | [memhack] Vector 0x0 The underlying Memhack vector (hidden, use public functions instead)

Data Functions

These are functions that draw from the data in the struct or set the data in the struct

Constants

Other Functions

There are a number of private and internal functions. These should generally be avoided outside of memhack

getSize

  • int Storage:getSize()

Returns the number of usable items in storage (excludes the 3 unusable entries).

Example:

local storage = Game:GetMemhackObj():getResearchControl():getStorage()
LOG("Storage has " .. storage:getSize() .. " items")

getAt

  • StorageObject Storage:getAt(index)
Argument name Type Description
index int 1-based index (automatically adjusted for unusable entries)

Returns the storage object at the specified index. Index is 1-based and automatically accounts for the 3 unusable entries.

Example:

local storage = Game:GetMemhackObj():getResearchControl():getStorage()
local item = storage:getAt(1)  -- First usable item
if item:isPilot() then
    LOG("First item is a pilot: " .. item:getPilot():getName())
end

getRange

  • table Storage:getRange(startIdx, endIdx)
Argument name Type Description
startIdx int Starting index (1-based, inclusive)
endIdx int Ending index (1-based, inclusive)

Returns an array of StorageObject for the specified range. Indices are 1-based and automatically account for the 3 unusable entries.

Example:

local items = storage:getRange(1, 5)
for i, item in ipairs(items) do
    LOG("Item " .. i .. ": " .. item:getType())
end

getAll

  • table Storage:getAll()

Returns an array of all StorageObject items in storage.

Example:

local allItems = storage:getAll()
LOG("Found " .. #allItems .. " items in storage")
for _, item in ipairs(allItems) do
    if item:isPilot() then
        LOG("Pilot: " .. item:getPilot():getName())
    end
end

getAllOfType

  • table Storage:getAllOfType(objType)
Argument name Type Description
objType string Type filter passed to StorageObject:isType (e.g. "Pilot", "Skill")

For each matching StorageObject, inserts storageObj:getPilot() into the result array.

Important: getPilot() is only meaningful for pilot entries. Filtering "Skill" still calls getPilot(), so results are typically nil entries. Prefer getAll() / getRange() and check item:isPilot() / item:getType() when you need skills or mixed storage contents.

Example:

local pilots = storage:getAllOfType("Pilot")
LOG("Found " .. #pilots .. " pilots in storage")
for _, pilot in ipairs(pilots) do
    if pilot then
        LOG("Pilot: " .. pilot:getNameStr())
    end
end

UNUSABLE_ENTRIES

  • int = 3

Constant representing the number of unusable entries at the start of the vector. All index calculations automatically account for this offset.

Private and Internal Functions

These functions are for internal use or advanced manipulation. Most users should use the public functions above instead. These are expected to primarily be used when making changes in memhack itself.

_getVector

  • Vector Storage:_getVector()

Returns the underlying Vector struct. For internal use only. Use the public getAt/getRange/getAll functions instead which handle the unusable entries automatically.

This getter is hidden (hideGetter: true) because direct vector access bypasses the UNUSABLE_ENTRIES offset logic.