Csimbi I post too much Reputation: 94
Joined: 14 Jul 2007 Posts: 3110
|
Posted: Sun Jan 28, 2024 9:53 am Post subject: Calling mono_invoke_method with returned argument |
|
|
Hello,
I am building a script to spawn things.
I suspect I am not passing the argument correctly.
I am hoping to get some suggestions on how to go about fixing this.
This is how the game does this internally:
Code: | protected override void OnApply(ECT cType, int cId)
{
for (int i = 0; i < amount; i++)
{
VService.SpawnNewV(RService.GetRandom());
}
}
|
This is my AA code:
Code: | [ENABLE]
{$lua}
if syntaxcheck then return end
print('----- Begin -----')
local domain = mono_enumDomains()[1]
local rsvcinstance=readPointer('[[[pGameRoot]]+18]+[iRServiceOffset]')
local vsvcinstance=readPointer('[[[pGameRoot]]+18]+[iVServiceOffset]')
local count = readInteger('iItemsToSpawn')
print(string.format('Count: %d', count))
local rmethod=mono_findMethod('Assembly-CSharp','RService', 'GetRandom')
mono_compile_method(rmethod)
local vmethod=mono_findMethod('Assembly-CSharp','VService', 'SpawnNewV')
mono_compile_method(vmethod)
local vparams=mono_method_get_parameters(vmethod)
if (rsvc==0 or vsvc==0) then ShowMessage('Invalid pointer(s)?')
elseif rmethod==nil or rmethod==0 or vmethod==nil or vmethod==0 then ShowMessage('Failed to find a required method.')
elseif vparams==nil or vparams==0 then ShowMessage('Failed to get parameters.')
elseif count<0 and count>50 then ShowMessage('Count does not seem right.')
else
print('Loop...')
for i=1,count do
print('GetRandom...')
print('rmethod: '..string.format('%x', rmethod))
print('rsvcinstance: '..string.format('%x', rsvcinstance))
local ritem=mono_invoke_method(domain, rmethod, rsvcinstance, {})
print('SpawnNewV...')
print('vmethod: '..string.format('%x', vmethod))
print('vsvcinstance: '..string.format('%x', vsvcinstance))
mono_invoke_method(domain, vmethod, vsvcinstance, {{type = vtPointer, value = ritem}})
print('Done...')
end
end
{$asm}
[DISABLE]
|
The first part works where I get back a random item: when I comment out the second mono_invoke_method, I can check via CE that all pointers and classes look okay, even ritem (the random item returned from the first mono_invoke_method call) is valid.
However, when I uncomment the second mono_invoke_method, the game crashes (completely disappears).
Any help would be appreciated.
Thank you!
|
|