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

Closed
yukieiji opened this issue Feb 17, 2024 · 8 comments
Closed

Unable to get NativeClassPtr in some classes #115

yukieiji opened this issue Feb 17, 2024 · 8 comments
Labels
question Further information is requested

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.

@ds5678
Copy link
Collaborator

ds5678 commented Jul 14, 2024

@yukieiji did the advice from js6pak resolve your issue?

@yukieiji
Copy link
Author

yukieiji commented Jul 14, 2024

I have solved the problem, but I don't know how to find out if it is an Il2CppReferenceArray<T> from the Type.

@ds5678
Copy link
Collaborator

ds5678 commented Jul 14, 2024

Interfaces are reference types.

@ds5678 ds5678 added the question Further information is requested label Jul 15, 2024
@ds5678 ds5678 closed this as completed Jul 15, 2024
@yukieiji
Copy link
Author

For example, for Type Il2CppSystem.Collections.Generic.Dictionary<Collider2D, IUsable[]>, what code should I use?

@ds5678
Copy link
Collaborator

ds5678 commented Jul 15, 2024

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

@yukieiji
Copy link
Author

yukieiji commented Jul 15, 2024

How can I dynamically check that an Array is included and replace it with an Il2CppReferenceArray<T>?
I need to dynamically detect and replace the Array contained in the Type for this function to work.

@ds5678
Copy link
Collaborator

ds5678 commented Jul 15, 2024

GPT:

In C#, you can determine if a System.Type represents a value type by using the IsValueType property. This property returns a boolean value indicating whether the type is a value type. Value types include all primitive types (such as int, float, char, etc.), as well as struct types.

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

No branches or pull requests

3 participants