Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Call Mono function by signature (if there's multiple with the same name); requires getMethodBySignature
- -- Based on: https://opencheattables.com/viewtopic.php?t=475
- -- EX: valueReturned = fireMonoMethodBySignature("SaveManager", "get_playerData", {100, true}, "bool, single")
- -- fireMonoMethodBySignature(className: string OR number, methodName: string, instance: number, args: table{any}, signature: string)
- -- @param className: name (string) or id (number) of the class containing the method
- -- @param methodName: name of the method to execute
- -- @param instance: address of the class instance to execute from/on
- -- @param args: table of arguments to the method
- -- @param signature: string of comma-separated parameter types for the method
- -- @return Result of invoking the method
- function fireMonoMethodBySignature(className, methodName, instance, args, signature)
- if type(args) ~= "table" then error("Args is not a table, use {}") end
- if type(signature) ~= "string" then error("Signature must be a string") end
- local classId = type(className) == 'number' and className or mono_findClass("", className)
- if not classId or classId == 0 then error("No class found") end
- local methodId = getMethodBySignature(classId, methodName, signature)
- if not methodId or methodId == 0 then error("No method found") end
- instance = instance or 0
- if instance == 0 then
- instance = mono_class_findInstancesOfClassListOnly(nil, classId)[1]
- end
- if not instance or instance == 0 then error("No instance found") end
- local params = mono_method_get_parameters(methodId).parameters
- if #args ~= #params then error("Found " .. #args .. " args, need " .. #params .. " args") end
- local newArgs = {}
- for i, v in pairs(params) do
- newArgs[i] = {
- type = monoTypeToVartypeLookup[v.type],
- value = args[i]
- }
- end
- return mono_invoke_method(nil, methodId, instance, newArgs)
- end
Advertisement
Add Comment
Please, Sign In to add comment