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)); } } }
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(); } }
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)) { MelonLogger.LogError("MelonLoader.AssemblyGenerator.exe does not Exist!"); return(false); } var generatorProcessInfo = new ProcessStartInfo(GeneratorProcessPath); generatorProcessInfo.Arguments = $"\"{MelonLoaderBase.UnityVersion}\" {"\"" + Regex.Replace(Imports.GetGameDirectory(), @"(\\+)$", @"$1$1") + "\""} {"\"" + Regex.Replace(Imports.GetGameDataDirectory(), @"(\\+)$", @"$1$1") + "\""} {(Force_Regenerate() ? "true" : "false")} {(string.IsNullOrEmpty(Force_Version_Unhollower()) ? "" : Force_Version_Unhollower())}"; generatorProcessInfo.UseShellExecute = false; generatorProcessInfo.RedirectStandardOutput = true; generatorProcessInfo.CreateNoWindow = true; Process process = null; try { process = Process.Start(generatorProcessInfo); } catch (Exception e) { MelonLogger.LogError(e.ToString()); MelonLogger.LogError("Unable to Start Assembly Generator!"); return(false); } var stdout = process.StandardOutput; while (!stdout.EndOfStream) { MelonLogger.Log(stdout.ReadLine()); } while (!process.HasExited) { Thread.Sleep(100); } if (process.ExitCode != 0) { MelonLogger.Native_ThrowInternalError($"Assembly Generator exited with code {process.ExitCode}"); return(false); } if (Imports.IsDebugMode()) { MelonLogger.Log($"Assembly Generator ran Successfully!"); } return(true); }
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); } } } } } }