Difference between revisions of "Lua:readStringLocal"

From Cheat Engine
Jump to navigation Jump to search
m (Syntax Highlighting.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' readStringLocal(''Address'', ''Maxlength'', ''isWideString'') ''':''' string
+
{{CodeBox|'''function''' readStringLocal(''Address'', ''MaxLength'', [''WideChar'']) ''':''' String}}
  
Reads the bytes at the given address, in Cheat Engine's memory, and interprets them as a string.
+
Reads a string from the specified address in Cheat Engine's own process memory (not the target process) until a 0-terminator is encountered.
 
+
The maximum number of characters to read is limited by ''MaxLength'' to prevent freezing. 
Note: The bytes read are from the Cheat Engine process instead of the targeted process.
+
Set ''WideChar'' to true if the string is encoded using widechar (UTF-16/Unicode) formatting.
  
 
===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 13:
 
|-
 
|-
 
|Address
 
|Address
|[[CEAddressString]] or Integer
+
|Integer or [[CEAddressString]]
|The address to read
+
|The address in Cheat Engine's memory to read from.
 
|-
 
|-
|Maxlength
+
|MaxLength
 
|Integer
 
|Integer
|The maximum number of characters to read. If the string does not have a 0-terminator this will be the length of the string returned
+
|The maximum number of characters to read (prevents infinite loops).
 
|-
 
|-
|isWideString
+
|WideChar
|Boolean
+
|Boolean (optional)
|Determines if this string is read out as a widestring or a normal ascii string
+
|Set to true to read as a widechar (UTF-16/Unicode) string. Default is false (ASCII/ANSI).
 
|}
 
|}
  
 +
===Returns===
 +
String — The string read from the specified address.
 +
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
-- Read an ASCII string from address 0x123456 in CE's memory, up to 100 characters
 +
local str = readStringLocal(0x123456, 100)
 +
print("String:", str)
 +
 +
-- Read a widechar (Unicode) string from a CEAddressString
 +
local wstr = readStringLocal("00400000+10", 256, true)
 +
print("Wide string:", wstr)
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{RelatedStrings}}
* [[ansiToUtf8]]
+
 
* [[utf8ToAnsi]]
+
{{ReadWriteMemory}}
* [[translate]]
 
* [[readBytes]]
 
* [[readInteger]]
 
* [[readQword]]
 
* [[readPointer]]
 
* [[readFloat]]
 
* [[readDouble]]
 
* [[readString]]
 
* [[writeBytes]]
 
* [[writeInteger]]
 
* [[writeQword]]
 
* [[writeFloat]]
 
* [[writeDouble]]
 
* [[writeString]]
 
* [[readBytesLocal]]
 
* [[readIntegerLocal]]
 
* [[readQwordLocal]]
 
* [[readPointerLocal]]
 
* [[readFloatLocal]]
 
* [[readDoubleLocal]]
 
* [[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:41, 25 June 2026

<> Lua API Reference

function readStringLocal(Address, MaxLength, [WideChar]) : String

Reads a string from the specified address in Cheat Engine's own process memory (not the target process) until a 0-terminator is encountered. The maximum number of characters to read is limited by MaxLength to prevent freezing. Set WideChar to true if the string is encoded using widechar (UTF-16/Unicode) formatting.

Function Parameters[edit]

Parameter Type Description
Address Integer or CEAddressString The address in Cheat Engine's memory to read from.
MaxLength Integer The maximum number of characters to read (prevents infinite loops).
WideChar Boolean (optional) Set to true to read as a widechar (UTF-16/Unicode) string. Default is false (ASCII/ANSI).

Returns[edit]

String — The string read from the specified address.

Examples[edit]

1 -- Read an ASCII string from address 0x123456 in CE's memory, up to 100 characters
2 local str = readStringLocal(0x123456, 100)
3 print("String:", str)
4 
5 -- Read a widechar (Unicode) string from a CEAddressString
6 local wstr = readStringLocal("00400000+10", 256, true)
7 print("Wide string:", wstr)

Main Pages

Core Lua documentation entry points

Lua
Script Engine

String Related Lua Functions

Encoding conversion and localized text helpers