Difference between revisions of "Lua:Class:Addresslist"

From Cheat Engine
Jump to navigation Jump to search
(Verified Lua-exposed properties/methods from source. Added 13 examples, noted unexposed properties (SelCount, colors, events). Fixed descriptions, enhanced indexing notes, improved structure.)
(Major overhaul of the post.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''AddressList''' '''class''': ('''Inheritance''': ''[[Lua:Class:Panel|Panel]]''->''[[Lua:Class:WinControl|WinControl]]''->''[[Lua:Class:Control|Control]]''->''[[Lua:Class:Component|Component]]''->''[[Lua:Class:Object|Object]]'')
+
{{Class|'''class''' Addresslist ''':''' Panel}}
  
The AddressList class represents Cheat Engine's address list (also known as the cheat table), which is the primary container for managing [[Lua:Class:MemoryRecord|MemoryRecord]] entries. This class provides methods to create, retrieve, and manipulate memory records, as well as trigger UI updates for description, address, type, and value changes.
+
The Addresslist class represents Cheat Engine's main cheat table address list.
  
The AddressList is accessible through the [[Lua:getAddressList|getAddressList]] function, which returns the main address list instance from Cheat Engine's main form.
+
It contains [[Lua:Class:MemoryRecord|MemoryRecord]] entries and provides methods for selecting, creating, finding, editing, activating, and disabling records.
  
== Properties ==
+
===Inheritance===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Class
 +
!align="left"|Inherits From
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|Addresslist
 +
|[[Lua:Class:Panel|Panel]]
 +
|The main cheat table address list control.
 +
|-
 +
|[[Lua:Class:Panel|Panel]]
 +
|[[Lua:Class:WinControl|WinControl]]
 +
|Base class for panel controls.
 +
|-
 +
|[[Lua:Class:WinControl|WinControl]]
 +
|[[Lua:Class:Control|Control]]
 +
|Base class for windowed controls.
 +
|-
 +
|[[Lua:Class:Control|Control]]
 +
|[[Lua:Class:Component|Component]]
 +
|Base class for visual controls.
 +
|-
 +
|[[Lua:Class:Component|Component]]
 +
|[[Lua:Class:Object|Object]]
 +
|Base class for components.
 +
|}
  
{|class="wikitable" style="width:100%"
+
===Properties===
! Property
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
! Type
+
!align="left"|Property
! Access
+
!align="left"|Type
! Description
+
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|LoadedTableVersion
 +
|Integer
 +
|Returns the table version of the last loaded table.
 +
|-
 +
|Count
 +
|Integer
 +
|The number of records in the address list.
 +
|-
 +
|SelCount
 +
|Integer
 +
|The number of selected records.
 +
|-
 +
|SelectedRecord
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|The main selected memory record.
 +
|-
 +
|MemoryRecord[]
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|Array-style accessor for individual memory records.
 +
|-
 +
|[]
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|Default accessor for individual memory records.
 +
|-
 +
|CheckboxActiveSelectedColor
 +
|Color
 +
|The checkbox color used for records that are both active and selected.
 +
|-
 +
|CheckboxActiveColor
 +
|Color
 +
|The checkbox color used for active records.
 +
|-
 +
|CheckboxSelectedColor
 +
|Color
 +
|The checkbox color used for selected records.
 
|-
 
|-
| Count
+
|CheckboxColor
| Integer
+
|Color
| Read-only
+
|The normal checkbox color.
| The total number of [[Lua:Class:MemoryRecord|MemoryRecord]] entries in the address list (all levels, including children).
 
 
|-
 
|-
| SelectedRecord
+
|SelectedBackgroundColor
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Color
| Read/Write
+
|The primary background color used for selected records.
| Gets or sets the currently selected memory record. Returns '''nil''' if no record is selected. Setting this property deselects all other records and selects the specified one.
 
 
|-
 
|-
| MemoryRecord[index]
+
|SelectedSecondaryBackgroundColor
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Color
| Read-only
+
|The secondary background color used for selected records.
| Array accessor to retrieve memory records by index (0-based). Can also be accessed using function call syntax: '''AddressList[index]'''. Same as '''getMemoryRecord(index)'''. Alternatively, can be accessed with a string to search by description.
 
 
|-
 
|-
| [index]
+
|ExpandSignColor
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Color
| Read-only
+
|The color of the expand/collapse sign.
| Default array accessor. Equivalent to '''MemoryRecord[index]'''.
+
|-
 +
|IncreaseArrowColor
 +
|Color
 +
|The color of the increase arrow.
 +
|-
 +
|DecreaseArrowColor
 +
|Color
 +
|The color of the decrease arrow.
 
|}
 
|}
  
=== Properties Not Exposed to Lua ===
+
===Events===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Event
 +
!align="left"|Callback
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|OnDescriptionChange
 +
|function(addresslist, memrec): boolean
 +
|Called when the user initiates a description column change on a record. Return true if you handle it, false for normal behavior.
 +
|-
 +
|OnAddressChange
 +
|function(addresslist, memrec): boolean
 +
|Called when the user initiates an address column change on a record. Return true if you handle it, false for normal behavior.
 +
|-
 +
|OnTypeChange
 +
|function(addresslist, memrec): boolean
 +
|Called when the user initiates a type column change on a record. Return true if you handle it, false for normal behavior.
 +
|-
 +
|OnValueChange
 +
|function(addresslist, memrec): boolean
 +
|Called when the user initiates a value column change on a record. Return true if you handle it, false for normal behavior.
 +
|-
 +
|OnAutoAssemblerEdit
 +
|function(addresslist, memrec)
 +
|Called when the user initiates a [[Lua:Class:MemoryRecord|MemoryRecord]] Auto Assembler script edit. The callback is responsible for changing the memory record.
 +
|}
  
The following properties are available in the Pascal TAddressList class but are '''not''' exposed to Lua scripts:
+
===Methods===
* LoadedTableVersion
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
* SelCount
+
!align="left"|Method
* CheckboxActiveSelectedColor, CheckboxActiveColor, CheckboxSelectedColor, CheckboxColor
+
!align="left"|Return Type
* SelectedBackgroundColor, SelectedSecondaryBackgroundColor
+
!style="width: 80%;background-color:white;" align="left"|Description
* ExpandSignColor, IncreaseArrowColor, DecreaseArrowColor
+
|-
* MouseHighlightedRecord
+
|getCount()
* OnDescriptionChange, OnAddressChange, OnTypeChange, OnValueChange, OnAutoAssemblerEdit (event callbacks)
+
|Integer
 
+
|Returns the number of records in the address list.
These properties are used internally by Cheat Engine's UI but cannot be accessed or modified from Lua scripts.
 
 
 
== Methods ==
 
 
 
{|class="wikitable" style="width:100%"
 
! Method
 
! Parameters
 
! Returns
 
! Description
 
 
|-
 
|-
| getCount
+
|getMemoryRecord(index)
| None
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| Integer
+
|Returns the memory record at the given index.
| Returns the total number of memory records in the address list.
 
 
|-
 
|-
| getMemoryRecord
+
|getMemoryRecordByDescription(description)
| Integer (index) OR String (description)
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Returns the first memory record with the given description.
| Returns the memory record at the specified index (0-based). Also accepts a string description to search by description. Returns '''nil''' if index is out of bounds or description not found.
 
 
|-
 
|-
| getMemoryRecordByDescription
+
|getMemoryRecordByID(ID)
| String (description)
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Returns the memory record with the given ID.
| Returns the first memory record with the specified description. Returns '''nil''' if not found. Uses an internal hash table for fast lookups.
 
 
|-
 
|-
| getMemoryRecordByID
+
|createMemoryRecord()
| Integer (id)
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Creates a generic cheat table entry and adds it to the address list.
| Returns the memory record with the specified unique ID. Returns '''nil''' if not found.
 
 
|-
 
|-
| createMemoryRecord
+
|getSelectedRecords()
| None
+
|Table
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Returns a table containing all selected records.
| Creates a new memory record and adds it to the address list. The record is initialized with default values (description: "Plugin Address", address: "0", type: vtDword). Returns the newly created [[Lua:Class:MemoryRecord|MemoryRecord]] object.
 
 
|-
 
|-
| getSelectedRecords
+
|doDescriptionChange()
| None
+
|void
| Table
+
|Shows the GUI window to change the description of the selected entry.
| Returns a table (1-indexed) containing all currently selected [[Lua:Class:MemoryRecord|MemoryRecord]] objects. Returns '''nil''' if no records are selected.
 
 
|-
 
|-
| getSelectedRecord
+
|doAddressChange()
| None
+
|void
| [[Lua:Class:MemoryRecord|MemoryRecord]]
+
|Shows the GUI window to change the address of the selected entry.
| Returns the currently selected memory record. Same as accessing the '''SelectedRecord''' property. Returns '''nil''' if no record is selected.
 
 
|-
 
|-
| setSelectedRecord
+
|doTypeChange()
| [[Lua:Class:MemoryRecord|MemoryRecord]] (memrec)
+
|void
| None
+
|Shows the GUI window to change the type of the selected entries.
| Sets the currently selected memory record, deselecting all others. Same as setting the '''SelectedRecord''' property.
 
 
|-
 
|-
| doDescriptionChange
+
|doValueChange()
| None
+
|void
| None
+
|Shows the GUI window to change the value of the selected entries.
| Shows the GUI window to change the description of the selected entry. Opens a dialog allowing the user to modify the description. Equivalent to double-clicking the description column.
 
 
|-
 
|-
| doAddressChange
+
|getSelectedRecord()
| None
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| None
+
|Gets the main selected memory record.
| Shows the GUI window to change the address of the selected entry. Opens a dialog allowing the user to modify the address and pointer settings. Equivalent to double-clicking the address column.
 
 
|-
 
|-
| doTypeChange
+
|setSelectedRecord(memrec)
| None
+
|void
| None
+
|Sets the currently selected memory record. This unselects all other entries.
| Shows the GUI window to change the type of the selected entries. Opens a dialog allowing the user to change the variable type. Equivalent to double-clicking the type column.
 
 
|-
 
|-
| doValueChange
+
|disableAllWithoutExecute()
| None
+
|void
| None
+
|Disables all memory records without executing their [Disable] sections.
| Shows the GUI window to change the value of the selected entries. Opens a dialog allowing the user to modify the value. Equivalent to double-clicking the value column.
 
 
|-
 
|-
| disableAllWithoutExecute
+
|rebuildDescriptionCache()
| None
+
|void
| None
+
|Rebuilds the description-to-record lookup table.
| Disables all active auto assembler script entries without executing their [DISABLE] sections. Useful for quickly disabling all scripts when detaching from a process or when scripts have failed.
 
 
|-
 
|-
| rebuildDescriptionCache
+
|MouseHighlightedRecord()
| None
+
|[[Lua:Class:MemoryRecord|MemoryRecord]]
| None
+
|Returns the memory record the mouse points at, or nil if nothing is highlighted.
| Rebuilds the internal hash table used for fast description-based lookups. Call this after making many changes to descriptions if you need to ensure '''getMemoryRecordByDescription''' reflects the latest state.
 
 
|}
 
|}
  
=== Inherited Properties and Methods ===
+
===Examples===
  
As AddressList inherits from Panel, it also has access to all [[Lua:Class:Panel|Panel]], [[Lua:Class:WinControl|WinControl]], [[Lua:Class:Control|Control]], [[Lua:Class:Component|Component]], and [[Lua:Class:Object|Object]] properties and methods. However, most inherited UI properties are not typically used in scripting contexts since the AddressList is part of the main Cheat Engine form.
+
====Get the Addresslist object====
 +
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
Useful inherited properties include:
+
print("Records: " .. tostring(addresslist.Count))
* '''Visible''' (boolean) - Show/hide the address list panel
+
</syntaxhighlight>
* '''Enabled''' (boolean) - Enable/disable user interaction
 
* '''PopupMenu''' ([[Lua:Class:PopupMenu|PopupMenu]]) - Custom context menu for the address list
 
  
== Usage Examples ==
+
====Use the global AddressList variable====
 +
<syntaxhighlight lang="lua" line>
 +
local addresslist1 = getAddressList()
 +
local addresslist2 = AddressList
  
=== Basic Address List Access ===
+
print(addresslist1 == addresslist2)
 +
</syntaxhighlight>
  
<pre>
+
====Create a new MemoryRecord====
-- Get the main address list
+
<syntaxhighlight lang="lua" line>
local addressList = getAddressList()
+
local addresslist = getAddressList()
 +
local record = addresslist.createMemoryRecord()
  
-- Get the count of all records
+
record.Description = "Player Health"
print("Total records: " .. addressList.Count)
+
record.Address = "game.exe+12345"
 +
record.Type = vtDword
 +
record.Value = "1000"
 +
</syntaxhighlight>
  
-- Get selected records to find selection count
+
====Iterate through all records====
local selected = addressList.getSelectedRecords()
+
<syntaxhighlight lang="lua" line>
if selected then
+
local addresslist = getAddressList()
  print("Selected records: " .. #selected)
 
else
 
  print("Selected records: 0")
 
end
 
  
-- Access records by index (0-based)
+
for i = 0, addresslist.Count - 1 do
if addressList.Count > 0 then
+
   local record = addresslist[i]
   local firstRecord = addressList[0]
 
  print("First record: " .. firstRecord.Description)
 
 
 
  -- Alternative syntax
 
  local secondRecord = addressList.getMemoryRecord(1)
 
  if secondRecord then
 
    print("Second record: " .. secondRecord.Description)
 
  end
 
end
 
  
-- Access by description (alternative to index)
+
   print(i .. ": " .. record.Description)
local healthRec = addressList["Player Health"]
 
if healthRec then
 
   print("Found by description: " .. healthRec.Description)
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Get/set selected record
+
====Access a record with getMemoryRecord====
local selected = addressList.SelectedRecord
+
<syntaxhighlight lang="lua" line>
if selected then
+
local addresslist = getAddressList()
  print("Currently selected: " .. selected.Description)
 
  print("Value: " .. selected.Value)
 
end
 
</pre>
 
  
=== Creating Memory Records ===
+
if addresslist.Count > 0 then
 +
  local record = addresslist.getMemoryRecord(0)
  
<pre>
+
  print(record.Description)
local addressList = getAddressList()
+
end
 
+
</syntaxhighlight>
-- Create a basic memory record
 
local mr = addressList.createMemoryRecord()
 
mr.Description = "Player Health"
 
mr.Address = "game.exe+1234"
 
mr.Type = vtDword
 
  
-- Create multiple records
+
====Find a record by description====
local stats = {"Health", "Mana", "Stamina"}
+
<syntaxhighlight lang="lua" line>
local offsets = {0x10, 0x14, 0x18}
+
local addresslist = getAddressList()
 +
local record = addresslist.getMemoryRecordByDescription("Player Health")
  
for i = 1, #stats do
+
if record ~= nil then
   local record = addressList.createMemoryRecord()
+
   print("Found: " .. record.Description)
  record.Description = "Player " .. stats[i]
 
  record.Address = string.format("player_base+%X", offsets[i])
 
  record.Type = vtFloat
 
  record.ShowAsHex = false
 
 
end
 
end
 +
</syntaxhighlight>
  
print("Created " .. #stats .. " new records")
+
====Find a record by ID====
print("Total records now: " .. addressList.Count)
+
<syntaxhighlight lang="lua" line>
</pre>
+
local addresslist = getAddressList()
 +
local record = addresslist.getMemoryRecordByID(10)
  
=== Finding Records by Description ===
+
if record ~= nil then
 +
  print("Found ID 10: " .. record.Description)
 +
end
 +
</syntaxhighlight>
  
<pre>
+
====Get the selected record====
local addressList = getAddressList()
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
 +
local record = addresslist.getSelectedRecord()
  
-- Find by exact description
+
if record ~= nil then
local healthRecord = addressList.getMemoryRecordByDescription("Player Health")
+
   print("Selected: " .. record.Description)
if healthRecord then
 
   print("Health value: " .. healthRecord.Value)
 
  healthRecord.Active = true
 
else
 
  print("Player Health not found")
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Alternative: Search by index with description
+
====Use the SelectedRecord property====
local record = addressList.getMemoryRecord("Player Mana")
+
<syntaxhighlight lang="lua" line>
if record then
+
local addresslist = getAddressList()
  print("Mana address: " .. record.Address)
 
end
 
  
-- Note: Description lookup is case-sensitive
+
if addresslist.SelCount > 0 then
local notFound = addressList.getMemoryRecordByDescription("player health")  -- Won't find "Player Health"
+
  local record = addresslist.SelectedRecord
</pre>
 
  
=== Finding Records by ID ===
+
  print("Selected: " .. record.Description)
 +
end
 +
</syntaxhighlight>
  
<pre>
+
====Set the selected record====
local addressList = getAddressList()
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
 +
local record = addresslist.getMemoryRecordByDescription("Player Health")
  
-- Get a record's ID and store it
+
if record ~= nil then
local healthRecord = addressList.getMemoryRecordByDescription("Player Health")
+
   addresslist.setSelectedRecord(record)
if healthRecord then
 
   local storedID = healthRecord.ID
 
  print("Stored ID: " .. storedID)
 
 
 
  -- Later, retrieve by ID (even if description changed)
 
  local retrievedRecord = addressList.getMemoryRecordByID(storedID)
 
  if retrievedRecord then
 
    print("Retrieved: " .. retrievedRecord.Description)
 
    print("Same record: " .. tostring(healthRecord == retrievedRecord))
 
  end
 
 
end
 
end
 +
</syntaxhighlight>
  
-- IDs are unique and persistent within a session
+
====Get all selected records====
-- Useful for tracking records across description changes
+
<syntaxhighlight lang="lua" line>
</pre>
+
local addresslist = getAddressList()
 +
local selectedRecords = addresslist.getSelectedRecords()
  
=== Working with Selected Records ===
+
for i, record in ipairs(selectedRecords) do
 +
  print(i .. ": " .. record.Description)
 +
end
 +
</syntaxhighlight>
  
<pre>
+
====Show the description change dialog====
local addressList = getAddressList()
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
-- Get all selected records
+
if addresslist.SelCount > 0 then
local selected = addressList.getSelectedRecords()
+
   addresslist.doDescriptionChange()
if selected then
 
   print("Processing " .. #selected .. " selected records")
 
 
 
  for i = 1, #selected do
 
    local record = selected[i]
 
    print(i .. ": " .. record.Description)
 
   
 
    -- Modify all selected records
 
    record.Active = true
 
    record.Color = 0x0000FF  -- Red (BGR format)
 
  end
 
else
 
  print("No records selected")
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Select a specific record programmatically
+
====Show the address change dialog====
local targetRecord = addressList.getMemoryRecordByDescription("God Mode")
+
<syntaxhighlight lang="lua" line>
if targetRecord then
+
local addresslist = getAddressList()
  addressList.SelectedRecord = targetRecord
 
  print("Selected: " .. targetRecord.Description)
 
end
 
  
-- Check current selection
+
if addresslist.SelCount > 0 then
local currentSelection = addressList.getSelectedRecord()
+
   addresslist.doAddressChange()
if currentSelection then
 
   print("Current selection: " .. currentSelection.Description)
 
 
end
 
end
</pre>
+
</syntaxhighlight>
 
 
=== Triggering UI Dialogs ===
 
  
<pre>
+
====Show the type change dialog====
local addressList = getAddressList()
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
-- Select a record first
+
if addresslist.SelCount > 0 then
local record = addressList.getMemoryRecordByDescription("Player Health")
+
   addresslist.doTypeChange()
if record then
 
   addressList.SelectedRecord = record
 
 
 
  -- Open description editor dialog
 
  -- addressList.doDescriptionChange()
 
 
 
  -- Open address editor dialog
 
  -- addressList.doAddressChange()
 
 
 
  -- Open type selector dialog
 
  -- addressList.doTypeChange()
 
 
 
  -- Open value editor dialog
 
  -- addressList.doValueChange()
 
 
 
  -- Note: These dialogs are modal and will pause script execution
 
  -- Uncomment the lines above to test interactively
 
 
end
 
end
</pre>
+
</syntaxhighlight>
  
=== Managing Auto Assembler Scripts ===
+
====Show the value change dialog====
 +
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
<pre>
+
if addresslist.SelCount > 0 then
local addressList = getAddressList()
+
  addresslist.doValueChange()
 +
end
 +
</syntaxhighlight>
  
-- Create an auto assembler script
+
====Disable all records without executing [Disable] sections====
local script = addressList.createMemoryRecord()
+
<syntaxhighlight lang="lua" line>
script.Description = "Infinite Health"
+
local addresslist = getAddressList()
script.Type = vtAutoAssembler
 
script.Script = [[
 
[ENABLE]
 
aobscan(health_code,89 0D * * * * 8B 45 08)
 
alloc(newmem,32)
 
  
label(code)
+
addresslist.disableAllWithoutExecute()
label(return)
+
</syntaxhighlight>
  
newmem:
+
====Rebuild the description cache====
code:
+
<syntaxhighlight lang="lua" line>
  mov [health_address],#1000  // Set to 1000
+
local addresslist = getAddressList()
  mov [edx],ecx
 
  jmp return
 
  
health_code:
+
addresslist.rebuildDescriptionCache()
  jmp newmem
+
</syntaxhighlight>
  nop
 
return:
 
registersymbol(health_code)
 
  
[DISABLE]
+
====Get the mouse-highlighted record====
health_code:
+
<syntaxhighlight lang="lua" line>
  db 89 0D * * * * 8B 45 08
+
local addresslist = getAddressList()
unregistersymbol(health_code)
+
local record = addresslist.MouseHighlightedRecord()
dealloc(newmem)
 
]]
 
  
-- Activate the script
+
if record ~= nil then
script.Active = true
+
  print("Mouse is over: " .. record.Description)
 
+
end
-- Later, disable all scripts without executing [DISABLE] sections
+
</syntaxhighlight>
-- Useful when the process is about to close or has crashed
 
addressList.disableAllWithoutExecute()
 
</pre>
 
  
=== Iterating Through All Records ===
+
====Change address list colors====
 +
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
<pre>
+
addresslist.CheckboxActiveColor = 0x00FF00
local addressList = getAddressList()
+
addresslist.CheckboxColor = 0x808080
 +
addresslist.SelectedBackgroundColor = 0x202020
 +
addresslist.SelectedSecondaryBackgroundColor = 0x303030
 +
addresslist.ExpandSignColor = 0xFFFFFF
 +
</syntaxhighlight>
  
-- Iterate through all records (including children)
+
====Handle description changes====
print("=== All Records ===")
+
<syntaxhighlight lang="lua" line>
for i = 0, addressList.Count - 1 do
+
local addresslist = getAddressList()
  local record = addressList[i]
 
  local indent = string.rep(" ", record.Parent and 1 or 0)
 
 
 
  print(string.format("%s[%d] %s = %s (%s)",
 
    indent, i, record.Description, record.Value,
 
    record.Active and "Active" or "Inactive"))
 
end
 
  
-- Find all active records
+
addresslist.OnDescriptionChange = function(sender, memrec)
print("\n=== Active Records ===")
+
   print("Description change requested for: " .. memrec.Description)
local activeCount = 0
 
for i = 0, addressList.Count - 1 do
 
  local record = addressList[i]
 
  if record.Active then
 
    print(record.Description)
 
    activeCount = activeCount + 1
 
   end
 
end
 
print("Total active: " .. activeCount)
 
  
-- Find all records of a specific type
+
   return false
print("\n=== Float Records ===")
 
for i = 0, addressList.Count - 1 do
 
   local record = addressList[i]
 
  if record.Type == vtFloat or record.Type == vtDouble then
 
    print(record.Description .. " @ " .. record.Address)
 
  end
 
 
end
 
end
</pre>
+
</syntaxhighlight>
  
=== Batch Operations ===
+
====Handle address changes====
 +
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
<pre>
+
addresslist.OnAddressChange = function(sender, memrec)
local addressList = getAddressList()
+
  print("Address change requested for: " .. memrec.Description)
  
-- Deactivate all records
+
   return false
print("Deactivating all records...")
 
for i = 0, addressList.Count - 1 do
 
   addressList[i].Active = false
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Activate records matching a pattern
+
====Handle value changes manually====
print("Activating player-related records...")
+
<syntaxhighlight lang="lua" line>
local activatedCount = 0
+
local addresslist = getAddressList()
for i = 0, addressList.Count - 1 do
 
  local record = addressList[i]
 
  if record.Description:lower():find("player") then
 
    record.Active = true
 
    activatedCount = activatedCount + 1
 
  end
 
end
 
print("Activated " .. activatedCount .. " records")
 
  
-- Change all values matching a condition
+
addresslist.OnValueChange = function(sender, memrec)
for i = 0, addressList.Count - 1 do
+
   local oldValue = memrec.Value
  local record = addressList[i]
 
   local numValue = tonumber(record.Value)
 
 
 
  if numValue and numValue < 100 then
 
    record.Value = "999"
 
    print("Changed " .. record.Description .. " to 999")
 
  end
 
end
 
</pre>
 
  
=== Rebuilding Description Cache ===
+
  memrec.Value = "999"
  
<pre>
+
  print("Changed " .. memrec.Description .. " from " .. oldValue .. " to " .. memrec.Value)
local addressList = getAddressList()
 
  
-- Make many description changes
+
   return true
for i = 0, addressList.Count - 1 do
 
   local record = addressList[i]
 
  record.Description = "Modified_" .. record.Description
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Rebuild the description cache for fast lookups
+
====Handle Auto Assembler script edits====
addressList.rebuildDescriptionCache()
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
-- Now lookups will work correctly
+
addresslist.OnAutoAssemblerEdit = function(sender, memrec)
local modifiedRecord = addressList.getMemoryRecordByDescription("Modified_Player Health")
+
   print("Auto Assembler edit requested for: " .. memrec.Description)
if modifiedRecord then
 
   print("Found: " .. modifiedRecord.Description)
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Note: The cache is automatically updated for individual changes,
+
====Create multiple records====
-- but rebuilding is useful after bulk modifications or when debugging
+
<syntaxhighlight lang="lua" line>
</pre>
+
local addresslist = getAddressList()
 
 
=== Working with Hierarchical Records ===
 
  
<pre>
+
local values = {
local addressList = getAddressList()
+
  { description = "Health", address = "game.exe+1000" },
 +
  { description = "Ammo", address = "game.exe+2000" },
 +
  { description = "Score", address = "game.exe+3000" }
 +
}
  
-- Create a parent group
+
for i, entry in ipairs(values) do
local group = addressList.createMemoryRecord()
+
  local record = addresslist.createMemoryRecord()
group.Description = "Player Stats"
 
group.IsGroupHeader = true
 
group.Options = "[moActivateChildrenAsWell,moDeactivateChildrenAsWell]"
 
  
-- Create children and attach to group
+
   record.Description = entry.description
local childDescriptions = {"Health", "Mana", "Stamina"}
+
   record.Address = entry.address
for i, desc in ipairs(childDescriptions) do
+
   record.Type = vtDword
  local child = addressList.createMemoryRecord()
 
   child.Description = desc
 
  child.Type = vtDword
 
   child.Address = string.format("player_base+%X", (i-1) * 4)
 
   child.appendToEntry(group)
 
 
end
 
end
 +
</syntaxhighlight>
  
-- Activate the group (children will activate too)
+
====Clear and rebuild the table====
group.Active = true
+
<syntaxhighlight lang="lua" line>
 +
local addresslist = getAddressList()
  
-- Note: All records are still in the flat addressList.Count
+
addresslist.clear()
-- Parent-child relationships are maintained separately
 
print("Total records: " .. addressList.Count)
 
print("Group children: " .. group.Count)
 
</pre>
 
  
=== Advanced: Monitoring Changes ===
+
local health = addresslist.createMemoryRecord()
 +
health.Description = "Health"
 +
health.Address = "game.exe+1234"
 +
health.Type = vtDword
  
<pre>
+
local ammo = addresslist.createMemoryRecord()
local addressList = getAddressList()
+
ammo.Description = "Ammo"
 
+
ammo.Address = "game.exe+5678"
-- Store initial state
+
ammo.Type = vtDword
local recordStates = {}
+
</syntaxhighlight>
for i = 0, addressList.Count - 1 do
 
  local record = addressList[i]
 
  recordStates[record.ID] = {
 
    description = record.Description,
 
    value = record.Value,
 
    active = record.Active
 
  }
 
end
 
 
 
-- Later, check for changes
 
print("=== Changes Detected ===")
 
for i = 0, addressList.Count - 1 do
 
  local record = addressList[i]
 
  local oldState = recordStates[record.ID]
 
 
 
  if oldState then
 
    if oldState.value ~= record.Value then
 
      print(record.Description .. " value changed: " ..
 
            oldState.value .. " -> " .. record.Value)
 
    end
 
   
 
    if oldState.active ~= record.Active then
 
      print(record.Description .. " activation changed: " ..
 
            tostring(oldState.active) .. " -> " .. tostring(record.Active))
 
    end
 
  end
 
end
 
</pre>
 
 
 
== Important Notes ==
 
 
 
=== Record Indexing ===
 
 
 
* The '''MemoryRecord[index]''' property uses '''0-based indexing'''
 
* The '''getSelectedRecords()''' method returns a '''1-indexed table''' (Lua convention)
 
* Child indices within parent records use '''0-based indexing'''
 
* You can use '''AddressList[index]''' as a shorthand for '''AddressList.MemoryRecord[index]'''
 
* You can also use '''AddressList["description"]''' to search by description
 
 
 
=== Description Lookup Performance ===
 
 
 
* '''getMemoryRecordByDescription''' uses an internal hash table for O(1) lookups
 
* The cache is automatically maintained for most operations
 
* Some reserved descriptions (e.g., "BYTE", "WORD", "DWORD", "QWORD", "INT", "FLOAT", "DOUBLE") cannot be found by description as they're in the forbidden list
 
* If lookups fail after many changes, call '''rebuildDescriptionCache()'''
 
* Description lookups are '''case-sensitive'''
 
 
 
=== Selection Behavior ===
 
 
 
* Setting '''SelectedRecord''' deselects all other records
 
* Multiple selection is typically done through the UI (Ctrl+Click, Shift+Click)
 
* '''getSelectedRecords()''' includes records at all hierarchy levels if selected
 
* Selected records remain selected until explicitly changed
 
* Use '''getSelectedRecord()''' or '''SelectedRecord''' property to get the main selected record
 
 
 
=== Memory Record Lifecycle ===
 
 
 
* Creating records with '''createMemoryRecord()''' adds them to the address list
 
* Records are removed from the count when deleted via '''memoryrecord.delete()'''
 
* The Count property reflects all records at all hierarchy levels (including children)
 
* Deleting a parent record automatically deletes all its children
 
 
 
=== Thread Safety ===
 
 
 
* Address list operations should be performed on the main thread
 
* Use [[Lua:synchronize|synchronize]] if accessing from background threads
 
* UI dialog methods ('''do*Change''') must be called from the main thread and will block script execution
 
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{Forms}}
* [[Lua:getAddressList|getAddressList]] - Get the main AddressList object
 
* [[Lua:getMainForm|getMainForm]] - Get the main Cheat Engine form
 
 
 
=== Related Classes ===
 
* [[Lua:Class:MemoryRecord|MemoryRecord]] - Individual address list entries
 
* [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]] - Hotkeys attached to memory records
 
* [[Lua:Class:Panel|Panel]] - Parent class
 
* [[Lua:Class:WinControl|WinControl]] - Grandparent class
 
* [[Lua:Class:Control|Control]] - Base control class
 
* [[Lua:Class:Component|Component]] - Base component class
 

Latest revision as of 18:44, 25 June 2026

{} Class

class Addresslist : Panel

The Addresslist class represents Cheat Engine's main cheat table address list.

It contains MemoryRecord entries and provides methods for selecting, creating, finding, editing, activating, and disabling records.

Inheritance[edit]

Class Inherits From Description
Addresslist Panel The main cheat table address list control.
Panel WinControl Base class for panel controls.
WinControl Control Base class for windowed controls.
Control Component Base class for visual controls.
Component Object Base class for components.

Properties[edit]

Property Type Description
LoadedTableVersion Integer Returns the table version of the last loaded table.
Count Integer The number of records in the address list.
SelCount Integer The number of selected records.
SelectedRecord MemoryRecord The main selected memory record.
MemoryRecord[] MemoryRecord Array-style accessor for individual memory records.
[] MemoryRecord Default accessor for individual memory records.
CheckboxActiveSelectedColor Color The checkbox color used for records that are both active and selected.
CheckboxActiveColor Color The checkbox color used for active records.
CheckboxSelectedColor Color The checkbox color used for selected records.
CheckboxColor Color The normal checkbox color.
SelectedBackgroundColor Color The primary background color used for selected records.
SelectedSecondaryBackgroundColor Color The secondary background color used for selected records.
ExpandSignColor Color The color of the expand/collapse sign.
IncreaseArrowColor Color The color of the increase arrow.
DecreaseArrowColor Color The color of the decrease arrow.

Events[edit]

Event Callback Description
OnDescriptionChange function(addresslist, memrec): boolean Called when the user initiates a description column change on a record. Return true if you handle it, false for normal behavior.
OnAddressChange function(addresslist, memrec): boolean Called when the user initiates an address column change on a record. Return true if you handle it, false for normal behavior.
OnTypeChange function(addresslist, memrec): boolean Called when the user initiates a type column change on a record. Return true if you handle it, false for normal behavior.
OnValueChange function(addresslist, memrec): boolean Called when the user initiates a value column change on a record. Return true if you handle it, false for normal behavior.
OnAutoAssemblerEdit function(addresslist, memrec) Called when the user initiates a MemoryRecord Auto Assembler script edit. The callback is responsible for changing the memory record.

Methods[edit]

Method Return Type Description
getCount() Integer Returns the number of records in the address list.
getMemoryRecord(index) MemoryRecord Returns the memory record at the given index.
getMemoryRecordByDescription(description) MemoryRecord Returns the first memory record with the given description.
getMemoryRecordByID(ID) MemoryRecord Returns the memory record with the given ID.
createMemoryRecord() MemoryRecord Creates a generic cheat table entry and adds it to the address list.
getSelectedRecords() Table Returns a table containing all selected records.
doDescriptionChange() void Shows the GUI window to change the description of the selected entry.
doAddressChange() void Shows the GUI window to change the address of the selected entry.
doTypeChange() void Shows the GUI window to change the type of the selected entries.
doValueChange() void Shows the GUI window to change the value of the selected entries.
getSelectedRecord() MemoryRecord Gets the main selected memory record.
setSelectedRecord(memrec) void Sets the currently selected memory record. This unselects all other entries.
disableAllWithoutExecute() void Disables all memory records without executing their [Disable] sections.
rebuildDescriptionCache() void Rebuilds the description-to-record lookup table.
MouseHighlightedRecord() MemoryRecord Returns the memory record the mouse points at, or nil if nothing is highlighted.

Examples[edit]

Get the Addresslist object[edit]

1 local addresslist = getAddressList()
2 
3 print("Records: " .. tostring(addresslist.Count))

Use the global AddressList variable[edit]

1 local addresslist1 = getAddressList()
2 local addresslist2 = AddressList
3 
4 print(addresslist1 == addresslist2)

Create a new MemoryRecord[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.createMemoryRecord()
3 
4 record.Description = "Player Health"
5 record.Address = "game.exe+12345"
6 record.Type = vtDword
7 record.Value = "1000"

Iterate through all records[edit]

1 local addresslist = getAddressList()
2 
3 for i = 0, addresslist.Count - 1 do
4   local record = addresslist[i]
5 
6   print(i .. ": " .. record.Description)
7 end

Access a record with getMemoryRecord[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.Count > 0 then
4   local record = addresslist.getMemoryRecord(0)
5 
6   print(record.Description)
7 end

Find a record by description[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.getMemoryRecordByDescription("Player Health")
3 
4 if record ~= nil then
5   print("Found: " .. record.Description)
6 end

Find a record by ID[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.getMemoryRecordByID(10)
3 
4 if record ~= nil then
5   print("Found ID 10: " .. record.Description)
6 end

Get the selected record[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.getSelectedRecord()
3 
4 if record ~= nil then
5   print("Selected: " .. record.Description)
6 end

Use the SelectedRecord property[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.SelCount > 0 then
4   local record = addresslist.SelectedRecord
5 
6   print("Selected: " .. record.Description)
7 end

Set the selected record[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.getMemoryRecordByDescription("Player Health")
3 
4 if record ~= nil then
5   addresslist.setSelectedRecord(record)
6 end

Get all selected records[edit]

1 local addresslist = getAddressList()
2 local selectedRecords = addresslist.getSelectedRecords()
3 
4 for i, record in ipairs(selectedRecords) do
5   print(i .. ": " .. record.Description)
6 end

Show the description change dialog[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.SelCount > 0 then
4   addresslist.doDescriptionChange()
5 end

Show the address change dialog[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.SelCount > 0 then
4   addresslist.doAddressChange()
5 end

Show the type change dialog[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.SelCount > 0 then
4   addresslist.doTypeChange()
5 end

Show the value change dialog[edit]

1 local addresslist = getAddressList()
2 
3 if addresslist.SelCount > 0 then
4   addresslist.doValueChange()
5 end

Disable all records without executing [Disable] sections[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.disableAllWithoutExecute()

Rebuild the description cache[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.rebuildDescriptionCache()

Get the mouse-highlighted record[edit]

1 local addresslist = getAddressList()
2 local record = addresslist.MouseHighlightedRecord()
3 
4 if record ~= nil then
5   print("Mouse is over: " .. record.Description)
6 end

Change address list colors[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.CheckboxActiveColor = 0x00FF00
4 addresslist.CheckboxColor = 0x808080
5 addresslist.SelectedBackgroundColor = 0x202020
6 addresslist.SelectedSecondaryBackgroundColor = 0x303030
7 addresslist.ExpandSignColor = 0xFFFFFF

Handle description changes[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.OnDescriptionChange = function(sender, memrec)
4   print("Description change requested for: " .. memrec.Description)
5 
6   return false
7 end

Handle address changes[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.OnAddressChange = function(sender, memrec)
4   print("Address change requested for: " .. memrec.Description)
5 
6   return false
7 end

Handle value changes manually[edit]

 1 local addresslist = getAddressList()
 2 
 3 addresslist.OnValueChange = function(sender, memrec)
 4   local oldValue = memrec.Value
 5 
 6   memrec.Value = "999"
 7 
 8   print("Changed " .. memrec.Description .. " from " .. oldValue .. " to " .. memrec.Value)
 9 
10   return true
11 end

Handle Auto Assembler script edits[edit]

1 local addresslist = getAddressList()
2 
3 addresslist.OnAutoAssemblerEdit = function(sender, memrec)
4   print("Auto Assembler edit requested for: " .. memrec.Description)
5 end

Create multiple records[edit]

 1 local addresslist = getAddressList()
 2 
 3 local values = {
 4   { description = "Health", address = "game.exe+1000" },
 5   { description = "Ammo", address = "game.exe+2000" },
 6   { description = "Score", address = "game.exe+3000" }
 7 }
 8 
 9 for i, entry in ipairs(values) do
10   local record = addresslist.createMemoryRecord()
11 
12   record.Description = entry.description
13   record.Address = entry.address
14   record.Type = vtDword
15 end

Clear and rebuild the table[edit]

 1 local addresslist = getAddressList()
 2 
 3 addresslist.clear()
 4 
 5 local health = addresslist.createMemoryRecord()
 6 health.Description = "Health"
 7 health.Address = "game.exe+1234"
 8 health.Type = vtDword
 9 
10 local ammo = addresslist.createMemoryRecord()
11 ammo.Description = "Ammo"
12 ammo.Address = "game.exe+5678"
13 ammo.Type = vtDword

See Also[edit]

Main Pages

Form Related Pages