コード例 #1
0
        private static void Initialize()
        {
            if (string.IsNullOrEmpty(AppDomain.CurrentDomain.BaseDirectory))
            {
                ((AppDomainSetup)typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(AppDomain.CurrentDomain, new object[0])).ApplicationBase = Imports.GetGameDirectory();
            }
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;

            CurrentGameAttribute = new MelonModGameAttribute(Imports.GetCompanyName(), Imports.GetProductName());
            UnityVersion         = GetUnityFileVersion();

            if (Imports.IsIl2CppGame())
            {
                IsVRChat    = CurrentGameAttribute.IsGame("VRChat", "VRChat");
                IsBoneworks = CurrentGameAttribute.IsGame("Stress Level Zero", "BONEWORKS");
            }

            if (!Imports.IsDebugMode() && Imports.IsConsoleEnabled())
            {
                Console.Enabled = true;
                Console.Create();
            }

            if (!Imports.IsIl2CppGame() || AssemblyGenerator.Main.Initialize())
            {
                HasGeneratedAssembly = true;
            }
            else
            {
                Imports.UNLOAD_MELONLOADER();
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: charlesdeepk/MelonLoader
        private static void Initialize()
        {
            if (string.IsNullOrEmpty(AppDomain.CurrentDomain.BaseDirectory))
            {
                ((AppDomainSetup)typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(AppDomain.CurrentDomain, new object[0])).ApplicationBase = Imports.GetGameDirectory();
            }
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;

            CurrentGameAttribute = new MelonModGameAttribute(Imports.GetCompanyName(), Imports.GetProductName());
            UnityVersion         = GetUnityFileVersion();

            if (Imports.IsIl2CppGame())
            {
                IsVRChat    = CurrentGameAttribute.IsGame("VRChat", "VRChat");
                IsBoneworks = CurrentGameAttribute.IsGame("Stress Level Zero", "BONEWORKS");
            }

            if (!Imports.IsDebugMode()
#if !DEBUG
                && Imports.IsConsoleEnabled()
#endif
                )
            {
                Console.Enabled = true;
                Console.Create();
            }

            if (!Imports.IsIl2CppGame() || AssemblyGenerator.Main.Initialize())
            {
                HasGeneratedAssembly = true;
            }
            else
            {
                Imports.UNLOAD_MELONLOADER();
            }

            if (HasGeneratedAssembly)
            {
                LoadDLLs(true);
                if (Plugins.Count > 0)
                {
                    HashSet <MelonPlugin> failedPlugins = new HashSet <MelonPlugin>();
                    TempPlugins = Plugins.Where(plugin => (plugin.Compatibility < MelonBase.MelonCompatibility.INCOMPATIBLE)).ToList();
                    DependencyGraph <MelonPlugin> .TopologicalSort(TempPlugins, plugin => plugin.InfoAttribute.Name);

                    for (int i = 0; i < TempPlugins.Count; i++)
                    {
                        MelonPlugin plugin = TempPlugins[i];
                        if (plugin != null)
                        {
                            try { plugin.OnPreInitialization(); } catch (Exception ex) { MelonModLogger.LogDLLError(ex.ToString(), plugin.InfoAttribute.Name); failedPlugins.Add(plugin); }
                        }
                    }
                    TempPlugins.RemoveAll(plugin => failedPlugins.Contains(plugin));
                }
            }
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: MonarchSolutions/MelonLoader
        private static void Initialize()
        {
            if (string.IsNullOrEmpty(AppDomain.CurrentDomain.BaseDirectory))
            {
                ((AppDomainSetup)typeof(AppDomain).GetProperty("SetupInformationNoCopy", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(AppDomain.CurrentDomain, new object[0])).ApplicationBase = Imports.GetGameDirectory();
            }
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;

            CurrentGameAttribute = new MelonModGameAttribute(Imports.GetCompanyName(), Imports.GetProductName());
            UnityVersion         = GetUnityFileVersion();

            if (Imports.IsIl2CppGame())
            {
                IsVRChat    = CurrentGameAttribute.IsGame("VRChat", "VRChat");
                IsBoneworks = CurrentGameAttribute.IsGame("Stress Level Zero", "BONEWORKS");
            }

            if (!Imports.IsDebugMode())
            {
                Console.Enabled = true;
                Console.Create();
            }

            if (Imports.IsIl2CppGame() && !AssemblyGenerator.Main.Initialize())
            {
                Imports.UNLOAD_MELONLOADER(true);
            }
            else
            {
                LoadMods(true);
                if (Mods.Count > 0)
                {
                    for (int i = 0; i < Mods.Count; i++)
                    {
                        MelonMod mod = Mods[i];
                        if (mod != null)
                        {
                            try { mod.OnPreInitialization(); } catch (Exception ex) { MelonModLogger.LogModError(ex.ToString(), mod.InfoAttribute.Name); }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: morag12/MelonLoader
        private static void Initialize()
        {
            CurrentGameAttribute = new MelonModGameAttribute(Imports.GetCompanyName(), Imports.GetProductName());

            if (Imports.IsIl2CppGame())
            {
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
                IsVRChat    = CurrentGameAttribute.IsGame("VRChat", "VRChat");
                IsBoneworks = CurrentGameAttribute.IsGame("Stress Level Zero", "BONEWORKS");
            }

            if (!Imports.IsDebugMode()
#if !DEBUG
                && Environment.CommandLine.Contains("--melonloader.console")
#endif
                )
            {
                MelonModLogger.consoleEnabled = true;
                Console.Create();
            }


            MelonModLogger.Log("------------------------------");
            MelonModLogger.Log("Unity " + Imports.GetUnityVersion());
            MelonModLogger.Log("Developer: " + CurrentGameAttribute.Developer);
            MelonModLogger.Log("GameName: " + CurrentGameAttribute.GameName);
            MelonModLogger.Log("------------------------------");
            MelonModLogger.Log("Using v" + BuildInfo.Version + " Open-Beta");
            MelonModLogger.Log("------------------------------");

            if (Imports.IsIl2CppGame())
            {
                MelonModLogger.Log("Initializing NET_SDK...");
                NET_SDK.SDK.Initialize();
                MelonModLogger.Log("------------------------------");
            }

            bool   no_mods      = false;
            string modDirectory = Path.Combine(Environment.CurrentDirectory, "Mods");
            if (!Directory.Exists(modDirectory))
            {
                Directory.CreateDirectory(modDirectory);
                no_mods = true;
            }
            else
            {
                string[] files = Directory.GetFiles(modDirectory, "*.dll");
                if (files.Length > 0)
                {
                    foreach (string s in files)
                    {
                        if (!File.Exists(s) || !s.EndsWith(".dll", true, null))
                        {
                            return;
                        }
                        try
                        {
                            byte[] data = File.ReadAllBytes(s);
                            if (data.Length > 0)
                            {
                                Assembly a = Assembly.Load(data);
                                if (a != null)
                                {
                                    LoadModsFromAssembly(a);
                                }
                                else
                                {
                                    MelonModLogger.LogError("Unable to load " + s);
                                }
                            }
                            else
                            {
                                MelonModLogger.LogError("Unable to load " + s);
                            }
                        }
                        catch (Exception e) { MelonModLogger.LogError("Unable to load " + s + ":\n" + e.ToString()); }
                        MelonModLogger.Log("------------------------------");
                    }
                    if (Mods.Count() <= 0)
                    {
                        no_mods = true;
                    }
                }
                else
                {
                    no_mods = true;
                }
            }
            if (no_mods)
            {
                MelonModLogger.Log("No Mods Loaded!");
                MelonModLogger.Log("------------------------------");
            }
            else
            {
                MelonModComponent.Create();
            }
        }