private void SaveColony(ref PersistentColony colony)
        {
            Log.Message("Saving colony data...");

            //var oldColonySaveFile = colony.FileInfo ?? new FileInfo(GetColonySaveFilePath(colony));

            colony = PersistentColony.Convert(this.persistentWorld, this.persistentWorld.Game, colony.ColonyData);

            var colonySaveFile = GetColonySaveFilePath(colony);
            var colonyFile     = new FileInfo(colonySaveFile);

            /*
             * if (!oldColonySaveFile.FullName.EqualsIgnoreCase(colonyFile.FullName))
             * {
             *  // It could only be here?
             *  //File.Delete(oldColonySaveFile.FullName);
             * }
             */

            this.SetCurrentFile(colonyFile);

            ReferenceTable.ClearReferencesFor(colonySaveFile, true);

            var @ref = colony;

            SafeSaver.Save(colonySaveFile, "colonyfile", delegate { Scribe_Deep.Look(ref @ref, "colony"); });

            colony          = @ref;
            colony.FileInfo = colonyFile;

            Log.Message("Saved colony data.");
        }
        private void SaveColonyMapData(PersistentColony colony)
        {
            Log.Message("Saving colony map data...");

            var maps = Current.Game.Maps;

            for (var i = 0; i < maps.Count; i++)
            {
                var map = maps[i];

                if (!persistentWorld.LoadedMaps.ContainsKey(map.Tile))
                {
                    continue;
                }

                var set = persistentWorld.LoadedMaps[map.Tile];

                if (!set.Contains(colony) || set.Count != 1)
                {
                    continue;
                }

                var mapSaveFile = mapsDirectory + "/" + map.Tile + PersistentWorldMapFileExtension;
                this.SetCurrentFile(mapSaveFile);

                ReferenceTable.ClearReferencesFor(mapSaveFile, true);

                SafeSaver.Save(mapSaveFile, "mapfile", delegate
                {
                    Scribe_Deep.Look(ref map, "map");
                });
            }

            Log.Message("Saved colony map data.");
        }
Exemple #3
0
        private static bool SaveMap(Map map, string fileName)
        {
            try
            {
                LongEventHandler.SetCurrentEventText("Saving...");
                string path = FilePathForSavedMap(fileName);
                SafeSaver.Save(path, "mapsave", delegate
                {
                    ModSupport.Savemap.StoreComponentDictionary("WorkTab.FavouriteManager", "workTabFavLi");
                    ModSupport.Savemap.StoreComponentDictionary("WorkTab.PriorityManager", "workTabLi");
                    ModSupport.Savemap.StoreComponentDictionary("CombatExtended.LoadoutManager", "ceLoadoutManager");

                    WorldObject wo = Current.Game.World.worldObjects.AllWorldObjects.Find(x => x.GetType().ToString().Contains("BetterPawnControl"));
                    if (wo != null)
                    {
                        Scribe_Deep.Look(ref wo, "BetterPawnControl");
                    }

                    Map target = map;
                    Scribe_Deep.Look(ref target, "li");
                });
            }
            catch (Exception arg)
            {
                Log.Error("Exception while saving map: " + arg);
                return(false);
            }

            return(true);
        }
Exemple #4
0
 private static void SaveGame(string savePath)
 {
     LongEventHandler.QueueLongEvent(() =>
     {
         string path = savePath + ".rws";
         SafeSaver.Save(path, "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game game = Current.Game;
             Scribe_Deep.LookDeep(ref game, "game");
         });
     }, "Saving Path Data", false, null);
 }
Exemple #5
0
 private static void SaveCurrentGame()
 {
     try
     {
         string path = FilePathForTmpSave();
         SafeSaver.Save(path, "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game target = Current.Game;
             Scribe_Deep.Look(ref target, "game");
         });
     }
     catch (Exception arg)
     {
         Log.Error("Exception while saving tmp game: " + arg);
     }
 }
        private void SaveMapData()
        {
            Log.Message("Saving map data...");

            var maps = Current.Game.Maps;

            for (var i = 0; i < maps.Count; i++)
            {
                var map = maps[i];

                var mapSaveFile = mapsDirectory + "/" + map.Tile + PersistentWorldMapFileExtension;
                this.SetCurrentFile(mapSaveFile);

                SafeSaver.Save(mapSaveFile, "mapfile", delegate { Scribe_Deep.Look(ref map, "map"); });
            }

            Log.Message("Saved map data.");
        }
