Difference between revisions of "Lua:Class:MemoryRecord"

From Cheat Engine
Jump to navigation Jump to search
m (added a simple description...)
m
 
(27 intermediate revisions by 9 users not shown)
Line 1: Line 1:
--Under Construction
+
[[Category:Lua]]
 +
{{Class|'''class''' MemoryRecord ''':''' Object}}
  
The class MemoryRecord are the entries in Cheat tables. This class is commonly used with [[Addresslist]].
+
The MemoryRecord class represents an entry in Cheat Engine's [[Lua:Class:Addresslist|Addresslist]].
  
----
+
A memory record can represent a normal address, a pointer, an Auto Assembler script, a Lua script entry, a group header, or another cheat table entry. MemoryRecord objects expose properties for address handling, value display, activation, child records, dropdown lists, hotkeys, and event callbacks.
  
 +
===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
 +
|-
 +
|MemoryRecord
 +
|[[Lua:Class:Object|Object]]
 +
|Represents one entry in the Cheat Engine address list.
 +
|}
  
'''MemoryRecord Class'''
+
===Properties===
  The Memoryrecord class object describes a Cheat Table's Cheat Entry.
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Property
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|ID
 +
|Integer
 +
|Unique ID of the memory record.
 +
|-
 +
|Index
 +
|Integer
 +
|The index of this record in the address list. 0 is the top entry. Read-only.
 +
|-
 +
|Description
 +
|String
 +
|The description of the memory record.
 +
|-
 +
|Address
 +
|String
 +
|Gets or sets the interpretable address string. This is useful for simple address settings and can contain symbols, module offsets, or expressions.
 +
|-
 +
|AddressString
 +
|String
 +
|The address string shown in Cheat Engine. Read-only.
 +
|-
 +
|OffsetCount
 +
|Integer
 +
|The number of offsets. Set this to 0 for a normal non-pointer address.
 +
|-
 +
|Offset[index]
 +
|Integer
 +
|Array-style access to each pointer offset.
 +
|-
 +
|OffsetText[index]
 +
|String
 +
|Array-style access to each pointer offset using interpretable text.
 +
|-
 +
|CurrentAddress
 +
|Integer
 +
|The resolved address the memory record points to.
 +
|-
 +
|VarType
 +
|String
 +
|The variable type of this record as a string.
 +
|-
 +
|Type
 +
|ValueType
 +
|The variable type of this record as a numeric ValueType constant.
 +
|-
 +
|CustomTypeName
 +
|String
 +
|If the type is vtCustom, this contains the name of the custom type.
 +
|-
 +
|Script
 +
|String
 +
|If the type is vtAutoAssembler, this contains the Auto Assembler script.
 +
|-
 +
|Value
 +
|String
 +
|The value in string form.
 +
|-
 +
|NumericalValue
 +
|Number
 +
|The value in numerical form, or nil if it cannot be parsed as a number.
 +
|-
 +
|Selected
 +
|Boolean
 +
|True if this record is selected. Read-only.
 +
|-
 +
|Active
 +
|Boolean
 +
|Set to true to activate or freeze the record. Set to false to deactivate or unfreeze it.
 +
|-
 +
|Color
 +
|Integer
 +
|The display color of the memory record.
 +
|-
 +
|ShowAsHex
 +
|Boolean
 +
|If true, the value is shown as hexadecimal.
 +
|-
 +
|ShowAsSigned
 +
|Boolean
 +
|If true, the value is shown as signed.
 +
|-
 +
|AllowIncrease
 +
|Boolean
 +
|Allows the value to increase while frozen. Unfreezing resets this to false.
 +
|-
 +
|AllowDecrease
 +
|Boolean
 +
|Allows the value to decrease while frozen. Unfreezing resets this to false.
 +
|-
 +
|Collapsed
 +
|Boolean
 +
|Set to true to collapse this record or false to expand it. Use expand/collapse methods for recursive operations where available.
 +
|-
 +
|IsGroupHeader
 +
|Boolean
 +
|Set to true if the record was created as a group header with no address or value information.
 +
|-
 +
|IsAddressGroupHeader
 +
|Boolean
 +
|Set to true if the record was created as a group header with an address.
 +
|-
 +
|IsReadable
 +
|Boolean
 +
|Set to false if the record contains an unreadable address. Read-only. This is only updated after the Value property has been accessed at least once.
 +
|-
 +
|Options
 +
|String set
 +
