Difference between revisions of "Mono:Mono Lua"

From Cheat Engine
Jump to navigation Jump to search
m
(Major overhaul of the post.)
 
(15 intermediate revisions by 5 users not shown)
Line 1: Line 1:
The advanced MONO features of Cheat Engine are controlled by the "monoscript.lua" script in the autorun directory where cheat engine is installed.  When you attach to a process, the script scans for "mono.dll".  If it is found, the appropriate MonoDataDissector dll from the autorun directory is injected into the process which creates a named pipe waiting for a connection.  The LUA code then connects to the pipe and messages are exchanged to perform the mono functions.
+
[[Category:Mono]]
 +
[[Category:Help]]
 +
[[Category:Lua]]
 +
{{DISPLAYTITLE:Mono - Lua}}
  
==== Main Methods ====
+
The advanced Mono features of Cheat Engine are controlled by the <code>monoscript.lua</code> script in the <code>autorun</code> directory.
  
; LaunchMonoDataCollector()
+
When Cheat Engine attaches to a process, the script checks for <code>mono.dll</code>. If Mono is detected, the matching <code>MonoDataDissector</code> DLL from the <code>autorun</code> directory is injected into the target process. The injected DLL creates a named pipe, and the Lua side communicates with it to perform Mono-related operations.
: this is some
 
: information
 
  
; varType = monoTypeToVarType(monoType)
+
== Main Methods ==
: Returns the Cheat Engine type (vtString, vtByte, vtWorkd, vtDword, vtSingle, vtDouble, vtPointer) for the given mono type
 
  
; result = LaunchMonoDataCollector()
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: injects the dll and returns 0 for failure, or monoBase returned from the CMD_INITMONO command on the pipe
+
!align="left"|Function
 +
!align="left"|Return Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|LaunchMonoDataCollector()
 +
|Integer
 +
|Injects the Mono data collector DLL. Returns 0 on failure, or the monoBase returned by the CMD_INITMONO pipe command.
 +
|-
 +
|monoTypeToVarType(monoType)
 +
|ValueType
 +
|Returns the Cheat Engine value type for the given Mono type, such as vtString, vtByte, vtWord, vtDword, vtSingle, vtDouble, or vtPointer.
 +
|-
 +
|mono_object_getClass(address)
 +
|Integer, String
 +
|Returns the class ID and class name of the object at the given address.
 +
|-
 +
|mono_enumDomains()
 +
|Table
 +
|Returns a table array containing the domain address of each Mono domain.
 +
|-
 +
|mono_setCurrentDomain(domainId)
 +
|Integer
 +
|Sets the Mono domain used by the MonoDataCollector.
 +
|-
 +
|mono_enumAssemblies()
 +
|Table
 +
|Returns a table containing the assembly IDs for each assembly in the current domain.
 +
|-
 +
|mono_getImageFromAssembly(assemblyId)
 +
|Integer
 +
|Returns the image ID for the given assembly.
 +
|-
 +
|mono_image_get_name(imageId)
 +
|String
 +
|Returns the name of the assembly image.
 +
|-
 +
|mono_image_enumClasses(imageId)
 +
|Table
 +
|Returns a table containing the class IDs for classes in the given assembly image.
 +
|-
 +
|mono_class_getName(classId)
 +
|String
 +
|Returns the class name of the given class.
 +
|-
 +
|mono_class_getNamespace(classId)
 +
|String
 +
|Returns the namespace of the given class.
 +
|-
 +
|mono_class_getParent(classId)
 +
|Integer
 +
|Returns the class ID of the parent class.
 +
|-
 +
|mono_class_getStaticFieldAddress(domainId, classId)
 +
|Integer
 +
|Returns the base address for the static field storage area of the given class in the given domain.
 +
|-
 +
|mono_class_enumFields(classId)
 +
|Table
 +
|Returns a table containing field objects for the given class.
 +
|-
 +
|mono_class_enumMethods(classId)
 +
|Table
 +
|Returns a table containing method objects for the given class.
 +
|-
 +
|mono_getJitInfo(address)
 +
|Table
 +
|Returns JIT information for the code address.
 +
|-
 +
|mono_image_findClass(imageId, namespace, className)
 +
|Integer
 +
|Returns the class ID for the given namespace and class name in the specified image.
 +
|-
 +
|mono_findClass(namespace, className)
 +
