#include "pch.h" #include "Il2CppHelper.h" const uint8_t* Il2CppHelper::FindMethodInHierarchy(Il2CppClass* klass, const std::string &methodName, const std::vector paramCount) { const uint8_t* method = nullptr; while (klass != nullptr) { method = FindMethod(klass, methodName, paramCount); if(method) break; klass = Il2CppApi::ClassGetParent(klass); } return method; } const uint8_t* Il2CppHelper::FindMethod(Il2CppClass* klass, const std::string &name, const std::vector &arg_types) { Il2CppApi::ClassInit(klass); void* iter = nullptr; while (auto method = Il2CppApi::ClassGetMethods(klass, &iter)) { auto methodName = Il2CppApi::MethodGetName(method); if (methodName == name) { auto paramCount = Il2CppApi::MethodGetParamCount(method); if (paramCount == arg_types.size()) { bool fail = false; for (size_t i = 0; i < paramCount; ++i) { auto typeName = Il2CppApi::TypeGetName(Il2CppApi::MethodGetParam(method, i)); if (arg_types[i] != typeName) { fail = true; break; } } if (!fail) { return method; } } } } return nullptr; } uintptr_t* Il2CppHelper::GetFieldDataPtr(uintptr_t* field, Il2CppObject* object) { size_t offset = Il2CppApi::FieldGetOffset(field); uintptr_t* base_ptr = reinterpret_cast(object); return base_ptr + offset; }