예제 #1
0
        internal static int PreStart()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                GameVersionHandler.Setup();
            }

            MelonHandler.OnApplicationEarlyStart();

            if (MelonUtils.IsGameIl2Cpp())
            {
                if (MelonLaunchOptions.Core.EnableAssemblyGeneration)
                {
                    if (!Il2CppAssemblyGenerator.Run())
                    {
                        return(1);
                    }
                }

                HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyIl2CppMethodPatcher.TryResolve;

                GameVersionHandler.Setup();
            }

            return(0);
        }
예제 #2
0
        public static void RegisterAssembly(Assembly asm)
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                return;
            }
            IEnumerable <Type> typeTbl = asm.GetValidTypes();

            if ((typeTbl == null) || (typeTbl.Count() <= 0))
            {
                return;
            }
            foreach (Type type in typeTbl)
            {
                object[] attTbl = type.GetCustomAttributes(typeof(RegisterTypeInIl2Cpp), false);
                if ((attTbl == null) || (attTbl.Length <= 0))
                {
                    continue;
                }
                RegisterTypeInIl2Cpp att = (RegisterTypeInIl2Cpp)attTbl[0];
                if (att == null)
                {
                    continue;
                }
                UnhollowerSupport.RegisterTypeInIl2CppDomain(type, att.LogSuccess);
            }
        }
예제 #3
0
        private static int PreStart()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                GameVersionHandler.Setup();
            }

            MelonHandler.OnApplicationEarlyStart();

            return(MelonStartScreen.LoadAndRun(Il2CppGameSetup));
        }
예제 #4
0
        internal static bool Initialize()
        {
            MelonLogger.Msg("Loading Support Module...");

            if (!MelonUtils.IsGameIl2Cpp())
            {
                throw new Exception("Non-IL2CPP MelonLoader plugins are currently not supported");
            }

            Interface = SM_Il2Cpp.Main.Initialize(new SupportModule_From());
            return(true);
        }
예제 #5
0
 public static void RegisterTypeInIl2CppDomain(Type type, bool logSuccess)
 {
     if (!MelonUtils.IsGameIl2Cpp())
     {
         throw new Exception("RegisterTypeInIl2CppDomain can't be used on Non-Il2Cpp Games");
     }
     if (type == null)
     {
         throw new NullReferenceException("The type cannot be null.");
     }
     ClassInjectorRegisterTypeInIl2Cpp.Invoke(null, new object[] { type, logSuccess });
 }
예제 #6
0
 public static int?GetIl2CppMethodCallerCount(MethodBase original)
 {
     if (!MelonUtils.IsGameIl2Cpp())
     {
         throw new Exception("GetIl2CppMethodCallerCount can't be used on Non-Il2Cpp Games");
     }
     object[] callerCountAttributes = original.GetCustomAttributes(Il2CppCallerCountAttributeType, false);
     if (callerCountAttributes.Length != 1)
     {
         return(null);
     }
     return((int)Il2CppCallerCountField.GetValue(callerCountAttributes[0]));
 }
예제 #7
0
        internal static bool Initialize()
        {
            MelonLogger.Msg("Loading Support Module...");
            string BaseDirectory = Path.Combine(Path.Combine(Path.Combine(MelonUtils.GameDirectory, "MelonLoader"), "Dependencies"), "SupportModules");

            if (!Directory.Exists(BaseDirectory))
            {
                MelonLogger.Error("Failed to Find SupportModules Directory!");
                return(false);
            }
            string ModuleName = (MelonUtils.IsGameIl2Cpp() ? "Il2Cpp.dll"
                : (File.Exists(Path.Combine(MelonUtils.GetManagedDirectory(), "UnityEngine.CoreModule.dll")) ? "Mono.dll"
                : (IsOldUnity() ? "Mono.Pre-5.dll"
                : "Mono.Pre-2017.dll")));
            string ModulePath = Path.Combine(BaseDirectory, ModuleName);

            if (!File.Exists(ModulePath))
            {
                MelonLogger.Error("Failed to Find Support Module " + ModuleName + "!");
                return(false);
            }
            try
            {
                Assembly assembly = Assembly.LoadFrom(ModulePath);
                if (assembly == null)
                {
                    MelonLogger.Error("Failed to Load Assembly from " + ModuleName + "!");
                    return(false);
                }
                Type type = assembly.GetType("MelonLoader.Support.Main");
                if (type == null)
                {
                    MelonLogger.Error("Failed to Get Type MelonLoader.Support.Main!");
                    return(false);
                }
                MethodInfo method = type.GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Static);
                if (method == null)
                {
                    MelonLogger.Error("Failed to Get Method Initialize!");
                    return(false);
                }
                Interface = (ISupportModule_To)method.Invoke(null, new object[] { new SupportModule_From() });
                if (Interface == null)
                {
                    MelonLogger.Error("Failed to Initialize Interface!");
                    return(false);
                }
            }
            catch (Exception ex) { MelonLogger.Error(ex.ToString()); return(false); }
            return(true);
        }