|Integer
 +
|Returns the class ID for the given namespace and class name.
 +
|-
 +
|mono_class_findMethod(classId, methodName)
 +
|Integer
 +
|Returns the method ID of the given method in the given class.
 +
|-
 +
|mono_findMethod(namespace, className, methodName)
 +
|Integer
 +
|Returns the method ID for the given namespace, class name, and method name.
 +
|-
 +
|mono_method_getName(methodId)
 +
|String
 +
|Returns the name of the given method.
 +
|-
 +
|mono_method_getHeader(methodId)
 +
|Integer
 +
|Returns the method header ID.
 +
|-
 +
|mono_method_getSignature(methodId)
 +
|String, Table, String
 +
|Returns the signature result, parameter names, and return type of the method.
 +
|-
 +
|mono_method_disassemble(methodId)
 +
|String
 +
|Returns the disassembled IL code for the given method.
 +
|-
 +
|mono_method_getClass(methodId)
 +
|Integer
 +
|Returns the class ID that owns the given method.
 +
|-
 +
|mono_compile_method(methodId)
 +
|Integer
 +
|JIT-compiles the method if needed and returns the native method address.
 +
|-
 +
|mono_free_method(methodId)
 +
|void
 +
|Frees a dynamic method. This only works on dynamic methods and only if the profiler is not being used.
 +
|-
 +
|mono_methodheader_getILCode(methodHeader)
 +
|Integer, Integer
 +
|Returns the IL code address and size for the given method header.
 +
|-
 +
|mono_getILCodeFromMethod(methodId)
 +
|Integer, Integer
 +
|Gets the method header and returns the IL code address and size.
 +
|-
 +
|mono_image_rva_map(imageId, offset)
 +
|Integer
 +
|Maps an image RVA/offset. Exact usage depends on the Mono image context.
 +
|-
 +
|mono_loadAssemblyFromFile(fname)
 +
|Integer
 +
|Loads a C# assembly in the target process.
 +
|-
 +
|mono_invoke_method(domainId, methodId, address, args)
 +
|Variant
 +
|Invokes a Mono method with the given domain, method, instance address, and arguments.
 +
|}
  
;mono_object_getClass(address)
+
== Field Object ==
: returns classId, className of the class at the given address in memory
 
  
;mono_enumDomains()
+
<code>mono_class_enumFields(classId)</code> returns a table of field objects.
: returns a table array of domainaddress for each domain in the game
 
  
;mono_setCurrentDomain(domainId)
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns ? (result of MONOCMD_SETCURRENTDOMAIN)
+
!align="left"|Field
: sets the domain the MonoDataCollector will use
+
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|field
 +
|Integer
 +
|The field ID.
 +
|-
 +
|type
 +
|ValueType
 +
|The Cheat Engine value type.
 +
|-
 +
|monotype
 +
|Integer
 +
|The Mono type.
 +
|-
 +
|parent
 +
|Integer
 +
|The parent class ID.
 +
|-
 +
|offset
 +
|Integer
 +
|The offset in bytes from the object or static field base address.
 +
|-
 +
|flags
 +
|Integer
 +
|The field flags.
 +
|-
 +
|isStatic
 +
|Boolean
 +
|True if the field is static. If true, use mono_class_getStaticFieldAddress to get the static field base address.
 +
|-
 +
|name
 +
|String
 +
|The field name.
 +
|-
 +
|typename
 +
|String
 +
|The type name, usually including namespace, such as System.Int32.
 +
|}
  
;mono_enumAssemblies()
+
== Method Object ==
: returns table of ''assemblyId'' for each assembly in the current domain from the MonoDataCollector
 
  
;mono_getImageFromAssembly(''assemblyId'')
+
<code>mono_class_enumMethods(classId)</code> returns a table of method objects.
: returns the ''imageId'' for the passed assembly
 
  
;mono_image_get_name(''imageId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns the ''name'' of the assembly with the given ''imageId''
+
!align="left"|Field
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|method
 +
|Integer
 +
|The method ID.
 +
|-
 +
|name
 +
|String
 +
|The method name.
 +
|}
  