Exemple #7
0
 public static void Save()
 {
     try
     {
         string path  = Path.Combine(GenFilePaths.SaveDataFolderPath, "ColonyLeadershipGlobal.xml");
         string label = "ColonyLeadershipGlobal";
         Action action;
         action = delegate() {
             Scribe_Values.Look <String>(ref lastReadVersion, "lastReadVersion", "none", false);
             //Scribe_Values.LookValue<int>(ref MaxSize, "MaxSize", 90, false);
             //Scribe_Values.LookValue<bool>(ref permanentCamps, "permanentCamps", false, false);
         };
         SafeSaver.Save(path, label, action);
     }
     catch (Exception ex)
     {
         Log.Error("Exception while saving colony leadership userdata: " + ex.ToString());
     }
 }
 public void Save(string fileName = null)
 {
     try {
         string filePath = SaveFilePath;
         if (fileName != null)
         {
             filePath = string.Join("/", ColonistHistoryMod.Settings.saveFolderPath, fileName);
         }
         SafeSaver.Save(filePath, "root", delegate {
             int xmlFormatVersion = ColonistHistoryMod.XmlFormatVersion;
             Scribe_Values.Look(ref xmlFormatVersion, "xmlFormatVersion");
             List <ColonistHistoryDataList> list = this.colonistHistories.Values.ToList();
             Scribe_Collections.Look(ref list, "colonistHistories", LookMode.Deep);
         });
         Messages.Message("ColonistHistory.SaveColonistHistoriesFileAs".Translate(filePath), MessageTypeDefOf.NeutralEvent, false);
     } catch (Exception ex) {
         Log.Error("Exception while saving world: " + ex.ToString());
     }
 }
Exemple #9
0
        private static bool SaveMap(Map map, string fileName)
        {
            try
            {
                LongEventHandler.SetCurrentEventText("Saving...");
                string path = FilePathForSavedMap(fileName);
                SafeSaver.Save(path, "mapsave", delegate
                {
                    Map target = map;
                    Scribe_Deep.Look(ref target, "li");
                });
            }
            catch (Exception arg)
            {
                Log.Error("Exception while saving map: " + arg);
                return(false);
            }

            return(true);
        }
Exemple #10
0
        public static bool PreFSaveGame(string fileName)
        {
            try
            {
                Traverse traverse = Traverse.CreateWithType("GameDataSaveLoader").Field("lastSaveTick");
                SafeSaver.Save(GenFilePaths.FilePathForSavedGame(fileName), "savegame", delegate
                {
                    ScribeMetaHeaderUtility.WriteMetaHeader();
                    Game game = Current.Game;
                    Scribe_Deep.Look <Game>(ref game, "Κgame", new object[0]);
                });
                traverse.SetValue(Find.TickManager.TicksGame);
            }
            catch (Exception e)
            {
                Log.Message(string.Format("EXCEPTION! {0}.{1} \n\tMESSAGE: {2} \n\tException occurred calling {3} method", e.TargetSite.ReflectedType.Name,
                                          e.TargetSite.Name, e.Message));
            }

            return(false);
        }
        public void SaveWorldData(bool check = false)
        {
            Log.Message("Saving world data...");

            this.persistentWorld.WorldData = PersistentWorldData.Convert(Current.Game, this.persistentWorld.WorldData);

            this.SetCurrentFile(new FileInfo(worldFilePath));

            SafeSaver.Save(this.worldFilePath, "worldfile", delegate
            {
                ScribeMetaHeaderUtility.WriteMetaHeader();
                Scribe_Deep.Look(ref this.persistentWorld.WorldData, "data");
            });

            if (check)
            {
                // ScribeSaver.FinalizeSaving() stops this from calling when Persistent World is present.
                Scribe.saver.loadIDsErrorsChecker.CheckForErrorsAndClear();
            }

            Log.Message("Saved world data.");
        }
Exemple #12
0
        public static bool SaveShipAndRemoveItemStacks()
        {
            if (ShipInteriorMod.saveShip)
            {
                string        str1          = Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships");
                DirectoryInfo directoryInfo = new DirectoryInfo(str1);
                if (!directoryInfo.Exists)
                {
                    directoryInfo.Create();
                }
                string name = Faction.OfPlayer.Name;

                var def = ShipInteriorMod.shipRoot.Map.GetSpaceAtmosphereMapComponent().DefinitionAt(ShipInteriorMod.shipRoot.Position);


                string str2 = Path.Combine(str1, name + "-" + def.Name + ".rwship2");

                SafeSaver.Save(str2, "RWShip", (Action)(() =>
                {
                    ScribeMetaHeaderUtility.WriteMetaHeader();
                    Scribe_Values.Look <FactionDef>(ref Faction.OfPlayer.def, "playerFactionDef", null, false);
                    Scribe_Values.Look(ref name, "playerFactionName");
                    def.ShouldSaveThings = true;
                    Scribe_Deep.Look(ref def, "shipDefinition");
                    def.ShouldSaveThings = false;
                    Scribe_Deep.Look <ResearchManager>(ref Current.Game.researchManager, false, "researchManager", new object[0]);
                    Scribe_Deep.Look <TaleManager>(ref Current.Game.taleManager, false, "taleManager", new object[0]);
                    Scribe_Deep.Look <UniqueIDsManager>(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]);
                    Scribe_Deep.Look <TickManager>(ref Current.Game.tickManager, false, "tickManager", new object[0]);
                    Scribe_Deep.Look <DrugPolicyDatabase>(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]);
                    Scribe_Deep.Look <OutfitDatabase>(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]);
                    Scribe_Deep.Look <PlayLog>(ref Current.Game.playLog, false, "playLog", new object[0]);
                }));
                def.Destroy(DestroyMode.Vanish);
            }
            return(true);
        }
        private static List <String> saveShip(List <Building> list, List <String> errors)
        {
            Log.Message("SAVE SHIP STARTED");
            string saved_name = "ship_file_name";

            try
            {
                foreach (Building building in list)
                {
                    if (building.def == ThingDefOf.Ship_ComputerCore)
                    {
                        Log.Message("getting ship name");
                        Building_CustomShipComputerCore core = building as Building_CustomShipComputerCore;
                        saved_name = core.outputname;
                        Log.Message("ship name : " + saved_name);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Message("CUSTOM_SHIP_COMPUTER_CORE is not valid");
                errors.Add("CUSTOM_SHIP_COMPUTER_CORE is not valid");
                Log.Message(e.Message);
            }

            if (saved_name == "")
            {
                saved_name = "ship_file_name";
            }

            string str1 = Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships");

            str1.Replace('/', '\\');
            Log.Message("checking if folder exists : " + str1);
            if (!System.IO.Directory.Exists(str1))
            {
                Log.Message("creating folder : " + str1);
                System.IO.Directory.CreateDirectory(str1);
                Log.Message("folder created successfully");
            }

            int    num    = 0;
            string orstr2 = Path.Combine(str1, saved_name);

            Log.Message(orstr2);
            string str2 = orstr2 + ".rwship";

            while (System.IO.File.Exists(str2))
            {
                num++;
                str2 = orstr2 + num.ToString() + ".rwship";
            }

            Log.Message(str2);

            SafeSaver.Save(str2, "RWShip", (Action)(() =>
            {
                Log.Message("safesaver");
                ScribeMetaHeaderUtility.WriteMetaHeader();


                List <Pawn> launchedpawns = new List <Pawn>();
                foreach (Building building in list)
                {
                    if (building.def == ThingDefOf.Ship_CryptosleepCasket)
                    {
                        Building_CryptosleepCasket cask = building as Building_CryptosleepCasket;
                        if (cask.HasAnyContents)
                        {
                            Pawn pawn = cask.ContainedThing as Pawn;
                            launchedpawns.Add(pawn);
                        }
                    }
                }

                //start saving
                Scribe_Collections.Look <Building>(ref list, "buildings", LookMode.Deep);

                Scribe_Deep.Look <ResearchManager>(ref Current.Game.researchManager, false, "researchManager", new object[0]);
                Scribe_Deep.Look <UniqueIDsManager>(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]);
                Scribe_Deep.Look <DrugPolicyDatabase>(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]);
                Scribe_Deep.Look <OutfitDatabase>(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]);
                Scribe_Deep.Look <IdeoManager>(ref Current.Game.World.ideoManager, false, "ideo", new object[0]);
                //    Scribe_Deep.Look<TaleManager>(ref Current.Game.taleManager, false, "taleManager", new object[0]);
                //    Scribe_Deep.Look<PlayLog>(ref Current.Game.playLog, false, "playLog", new object[0]);


                int year = GenDate.YearsPassed;
                Log.Message("year:" + year);
                Scribe_Values.Look <int>(ref year, "currentyear", 0);

                List <Pawn> savedpawns = new List <Pawn>();
                List <Pawn> mappawns = Current.Game.CurrentMap.mapPawns.AllPawns.ToList();
                for (int i = 0; i < mappawns.Count; i++)
                {
                    Pawn p = mappawns[i];
                    if (p == null)
                    {
                        continue;
                    }
                    if (p.Destroyed)
                    {
                        continue;
                    }
                    if (p.Faction != Faction.OfPlayer)
                    {
                        continue;
                    }
                    if (launchedpawns.Contains(p))
                    {
                        continue;
                    }
                    Log.Message("rpawns:" + p.Name);
                    savedpawns.Add(p);
                }
                for (int i = 0; i < Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count(); i++)
                {
                    Pawn efpawn = null;
                    try
                    {
                        Pawn pawn = Current.Game.World.worldPawns.AllPawnsAliveOrDead.ElementAt(i);
                        efpawn = pawn;
                        if (pawn == null)
                        {
                            continue;
                        }
                        if (pawn.Destroyed)
                        {
                            continue;
                        }
                        Log.Message("world pawn:" + pawn.Name);
                        if (pawn.Faction == Faction.OfPlayer)
                        {
                            Log.Message("colonistsaved:" + pawn.Name);
                            savedpawns.Add(pawn);
                            continue;
                        }

                        foreach (Pawn colonist in launchedpawns)
                        {
                            bool doo = false;
                            if (
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Bond, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Lover, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Parent, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Child, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.ExSpouse, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Spouse, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Fiance, colonist))
                            {
                                doo = true;
                            }
                            if (pawn.relations.FamilyByBlood.Contains(colonist))
                            {
                                doo = true;
                            }
                            if (doo)
                            {
                                Log.Message("relativeof:" + colonist.Name);
                                pawn.SetFaction(Current.Game.World.factionManager.OfPlayer);
                                savedpawns.Add(pawn);
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("ERROR AT PAWN");
                        Log.Error(e.Message);
                        errors.Add("ERROR AT PAWN");
                        errors.Add(e.Message);
                        try
                        {
                            Log.Message(efpawn.Name.ToString());
                            errors.Add(efpawn.Name.ToString());
                        }
                        catch (Exception innere)
                        {
                            Log.Error("cannot access its name");
                            errors.Add("cannot access its name");
                            Log.Message("innerebegin");
                            Log.Error(innere.Message);
                            Log.Message("innereend");
                        }
                    }
                }
                Log.Message("Finishing");
                Log.Message("Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count:" + Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count());

                Log.Message("savedpawns saving");
                Scribe_Collections.Look <Pawn>(ref savedpawns, "oldpawns", LookMode.Deep);
                Log.Message("savedpawns saved successfully");
            }));
            return(errors);
        }