Mono: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.

## Main Methods

LaunchMonoDataCollector()
injects the dll and returns 0 for failure, or monoBase returned from the CMD\_INITMONO command on the pipe
varType = monoTypeToVarType(monoType)
Returns the Cheat Engine type (vtString, vtByte, vtWorkd, vtDword, vtSingle, vtDouble, vtPointer) for the given mono type
mono\_object\_getClass(address)
returns classId, className of the class at the given address in memory
mono\_enumDomains()
returns a table array of domainaddress for each domain in the game
mono\_setCurrentDomain(domainId)
returns ? (result of MONOCMD\_SETCURRENTDOMAIN)
sets the domain the MonoDataCollector will use
mono\_enumAssemblies()
returns table of *assemblyId* for each assembly in the current domain from the MonoDataCollector
mono\_getImageFromAssembly(*assemblyId*)
returns the *imageId* for the passed assembly
mono\_image\_get\_name(*imageId*)
returns the *name* of the assembly with the given *imageId*
mono\_image\_enumClasses(*imageId*)
returns a *table* of *classId* for classes in the given assembly image
mono\_class\_getName(*classId*)
returns the *class name* as a string
mono\_class\_getNamespace(*classId*)
returns the *namespace* of the given class as a string
mono\_class\_getParent(*classId*)
returns the *classId* of the parent class of the given class
mono\_class\_getStaticFieldAddress(*domainId, classId*)
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*)
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*)
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*)
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*)
returns the ***methodId*** of a certain method, calls **mono\_image\_findClass** and **mono\_class\_findMethod**
mono\_method\_getName(*methodId*)
returns the name of a method given the id
mono\_method\_getHeader(*methodId*)
returns a ***headerId***??
mono\_method\_getSignature(*methodId*)
returns ***result, parameternames, returntype***
***result*** - ?? string
***parameterNames*** - table of strings representing parameter names
***returnType*** - string?? - mono type string?
mono\_method\_disassemble(*methodId*)
returns a string - ?? the IL code ??
mono\_method\_getClass(*methodId*)
returns the ***classId*** a method belongs in
mono\_compile\_method(*methodId*)
JIT a method if it wasn't compiled yet, returns the address of the method
mono\_free\_method(*methodId*)
(no return value) - only works on dynamic method, and only if profiler isn't being used
mono\_methodheader\_getILCode(*methodHeader*)
returns ***address, size***
***address*** - address of start of IL code?
***size*** - size of IL code?
mono\_getILCodeFromMethod(*methodId*)
combination of **mono\_method\_getHeader** and **mono\_methodheader\_getILCode**
mono\_iamge\_rva\_map(*imageId, offset*)
?? not sure what this is ??
mono\_loadAssemblyFromFile(*fname*)
loads a c# assembly in the target process
mono\_invoke\_method(*domainId*, *methodId*, *address*, *args...*)
Lets you invoke a method with the given arguments. args is a tablearray of record with value and type
## Cheat Engine Hooks

mono\_initialize()
sets up hooks, calls old open process hook if there was one, calls `syncrhonize("mono_OpenProcessMT")`
mono\_OpenProcessMT(*t*)
if parameter is not nil, calls `t.destroy()`, enumerates modules looking for 'mono.dll', adds menu item to cheat engine main form
mono\_OpenProcess(*processid*)
mono\_structureDissectOverrideCallback(*structure*, *baseaddress*)
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 `mono_object_findRealStartOfObject(baseaddress)`, `mono_class_enumFields(classaddress)`, `monoTypeToVarType(monotype)`
mono\_structureNameLookupCallback(*address*)
Returns classname,currentaddress (the real base address) or nil
Called by CE when creating a new structure in the structure dissector
mono\_symbolLookupCallback(*symbol*)
returns pointer or nil
called by CE when it is trying to find the address to go with a symbol
calls mono\_findMethod and mono\_compile\_method
mono\_addressLookupCallback(*address*)
returns string
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)

## Mono Dissector Methods

monoform\_killform(*sender*)
monoform\_miShowILDisassemblyClick(*sender*)
monoform\_miRejitClick(*sender*)
monoform\_miGetILCodeClick(*sender*)
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*)

## See also

* Mono
* Mono Dissect Form
* Mono Structure Dissection
* **Mono Lua**
	+ Mono Lua Functions
* Mono AA Commands
* Tutorial - Mono - Basic