Difference between revisions of "Lua:Class:MemoryRecord"

From Cheat Engine
Jump to navigation Jump to search
(Properties)
(Added 15+ properties (CachedAddress, CustomType, DisplayValue, LastAAExecutionFailed, etc.), Variable Types/Hotkey Actions tables, enhanced methods docs, 10+ examples, extensive cross-refs.)
 
(21 intermediate revisions by 8 users not shown)
Line 1: Line 1:
--Under Construction
+
[[Category:Lua]]
 +
'''MemoryRecord''' '''class''': ('''Inheritance''': ''[[Lua:Class:Object|Object]]'')
  
The class MemoryRecord are the entries in Cheat tables. This class is commonly used with [[Addresslist]].
+
The MemoryRecord class represents an entry in the Cheat Engine address list.
 +
Each memory record can represent an address, pointer, script, or group header, and provides access to its properties, children, hotkeys, and events.
  
 +
== Properties ==
 +
{|class="wikitable" style="width:100%"
 +
! Property
 +
! Type
 +
! Description
 +
|-
 +
| ID
 +
| Integer
 +
| Unique ID of the memory record.
 +
|-
 +
| Index
 +
| Integer
 +
| The index of this record in the address list (0 is top, ReadOnly).
 +
|-
 +
| Description
 +
| String
 +
| The description of the memory record.
 +
|-
 +
| Address
 +
| String
 +
| Get/set the interpretable address string. Supports symbols, module+offset notation, and Lua expressions. See [[Lua:getAddress|getAddress]] and [[Lua:getNameFromAddress|getNameFromAddress]].
 +
|-
 +
| AddressString
 +
| String
 +
| The address string shown in CE (ReadOnly).
 +
|-
 +
| OffsetCount
 +
| Integer
 +
| The number of offsets. Set to 0 for a normal address.
 +
|-
 +
| Offset[index]
 +
| Integer
 +
| Array to access each offset by index (0-based).
 +
|-
 +
| OffsetText[index]
 +
| String
 +
| Array to access each offset using interpretable text style (0-based).
 +
|-
 +
| CurrentAddress
 +
| Integer
 +
| The address the memory record points to (ReadOnly). Alias: '''CachedAddress'''. See [[Lua:getAddress|getAddress]] and [[Lua:readInteger|memory reading functions]].
 +
|-
 +
| CachedAddress
 +
| Integer
 +
| The cached/real address value (ReadOnly). Same as '''CurrentAddress'''.
 +
|-
 +
| VarType
 +
| String
 +
| The variable type of this record as a string name (e.g., "vtByte", "vtDword"). See [[#Variable Types|Variable Types]] and [[Lua:VariableType|VariableType]].
 +
|-
 +
| Type
 +
| Integer
 +
| The variable type of this record as an integer constant (0-16). See [[#Variable Types|Variable Types]].
 +
|-
 +
| CustomTypeName
 +
| String
 +
| If the type is vtCustom, this contains the name of the CustomType.
 +
|-
 +
| CustomType
 +
| [[Lua:Class:CustomType|CustomType]]
 +
| If the type is vtCustom, this contains the actual CustomType object (ReadOnly).
 +
|-
 +
| Script
 +
| String
 +
| If the type is vtAutoAssembler, this contains the auto assembler script. See [[Lua:Auto Assembler|Auto Assembler]] and [[Lua:autoAssemble|autoAssemble]].
 +
|-
 +
| Value
 +
| String
 +
| The value in string form. For direct memory access, see [[Lua:readInteger|readInteger]], [[Lua:readFloat|readFloat]], [[Lua:readString|readString]], [[Lua:writeInteger|writeInteger]], etc.
 +
|-
 +
| DisplayValue
 +
| String
 +
| The value as displayed in the address list, formatted according to display settings (ReadOnly).
 +
|-
 +
| NumericalValue
 +
| Number
 +
| The value in numerical form, or '''nil''' if it cannot be parsed.
 +
|-
 +
| Selected
 +
| Boolean
 +
| True if selected (ReadOnly).
 +
|-
 +
| Active
 +
| Boolean
 +
| Set to true to activate/freeze, false to deactivate/unfreeze.
 +
|-
 +
| Color
 +
| Integer
 +
| The color of the memory record.
 +
|-
 +
| ShowAsHex
 +
| Boolean
 +
| Show value as hexadecimal.
 +
|-
 +
| ShowAsSigned
 +
| Boolean
 +
| Show value as signed.
 +
|-
 +
| AllowIncrease
 +
| Boolean
 +
| Allow value increasing; unfreeze resets to false.
 +
|-
 +
| AllowDecrease
 +
| Boolean
 +
| Allow value decreasing; unfreeze resets to false.
 +
|-
 +
| Collapsed
 +
| Boolean
 +
| Set to true to collapse this record, false to expand.
 +
|-
 +
| IsGroupHeader
 +
| Boolean
 +
| True if the record is a group header with no address or value info.
 +
|-
 +
| IsAddressGroupHeader
 +
| Boolean
 +
| True if the record is a group header with address.
 +
|-
 +
| IsReadableAddress
 +
| Boolean
 +
| False if record contains an unreadable address (ReadOnly, set after value is accessed).
 +
|-
 +
| IsReadable
 +
| Boolean
 +
| Alias for '''IsReadableAddress'''. False if record contains an unreadable address (ReadOnly).
 +
|-
 +
| Options
 +
| String set
 +
| A string enclosed by square brackets with options separated by commas (e.g., [moHideChildren,moActivateChildrenAsWell]). See [[#MemoryRecord Options|MemoryRecord Options]].
 +
|-
 +
| DropDownLinked
 +
| Boolean
 +
| True if dropdown list refers to another memory record's list.
 +
|-
 +
| DropDownLinkedMemrec
 +
| String
 +
| Description of linked memory record or empty string if not linked.
 +
|-
 +
| DropDownList
 +
| [[Lua:Class:Stringlist|Stringlist]]
 +
| List of "value:description" lines. Use '''DropDownList.Text''' to set (the stringList field cannot be overwritten directly). See [[Lua:Class:Stringlist|Stringlist]].
 +
|-
 +
| DropDownReadOnly
 +
| Boolean
 +
| True if 'Disallow manual user input' is set.
 +
|-
 +
| DropDownDescriptionOnly
 +
| Boolean
 +
| If true, only the description is shown (not the value).
 +
|-
 +
| DisplayAsDropDownListItem
 +
| Boolean
 +
| If true, the value is displayed as a dropdown list item.
 +
|-
 +
| DropDownCount
 +
| Integer
 +
| Equivalent to '''DropDownList.Count''' (ReadOnly).
 +
|-
 +
| DropDownValue[index]
 +
| String
 +
| Array to access values in DropDownList by index (0-based, ReadOnly).
 +
|-
 +
| DropDownDescription[index]
 +
| String
 +
| Array to access descriptions in DropDownList by index (0-based, ReadOnly).
 +
|-
 +
| Count
 +
| Integer
 +
| Number of child records (ReadOnly).
 +
|-
 +
| Child[index]
 +
| MemoryRecord
 +
| Array to access child records by index (0-based).
 +
|-
 +
| Parent
 +
| MemoryRecord
 +
| The parent of the memory record.
 +
|-
 +
| HotkeyCount
 +
| Integer
 +
| Number of hotkeys attached to this memory record (ReadOnly).
 +
|-
 +
| Hotkey[index]
 +
| [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
| Array to index the hotkeys by index (0-based). See [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]].
 +
|-
 +
| Async
 +
| Boolean
 +
| Set to true if activating this entry will be asynchronous (only for AA/Lua scripts).
 +
|-
 +
| AsyncProcessing
 +
| Boolean
 +
| True when async is true and it's being processed (ReadOnly).
 +
|-
 +
| AsyncProcessingTime
 +
| Qword
 +
| The time that it has been processing in milliseconds (ReadOnly).
 +
|-
 +
| HasMouseOver
 +
| Boolean
 +
| True if the mouse is currently over it (ReadOnly). Alias: '''HasMouseFocus'''.
 +
|-
 +
| HasMouseFocus
 +
| Boolean
 +
| Alias for '''HasMouseOver'''. True if the mouse is currently over it (ReadOnly).
 +
|-
 +
| LastAAExecutionFailed
 +
| Boolean
 +
| True if the last auto assembler script execution failed (ReadOnly).
 +
|-
 +
| LastAAExecutionFailedReason
 +
| String
 +
| Contains the error message if LastAAExecutionFailed is true (ReadOnly).
 +
|-
 +
| ScriptHotKey
 +
| [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
| The hotkey that was used to toggle this script (ReadOnly). Only set when a hotkey activates an auto-assembler script.
 +
|-
 +
| DontSave
 +
| Boolean
 +
| Don't save this memoryrecord and its children.
 +
|-
 +
| OnActivate
 +
| function
 +
| Event callback: '''function(memoryrecord, before):boolean'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|-
 +
| OnDeactivate
 +
| function
 +
| Event callback: '''function(memoryrecord, before):boolean'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|-
 +
| OnDestroy
 +
| function
 +
| Event callback: '''function()'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|-
 +
| OnGetDisplayValue
 +
| function
 +
| Event callback: '''function(memoryrecord, valuestring):boolean,string'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|-
 +
| OnValueChanged
 +
| function
 +
| Event callback: '''function(memoryrecord, oldvalue, newvalue)'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|-
 +
| OnValueChangedByUser
 +
| function
 +
| Event callback: '''function(memoryrecord, oldvalue, newvalue)'''. See [[#Events / Callbacks|Events / Callbacks]].
 +
|}
  
'''MemoryRecord Class'''
+
=== Special Properties by Type ===
  The Memoryrecord class object describes a Cheat Table's Cheat Entry.
 
  
 +
When a MemoryRecord is set to specific variable types, additional properties become available through nested property accessors. These properties configure type-specific behavior.
  
----
+
==== String Type Properties ====
  
 +
When '''VarType''' = '''vtString''', the following properties are available:
  
== Properties ==
+
{|class="wikitable" style="width:85%"
  ID: Integer - Unique ID
+
! Property
  Index: Integer - The index ID for this record. 0 is top. (ReadOnly)
+
! Type
  Description: string- The description of the memory record
+
! Description
  Address: string - Get/set the interpretable address string. Useful for simple address settings.
+
|-
  OffsetCount: integer - The number of offsets. Set to 0 for a normal address
+
| String.Size
  Offset[] : integer - Array to access each offset
+
| Integer
  OffsetText[] : string - Array to access each offset using the interpretable text style
+
| The length of the string in characters (or bytes for non-Unicode). If Unicode is enabled, each character is 2 bytes.
 +
|-
 +
| String.Unicode
 +
| Boolean
 +
| If true, the string is treated as a Unicode (UTF-16) string. If false, it's an ANSI or codepage string. Setting this to true automatically sets Codepage to false.
 +
|-
 +
| String.Codepage
 +
| Boolean
 +
| If true, the string uses the system codepage encoding (Windows codepage). If false, it's treated as standard ANSI. Setting this to true automatically sets Unicode to false.
 +
|}
 +
 
 +
'''Example:'''
 +
<pre>
 +
local mr = AddressList.createMemoryRecord()
 +
mr.Type = vtString
 +
mr.Address = "player_name"
 +
mr.String.Size = 32          -- 32 characters max
 +
mr.String.Unicode = true      -- Use Unicode encoding
 +
-- mr.String.Codepage is now false (mutually exclusive with Unicode)
 +
</pre>
 +
 
 +
==== Binary Type Properties ====
 +
 
 +
When '''VarType''' = '''vtBinary''', the following properties are available for bitfield manipulation:
 +
 
 +
{|class="wikitable" style="width:85%"
 +
! Property
 +
! Type
 +
! Description
 +
|-
 +
| Binary.Startbit
 +
| Integer
 +
| The bit position (0-based) within the byte(s) where the bitfield starts. For example, Startbit=2 means the bitfield begins at bit 2.
 +
|-
 +
| Binary.Size
 +
| Integer
 +
| The number of bits in the bitfield (also called bitlength). For example, Size=4 means a 4-bit field.
 +
|}
 +
 
 +
'''Note:''' The Binary type allows you to read/write specific bits within a memory address. The value is extracted by shifting and masking the underlying bytes.
 +
 
 +
'''Example:'''
 +
<pre>
 +
local flags = AddressList.createMemoryRecord()
 +
flags.Type = vtBinary
 +
flags.Address = "0x00400000"
 +
flags.Binary.Startbit = 3    -- Start at bit 3
 +
flags.Binary.Size = 2        -- Read 2 bits (bits 3-4)
 +
-- This will read bits 3 and 4 from the byte at 0x00400000
 +
-- If the byte is 0b00011000 (0x18), the value will be 0b11 (3)
 +
</pre>
 +
 
 +
==== ByteArray Type Properties ====
  
  CurrentAddress: integer - The address the memoryrecord points to
+
When '''VarType''' = '''vtByteArray''', the following property is available:
  Type: ValueType - The variable type of this record. See vtByte to vtCustom
 
    If the type is vtString then the following properties are available:
 
    String.Size: Number of characters in the string
 
    String.Unicode: boolean
 
  
    If the type is vtBinary then the following properties are available
+
{|class="wikitable" style="width:85%"
      Binary.Startbit: First bit to start reading from
+
! Property
      Binary.Size : Number of bits
+
! Type
 +
! Description
 +
|-
 +
| Aob.Size
 +
| Integer
 +
| The number of bytes in the array. This determines how many bytes are read/written from memory.
 +
|}
  
    If the type is vtByteArray then the following properties are available
+
'''Example:'''
      Aob.Size : Number of bytes
+
<pre>
 +
local signature = AddressList.createMemoryRecord()
 +
signature.Type = vtByteArray
 +
signature.Address = "module+1000"
 +
signature.Aob.Size = 16      -- Read 16 bytes
 +
signature.ShowAsHex = true    -- Display as hex bytes
 +
-- Value might display as: 48 8B 05 12 34 56 78 90 AB CD EF 01 23 45 67 89
 +
</pre>
  
  CustomTypeName: String - If the type is vtCustomType this will contain the name of the CustomType
+
== Variable Types ==
  Script: String - If the type is vtAutoAssembler this will contain the auto assembler script
+
{|class="wikitable" style="width:60%"
  Value: string - The value in stringform.
+
! Constant
  Selected: boolean - Set to true if selected (ReadOnly)
+
! Value
  Active: boolean - Set to true to activate/freeze, false to deactivate/unfreeze
+
! Description
  Color: integer
+
|-
  ShowAsHex: boolean - Self explanatory
+
| vtByte
  ShowAsSigned: boolean - Self explanatory
+
| 0
  AllowIncrease: boolean - Allow value increasing, unfreeze will reset it to false
+
| 1 byte (unsigned)
  AllowDecrease: boolean - Allow value decreasing, unfreeze will reset it to false
+
|-
  Collapsed: boolean - Set to true to collapse this record or false to expand it. Use expand/collapse methods for recursive operations.
+
| vtWord
  IsGroupHeader: boolean - Set to true if the record was created as a Group Header with no address or value info. (ReadOnly)
+
| 1
  IsReadable: boolean - Set to false if record contains an unreadable address. NOTE: This property will not be set until the value property is accessed at least once. (ReadOnly)
+
| 2 bytes (unsigned)
 +
|-
 +
| vtDword
 +
| 2
 +
| 4 bytes (unsigned)
 +
|-
 +
| vtQword
 +
| 3
 +
| 8 bytes (unsigned)
 +
|-
 +
| vtSingle
 +
| 4
 +
| 4 bytes (float)
 +
|-
 +
| vtDouble
 +
| 5
 +
| 8 bytes (double/float)
 +
|-
 +
| vtString
 +
| 6
 +
| String (ASCII)
 +
|-
 +
| vtUnicodeString<br>vtWideString
 +
| 7
 +
| Unicode string (Only used by autoguess)
 +
|-
 +
| vtByteArray
 +
| 8
 +
| Array of bytes
 +
|-
 +
| vtBinary
 +
| 9
 +
| Binary (bitfield)
 +
|-
 +
| vtAll
 +
| 10
 +
| All types (used for scans)
 +
|-
 +
| vtAutoAssembler
 +
| 11
 +
| Auto Assembler script
 +
|-
 +
| vtPointer
 +
| 12
 +
| Pointer (Only used by autoguess and structures)
 +
|-
 +
| vtCustom
 +
| 13
 +
| Custom type
 +
|-
 +
| vtGrouped
 +
| 14
 +
| Grouped type
 +
|-
 +
| vtByteArrays
 +
| 15
 +
| Multiple byte arrays
 +
|-
 +
| vtCodePageString
 +
| 16
 +
| Code page string
 +
|}
  
  Count: Number of children
+
== MemoryRecord Options ==
  Child[index] : Array to access the child records
 
  [index] = Child[index]
 
  
  HotkeyCount: integer - Number of hotkeys attached to this memory record
+
The following options can be set in the '''Options''' property of a MemoryRecord. 
  Hotkey[] : Array to index the hotkeys
+
The value is a string enclosed in square brackets, with options separated by commas (e.g., <code>[moHideChildren,moActivateChildrenAsWell]</code>).
  
  OnActivate: function(memoryrecord,before,currentstate):boolean - The function to call when the memoryrecord will change (or changed) Active to true. If before is true, not returning true will cause the activation to stop.
+
{|class="wikitable" style="width:60%"
  OnDeactivate: function(memoryrecord,before,currentstate):boolean - The function to call when the memoryrecord will change (or changed) Active to false. If before is true, not returning true will cause the deactivation to stop.
+
! Option
  OnDestroy: function() - Called when the memoryrecord is destroyed.
+
! Description
  OnGetDisplayValue: function(memoryrecord,valuestring):boolean,string - This function gets called when rendering the value of a memory record. Return true and a new string to override the value shown
+
|-
  DontSave: boolean - Don't save this memoryrecord and it's children
+
| 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 will also set the value of all children recursively.
 +
|-
 +
| moAllowManualCollapseAndExpand
 +
| Allows the user to manually collapse or expand this record in the address list.
 +
|-
 +
| moManualExpandCollapse
 +
| Enables manual expand/collapse behavior for this record.
 +
|-
 +
| moAlwaysHideChildren
 +
| Always hides the children, regardless of other settings.
 +
|}
  
 
== Methods ==
 
== Methods ==
 +
{|class="wikitable" style="width:100%"
 +
! Method
 +
! Parameters
 +
! Returns
 +
! Description
 +
|-
 +
| getDescription
 +
| None
 +
| String
 +
| Gets the description.
 +
|-
 +
| setDescription
 +
| String
 +
| None
 +
| Sets the description.
 +
|-
 +
| getAddress
 +
| None
 +
| String [, Table]
 +
| Returns the interpretable address string. For pointer records, returns two values: the base address string and a table of offsets (1-indexed).
 +
|-
 +
| setAddress
 +
| String [, Table]
 +
| None
 +
| Sets the interpretable address string. Optional second parameter: offset table (1-indexed) for pointer records.
 +
|-
 +
| getOffsetCount
 +
| None
 +
| Integer
 +
| Returns the number of offsets.
 +
|-
 +
| setOffsetCount
 +
| Integer
 +
| None
 +
| Sets the number of offsets.
 +
|-
 +
| getOffset
 +
| Integer (index)
 +
| Integer
 +
| Gets the offset at the given index (0-based).
 +
|-
 +
| setOffset
 +
| Integer (index), Integer (value)
 +
| None
 +
| Sets the offset at the given index (0-based).
 +
|-
 +
| getCurrentAddress
 +
| None
 +
| Integer
 +
| Returns the current address as an integer.
 +
|-
 +
| appendToEntry
 +
| MemoryRecord
 +
| None
 +
| Appends the current memory record to the given memory record as a child.
 +
|-
 +
| getHotkey
 +
| Integer (index)
 +
| [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
| Returns the hotkey from the hotkey array at the given index (0-based).
 +
|-
 +
| getHotkeyByID
 +
| Integer (id)
 +
| [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
| Returns the hotkey with the given id.
 +
|-
 +
| reinterpret
 +
| None
 +
| None
 +
| Reinterprets the memory record's address.
 +
|-
 +
| createHotkey
 +
| Table (keys), Integer (action), String (value, OPTIONAL), String (description, OPTIONAL)
 +
| [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]]
 +
| Creates a hotkey object and registers it. The '''keys''' table is 1-indexed and contains up to 5 virtual key codes (e.g., {0x70} for F1, {0x11, 0x70} for Ctrl+F1). See [[Lua:Defines|Virtual Key Codes]]. The '''action''' is one of the [[#Hotkey Actions|hotkey action constants]] (0-7). Returns the created and registered hotkey object.
 +
|-
 +
| disableWithoutExecute
 +
| None
 +
| None
 +
| Sets the entry to disabled without executing the disable section (for AA scripts).
 +
|-
 +
| beginEdit
 +
| None
 +
| None
 +
| Call when you wish to take a long time to edit a record. Prevents automatic updates.
 +
|-
 +
| endEdit
 +
| None
 +
| None
 +
| Marks the end of your long edit sequence. Re-enables automatic updates.
 +
|-
 +
| delete
 +
| None
 +
| None
 +
| Deletes this memory record (frees the object).
 +
|}
  
 +
== Hotkey Actions ==
  
'''getID'''()
+
The following constants define the actions a hotkey can perform:
  Returns the unique id of this memory record. Every memory record has an unique id
 
  
 +
{|class="wikitable" style="width:60%"
 +
! Constant
 +
! Value
 +
! Description
 +
|-
 +
| mrhToggleActivation
 +
| 0
 +
| Toggle the active state of the memory record.
 +
|-
 +
| mrhToggleActivationAllowIncrease
 +
| 1
 +
| Toggle activation and allow the value to increase while frozen.
 +
|-
 +
| mrhToggleActivationAllowDecrease
 +
| 2
 +
| Toggle activation and allow the value to decrease while frozen.
 +
|-
 +
| mrhActivate
 +
| 3
 +
| Activate (freeze) the memory record.
 +
|-
 +
| mrhDeactivate
 +
| 4
 +
| Deactivate (unfreeze) the memory record.
 +
|-
 +
| mrhSetValue
 +
| 5
 +
| Set the memory record to the specified value.
 +
|-
 +
| mrhIncreaseValue
 +
| 6
 +
| Increase the current value by the specified amount.
 +
|-
 +
| mrhDecreaseValue
 +
| 7
 +
| Decrease the current value by the specified amount.
 +
|}
  
'''getHotkeyCount'''()
+
== Events / Callbacks ==
  Returns the number of hotkeys assigned to this Cheat Entry
+
{|class="wikitable" style="width:100%"
 +
! Event
 +
! Parameters
 +
! Description
 +
|-
 +
| OnActivate
 +
| function(memoryrecord, before):boolean
 +
| Called when the memoryrecord will change (or changed) Active to true. If '''before''' is true, not returning true will cause the activation to stop. The '''before''' parameter indicates if this is called before (true) or after (false) activation.
 +
|-
 +
| OnDeactivate
 +
| function(memoryrecord, before):boolean
 +
| Called when the memoryrecord will change (or changed) Active to false. If '''before''' is true, not returning true will cause the deactivation to stop. The '''before''' parameter indicates if this is called before (true) or after (false) deactivation.
 +
|-
 +
| OnDestroy
 +
| function()
 +
| Called when the memoryrecord is destroyed.
 +
|-
 +
| ~~OnActivationFailure~~
 +
| ~~function(memoryrecord, reason, reasonText)~~
 +
| '''Deprecated/Not Implemented''': This callback was mentioned in older documentation but is not exposed in the Lua API. To detect activation failures, check the '''LastAAExecutionFailed''' property after attempting to activate an auto-assembler script.
 +
|-
 +
| OnGetDisplayValue
 +
| function(memoryrecord, valuestring):boolean,string
 +
| Called when rendering the value of a memory record. The function receives the memoryrecord and current value string. Return true and a modified string to override the displayed value, or false to use the default.
 +
|-
 +
| OnValueChanged
 +
| function(memoryrecord, oldvalue, newvalue)
 +
| Called whenever the value of a memory record has changed. Parameters are the memoryrecord object, old value string, and new value string.
 +
|-
 +
| OnValueChangedByUser
 +
| function(memoryrecord, oldvalue, newvalue)
 +
| Called whenever the value of a memory record has changed by the user (not by the freezer). Parameters are the memoryrecord object, old value string, and new value string.
 +
|}
  
 +
== Global Events ==
  
'''getHotkey'''(index)
+
'''Note:''' These global event functions can be defined in your Lua scripts to monitor all memory record activation/deactivation events globally.
  Returns a memoryrecordhotkey class
 
  
 +
<pre>
 +
function onMemRecPreExecute(memoryrecord, newstate BOOLEAN)
 +
  -- Called before action is performed. Active property is about to change to newState.
 +
  -- Return false to cancel the operation.
 +
end
  
'''getHotkeyByID'''(ID)  
+
function onMemRecPostExecute(memoryrecord, newState BOOLEAN, succeeded BOOLEAN)
   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)
+
   -- Called after action is performed. Active property was supposed to change to newState.
 +
  -- If 'succeeded' is true, Active state has changed and is newState.
 +
end
 +
</pre>
  
 +
== Examples ==
  
'''setDescription'''(description)
+
=== Basic Usage ===
  Sets the specified description for this entry
+
<pre>
 +
-- Get the first memory record in the address list
 +
local mr = AddressList[0]
  
 +
-- Print some basic properties
 +
print("ID:", mr.ID)
 +
print("Description:", mr.Description)
 +
print("Address:", mr.Address)
 +
print("Current Value:", mr.Value)
 +
print("Active:", mr.Active)
  
'''getDescription'''()
+
-- Change the value and activate the record
  Gets the current description of this entry
+
mr.Value = "999"
 +
mr.Active = true
 +
</pre>
  
 +
=== Working with Pointers ===
 +
<pre>
 +
-- Create a pointer-based memory record
 +
local mr = AddressList.createMemoryRecord()
 +
mr.Description = "Player Health"
  
'''getAddress'''()  
+
-- Set as a 4-byte pointer with offsets
  Returns the address and optional offsets for a pointer (note that in 64-bit kernelmode addresses will be rounded down...)
+
mr.Type = vtDword
 +
mr.setAddress("player_base", {0x10, 0x8, 0x120}) -- Base + offsets (1-indexed table)
  
 +
-- Alternative: Set offsets individually
 +
mr.Address = "player_base"
 +
mr.OffsetCount = 3
 +
mr.Offset[0] = 0x10
 +
mr.Offset[1] = 0x8
 +
mr.Offset[2] = 0x120
  
'''setAddress'''(address,offsets OPTIONAL) 
+
-- Or use interpretable offset text
  Sets the address of a entry. You can give as many offsets as you need
+
mr.OffsetText[0] = "10"
 +
mr.OffsetText[1] = "8"
 +
mr.OffsetText[2] = "120"
  
 +
print("Resolved Address:", string.format("%X", mr.CurrentAddress))
 +
</pre>
  
'''getType'''() 
+
=== Using Special Type Properties ===
  Returns the Variable type. (vtByte to vtCustom)
+
<pre>
 +
-- String type
 +
local strRecord = AddressList.createMemoryRecord()
 +
strRecord.Description = "Player Name"
 +
strRecord.Type = vtString
 +
strRecord.Address = "0x00400000"
 +
strRecord.String.Size = 20
 +
strRecord.String.Unicode = false
  
 +
-- Binary type (bitfield)
 +
local bitRecord = AddressList.createMemoryRecord()
 +
bitRecord.Description = "Flags"
 +
bitRecord.Type = vtBinary
 +
bitRecord.Address = "0x00500000"
 +
bitRecord.Binary.Startbit = 2
 +
bitRecord.Binary.Size = 4
  
'''setType'''(vartype)
+
-- Array of Bytes
  Sets the type of the entry
+
local aobRecord = AddressList.createMemoryRecord()
 +
aobRecord.Description = "Byte Array"
 +
aobRecord.Type = vtByteArray
 +
aobRecord.Address = "0x00600000"
 +
aobRecord.Aob.Size = 16
 +
</pre>
  
 +
=== Using Dropdown Lists ===
 +
<pre>
 +
local mr = AddressList.createMemoryRecord()
 +
mr.Description = "Game State"
 +
mr.Type = vtByte
 +
mr.Address = "game_state"
  
'''getValue'''()
+
-- Add dropdown values
  Returns the current value of the cheat table entry as a string
+
mr.DropDownList.Text = [[0:Menu
 +
1:Playing
 +
2:Paused
 +
3:GameOver]]
  
 +
mr.DropDownReadOnly = true
 +
mr.DropDownDescriptionOnly = true
 +
mr.DisplayAsDropDownListItem = true
  
'''setValue'''(value)  
+
-- Access dropdown items
  Sets the value of a cheat table entry
+
for i = 0, mr.DropDownCount - 1 do
 +
  print(mr.DropDownValue[i], ":", mr.DropDownDescription[i])
 +
end
 +
</pre>
  
 +
=== Event Callbacks ===
 +
<pre>
 +
local mr = AddressList.getMemoryRecordByDescription("Player Health")
  
'''getScript'''()
+
-- OnActivate callback (called before/after activation)
   If the entry is of type vtAutoAssembler then you can get the script with this routine
+
mr.OnActivate = function(memrec, before)
 +
   if before then
 +
    print("About to activate:", memrec.Description)
 +
    -- Return false to prevent activation
 +
    return true
 +
  else
 +
    print("Activated:", memrec.Description)
 +
    return true
 +
  end
 +
end
  
 +
-- OnValueChanged callback
 +
mr.OnValueChanged = function(memrec, oldvalue, newvalue)
 +
  print(string.format("%s changed from %s to %s",
 +
    memrec.Description, oldvalue, newvalue))
 +
end
  
'''setScript'''(script)
+
-- OnGetDisplayValue callback (customize display)
 +
mr.OnGetDisplayValue = function(memrec, value)
 +
  local numValue = tonumber(value)
 +
  if numValue then
 +
    return true, string.format("%d HP", numValue)
 +
  end
 +
  return false  -- Use default display
 +
end
 +
</pre>
  
 +
=== Creating Hotkeys ===
 +
<pre>
 +
local mr = AddressList.getMemoryRecordByDescription("God Mode")
  
'''isActive'''()
+
-- Create a hotkey: F1 to toggle
 +
local keys = {0x70}  -- VK_F1 (1-indexed table)
 +
local action = 0    -- mrhToggleActivation
 +
local hotkey = mr.createHotkey(keys, action, "", "Toggle God Mode")
  
 +
print("Hotkey ID:", hotkey.ID)
 +
print("Hotkey String:", hotkey.HotkeyString)  -- e.g., "F1"
 +
print("Owner Description:", hotkey.Owner.Description)
  
'''freeze'''(updownfreeze OPTIONAL)
+
-- Create a hotkey: Ctrl+F2 to set value
  Sets the entry to frozen state. updownfreeze is optional. 0=freeze, 1=allow increase, 2=allow decrease
+
local keys2 = {0x11, 0x71}  -- VK_CONTROL + VK_F2
 +
local action2 = 5          -- mrhSetValue
 +
local hotkey2 = mr.createHotkey(keys2, action2, "100", "Set to 100")
  
 +
-- Access hotkeys by index or ID
 +
print("Hotkey count:", mr.HotkeyCount)
 +
for i = 0, mr.HotkeyCount - 1 do
 +
  local hk = mr.Hotkey[i]
 +
  print(string.format("Hotkey %d: %s - %s", hk.ID, hk.HotkeyString, hk.Description))
 +
end
  
'''unfreeze'''()  
+
-- Get specific hotkey by ID
  Unfreezes an entry
+
local specificHotkey = mr.getHotkeyByID(hotkey.ID)
  
 +
-- Manually trigger a hotkey
 +
hotkey.doHotkey()
 +
</pre>
  
'''setColor'''(colorrgb)  
+
=== Working with Children ===
  Sets the color of the entry
+
<pre>
 +
-- Create a parent group
 +
local parent = AddressList.createMemoryRecord()
 +
parent.Description = "Player Stats"
 +
parent.IsGroupHeader = true
  
 +
-- Create children
 +
local health = AddressList.createMemoryRecord()
 +
health.Description = "Health"
 +
health.Type = vtDword
 +
health.Address = "player_base+10"
 +
health.appendToEntry(parent)
  
'''appendToEntry'''(memoryrecord)
+
local mana = AddressList.createMemoryRecord()
  Adds the entry to another entry
+
mana.Description = "Mana"
 +
mana.Type = vtDword
 +
mana.Address = "player_base+14"
 +
mana.appendToEntry(parent)
  
 +
-- Iterate through children
 +
print("Child count:", parent.Count)
 +
for i = 0, parent.Count - 1 do
 +
  local child = parent.Child[i]
 +
  print("Child:", child.Description, "Value:", child.Value)
 +
end
  
'''delete'''()
+
-- Set options
  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...
+
parent.Options = "[moActivateChildrenAsWell,moDeactivateChildrenAsWell]"
 +
</pre>
  
 +
=== Auto Assembler Scripts ===
 +
<pre>
 +
local script = AddressList.createMemoryRecord()
 +
script.Description = "Infinite Ammo"
 +
script.Type = vtAutoAssembler
 +
script.Script = [[
 +
[ENABLE]
 +
aobscan(ammo_code,FF 0D * * * * 83 C4 08)
 +
alloc(newmem,32)
  
'''onActivate'''(, function)  
+
label(code)
  Registers a function to be called when a cheat entry is Activated
+
label(return)
    function (memoryrecord, before, currentstate) boolean
 
    If before is true returning false will cause the activation to stop
 
  
 +
newmem:
 +
code:
 +
  // Don't decrease ammo
 +
  nop
 +
  nop
 +
  nop
 +
  nop
 +
  nop
 +
  nop
 +
  jmp return
  
'''onDeactivate'''(function)
+
ammo_code:
   Registers a function to be called when a cheat entry is Deactivated
+
   jmp newmem
    function (memoryrecord, before, currentstate) boolean
+
return:
    If before is true returning false will cause the deactivation to stop
+
registersymbol(ammo_code)
  
 +
[DISABLE]
 +
ammo_code:
 +
  db FF 0D * * * * 83 C4 08
 +
unregistersymbol(ammo_code)
 +
dealloc(newmem)
 +
]]
  
'''onDestroy'''(function)
+
-- Activate the script
  Registers a function to be called when a cheat entry is delete
+
script.Active = true
    function (memoryrecord)
 
 
 
  
 +
-- Check if execution failed
 +
if script.LastAAExecutionFailed then
 +
  print("Script failed:", script.LastAAExecutionFailedReason)
 +
end
 +
</pre>
  
Example:
+
=== Async Script Execution ===
 
<pre>
 
<pre>
al = getAddressList()
+
local asyncScript = AddressList.createMemoryRecord()
description1= [[Health]]
+
asyncScript.Description = "Slow Script"
description2= [[Health Pointer]]
+
asyncScript.Type = vtAutoAssembler
memoryrec1 = al.getMemoryRecordByDescription(description1)
+
asyncScript.Async = true  -- Enable async processing
memoryrec2 = al.getMemoryRecordByDescription(description2)
+
asyncScript.Script = [[
 +
[ENABLE]
 +
// ... complex AA script ...
  
desc = memoryrec1.Description    --Gets the current memoryrecord's description
+
[DISABLE]
print(desc)
+
// ... disable code ...
 +
]]
  
memoryrec1.Description=[[My new health description]]  --sets the memorydescription
+
asyncScript.Active = true
  
 +
-- Check processing status
 +
if asyncScript.AsyncProcessing then
 +
  print("Processing... Time:", asyncScript.AsyncProcessingTime, "ms")
 +
end
 +
</pre>
  
value = memoryrec2.Value  --Gets the current value of the memory record.
+
=== Editing Records Efficiently ===
print(value)
+
<pre>
 +
local mr = AddressList[0]
  
newvalue = 66
+
-- Begin edit to prevent updates during batch changes
memoryrec2.Value=newvalue  --sets value for the memoryrecord
+
mr.beginEdit()
  
if memoryrecord.Active then  --Checks if memoryrecord is in frozen state or not
+
mr.Description = "Modified Entry"
else
+
mr.Address = "new_address"
memoryrec2.Active=false  -- freezes the memoryrecord, to unfreeze use memoryrecord_freeze
+
mr.Type = vtQword
end
+
mr.ShowAsHex = true
  
memoryrec2.Color=0x0000ff --Sets the color of the memoryrecord. Here Red. Color range {0x000000 to 0xFFFFFF)
+
-- End edit to re-enable updates
 +
mr.endEdit()
 +
</pre>
  
count = memoryrec2.HotkeyCount --Gets number of hotkeys associated with memoryrecord
+
{{LuaSeeAlso}}
print(count)                                    --From the image, We can see it is 2.   
 
  
----
+
=== Related Functions ===
 +
* [[Lua:getMainForm|getMainForm]] - Get the main Cheat Engine form
 +
* [[Lua:getAddressList|getAddressList]] - Get the address list containing memory records
 +
* [[Lua:readInteger|readInteger]] - Read integer values from memory
 +
* [[Lua:readFloat|readFloat]] - Read float values from memory
 +
* [[Lua:readString|readString]] - Read string values from memory
 +
* [[Lua:writeInteger|writeInteger]] - Write integer values to memory
 +
* [[Lua:writeFloat|writeFloat]] - Write float values to memory
 +
* [[Lua:writeString|writeString]] - Write string values to memory
 +
* [[Lua:AOBScan|AOBScan]] - Scan for array of bytes patterns
 +
* [[Lua:autoAssemble|autoAssemble]] - Execute auto assembler scripts
  
* [[Lua|Lua Functions and Classes]]
+
=== Related Classes ===
 +
* [[Lua:Class:Addresslist|Addresslist]] - The address list that contains memory records
 +
* [[Lua:Class:MemoryRecordHotkey|MemoryRecordHotkey]] - Hotkey objects attached to memory records
 +
* [[Lua:Class:CustomType|CustomType]] - Custom variable type definitions
 +
* [[Lua:Class:Stringlist|Stringlist]] - String list used for dropdown values
 +
* [[Lua:Class:Object|Object]] - Base class for all Lua-exposed objects

Latest revision as of 18:24, 25 October 2025

MemoryRecord class: (Inheritance: Object)

The MemoryRecord class represents an entry in the Cheat Engine address list. Each memory record can represent an address, pointer, script, or group header, and provides access to its properties, children, hotkeys, and events.

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 top, ReadOnly).
Description String The description of the memory record.
Address String Get/set the interpretable address string. Supports symbols, module+offset notation, and Lua expressions. See getAddress and getNameFromAddress.
AddressString String The address string shown in CE (ReadOnly).
OffsetCount Integer The number of offsets. Set to 0 for a normal address.
Offset[index] Integer Array to access each offset by index (0-based).
OffsetText[index] String Array to access each offset using interpretable text style (0-based).
CurrentAddress Integer The address the memory record points to (ReadOnly). Alias: CachedAddress. See getAddress and memory reading functions.
CachedAddress Integer The cached/real address value (ReadOnly). Same as CurrentAddress.
VarType String The variable type of this record as a string name (e.g., "vtByte", "vtDword"). See Variable Types and VariableType.
Type Integer The variable type of this record as an integer constant (0-16). See Variable Types.
CustomTypeName String If the type is vtCustom, this contains the name of the CustomType.
CustomType CustomType If the type is vtCustom, this contains the actual CustomType object (ReadOnly).
Script String If the type is vtAutoAssembler, this contains the auto assembler script. See Auto Assembler and autoAssemble.
Value String The value in string form. For direct memory access, see readInteger, readFloat, readString, writeInteger, etc.
DisplayValue String The value as displayed in the address list, formatted according to display settings (ReadOnly).
NumericalValue Number The value in numerical form, or nil if it cannot be parsed.
Selected Boolean True if selected (ReadOnly).
Active Boolean Set to true to activate/freeze, false to deactivate/unfreeze.
Color Integer The color of the memory record.
ShowAsHex Boolean Show value as hexadecimal.
ShowAsSigned Boolean Show value as signed.
AllowIncrease Boolean Allow value increasing; unfreeze resets to false.
AllowDecrease Boolean Allow value decreasing; unfreeze resets to false.
Collapsed Boolean Set to true to collapse this record, false to expand.
IsGroupHeader Boolean True if the record is a group header with no address or value info.
IsAddressGroupHeader Boolean True if the record is a group header with address.
IsReadableAddress Boolean False if record contains an unreadable address (ReadOnly, set after value is accessed).
IsReadable Boolean Alias for IsReadableAddress. False if record contains an unreadable address (ReadOnly).
Options String set A string enclosed by square brackets with options separated by commas (e.g., [moHideChildren,moActivateChildrenAsWell]). See MemoryRecord Options.
DropDownLinked Boolean True if dropdown list refers to another memory record's list.
DropDownLinkedMemrec String Description of linked memory record or empty string if not linked.
DropDownList Stringlist List of "value:description" lines. Use DropDownList.Text to set (the stringList field cannot be overwritten directly). See Stringlist.
DropDownReadOnly Boolean True if 'Disallow manual user input' is set.
DropDownDescriptionOnly Boolean If true, only the description is shown (not the value).
DisplayAsDropDownListItem Boolean If true, the value is displayed as a dropdown list item.
DropDownCount Integer Equivalent to DropDownList.Count (ReadOnly).
DropDownValue[index] String Array to access values in DropDownList by index (0-based, ReadOnly).
DropDownDescription[index] String Array to access descriptions in DropDownList by index (0-based, ReadOnly).
Count Integer Number of child records (ReadOnly).
Child[index] MemoryRecord Array to access child records by index (0-based).
Parent MemoryRecord The parent of the memory record.
HotkeyCount Integer Number of hotkeys attached to this memory record (ReadOnly).
Hotkey[index] MemoryRecordHotkey Array to index the hotkeys by index (0-based). See MemoryRecordHotkey.
Async Boolean Set to true if activating this entry will be asynchronous (only for AA/Lua scripts).
AsyncProcessing Boolean True when async is true and it's being processed (ReadOnly).
AsyncProcessingTime Qword The time that it has been processing in milliseconds (ReadOnly).
HasMouseOver Boolean True if the mouse is currently over it (ReadOnly). Alias: HasMouseFocus.
HasMouseFocus Boolean Alias for HasMouseOver. True if the mouse is currently over it (ReadOnly).
LastAAExecutionFailed Boolean True if the last auto assembler script execution failed (ReadOnly).
LastAAExecutionFailedReason String Contains the error message if LastAAExecutionFailed is true (ReadOnly).
ScriptHotKey MemoryRecordHotkey The hotkey that was used to toggle this script (ReadOnly). Only set when a hotkey activates an auto-assembler script.
DontSave Boolean Don't save this memoryrecord and its children.
OnActivate function Event callback: function(memoryrecord, before):boolean. See Events / Callbacks.
OnDeactivate function Event callback: function(memoryrecord, before):boolean. See Events / Callbacks.
OnDestroy function Event callback: function(). See Events / Callbacks.
OnGetDisplayValue function Event callback: function(memoryrecord, valuestring):boolean,string. See Events / Callbacks.
OnValueChanged function Event callback: function(memoryrecord, oldvalue, newvalue). See Events / Callbacks.
OnValueChangedByUser function Event callback: function(memoryrecord, oldvalue, newvalue). See Events / Callbacks.

Special Properties by Type[edit]

When a MemoryRecord is set to specific variable types, additional properties become available through nested property accessors. These properties configure type-specific behavior.

String Type Properties[edit]

When VarType = vtString, the following properties are available:

Property Type Description
String.Size Integer The length of the string in characters (or bytes for non-Unicode). If Unicode is enabled, each character is 2 bytes.
String.Unicode Boolean If true, the string is treated as a Unicode (UTF-16) string. If false, it's an ANSI or codepage string. Setting this to true automatically sets Codepage to false.
String.Codepage Boolean If true, the string uses the system codepage encoding (Windows codepage). If false, it's treated as standard ANSI. Setting this to true automatically sets Unicode to false.

Example:

local mr = AddressList.createMemoryRecord()
mr.Type = vtString
mr.Address = "player_name"
mr.String.Size = 32           -- 32 characters max
mr.String.Unicode = true      -- Use Unicode encoding
-- mr.String.Codepage is now false (mutually exclusive with Unicode)

Binary Type Properties[edit]

When VarType = vtBinary, the following properties are available for bitfield manipulation:

Property Type Description
Binary.Startbit Integer The bit position (0-based) within the byte(s) where the bitfield starts. For example, Startbit=2 means the bitfield begins at bit 2.
Binary.Size Integer The number of bits in the bitfield (also called bitlength). For example, Size=4 means a 4-bit field.

Note: The Binary type allows you to read/write specific bits within a memory address. The value is extracted by shifting and masking the underlying bytes.

Example:

local flags = AddressList.createMemoryRecord()
flags.Type = vtBinary
flags.Address = "0x00400000"
flags.Binary.Startbit = 3     -- Start at bit 3
flags.Binary.Size = 2         -- Read 2 bits (bits 3-4)
-- This will read bits 3 and 4 from the byte at 0x00400000
-- If the byte is 0b00011000 (0x18), the value will be 0b11 (3)

ByteArray Type Properties[edit]

When VarType = vtByteArray, the following property is available:

Property Type Description
Aob.Size Integer The number of bytes in the array. This determines how many bytes are read/written from memory.

Example:

local signature = AddressList.createMemoryRecord()
signature.Type = vtByteArray
signature.Address = "module+1000"
signature.Aob.Size = 16       -- Read 16 bytes
signature.ShowAsHex = true    -- Display as hex bytes
-- Value might display as: 48 8B 05 12 34 56 78 90 AB CD EF 01 23 45 67 89

Variable Types[edit]

Constant Value Description
vtByte 0 1 byte (unsigned)
vtWord 1 2 bytes (unsigned)
vtDword 2 4 bytes (unsigned)
vtQword 3 8 bytes (unsigned)
vtSingle 4 4 bytes (float)
vtDouble 5 8 bytes (double/float)
vtString 6 String (ASCII)
vtUnicodeString
vtWideString
7 Unicode string (Only used by autoguess)
vtByteArray 8 Array of bytes
vtBinary 9 Binary (bitfield)
vtAll 10 All types (used for scans)
vtAutoAssembler 11 Auto Assembler script
vtPointer 12 Pointer (Only used by autoguess and structures)
vtCustom 13 Custom type
vtGrouped 14 Grouped type
vtByteArrays 15 Multiple byte arrays
vtCodePageString 16 Code page string

MemoryRecord Options[edit]

The following options can be set in the Options property of a MemoryRecord. The value is a string enclosed in square brackets, with options separated by commas (e.g., [moHideChildren,moActivateChildrenAsWell]).

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 will also set the value of all children recursively.
moAllowManualCollapseAndExpand Allows the user to manually collapse or expand this record in the address list.
moManualExpandCollapse Enables manual expand/collapse behavior for this record.
moAlwaysHideChildren Always hides the children, regardless of other settings.

Methods[edit]

Method Parameters Returns Description
getDescription None String Gets the description.
setDescription String None Sets the description.
getAddress None String [, Table] Returns the interpretable address string. For pointer records, returns two values: the base address string and a table of offsets (1-indexed).
setAddress String [, Table] None Sets the interpretable address string. Optional second parameter: offset table (1-indexed) for pointer records.
getOffsetCount None Integer Returns the number of offsets.
setOffsetCount Integer None Sets the number of offsets.
getOffset Integer (index) Integer Gets the offset at the given index (0-based).
setOffset Integer (index), Integer (value) None Sets the offset at the given index (0-based).
getCurrentAddress None Integer Returns the current address as an integer.
appendToEntry MemoryRecord None Appends the current memory record to the given memory record as a child.
getHotkey Integer (index) MemoryRecordHotkey Returns the hotkey from the hotkey array at the given index (0-based).
getHotkeyByID Integer (id) MemoryRecordHotkey Returns the hotkey with the given id.
reinterpret None None Reinterprets the memory record's address.
createHotkey Table (keys), Integer (action), String (value, OPTIONAL), String (description, OPTIONAL) MemoryRecordHotkey Creates a hotkey object and registers it. The keys table is 1-indexed and contains up to 5 virtual key codes (e.g., {0x70} for F1, {0x11, 0x70} for Ctrl+F1). See Virtual Key Codes. The action is one of the hotkey action constants (0-7). Returns the created and registered hotkey object.
disableWithoutExecute None None Sets the entry to disabled without executing the disable section (for AA scripts).
beginEdit None None Call when you wish to take a long time to edit a record. Prevents automatic updates.
endEdit None None Marks the end of your long edit sequence. Re-enables automatic updates.
delete None None Deletes this memory record (frees the object).

Hotkey Actions[edit]

The following constants define the actions a hotkey can perform:

Constant Value Description
mrhToggleActivation 0 Toggle the active state of the memory record.
mrhToggleActivationAllowIncrease 1 Toggle activation and allow the value to increase while frozen.
mrhToggleActivationAllowDecrease 2 Toggle activation and allow the value to decrease while frozen.
mrhActivate 3 Activate (freeze) the memory record.
mrhDeactivate 4 Deactivate (unfreeze) the memory record.
mrhSetValue 5 Set the memory record to the specified value.
mrhIncreaseValue 6 Increase the current value by the specified amount.
mrhDecreaseValue 7 Decrease the current value by the specified amount.

Events / Callbacks[edit]

Event Parameters Description
OnActivate function(memoryrecord, before):boolean Called when the memoryrecord will change (or changed) Active to true. If before is true, not returning true will cause the activation to stop. The before parameter indicates if this is called before (true) or after (false) activation.
OnDeactivate function(memoryrecord, before):boolean Called when the memoryrecord will change (or changed) Active to false. If before is true, not returning true will cause the deactivation to stop. The before parameter indicates if this is called before (true) or after (false) deactivation.
OnDestroy function() Called when the memoryrecord is destroyed.
~~OnActivationFailure~~ ~~function(memoryrecord, reason, reasonText)~~ Deprecated/Not Implemented: This callback was mentioned in older documentation but is not exposed in the Lua API. To detect activation failures, check the LastAAExecutionFailed property after attempting to activate an auto-assembler script.
OnGetDisplayValue function(memoryrecord, valuestring):boolean,string Called when rendering the value of a memory record. The function receives the memoryrecord and current value string. Return true and a modified string to override the displayed value, or false to use the default.
OnValueChanged function(memoryrecord, oldvalue, newvalue) Called whenever the value of a memory record has changed. Parameters are the memoryrecord object, old value string, and new value string.
OnValueChangedByUser function(memoryrecord, oldvalue, newvalue) Called whenever the value of a memory record has changed by the user (not by the freezer). Parameters are the memoryrecord object, old value string, and new value string.

Global Events[edit]

Note: These global event functions can be defined in your Lua scripts to monitor all memory record activation/deactivation events globally.

function onMemRecPreExecute(memoryrecord, newstate BOOLEAN)
  -- Called before action is performed. Active property is about to change to newState.
  -- Return false to cancel the operation.
end

function onMemRecPostExecute(memoryrecord, newState BOOLEAN, succeeded BOOLEAN)
  -- Called after action is performed. Active property was supposed to change to newState.
  -- If 'succeeded' is true, Active state has changed and is newState.
end

Examples[edit]

Basic Usage[edit]

-- Get the first memory record in the address list
local mr = AddressList[0]

-- Print some basic properties
print("ID:", mr.ID)
print("Description:", mr.Description)
print("Address:", mr.Address)
print("Current Value:", mr.Value)
print("Active:", mr.Active)

-- Change the value and activate the record
mr.Value = "999"
mr.Active = true

Working with Pointers[edit]

-- Create a pointer-based memory record
local mr = AddressList.createMemoryRecord()
mr.Description = "Player Health"

-- Set as a 4-byte pointer with offsets
mr.Type = vtDword
mr.setAddress("player_base", {0x10, 0x8, 0x120})  -- Base + offsets (1-indexed table)

-- Alternative: Set offsets individually
mr.Address = "player_base"
mr.OffsetCount = 3
mr.Offset[0] = 0x10
mr.Offset[1] = 0x8
mr.Offset[2] = 0x120

-- Or use interpretable offset text
mr.OffsetText[0] = "10"
mr.OffsetText[1] = "8"
mr.OffsetText[2] = "120"

print("Resolved Address:", string.format("%X", mr.CurrentAddress))

Using Special Type Properties[edit]

-- String type
local strRecord = AddressList.createMemoryRecord()
strRecord.Description = "Player Name"
strRecord.Type = vtString
strRecord.Address = "0x00400000"
strRecord.String.Size = 20
strRecord.String.Unicode = false

-- Binary type (bitfield)
local bitRecord = AddressList.createMemoryRecord()
bitRecord.Description = "Flags"
bitRecord.Type = vtBinary
bitRecord.Address = "0x00500000"
bitRecord.Binary.Startbit = 2
bitRecord.Binary.Size = 4

-- Array of Bytes
local aobRecord = AddressList.createMemoryRecord()
aobRecord.Description = "Byte Array"
aobRecord.Type = vtByteArray
aobRecord.Address = "0x00600000"
aobRecord.Aob.Size = 16

Using Dropdown Lists[edit]

local mr = AddressList.createMemoryRecord()
mr.Description = "Game State"
mr.Type = vtByte
mr.Address = "game_state"

-- Add dropdown values
mr.DropDownList.Text = [[0:Menu
1:Playing
2:Paused
3:GameOver]]

mr.DropDownReadOnly = true
mr.DropDownDescriptionOnly = true
mr.DisplayAsDropDownListItem = true

-- Access dropdown items
for i = 0, mr.DropDownCount - 1 do
  print(mr.DropDownValue[i], ":", mr.DropDownDescription[i])
end

Event Callbacks[edit]

local mr = AddressList.getMemoryRecordByDescription("Player Health")

-- OnActivate callback (called before/after activation)
mr.OnActivate = function(memrec, before)
  if before then
    print("About to activate:", memrec.Description)
    -- Return false to prevent activation
    return true
  else
    print("Activated:", memrec.Description)
    return true
  end
end

-- OnValueChanged callback
mr.OnValueChanged = function(memrec, oldvalue, newvalue)
  print(string.format("%s changed from %s to %s", 
    memrec.Description, oldvalue, newvalue))
end

-- OnGetDisplayValue callback (customize display)
mr.OnGetDisplayValue = function(memrec, value)
  local numValue = tonumber(value)
  if numValue then
    return true, string.format("%d HP", numValue)
  end
  return false  -- Use default display
end

Creating Hotkeys[edit]

local mr = AddressList.getMemoryRecordByDescription("God Mode")

-- Create a hotkey: F1 to toggle
local keys = {0x70}  -- VK_F1 (1-indexed table)
local action = 0     -- mrhToggleActivation
local hotkey = mr.createHotkey(keys, action, "", "Toggle God Mode")

print("Hotkey ID:", hotkey.ID)
print("Hotkey String:", hotkey.HotkeyString)  -- e.g., "F1"
print("Owner Description:", hotkey.Owner.Description)

-- Create a hotkey: Ctrl+F2 to set value
local keys2 = {0x11, 0x71}  -- VK_CONTROL + VK_F2
local action2 = 5           -- mrhSetValue
local hotkey2 = mr.createHotkey(keys2, action2, "100", "Set to 100")

-- Access hotkeys by index or ID
print("Hotkey count:", mr.HotkeyCount)
for i = 0, mr.HotkeyCount - 1 do
  local hk = mr.Hotkey[i]
  print(string.format("Hotkey %d: %s - %s", hk.ID, hk.HotkeyString, hk.Description))
end

-- Get specific hotkey by ID
local specificHotkey = mr.getHotkeyByID(hotkey.ID)

-- Manually trigger a hotkey
hotkey.doHotkey()

Working with Children[edit]

-- Create a parent group
local parent = AddressList.createMemoryRecord()
parent.Description = "Player Stats"
parent.IsGroupHeader = true

-- Create children
local health = AddressList.createMemoryRecord()
health.Description = "Health"
health.Type = vtDword
health.Address = "player_base+10"
health.appendToEntry(parent)

local mana = AddressList.createMemoryRecord()
mana.Description = "Mana"
mana.Type = vtDword
mana.Address = "player_base+14"
mana.appendToEntry(parent)

-- Iterate through children
print("Child count:", parent.Count)
for i = 0, parent.Count - 1 do
  local child = parent.Child[i]
  print("Child:", child.Description, "Value:", child.Value)
end

-- Set options
parent.Options = "[moActivateChildrenAsWell,moDeactivateChildrenAsWell]"

Auto Assembler Scripts[edit]

local script = AddressList.createMemoryRecord()
script.Description = "Infinite Ammo"
script.Type = vtAutoAssembler
script.Script = [[
[ENABLE]
aobscan(ammo_code,FF 0D * * * * 83 C4 08)
alloc(newmem,32)

label(code)
label(return)

newmem:
code:
  // Don't decrease ammo
  nop
  nop
  nop
  nop
  nop
  nop
  jmp return

ammo_code:
  jmp newmem
return:
registersymbol(ammo_code)

[DISABLE]
ammo_code:
  db FF 0D * * * * 83 C4 08
unregistersymbol(ammo_code)
dealloc(newmem)
]]

-- Activate the script
script.Active = true

-- Check if execution failed
if script.LastAAExecutionFailed then
  print("Script failed:", script.LastAAExecutionFailedReason)
end

Async Script Execution[edit]

local asyncScript = AddressList.createMemoryRecord()
asyncScript.Description = "Slow Script"
asyncScript.Type = vtAutoAssembler
asyncScript.Async = true  -- Enable async processing
asyncScript.Script = [[
[ENABLE]
// ... complex AA script ...

[DISABLE]
// ... disable code ...
]]

asyncScript.Active = true

-- Check processing status
if asyncScript.AsyncProcessing then
  print("Processing... Time:", asyncScript.AsyncProcessingTime, "ms")
end

Editing Records Efficiently[edit]

local mr = AddressList[0]

-- Begin edit to prevent updates during batch changes
mr.beginEdit()

mr.Description = "Modified Entry"
mr.Address = "new_address"
mr.Type = vtQword
mr.ShowAsHex = true

-- End edit to re-enable updates
mr.endEdit()

See also[edit]

Related Functions[edit]

Related Classes[edit]