Europefan69
Member
- Aug 20, 2020
- 167
- 175
Thanks so much for the help! I just got back from vacation and took a break from this so I'm just now seeing this. I originally had trouble registering my Monobehaviour since this is the first time I'm using bepinex 6 for a Il2Cpp game so I thought this would be a "cheeky" way to avoid that but it seemed to just cause more headaches. If I Call ClassInjector.RegisterTypeInIl2Cpp<MyMonoBehaviour>() in my BasePlugin's load function, this crashes the game on launch withMany crashes are due to memory access violation. It looks like all of your code is in the BasePlugin. When your code is here, it is in the managed domain, and all references to Unity and ingame classes are unsafe because they are in the IL2CPP domain, which has a different garbage collector (IL2CPP has its own runtime, so this will be non-deterministic, which is why you may have a hard time tracking down crashes because they come and go). The managed CoreCLR domain also doesn't have proper access to many Unity API.
In IL2CPP BepInEx plugins, your code and HarmonyX patches should be in a MonoBehavior registered in IL2CPP domain with ClassInjector.RegisterTypeInIl2Cpp<T>(). Your BasePlugin should only be responsible for calling this method and adding the registered MonoBehavior. This way, your managed code will be integrated with IL2CPP GC, and you can safely access Unity/game classes. (I think Il2CppInterop will make sure your references implicitly use safe wrappers, but I don't know for sure. We don't need to worry about that though)
Also keep in mind that, if you do anything with reflection, you may still need to explicitly use Il2Cpp helper methods, even in a registered component in the IL2CPP domain.
You must be registered to see the links
[Warning:Il2CppInterop] Class::Init signatures have been exhausted, using a substitute!
[Warning:Il2CppInterop] GarbageCollector::RunFinalizer not found, disabling Il2CppObjectPool
in the LogOutput. Am I missing something or is this the incorrect way to register the class?
here is also the ErrorLog:
You don't have permission to view the spoiler content.
Log in or register now.