;mono_image_enumClasses(''imageId'')
+
== JIT Info Object ==
: returns a ''table'' of ''classId'' for classes in the given assembly image
 
  
;mono_class_getName(''classId'')
+
<code>mono_getJitInfo(address)</code> returns a table with information about the compiled native method at the given address.
: returns the ''class name'' as a string
 
  
;mono_class_getNamespace(''classId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns the ''namespace'' of the given class as a string
+
!align="left"|Field
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|method
 +
|Integer
 +
|The method ID.
 +
|-
 +
|code_start
 +
|Integer
 +
|The native code start address.
 +
|-
 +
|code_size
 +
|Integer
 +
|The native code size in bytes.
 +
|}
  
;mono_class_getParent(''classId'')
+
== Method Signature Result ==
: returns the ''classId'' of the parent class of the given class
 
  
;mono_class_getStaticFieldAddress(''domainId, classId'')
+
<code>mono_method_getSignature(methodId)</code> returns multiple values.
: returns the base address for a special area that stores static addresses for a given class. For example if you have a class that has 5 static fields, their offsets will be added to this base address to get the memory location
 
  
;mono_class_enumFields(''classId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
:returns a table of field objects for fields in the given class
+
!align="left"|Return Value
: '''''field''''' - the field id
+
!align="left"|Type
:  '''''type''''' - ?? the Cheat Engine type?  (i.e. vtByte, vtWord, vtString, etc?)
+
!style="width: 80%;background-color:white;" align="left"|Description
:  '''''monotype''''' - ?? the mono type?
+
|-
:  '''''parent''''' - ?? the class id?
+
|result
:  '''''offset''''' - the offset in bytes from the structure base address
+
|String
:  '''''flags''''' - ??
+
|The formatted method signature result.
:  '''''isStatic''''' - true/false - if true, offset is into static address, use mono_class_getStaticFieldAddress
+
|-
:  '''''name''''' - field name
+
|parameterNames
:  '''''typename''''' - name of the type with namespace (i.e. "System.Int32")
+
|Table
 +
|A table containing parameter names.
 +
|-
 +
|returnType
 +
|String
 +
|The return type string.
 +
|}
  
;mono_class_enumMethods(''classId'')
+
== Cheat Engine Hooks ==
:returns a table of method objects for the methods in the given class
 
:  '''''method''''' - method id
 
:  '''''name''''' - string name of the method
 
  
;mono_getJitInfo(''address'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
:returns a result object with the properties given the address of code in memory
+
!align="left"|Function
:  '''''method''''' - the method id
+
!align="left"|Return Type
:  '''''code_start''''' - address where method code begins
+
!style="width: 80%;background-color:white;" align="left"|Description
'''''code_size''''' - length of code in bytes
+
|-
 +
|mono_initialize()
 +
|void
 +
|Sets up Mono-related hooks, calls the previous open-process hook if present, and schedules mono_OpenProcessMT.
 +
|-
 +
|mono_OpenProcessMT(t)
 +
|void
 +
|Called when a process is opened. If t is not nil, it destroys t, enumerates modules looking for mono.dll, and adds Mono menu items to the main form.
 +
|-
 +
|mono_OpenProcess(processid)
 +
|void
 +
|Open-process hook used by the Mono integration.
 +
|-
 +
|mono_structureDissectOverrideCallback(structure, baseaddress)
 +
|Boolean/nil
 +
|Called by Cheat Engine when a structure is dissected. Returns true if structure members were defined, otherwise nil.
 +
|-
 +
|mono_structureNameLookupCallback(address)
 +
|String, Integer/nil
 +
|Called by Cheat Engine when creating a new structure in the structure dissector. Returns classname and current address, or nil.
 +
|-
 +
|mono_symbolLookupCallback(symbol)
 +
|Integer/nil
 +
|Called by Cheat Engine when resolving a Mono symbol. Returns an address or nil.
 +
|-
 +
|mono_addressLookupCallback(address)
 +
|String
 +
|Called by Cheat Engine's disassembly view to display a Mono symbol name for the given address.
 +
|}
  
