Difference between revisions of "Lua:executeCodeEx"
(Created page with "<b>executeCodeEx(callmethod, timeout, address, {type=x,value=param1} or param1,{type=x,value=param2} or param2,...)</b> <pre> callmethod: 0=stdcall, 1=cdecl timeout: Numb...") |
|||
| Line 1: | Line 1: | ||
| − | + | [[Category:Lua]] | |
| + | {{NeedWork}} | ||
| + | {{CodeBox|'''function''' executeCodeEx(''callmethod'', ''timeout'', ''address'', ''param1'', ''...'') ''':''' integer or nil}} | ||
| + | |||
| + | Executes code at the specified address. | ||
| + | |||
| + | The ''callmethod'' parameter determines the calling convention. The ''timeout'' parameter determines how long Cheat Engine waits for a result. Function parameters can either be passed directly, in which case Cheat Engine will try to guess the type, or as explicit parameter tables containing a ''type'' and ''value'' field. | ||
| + | |||
| + | If ''timeout'' is 0, Cheat Engine will not wait for a result. In that case, the call memory will not be freed automatically, which can cause a memory leak. | ||
| + | |||
| + | When calling compiled C++ instance methods, keep in mind that the object instance is passed implicitly by the compiler. The instance is not written as a normal argument in the C++ source code, but the compiled function still expects it. On 64-bit Windows, this pointer is commonly passed in RCX, so it must be provided as the first parameter. | ||
| + | |||
| + | For example, a method such as ''CheatManager::Fly'' may need to be called by passing the CheatManager instance as the first argument. '''(Reference provided by SunBeam)''' | ||
| + | |||
| + | ===Function Parameters=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |callmethod | ||
| + | |Integer | ||
| + | |The calling convention to use. 0 uses stdcall, and 1 uses cdecl. | ||
| + | |- | ||
| + | |timeout | ||
| + | |Integer or nil | ||
| + | |The number of milliseconds to wait for a result. nil or -1 waits indefinitely. 0 does not wait for a result. | ||
| + | |- | ||
| + | |address | ||
| + | |Integer or [[CEAddressString]] | ||
| + | |The address to execute. | ||
| + | |- | ||
| + | |param1 | ||
| + | |Any or Table (optional) | ||
| + | |The first parameter to pass to the executed code. This can be a direct value or a table containing a type and value field. | ||
| + | |- | ||
| + | |... | ||
| + | |Any or Table (optional) | ||
| + | |Additional parameters to pass to the executed code. | ||
| + | |} | ||
| + | |||
| + | ===Call Method Values=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Value | ||
| + | !align="left"|Calling Convention | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |0 | ||
| + | |stdcall | ||
| + | |Uses the stdcall calling convention. | ||
| + | |- | ||
| + | |1 | ||
| + | |cdecl | ||
| + | |Uses the cdecl calling convention. | ||
| + | |} | ||
| + | |||
| + | ===Timeout Values=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Value | ||
| + | !align="left"|Meaning | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |nil | ||
| + | |Wait indefinitely | ||
| + | |Waits indefinitely for the executed code to finish. | ||
| + | |- | ||
| + | |-1 | ||
| + | |Wait indefinitely | ||
| + | |Waits indefinitely for the executed code to finish. | ||
| + | |- | ||
| + | |0 | ||
| + | |Do not wait | ||
| + | |Does not wait for a result. The call memory will not be freed automatically, which can cause a memory leak. | ||
| + | |- | ||
| + | |> 0 | ||
| + | |Timed wait | ||
| + | |Waits up to the specified number of milliseconds for a result. | ||
| + | |} | ||
| + | |||
| + | ===Parameter Table Fields=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Field | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |type | ||
| + | |Integer | ||
| + | |The explicit type of the parameter value. | ||
| + | |- | ||
| + | |value | ||
| + | |Any | ||
| + | |The value to pass to the executed code. | ||
| + | |} | ||
| + | |||
| + | ===Parameter Type Values=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Value | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |0 | ||
| + | |Integer or pointer | ||
| + | |A 32-bit or 64-bit integer value. This can also be used for pointers. | ||
| + | |- | ||
| + | |1 | ||
| + | |Float | ||
| + | |A 32-bit floating point value. | ||
| + | |- | ||
| + | |2 | ||
| + | |Double | ||
| + | |A 64-bit floating point value. | ||
| + | |- | ||
| + | |3 | ||
| + | |ASCII string | ||
| + | |An ASCII string. The string will be converted to a pointer to that string. | ||
| + | |- | ||
| + | |4 | ||
| + | |Wide string | ||
| + | |A wide string. The string will be converted to a pointer to that string. | ||
| + | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | integer or nil — The result of the executed code when Cheat Engine waits for completion, or nil when no result is available. | ||
| + | |||
| + | ===Examples=== | ||
<pre> | <pre> | ||
| − | + | local address = getAddress("SomeFunction") | |
| − | + | local result = executeCodeEx( | |
| + | 0, | ||
| + | 1000, | ||
| + | address, | ||
| + | {type = 0, value = 123} | ||
| + | ) | ||
| + | |||
| + | print("Result: " .. tostring(result)) | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | local address = getAddress("SomeFunction") | ||
| − | + | -- Let Cheat Engine guess the parameter types | |
| + | local result = executeCodeEx(0, 1000, address, 123, 456) | ||
| − | + | print("Result: " .. tostring(result)) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</pre> | </pre> | ||
| − | + | <pre> | |
| + | local address = getAddress("SomeFunction") | ||
| + | -- Pass an ASCII string parameter | ||
| + | local result = executeCodeEx( | ||
| + | 0, | ||
| + | 1000, | ||
| + | address, | ||
| + | {type = 3, value = "Hello World"} | ||
| + | ) | ||
| + | |||
| + | print("Result: " .. tostring(result)) | ||
| + | </pre> | ||
| − | |||
<pre> | <pre> | ||
| − | + | local flyAddress = getAddress("CheatManager.Fly") | |
| + | local cheatManagerInstance = getAddress("CheatManagerInstance") | ||
| + | |||
| + | -- Pass the class instance as the first argument | ||
| + | executeCodeEx(0, nil, flyAddress, cheatManagerInstance) | ||
</pre> | </pre> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
Latest revision as of 05:04, 21 June 2026
Executes code at the specified address.
The callmethod parameter determines the calling convention. The timeout parameter determines how long Cheat Engine waits for a result. Function parameters can either be passed directly, in which case Cheat Engine will try to guess the type, or as explicit parameter tables containing a type and value field.
If timeout is 0, Cheat Engine will not wait for a result. In that case, the call memory will not be freed automatically, which can cause a memory leak.
When calling compiled C++ instance methods, keep in mind that the object instance is passed implicitly by the compiler. The instance is not written as a normal argument in the C++ source code, but the compiled function still expects it. On 64-bit Windows, this pointer is commonly passed in RCX, so it must be provided as the first parameter.
For example, a method such as CheatManager::Fly may need to be called by passing the CheatManager instance as the first argument. (Reference provided by SunBeam)
Contents
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| callmethod | Integer | The calling convention to use. 0 uses stdcall, and 1 uses cdecl. |
| timeout | Integer or nil | The number of milliseconds to wait for a result. nil or -1 waits indefinitely. 0 does not wait for a result. |
| address | Integer or CEAddressString | The address to execute. |
| param1 | Any or Table (optional) | The first parameter to pass to the executed code. This can be a direct value or a table containing a type and value field. |
| ... | Any or Table (optional) | Additional parameters to pass to the executed code. |
Call Method Values[edit]
| Value | Calling Convention | Description |
|---|---|---|
| 0 | stdcall | Uses the stdcall calling convention. |
| 1 | cdecl | Uses the cdecl calling convention. |
Timeout Values[edit]
| Value | Meaning | Description |
|---|---|---|
| nil | Wait indefinitely | Waits indefinitely for the executed code to finish. |
| Wait indefinitely | Waits indefinitely for the executed code to finish. | |
| 0 | Do not wait | Does not wait for a result. The call memory will not be freed automatically, which can cause a memory leak. |
| > 0 | Timed wait | Waits up to the specified number of milliseconds for a result. |
Parameter Table Fields[edit]
| Field | Type | Description |
|---|---|---|
| type | Integer | The explicit type of the parameter value. |
| value | Any | The value to pass to the executed code. |
Parameter Type Values[edit]
| Value | Type | Description |
|---|---|---|
| 0 | Integer or pointer | A 32-bit or 64-bit integer value. This can also be used for pointers. |
| 1 | Float | A 32-bit floating point value. |
| 2 | Double | A 64-bit floating point value. |
| 3 | ASCII string | An ASCII string. The string will be converted to a pointer to that string. |
| 4 | Wide string | A wide string. The string will be converted to a pointer to that string. |
Returns[edit]
integer or nil — The result of the executed code when Cheat Engine waits for completion, or nil when no result is available.
Examples[edit]
local address = getAddress("SomeFunction")
local result = executeCodeEx(
0,
1000,
address,
{type = 0, value = 123}
)
print("Result: " .. tostring(result))
local address = getAddress("SomeFunction")
-- Let Cheat Engine guess the parameter types
local result = executeCodeEx(0, 1000, address, 123, 456)
print("Result: " .. tostring(result))
local address = getAddress("SomeFunction")
-- Pass an ASCII string parameter
local result = executeCodeEx(
0,
1000,
address,
{type = 3, value = "Hello World"}
)
print("Result: " .. tostring(result))
local flyAddress = getAddress("CheatManager.Fly")
local cheatManagerInstance = getAddress("CheatManagerInstance")
-- Pass the class instance as the first argument
executeCodeEx(0, nil, flyAddress, cheatManagerInstance)