Beispiel #1
0
        public static SaveBugs New(string bugName, string description, UnityAction fix)
        {
            SaveBugs bug = new SaveBugs();

            bug.BugName     = bugName;
            bug.Description = description;
            bug.Fix         = fix;
            return(bug);
        }
Beispiel #2
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 :)");
            }
        }