;mono_image_findClass(''imageId, namespace, className'')
+
== Mono Dissector Methods ==
:returns the '''''classId''''' of the given class name and namespace in an image
 
  
;mono_findClass(''namespace, className'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
:returns the '''''classId''''' of the given class name and namespace
+
!align="left"|Function
 +
!align="left"|Description
 +
|-
 +
|monoform_killform(sender)
 +
|Closes or destroys the Mono dissector form.
 +
|-
 +
|monoform_miShowILDisassemblyClick(sender)
 +
|Handles the Show IL Disassembly menu item.
 +
|-
 +
|monoform_miRejitClick(sender)
 +
|Handles the ReJIT menu item.
 +
|-
 +
|monoform_miGetILCodeClick(sender)
 +
|Handles the Get IL Code menu item.
 +
|-
 +
|monoform_EnumImages(node)
 +
|Enumerates images for the selected tree node.
 +
|-
 +
|monoform_EnumClasses(node)
 +
|Enumerates classes for the selected tree node.
 +
|-
 +
|monoform_EnumFields(node)
 +
|Enumerates fields for the selected tree node.
 +
|-
 +
|monoform_EnumMethods(node)
 +
|Enumerates methods for the selected tree node.
 +
|-
 +
|mono_TVExpanding(sender, node)
 +
|Handles Mono tree-view expansion.
 +
|-
 +
|mono_TVCollapsing(sender, node)
 +
|Handles Mono tree-view collapsing.
 +
|-
 +
|monoform_FindDialogFind(sender)
 +
|Handles Mono dissector find dialog searches.
 +
|-
 +
|monoform_miFindClick(sender)
 +
|Handles the Find menu item.
 +
|-
 +
|monoform_miExpandAllClick(sender)
 +
|Handles the Expand All menu item.
 +
|-
 +
|monoform_miSaveClick(sender)
 +
|Handles the Save menu item.
 +
|-
 +
|mono_dissect()
 +
|Opens or initializes the Mono dissector.
 +
|-
 +
|miMonoActivateClick(sender)
 +
|Handles Mono activation from the Cheat Engine menu.
 +
|-
 +
|miMonoDissectClick(sender)
 +
|Handles opening the Mono dissector from the Cheat Engine menu.
 +
|}
  
;mono_class_findMethod(''classId, methodName'')
+
== Examples ==
:returns the '''''methodId''''' of a certain method in a class
 
  
;mono_findMethod(''namespace, className, methodName'')
+
===Launch the Mono data collector===
:returns the '''''methodId''''' of a certain method, calls '''mono_image_findClass''' and '''mono_class_findMethod'''
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local monoBase = LaunchMonoDataCollector()
  
;mono_method_getName(''methodId'')
+
if monoBase == 0 then
:returns the name of a method given the id
+
  print("Mono data collector could not be launched")
 +
else
 +
  print(string.format("Mono base: %X", monoBase))
 +
end
 +
</syntaxhighlight>
  
;mono_method_getHeader(''methodId'')
+
===Enumerate Mono domains===
:returns a '''''headerId'''''??
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local domains = mono_enumDomains()
  
;mono_method_getSignature(''methodId'')
+
for i, domain in ipairs(domains) do
:returns '''''result, parameternames, returntype'''''
+
  print(i .. ": " .. string.format("%X", domain))
:  '''''result''''' - ?? string
+
end
:  '''''parameterNames''''' - table of strings representing parameter names
+
</syntaxhighlight>
:  '''''returnType''''' - string??  - mono type string?
 
  
;mono_method_disassemble(''methodId'')
+
===Set the current Mono domain===
:returns a string - ?? the IL code ??
+
<syntaxhighlight lang="lua" line highlight="1,5">
 +
local domains = mono_enumDomains()
  
;mono_method_getClass(''methodId'')
+
if #domains > 0 then
:returns the '''''classId''''' a method belongs in
+
  local domain = domains[1]
 +
  mono_setCurrentDomain(domain)
 +
end
 +
</syntaxhighlight>
  
;mono_compile_method(''methodId'')
+
===Enumerate assemblies===
:JIT a method if it wasn't compiled yet (??return value address of assembly??)
+
<syntaxhighlight lang="lua" line highlight="1,4">
 +
local assemblies = mono_enumAssemblies()
  
;mono_free_method(''methodId'')
+
for i, assembly in ipairs(assemblies) do
:(no return value) - only works on dynamic method, and only if profiler isn't being used
+
  local image = mono_getImageFromAssembly(assembly)
  
;mono_methodheader_getILCode(''methodHeader'')
+
  print(i .. ": " .. tostring(mono_image_get_name(image)))