예제 #8
0
        private static int PreStart()
        {
            MelonHandler.OnApplicationEarlyStart();

            if (!Il2CppAssemblyGenerator.Run())
            {
                return(1);
            }

            if (MelonUtils.IsGameIl2Cpp())
            {
                HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyIl2CppMethodPatcher.TryResolve;
            }

            return(0);
        }
예제 #9
0
 public static T Il2CppObjectPtrToIl2CppObject <T>(IntPtr ptr)
 {
     if (!MelonUtils.IsGameIl2Cpp())
     {
         throw new Exception("Il2CppObjectPtrToIl2CppObject can't be used on Non-Il2Cpp Games");
     }
     if (ptr == IntPtr.Zero)
     {
         throw new NullReferenceException("The ptr cannot be IntPtr.Zero.");
     }
     if (!IsGeneratedAssemblyType(typeof(T)))
     {
         throw new NullReferenceException("The type must be a Generated Assembly Type.");
     }
     return((T)typeof(T).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(IntPtr) }, new ParameterModifier[0]).Invoke(new object[] { ptr }));
 }
예제 #10
0
        private static int Il2CppGameSetup()
        {
            if (MelonUtils.IsGameIl2Cpp())
            {
                if (!Il2CppAssemblyGenerator.Run())
                {
                    return(1);
                }

                HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyIl2CppMethodPatcher.TryResolve;

                GameVersionHandler.Setup();
            }

            return(0);
        }
        internal static void Load()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                return;
            }

            MelonLogger.Msg("Loading Il2CppAssemblyGenerator...");

            string BaseDirectory = Path.Combine(Path.Combine(Path.Combine(MelonUtils.GameDirectory, "MelonLoader"), "Dependencies"), "Il2CppAssemblyGenerator");

            if (!Directory.Exists(BaseDirectory))
            {
                MelonLogger.Error("Failed to Find Il2CppAssemblyGenerator Directory!");
                return;
            }

            string AssemblyPath = Path.Combine(BaseDirectory, FileNameWithExtension);

            if (!File.Exists(AssemblyPath))
            {
                MelonLogger.Error($"Failed to Find {FileNameWithExtension}!");
                return;
            }

            try
            {
                asm = Assembly.LoadFrom(AssemblyPath);
                if (asm == null)
                {
                    MelonLogger.ThrowInternalFailure($"Failed to Load Assembly for {FileNameWithExtension}!");
                    return;
                }

                AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver;

                Type type = asm.GetType("MelonLoader.Il2CppAssemblyGenerator.Core");
                if (type == null)
                {
                    MelonLogger.ThrowInternalFailure($"Failed to Get Type for MelonLoader.Il2CppAssemblyGenerator.Core!");
                    return;
                }

                RunMethod = type.GetMethod("Run", BindingFlags.NonPublic | BindingFlags.Static);
            }
            catch (Exception ex) { MelonLogger.ThrowInternalFailure($"Il2CppAssemblyGenerator Exception: {ex}"); }
        }
예제 #12
0
        public static FieldInfo MethodBaseToIl2CppFieldInfo(MethodBase method)
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                throw new Exception("MethodBaseToIl2CppFieldInfo can't be used on Non-Il2Cpp Games");
            }
            if (method == null)
            {
                throw new NullReferenceException("The method cannot be null.");
            }
            FieldInfo methodPtr = (FieldInfo)GetIl2CppMethodInfoPointerFieldForGeneratedMethod.Invoke(null, new object[] { method });

            if (methodPtr == null)
            {
                throw new NotSupportedException($"Cannot get IntPtr for {method.Name} as there is no corresponding IL2CPP method");
            }
            return(methodPtr);
        }
        internal static bool Run()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                return(true);
            }

            if (RunMethod != null)
            {
                DisableCloseButton();
                int returnval = (int)RunMethod.Invoke(null, new object[0]);
                EnableCloseButton();
                Fixes.ApplicationBase.Run(AppDomain.CurrentDomain);
                return(returnval == 0);
            }

            return(false);
        }
예제 #14
0
        static UnhollowerSupport()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                return;
            }
            Assembly UnhollowerBaseLib = Assembly.Load("UnhollowerBaseLib");

            if (UnhollowerBaseLib == null)
            {
                MelonLogger.ThrowInternalFailure("Failed to Load Assembly for UnhollowerBaseLib!");
                return;
            }
            Il2CppObjectBaseType        = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Il2CppObjectBase");
            Il2CppMethodInfoType        = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Runtime.Il2CppMethodInfo");
            Il2CppObjectBaseToPtrMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("Il2CppObjectBaseToPtr");
            Il2CppStringToManagedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("Il2CppStringToManaged");
            ManagedStringToIl2CppMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP").GetMethod("ManagedStringToIl2Cpp");
            GetIl2CppMethodInfoPointerFieldForGeneratedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.UnhollowerUtils").GetMethod("GetIl2CppMethodInfoPointerFieldForGeneratedMethod");
            Il2CppCallerCountAttributeType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Attributes.CallerCountAttribute");
            Il2CppCallerCountField         = Il2CppCallerCountAttributeType.GetField("Count", BindingFlags.Public | BindingFlags.Instance);
        }
예제 #15
0
        private static int Start()
        {
            bHaptics.Start();

            MelonHandler.OnApplicationStart_Plugins();
            MelonHandler.LoadMods();
            MelonHandler.OnPreSupportModule();

            if (!SupportModule.Setup())
            {
                return(1);
            }

            if (MelonUtils.IsGameIl2Cpp())
            {
                HarmonyLib.Public.Patching.PatchManager.ResolvePatcher += HarmonyIl2CppMethodPatcher.TryResolve;
            }
            MelonCompatibilityLayer.SetupModules(MelonCompatibilityLayer.SetupType.OnApplicationStart);
            AddUnityDebugLog();
            MelonHandler.OnApplicationStart_Mods();
            //MelonStartScreen.DisplayModLoadIssuesIfNeeded();

            return(0);
        }
예제 #16
0
        static UnhollowerSupport()
        {
            if (!MelonUtils.IsGameIl2Cpp())
            {
                return;
            }
            Assembly UnhollowerBaseLib = Assembly.Load("UnhollowerBaseLib");

            if (UnhollowerBaseLib == null)
            {
                MelonLogger.ThrowInternalFailure("Failed to Load Assembly for UnhollowerBaseLib!");
                return;
            }
            IL2CPPType                        = UnhollowerBaseLib.GetType("UnhollowerBaseLib.IL2CPP");
            Il2CppObjectBaseType              = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Il2CppObjectBase");
            CopyMethodInfoStructMethod        = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Runtime.UnityVersionHandler").GetMethod("CopyMethodInfoStruct");
            Il2CppObjectBaseToPtrMethod       = IL2CPPType.GetMethod("Il2CppObjectBaseToPtr");
            Il2CppStringToManagedMethod       = IL2CPPType.GetMethod("Il2CppStringToManaged");
            ManagedStringToIl2CppMethod       = IL2CPPType.GetMethod("ManagedStringToIl2Cpp");
            ClassInjectorRegisterTypeInIl2Cpp = UnhollowerBaseLib.GetType("UnhollowerRuntimeLib.ClassInjector").GetMethods().First(x => x.Name.Equals("RegisterTypeInIl2Cpp") && !x.IsGenericMethod && (x.GetParameters().Count() == 2));
            GetIl2CppMethodInfoPointerFieldForGeneratedMethod = UnhollowerBaseLib.GetType("UnhollowerBaseLib.UnhollowerUtils").GetMethod("GetIl2CppMethodInfoPointerFieldForGeneratedMethod");
            Il2CppCallerCountAttributeType = UnhollowerBaseLib.GetType("UnhollowerBaseLib.Attributes.CallerCountAttribute");
            Il2CppCallerCountField         = Il2CppCallerCountAttributeType.GetField("Count", BindingFlags.Public | BindingFlags.Instance);
        }
 public static bool IsIl2CppGame() => MelonUtils.IsGameIl2Cpp();
예제 #18
0
 private static int Il2CppGameSetup()
 => (MelonUtils.IsGameIl2Cpp() &&
     !Il2CppAssemblyGenerator.Run())
         ? 1 : 0;