From 932c279f10e5a356825a7f8db6c797ac06e54cc4 Mon Sep 17 00:00:00 2001 From: Ji O Date: Tue, 1 Nov 2022 01:16:13 +0900 Subject: [PATCH] Enhanced load custom asset --- src/hook.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hook.cpp b/src/hook.cpp index 62fd403..dbbbac4 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -132,7 +132,7 @@ namespace return reinterpret_cast(il2cpp_symbols::get_method_pointer("mscorlib.dll", "System", "Enum", "ToUInt64", 1))(runtimeEnum); } - unsigned long GetTextIdByName(string name) + unsigned long GetTextIdByName(const string& name) { return GetEnumValue(ParseEnum(GetRuntimeType("umamusume.dll", "Gallop", "TextId"), name)); } @@ -1237,10 +1237,19 @@ namespace void* assetbundle_load_asset_orig = nullptr; Il2CppObject* assetbundle_load_asset_hook(Il2CppObject* _this, Il2CppString* name, const Il2CppType* type) { - string u8Name = local::wide_u8(name->start_char); - if (find(replaceAssetNames.begin(), replaceAssetNames.end(), u8Name) != replaceAssetNames.end()) + stringstream pathStream(local::wide_u8(name->start_char)); + string segment; + vector splited; + while (getline(pathStream, segment, '/')) + { + splited.emplace_back(segment); + } + auto &fileName = splited.back(); + if (find_if(replaceAssetNames.begin(), replaceAssetNames.end(), [fileName](const string& item) { + return item.find(fileName) != string::npos; + }) != replaceAssetNames.end()) { - return reinterpret_cast(assetbundle_load_asset_orig)(replaceAssets, name, type); + return reinterpret_cast(assetbundle_load_asset_orig)(replaceAssets, il2cpp_string_new(fileName.data()), type); } auto obj = reinterpret_cast(assetbundle_load_asset_orig)(_this, name, type); if (obj->klass->name == "GameObject"s)