|A string enclosed by square brackets containing comma-separated options. See [[#MemoryRecord Options|MemoryRecord Options]].
 +
|-
 +
|DropDownLinked
 +
|Boolean
 +
|True if the dropdown list refers to the dropdown list of another memory record.
 +
|-
 +
|DropDownLinkedMemrec
 +
|String
 +
|Description of the linked memory record, or an empty string if no record is linked.
 +
|-
 +
|DropDownList
 +
|[[Lua:Class:Stringlist|Stringlist]]
 +
|List of "value:description" lines used for dropdown display.
 +
|-
 +
|DropDownReadOnly
 +
|Boolean
 +
|True if manual user input is disallowed.
 +
|-
 +
|DropDownDescriptionOnly
 +
|Boolean
 +
|If true, only the dropdown description is displayed.
 +
|-
 +
|DisplayAsDropDownListItem
 +
|Boolean
 +
|If true, the value is displayed as a dropdown list item.
 +
|-
 +
|DropDownCount
 +
|Integer
 +
|Equivalent to DropDownList.Count. Read-only.
 +
|-
 +
|DropDownValue[index]
 +
|String
 +
|Array-style access to dropdown values. Read-only.
 +
|-
 +
|DropDownDescription[index]
 +
|String
 +
|Array-style access to dropdown descriptions. Read-only.
 +
|-
 +
|Count
 +
|Integer
 +
|The number of child records.
 +
|-
 +
|Child[index]
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|Array-style access to child records.
 +
|-
 +
|[index]
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|Default accessor for child records.
 +
|-
 +
|Parent
 +
|[[Lua:Class:MemoryRecord|MemoryRecord]]
 +
|The parent memory record.
 +
|-
 +
|HotkeyCount
 +
|Integer
 +
|The number of hotkeys attached to this memory record.
 +
|-
 +
|Hotkey[index]
 +
|[[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
|Array-style access to hotkeys attached to this memory record.
 +
|-
 +
|Async
 +
|Boolean
 +
|Set to true if activating this entry should be asynchronous. This only applies to Auto Assembler or Lua script records.
 +
|-
 +
|AsyncProcessing
 +
|Boolean
 +
|True when Async is true and the record is currently being processed.
 +
|-
 +
|AsyncProcessingTime
 +
|Qword
 +
|The time in milliseconds that the record has been processing asynchronously.
 +
|-
 +
|HasMouseOver
 +
|Boolean
 +
|True if the mouse is currently over this memory record.
 +
|-
 +
|DontSave
 +
|Boolean
 +
|If true, this memory record and its children will not be saved.
 +
|}
  
 +
===Type-Specific Properties===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Record Type
 +
!align="left"|Property
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|vtString
 +
|String.Size
 +
|The number of characters in the string.
 +
|-
 +
|vtString
 +
|String.Unicode
 +
|If true, the string is treated as Unicode.
 +
|-
 +
|vtString
 +
|String.Codepage
 +
|If true, the string uses codepage handling.
 +
|-
 +
|vtBinary
 +
|Binary.Startbit
 +
|The first bit to start reading from.
 +
|-
 +
|vtBinary
 +
|Binary.Size
 +
|The number of bits.
 +
|-
 +
|vtByteArray
 +
|Aob.Size
 +
|The number of bytes in the byte array.
 +
|}
  
'''memoryrecord_getID'''(memoryrecord)
+
===Events===
  Returns the unique id of this memory record. Every memory record has an unique id
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Event
 +
!align="left"|Callback
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|OnActivate
 +
|function(memoryrecord, before, currentstate): boolean
 +
|Called when the memory record will change or has changed Active to true. If before is true, not returning true stops activation.
 +
|-
 +
|OnDeactivate
 +
|function(memoryrecord, before, currentstate): boolean
 +
|Called when the memory record will change or has changed Active to false. If before is true, not returning true stops deactivation.
 +
|-
 +
|OnDestroy
 +
|function()
 +
|Called when the memory record is destroyed.
 +
|-
 +
|OnGetDisplayValue
 +
|function(memoryrecord, valuestring): boolean, string
 +
|Called when rendering the value of a memory record. Return true and a string to override the displayed value.
 +
|-
 +
|OnValueChanged
 +
|function(memoryrecord, oldvalue, newvalue)
 +
|Called whenever the value of a memory record has changed.
 +
|-
 +
|OnValueChangedByUser
 +
|function(memoryrecord, oldvalue, newvalue)
 +
|Called whenever the value of a memory record has been changed by the user.
 +
|}
  
 +
===Methods===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Method
 +
!align="left"|Return Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|getDescription()
 +
|String
 +
|Returns the description of the memory record.
 +
|-
 +
|setDescription(description)
 +
|void
 +
|Sets the description of the memory record.
 +
|-
 +
|getAddress()
 +
|String, Table
 +
|Returns the interpretable address string. If it is a pointer, it returns a second result containing a table with the offsets.
 +
|-
 +
|setAddress(address)
 +
|void
 +
|Sets the interpretable address string.
 +
|-
 +
|setAddress(address, offsets)
 +
|void
 +
|Sets the interpretable address string and pointer offsets.
 +
|-
 +
|getOffsetCount()
 +
|Integer
 +
|Returns the number of offsets for this memory record.
 +
|-
 +
|setOffsetCount(count)
 +
|void
 +
|Sets the number of offsets.
 +
|-
 +
|getOffset(index)
 +
|Integer
 +
|Returns the offset at the given index.
 +
|-
 +
|setOffset(index, value)
 +
|void
 +
|Sets the offset at the given index.
 +
|-
 +
|getCurrentAddress()
 +
|Integer
 +
|Returns the current resolved address as an integer.
 +
|-
 +
|appendToEntry(memrec)
 +
|void
 +
|Appends this memory record to the given memory record as a child.
 +
|-
 +
|getHotkey(index)
 +
|[[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
|Returns the hotkey at the given index.
 +
|-
 +
|getHotkeyByID(id)
 +
|[[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
|Returns the hotkey with the given ID.
 +
|-
 +
|reinterpret()
 +
|void
 +
|Reinterprets the memory record.
 +
|-
 +
|createHotkey(keys, action, value, description)
 +
|[[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
|Creates a hotkey object for this memory record.
 +
|-
 +
|disableWithoutExecute()
 +
|void
 +
|Disables the entry without executing its disable section.
 +
|-
 +
|beginEdit()
 +
|void
 +
|Call this before a long edit sequence. This prevents the record from being deleted while editing.
 +
|-
 +
|endEdit()
 +
|void
 +
|Marks the end of a long edit sequence started with beginEdit().
 +
|}
  
'''memoryrecord_getHotkeyCount'''(memoryrecord)
+
===Value Types===
  Returns the number of hotkeys assigned to this Cheat Entry
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|vtByte
 +
|0
 +
|1-byte integer.
 +
|-
 +
|vtWord
 +
|1
 +
|2-byte integer.
 +
|-
 +
|vtDword
 +
|2
 +
|4-byte integer.
 +
|-
 +
|vtQword
 +
|3
 +
|8-byte integer.
 +
|-
 +
|vtSingle
 +
|4
 +
|Single-precision float.
 +
|-
 +
|vtDouble
 +
|5
 +
|Double-precision float.
 +
|-
 +
|vtString
 +
|6
 +
|String.
 +
|-
 +
|vtUnicodeString
 +
|7
 +
|Unicode string.
 +
|-
 +
|vtByteArray
 +
|8
 +
|Array of bytes.
 +
|-
 +
|vtBinary
 +
|9
 +
|Binary bitfield.
 +
|-
 +
|vtAll
 +
|10
 +
|All value types.
 +
|-
 +
|vtAutoAssembler
 +
|11
 +
|Auto Assembler script.
 +
|-
 +
|vtPointer
 +
|12
 +
|Pointer type.
 +
|-
 +
|vtCustom
 +
|13
 +
|Custom type.
 +
|-
 +
|vtGrouped
 +
|14
 +
|Grouped type.
 +
|-
 +
|vtByteArrays
 +
|15
 +
|Multiple byte arrays.
 +
|-
 +
|vtCodePageString
 +
|16
 +
|Codepage string.
 +
|}
  
 +
===MemoryRecord Options===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Option
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|moHideChildren
 +
|Hides the child records of this memory record.
 +
|-
 +
|moActivateChildrenAsWell
 +
|Activating this record also activates its children.
 +
|-
 +
|moDeactivateChildrenAsWell
 +
|Deactivating this record also deactivates its children.
 +
|-
 +
|moRecursiveSetValue
 +
|Setting the value also sets the value of all children recursively.
 +
|-
 +
|moAllowManualCollapseAndExpand
 +
|Allows the user to manually collapse and expand this record.
 +
|-
 +
|moManualExpandCollapse
 +
|Enables manual expand/collapse behavior.
 +
|-
 +
|moAlwaysHideChildren
 +
|Always hides the child records.
 +
|}
  
'''memoryrecord_getHotkey'''(memoryrecord, index)
+
===Hotkey Actions===
  Returns a memoryrecordhotkey class
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Constant
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|mrhToggleActivation
 +
|0
 +
|Toggles the active state of the memory record.
 +
|-
 +
|mrhToggleActivationAllowIncrease
 +
|1
 +
|Toggles activation and allows the value to increase while frozen.
 +
|-
 +
|mrhToggleActivationAllowDecrease
 +
|2
 +
|Toggles activation and allows the value to decrease while frozen.
 +
|-
 +
|mrhActivate
 +
|3
 +
|Activates the memory record.
 +
|-
 +
|mrhDeactivate
 +
|4
 +
|Deactivates the memory record.
 +
|-
 +
|mrhSetValue
 +
|5
 +
|Sets the memory record to the specified value.
 +
|-
 +
|mrhIncreaseValue
 +
|6
 +
|Increases the current value by the specified amount.
 +
|-
 +
|mrhDecreaseValue
 +
|7
 +
|Decreases the current value by the specified amount.
 +
|}
  
 +
===Global Events===
 +
{{CodeBox|'''function''' onMemRecPreExecute(''memoryrecord'', ''newstate'') ''':''' boolean}}
  
'''memoryrecord_getHotkeyByID'''(memoryrecord, ID)
+
If defined, this function is called before a memory record action is performed. The Active property is about to change to newstate.
  Every hotkey in a memoryrecord gets an unique ID. This way you can always find the hotkey even if the order of hotkeys has changed (or deleted)
 
  
 +
{{CodeBox|'''function''' onMemRecPostExecute(''memoryrecord'', ''newstate'', ''succeeded'') ''':''' void}}
  
'''memoryrecord_setDescription'''(memoryrecord, description)
+
If defined, this function is called after a memory record action has been performed. If succeeded is true, the Active state changed to newstate.
  Sets the specified description for this entry
 
  
 +
===Examples===
  
'''memoryrecord_getDescription'''(memoryrecord)
+
====Get the first MemoryRecord====
  Gets the current description of this entry
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList[0]
  
 +
if record ~= nil then
 +
  print(record.Description)
 +
  print(record.Value)
 +
end
 +
</syntaxhighlight>
 +
 +
====Create a simple 4-byte record====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Health"
 +
record.Address = "game.exe+12345"
 +
record.Type = vtDword
 +
record.Value = "1000"
 +
</syntaxhighlight>
 +
 +
====Create a float record====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Speed"
 +
record.Address = "game.exe+23456"
 +
record.Type = vtSingle
 +
record.Value = "1.5"
 +
</syntaxhighlight>
 +
 +
====Create a pointer record with setAddress====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Health Pointer"
 +
record.Type = vtDword
 +
record.setAddress("player_base", {0x10, 0x8, 0x120})
 +
 +
print(string.format("%X", record.CurrentAddress))
 +
</syntaxhighlight>
 +
 +
====Create a pointer record with Offset properties====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Ammo Pointer"
 +
record.Type = vtDword
 +
record.Address = "player_base"
 +
record.OffsetCount = 3
 +
record.Offset[0] = 0x10
 +
record.Offset[1] = 0x8
 +
record.Offset[2] = 0x120
 +
</syntaxhighlight>
 +
 +
====Use OffsetText for interpretable offsets====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Pointer With Text Offsets"
 +
record.Type = vtDword
 +
record.Address = "player_base"
 +
record.OffsetCount = 2
 +
record.OffsetText[0] = "10"
 +
record.OffsetText[1] = "someSymbol+20"
 +
</syntaxhighlight>
 +
 +
====Read the resolved current address====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Player Health")
 +
 +
if record ~= nil then
 +
  local address = record.getCurrentAddress()
 +
 +
  print(string.format("%X", address))
 +
end
 +
</syntaxhighlight>
 +
 +
====Activate and deactivate a record====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Player Health")
 +
 +
if record ~= nil then
 +
  record.Active = true
 +
  sleep(1000)
 +
  record.Active = false
 +
end
 +
</syntaxhighlight>
 +
 +
====Disable without executing the disable section====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Infinite Ammo")
 +
 +
if record ~= nil then
 +
  record.disableWithoutExecute()
 +
end
 +
</syntaxhighlight>
 +
 +
====Show a value as hexadecimal====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Flags"
 +
record.Address = "game.exe+4000"
 +
record.Type = vtDword
 +
record.ShowAsHex = true
 +
</syntaxhighlight>
 +
 +
====Use a string MemoryRecord====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Name"
 +
record.Type = vtString
 +
record.Address = "player_name"
 +
record.String.Size = 32
 +
record.String.Unicode = true
 +
</syntaxhighlight>
 +
 +
====Use a binary MemoryRecord====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Player Flags"
 +
record.Type = vtBinary
 +
record.Address = "game.exe+5000"
 +
record.Binary.Startbit = 2
 +
record.Binary.Size = 4
 +
</syntaxhighlight>
 +
 +
====Use an array-of-bytes MemoryRecord====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Instruction Bytes"
 +
record.Type = vtByteArray
 +
record.Address = "game.exe+6000"
 +
record.Aob.Size = 16
 +
record.ShowAsHex = true
 +
</syntaxhighlight>
 +
 +
====Use a dropdown list====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Game State"
 +
record.Type = vtByte
 +
record.Address = "game_state"
 +
 +
record.DropDownList.Text = [[0:Menu
 +
1:Playing
 +
2:Paused
 +
3:Game Over]]
 +
 +
record.DropDownReadOnly = true
 +
record.DropDownDescriptionOnly = true
 +
record.DisplayAsDropDownListItem = true
 +
</syntaxhighlight>
 +
 +
====Read dropdown values====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Game State")
 +
 +
if record ~= nil then
 +
  for i = 0, record.DropDownCount - 1 do
 +
    print(record.DropDownValue[i] .. " = " .. record.DropDownDescription[i])
 +
  end
 +
end
 +
</syntaxhighlight>
 +
 +
====Link a dropdown list to another record====
 +
<syntaxhighlight lang="lua" line>
 +
local source = AddressList.createMemoryRecord()
 +
source.Description = "Shared States"
 +
source.DropDownList.Text = [[0:Disabled
 +
1:Enabled]]
 +
 +
local target = AddressList.createMemoryRecord()
 +
target.Description = "Current State"
 +
target.Type = vtByte
 +
target.Address = "state_value"
 +
target.DropDownLinked = true
 +
target.DropDownLinkedMemrec = "Shared States"
 +
target.DisplayAsDropDownListItem = true
 +
</syntaxhighlight>
 +
 +
====Create a group header====
 +
<syntaxhighlight lang="lua" line>
 +
local group = AddressList.createMemoryRecord()
 +
 +
group.Description = "Player Stats"
 +
group.IsGroupHeader = true
 +
group.Options = "[moHideChildren]"
 +
</syntaxhighlight>
 +
 +
====Append records as children====
 +
<syntaxhighlight lang="lua" line>
 +
local group = AddressList.createMemoryRecord()
 +
group.Description = "Player Stats"
 +
group.IsGroupHeader = true
 +
 +
local health = AddressList.createMemoryRecord()
 +
health.Description = "Health"
 +
health.Type = vtDword
 +
health.Address = "player_base+10"
 +
health.appendToEntry(group)
 +
 +
local ammo = AddressList.createMemoryRecord()
 +
ammo.Description = "Ammo"
 +
ammo.Type = vtDword
 +
ammo.Address = "player_base+14"
 +
ammo.appendToEntry(group)
 +
</syntaxhighlight>
 +
 +
====Iterate through child records====
 +
<syntaxhighlight lang="lua" line>
 +
local group = AddressList.getMemoryRecordByDescription("Player Stats")
 +
 +
if group ~= nil then
 +
  for i = 0, group.Count - 1 do
 +
    local child = group.Child[i]
 +
 +
    print(child.Description .. " = " .. child.Value)
 +
  end
 +
end
 +
</syntaxhighlight>
 +
 +
====Use parent and child accessors====
 +
<syntaxhighlight lang="lua" line>
 +
local child = AddressList.getMemoryRecordByDescription("Health")
 +
 +
if child ~= nil and child.Parent ~= nil then
 +
  print("Parent: " .. child.Parent.Description)
 +
end
 +
</syntaxhighlight>
  
'''memoryrecord_getAddress'''(memoryrecord)
+
====Create an Auto Assembler script record====
  Returns the address and optional offsets for a pointer (note that in 64-bit kernelmode addresses will be rounded down...)
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
  
 +
record.Description = "Infinite Ammo"
 +
record.Type = vtAutoAssembler
 +
record.Script = [[
 +
[ENABLE]
 +
alloc(newmem,1024)
  
'''memoryrecord_setAddress'''(memoryrecord,address,offsets OPTIONAL) 
+
newmem:
   Sets the address of a entry. You can give as many offsets as you need
+
   ret
  
 +
[DISABLE]
 +
dealloc(newmem)
 +
]]
 +
</syntaxhighlight>
  
'''memoryrecord_getType'''(memoryrecord) 
+
====Activate an Auto Assembler script and check failure====
  Returns the Variable type. (vtByte to vtCustom)
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Infinite Ammo")
  
 +
if record ~= nil then
 +
  record.Active = true
  
'''memoryrecord_setType'''(memoryrecord, vartype)
+
  if record.LastAAExecutionFailed then
   Sets the type of the entry
+
    print(record.LastAAExecutionFailedReason)
 +
   end
 +
end
 +
</syntaxhighlight>
  
 +
====Use asynchronous activation====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Slow Script")
  
'''memoryrecord_getValue'''(memoryrecord)
+
if record ~= nil then
   Returns the current value of the cheat table entry as a string
+
   record.Async = true
 +
  record.Active = true
  
 +
  while record.AsyncProcessing do
 +
    print("Processing for " .. tostring(record.AsyncProcessingTime) .. " ms")
 +
    sleep(100)
 +
  end
 +
end
 +
</syntaxhighlight>
  
'''memoryrecord_setValue'''(memoryrecord, value)  
+
====Create a hotkey====
  Sets the value of a cheat table entry
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("God Mode")
  
 +
if record ~= nil then
 +
  local hotkey = record.createHotkey({VK_F1}, mrhToggleActivation, "", "Toggle God Mode")
  
'''memoryrecord_getScript'''(memoryrecord)
+
  print(hotkey.Description)
  If the entry is of type vtAutoAssembler then you can get the script with this routine
+
end
 +
</syntaxhighlight>
  
 +
====Create a hotkey that sets a value====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Health")
  
'''memoryrecord_setScript'''(memoryrecord, script)
+
if record ~= nil then
 +
  record.createHotkey({VK_CONTROL, VK_F2}, mrhSetValue, "100", "Set health to 100")
 +
end
 +
</syntaxhighlight>
  
 +
====List hotkeys====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("God Mode")
  
'''memoryrecord_isActive'''(memoryrecord)
+
if record ~= nil then
 +
  for i = 0, record.HotkeyCount - 1 do
 +
    local hotkey = record.Hotkey[i]
  
 +
    print(hotkey.ID .. ": " .. hotkey.Description)
 +
  end
 +
end
 +
</syntaxhighlight>
  
'''memoryrecord_freeze'''(memoryrecord, updownfreeze OPTIONAL)
+
====Use beginEdit and endEdit====
  Sets the entry to frozen state. updownfreeze is optional. 0=freeze, 1=allow increase, 2=allow decrease
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList[0]
  
 +
if record ~= nil then
 +
  record.beginEdit()
  
'''memoryrecord_unfreeze'''(memoryrecord)
+
  record.Description = "Edited Record"
   Unfreezes an entry
+
  record.Address = "game.exe+7777"
 +
  record.Type = vtQword
 +
   record.ShowAsHex = true
  
 +
  record.endEdit()
 +
end
 +
</syntaxhighlight>
  
'''memoryrecord_setColor'''(memoryrecord, colorrgb)  
+
====Handle activation====
  Sets the color of the entry
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("God Mode")
  
 +
if record ~= nil then
 +
  record.OnActivate = function(memrec, before, currentstate)
 +
    if before then
 +
      print("About to activate: " .. memrec.Description)
 +
      return true
 +
    end
  
'''memoryrecord_appendToEntry'''(memoryrecord,memoryrecord)
+
    print("Activated: " .. memrec.Description)
   Adds the entry to another entry
+
    return true
 +
   end
 +
end
 +
</syntaxhighlight>
  
 +
====Block activation====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Dangerous Script")
  
'''memoryrecord_delete'''(memoryrecord)
+
if record ~= nil then
   It's unknown what this function does, all that is known is that after using this command other memrec routines with this table entry value don't work anymore...
+
   record.OnActivate = function(memrec, before, currentstate)
 +
    if before then
 +
      print("Activation blocked")
 +
      return false
 +
    end
  
 +
    return true
 +
  end
 +
end
 +
</syntaxhighlight>
  
'''memoryrecord_onActivate'''(memoryrecord, function)
+
====Handle deactivation====
  Registers a function to be called when a cheat entry is Activated
+
<syntaxhighlight lang="lua" line>
    function (memoryrecord, before, currentstate) boolean
+
local record = AddressList.getMemoryRecordByDescription("God Mode")
    If before is true returning false will cause the activation to stop
 
  
 +
if record ~= nil then
 +
  record.OnDeactivate = function(memrec, before, currentstate)
 +
    if before then
 +
      print("About to deactivate: " .. memrec.Description)
 +
      return true
 +
    end
  
'''memoryrecord_onDeactivate'''(memoryrecord, function)
+
    print("Deactivated: " .. memrec.Description)
   Registers a function to be called when a cheat entry is Deactivated
+
    return true
    function (memoryrecord, before, currentstate) boolean
+
   end
    If before is true returning false will cause the deactivation to stop
+
end
 +
</syntaxhighlight>
  
 +
====Override the displayed value====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Health")
  
'''memoryrecord_onDestroy'''(memoryrecord, function)  
+
if record ~= nil then
   Registers a function to be called when a cheat entry is delete
+
  record.OnGetDisplayValue = function(memrec, valuestring)
    function (memoryrecord)
+
    return true, valuestring .. " HP"
 +
   end
 +
end
 +
</syntaxhighlight>
 +
 
 +
====Handle value changes====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Health")
  
 +
if record ~= nil then
 +
  record.OnValueChanged = function(memrec, oldvalue, newvalue)
 +
    print(memrec.Description .. " changed from " .. oldvalue .. " to " .. newvalue)
 +
  end
 +
end
 +
</syntaxhighlight>
  
 +
====Handle user value changes====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Health")
  
Example:
+
if record ~= nil then
<pre>
+
  record.OnValueChangedByUser = function(memrec, oldvalue, newvalue)
addresslist = getAddressList()
+
    print("User changed " .. memrec.Description .. " from " .. oldvalue .. " to " .. newvalue)
description1= [[Health]]
+
  end
description2= [[Health Pointer]]
+
end
memoryrec1 = addresslist_getMemoryRecordByDescription(addresslist, description1)
+
</syntaxhighlight>
memoryrec2 = addresslist_getMemoryRecordByDescription(addresslist, description2)
 
  
desc = memoryrecord_getDescription(memoryrec1)    --Gets the current memroyrecord's description
+
====Handle destroy====
print(desc)
+
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.getMemoryRecordByDescription("Temporary Record")
  
memoryrecord_setDescription(memoryrec1, [[My new health description]]) --sets the memorydescription
+
if record ~= nil then
 +
  record.OnDestroy = function()
 +
    print("MemoryRecord destroyed")
 +
  end
  
 +
  record.destroy()
 +
end
 +
</syntaxhighlight>
  
value = memoryrecord_getValue(memoryrec2)   --Gets the current value of the memory record.
+
====Use global pre/post execute events====
print(value)
+
<syntaxhighlight lang="lua" line>
 +
function onMemRecPreExecute(memoryrecord, newstate)
 +
  print("Before execution: " .. memoryrecord.Description .. " -> " .. tostring(newstate))
  
newvalue = 66
+
  return true
memoryrecord_setValue(memoryrec2, newvalue)  --sets value for the memoryrecord
+
end
  
if memoryrecord_isActive(memoryrecord) then   --Checks if memoryrecord is in frozen state or not
+
function onMemRecPostExecute(memoryrecord, newstate, succeeded)
else
+
   print("After execution: " .. memoryrecord.Description)
memoryrecord_freeze(memoryrec2) -- freezes the memoryrecord, to unfreeze use memoryrecord_freeze
+
  print("New state: " .. tostring(newstate))
 +
  print("Succeeded: " .. tostring(succeeded))
 
end
 
end
 +
</syntaxhighlight>
 +
 +
====Do not save a record====
 +
<syntaxhighlight lang="lua" line>
 +
local record = AddressList.createMemoryRecord()
 +
 +
record.Description = "Temporary Runtime Record"
 +
record.Address = "game.exe+1234"
 +
record.Type = vtDword
 +
record.DontSave = true
 +
</syntaxhighlight>
  
memoryrecord_setColor(memoryrec2,0x0000FF)  --Sets the color of the memoryrecord. Here Red. Color range {0x000000 to 0xFFFFFF)
+
{{LuaSeeAlso}}
  
count = memoryrecord_getHotkeyCount(memoryrec2)  --Gets number of hotkeys associated with memoryrecord
+
{{Forms}}
print(count)                                    --From the image, We can see it is 2.   
 
</pre>[[Image:Image.png|frame|CheatEngine Encyclopedia]]
 
[[Image:Hotkey.png|frame|CheatEngine Encyclopedia]]
 

Latest revision as of 18:48, 25 June 2026

{} Class

class MemoryRecord : Object

The MemoryRecord class represents an entry in Cheat Engine's Addresslist.

A memory record can represent a normal address, a pointer, an Auto Assembler script, a Lua script entry, a group header, or another cheat table entry. MemoryRecord objects expose properties for address handling, value display, activation, child records, dropdown lists, hotkeys, and event callbacks.

Inheritance[edit]

Class Inherits From Description
MemoryRecord Object Represents one entry in the Cheat Engine address list.

Properties[edit]

Property Type Description
ID Integer Unique ID of the memory record.
Index Integer The index of this record in the address list. 0 is the top entry. Read-only.
Description String The description of the memory record.
Address String Gets or sets the interpretable address string. This is useful for simple address settings and can contain symbols, module offsets, or expressions.
AddressString String The address string shown in Cheat Engine. Read-only.
OffsetCount Integer The number of offsets. Set this to 0 for a normal non-pointer address.
Offset[index] Integer Array-style access to each pointer offset.
OffsetText[index] String Array-style access to each pointer offset using interpretable text.
CurrentAddress Integer The resolved address the memory record points to.
VarType String The variable type of this record as a string.
Type ValueType The variable type of this record as a numeric ValueType constant.
CustomTypeName String If the type is vtCustom, this contains the name of the custom type.
Script String If the type is vtAutoAssembler, this contains the Auto Assembler script.
Value String The value in string form.
NumericalValue Number The value in numerical form, or nil if it cannot be parsed as a number.
Selected Boolean True if this record is selected. Read-only.
Active Boolean Set to true to activate or freeze the record. Set to false to deactivate or unfreeze it.
Color Integer The display color of the memory record.
ShowAsHex Boolean If true, the value is shown as hexadecimal.
ShowAsSigned Boolean If true, the value is shown as signed.
AllowIncrease Boolean Allows the value to increase while frozen. Unfreezing resets this to false.
AllowDecrease Boolean Allows the value to decrease while frozen. Unfreezing resets this to false.
Collapsed Boolean Set to true to collapse this record or false to expand it. Use expand/collapse methods for recursive operations where available.
IsGroupHeader Boolean Set to true if the record was created as a group header with no address or value information.
IsAddressGroupHeader Boolean Set to true if the record was created as a group header with an address.
IsReadable Boolean Set to false if the record contains an unreadable address. Read-only. This is only updated after the Value property has been accessed at least once.
Options String set A string enclosed by square brackets containing comma-separated options. See MemoryRecord Options.
DropDownLinked Boolean True if the dropdown list refers to the dropdown list of another memory record.
DropDownLinkedMemrec String Description of the linked memory record, or an empty string if no record is linked.
DropDownList Stringlist List of "value:description" lines used for dropdown display.
DropDownReadOnly Boolean True if manual user input is disallowed.
DropDownDescriptionOnly Boolean If true, only the dropdown description is displayed.
DisplayAsDropDownListItem Boolean If true, the value is displayed as a dropdown list item.
DropDownCount Integer Equivalent to DropDownList.Count. Read-only.
DropDownValue[index] String Array-style access to dropdown values. Read-only.
DropDownDescription[index] String Array-style access to dropdown descriptions. Read-only.
Count Integer The number of child records.
Child[index] MemoryRecord Array-style access to child records.
[index] MemoryRecord Default accessor for child records.
Parent MemoryRecord The parent memory record.
HotkeyCount Integer The number of hotkeys attached to this memory record.
Hotkey[index] MemoryRecordHotkey Array-style access to hotkeys attached to this memory record.
Async Boolean Set to true if activating this entry should be asynchronous. This only applies to Auto Assembler or Lua script records.
AsyncProcessing Boolean True when Async is true and the record is currently being processed.
AsyncProcessingTime Qword The time in milliseconds that the record has been processing asynchronously.
HasMouseOver Boolean True if the mouse is currently over this memory record.
DontSave Boolean If true, this memory record and its children will not be saved.

Type-Specific Properties[edit]

Record Type Property Description
vtString String.Size The number of characters in the string.
vtString String.Unicode If true, the string is treated as Unicode.
vtString String.Codepage If true, the string uses codepage handling.
vtBinary Binary.Startbit The first bit to start reading from.
vtBinary Binary.Size The number of bits.
vtByteArray Aob.Size The number of bytes in the byte array.

Events[edit]

Event Callback Description
OnActivate function(memoryrecord, before, currentstate): boolean Called when the memory record will change or has changed Active to true. If before is true, not returning true stops activation.
OnDeactivate function(memoryrecord, before, currentstate): boolean Called when the memory record will change or has changed Active to false. If before is true, not returning true stops deactivation.
OnDestroy function() Called when the memory record is destroyed.
OnGetDisplayValue function(memoryrecord, valuestring): boolean, string Called when rendering the value of a memory record. Return true and a string to override the displayed value.
OnValueChanged function(memoryrecord, oldvalue, newvalue) Called whenever the value of a memory record has changed.
OnValueChangedByUser function(memoryrecord, oldvalue, newvalue) Called whenever the value of a memory record has been changed by the user.

Methods[edit]

Method Return Type Description
getDescription() String Returns the description of the memory record.
setDescription(description) void Sets the description of the memory record.
getAddress() String, Table Returns the interpretable address string. If it is a pointer, it returns a second result containing a table with the offsets.
setAddress(address) void Sets the interpretable address string.
setAddress(address, offsets) void Sets the interpretable address string and pointer offsets.
getOffsetCount() Integer Returns the number of offsets for this memory record.
setOffsetCount(count) void Sets the number of offsets.
getOffset(index) Integer Returns the offset at the given index.
setOffset(index, value) void Sets the offset at the given index.
getCurrentAddress() Integer Returns the current resolved address as an integer.
appendToEntry(memrec) void Appends this memory record to the given memory record as a child.
getHotkey(index) MemoryRecordHotkey Returns the hotkey at the given index.
getHotkeyByID(id) MemoryRecordHotkey Returns the hotkey with the given ID.
reinterpret() void Reinterprets the memory record.
createHotkey(keys, action, value, description) MemoryRecordHotkey Creates a hotkey object for this memory record.
disableWithoutExecute() void Disables the entry without executing its disable section.
beginEdit() void Call this before a long edit sequence. This prevents the record from being deleted while editing.
endEdit() void Marks the end of a long edit sequence started with beginEdit().

Value Types[edit]

Constant Value Description
vtByte 0 1-byte integer.
vtWord 1 2-byte integer.
vtDword 2 4-byte integer.
vtQword 3 8-byte integer.
vtSingle 4 Single-precision float.
vtDouble 5 Double-precision float.
vtString 6 String.
vtUnicodeString 7 Unicode string.
vtByteArray 8 Array of bytes.
vtBinary 9 Binary bitfield.
vtAll 10 All value types.
vtAutoAssembler 11 Auto Assembler script.
vtPointer 12 Pointer type.
vtCustom 13 Custom type.
vtGrouped 14 Grouped type.
vtByteArrays 15 Multiple byte arrays.
vtCodePageString 16 Codepage string.

MemoryRecord Options[edit]

Option Description
moHideChildren Hides the child records of this memory record.
moActivateChildrenAsWell Activating this record also activates its children.
moDeactivateChildrenAsWell Deactivating this record also deactivates its children.
moRecursiveSetValue Setting the value also sets the value of all children recursively.
moAllowManualCollapseAndExpand Allows the user to manually collapse and expand this record.
moManualExpandCollapse Enables manual expand/collapse behavior.
moAlwaysHideChildren Always hides the child records.

Hotkey Actions[edit]

Constant Value Description
mrhToggleActivation 0 Toggles the active state of the memory record.
mrhToggleActivationAllowIncrease 1 Toggles activation and allows the value to increase while frozen.
mrhToggleActivationAllowDecrease 2 Toggles activation and allows the value to decrease while frozen.
mrhActivate 3 Activates the memory record.
mrhDeactivate 4 Deactivates the memory record.
mrhSetValue 5 Sets the memory record to the specified value.
mrhIncreaseValue 6 Increases the current value by the specified amount.
mrhDecreaseValue 7 Decreases the current value by the specified amount.

Global Events[edit]

<> Lua API Reference

function onMemRecPreExecute(memoryrecord, newstate) : boolean

If defined, this function is called before a memory record action is performed. The Active property is about to change to newstate.

<> Lua API Reference

function onMemRecPostExecute(memoryrecord, newstate, succeeded) : void

If defined, this function is called after a memory record action has been performed. If succeeded is true, the Active state changed to newstate.

Examples[edit]

Get the first MemoryRecord[edit]

1 local record = AddressList[0]
2 
3 if record ~= nil then
4   print(record.Description)
5   print(record.Value)
6 end

Create a simple 4-byte record[edit]

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

Create a float record[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Player Speed"
4 record.Address = "game.exe+23456"
5 record.Type = vtSingle
6 record.Value = "1.5"

Create a pointer record with setAddress[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Player Health Pointer"
4 record.Type = vtDword
5 record.setAddress("player_base", {0x10, 0x8, 0x120})
6 
7 print(string.format("%X", record.CurrentAddress))

Create a pointer record with Offset properties[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Player Ammo Pointer"
4 record.Type = vtDword
5 record.Address = "player_base"
6 record.OffsetCount = 3
7 record.Offset[0] = 0x10
8 record.Offset[1] = 0x8
9 record.Offset[2] = 0x120

Use OffsetText for interpretable offsets[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Pointer With Text Offsets"
4 record.Type = vtDword
5 record.Address = "player_base"
6 record.OffsetCount = 2
7 record.OffsetText[0] = "10"
8 record.OffsetText[1] = "someSymbol+20"

Read the resolved current address[edit]

1 local record = AddressList.getMemoryRecordByDescription("Player Health")
2 
3 if record ~= nil then
4   local address = record.getCurrentAddress()
5 
6   print(string.format("%X", address))
7 end

Activate and deactivate a record[edit]

1 local record = AddressList.getMemoryRecordByDescription("Player Health")
2 
3 if record ~= nil then
4   record.Active = true
5   sleep(1000)
6   record.Active = false
7 end

Disable without executing the disable section[edit]

1 local record = AddressList.getMemoryRecordByDescription("Infinite Ammo")
2 
3 if record ~= nil then
4   record.disableWithoutExecute()
5 end

Show a value as hexadecimal[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Flags"
4 record.Address = "game.exe+4000"
5 record.Type = vtDword
6 record.ShowAsHex = true

Use a string MemoryRecord[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Player Name"
4 record.Type = vtString
5 record.Address = "player_name"
6 record.String.Size = 32
7 record.String.Unicode = true

Use a binary MemoryRecord[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Player Flags"
4 record.Type = vtBinary
5 record.Address = "game.exe+5000"
6 record.Binary.Startbit = 2
7 record.Binary.Size = 4

Use an array-of-bytes MemoryRecord[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Instruction Bytes"
4 record.Type = vtByteArray
5 record.Address = "game.exe+6000"
6 record.Aob.Size = 16
7 record.ShowAsHex = true

Use a dropdown list[edit]

 1 local record = AddressList.createMemoryRecord()
 2 
 3 record.Description = "Game State"
 4 record.Type = vtByte
 5 record.Address = "game_state"
 6 
 7 record.DropDownList.Text = [[0:Menu
 8 1:Playing
 9 2:Paused
10 3:Game Over]]
11 
12 record.DropDownReadOnly = true
13 record.DropDownDescriptionOnly = true
14 record.DisplayAsDropDownListItem = true

Read dropdown values[edit]

1 local record = AddressList.getMemoryRecordByDescription("Game State")
2 
3 if record ~= nil then
4   for i = 0, record.DropDownCount - 1 do
5     print(record.DropDownValue[i] .. " = " .. record.DropDownDescription[i])
6   end
7 end

Link a dropdown list to another record[edit]

 1 local source = AddressList.createMemoryRecord()
 2 source.Description = "Shared States"
 3 source.DropDownList.Text = [[0:Disabled
 4 1:Enabled]]
 5 
 6 local target = AddressList.createMemoryRecord()
 7 target.Description = "Current State"
 8 target.Type = vtByte
 9 target.Address = "state_value"
10 target.DropDownLinked = true
11 target.DropDownLinkedMemrec = "Shared States"
12 target.DisplayAsDropDownListItem = true

Create a group header[edit]

1 local group = AddressList.createMemoryRecord()
2 
3 group.Description = "Player Stats"
4 group.IsGroupHeader = true
5 group.Options = "[moHideChildren]"

Append records as children[edit]

 1 local group = AddressList.createMemoryRecord()
 2 group.Description = "Player Stats"
 3 group.IsGroupHeader = true
 4 
 5 local health = AddressList.createMemoryRecord()
 6 health.Description = "Health"
 7 health.Type = vtDword
 8 health.Address = "player_base+10"
 9 health.appendToEntry(group)
10 
11 local ammo = AddressList.createMemoryRecord()
12 ammo.Description = "Ammo"
13 ammo.Type = vtDword
14 ammo.Address = "player_base+14"
15 ammo.appendToEntry(group)

Iterate through child records[edit]

1 local group = AddressList.getMemoryRecordByDescription("Player Stats")
2 
3 if group ~= nil then
4   for i = 0, group.Count - 1 do
5     local child = group.Child[i]
6 
7     print(child.Description .. " = " .. child.Value)
8   end
9 end

Use parent and child accessors[edit]

1 local child = AddressList.getMemoryRecordByDescription("Health")
2 
3 if child ~= nil and child.Parent ~= nil then
4   print("Parent: " .. child.Parent.Description)
5 end

Create an Auto Assembler script record[edit]

 1 local record = AddressList.createMemoryRecord()
 2 
 3 record.Description = "Infinite Ammo"
 4 record.Type = vtAutoAssembler
 5 record.Script = [[
 6 [ENABLE]
 7 alloc(newmem,1024)
 8 
 9 newmem:
10   ret
11 
12 [DISABLE]
13 dealloc(newmem)
14 ]]

Activate an Auto Assembler script and check failure[edit]

1 local record = AddressList.getMemoryRecordByDescription("Infinite Ammo")
2 
3 if record ~= nil then
4   record.Active = true
5 
6   if record.LastAAExecutionFailed then
7     print(record.LastAAExecutionFailedReason)
8   end
9 end

Use asynchronous activation[edit]

 1 local record = AddressList.getMemoryRecordByDescription("Slow Script")
 2 
 3 if record ~= nil then
 4   record.Async = true
 5   record.Active = true
 6 
 7   while record.AsyncProcessing do
 8     print("Processing for " .. tostring(record.AsyncProcessingTime) .. " ms")
 9     sleep(100)
10   end
11 end

Create a hotkey[edit]

1 local record = AddressList.getMemoryRecordByDescription("God Mode")
2 
3 if record ~= nil then
4   local hotkey = record.createHotkey({VK_F1}, mrhToggleActivation, "", "Toggle God Mode")
5 
6   print(hotkey.Description)
7 end

Create a hotkey that sets a value[edit]

1 local record = AddressList.getMemoryRecordByDescription("Health")
2 
3 if record ~= nil then
4   record.createHotkey({VK_CONTROL, VK_F2}, mrhSetValue, "100", "Set health to 100")
5 end

List hotkeys[edit]

1 local record = AddressList.getMemoryRecordByDescription("God Mode")
2 
3 if record ~= nil then
4   for i = 0, record.HotkeyCount - 1 do
5     local hotkey = record.Hotkey[i]
6 
7     print(hotkey.ID .. ": " .. hotkey.Description)
8   end
9 end

Use beginEdit and endEdit[edit]

 1 local record = AddressList[0]
 2 
 3 if record ~= nil then
 4   record.beginEdit()
 5 
 6   record.Description = "Edited Record"
 7   record.Address = "game.exe+7777"
 8   record.Type = vtQword
 9   record.ShowAsHex = true
10 
11   record.endEdit()
12 end

Handle activation[edit]

 1 local record = AddressList.getMemoryRecordByDescription("God Mode")
 2 
 3 if record ~= nil then
 4   record.OnActivate = function(memrec, before, currentstate)
 5     if before then
 6       print("About to activate: " .. memrec.Description)
 7       return true
 8     end
 9 
10     print("Activated: " .. memrec.Description)
11     return true
12   end
13 end

Block activation[edit]

 1 local record = AddressList.getMemoryRecordByDescription("Dangerous Script")
 2 
 3 if record ~= nil then
 4   record.OnActivate = function(memrec, before, currentstate)
 5     if before then
 6       print("Activation blocked")
 7       return false
 8     end
 9 
10     return true
11   end
12 end

Handle deactivation[edit]

 1 local record = AddressList.getMemoryRecordByDescription("God Mode")
 2 
 3 if record ~= nil then
 4   record.OnDeactivate = function(memrec, before, currentstate)
 5     if before then
 6       print("About to deactivate: " .. memrec.Description)
 7       return true
 8     end
 9 
10     print("Deactivated: " .. memrec.Description)
11     return true
12   end
13 end

Override the displayed value[edit]

1 local record = AddressList.getMemoryRecordByDescription("Health")
2 
3 if record ~= nil then
4   record.OnGetDisplayValue = function(memrec, valuestring)
5     return true, valuestring .. " HP"
6   end
7 end

Handle value changes[edit]

1 local record = AddressList.getMemoryRecordByDescription("Health")
2 
3 if record ~= nil then
4   record.OnValueChanged = function(memrec, oldvalue, newvalue)
5     print(memrec.Description .. " changed from " .. oldvalue .. " to " .. newvalue)
6   end
7 end

Handle user value changes[edit]

1 local record = AddressList.getMemoryRecordByDescription("Health")
2 
3 if record ~= nil then
4   record.OnValueChangedByUser = function(memrec, oldvalue, newvalue)
5     print("User changed " .. memrec.Description .. " from " .. oldvalue .. " to " .. newvalue)
6   end
7 end

Handle destroy[edit]

1 local record = AddressList.getMemoryRecordByDescription("Temporary Record")
2 
3 if record ~= nil then
4   record.OnDestroy = function()
5     print("MemoryRecord destroyed")
6   end
7 
8   record.destroy()
9 end

Use global pre/post execute events[edit]

 1 function onMemRecPreExecute(memoryrecord, newstate)
 2   print("Before execution: " .. memoryrecord.Description .. " -> " .. tostring(newstate))
 3 
 4   return true
 5 end
 6 
 7 function onMemRecPostExecute(memoryrecord, newstate, succeeded)
 8   print("After execution: " .. memoryrecord.Description)
 9   print("New state: " .. tostring(newstate))
10   print("Succeeded: " .. tostring(succeeded))
11 end

Do not save a record[edit]

1 local record = AddressList.createMemoryRecord()
2 
3 record.Description = "Temporary Runtime Record"
4 record.Address = "game.exe+1234"
5 record.Type = vtDword
6 record.DontSave = true

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Form Related Classes