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

Unable to get NativeClassPtr in some classes #115

Open
yukieiji opened this issue Feb 17, 2024 · 1 comment
Open

Unable to get NativeClassPtr in some classes #115

yukieiji opened this issue Feb 17, 2024 · 1 comment

Comments

@yukieiji
Copy link

yukieiji commented Feb 17, 2024

When I try to get NativeClassPtr of a class like Il2cppSystem.Collection.Generic.Dictionary<Collider2D, IUsable[]>(in AmongUs), I get the following error.

  • error log
[Error  :Il2CppInterop] Exception in IL2CPP-to-Managed trampoline, not passing it to il2cpp: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'Il2CppInterop.Runtime.Il2CppClassPointerStore`1' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Il2CppSystem.Collections.Generic.Dictionary`2' threw an exception.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Il2CppInterop.Runtime.Injection.Hooks.Class_FromIl2CppType_Hook.Hook(Il2CppType* type, Boolean throwOnError) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/Hooks/Class_FromIl2CppType_Hook.cs:line 33
   at Il2CppInterop.Runtime.IL2CPP.il2cpp_runtime_invoke(IntPtr method, IntPtr obj, Void** param, IntPtr& exc)
   at Il2CppSystem.Type.internal_from_handle(IntPtr handle)
   at Il2CppSystem.Collections.Generic.Dictionary`2..cctor()
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(QCallTypeHandle type)
   at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type)
   at Il2CppInterop.Runtime.Il2CppClassPointerStore`1..cctor() in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Il2CppClassPointerStore.cs:line 42
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at System.RuntimeFieldHandle.GetValue(RtFieldInfo field, Object instance, RuntimeType fieldType, RuntimeType declaringType, Boolean& domainInitialized)
   at System.Reflection.RtFieldInfo.GetValue(Object obj)
   at UniverseLib.Il2CppReflection.Il2CppTypeNotNull(Type type, IntPtr& il2cppPtr)
   at UniverseLib.Il2CppReflection.Internal_TryCast(Object obj, Type toType)
   at UniverseLib.ReflectionExtensions.TryCast(Object obj)
   at UnityExplorer.CacheObject.CacheObjectBase.SetValueFromSource(Object value)
   at UnityExplorer.CacheObject.CacheMember.Evaluate()
   at UnityExplorer.CacheObject.CacheMember.TryAutoEvaluateIfUnitialized(CacheObjectCell objectcell)
   at UnityExplorer.CacheObject.CacheObjectBase.SetDataToCell(CacheObjectCell cell)
   at UnityExplorer.CacheObject.CacheObjectControllerHelper.SetCell(CacheObjectCell cell, Int32 index, IList cachedEntries, Action`1 onDataSetToCell)
   at UnityExplorer.Inspectors.ReflectionInspector.SetCell(CacheMemberCell cell, Int32 index)
   at UniverseLib.UI.Widgets.ScrollView.ScrollPool`1.SetCell(T cachedCell, Int32 dataIndex)
   at UniverseLib.UI.Widgets.ScrollView.ScrollPool`1.InitCoroutine(Action onHeightChangedListener)+MoveNext()
   at UniverseLib.Runtime.Il2Cpp.Il2CppManagedEnumerator.MoveNext()
   at Trampoline_ByteThisUniverseLib.Runtime.Il2Cpp.Il2CppManagedEnumeratorMoveNext(IntPtr , Il2CppMethodInfo* )

This error is caused by the original method of retrieving NativeClassPtr with a function, but the same error occurs when using Il2CppClassPointerStore.GetNativeClassPointer

@js6pak
Copy link
Member

js6pak commented Feb 25, 2024

Try Il2CppSystem.Collections.Generic.Dictionary<Collider2D, Il2CppReferenceArray<IUsable>> instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants