Lua:compareMemory

From Cheat Engine
Revision as of 14:55, 25 June 2026 by Leunsel (talk | contribs)
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

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

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

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

local address1 = getAddress("game.exe")
local address2 = address1 + 0x1000

local same, index = compareMemory(address1, address2, 256, 0)

if same then
  print("Memory regions are identical")
else
  print("Memory regions differ at index: " .. tostring(index))
end
local targetAddress = getAddress("game.exe")
local ceCopy = copyMemory(targetAddress, 256, nil, 1)

if ceCopy ~= nil then
  local same, index = compareMemory(targetAddress, ceCopy, 256, 1)

  if same then
    print("Target memory matches the CE memory copy")
  else
    print("Memory differs at index: " .. tostring(index))
  end
end

See Also

Main Pages

Memory Related Functions