Skip to content

Commit

Permalink
fix: lazy initializing - can't get class from * namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
chinosk6 committed Jul 5, 2024
1 parent 77fc61d commit 573bfb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/src/main/cpp/GakumasLocalify/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace GakumasLocal::HookMain {
UnityResolve::UnityType::Transform* cameraTransformCache = nullptr;
void CheckAndUpdateMainCamera() {
if (!Config::enableFreeCamera) return;
if (IsNativeObjectAlive(mainCameraCache)) return;
if (IsNativeObjectAlive(mainCameraCache) && IsNativeObjectAlive(cameraTransformCache)) return;

mainCameraCache = UnityResolve::UnityType::Camera::GetMain();
cameraTransformCache = mainCameraCache->GetTransform();
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/cpp/deps/UnityResolve/UnityResolve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,27 @@ class UnityResolve final {
}
}

static auto GetPClassFromUnknownNamespace(void* image, const char* klassName) -> void* {
const auto count = Invoke<int>("il2cpp_image_get_class_count", image);
for (auto i = 0; i < count; i++) {
const auto pClass = Invoke<void*>("il2cpp_image_get_class", image, i);
const auto className = Invoke<const char*>("il2cpp_class_get_name", pClass);
if (strcmp(className, klassName) == 0) {
return pClass;
}
}
return nullptr;
}

static auto FillClass_Il2ccpp(Assembly* assembly, const char* namespaze, const char* klassName) -> Class* {
auto image = Invoke<void*>("il2cpp_assembly_get_image", assembly->address);
const auto pClass = Invoke<void*>("il2cpp_class_from_name", image, namespaze, klassName);
void* pClass;
if (strcmp(namespaze, "*") == 0) {
pClass = GetPClassFromUnknownNamespace(image, klassName);
}
else {
pClass = Invoke<void*>("il2cpp_class_from_name", image, namespaze, klassName);
}
if (pClass == nullptr) return nullptr;
const auto pAClass = new Class();
pAClass->address = pClass;
Expand Down

0 comments on commit 573bfb8

Please sign in to comment.