Difference between revisions of "Lua:readBytesLocal"

From Cheat Engine
Jump to navigation Jump to search
m (Syntax Highlighting.)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' readBytesLocal(''Address'', ''Bytecount'', ''ReturnAsTable'' ) ''':''' (byte, ...) '''-''' table
+
{{CodeBox|'''function''' readBytesLocal(''Address'', ''ByteCount'', [''ReturnAsTable''])}}
  
Returns the bytes at the given address, in Cheat Engine's memory.
+
Reads bytes from the specified address in Cheat Engine's own process memory (not the target process).
 
+
Returns the bytes as multiple return values or as a table if ''ReturnAsTable'' is true.
Note: The bytes read are from the Cheat Engine process instead of the targeted process.
 
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 13: Line 12:
 
|-
 
|-
 
|Address
 
|Address
|[[CEAddressString]] or Integer
+
|Integer or [[CEAddressString]]
|The address to read
+
|The address in Cheat Engine's memory to read from.
 
|-
 
|-
|Bytecount
+
|ByteCount
 
|Integer
 
|Integer
|The number of bytes to read
+
|The number of bytes to read.
 
|-
 
|-
 
|ReturnAsTable
 
|ReturnAsTable
|Boolean
+
|Boolean (optional)
|Returns a table object instead of multiple return values
+
|If true, returns a table of bytes. If false or omitted, returns each byte as a separate return value.
 
|}
 
|}
  
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
-- Read 4 bytes and get them as separate values
 +
local b1, b2, b3, b4 = readBytesLocal(0x123456, 4)
 +
print(b1, b2, b3, b4)
 +
 +
-- Read 4 bytes and get them as a table
 +
local bytes = readBytesLocal(0x123456, 4, true)
 +
for i, v in ipairs(bytes) do
 +
  print("Byte " .. i .. ": " .. v)
 +
end
 +
</syntaxhighlight>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua]]
 
* [[Help_File:Script engine|Script engine]]
 
  
=== Related Functions ===
+
{{ReadWriteMemory}}
* [[readBytes]]
 
* [[readInteger]]
 
* [[readQword]]
 
* [[readPointer]]
 
* [[readFloat]]
 
* [[readDouble]]
 
* [[readString]]
 
* [[writeBytes]]
 
* [[writeInteger]]
 
* [[writeQword]]
 
* [[writeFloat]]
 
* [[writeDouble]]
 
* [[writeString]]
 
* [[readIntegerLocal]]
 
* [[readQwordLocal]]
 
* [[readPointerLocal]]
 
* [[readFloatLocal]]
 
* [[readDoubleLocal]]
 
* [[readStringLocal]]
 
* [[writeBytesLocal]]
 
* [[writeIntegerLocal]]
 
* [[writeQwordLocal]]
 
* [[writeFloatLocal]]
 
* [[writeDoubleLocal]]
 
* [[writeStringLocal]]
 
* [[wordToByteTable]]
 
* [[dwordToByteTable]]
 
* [[qwordToByteTable]]
 
* [[floatToByteTable]]
 
* [[doubleToByteTable]]
 
* [[stringToByteTable]]
 
* [[wideStringToByteTable]]
 
* [[byteTableToWord]]
 
* [[byteTableToDword]]
 
* [[byteTableToQword]]
 
* [[byteTableToFloat]]
 
* [[byteTableToDouble]]
 
* [[byteTableToString]]
 
* [[byteTableToWideString]]
 

Latest revision as of 15:39, 25 June 2026

<> Lua API Reference

function readBytesLocal(Address, ByteCount, [ReturnAsTable])

Reads bytes from the specified address in Cheat Engine's own process memory (not the 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 Cheat Engine's memory 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]

1 -- Read 4 bytes and get them as separate values
2 local b1, b2, b3, b4 = readBytesLocal(0x123456, 4)
3 print(b1, b2, b3, b4)
4 
5 -- Read 4 bytes and get them as a table
6 local bytes = readBytesLocal(0x123456, 4, true)
7 for i, v in ipairs(bytes) do
8   print("Byte " .. i .. ": " .. v)
9 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine