Posted: Sun Jul 26, 2026 2:24 pm Post subject: How to automatically iterate through an array?
Hey everyone,
I have a pointer to an array of pointers to int32's that I added manually to the address list and I would like to iterate through it by incrementing one of the offsets by 8 bytes at a time. Is there a way to do this in Cheat Engine and have it export the value pointed to by the pointer to a CSV table (or any other format)?
This example code assumes the memory record has 4 offsets, the third offset from the base address (2nd from the top) is the one that changes, the memory record points to the first element in the array, and the array's length is 10.
Code:
local mr = AddressList.getMemoryRecordByDescription'My array'
assert(mr and mr.OffsetCount == 4)
local baseAddressStr, offsets = mr.getAddress()
local node = readPointer(baseAddressStr)
assert(node and node ~= 0)
-- last offsets in table are closest to the base address
for i in 4, 3, -1 do
node = readPointer(node + offsets[i])
assert(node and node ~= 0)
end
local values = {}
-- array length is 10 (bounds are inclusive)
for i in 0, 9 do
local offset = offsets[2] + i * 8
local addr = readPointer(node + offset)
assert(addr and addr ~= 0)
-- don't dereference last offset- it's the address of the integer we want
addr = addr + offsets[1]
-- `readInteger` can take a second parameter. If true, interpret value as signed
local val = readInteger(addr, true)
-- could do string formatting here, e.g. if you wanted it in hex
values[#values+1] = val
end
local csv_str = table.concat(values, ',')
writeToClipboard(csv_str)
_________________
I don't know where I'm going, but I'll figure it out when I get there.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum