Skip to content

Commit

Permalink
Fix issue #140 (AssetBundles cannot be loaded at runtime) (#197)
Browse files Browse the repository at this point in the history
* Fix issue #140 (AssetBundles cannot be loaded at runtime)

* Revert Il2CppObjectPool.cs and change incorrect typeof

* Revert typeof changes and correction IL code comment
  • Loading branch information
aceman1209 authored Jan 4, 2025
1 parent ba67c11 commit 3f97933
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Il2CppInterop.Runtime/InteropTypes/Il2CppObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public T Unbox<T>() where T : unmanaged
private static readonly Type[] _intPtrTypeArray = { typeof(IntPtr) };
private static readonly MethodInfo _getUninitializedObject = typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.GetUninitializedObject))!;
private static readonly MethodInfo _getTypeFromHandle = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle))!;
private static readonly MethodInfo _createGCHandle = typeof(Il2CppObjectBase).GetMethod(nameof(CreateGCHandle))!;
private static readonly FieldInfo _isWrapped = typeof(Il2CppObjectBase).GetField(nameof(isWrapped))!;
private static readonly MethodInfo _createGCHandle = typeof(Il2CppObjectBase).GetMethod(nameof(CreateGCHandle), BindingFlags.Instance | BindingFlags.NonPublic)!;
private static readonly FieldInfo _isWrapped = typeof(Il2CppObjectBase).GetField(nameof(isWrapped), BindingFlags.Instance | BindingFlags.NonPublic)!;

internal static class InitializerStore<T>
{
Expand All @@ -112,7 +112,7 @@ private static Func<IntPtr, T> Create()
// However, it could be be user-made or implicit
// In that case we set the GCHandle and then call the ctor and let GC destroy any objects created by DerivedConstructorPointer

// var obj = (T)FormatterServices.GetUninitializedObject(type);
// var obj = (T)RuntimeHelpers.GetUninitializedObject(type);
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, _getTypeFromHandle);
il.Emit(OpCodes.Call, _getUninitializedObject);
Expand All @@ -126,7 +126,7 @@ private static Func<IntPtr, T> Create()
// obj.isWrapped = true;
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Ldc_I4_1);
il.Emit(OpCodes.Stsfld, _isWrapped);
il.Emit(OpCodes.Stfld, _isWrapped);

var parameterlessConstructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
if (parameterlessConstructor != null)
Expand Down

0 comments on commit 3f97933

Please sign in to comment.