:returns '''''address, size'''''
+
end
:  '''''address''''' - address of start of IL code?
+
</syntaxhighlight>
:  '''''size''''' - size of IL code?
 
  
;mono_getILCodeFromMethod(''methodId'')
+
===Find a class===
:combination of '''mono_method_getHeader''' and '''mono_methodheader_getILCode'''
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
 +
if classId ~= nil and classId ~= 0 then
 +
  print("Class found: " .. tostring(classId))
 +
end
 +
</syntaxhighlight>
  
 +
===Enumerate class fields===
 +
<syntaxhighlight lang="lua" line highlight="1,3">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
 +
local fields = mono_class_enumFields(classId)
  
 +
for i, field in ipairs(fields) do
 +
  print(field.name .. " : " .. field.typename .. " @ " .. string.format("%X", field.offset))
 +
end
 +
</syntaxhighlight>
  
 +
===Enumerate class methods===
 +
<syntaxhighlight lang="lua" line highlight="1,3">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
 +
local methods = mono_class_enumMethods(classId)
  
==== Cheat Engine Hooks ====
+
for i, method in ipairs(methods) do
 +
  print(method.name .. " = " .. tostring(method.method))
 +
end
 +
</syntaxhighlight>
  
;mono_structureDissectOverrideCallback(''structure'', ''baseaddress'')
+
===Find and compile a method===
:Called by CE when a structure is being dissected to fill in the values if we know the structure
+
<syntaxhighlight lang="lua" line highlight="1,4">
:Returns true if the structure members were defined, nil if not
+
local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
:Calls <code>mono_object_findRealStartOfObject(baseaddress)</code>, <code>mono_class_enumFields(classaddress)</code>, <code>monoTypeToVarType(monotype)</code>
 
  
;mono_structureNameLookupCallback(''address'')
+
if methodId ~= nil and methodId ~= 0 then
:Returns classname,currentaddress (the real base address) or nil
+
  local address = mono_compile_method(methodId)
:Called by CE when creating a new structure in the structure dissector
 
  
;;mono_symbolLookupCallback(''symbol'')
+
  print(string.format("Native address: %X", address))
:returns pointer or nil
+
end
:called by CE when it is trying to find the address to go with a symbol
+
</syntaxhighlight>
:calls mono_findMethod and mono_compile_method
 
  
;mono_addressLookupCallback(''address'')
+
===Get method signature===
:returns string
+
<syntaxhighlight lang="lua" line highlight="1,4">
:called by CE in the disassembly window to show a symbol name for the address
+
local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
:calls mono_getJitInfo(address), mono_method_getClass(method), mono_class_GetName(class), mono_class_GetNamespace(class), mono_method_getName(method)
+
 
</pre>
+
if methodId ~= nil and methodId ~= 0 then
 +
  local signature, parameterNames, returnType = mono_method_getSignature(methodId)
 +
 
 +
  print(signature)
 +
  print("Returns: " .. tostring(returnType))
 +
end
 +
</syntaxhighlight>
 +
 
 +
===Get JIT information from an address===
 +
<syntaxhighlight lang="lua" line highlight="2">
 +
local address = getAddress("GameAssembly.dll+123456")
 +
local info = mono_getJitInfo(address)
 +
 
 +
if info ~= nil then
 +
  print("Method: " .. tostring(info.method))
 +
  print("Code start: " .. string.format("%X", info.code_start))
 +
  print("Code size: " .. tostring(info.code_size))
 +
end
 +
</syntaxhighlight>
 +
 
 +
{{MonoSeeAlso}}

Latest revision as of 20:32, 25 June 2026


The advanced Mono features of Cheat Engine are controlled by the monoscript.lua script in the autorun directory.

When Cheat Engine attaches to a process, the script checks for mono.dll. If Mono is detected, the matching MonoDataDissector DLL from the autorun directory is injected into the target process. The injected DLL creates a named pipe, and the Lua side communicates with it to perform Mono-related operations.

Main Methods[edit]

Function Return Type Description
LaunchMonoDataCollector() Integer Injects the Mono data collector DLL. Returns 0 on failure, or the monoBase returned by the CMD_INITMONO pipe command.
monoTypeToVarType(monoType) ValueType Returns the Cheat Engine value type for the given Mono type, such as vtString, vtByte, vtWord, vtDword, vtSingle, vtDouble, or vtPointer.
mono_object_getClass(address) Integer, String Returns the class ID and class name of the object at the given address.
mono_enumDomains() Table Returns a table array containing the domain address of each Mono domain.
mono_setCurrentDomain(domainId) Integer Sets the Mono domain used by the MonoDataCollector.
mono_enumAssemblies() Table Returns a table containing the assembly IDs for each assembly in the current domain.
mono_getImageFromAssembly(assemblyId) Integer Returns the image ID for the given assembly.
mono_image_get_name(imageId) String Returns the name of the assembly image.
mono_image_enumClasses(imageId) Table Returns a table containing the class IDs for classes in the given assembly image.
mono_class_getName(classId) String Returns the class name of the given class.
mono_class_getNamespace(classId) String Returns the namespace of the given class.
mono_class_getParent(classId) Integer Returns the class ID of the parent class.
mono_class_getStaticFieldAddress(domainId, classId) Integer Returns the base address for the static field storage area of the given class in the given domain.
mono_class_enumFields(classId) Table Returns a table containing field objects for the given class.
mono_class_enumMethods(classId) Table Returns a table containing method objects for the given class.
mono_getJitInfo(address) Table Returns JIT information for the code address.
mono_image_findClass(imageId, namespace, className) Integer Returns the class ID for the given namespace and class name in the specified image.
mono_findClass(namespace, className) Integer Returns the class ID for the given namespace and class name.
mono_class_findMethod(classId, methodName) Integer Returns the method ID of the given method in the given class.
mono_findMethod(namespace, className, methodName) Integer Returns the method ID for the given namespace, class name, and method name.
mono_method_getName(methodId) String Returns the name of the given method.
mono_method_getHeader(methodId) Integer Returns the method header ID.
mono_method_getSignature(methodId) String, Table, String Returns the signature result, parameter names, and return type of the method.
mono_method_disassemble(methodId) String Returns the disassembled IL code for the given method.
mono_method_getClass(methodId) Integer Returns the class ID that owns the given method.
mono_compile_method(methodId) Integer JIT-compiles the method if needed and returns the native method address.
mono_free_method(methodId) void Frees a dynamic method. This only works on dynamic methods and only if the profiler is not being used.
mono_methodheader_getILCode(methodHeader) Integer, Integer Returns the IL code address and size for the given method header.
mono_getILCodeFromMethod(methodId) Integer, Integer Gets the method header and returns the IL code address and size.
mono_image_rva_map(imageId, offset) Integer Maps an image RVA/offset. Exact usage depends on the Mono image context.
mono_loadAssemblyFromFile(fname) Integer Loads a C# assembly in the target process.
mono_invoke_method(domainId, methodId, address, args) Variant Invokes a Mono method with the given domain, method, instance address, and arguments.

Field Object[edit]

mono_class_enumFields(classId) returns a table of field objects.

Field Type Description
field Integer The field ID.
type ValueType The Cheat Engine value type.
monotype Integer The Mono type.
parent Integer The parent class ID.
offset Integer The offset in bytes from the object or static field base address.
flags Integer The field flags.
isStatic Boolean True if the field is static. If true, use mono_class_getStaticFieldAddress to get the static field base address.
name String The field name.
typename String The type name, usually including namespace, such as System.Int32.

Method Object[edit]

mono_class_enumMethods(classId) returns a table of method objects.

Field Type Description
method Integer The method ID.
name String The method name.

JIT Info Object[edit]

mono_getJitInfo(address) returns a table with information about the compiled native method at the given address.

Field Type Description
method Integer The method ID.
code_start Integer The native code start address.
code_size Integer The native code size in bytes.

Method Signature Result[edit]

mono_method_getSignature(methodId) returns multiple values.

Return Value Type Description
result String The formatted method signature result.
parameterNames Table A table containing parameter names.
returnType String The return type string.

Cheat Engine Hooks[edit]

Function Return Type Description
mono_initialize() void Sets up Mono-related hooks, calls the previous open-process hook if present, and schedules mono_OpenProcessMT.
mono_OpenProcessMT(t) void Called when a process is opened. If t is not nil, it destroys t, enumerates modules looking for mono.dll, and adds Mono menu items to the main form.
mono_OpenProcess(processid) void Open-process hook used by the Mono integration.
mono_structureDissectOverrideCallback(structure, baseaddress) Boolean/nil Called by Cheat Engine when a structure is dissected. Returns true if structure members were defined, otherwise nil.
mono_structureNameLookupCallback(address) String, Integer/nil Called by Cheat Engine when creating a new structure in the structure dissector. Returns classname and current address, or nil.
mono_symbolLookupCallback(symbol) Integer/nil Called by Cheat Engine when resolving a Mono symbol. Returns an address or nil.
mono_addressLookupCallback(address) String Called by Cheat Engine's disassembly view to display a Mono symbol name for the given address.

Mono Dissector Methods[edit]

Function Description
monoform_killform(sender) Closes or destroys the Mono dissector form.
monoform_miShowILDisassemblyClick(sender) Handles the Show IL Disassembly menu item.
monoform_miRejitClick(sender) Handles the ReJIT menu item.
monoform_miGetILCodeClick(sender) Handles the Get IL Code menu item.
monoform_EnumImages(node) Enumerates images for the selected tree node.
monoform_EnumClasses(node) Enumerates classes for the selected tree node.
monoform_EnumFields(node) Enumerates fields for the selected tree node.
monoform_EnumMethods(node) Enumerates methods for the selected tree node.
mono_TVExpanding(sender, node) Handles Mono tree-view expansion.
mono_TVCollapsing(sender, node) Handles Mono tree-view collapsing.
monoform_FindDialogFind(sender) Handles Mono dissector find dialog searches.
monoform_miFindClick(sender) Handles the Find menu item.
monoform_miExpandAllClick(sender) Handles the Expand All menu item.
monoform_miSaveClick(sender) Handles the Save menu item.
mono_dissect() Opens or initializes the Mono dissector.
miMonoActivateClick(sender) Handles Mono activation from the Cheat Engine menu.
miMonoDissectClick(sender) Handles opening the Mono dissector from the Cheat Engine menu.

Examples[edit]

Launch the Mono data collector[edit]

1 local monoBase = LaunchMonoDataCollector()
2 
3 if monoBase == 0 then
4   print("Mono data collector could not be launched")
5 else
6   print(string.format("Mono base: %X", monoBase))
7 end

Enumerate Mono domains[edit]

1 local domains = mono_enumDomains()
2 
3 for i, domain in ipairs(domains) do
4   print(i .. ": " .. string.format("%X", domain))
5 end

Set the current Mono domain[edit]

1 local domains = mono_enumDomains()
2 
3 if #domains > 0 then
4   local domain = domains[1]
5   mono_setCurrentDomain(domain)
6 end

Enumerate assemblies[edit]

1 local assemblies = mono_enumAssemblies()
2 
3 for i, assembly in ipairs(assemblies) do
4   local image = mono_getImageFromAssembly(assembly)
5 
6   print(i .. ": " .. tostring(mono_image_get_name(image)))
7 end

Find a class[edit]

1 local classId = mono_findClass("PlayerNamespace", "PlayerController")
2 
3 if classId ~= nil and classId ~= 0 then
4   print("Class found: " .. tostring(classId))
5 end

Enumerate class fields[edit]

1 local classId = mono_findClass("PlayerNamespace", "PlayerController")
2 
3 local fields = mono_class_enumFields(classId)
4 
5 for i, field in ipairs(fields) do
6   print(field.name .. " : " .. field.typename .. " @ " .. string.format("%X", field.offset))
7 end

Enumerate class methods[edit]

1 local classId = mono_findClass("PlayerNamespace", "PlayerController")
2 
3 local methods = mono_class_enumMethods(classId)
4 
5 for i, method in ipairs(methods) do
6   print(method.name .. " = " .. tostring(method.method))
7 end

Find and compile a method[edit]

1 local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
2 
3 if methodId ~= nil and methodId ~= 0 then
4   local address = mono_compile_method(methodId)
5 
6   print(string.format("Native address: %X", address))
7 end

Get method signature[edit]

1 local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
2 
3 if methodId ~= nil and methodId ~= 0 then
4   local signature, parameterNames, returnType = mono_method_getSignature(methodId)
5 
6   print(signature)
7   print("Returns: " .. tostring(returnType))
8 end

Get JIT information from an address[edit]

1 local address = getAddress("GameAssembly.dll+123456")
2 local info = mono_getJitInfo(address)
3 
4 if info ~= nil then
5   print("Method: " .. tostring(info.method))
6   print("Code start: " .. string.format("%X", info.code_start))
7   print("Code size: " .. tostring(info.code_size))
8 end

See also[edit]