knah / Il2CppAssemblyUnhollower

A tool to generate Managed->IL2CPP proxy assemblies
GNU Lesser General Public License v3.0
500 stars 87 forks source link

System.ArgumentException: Base class UnityEngine.MonoBehaviour is value type and can't be inherited from #10

Closed LelouBil closed 3 years ago

LelouBil commented 3 years ago

I'm trying class injection but I keep having this error.

System.ArgumentException: Base class UnityEngine.MonoBehaviour is value type and can't be inherited from
  at UnhollowerRuntimeLib.ClassInjector.RegisterTypeInIl2Cpp[T] () [0x000c3] in <e23489bf60bd4989ae101f3462221c4c>:0
  at MyMods0c6c997e473c4c9fa6c7c23c8ef04755.Init.Setup () [0x00071] in <fca399b1c8814998958ecbbee0151af9>:0

What am I doing wrong ? Class being injected

public class ModMain : UnityEngine.MonoBehaviour
    {

        private void OnEnable()
        {
            System.Console.WriteLine("enabled yes");
        }

        public ModMain(IntPtr pointer) : base(pointer)
        {
        }
    }

Injector code

UnityVersionHandler.Initialize(2019, 4, 9);
ClassInjector.RegisterTypeInIl2Cpp<ModMain>();
knah commented 3 years ago

This is caused by the same struct mismatch issues as #8 - while there is a PR for some of these (#9) I'll likely rewrite that part for a more flexible approach in general

LelouBil commented 3 years ago

okay thanks

knah commented 3 years ago

99a080d includes a rewrite of struct handling and fixes #8, so this one might be fixed be fixed in 0.4.10.0 aswell. In general, native struct handling is a bit more streamlined now, so PRs for other specific version support would be welcome.