Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #140 (AssetBundles cannot be loaded at runtime) #197

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading