From 3512c92a944a68812fa200e9679f3503e01752d8 Mon Sep 17 00:00:00 2001 From: Herp Derpinstine Date: Mon, 30 Sep 2024 00:16:12 -0600 Subject: [PATCH] Fixed an issue with Il2Cpp Class Injection Attributes causing exceptions to be thrown on Mono games --- MelonLoader/Attributes/RegisterTypeInIl2CppWithInterfaces.cs | 1 + MelonLoader/Core.cs | 3 +++ MelonLoader/Melons/MelonAssembly.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/MelonLoader/Attributes/RegisterTypeInIl2CppWithInterfaces.cs b/MelonLoader/Attributes/RegisterTypeInIl2CppWithInterfaces.cs index d0bbc1d1..5a1c679d 100644 --- a/MelonLoader/Attributes/RegisterTypeInIl2CppWithInterfaces.cs +++ b/MelonLoader/Attributes/RegisterTypeInIl2CppWithInterfaces.cs @@ -11,6 +11,7 @@ public class RegisterTypeInIl2CppWithInterfaces : Attribute //Naming violation? internal static List registrationQueue = new List(); internal static bool ready; internal bool LogSuccess = true; + internal Type[] Interfaces; internal bool GetInterfacesFromType; diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index 241e9491..d385ba6a 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -142,8 +142,11 @@ internal static int Start() return 1; AddUnityDebugLog(); + +#if NET6_0_OR_GREATER RegisterTypeInIl2Cpp.SetReady(); RegisterTypeInIl2CppWithInterfaces.SetReady(); +#endif MelonEvents.MelonHarmonyInit.Invoke(); MelonEvents.OnApplicationStart.Invoke(); diff --git a/MelonLoader/Melons/MelonAssembly.cs b/MelonLoader/Melons/MelonAssembly.cs index fd985a10..8806bdc0 100644 --- a/MelonLoader/Melons/MelonAssembly.cs +++ b/MelonLoader/Melons/MelonAssembly.cs @@ -290,8 +290,10 @@ public void LoadMelons() } } +#if NET6_0_OR_GREATER RegisterTypeInIl2Cpp.RegisterAssembly(Assembly); RegisterTypeInIl2CppWithInterfaces.RegisterAssembly(Assembly); +#endif if (rottenMelons.Count != 0) {