Lua:copyMemory

From Cheat Engine
Revision as of 16:33, 25 June 2026 by Leunsel (talk | contribs) (Syntax Highlighting.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<> Lua API Reference

function copyMemory(sourceAddress, size, destinationAddress, Method) : integer or nil

Copies memory from the given source address to the destination address.

If destinationAddress is omitted or nil, Cheat Engine will allocate a random destination address for the copy.

The Method parameter controls whether the source and destination addresses are interpreted as target process memory or Cheat Engine memory.

Function Parameters

Parameter Type Description
sourceAddress Integer or CEAddressString The source address to copy memory from.
size Integer The number of bytes to copy.
destinationAddress Integer or CEAddressString (semi-optional) The destination address to copy memory to. If omitted or nil, Cheat Engine will allocate a random destination address.
Method Integer (optional) The copy method to use. If omitted or nil, method 0 is used.

Method Values

Value Method Description
nil or 0 Target process to target process Copies memory from the target process to the target process.
1 Target process to Cheat Engine memory Copies memory from the target process to Cheat Engine memory.
2 Cheat Engine memory to target process Copies memory from Cheat Engine memory to the target process.
3 Cheat Engine memory to Cheat Engine memory Copies memory from Cheat Engine memory to Cheat Engine memory.

Returns

integer or nil — The address of the copied memory on success, or nil on failure.

Examples

1 local source = getAddress("game.exe")
2 local copiedAddress = copyMemory(source, 1024)
3 
4 if copiedAddress ~= nil then
5   print("Copied memory to: " .. string.format("%X", copiedAddress))
6 else
7   print("Failed to copy memory")
8 end
1 local source = getAddress("game.exe")
2 local destination = allocateMemory(1024)
3 
4 local copiedAddress = copyMemory(source, 1024, destination)
5 
6 if copiedAddress ~= nil then
7   print("Copied memory to: " .. string.format("%X", copiedAddress))
8 end
1 local source = getAddress("game.exe")
2 
3 -- Copy memory from the target process to Cheat Engine memory
4 local copiedAddress = copyMemory(source, 1024, nil, 1)
5 
6 if copiedAddress ~= nil then
7   print("Copied memory to CE memory: " .. string.format("%X", copiedAddress))
8 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Sections / Views

Memory Mapping

Memory Copy / Compare

Memory Streams