CoSMOS
Documentation
×
Menu

mono_invoke_method

Description:

 
You can execute a game function by knowing its name.
 

Command Parameters:

 
Parameter
Type
Description
Domain
long / 8 bytes
Its very rare that the method is in any other than main domain, so you can also use NIL
Method
string
Address of the method
Instance
long / 8 bytes
Instance of the class, for static methods it can be 0. See below
Args
LuaTable
Lua table holding lua tables holding Type & value of the arguments the method is called with
 

List of common values for Type parameter

 
2
MONO_TYPE_BOOLEAN
3
MONO_TYPE_CHAR
4
MONO_TYPE_I1 (byte)
5
MONO_TYPE_U1 (unsigned byte)
6
MONO_TYPE_I2 (2 bytes)
7
MONO_TYPE_U2 (unsigned 2 bytes)
8
MONO_TYPE_I4 (4 bytes)
9
MONO_TYPE_U4 (unsigned 4 bytes)
10
MONO_TYPE_I8 (8 bytes)
11
MONO_TYPE_U8 (unsigned 8 bytes)
12
MONO_TYPE_R4 (float)
13
MONO_TYPE_R8 (double)
14
MONO_TYPE_STRING (string)
 

Example

 
 
You see the class "GlobalData" has a static method "AddPlayerMoney" (it doesn't have a namespace which you can see by namespace is "-") with a parameter of type MONO_TYPE_I4 which is the type for int contains the money to add. You can simply execute this via this script:
 
 
When the method is NOT static, the 3rd parameter of mono_invoke_method needs to be an address of an instance of the object. This you can get by another script, like this:
 
 
In unity games "Update" methods are your best friend to get the base address of the class, which is the instance address you will need to pass to mono_invoke_method then