Difference between revisions of "Mono:Lua:mono invoke method"

From Cheat Engine
Jump to navigation Jump to search
(Examples)
 
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
  
== '''Function Parameters''' ==
+
===Function Parameters===
 
+
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
'''Parameter Type Description'''
+
!align="left"|Parameter
 
+
!align="left"|Type
domain string the domain's name
+
!style="width: 80%;background-color:white;" align="left"|Description
 
+
|-
method string The methods name
+
|domain
 
+
|string
instanseAddress integer The address of instanse (?)
+
|The namespace of the method
 
+
|-
args table the arguments
+
|methodId
 
+
|integer
 
+
|The method's id
 +
|-
 +
|instanseAddress
 +
|integer
 +
|The address of instanse
 +
|-
 +
|args
 +
|table
 +
|The arguments
 +
|}
  
 
----
 
----
  
 
== Examples ==
 
== Examples ==
 +
<pre>
 +
function my_mono_invoke_method(domain, method, args)  --make it easier to call
  
local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage')
+
  local c=mono_method_getClass(method)
 
+
  local instance = mono_class_findInstancesOfClassListOnly(domain,c)
local c = mono_method_getClass(methodId)
+
  instance = instance[1]
 
+
 
mono_class_findInstancesOfClass(nil,c,function(m)         -- asynchronously
+
   local params = mono_method_get_parameters(method)
 
+
   if #args ~= #params.parameters then
   local fl = createFoundList(m)  
+
    print('ERROR:my_mono_invoke_method : wrong length of args')
 
+
    return
   fl.initialize()
+
  end
 
+
    
   if fl.Count >0 then
+
  local i
 
+
  local args_t={}
     InstancesAddress=fl[0]
+
  for i=1, #params.parameters do
 
+
    args_t[i] = {}
     mono_invoke_method('' , methodId , InstancesAddress , {{100}} )
+
     args_t[i].type = monoTypeToVartypeLookup[params.parameters[i].type]
 
+
args_t[i].value = args[i]
   else
+
  end
 
+
 
     print('Faild to find Instances')
+
  if method==nil or method==0 then
 
+
     print('ERROR:my_mono_invoke_method : method==0')
 +
return
 +
   end
 +
 
 +
  if instance==nil or instance==0 then
 +
     print('ERROR:my_mono_invoke_method : instance==0')
 +
return 
 
   end
 
   end
  
   fl.destroy()
+
   local r=mono_invoke_method(domain, method, instance, args_t)
 +
  return r
 +
end
  
  m.destroy()
+
local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage') --find target method
 
+
my_mono_invoke_method('',methodId,{100.0})
  end
 
  
  )
+
</pre>

Latest revision as of 07:31, 18 December 2018

function mono_invoke_method(domain, method, instanseAddress, args): mono_readObject()??




Function Parameters[edit]

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[edit]

function my_mono_invoke_method(domain, method, args)  --make it easier to call

  local c=mono_method_getClass(method)
  local instance = mono_class_findInstancesOfClassListOnly(domain,c)
  instance = instance[1]
  
  local params = mono_method_get_parameters(method)
  if #args ~= #params.parameters then
    print('ERROR:my_mono_invoke_method : wrong length of args')
    return
  end
  
  local i
  local args_t={}
  for i=1, #params.parameters do
    args_t[i] = {}
    args_t[i].type = monoTypeToVartypeLookup[params.parameters[i].type]
	args_t[i].value = args[i]
  end
  
  if method==nil or method==0 then
    print('ERROR:my_mono_invoke_method : method==0')
	return
  end
  
  if instance==nil or instance==0 then
    print('ERROR:my_mono_invoke_method : instance==0')
	return   
  end

  local r=mono_invoke_method(domain, method, instance, args_t)
  return r
end

local methodId = mono_findMethod('', 'PlayerStatsManager', 'TakeDamage')  --find target method
my_mono_invoke_method('',methodId,{100.0})