How to Invoke a Method?
How to Invoke a Method?
Hi, I noticed that cheatengine mono has a function that invokes a method. Can someone show me a sample script where that is possible using the [URL='https://wiki.cheatengine.org/index.php?title=Mono:Lua:mono_invoke_method&action=edit&redlink=1']mono_invoke_method[/URL] in the
mono LUA_Functions? Like use this method:
DebugMenu_Cheats:FlipMapCards
I need a script example because I want to make some options that invoke various debug cheats. I used the mono dissector but can't figure out how to get it into a script. Thanks!
mono LUA_Functions? Like use this method:
DebugMenu_Cheats:FlipMapCards
I need a script example because I want to make some options that invoke various debug cheats. I used the mono dissector but can't figure out how to get it into a script. Thanks!
How to Invoke a Method?
I'd never done it before, but here's a simple example that works with DeadAge. I find the combatant pointer with an AA script and this works to return the current HP, pretty cool...
In a script you would just put "{$lua}" before and "${asm}" after it and the lua code will run when you enable/disable the script, and only run if syntaxcheck isn't true. This little diddy speaks the current hit points out loud when enabled:
Code: Select all
local method = mono_findMethod('', 'Combatant', 'GetCurrentHP') -- no namespace
local address = 0x24173e70 -- address of main player I found
local domain = mono_enumDomains()[1] -- should only be one domain, but needed for call
return mono_invoke_method(domain, method, address, {}) -- empty table for args
In a script you would just put "{$lua}" before and "${asm}" after it and the lua code will run when you enable/disable the script, and only run if syntaxcheck isn't true. This little diddy speaks the current hit points out loud when enabled:
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
local method = mono_findMethod('', 'Combatant', 'GetCurrentHP')
local address = readPointer('pCharacter') -- global pointer storing pointer to a 'Combatant' instance
local class = mono_method_getClass(method)
local domain = mono_enumDomains()[1]
local hp = mono_invoke_method(domain, method, address, {})
local name = readString(readPointer(readPointer('pCharacter')+0x18)+0x0c, 32, true)
speak(name..' currently has '..tostring(math.floor(hp))..' hit points')
{$asm}
[disable]
Last edited by Anonymous on Wed Jul 25, 2018 1:32 am, edited 3 times in total.
How to Invoke a Method?
Great thanks! I did it like this and it worked:
Now what about methods that want you to set a bool or something? Like I can call these get and set but nothing happens. Take a look at this screenshot from Dnspy please:
It looks like its a method called set_AllTrials but there is a rachet which means its a "member" so maybe Im not coding it correctly? Also it looks like all of the racthets Members have a get and set method and I think they want a value. like set it to 1 to enable? Anyway this doesn't do anything:
And looking at this screenshot when I use cheat engine JIT to invoke it, it wants a bool:
Do I have to add extra commas because its a "member" and how do I set a bool in the script to 1 (just to try)?
Thanks a LOT, this will help me in the future!
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
local method = mono_findMethod('', 'DebugMenu_Cheats', 'FlipMapCards')
local class = mono_method_getClass(method)
local domain = mono_enumDomains()[1]
local hp = mono_invoke_method(domain, method, address, {})
{$asm}
[disable]
Now what about methods that want you to set a bool or something? Like I can call these get and set but nothing happens. Take a look at this screenshot from Dnspy please:
It looks like its a method called set_AllTrials but there is a rachet which means its a "member" so maybe Im not coding it correctly? Also it looks like all of the racthets Members have a get and set method and I think they want a value. like set it to 1 to enable? Anyway this doesn't do anything:
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
local method = mono_findMethod('', 'DebugMenu_Cheats', 'set_AllTrials')
local class = mono_method_getClass(method)
local domain = mono_enumDomains()[1]
local hp = mono_invoke_method(domain, method, address, {})
{$asm}
[disable]
And looking at this screenshot when I use cheat engine JIT to invoke it, it wants a bool:
Do I have to add extra commas because its a "member" and how do I set a bool in the script to 1 (just to try)?
Thanks a LOT, this will help me in the future!
Last edited by Anonymous on Wed Jul 25, 2018 1:32 am, edited 1 time in total.
How to Invoke a Method?
Looking at the "monoscript.lua" file, it looks like the args is a table with type and value keys/values.
Try the mono_invoke_method_dialog if you are just testing stuff.
CE folder/autorun/monoscript.lua
line 1659
line 1832
line 1891
Try the mono_invoke_method_dialog if you are just testing stuff.
CE folder/autorun/monoscript.lua
line 1659
Code: Select all
function mono_invoke_method_dialog(domain, method, address)
--spawn a dialog where the user can fill in fields like: instance and parameter values
--parameter fields will be of the proper type
line 1832
Code: Select all
local params=mono_method_get_parameters(method)
--use monoTypeToVartypeLookup to convert it to the type mono_method_invole likes it
local args={}
for i=1, #params.parameters do
args[i]={}
args[i].type=monoTypeToVartypeLookup[params.parameters[i].type]
if args[i].type==vtString then
args[i].value=mifinfo.parameters[i].edtVarText.Text
else
args[i].value=tonumber(mifinfo.parameters[i].edtVarText.Text)
end
if args[i].value==nil then
messageDialog(translate('parameter ')..i..': "'..mifinfo.parameters[i].edtVarText.Text..'" '..translate('is not a valid value'), mtError, mbOK)
return
end
end
_G.args=args
_G.instance=instance
_G.method=method
_G.bla=123
local r=mono_invoke_method(domain, method, instance, args)
if r then
print(r)
end
line 1891
Code: Select all
function mono_invoke_method(domain, method, object, args)
How to Invoke a Method?
Yea I tried using the dialog to test some of them out and I guess some aren't working. But lets say I wanted to put in a boolean value directly into a script without using the dialog. Is that even possible? like what would it look like with this script here:
So I want to set_AllTrials to boolean =1. How would it be written? Also I see Domain, Method,Object,args. Also Set_AllTrials is a "member." Thanks!
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
local method = mono_findMethod('', 'DebugMenu_Cheats', 'set_AllTrials')
local class = mono_method_getClass(method)
local domain = mono_enumDomains()[1]
local hp = mono_invoke_method(domain, method, address, {})
{$asm}
[disable]
So I want to set_AllTrials to boolean =1. How would it be written? Also I see Domain, Method,Object,args. Also Set_AllTrials is a "member." Thanks!
How to Invoke a Method?
From what I can tell you just need to set the type and value for each argument; The "set_AllTrials" only has 1 argument so something like this should work.
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
local method = mono_findMethod('', 'DebugMenu_Cheats', 'set_AllTrials')
local class = mono_method_getClass(method)
local domain = mono_enumDomains()[1]
local args = {}
args[1] = {}
args[1].type = monoTypeToVartypeLookup[MONO_TYPE_BOOLEAN] -- vtByte
args[1].value = 1
local r = mono_invoke_method(domain, method, address, args)
if r then
print(r)
end
{$asm}
[disable]
Last edited by TimFun13 on Thu Jan 01, 1970 12:00 am, edited 1 time in total.
- koderkrazy
- Expert Cheater
- Posts: 254
- Joined: Sun Jun 17, 2018 2:14 pm
- Reputation: 190
How to Invoke a Method?
Thank you guys!
I've successfully called the getter and setter methods on player object after learning from above discussion.
Check my table Hero-U_TableV3 threads/hero-u-rogue-to-redemption-time ... mode.7417/
91 I've managed to call most of the methods on the stat object except one:
My Lua code:
I've tried to pass System.String object reference(literals that game uses), vStringObject is the object in above code, but still it's not working.
What am I missing here?
Also, when I start debugging mono features get de-activated. Is there any way to keep them both running?
I've successfully called the getter and setter methods on player object after learning from above discussion.
Check my table Hero-U_TableV3 threads/hero-u-rogue-to-redemption-time ... mode.7417/
91 I've managed to call most of the methods on the stat object except one:
Code: Select all
public Stat GetStat(string name)
{
return (Stat)(((object)Skills[name]) ?? ((object)Attributes[name]));
}
My Lua code:
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
print('Start!')
local method = mono_findMethod('', 'CharacterSheet', 'GetStat')
print(string.format('Method ptr: %02X', method))
local address = readPointer('pCharSheet')
local args={}
args[1] = {}
args[1].type = monoTypeToVartypeLookup[MONO_TYPE_STRING]
--args[1].value='Stealth'
--args[1].value = getAddress(pSkillName) --utf 16 string
args[1].value = getAddress('vStringObject')
print(string.format('String obj ptr: %02X', args[1].value))
local r = mono_invoke_method(nil, method, address, args)
print(r)
print('Done!')
{$asm}
[disable]
Output Lua Engine Window:
Start!
Method ptr: 184DB8C8
String obj ptr: 1B80180
Done!
What am I missing here?
Also, when I start debugging mono features get de-activated. Is there any way to keep them both running?
How to Invoke a Method?
18664
Not really sure but maybe you need to use "MONO_TYPE_CHAR" as it is set to "vtString".
Not really sure but maybe you need to use "MONO_TYPE_CHAR" as it is set to "vtString".
Code: Select all
[enable]
{$lua}
if (syntaxcheck) then return end
print('Start!')
local method = mono_findMethod('', 'CharacterSheet', 'GetStat')
print(string.format('Method ptr: %02X', method))
local address = readPointer('pCharSheet')
local args={}
args[1] = {}
args[1].type = monoTypeToVartypeLookup[MONO_TYPE_CHAR] -- vtString
args[1].value='Stealth'
--print(string.format('String obj ptr: %02X', args[1].value))
local r = mono_invoke_method(nil, method, address, args)
print(r)
print('Done!')
{$asm}
[disable]
Last edited by TimFun13 on Thu Jan 01, 1970 12:00 am, edited 1 time in total.
- koderkrazy
- Expert Cheater
- Posts: 254
- Joined: Sun Jun 17, 2018 2:14 pm
- Reputation: 190
How to Invoke a Method?
MONO_TYPE_CHAR worked.
Thanks!
Thanks!
Who is online
Users browsing this forum: No registered users