|
5 | 5 | #include "UnityEngine/AssetBundleCreateRequest.hpp" |
6 | 6 | #include "UnityEngine/AssetBundleRequest.hpp" |
7 | 7 | #include "GraphicsTweaksConfig.hpp" |
| 8 | +#include "UnityEngine/Bindings/ManagedSpanWrapper.hpp" |
8 | 9 |
|
9 | 10 | #include "assets.hpp" |
10 | 11 |
|
@@ -46,12 +47,31 @@ namespace GraphicsTweaks |
46 | 47 | co_return; |
47 | 48 | } |
48 | 49 |
|
| 50 | + ::UnityEngine::AssetBundleCreateRequest* LoadBundleFromMemoryAsync_Internal(ArrayW<uint8_t> bytes, uint32_t crc = 0) { |
| 51 | + using AssetBundle_LoadFromMemoryAsync = function_ptr_t<void *, ByRef<UnityEngine::Bindings::ManagedSpanWrapper>, uint32_t>; |
| 52 | + static AssetBundle_LoadFromMemoryAsync assetBundle_LoadFromMemoryAsync = reinterpret_cast<AssetBundle_LoadFromMemoryAsync>(il2cpp_functions::resolve_icall("UnityEngine.AssetBundle::LoadFromMemoryAsync_Internal_Injected")); |
| 53 | + CRASH_UNLESS(assetBundle_LoadFromMemoryAsync); |
| 54 | + |
| 55 | + auto *managedSpanWrapper = new UnityEngine::Bindings::ManagedSpanWrapper(bytes->begin(), bytes.size()); |
| 56 | + |
| 57 | + void* request = assetBundle_LoadFromMemoryAsync(*managedSpanWrapper, crc); |
| 58 | + if (!request) |
| 59 | + { |
| 60 | + return nullptr; |
| 61 | + } |
| 62 | + return UnityEngine::AssetBundleCreateRequest::BindingsMarshaller::ConvertToManaged(request); |
| 63 | + } |
| 64 | + |
49 | 65 | custom_types::Helpers::Coroutine FPSCounter::LoadBundleFromMemoryAsync(ArrayW<uint8_t> bytes, UnityEngine::AssetBundle*& out) |
50 | 66 | { |
51 | | - using AssetBundle_LoadFromMemoryAsync = function_ptr_t<UnityEngine::AssetBundleCreateRequest*, ArrayW<uint8_t>, int>; |
52 | | - static AssetBundle_LoadFromMemoryAsync assetBundle_LoadFromMemoryAsync = reinterpret_cast<AssetBundle_LoadFromMemoryAsync>(il2cpp_functions::resolve_icall("UnityEngine.AssetBundle::LoadFromMemoryAsync_Internal")); |
| 67 | + auto *req = LoadBundleFromMemoryAsync_Internal(bytes); |
| 68 | + if (!req) |
| 69 | + { |
| 70 | + ERROR("Failed to create AssetBundleCreateRequest!"); |
| 71 | + out = nullptr; |
| 72 | + co_return; |
| 73 | + } |
53 | 74 |
|
54 | | - auto req = assetBundle_LoadFromMemoryAsync(bytes, 0); |
55 | 75 | req->set_allowSceneActivation(true); |
56 | 76 | while (!req->get_isDone()) |
57 | 77 | co_yield nullptr; |
|
0 commit comments