53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
#include "pch.h"
|
|
#include "Il2CppHelper.h"
|
|
|
|
const uint8_t* Il2CppHelper::FindMethodInHierarchy(Il2CppClass* klass, const std::string &methodName, const std::vector<std::string> 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<std::string> &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<uintptr_t*>(object);
|
|
|
|
return base_ptr + offset;
|
|
}
|