public void LoadWorld()
        {
            this.ReferenceTable.ClearReferences();

            if (ScribeMultiLoader.Empty())
            {
                PreloadWorldColoniesMaps();
            }

            Status = PersistentWorldLoadStatus.Loading;

            this.SetCurrentFile(worldFilePath);

            Log.Message("Loading world " + worldFolderPath);

            // Select world to load XML node data for.
            ScribeMultiLoader.SetScribeCurXmlParentByFilePath(this.worldFilePath);

            // Required otherwise errors because of internal requirements.
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);

            // Load data.
            Scribe_Deep.Look <PersistentWorldData>(ref this.persistentWorld.WorldData, "data");

            //this.persistentWorld.ResetPlayerFaction(FactionDefOf.PlayerColony);

            Log.Message("Loaded world data...");
        }
예제 #2
0
        public static bool PreFLoadGameFromSaveFile(string fileName)
        {
            string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods
                                             select mod.ToString(), true);

            Log.Message("Loading game from file " + fileName + " with mods " + str);
            DeepProfiler.Start("Loading game from file " + fileName);
            Current.Game = new Game();
            DeepProfiler.Start("InitLoading (read file)");
            Scribe.loader.InitLoading(GenFilePaths.FilePathForSavedGame(fileName));
            DeepProfiler.End();
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
            bool flag = !Scribe.EnterNode("Κgame");
            bool result;

            if (flag)
            {
                Log.Error("Could not find DTMG XML node.");
                Scribe.ForceStop();
                GenScene.GoToMainMenu();
                Messages.Message("Game MUST be created with 'Don't Tempt Me!' loaded. Please select a 'Don't Tempt Me!' save game file.", MessageTypeDefOf.RejectInput);
                result = false;
            }
            else
            {
                Current.Game = new Game();
                Current.Game.LoadGame();
                PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
                DeepProfiler.End();
                result = false;
            }
            return(result);
        }
예제 #3
0
        public static PathDataLog LoadFromFile(string filename)
        {
            var pathData = new PathDataLog();

            try
            {
                Scribe.InitLoading(filename);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("PathData");
                pathData.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            return(pathData);
        }
예제 #4
0
 private static void Read(string filepath)
 {
     Scribe.loader.InitLoadingMetaHeaderOnly(filepath);
     ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
     importList = ScribeMetaHeaderUtility.loadedModIdsList;
     Scribe.loader.FinalizeLoading();
 }
        /// <summary>
        /// Read a save file
        /// </summary>
        /// <param name="filepath">The path to the savefile</param>
        private static void Read(string filepath)
        {
            Main.LogDebug("reading {0}", filepath);

            Scribe.SaveState();
            Scribe.InitLoadingMetaHeaderOnly(filepath);
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
            importList = ScribeMetaHeaderUtility.loadedModIdsList;
            Scribe.FinalizeLoading();
            Scribe.RestoreState();
        }
        private void DoImport(SaveFileInfo file)
        {
            try
            {
                // load stuff
                Scribe.InitLoading(_folder + "/" + file.FileInfo.Name);
                Manager.LoadSaveMode = Manager.Modes.ImportExport;
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("JobStack");
                _jobStackIO.ExposeData();
                Scribe.ExitNode();
                Scribe.FinalizeLoading();

                // resolve crossreferences
                // these are registered during the loading stage, and cleared afterwards
                // will most definitely give errors/warnings on crossgame imports
                CrossRefResolver.ResolveAllCrossReferences();

                // replace the old jobstack
                Manager.For(manager).NewJobStack(_jobStackIO);

                // remove invalid jobs
                var invalid = 0;
                foreach (ManagerJob job in Manager.For(manager).JobStack.FullStack())
                {
                    if (!job.IsValid)
                    {
                        invalid++;
                        job.Delete(false);
                    }
                }

                // provide some feedback on failed import(s)
                // if debug is enabled the screen will also pop up with reference errors.
                if (invalid > 0)
                {
                    Messages.Message("FM.InvalidJobsDeleted".Translate(invalid), MessageSound.SeriousAlert);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading jobstack: " + e);
            }
            finally
            {
                // done?
                Scribe.mode          = LoadSaveMode.Inactive;
                Manager.LoadSaveMode = Manager.Modes.Normal;
                Messages.Message("FM.JobsImported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
예제 #7
0
        static bool Prefix()
        {
            if (gameToLoad == null)
            {
                return(true);
            }

            SaveCompression.doSaveCompression = true;

            try
            {
                ScribeUtil.StartLoading(gameToLoad.SaveData);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("game");
                Current.Game = new Game();
                Current.Game.LoadGame(); // calls Scribe.loader.FinalizeLoading()
                SemiPersistent.ReadSemiPersistent(gameToLoad.SemiPersistent);
            }
            finally
            {
                SaveCompression.doSaveCompression = false;
                gameToLoad = null;
            }

            Log.Message("Game loaded");

            if (Multiplayer.Client != null)
            {
                LongEventHandler.ExecuteWhenFinished(() =>
                {
                    // Inits all caches
                    foreach (ITickable tickable in TickPatch.AllTickables.Where(t => !(t is ConstantTicker)))
                    {
                        tickable.Tick();
                    }

                    if (!Current.Game.Maps.Any())
                    {
                        MemoryUtility.UnloadUnusedUnityAssets();
                        Find.World.renderer.RegenerateAllLayersNow();
                    }
                });
            }

            return(false);
        }
예제 #8
0
        internal static Blueprint LoadFromXML(SaveFileInfo file)
        {
            // set up empty blueprint
            Blueprint blueprint = new Blueprint();

#if DEBUG
            Log.Message("Attempting to load from: " + file.FileInfo.FullName);
#endif

            // load stuff
            try
            {
                Scribe.InitLoading(BlueprintSaveLocation + "/" + file.FileInfo.Name);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
                Scribe.EnterNode("Blueprint");
                blueprint.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading blueprint: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            // if a def used in the blueprint doesn't exist, exposeData will throw an error,
            // which is fine. in addition, it'll set the field to null - which may result in problems down the road.
            // Make sure each item in the blueprint has a def set, if not - remove it.
            // This check itself will throw another error, which is also fine. User will have to resolve the issue manually.
            blueprint.contents = blueprint.contents.Where(item => item.BuildableDef != null).ToList();

            // return blueprint.
            return(blueprint);
        }
예제 #9
0
        internal static void _CheckVersionAndLoad(string path, ScribeMetaHeaderUtility.ScribeHeaderMode mode, Action loadAct)
        {
            bool mismatchWarnings;

            try
            {
                try
                {
                    Scribe.InitLoadingMetaHeaderOnly(path);
                }
                catch (Exception ex)
                {
                    Log.Warning(string.Concat(new object[4]
                    {
                        (object)"Exception loading ",
                        (object)path,
                        (object)": ",
                        (object)ex
                    }));
                }
                ScribeMetaHeaderUtility.LoadGameDataHeader(mode, false);
                mismatchWarnings = ScribeMetaHeaderUtility.TryCreateDialogsForVersionMismatchWarnings(loadAct);
                CrossRefResolver.ResolveAllCrossReferences();
                PostLoadInitter.DoAllPostLoadInits();
            }
            catch
            {
                CrossRefResolver.Clear();
                PostLoadInitter.Clear();
                throw;
            }
            Controller.Data.ResetInjectionSubController();
            if (mismatchWarnings)
            {
                return;
            }
            loadAct();
        }
예제 #10
0
        private static void LoadGameFromTmpSave(string fileName)
        {
            string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods
                                             select mod.ToString());

            Log.Message("Loading game with colony " + fileName + " with mods " + str);

            MemoryUtility.ClearAllMapsAndWorld();
            Current.Game = new Game();
            Scribe.loader.InitLoading(FilePathForTmpSave());
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, logVersionConflictWarning: true);
            if (Scribe.EnterNode("game"))
            {
                Current.Game = new Game();
                Current.Game.LoadGame();
                PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
            }
            else
            {
                Log.Error("Could not find game XML node.");
                Scribe.ForceStop();
            }
            RemoveTmpSave();
        }