BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
185 stars 59 forks source link

Unable to get NativeClassPtr in some classes #115

Closed yukieiji closed 1 month ago

yukieiji commented 6 months ago

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



This error is caused by the original method of retrieving `NativeClassPtr` with a function, but the same error occurs when using `Il2CppClassPointerStore.GetNativeClassPointer`
js6pak commented 5 months ago

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

ds5678 commented 1 month ago

@yukieiji did the advice from js6pak resolve your issue?

yukieiji commented 1 month ago

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

ds5678 commented 1 month ago

Interfaces are reference types.

yukieiji commented 1 month ago

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

ds5678 commented 1 month ago

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

yukieiji commented 1 month ago

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 commented 1 month ago

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.