From 0ea432c8541c70b6d0764195e3798b33fd25200c Mon Sep 17 00:00:00 2001 From: chinosk <2248589280@qq.com> Date: Thu, 11 Jun 2026 21:33:45 +0800 Subject: [PATCH] update handle --- src/GakumasLocalify/Hook.cpp | 37 +++++++++++++++++++++--------------- src/windowsPlatform.cpp | 3 ++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/GakumasLocalify/Hook.cpp b/src/GakumasLocalify/Hook.cpp index 46f8c29..a250b4f 100644 --- a/src/GakumasLocalify/Hook.cpp +++ b/src/GakumasLocalify/Hook.cpp @@ -381,7 +381,7 @@ namespace GakumasLocal::HookMain { typedef std::unordered_set> AssetPathsType; std::map CustomAssetBundleAssetPaths; - std::unordered_map CustomAssetBundleHandleMap{}; + std::unordered_map CustomAssetBundleHandleMap{}; std::list g_extra_assetbundle_paths{}; void LoadExtraAssetBundle() { @@ -394,9 +394,12 @@ namespace GakumasLocal::HookMain { // CustomAssetBundleAssetPaths.clear(); // assert(!ExtraAssetBundleHandle && ExtraAssetBundleAssetPaths.empty()); - static auto AssetBundle_GetAllAssetNames = reinterpret_cast( - Il2cppUtils::il2cpp_resolve_icall("UnityEngine.AssetBundle::GetAllAssetNames()") - ); + static auto AssetBundle_GetAllAssetNames = Il2cppUtils::GetMethod( + "UnityEngine.AssetBundleModule.dll", + "UnityEngine", + "AssetBundle", + "GetAllAssetNames" + ); for (const auto& i : g_extra_assetbundle_paths) { if (CustomAssetBundleHandleMap.contains(i)) continue; @@ -404,7 +407,7 @@ namespace GakumasLocal::HookMain { const auto extraAssetBundle = WinHooks::LoadAssetBundle(i); if (extraAssetBundle) { - const auto allAssetPaths = AssetBundle_GetAllAssetNames(extraAssetBundle); + const auto allAssetPaths = AssetBundle_GetAllAssetNames->Invoke(extraAssetBundle); AssetPathsType assetPath{}; Il2cppUtils::iterate_IEnumerable(allAssetPaths, [&assetPath](Il2CppString* path) { @@ -413,7 +416,7 @@ namespace GakumasLocal::HookMain { assetPath.emplace(path->start_char); }); CustomAssetBundleAssetPaths.emplace(i, assetPath); - CustomAssetBundleHandleMap.emplace(i, UnityResolve::Invoke("il2cpp_gchandle_new", extraAssetBundle, false)); + CustomAssetBundleHandleMap.emplace(i, UnityResolve::Invoke("il2cpp_gchandle_new", extraAssetBundle, false)); } else { @@ -422,7 +425,7 @@ namespace GakumasLocal::HookMain { } } - uint32_t GetBundleHandleByAssetName(std::wstring assetName) { + uint64_t GetBundleHandleByAssetName(std::wstring assetName) { for (const auto& i : CustomAssetBundleAssetPaths) { for (const auto& m : i.second) { if (std::equal(m.begin(), m.end(), assetName.begin(), assetName.end(), @@ -436,11 +439,11 @@ namespace GakumasLocal::HookMain { return NULL; } - uint32_t GetBundleHandleByAssetName(std::string assetName) { + uint64_t GetBundleHandleByAssetName(std::string assetName) { return GetBundleHandleByAssetName(utility::conversions::to_string_t(assetName)); } - uint32_t ReplaceFontHandle; + uint64_t ReplaceFontHandle; void* GetReplaceFont() { static auto FontClass = Il2cppUtils::GetClass("UnityEngine.TextRenderingModule.dll", "UnityEngine", "Font"); @@ -451,7 +454,7 @@ namespace GakumasLocal::HookMain { const auto fontPath = "assets/fonts/gkamszhfontmix.otf"; void* replaceFont{}; - const auto& bundleHandle = GetBundleHandleByAssetName(fontPath); + const auto bundleHandle = GetBundleHandleByAssetName(fontPath); if (bundleHandle) { if (ReplaceFontHandle) @@ -471,14 +474,18 @@ namespace GakumasLocal::HookMain { } const auto extraAssetBundle = UnityResolve::Invoke("il2cpp_gchandle_get_target", bundleHandle); - static auto AssetBundle_LoadAsset = reinterpret_cast( - Il2cppUtils::il2cpp_resolve_icall("UnityEngine.AssetBundle::LoadAsset_Internal(System.String,System.Type)") - );; + static auto AssetBundle_LoadAsset = Il2cppUtils::GetMethod( + "UnityEngine.AssetBundleModule.dll", + "UnityEngine", + "AssetBundle", + "LoadAsset_Internal", + { "System.String", "System.Type" } + ); - replaceFont = AssetBundle_LoadAsset(extraAssetBundle, Il2cppString::New(fontPath), Font_Type); + replaceFont = AssetBundle_LoadAsset->Invoke(extraAssetBundle, Il2cppString::New(fontPath), Font_Type); if (replaceFont) { - ReplaceFontHandle = UnityResolve::Invoke("il2cpp_gchandle_new", replaceFont, false); + ReplaceFontHandle = UnityResolve::Invoke("il2cpp_gchandle_new", replaceFont, false); } else { diff --git a/src/windowsPlatform.cpp b/src/windowsPlatform.cpp index 75c3aed..c63663d 100644 --- a/src/windowsPlatform.cpp +++ b/src/windowsPlatform.cpp @@ -206,7 +206,8 @@ namespace GakumasLocal::WinHooks { using Il2cppString = UnityResolve::UnityType::String; void* LoadAssetBundle(const std::string& path) { - Il2cppString* bundlePath = Il2cppString::New(path); + std::filesystem::path abs_path = std::filesystem::absolute(path).lexically_normal(); + Il2cppString* bundlePath = Il2cppString::New(abs_path.string()); static auto LoadFromFileAsync = Il2cppUtils::GetMethod("UnityEngine.AssetBundleModule.dll", "UnityEngine", "AssetBundle", "LoadFromFileAsync"); static auto get_assetBundle = Il2cppUtils::GetMethod("UnityEngine.AssetBundleModule.dll", "UnityEngine", "AssetBundleCreateRequest", "get_assetBundle");