Exemple #1
0
 private void LoadGame(string name)
 {
     if (name.EndsWith(".sfs"))
     {
         name = name.Substring(0, name.Length - 4);
     }
     if (HighLogic.CurrentGame.Parameters.Flight.CanQuickLoad)
     {
         string filename = name + ".sfs";
         string path     = KSPUtil.GetOrCreatePath("saves/" + HighLogic.SaveFolder);
         if (!File.Exists(Path.Combine(path, filename)))
         {
             throw new KOSException("Error loading the quicksave file, the save file does not exist.");
         }
         shared.Cpu.GetCurrentOpcode().AbortProgram = true;
         try
         {
             SaveGame("kos-backup-quicksave");
             var game = GamePersistence.LoadGame(name, HighLogic.SaveFolder, true, false);
             if (game.flightState != null)
             {
                 if (game.compatible)
                 {
                     GamePersistence.UpdateScenarioModules(game);
                     if (game.startScene != GameScenes.FLIGHT)
                     {
                         if (KSPUtil.CheckVersion(game.file_version_major, game.file_version_minor, game.file_version_revision, 0, 24, 0) != VersionCompareResult.INCOMPATIBLE_TOO_EARLY)
                         {
                             GamePersistence.SaveGame(game, name, HighLogic.SaveFolder, SaveMode.OVERWRITE);
                             HighLogic.LoadScene(GameScenes.SPACECENTER);
                             return;
                         }
                     }
                     FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
                 }
             }
         }
         catch (Exception ex)
         {
             SafeHouse.Logger.Log(ex.Message);
             throw new KOSException("Error loading the quicksave file");
         }
     }
     else
     {
         throw new KOSException("KSP prevents using quickload currently.");
     }
 }
Exemple #2
0
        IEnumerator QStart()
        {
            if (string.IsNullOrEmpty(QSaveGame.LastUsed))
            {
                QDebug.Warning("Last savegame not found!", "QMainMenu");
                DestroyThis();
                yield break;
            }
            if (!QSettings.Instance.Enabled)
            {
                QDebug.Log("QuickStart is disabled!", "QMainMenu");
                DestroyThis();
                yield break;
            }
            while (!Ready)
            {
                yield return(0);
            }
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForSeconds(QSettings.Instance.WaitLoading));

            yield return(new WaitForEndOfFrame());

            QDebug.Log("MainMenu Loaded", "QMainMenu");
            QDebug.Warning("The last game found: " + QSaveGame.LastUsed, "QMainMenu");
            HighLogic.CurrentGame = GamePersistence.LoadGame(QSaveGame.FILE, QSaveGame.LastUsed, true, false);
            if (HighLogic.CurrentGame != null)
            {
                HighLogic.SaveFolder = QSaveGame.LastUsed;
                if (GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame))
                {
                    GamePersistence.SaveGame(HighLogic.CurrentGame, QSaveGame.FILE, HighLogic.SaveFolder, SaveMode.OVERWRITE);
                }
                QDebug.Log("Goto SpaceCenter", "QMainMenu");
                HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
                HighLogic.CurrentGame.Start();
                InputLockManager.ClearControlLocks();
                Destroy(this);
                yield break;
            }
            QDebug.Warning("Can't load the last save game", "QMainMenu");
            DestroyThis();
            yield break;
        }
Exemple #3
0
        static void OnLoadDialogPipelineFinished(ConfigNode node)
        {
            // Load game cfg
            HighLogic.CurrentGame = GamePersistence.LoadGameCfg(node, Game, true, false);
            if (HighLogic.CurrentGame == null)
            {
                Console.WriteLine("[kRPC testing tools]: Failed to load game, got null when loading game cfg");
                return;
            }
            if (GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame))
            {
                Console.WriteLine("[kRPC testing tools]: Failed to load game, scenario update required");
                return;
            }

            // Find the vessel to switch to
            bool foundVessel = false;
            int  vesselIdx   = 0;

            foreach (var vessel in HighLogic.CurrentGame.flightState.protoVessels)
            {
                if (vessel.vesselType != VesselType.SpaceObject)
                {
                    foundVessel = true;
                    break;
                }
                vesselIdx++;
            }
            if (!foundVessel)
            {
                Console.WriteLine("[kRPC testing tools]: Failed to find vessel to switch to");
                return;
            }
            AutoSwitchVessel.Vessel = vesselIdx;

            // Load the game
            HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
            HighLogic.SaveFolder             = Game;
            HighLogic.CurrentGame.Start();
        }
Exemple #4
0
 void OnLoadDialogPipelineFinished(ConfigNode node)
 {
     HighLogic.CurrentGame = GamePersistence.LoadGameCfg(node, game, true, false);
     if (HighLogic.CurrentGame != null)
     {
         if (GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame))
         {
             if (node != null)
             {
                 GameEvents.onGameStatePostLoad.Fire(node);
             }
             GamePersistence.SaveGame(HighLogic.CurrentGame, save, game, SaveMode.OVERWRITE);
         }
         if (HighLogic.CurrentGame.startScene == GameScenes.FLIGHT)
         {
             AutoSwitchVessel.activeVessel = HighLogic.CurrentGame.flightState.activeVesselIdx;
             AutoSwitchVessel.save         = save;
         }
         HighLogic.CurrentGame.startScene = GameScenes.SPACECENTER;
         HighLogic.SaveFolder             = game;
         HighLogic.CurrentGame.Start();
     }
 }
Exemple #5
0
        static void onPipelineFinished(ConfigNode node, string saveName, Version originalVersion)
        {
            var game = GamePersistence.LoadGameCfg(node, saveName, true, false);

            if (game != null && game.flightState != null)
            {
                if (game.compatible)
                {
                    GamePersistence.UpdateScenarioModules(game);
                    if (node != null)
                    {
                        GameEvents.onGameStatePostLoad.Fire(node);
                    }
                    if (game.startScene != GameScenes.FLIGHT &&
                        originalVersion >= new Version(0, 24, 0))
                    {
                        GamePersistence.SaveGame(game, "persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                        HighLogic.LoadScene(GameScenes.SPACECENTER);
                        return;
                    }
                }
                FlightDriver.StartAndFocusVessel(game, game.flightState.activeVesselIdx);
            }
        }
Exemple #6
0
        void Awake()
        {
            //load the game only the first time (i.e. at game start)
            if (Loaded)
            {
                return;
            }
            Loaded = true;
            //get the game and the save
            var game = "";
            var save = "";

            if (File.Exists(config))
            {
                var cfg = ConfigNode.Load(config);
                if (cfg != null)
                {
                    var val = cfg.GetValue("game");
                    if (val != null)
                    {
                        game = val;
                    }
                    val = cfg.GetValue("save");
                    if (val != null)
                    {
                        save = val;
                    }
                }
                else
                {
                    Log("LoadTestGame: Configuration file is empty: {0}", config);
                    return;
                }
            }
            else
            {
                Log("LoadTestGame: Configuration file not found: {0}", config);
                return;
            }
            var gamedir = Path.Combine(savesdir, game);

            if (!Directory.Exists(gamedir))
            {
                Log("No game directory: {0}", gamedir);
                return;
            }
            var savefile = Path.Combine(gamedir, save + ".sfs");

            if (!File.Exists(savefile))
            {
                Log("No such file: {0}", savefile);
                return;
            }
            //load the game
            HighLogic.CurrentGame = GamePersistence.LoadGame(save, game, false, false);
            if (HighLogic.CurrentGame != null)
            {
                GamePersistence.UpdateScenarioModules(HighLogic.CurrentGame);
                HighLogic.SaveFolder = game;
                HighLogic.CurrentGame.Start();
            }
        }