Skip to content

Commit 7218415

Browse files
committed
Fix bundle loading
1 parent 6836cb2 commit 7218415

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

src/FPSCounter.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "UnityEngine/AssetBundleCreateRequest.hpp"
66
#include "UnityEngine/AssetBundleRequest.hpp"
77
#include "GraphicsTweaksConfig.hpp"
8+
#include "UnityEngine/Bindings/ManagedSpanWrapper.hpp"
89

910
#include "assets.hpp"
1011

@@ -46,12 +47,31 @@ namespace GraphicsTweaks
4647
co_return;
4748
}
4849

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+
4965
custom_types::Helpers::Coroutine FPSCounter::LoadBundleFromMemoryAsync(ArrayW<uint8_t> bytes, UnityEngine::AssetBundle*& out)
5066
{
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+
}
5374

54-
auto req = assetBundle_LoadFromMemoryAsync(bytes, 0);
5575
req->set_allowSceneActivation(true);
5676
while (!req->get_isDone())
5777
co_yield nullptr;

0 commit comments

Comments
 (0)