Difference between revisions of "Lua:process"

From Cheat Engine
Jump to navigation Jump to search
m (Reverted edits by This content is not available (Talk) to last revision by TheyCallMeTim13)
(Major overhaul of the post.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''global variable''' process
+
{{CodeBox|'''variable''' process ''':''' string}}
  
'''type''' (nil, string)
+
Contains the main module name of the currently opened process.
  
A variable that contains the main module name of the currently opened process
+
===Value===
 +
String — The main module name of the currently opened process.
  
 +
If no process is opened, this variable may be empty or not point to a readable module base.
  
== Examples ==
+
===Examples===
When '''not attached''' to any process:
 
  
Code:
+
====Print the current process module name====
print(type(process))
+
<syntaxhighlight lang="lua" line highlight="1">
print(process)
+
print(process)
print('Attached to ' .. (process or 'NOTHING'))
+
</syntaxhighlight>
if process then
 
  print('attached')
 
else
 
  print('Not Attached')
 
end
 
Output:
 
nil
 
&nbsp;
 
Attached to NOTHING
 
Not Attached
 
  
With the same code as above and '''attached''' to the '''''Cheat Engine Tutorial (64-Bit)''''':
+
====Check whether Cheat Engine is attached====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local attached = readInteger(process) ~= nil
  
Output:
+
print("Attached: " .. tostring(attached))
string
+
</syntaxhighlight>
Tutorial-x86_64.exe
 
Attached to Tutorial-x86_64.exe
 
attached
 
  
Note: If attached, and the attached process closes the "process" variable will still contain the last attached process' main module name. But "readInteger(process)" can be used.
+
====Use process as a module base====
if process ~= nil and readInteger(process) ~= nil then
+
<syntaxhighlight lang="lua" line highlight="1">
  print('Attached to ' .. process)
+
local base = getAddress(process)
end
 
  
 +
print(string.format("%X", base))
 +
</syntaxhighlight>
  
== See also ==
+
====Resolve an address relative to the main module====
* [[Lua]]
+
<syntaxhighlight lang="lua" line highlight="1">
* [[Help_File:Script_engine|Script engine]]
+
local address = getAddress(process .. "+1234")
  
=== Related Variables ===
+
print(string.format("%X", address))
* [[Lua:dbk_NtOpenProcess|dbk_NtOpenProcess]]
+
</syntaxhighlight>
* [[Lua:TrainerOrigin|TrainerOrigin]]
 
  
=== Related Functions ===
+
====Read a value relative to the main module====
* [[Lua:getProcesslist|getProcesslist]]
+
<syntaxhighlight lang="lua" line highlight="1">
* [[Lua:getOpenedProcessID|getOpenedProcessID]]
+
local value = readInteger(process .. "+1234")
* [[Lua:getProcessIDFromProcessName|getProcessIDFromProcessName]]
+
 
* [[Lua:openProcess|openProcess]]
+
print(value)
* [[Lua:getForegroundProcess|getForegroundProcess]]
+
</syntaxhighlight>
* [[Lua:getWindowProcessID|getWindowProcessID]]
+
 
* [[Lua:createProcess|createProcess]]
+
====Guard code until a process is attached====
* [[Lua:debugProcess|debugProcess]]
+
<syntaxhighlight lang="lua" line highlight="1">
* [[Lua:dbk_useKernelmodeOpenProcess|dbk_useKernelmodeOpenProcess]]
+
if readInteger(process) == nil then
* [[Lua:dbk_useKernelmodeProcessMemoryAccess|dbk_useKernelmodeProcessMemoryAccess]]
+
  print("No readable process module is currently opened")
* [[Lua:dbk_getPEProcess|dbk_getPEProcess]]
+
  return
 +
end
 +
 
 +
print("Attached to: " .. process)
 +
</syntaxhighlight>
 +
 
 +
====Use process with auto assembler scripts====
 +
<syntaxhighlight lang="lua" line highlight="1,4">
 +
local script = process .. [[+1234:
 +
  nop
 +
]]
 +
 
 +
autoAssemble(script)
 +
</syntaxhighlight>
 +
 
 +
====Compare process with a target name====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
if process == "game.exe" then
 +
  print("The target process is open")
 +
end
 +
</syntaxhighlight>
 +
 
 +
{{LuaSeeAlso}}

Latest revision as of 20:24, 25 June 2026

<> Lua API Reference

variable process : string

Contains the main module name of the currently opened process.

Value[edit]

String — The main module name of the currently opened process.

If no process is opened, this variable may be empty or not point to a readable module base.

Examples[edit]

Print the current process module name[edit]

1 print(process)

Check whether Cheat Engine is attached[edit]

1 local attached = readInteger(process) ~= nil
2 
3 print("Attached: " .. tostring(attached))

Use process as a module base[edit]

1 local base = getAddress(process)
2 
3 print(string.format("%X", base))

Resolve an address relative to the main module[edit]

1 local address = getAddress(process .. "+1234")
2 
3 print(string.format("%X", address))

Read a value relative to the main module[edit]

1 local value = readInteger(process .. "+1234")
2 
3 print(value)

Guard code until a process is attached[edit]

1 if readInteger(process) == nil then
2   print("No readable process module is currently opened")
3   return
4 end
5 
6 print("Attached to: " .. process)

Use process with auto assembler scripts[edit]

1 local script = process .. [[+1234:
2   nop
3 ]]
4 
5 autoAssemble(script)

Compare process with a target name[edit]

1 if process == "game.exe" then
2   print("The target process is open")
3 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine