Il2CppInterop icon indicating copy to clipboard operation
Il2CppInterop copied to clipboard

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

Open Lionmeow opened this issue 1 year ago • 1 comments

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.

Lionmeow avatar Mar 02 '23 21:03 Lionmeow

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

karaok1 avatar Feb 20 '24 17:02 karaok1

Sounds like #135

ds5678 avatar Jul 15 '24 02:07 ds5678