Difference between revisions of "Lua:decodeFunction"

From Cheat Engine
Jump to navigation Jump to search
(Created page with 'Category:Lua '''function''' decodeFunction(''encodedString'') ''':''' function Converts a given string converted by encodeFunction back into function.…')
 
m (Added related function template.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' decodeFunction(''encodedString'') ''':''' function
+
{{CodeBox|'''function''' decodeFunction(''string'') ''':''' function}}
  
Converts a given string converted by [[Lua:encodeFunction|encodeFunction]] back into function.
+
Converts an encoded function string back into a callable Lua function.
 +
 
 +
The encoded string must have been created for the same architecture as the current Cheat Engine process. A 32-bit encoded function can only be loaded by a 32-bit Lua state, and a 64-bit encoded function can only be loaded by a 64-bit Lua state.
  
 
===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
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|encodedString
 
 
|string
 
|string
|The string to decode into a function
+
|String
 +
|The encoded function string created by [[Lua:encodeFunction|encodeFunction]].
 
|}
 
|}
  
== Examples ==
+
===Returns===
<pre><nowiki>
+
Function — The decoded Lua function.
local myCoolFunction = decodeFunction([[c-oWpDNPJ!ketlRCB=/U!NS2(5ypT38s!d+42)bq1T)V$DK]cOh6W(:.:sVD24sPxSl9{RGV?9p8L$BW3{Oh^]])
+
 
myCoolFunction('I have the power!')
+
===Examples===
</nowiki></pre>
+
<syntaxhighlight lang="lua" line>
<pre>
+
local encoded = encodeFunction(function()
local function myCoolFunction(str) print(str) end
+
  print("Hello from a decoded function")
local encodedFunc = encodeFunction(myCoolFunction)
+
end)
local decodedFunc = decodeFunction(encodedFunc)
+
 
decodedFunc('I have the power!')
+
local decoded = decodeFunction(encoded)
</pre>
+
 
 +
decoded()
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local encoded = encodeFunction(function(value)
 +
  return value * 2
 +
end)
 +
 
 +
local decoded = decodeFunction(encoded)
 +
 
 +
print(decoded(21))
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua" line>
 +
local encoded32 = "..." -- encoded on 32-bit Cheat Engine
 +
local encoded64 = "..." -- encoded on 64-bit Cheat Engine
 +
 
 +
local encoded
 +
 
 +
if cheatEngineIs64Bit() then
 +
  encoded = encoded64
 +
else
 +
  encoded = encoded32
 +
end
 +
 
 +
local decoded = decodeFunction(encoded)
 +
 
 +
decoded()
 +
</syntaxhighlight>
 +
 
 +
===Architecture Compatibility===
 +
Encoded functions are architecture-dependent.
 +
 
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Encoded On
 +
!align="left"|Can Be Decoded On
 +
!style="width: 80%;background-color:white;" align="left"|Notes
 +
|-
 +
|32-bit Cheat Engine
 +
|32-bit Cheat Engine
 +
|A 32-bit encoded function can only be decoded in a 32-bit Lua state.
 +
|-
 +
|64-bit Cheat Engine
 +
|64-bit Cheat Engine
 +
|A 64-bit encoded function can only be decoded in a 64-bit Lua state.
 +
|-
 +
|32-bit Cheat Engine
 +
|64-bit Cheat Engine
 +
|Not compatible.
 +
|-
 +
|64-bit Cheat Engine
 +
|32-bit Cheat Engine
 +
|Not compatible.
 +
|}
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{EncodeDecode}}
* [[Lua:encodeFunction|encodeFunction]]
 

Latest revision as of 00:11, 27 June 2026

<> Lua API Reference

function decodeFunction(string) : function

Converts an encoded function string back into a callable Lua function.

The encoded string must have been created for the same architecture as the current Cheat Engine process. A 32-bit encoded function can only be loaded by a 32-bit Lua state, and a 64-bit encoded function can only be loaded by a 64-bit Lua state.

Function Parameters[edit]

Parameter Type Description
string String The encoded function string created by encodeFunction.

Returns[edit]

Function — The decoded Lua function.

Examples[edit]

1 local encoded = encodeFunction(function()
2   print("Hello from a decoded function")
3 end)
4 
5 local decoded = decodeFunction(encoded)
6 
7 decoded()
1 local encoded = encodeFunction(function(value)
2   return value * 2
3 end)
4 
5 local decoded = decodeFunction(encoded)
6 
7 print(decoded(21))
 1 local encoded32 = "..." -- encoded on 32-bit Cheat Engine
 2 local encoded64 = "..." -- encoded on 64-bit Cheat Engine
 3 
 4 local encoded
 5 
 6 if cheatEngineIs64Bit() then
 7   encoded = encoded64
 8 else
 9   encoded = encoded32
10 end
11 
12 local decoded = decodeFunction(encoded)
13 
14 decoded()

Architecture Compatibility[edit]

Encoded functions are architecture-dependent.

Encoded On Can Be Decoded On Notes
32-bit Cheat Engine 32-bit Cheat Engine A 32-bit encoded function can only be decoded in a 32-bit Lua state.
64-bit Cheat Engine 64-bit Cheat Engine A 64-bit encoded function can only be decoded in a 64-bit Lua state.
32-bit Cheat Engine 64-bit Cheat Engine Not compatible.
64-bit Cheat Engine 32-bit Cheat Engine Not compatible.

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Function Encoding Related Lua Functions