Difference between revisions of "Mono:Lua:mono invoke method"
Jump to navigation
Jump to search
Wangyujie96 (talk | contribs) m (→Examples) |
Wangyujie96 (talk | contribs) (→Examples) |
||
Line 32: | Line 32: | ||
== Examples == | == Examples == | ||
<pre> | <pre> | ||
− | local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage') | + | local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage') --find target method |
local c = mono_method_getClass(methodId) | local c = mono_method_getClass(methodId) | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
mono_class_findInstancesOfClass(nil,c,function(m) -- asynchronously | mono_class_findInstancesOfClass(nil,c,function(m) -- asynchronously | ||
Line 47: | Line 39: | ||
fl.initialize() | fl.initialize() | ||
if fl.Count >0 then | if fl.Count >0 then | ||
− | InstancesAddress=fl[0] | + | InstancesAddress=getAddressSafe(fl[0]) --must be number ,but fl[0] is a hex text.It might be more than one if game have the same objects; |
+ | |||
+ | local params = mono_method_get_parameters(methodId) --find parameters | ||
+ | |||
+ | local args = {} | ||
+ | for i=1, #params.parameters do | ||
+ | args[i]={} | ||
+ | args[i].type=monoTypeToVartypeLookup[params.parameters[i].type] | ||
+ | end | ||
+ | |||
+ | ---- input damage value here ---- | ||
+ | args[1].value=100.0 | ||
+ | |||
+ | ----execute / invoke the function : | ||
mono_invoke_method('' , methodId , InstancesAddress ,args) | mono_invoke_method('' , methodId , InstancesAddress ,args) | ||
else | else |
Revision as of 14:13, 17 December 2018
function mono_invoke_method(domain, method, instanseAddress, args): mono_readObject()??
Function Parameters
Parameter | Type | Description |
---|---|---|
domain | string | The namespace of the method |
methodId | integer | The method's id |
instanseAddress | integer | The address of instanse |
args | table | The arguments |
Examples
local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage') --find target method local c = mono_method_getClass(methodId) mono_class_findInstancesOfClass(nil,c,function(m) -- asynchronously local fl = createFoundList(m) fl.initialize() if fl.Count >0 then InstancesAddress=getAddressSafe(fl[0]) --must be number ,but fl[0] is a hex text.It might be more than one if game have the same objects; local params = mono_method_get_parameters(methodId) --find parameters local args = {} for i=1, #params.parameters do args[i]={} args[i].type=monoTypeToVartypeLookup[params.parameters[i].type] end ---- input damage value here ---- args[1].value=100.0 ----execute / invoke the function : mono_invoke_method('' , methodId , InstancesAddress ,args) else print('Faild to find Instances') end fl.destroy() m.destroy() end )