invoke overloaded mono method

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
What is cheating?
What is cheating?
Posts: 1
Joined: Sat Apr 15, 2023 7:11 pm
Reputation: 2

invoke overloaded mono method

Post by koopa539 »

Hi! I am trying to find the player's CharacterBody entity in Risk of Rain 2 using the mono API and it crashes on the `mono_class_findMethod` call.
Most likely I am doing it wrong, below is the code. Can anyone spot something?
NB: It works when I invoke the method using the mono dissect GUI and use the address I get from `readQword(body + inventoryOffset)`

Code: Select all

debugInstanceLookup = true

-- member offsets for RoR2.CharacterBody
local bodyOffset = 0x30
local inventoryOffset = 0x70

function getBody()
  local charBody = mono_findClass('RoR2', 'CharacterBody')
  local charController = mono_findClass('RoR2', 'PlayerCharacterMasterController')
  print(("found controller at %x"):format(charController))
  local maybeControllerEntities = mono_class_findInstancesOfClassListOnly('RoR2', charController)
  local maybeBodyEntities = mono_class_findInstancesOfClassListOnly('RoR2', charBody)
  for k,v in ipairs(maybeControllerEntities) do
    local body = readQword(v + bodyOffset)
    for x,maybeBody in ipairs(maybeBodyEntities) do
      if(body == maybeBody) then -- controller body matches the body entity. that's a bingo
        print(("found body at %x"):format(body))
        return body
local body = getBody()
local inventory = readQword(body + inventoryOffset)
print(("Inventory %x"):format(inventory))

-- local giveItem = mono_class_findMethod(inventory, 'GiveItem')
local giveRandomItems = mono_class_findMethod(inventory, 'GiveRandomItems')
mono_invoke_method('', giveRandomItems, inventory, {{type=int, value=10}})
Also I was wondering what if there is an overloaded function, how will `mono_class_findMethod` know which one to get?
For example `GiveItem` exists twice in the `Inventory` objects. One expects an item and the other an item index.
Last question, how to get the function signatures in LUA via the monopipe? Thanks!

PS: Not sure whether this is even a good idea how to get the address I need or if I am overcomplicating things. Please feel free to let me know if I should do things differently, cheers.

Expert Cheater
Expert Cheater
Posts: 293
Joined: Sat Mar 04, 2017 7:28 am
Reputation: 232

Re: invoke overloaded mono method

Post by TheByteSize »

This might help you if you trying to differentiate overload methods.

Post Reply

Who is online

Users browsing this forum: No registered users