Lua:compareMemory

From Cheat Engine
Jump to navigation Jump to search

<> Reference

function compareMemory(address1, address2, size, method) : boolean, integer

Compares two memory regions.

Returns true if the memory regions are the same. If they differ, this function returns false and a secondary return value containing the index where the first difference was found.

The method parameter controls whether the given addresses are interpreted as target process memory or Cheat Engine memory.

Function Parameters[edit]

Parameter Type Description
address1 Integer or CEAddressString The first address to compare.
address2 Integer or CEAddressString The second address to compare.
size Integer The number of bytes to compare.
method Integer The comparison method to use.

Method Values[edit]

Value Method Description
0 Target to target Compares address1 and address2 as target process addresses.
1 Target to Cheat Engine memory Compares address1 as a target process address and address2 as a Cheat Engine memory address.
2 Cheat Engine memory to Cheat Engine memory Compares address1 and address2 as Cheat Engine memory addresses.

Returns[edit]

boolean, integer — Returns true if the memory regions are the same. If they differ, returns false and the index where the first difference was found.

Examples[edit]

 1 local address1 = getAddress("game.exe")
 2 local address2 = address1 + 0x1000
 3 
 4 local same, index = compareMemory(address1, address2, 256, 0)
 5 
 6 if same then
 7   print("Memory regions are identical")
 8 else
 9   print("Memory regions differ at index: " .. tostring(index))
10 end
 1 local targetAddress = getAddress("game.exe")
 2 local ceCopy = copyMemory(targetAddress, 256, nil, 1)
 3 
 4 if ceCopy ~= nil then
 5   local same, index = compareMemory(targetAddress, ceCopy, 256, 1)
 6 
 7   if same then
 8     print("Target memory matches the CE memory copy")
 9   else
10     print("Memory differs at index: " .. tostring(index))
11   end
12 end

See Also[edit]

Main Pages

Memory Related Functions