Difference between revisions of "Lua:readBytes"

From Cheat Engine
Jump to navigation Jump to search
m
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The address list is the place where all the addresses will go that you think are usable.
+
[[Category:Lua]]
 +
'''function''' readBytes(''Address'', ''ByteCount'', [''ReturnAsTable''])
  
The list can be navigated by using the keyboard and mouse. There are 2 ways to change a value in the list, by either double-clicking the value, or by selecting it and pressing enter. For all the other items in the list just double click on it and it will open up a new window allowing you to change it.
+
Reads bytes from the specified address in the currently opened (target) process. 
 +
Returns the bytes as multiple return values or as a table if ''ReturnAsTable'' is true.
  
The check boxes allow you to freeze and unfreeze the address. If you freeze a address the address will not change until you unfreeze it. The value does change but Cheat Engine will restore the value to it's frozen state every few milliseconds (The number of milliseconds can be changed in the settings window).
+
===Function Parameters===
  
There are 3 types of freezing: Normal ('''='''), Allow Increase Only ('''+'''), and Allow Decrease Only ('''-'''). You can change the type of freezing by clicking on the symbol right of the check box. The allow positive and negative can be set also by keyboard's numeric '''+''' and '''-''' keys.
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
+
!align="left"|Parameter
Also, when you right-click on one or more addresses a pop-up window will show with additional options.
+
!align="left"|Type
* Delete this record: Remove the selected values, pointers or scripts from the table.
+
!style="width: 80%;background-color:white;" align="left"|Description
* Change record: Change the description, address, type and value for the selected records.
 
* Browse this memory region: Open the memory viewer and jump to the address in the hex view.
 
* Show as hexadecimal/show as decimal: Display the selected records in hexadecimal or in decimal again.
 
* Change color: Change the color of the selected records.
 
* Set/Change hotkeys: Set or change a hotkey to freeze or change a value in any way or to toggle a script on/off. Hotkeys are saved with your table.
 
* Toggle selected entries: Freeze/unfreeze selected addresses and toggle scripts on/off.
 
* Change script: Edit the selected script.
 
* Pointer scan for this address: Open the pointer scanner to search for pointers.
 
* Find out what accesses this address: Use the debugger to show codes that are accessing to the address.
 
* Find out what writes to this address: Use the debugger to show codes that are writing to the address.
 
* Recalculate new addresses: Recalculated the addresses according to the given parameters.
 
* Force recheck symbols: Recheck symbols in the table.
 
* Cut, Copy, Paste: Using the clipboard.
 
* Create Header: Create Headers to organize your records in groups.
 
 
 
 
 
The following keys can be used when the address list has focus:
 
{|cellpadding="10%" cellpadding="5%" cellspacing="0" border="solid"
 
!align="left"|Key(s)
 
!style="width: 80%" align="left"|Description
 
|-
 
|Enter
 
|Change Value
 
|-
 
|Ctrl+Enter
 
|Change Description
 
|-
 
|Ctrl+Alt+Enter
 
|Change Address
 
|-
 
|Alt+Enter
 
|Change Type
 
|-
 
|Shift+Ctrl+Alt+Enter
 
|Change address Complex
 
|-
 
|Space
 
|Freeze or Enable / Disable script
 
|-
 
|Grey Keypad Plus
 
|Freeze but allow increase
 
 
|-
 
|-
|Grey Keypad Minus
+
|Address
|Freeze but allow decrease
+
|Integer or [[CEAddressString]]
 +
|The address in the target process to read from.
 
|-
 
|-
|Delete
+
|ByteCount
|Delete Address
+
|Integer
|-
+
|The number of bytes to read.
|Ctrl+Alt+A
 
|Open the auto assembler
 
 
|-
 
|-
 +
|ReturnAsTable
 +
|Boolean (optional)
 +
|If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.
 
|}
 
|}
  
 +
===Examples===
 +
<pre>
 +
-- Read 4 bytes and get them as separate values
 +
local b1, b2, b3, b4 = readBytes(0x123456, 4)
 +
print(b1, b2, b3, b4)
  
You can make additions to the list either by adding them from the [[Help_File:Found_address_list|found address list]] or by clicking the.
+
-- Read 4 bytes and get them as a table
'Add address manually' button. Here you type the exact address, a description for it and it's datatype.
+
local bytes = readBytes(0x123456, 4, true)
You can also opt to create a pointer-path here on this same dialog.
+
for i, v in ipairs(bytes) do
 
+
  print("Byte " .. i .. ": " .. v)
 
+
end
As of Cheat Engine 6 you can re-arrange items in the list by dragging them and even attach entries to other entries as well
+
</pre>
 
 
 
 
You can use the address list to change values of memory records.
 
There are a few special values you can enter that have a special effect.
 
If you enclose a value by parenthesis '''( )'''  and the value is the name of an address list entries description, the new value will be that of that specific address list entry.
 
 
 
 
 
Example:
 
 
 
You have two entries. One named "Health" and the other named "Max Health" with the value 100
 
If you change the value of Health to "(Max Health)" Health will get the value 100
 
 
 
 
 
Tip: If you first freeze a record and then set the value to "(Max Health)" cheat engine will constantly write the current value of "Max Health" to "Health"
 
 
 
 
 
Another special notation that the change value field supports is enclosing the new value by square brackets '''&#91; &#93;'''
 
The value between the backets will be calculated by lua as if it would do a "return &lt;valuebetweenbrackets&gt;"
 
For example &#91;10+12&#93; would return 22, but you can also do more advanced scripting like &#91;readInteger(12345678)*2&#93;
 
 
 
== Links ==
 
* [[Cheat Engine:Help File|Help File]]
 
  
* [[Help_File:Found_address_list|Back]]
+
{{LuaSeeAlso}}
  
* [[Help_File:Table_Extras|Next]]
+
=== Related Functions ===
 +
{{ReadWriteMemory}}

Latest revision as of 16:01, 11 July 2025

function readBytes(Address, ByteCount, [ReturnAsTable])

Reads bytes from the specified address in the currently opened (target) process. Returns the bytes as multiple return values or as a table if ReturnAsTable is true.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in the target process to read from.
ByteCount Integer The number of bytes to read.
ReturnAsTable Boolean (optional) If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.

Examples[edit]

-- Read 4 bytes and get them as separate values
local b1, b2, b3, b4 = readBytes(0x123456, 4)
print(b1, b2, b3, b4)

-- Read 4 bytes and get them as a table
local bytes = readBytes(0x123456, 4, true)
for i, v in ipairs(bytes) do
  print("Byte " .. i .. ": " .. v)
end

See also[edit]

Related Functions[edit]