コード例 #1
0
 public static void SaveConfig()
 {
     foreach (KeyValuePair <string, Dictionary <string, MelonPreference> > prefsInSection in prefs)
     {
         foreach (KeyValuePair <string, MelonPreference> pref in prefsInSection.Value)
         {
             pref.Value.Value = pref.Value.ValueEdited;
             ConfigFile.SetString(prefsInSection.Key, pref.Key, pref.Value.Value);
         }
     }
     MelonHandler.OnModSettingsApplied();
     MelonLogger.Log("Config Saved!");
 }
コード例 #2
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);
        }