Exemplo n.º 1
0
        static void FixAllProblems()
        {
            int success = 0, fail = 0;

            foreach (SaveBugs bug in saveBugs)
            {
                try
                {
                    bug.Fix.Invoke();
                    success++;
                }
                catch
                {
                    fail++;
                }
            }

            string msg = $"<color=yellow>{success}</color> issue{(success > 1 ? "s have" : " has")} been fixed.";

            if (fail > 0)
            {
                msg += $"\n<color=red>{fail}</color> issue{(fail > 1 ? "s" : "")} couldn't be fixed.";
            }

            ModPrompt.CreatePrompt(msg, "MOP - Save Integrity Check");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the entire logs folder.
        /// </summary>
        public static void DeleteAllLogs()
        {
            if (!Directory.Exists($"{RootPath}/{LogFolder}"))
            {
                ModPrompt.CreatePrompt("Log folder doesn't exist.", "MOP");
                return;
            }

            ModPrompt.CreateYesNoPrompt("Are you sure you want to delete all logs?", "MOP", () => Directory.Delete($"{RootPath}/{LogFolder}", true));
        }
Exemplo n.º 3
0
 public static void OpenCurrentSessionLogFolder()
 {
     if (ThisSessionLogDirectoryExists)
     {
         Process.Start(LogFolder);
     }
     else
     {
         ModPrompt.CreatePrompt("Logs folder doesn't exist.", "MOP");
     }
 }
Exemplo n.º 4
0
 public static void OpenOutputLog()
 {
     if (File.Exists(OutputLogPath))
     {
         Process.Start(OutputLogPath);
     }
     else
     {
         ModPrompt.CreatePrompt("File \"output_log.txt\" doesn't exist.", "MOP");
     }
 }
Exemplo n.º 5
0
        public static void FileBugReport()
        {
            if (!MopSettings.LoadedOnce)
            {
                ModPrompt.CreateContinueAbortPrompt("It is recommended to start the game at least once before filing bug report.\n\n" +
                                                    "If you can't load the game, press Continue to generate mod report anyway.",
                                                    "MOP - Bug Report",
                                                    () => instance.BugReport());
                return;
            }

            instance.BugReport();
        }
Exemplo n.º 6
0
        internal static void UpdatePerformanceMode()
        {
            // MODES
            // Show the warning about safe mode, if the player disables safe mode and is not in main menu.
            bool dontUpdate = false;

            if (ModLoader.CurrentScene != CurrentScene.MainMenu && IsModActive)
            {
                if (Mode == PerformanceMode.Safe && MOP.PerformanceModes.Value != 3)
                {
                    ModPrompt.CreatePrompt("Safe Mode will be disabled after the restart.", "MOP");
                    dontUpdate = true;
                }
                else if (Mode != PerformanceMode.Safe && MOP.PerformanceModes.Value == 3)
                {
                    ModPrompt.CreatePrompt("Safe Mode will be enabled after the restart.", "MOP");
                    dontUpdate = true;
                }

                if (!dontUpdate)
                {
                    switch (MOP.PerformanceModes.Value)
                    {
                    default:
                        Mode = PerformanceMode.Balanced;
                        break;

                    case 0:
                        Mode = PerformanceMode.Performance;
                        break;

                    case 1:
                        Mode = PerformanceMode.Balanced;
                        break;

                    case 2:
                        Mode = PerformanceMode.Quality;
                        break;

                    case 3:
                        Mode = PerformanceMode.Safe;
                        break;
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static void VerifySave()
        {
            if (!File.Exists(SavePath))
            {
                return;
            }

            // Passenger bucket seat.
            // Check if driver bucket seat is bought and check the same for passenger one.
            // If they do not match, fix it.
            try
            {
                saveBugs = new List <SaveBugs>();

                bool bucketPassengerSeat = ES2.Load <bool>(SavePath + "?tag=bucket seat passenger(Clone)Purchased", setting);
                bool bucketDriverSeat    = ES2.Load <bool>(SavePath + "?tag=bucket seat driver(Clone)Purchased", setting);
                if (bucketDriverSeat != bucketPassengerSeat)
                {
                    saveBugs.Add(SaveBugs.New("Bucket Seats", "One bucket seat is present in the game world, while the other isn't - both should be in game world.", () =>
                    {
                        ES2.Save(true, SavePath + "?tag=bucket seat passenger(Clone)Purchased");
                        ES2.Save(true, SavePath + "?tag=bucket seat driver(Clone)Purchased");
                    }));
                }
            }
            catch (Exception e)
            {
                ExceptionManager.New(e, false, "VERIFY_SAVE_BUCKET_SEAT");
            }

            try
            {
                bool      tractorTrailerAttached = ES2.Load <bool>(SavePath + "?tag=TractorTrailerAttached", setting);
                Transform flatbedTransform       = ES2.Load <Transform>(SavePath + "?tag=FlatbedTransform", setting);
                Transform kekmetTransform        = ES2.Load <Transform>(SavePath + "?tag=TractorTransform", setting);
                if (tractorTrailerAttached && Vector3.Distance(flatbedTransform.position, kekmetTransform.position) > 5.5f)
                {
                    saveBugs.Add(SaveBugs.New("Flatbed Trailer Attached", "Trailer and tractor are too far apart from each other - impossible for them to be attached.", () =>
                    {
                        ES2.Save(false, SavePath + "?tag=TractorTrailerAttached", new ES2Settings());
                    }));
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "VERIFY_SAVE_FLATBED");
            }

            try
            {
                // This one applies fix quietly, as it happens so often,
                // it would be annoying to nag player about that error.
                if (SaveFileExists)
                {
                    MopSaveData save = ModSave.Load <MopSaveData>(mopSavePath);
                    bool        bumperRearInstalled = ES2.Load <bool>(SavePath + "?tag=bumper rear(Clone)Installed", setting);
                    float       bumperTightness     = ES2.Load <float>(SavePath + "?tag=Bumper_RearTightness", setting);
                    if (bumperRearInstalled && bumperTightness != save.rearBumperTightness)
                    {
                        ES2.Save(save.rearBumperTightness, SavePath + "?tag=Bumper_RearTightness");
                        ES2.Save(save.rearBumperBolts, SavePath + "?tag=Bumper_RearBolts");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.New(ex, false, "VERIFY_BUMPER_REAR");
            }

            if (saveBugs.Count > 0)
            {
                ModPrompt.CreateYesNoPrompt($"MOP found <color=yellow>{saveBugs.Count}</color> problem{(saveBugs.Count > 1 ? "s" : "")} with your save:\n\n" +
                                            $"<color=yellow>{string.Join(", ", saveBugs.Select(f => f.BugName).ToArray())}</color>\n\n" +
                                            $"Would you like MOP to try and fix {((saveBugs.Count > 1) ? "them" : "it")}?", "MOP - Save Integrity Verification", FixAllProblems);
            }
            else
            {
                ModConsole.Log("[MOP] MOP didn't find any problems with your save :)");
            }
        }
Exemplo n.º 8
0
        public void BugReport()
        {
            if (Directory.Exists(BugReportPath))
            {
                Directory.Delete(BugReportPath, true);
            }

            Directory.CreateDirectory(BugReportPath);

            // Get output_log.txt
            if (File.Exists($"{ExceptionManager.RootPath}/output_log.txt"))
            {
                File.Copy($"{ExceptionManager.RootPath}/output_log.txt", $"{BugReportPath}/output_log.txt");
            }

            // Now we are getting logs generated today.
            string today = DateTime.Now.ToString("yyyy-MM-dd");

            foreach (string log in Directory.GetFiles(ExceptionManager.LogFolder, $"*{today}*.txt"))
            {
                string pathToFile = log.Replace("\\", "/");
                string nameOfFile = log.Split('\\')[1];
                ModConsole.Log(nameOfFile);
                File.Copy(pathToFile, $"{BugReportPath}/{nameOfFile}");
            }

            // Generate a MOP report.
            using (StreamWriter sw = new StreamWriter($"{BugReportPath}/MOP_REPORT.txt"))
            {
                sw.WriteLine(ExceptionManager.GetGameInfo());
            }

            // Now we are packing up everything.
            string lastZipFilePath = $"{BugReportPath}/MOP Bug Report - {DateTime.Now:yyyy-MM-dd_HH-mm}.zip";

            using (ZipFile zip = new ZipFile())
            {
                foreach (string file in Directory.GetFiles(BugReportPath, "*.txt"))
                {
                    zip.AddFile(file, "");
                }

                zip.Save(lastZipFilePath);
            }

            // Now we are deleting all .txt files.
            foreach (string file in Directory.GetFiles(BugReportPath, "*.txt"))
            {
                File.Delete(file);
            }

            // Create the tutorial.
            using (StreamWriter sw = new StreamWriter($"{BugReportPath}/README.txt"))
            {
                sw.WriteLine("A MOP report archive has been successfully generated.\n");
                sw.WriteLine("Upload .zip file to some file hosting site, such as https://www.mediafire.com/. \n\n" +
                             "Remember to describe how you stumbled uppon the error!");
            }

            // We are asking the user if he wants to add his game save to the zip file.
            if (File.Exists(SaveManager.SavePath))
            {
                ModPrompt.CreateYesNoPrompt("Would you like to your include save file?\n\n" +
                                            "This may greatly improve finding and fixing the bug.", "MOP - Bug Report",
                                            () => {
                    using (ZipFile zip = ZipFile.Read(lastZipFilePath))
                    {
                        // Create folder called Save in the zip and get defaultES2Save.txt and items.txt.
                        zip.AddDirectoryByName("Save");
                        if (File.Exists(SaveManager.SavePath))
                        {
                            zip.AddFile(SaveManager.SavePath, "Save");
                        }

                        if (File.Exists(SaveManager.ItemsPath))
                        {
                            zip.AddFile(SaveManager.ItemsPath, "Save");
                        }

                        zip.Save();
                    }
                },
                                            onPromptClose: () => { Process.Start(BugReportPath); Process.Start($"{BugReportPath}/README.txt"); });
            }
        }