Exemplo n.º 1
0
        // Called once, when mod is loading after game is fully loaded
        public override void OnLoad()
        {
            // Load dem assets
            AssetBundle ab          = ModAssets.LoadBundle(Properties.Resources.mop);
            GameObject  originalMop = ab.LoadAsset <GameObject>("mop.prefab");

            mop = GameObject.Instantiate <GameObject>(originalMop);
            ab.Unload(false);

            // Add MopBehaviour component
            MopBehaviour behaviour = mop.AddComponent <MopBehaviour>();

            // Load save data
            MopSaveData mopSaveData = ModSave.Load <MopSaveData>(SaveFile);

            if (mopSaveData != null)
            {
                behaviour.Initialize(mopSaveData);
            }

            GameObject      actualMopManager = new GameObject("ActualMopManager");
            MopOptimization optimization     = actualMopManager.AddComponent <MopOptimization>();

            optimization.Initialize(mop.transform);
        }
Exemplo n.º 2
0
 internal static void ReleaseSave()
 {
     if (SaveFileExists)
     {
         ModSave.Delete(mopSavePath);
     }
 }
Exemplo n.º 3
0
        internal static void AddSaveFlag()
        {
            if (ES2.Exists(SavePath + "?tag=Bumper_RearTightness") && ES2.Exists(SavePath + "?tag=Bumper_RearBolts", setting))
            {
                MopSaveData save = new MopSaveData();
                save.rearBumperTightness = ES2.Load <float>(SavePath + "?tag=Bumper_RearTightness", setting);
                save.rearBumperBolts     = ES2.LoadList <string>(SavePath + "?tag=Bumper_RearBolts", setting);

                ModSave.Save(mopSavePath, save);
            }
        }
Exemplo n.º 4
0
 public override void OnNewGame()
 {
     // Delete save data on new game
     ModConsole.Log("[Actual Mop] Resetting save data.");
     ModSave.Delete(SaveFile);
 }
Exemplo n.º 5
0
 public override void OnSave()
 {
     ModSave.Save(SaveFile, mop.GetComponent <MopBehaviour>().GetSaveInfo());
 }
Exemplo n.º 6
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 :)");
            }
        }