update handle

This commit is contained in:
chinosk
2026-06-11 21:33:45 +08:00
parent 2d809b4caa
commit 0ea432c854
2 changed files with 24 additions and 16 deletions
+22 -15
View File
@@ -381,7 +381,7 @@ namespace GakumasLocal::HookMain {
typedef std::unordered_set<std::wstring, TransparentStringHash, std::equal_to<void>> AssetPathsType;
std::map<std::string, AssetPathsType> CustomAssetBundleAssetPaths;
std::unordered_map<std::string, uint32_t> CustomAssetBundleHandleMap{};
std::unordered_map<std::string, uint64_t> CustomAssetBundleHandleMap{};
std::list<std::string> 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<void* (*)(void*)>(
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<void*>(extraAssetBundle);
AssetPathsType assetPath{};
Il2cppUtils::iterate_IEnumerable<Il2CppString*>(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<uint32_t>("il2cpp_gchandle_new", extraAssetBundle, false));
CustomAssetBundleHandleMap.emplace(i, UnityResolve::Invoke<uint64_t>("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<void*>("il2cpp_gchandle_get_target", bundleHandle);
static auto AssetBundle_LoadAsset = reinterpret_cast<void* (*)(void* _this, Il2CppString* name, Il2cppUtils::Il2CppReflectionType* type)>(
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<void*>(extraAssetBundle, Il2cppString::New(fontPath), Font_Type);
if (replaceFont)
{
ReplaceFontHandle = UnityResolve::Invoke<uint32_t>("il2cpp_gchandle_new", replaceFont, false);
ReplaceFontHandle = UnityResolve::Invoke<uint64_t>("il2cpp_gchandle_new", replaceFont, false);
}
else
{
+2 -1
View File
@@ -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");