Esempio n. 1
0
        public static void Log(string s)
        {
            string namesection = GetNameSection();

            Imports.Logger_Log(namesection + s);
            if (!Imports.IsDebugMode() && Console.Enabled)
            {
                bool rainbow_check = RainbowCheck();
                System.Console.Write("[");
                if (!rainbow_check)
                {
                    Console.SetColor(ConsoleColor.Green);
                }
                System.Console.Write(GetTimestamp());
                if (!rainbow_check)
                {
                    Console.SetColor(ConsoleColor.Gray);
                }
                System.Console.Write("] [");
                if (!rainbow_check)
                {
                    Console.SetColor(ConsoleColor.Magenta);
                }
                System.Console.Write("MelonLoader");
                if (!rainbow_check)
                {
                    Console.SetColor(ConsoleColor.Gray);
                }
                System.Console.WriteLine("] " + namesection + s);
                if (rainbow_check)
                {
                    Console.SetColor(ConsoleColor.Gray);
                }
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        private static void OnApplicationStart()
        {
            if (Imports.IsIl2CppGame())
            {
                Assembly_CSharp = Assembly.Load("Assembly-CSharp");
                UnhollowerSupport.Initialize();
            }
            SupportModule.Initialize();

            MelonModLogger.Log("------------------------------");
            MelonModLogger.Log("Unity " + UnityVersion);
            MelonModLogger.Log("------------------------------");
            MelonModLogger.Log("Name: " + CurrentGameAttribute.GameName);
            MelonModLogger.Log("Developer: " + CurrentGameAttribute.Developer);
            MelonModLogger.Log("Type: " + (Imports.IsIl2CppGame() ? "Il2Cpp" : (Imports.IsOldMono() ? "Mono" : "MonoBleedingEdge")));
            MelonModLogger.Log("------------------------------");
            MelonModLogger.Log("Using v" + BuildInfo.Version + " Open-Beta");
            MelonModLogger.Log("------------------------------");

            LoadMods();
            if (Mods.Count > 0)
            {
                for (int i = 0; i < Mods.Count; i++)
                {
                    MelonMod mod = Mods[i];
                    if (mod != null)
                    {
                        MelonModLogger.Log(mod.InfoAttribute.Name
                                           + (!string.IsNullOrEmpty(mod.InfoAttribute.Version)
                            ? (" v" + mod.InfoAttribute.Version) : "")
                                           + (!string.IsNullOrEmpty(mod.InfoAttribute.Author)
                            ? (" by " + mod.InfoAttribute.Author) : "")
                                           + (!string.IsNullOrEmpty(mod.InfoAttribute.DownloadLink)
                            ? (" (" + mod.InfoAttribute.DownloadLink + ")")
                            : "")
                                           );
                        if (Imports.IsDebugMode())
                        {
                            MelonModLogger.Log("Preload: " + mod.IsPreload.ToString());
                        }
                        MelonModLogger.LogModStatus((mod.GameAttributes.Any()) ? (mod.IsUniversal ? 0 : 1) : 2);
                        MelonModLogger.Log("------------------------------");
                    }
                }
                for (int i = 0; i < Mods.Count; i++)
                {
                    MelonMod mod = Mods[i];
                    if (mod != null)
                    {
                        try { mod.OnApplicationStart(); } catch (Exception ex) { MelonModLogger.LogModError(ex.ToString(), mod.InfoAttribute.Name); }
                    }
                }
            }
            else
            {
                MelonModLogger.Log("No Mods Loaded!");
                MelonModLogger.Log("------------------------------");
            }
        }
Esempio n. 4
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()
#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));
                }
            }
        }
Esempio n. 5
0
        internal static void Check()
        {
            if (!Imports.IsDebugMode()
#if !DEBUG
                && IsConsoleEnabled()
#endif
                )
            {
                Create();
            }
        }
Esempio n. 6
0
        public static void LogError(string s)
        {
            string namesection = GetNameSection();

            Imports.Logger_LogError(namesection, s);
            if (!Imports.IsDebugMode() && consoleEnabled)
            {
                System.Console.ForegroundColor = ConsoleColor.Red;
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Error] " + s);
                System.Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
Esempio n. 7
0
        internal static void LogModError(string msg, string modname)
        {
            string namesection = (string.IsNullOrEmpty(modname) ? "" : ("[" + modname.Replace(" ", "_") + "] "));

            Imports.Logger_LogModError(namesection, msg);
            if (!Imports.IsDebugMode() && consoleEnabled)
            {
                System.Console.ForegroundColor = ConsoleColor.Yellow;
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Error] " + msg);
                System.Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
        public static void LogWarning(string s)
        {
            string namesection = GetNameSection();

            Imports.Logger_LogWarning(namesection, s);
            if (!Imports.IsDebugMode() && Console.Enabled)
            {
                Imports.Console_SetColor(ConsoleColor.Yellow);
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Warning] " + s);
                Imports.Console_SetColor(ConsoleColor.Gray);
            }
        }
Esempio n. 9
0
        public static void Log(ConsoleColor color, string s)
        {
            string namesection = GetNameSection();

            Imports.Logger_LogColor((namesection + s), color);
            if (!Imports.IsDebugMode() && Console.Enabled)
            {
                Console.SetColor(color);
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + s);
                Console.SetColor(ConsoleColor.Gray);
            }
        }
Esempio n. 10
0
        public static void LogWarning(string s, params object[] args)
        {
            string namesection = GetNameSection();
            var    formatted   = string.Format(s, args);

            Imports.Logger_LogWarning(namesection, formatted);
            if (!Imports.IsDebugMode() && Console.Enabled)
            {
                Console.SetColor(ConsoleColor.Yellow);
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Warning] " + formatted);
                Console.SetColor(ConsoleColor.Gray);
            }
        }
        public static void Log(ConsoleColor color, string s, params object[] args)
        {
            string namesection = GetNameSection();
            var    formatted   = string.Format(s, args);

            Imports.Logger_LogColor((namesection + formatted), color);
            if (!Imports.IsDebugMode() && Console.Enabled)
            {
                Imports.Console_SetColor(color);
                RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + formatted);
                Imports.Console_SetColor(ConsoleColor.Gray);
            }
        }
Esempio n. 12
0
        public static void Log(string s, params object[] args)
        {
            string namesection = GetNameSection();
            var    formatted   = string.Format(s, args);

            Imports.Logger_Log(namesection + formatted);
            if (!Imports.IsDebugMode() && consoleEnabled)
            {
                bool rainbow_check = RainbowCheck();
                System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + formatted);
                if (rainbow_check)
                {
                    System.Console.ForegroundColor = ConsoleColor.Gray;
                }
            }
        }
Esempio n. 13
0
 internal static void LogModError(string msg, string modname)
 {
     if (ErrorCount < MaxErrorCount)
     {
         string namesection = (string.IsNullOrEmpty(modname) ? "" : ("[" + modname.Replace(" ", "_") + "] "));
         Imports.Logger_LogModError(namesection, msg);
         if (!Imports.IsDebugMode() && Console.Enabled)
         {
             Console.SetColor(ConsoleColor.Yellow);
             RainbowCheck();
             System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Error] " + msg);
             Console.SetColor(ConsoleColor.Gray);
         }
         ErrorCount++;
     }
 }
Esempio n. 14
0
 public static void LogError(string s)
 {
     if (ErrorCount < MaxErrorCount)
     {
         string namesection = GetNameSection();
         Imports.Logger_LogError(namesection, s);
         if (!Imports.IsDebugMode() && Console.Enabled)
         {
             Console.SetColor(ConsoleColor.Red);
             RainbowCheck();
             System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Error] " + s);
             Console.SetColor(ConsoleColor.Gray);
         }
         ErrorCount++;
     }
 }
 public static void LogError(string s, params object[] args)
 {
     if (ErrorCount < MaxErrorCount)
     {
         string namesection = GetNameSection();
         var    formatted   = string.Format(s, args);
         Imports.Logger_LogError(namesection, formatted);
         if (!Imports.IsDebugMode() && Console.Enabled)
         {
             Imports.Console_SetColor(ConsoleColor.Red);
             RainbowCheck();
             System.Console.WriteLine("[" + GetTimestamp() + "] [MelonLoader] " + namesection + "[Error] " + formatted);
             Imports.Console_SetColor(ConsoleColor.Gray);
         }
         ErrorCount++;
     }
 }
Esempio n. 16
0
        private static bool Initialize()
        {
            string GeneratorProcessPath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Imports.GetGameDirectory(), "MelonLoader"), "Dependencies"), "AssemblyGenerator"), "MelonLoader.AssemblyGenerator.exe");

            if (File.Exists(GeneratorProcessPath))
            {
                var generatorProcessInfo = new ProcessStartInfo(GeneratorProcessPath);
                generatorProcessInfo.Arguments              = $"\"{MelonLoaderBase.UnityVersion}\" \"{Imports.GetGameDirectory()}\" \"{Imports.GetGameDataDirectory()}\" {(Force_Regenerate() ? "true" : "false")} {(string.IsNullOrEmpty(Force_Version_Unhollower()) ? "" : Force_Version_Unhollower())}";
                generatorProcessInfo.UseShellExecute        = false;
                generatorProcessInfo.RedirectStandardOutput = true;
                generatorProcessInfo.CreateNoWindow         = true;
                var process = Process.Start(generatorProcessInfo);
                if (process == null)
                {
                    MelonLogger.LogError("Unable to Start Assembly Generator!");
                }
                else
                {
                    var stdout = process.StandardOutput;
                    while (!stdout.EndOfStream)
                    {
                        var line = stdout.ReadLine();
                        MelonLogger.Log(line);
                    }
                    while (!process.HasExited)
                    {
                        Thread.Sleep(100);
                    }
                    if (process.ExitCode == 0)
                    {
                        if (Imports.IsDebugMode())
                        {
                            MelonLogger.Log($"Assembly Generator ran Successfully!");
                        }
                        return(true);
                    }
                    MelonLogger.Native_ThrowInternalError($"Assembly Generator exited with code {process.ExitCode}");
                }
            }
            else
            {
                MelonLogger.LogError("MelonLoader.AssemblyGenerator.exe does not Exist!");
            }
            return(false);
        }
Esempio n. 17
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())
            {
                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); }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        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();
            }
        }
Esempio n. 19
0
 internal static void LogModStatus(int type)
 {
     Imports.Logger_LogModStatus(type);
     if (!Imports.IsDebugMode() && Console.Enabled)
     {
         bool rainbow_check = RainbowCheck();
         System.Console.Write("[");
         if (!rainbow_check)
         {
             Console.SetColor(ConsoleColor.Green);
         }
         System.Console.Write(GetTimestamp());
         if (!rainbow_check)
         {
             Console.SetColor(ConsoleColor.Gray);
         }
         System.Console.Write("] [");
         if (!rainbow_check)
         {
             Console.SetColor(ConsoleColor.Magenta);
         }
         System.Console.Write("MelonLoader");
         if (!rainbow_check)
         {
             Console.SetColor(ConsoleColor.Gray);
         }
         System.Console.Write("] ");
         if (!rainbow_check)
         {
             Console.SetColor(ConsoleColor.Blue);
         }
         System.Console.Write("Status: ");
         if (type == 0)
         {
             if (!rainbow_check)
             {
                 Console.SetColor(ConsoleColor.Cyan);
             }
             System.Console.WriteLine("Universal");
         }
         else if (type == 1)
         {
             if (!rainbow_check)
             {
                 Console.SetColor(ConsoleColor.Green);
             }
             System.Console.WriteLine("Compatible");
         }
         else if (type == 2)
         {
             if (!rainbow_check)
             {
                 Console.SetColor(ConsoleColor.Yellow);
             }
             System.Console.WriteLine("No MelonModGameAttribute!");
         }
         else
         {
             if (!rainbow_check)
             {
                 Console.SetColor(ConsoleColor.Red);
             }
             System.Console.WriteLine("INCOMPATIBLE!");
         }
         Console.SetColor(ConsoleColor.Gray);
     }
 }