Find and iterate through list of objects.

A forum dedicated to use and support LUA for Cheat Engine.


Post Reply
tigertoe
Table Maker
Table Maker
Cheater
Cheater
Posts: 19
Joined: Sun Aug 07, 2022 7:51 am
Answers: 0
x 30

Find and iterate through list of objects.

Post by tigertoe »

Here is an example I posted in the old forums that some may find useful. This example is for FarCry and will set the HP of every enemy mob in the zone to zero. First, we need to find a unique value found in each entity object ("mob"). The unique value in this example is a pointer to a vtable but it could be anything. Once we know a unique value, we scan for this value and create an array of the addresses containing this value. Then, we iterate through this array and use offsets relative to our found address to create variables that are more convenient for us to use. We then modify these variables or do whatever operations we want on our instance of this entity object. In some cases, you may need to "skip" certain instances that we do not want to modify (e.g. PCs, friendly mobs, etc).

--Scan for vtable pointer address
local scan = createMemScan(true);
scan.setOnlyOneResult(false);
scan.firstScan(soExactValue,vtDword,nil,"856668400",nil,0,0xffffffffffffffff,"+W-C",fsmNotAligned,nil,false,false,false,false);
scan.waitTillDone();

--Fetch result list
local FoundList=createFoundList(scan);
FoundList.initialize();

--Iterate through list of found addresses
for i=0,FoundList.Count-1 do
  local baseAddress = FoundList.Address[i]
  local healthAddress = tonumber(baseAddress,16)+160
  local typeValue = readInteger(tonumber(baseAddress,16)+224)

  --Do not kill Player or Val
  if typeValue == 255 then
     goto continue
  end

  --Set Trash mob HP to zero
  writeInteger(healthAddress,0)
  ::continue::
end

Post Reply