Difference between revisions of "Lua:process"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''global variable''' process
+
[[Category:Lua]]
 +
{{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.
  
== Example Usage ==
+
===Examples===
  
 +
====Print the current process module name====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
print(process)
 +
</syntaxhighlight>
  
When '''not attached''' to any process:
+
====Check whether Cheat Engine is attached====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local attached = readInteger(process) ~= nil
  
Code:
+
print("Attached: " .. tostring(attached))
  print(type(process))
+
</syntaxhighlight>
  print(process)
 
  print('Attached to ' .. (process or 'NOTHING'))
 
  if process then
 
    print('attached')
 
  else
 
    print('Not Attached')
 
  end
 
Output:
 
  nil
 
  &nbsp;
 
  Attached to NOTHING
 
  Not Attached
 
  
Note: If attached, and the attached process closes the "process" variable will still contain the last attached process' main module name.
+
====Use process as a module base====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local base = getAddress(process)
  
 +
print(string.format("%X", base))
 +
</syntaxhighlight>
  
With the same code as above and '''attached''' to the '''''Cheat Engine Tutorial (64-Bit)''''':
+
====Resolve an address relative to the main module====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local address = getAddress(process .. "+1234")
  
Output:
+
print(string.format("%X", address))
  string  
+
</syntaxhighlight>
  Tutorial-x86_64.exe
 
  Attached to Tutorial-x86_64.exe
 
  attached
 
  
 +
====Read a value relative to the main module====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local value = readInteger(process .. "+1234")
  
== See also ==
+
print(value)
 +
</syntaxhighlight>
  
* [[Lua]]
+
====Guard code until a process is attached====
* [[Help_File:Script_engine|Script engine]]
+
<syntaxhighlight lang="lua" line highlight="1">
 +
if readInteger(process) == nil then
 +
  print("No readable process module is currently opened")
 +
  return
 +
end
  
=== Related Variables ===
+
print("Attached to: " .. process)
* [[dbk_NtOpenProcess]]
+
</syntaxhighlight>
  
=== Related Functions ===
+
====Use process with auto assembler scripts====
* [[getProcesslist]]
+
<syntaxhighlight lang="lua" line highlight="1,4">
* [[getOpenedProcessID]]
+
local script = process .. [[+1234:
* [[getProcessIDFromProcessName]]
+
  nop
* [[openProcess]]
+
]]
* [[getForegroundProcess]]
+
 
* [[getWindowProcessID]]
+
autoAssemble(script)
* [[createProcess]]
+
</syntaxhighlight>
* [[debugProcess]]
+
 
* [[dbk_useKernelmodeOpenProcess]]
+
====Compare process with a target name====
* [[dbk_useKernelmodeProcessMemoryAccess]]
+
<syntaxhighlight lang="lua" line highlight="1">
* [[dbk_getPEProcess]]
+
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