HenryEx

fireMonoMethodBySignature

Aug 18th, 2026
4,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | Source Code | 0 0
  1. --- Call Mono function by signature (if there's multiple with the same name); requires getMethodBySignature
  2. -- Based on: https://opencheattables.com/viewtopic.php?t=475
  3. -- EX: valueReturned = fireMonoMethodBySignature("SaveManager", "get_playerData", {100, true}, "bool, single")
  4. -- fireMonoMethodBySignature(className: string OR number, methodName: string, instance: number, args: table{any}, signature: string)
  5. -- @param className: name (string) or id (number) of the class containing the method
  6. -- @param methodName: name of the method to execute
  7. -- @param instance: address of the class instance to execute from/on
  8. -- @param args: table of arguments to the method
  9. -- @param signature: string of comma-separated parameter types for the method
  10. -- @return Result of invoking the method
  11.  
  12. function fireMonoMethodBySignature(className, methodName, instance, args, signature)
  13.   if type(args) ~= "table" then error("Args is not a table, use {}") end
  14.   if type(signature) ~= "string" then error("Signature must be a string") end
  15.  
  16.   local classId = type(className) == 'number' and className or mono_findClass("", className)
  17.   if not classId or classId == 0 then error("No class found") end
  18.  
  19.   local methodId = getMethodBySignature(classId, methodName, signature)
  20.   if not methodId or methodId == 0 then error("No method found") end
  21.  
  22.   instance = instance or 0
  23.   if instance == 0 then
  24.     instance = mono_class_findInstancesOfClassListOnly(nil, classId)[1]
  25.   end
  26.   if not instance or instance == 0 then error("No instance found") end
  27.  
  28.   local params = mono_method_get_parameters(methodId).parameters
  29.   if #args ~= #params then error("Found " .. #args .. " args, need " .. #params .. " args") end
  30.  
  31.   local newArgs = {}
  32.   for i, v in pairs(params) do
  33.     newArgs[i] = {
  34.       type = monoTypeToVartypeLookup[v.type],
  35.       value = args[i]
  36.     }
  37.   end
  38.  
  39.   return mono_invoke_method(nil, methodId, instance, newArgs)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment