BepInEx / Il2CppInterop

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

Abstract System.Type not being found after being directly or indirectly referenced. #81

Closed Lionmeow closed 1 month ago

Lionmeow commented 1 year ago

I've been working on a MelonLoader plugin for the game Slime Rancher 2. The game uses several abstract class for various behaviors like player movement, slime behavior, etc. Unhollower was unable to handle inheriting from abstract classes, but if you inherited from a class that inherited from the abstract class, you could use some Harmony patches to get it to work like it's being inherited.

When switching from Unhollower to Interop, this stopped working. Both directly inheriting from abstract classes as well as any offshoots of them are causing an error. Offshoot:

System.NullReferenceException: Couldn't find System.Type for Il2Cpp type: SlimeSubbehaviour, Assembly-CSharp
   at Il2CppInterop.Runtime.Injection.ClassInjector.SystemTypeFromIl2CppType(Il2CppTypeStruct* typePointer) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 1068
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(Type type, RegisterTypeOptions options) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 408
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(Type type) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 147
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp[T]() in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 142
   at MelonSRML.EntryPoint.OnInitializeMelon()
   at MelonLoader.MelonBase.LoaderInitialized() in D:\a\MelonLoader\MelonLoader\MelonLoader\Melons\MelonBase.cs:line 435

Directly:

System.ArgumentNullException: Value cannot be null. (Parameter 'name')
   at System.Type.GetMethod(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(Type type, RegisterTypeOptions options) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 406
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(Type type) in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 147
   at Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp[T]() in /home/runner/work/Il2CppInterop/Il2CppInterop/Il2CppInterop.Runtime/Injection/ClassInjector.cs:line 142
   at sr2melon.EntryPoint.OnGameContext(GameContext gameContext)
   at MelonSRML.Patches.GameContextModEventPatch.Prefix(GameContext __instance)

(SlimeSubbehaviour being an abstract class) In simpler terms, vanilla class X inherits from abstract vanilla class Y. With Unhollower, while modded class Z couldn't inherit from Y, it could inherit from X. This could be used to make a sort of pseudo-inheritance via Harmony. However, in Interop, the above error throws when Z inherits from either X or Y.

I'm unsure if this is a bug with Interop, or simply a limitation that didn't exist in Unhollower. However, due to inheriting from offshoots working in Unhollower, I'd assume that it's the former.

karaok1 commented 6 months ago

Have you been able to solve this? I have been facing a similar issue...

ds5678 commented 1 month ago

Sounds like #135