Lua:Class:MemoryRecord
Jump to navigation
Jump to search
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.
Contents
- 1 Inheritance
- 2 Properties
- 3 Type-Specific Properties
- 4 Events
- 5 Methods
- 6 Value Types
- 7 MemoryRecord Options
- 8 Hotkey Actions
- 9 Global Events
- 10 Examples
- 10.1 Get the first MemoryRecord
- 10.2 Create a simple 4-byte record
- 10.3 Create a float record
- 10.4 Create a pointer record with setAddress
- 10.5 Create a pointer record with Offset properties
- 10.6 Use OffsetText for interpretable offsets
- 10.7 Read the resolved current address
- 10.8 Activate and deactivate a record
- 10.9 Disable without executing the disable section
- 10.10 Show a value as hexadecimal
- 10.11 Use a string MemoryRecord
- 10.12 Use a binary MemoryRecord
- 10.13 Use an array-of-bytes MemoryRecord
- 10.14 Use a dropdown list
- 10.15 Read dropdown values
- 10.16 Link a dropdown list to another record
- 10.17 Create a group header
- 10.18 Append records as children
- 10.19 Iterate through child records
- 10.20 Use parent and child accessors
- 10.21 Create an Auto Assembler script record
- 10.22 Activate an Auto Assembler script and check failure
- 10.23 Use asynchronous activation
- 10.24 Create a hotkey
- 10.25 Create a hotkey that sets a value
- 10.26 List hotkeys
- 10.27 Use beginEdit and endEdit
- 10.28 Handle activation
- 10.29 Block activation
- 10.30 Handle deactivation
- 10.31 Override the displayed value
- 10.32 Handle value changes
- 10.33 Handle user value changes
- 10.34 Handle destroy
- 10.35 Use global pre/post execute events
- 10.36 Do not save a record
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]
If defined, this function is called before a memory record action is performed. The Active property is about to change to newstate.
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