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 


Iterating through a list ?

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

Joined: 02 May 2017
Posts: 6

PostPosted: Mon Jun 12, 2017 3:43 am    Post subject: Iterating through a list ? Reply with quote

(unity game) Found a "list" of inventory items. Complex pointer where the 4th offset is the inventory slot, and the 5th points to the item ID I'm looking for.

I'm looking for a handful of item IDs (perhaps 5 items in the list out of >50). The items are in a random order every time a game is loaded, and for a bunch of reasons I won't bother going into, the best solution I think will work consistently is to iterate through the list, finding the IDs I want, and then assigning the proper 4th offset to corresponding CE table entries.

(for example, iterate through a list, if I find the shield item then the shield structure in the table get populated by adjusting the offsets to point at the found item)



I know how to do this sort of thing in C/C++, but in Lua and the other CE stuff I'm quite lost.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jun 12, 2017 9:20 am    Post subject: Reply with quote

Hm so you have something like

inventory = [[[base+off1]+off2]+off3]+off4
itemid = [[[[base+off1]+off2]+off3]+off4]+off5

where base is the start of the array (the first element) and you need to check, potentially, 50+ to find 5 itemids you care about?

I haven't tested it but something like this might work (lua)

Code:

al = getAddressList()

local iCare = cared = {[1]=true ,[2]=true, [3]=true, [5]=true, [8]=true} -- ids you care about
local numCaredAbout = 5 -- #iCare would only give 3, since 4 is nil

local numElements = 50 -- lua does not use hex by default so this is decimal 50
local elementSize = 4
local maxOffset = numElements*elementSize

local found = 0

for off1 = 0, maxOffset  do
  -- string address is parsed by CE, so numbers are hex by default...
  local addr = "[[[[base+" .. string.format("%x", off1) .. "]+off2]+off3]+off4]+off5"
  local itemid = readInteger(addr) -- assuming the id is a 4 byte int
  if iCare[itemid] then
    local mr = al.getMemoryRecordByDescription("Inventory Slot for ItemID " .. itemid)
    -- below will give error if memory record with that name/description did not exist
    -- that's probably a good thing since it'll let you know something is wrong :)
    mr.setAddress(addr)

    -- stop looking if we've found all the ones we care about
    found = found + 1
    if found >= numCaredAbout then break end
  end
end


I wouldn't be surprised if someone else had a better method (or if I was off by 1) since I don't know lua all that well lol (and obviously some of the variables are just for readability)
Back to top
View user's profile Send private message
AMAzEonAe
How do I cheat?
Reputation: 0

Joined: 02 May 2017
Posts: 6

PostPosted: Mon Jun 12, 2017 1:22 pm    Post subject: Reply with quote

Ah alright, I see where your going with this
(geez scripting languages have weird syntax....)

Thanks a bunch, I'll give a method like that a try
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