Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Calling mono_invoke_method with returned argument

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 94

Joined: 14 Jul 2007
Posts: 3110

PostPosted: Sun Jan 28, 2024 9:53 am    Post subject: Calling mono_invoke_method with returned argument Reply with quote

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!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites