Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to automatically iterate through an array?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
confiture
How do I cheat?
Reputation: 0

Joined: 26 Jul 2026
Posts: 1

PostPosted: Sun Jul 26, 2026 2:24 pm    Post subject: How to automatically iterate through an array? Reply with quote

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)?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 155

Joined: 06 Jul 2014
Posts: 4774

PostPosted: Sun Jul 26, 2026 3:36 pm    Post subject: Reply with quote

How long is the array?

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites