Difference between revisions of "Mono:Mono Lua"

From Cheat Engine
Jump to navigation Jump to search
m (Reverted edits by This content is not available (Talk) to last revision by Igromanru)
(Major overhaul of the post.)
 
Line 2: Line 2:
 
[[Category:Help]]
 
[[Category:Help]]
 
[[Category:Lua]]
 
[[Category:Lua]]
{{NeedWork}}
 
 
{{DISPLAYTITLE:Mono - Lua}}
 
{{DISPLAYTITLE:Mono - Lua}}
  
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.
+
The advanced Mono features of Cheat Engine are controlled by the <code>monoscript.lua</code> script in the <code>autorun</code> directory.
 
 
  
 +
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.
  
 
== Main Methods ==
 
== Main Methods ==
  
; 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.
 +
|}
  
; varType = monoTypeToVarType(monoType)
+
== Field Object ==
: Returns the Cheat Engine type (vtString, vtByte, vtWorkd, vtDword, vtSingle, vtDouble, vtPointer) for the given mono type
 
  
;mono_object_getClass(address)
+
<code>mono_class_enumFields(classId)</code> returns a table of field objects.
: returns classId, className of the class at the given address in memory
 
  
;mono_enumDomains()
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns a table array of domainaddress for each domain in the game
+
!align="left"|Field
 +
!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_setCurrentDomain(domainId)
+
== Method Object ==
: returns ? (result of MONOCMD_SETCURRENTDOMAIN)
 
: sets the domain the MonoDataCollector will use
 
  
;mono_enumAssemblies()
+
<code>mono_class_enumMethods(classId)</code> returns a table of method objects.
: returns table of ''assemblyId'' for each assembly in the current domain from the MonoDataCollector
 
  
;mono_getImageFromAssembly(''assemblyId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns the ''imageId'' for the passed assembly
+
!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_get_name(''imageId'')
+
== JIT Info Object ==
: returns the ''name'' of the assembly with the given ''imageId''
 
  
;mono_image_enumClasses(''imageId'')
+
<code>mono_getJitInfo(address)</code> returns a table with information about the compiled native method at the given address.
: returns a ''table'' of ''classId'' for classes in the given assembly image
 
  
;mono_class_getName(''classId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: returns the ''class name'' 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_getNamespace(''classId'')
+
== Method Signature Result ==
: returns the ''namespace'' of the given class as a string
 
  
;mono_class_getParent(''classId'')
+
<code>mono_method_getSignature(methodId)</code> returns multiple values.
: returns the ''classId'' of the parent class of the given class
 
  
;mono_class_getStaticFieldAddress(''domainId, classId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
: 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
+
!align="left"|Return Value
 +
!align="left"|Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|result
 +
|String
 +
|The formatted method signature result.
 +
|-
 +
|parameterNames
 +
|Table
 +
|A table containing parameter names.
 +
|-
 +
|returnType
 +
|String
 +
|The return type string.
 +
|}
  
;mono_class_enumFields(''classId'')
+
== Cheat Engine Hooks ==
:returns a table of field objects for fields in the given class
 
:  '''''field''''' - the field id
 
:  '''''type''''' - ?? the Cheat Engine type?  (i.e. vtByte, vtWord, vtString, etc?)
 
:  '''''monotype''''' - ?? the mono type?
 
:  '''''parent''''' - ?? the class id?
 
:  '''''offset''''' - the offset in bytes from the structure base address
 
:  '''''flags''''' - ??
 
:  '''''isStatic''''' - true/false - if true, offset is into static address, use mono_class_getStaticFieldAddress
 
:  '''''name''''' - field name
 
:  '''''typename''''' - name of the type with namespace (i.e. "System.Int32")
 
  
;mono_class_enumMethods(''classId'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
:returns a table of method objects for the methods in the given class
+
!align="left"|Function
:  '''''method''''' - method id
+
!align="left"|Return Type
:  '''''name''''' - string name of the method
+
!style="width: 80%;background-color:white;" align="left"|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_getJitInfo(''address'')
+
== Mono Dissector Methods ==
:returns a result object with the properties given the address of code in memory
 
:  '''''method''''' - the method id
 
:  '''''code_start''''' - address where method code begins
 
:  '''''code_size''''' - length of code in bytes
 
 
 
;mono_image_findClass(''imageId, namespace, className'')
 
:returns the '''''classId''''' of the given class name and namespace in an image
 
 
 
;mono_findClass(''namespace, className'')
 
:returns the '''''classId''''' of the given class name and namespace
 
 
 
;mono_class_findMethod(''classId, methodName'')
 
:returns the '''''methodId''''' of a certain method in a class
 
  
;mono_findMethod(''namespace, className, methodName'')
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
:returns the '''''methodId''''' of a certain method, calls '''mono_image_findClass''' and '''mono_class_findMethod'''
+
!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_method_getName(''methodId'')
+
== Examples ==
:returns the name of a method given the id
 
  
;mono_method_getHeader(''methodId'')
+
===Launch the Mono data collector===
:returns a '''''headerId'''''??
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local monoBase = LaunchMonoDataCollector()
  
;mono_method_getSignature(''methodId'')
+
if monoBase == 0 then
:returns '''''result, parameternames, returntype'''''
+
  print("Mono data collector could not be launched")
:  '''''result''''' - ?? string
+
else
:  '''''parameterNames''''' - table of strings representing parameter names
+
  print(string.format("Mono base: %X", monoBase))
:  '''''returnType''''' - string??  - mono type string?
+
end
 +
</syntaxhighlight>
  
;mono_method_disassemble(''methodId'')
+
===Enumerate Mono domains===
:returns a string - ?? the IL code ??
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local domains = mono_enumDomains()
  
;mono_method_getClass(''methodId'')
+
for i, domain in ipairs(domains) do
:returns the '''''classId''''' a method belongs in
+
  print(i .. ": " .. string.format("%X", domain))
 +
end
 +
</syntaxhighlight>
  
;mono_compile_method(''methodId'')
+
===Set the current Mono domain===
:JIT a method if it wasn't compiled yet, returns the address of the method
+
<syntaxhighlight lang="lua" line highlight="1,5">
 +
local domains = mono_enumDomains()
  
;mono_free_method(''methodId'')
+
if #domains > 0 then
:(no return value) - only works on dynamic method, and only if profiler isn't being used
+
  local domain = domains[1]
 +
  mono_setCurrentDomain(domain)
 +
end
 +
</syntaxhighlight>
  
;mono_methodheader_getILCode(''methodHeader'')
+
===Enumerate assemblies===
:returns '''''address, size'''''
+
<syntaxhighlight lang="lua" line highlight="1,4">
:  '''''address''''' - address of start of IL code?
+
local assemblies = mono_enumAssemblies()
:  '''''size''''' - size of IL code?
 
  
;mono_getILCodeFromMethod(''methodId'')
+
for i, assembly in ipairs(assemblies) do
:combination of '''mono_method_getHeader''' and '''mono_methodheader_getILCode'''
+
  local image = mono_getImageFromAssembly(assembly)
  
;mono_iamge_rva_map(''imageId, offset'')
+
  print(i .. ": " .. tostring(mono_image_get_name(image)))
:?? not sure what this is ??
+
end
 +
</syntaxhighlight>
  
;mono_loadAssemblyFromFile(''fname'')
+
===Find a class===
:loads a c# assembly in the target process
+
<syntaxhighlight lang="lua" line highlight="1">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
;mono_invoke_method(''domainId'', ''methodId'', ''address'', ''args...'')
+
if classId ~= nil and classId ~= 0 then
:Lets you invoke a method with the given arguments. args is a tablearray of record with value and type
+
  print("Class found: " .. tostring(classId))
 +
end
 +
</syntaxhighlight>
  
== Cheat Engine Hooks ==
+
===Enumerate class fields===
 +
<syntaxhighlight lang="lua" line highlight="1,3">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
;mono_initialize()
+
local fields = mono_class_enumFields(classId)
: sets up hooks, calls old open process hook if there was one, calls <code>syncrhonize("mono_OpenProcessMT")</code>
 
  
;mono_OpenProcessMT(''t'')
+
for i, field in ipairs(fields) do
: if parameter is not nil, calls <code>t.destroy()</code>, enumerates modules looking for 'mono.dll', adds menu item to cheat engine main form
+
  print(field.name .. " : " .. field.typename .. " @ " .. string.format("%X", field.offset))
 +
end
 +
</syntaxhighlight>
  
;mono_OpenProcess(''processid'')
+
===Enumerate class methods===
 +
<syntaxhighlight lang="lua" line highlight="1,3">
 +
local classId = mono_findClass("PlayerNamespace", "PlayerController")
  
;mono_structureDissectOverrideCallback(''structure'', ''baseaddress'')
+
local methods = mono_class_enumMethods(classId)
:Called by CE when a structure is being dissected to fill in the values if we know the structure
 
:Returns true if the structure members were defined, nil if not
 
:Calls <code>mono_object_findRealStartOfObject(baseaddress)</code>, <code>mono_class_enumFields(classaddress)</code>, <code>monoTypeToVarType(monotype)</code>
 
  
;mono_structureNameLookupCallback(''address'')
+
for i, method in ipairs(methods) do
:Returns classname,currentaddress (the real base address) or nil
+
  print(method.name .. " = " .. tostring(method.method))
:Called by CE when creating a new structure in the structure dissector
+
end
 +
</syntaxhighlight>
  
;;mono_symbolLookupCallback(''symbol'')
+
===Find and compile a method===
:returns pointer or nil
+
<syntaxhighlight lang="lua" line highlight="1,4">
:called by CE when it is trying to find the address to go with a symbol
+
local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
:calls mono_findMethod and mono_compile_method
 
  
;mono_addressLookupCallback(''address'')
+
if methodId ~= nil and methodId ~= 0 then
:returns string
+
  local address = mono_compile_method(methodId)
:called by CE in the disassembly window to show a symbol name for the address
 
:calls mono_getJitInfo(address), mono_method_getClass(method), mono_class_GetName(class), mono_class_GetNamespace(class), mono_method_getName(method)
 
  
 +
  print(string.format("Native address: %X", address))
 +
end
 +
</syntaxhighlight>
  
 +
===Get method signature===
 +
<syntaxhighlight lang="lua" line highlight="1,4">
 +
local methodId = mono_findMethod("PlayerNamespace", "PlayerController", "TakeDamage")
  
== Mono Dissector Methods ==
+
if methodId ~= nil and methodId ~= 0 then
 +
  local signature, parameterNames, returnType = mono_method_getSignature(methodId)
  
;monoform_killform(''sender'')
+
  print(signature)
;monoform_miShowILDisassemblyClick(''sender'')
+
  print("Returns: " .. tostring(returnType))
;monoform_miRejitClick(''sender'')
+
end
;monoform_miGetILCodeClick(''sender'')
+
</syntaxhighlight>
;monoform_EnumImages(''node'')
 
;monoform_EnumClasses(''node'')
 
;monoform_EnumFields(''node'')
 
;monoform_EnumMethods(''node'')
 
;mono_TVExpanding(''sender, node'')
 
;mono_TVCollapsing(''sender, node'')
 
;monoform_FindDialogFind(''sender'')
 
;monoform_miFindClick(''sender'')
 
;monoform_miExpandAllClick(''sender'')
 
;monoform_miSaveClick(''sender'')
 
;mono_dissect()
 
;miMonoActivateClick(''sender'')
 
;miMonoDissectClick(''sender'')
 
  
 +
===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}}
 
{{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]