public static XmlDocument SaveGame()
        {
            SaveCompression.doSaveCompression = true;

            ScribeUtil.StartWritingToDoc();

            Scribe.EnterNode("savegame");
            ScribeMetaHeaderUtility.WriteMetaHeader();
            Scribe.EnterNode("game");
            int currentMapIndex = Current.Game.currentMapIndex;

            Scribe_Values.Look(ref currentMapIndex, "currentMapIndex", -1);
            Current.Game.ExposeSmallComponents();
            World world = Current.Game.World;

            Scribe_Deep.Look(ref world, "world");
            List <Map> maps = Find.Maps;

            Scribe_Collections.Look(ref maps, "maps", LookMode.Deep);
            Find.CameraDriver.Expose();
            Scribe.ExitNode();

            SaveCompression.doSaveCompression = false;

            return(ScribeUtil.FinishWritingToDoc());
        }
        private void DoExport(string name)
        {
            try
            {
                try
                {
                    Scribe.InitWriting(FilePath(name), "ManagerJobs");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("ProblemSavingFile".Translate(ex.ToString()));
                    throw;
                }

                ScribeMetaHeaderUtility.WriteMetaHeader();

                _jobStackIO = Manager.For(manager).JobStack;
                Scribe_Deep.LookDeep(ref _jobStackIO, "JobStack");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving jobstack: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
                Messages.Message("FM.JobsExported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
示例#3
0
        public static void SaveToXML(Blueprint blueprint)
        {
            try
            {
                try
                {
                    Scribe.InitWriting(FullSaveLocation(blueprint.name), "Blueprint");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("ProblemSavingFile".Translate(ex.ToString()));
                    throw;
                }
                ScribeMetaHeaderUtility.WriteMetaHeader();

                Scribe_Deep.LookDeep(ref blueprint, "Blueprint");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving blueprint: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
            }

            // set exported flag.
            blueprint.exported = true;
        }
示例#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);
 }
示例#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);
     }
 }
示例#6
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.");
        }
示例#8
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);
        }
示例#9
0
        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);
        }
示例#10
0
        public static void SaveFromPathCall(Map map, IntVec3 startVec, LocalTargetInfo dest, TraverseParms traverseParms, PathEndMode peMode)
        {
            CellRect destinationRect;

            if (dest.HasThing && peMode != PathEndMode.OnCell)
            {
                destinationRect = dest.Thing.OccupiedRect();
            }
            else
            {
                destinationRect = CellRect.SingleCell(dest.Cell);
            }

            var dumper = new PathDataLog
            {
                mapSize         = map.Size,
                start           = startVec,
                dest            = destinationRect,
                peMode          = peMode,
                tpMode          = traverseParms.mode,
                tpMaxDanger     = traverseParms.maxDanger,
                tpCanBash       = traverseParms.canBash,
                tpMoveCardinal  = traverseParms.pawn?.TicksPerMoveCardinal ?? -1,
                tpMoveDiagonal  = traverseParms.pawn?.TicksPerMoveDiagonal ?? -1,
                pathGrid        = map.pathGrid.pathGrid,
                fakeEdificeGrid = new ByteGrid(map),
                avoidGrid       = traverseParms.pawn?.GetAvoidGrid(),
                allowedArea     = traverseParms.pawn?.playerSettings?.AreaRestrictionInPawnCurrentMap
            };

            foreach (var cell in map.AllCells)
            {
                var rb    = cell.GetRegionBarrier(map);
                int value = Edifice_None;
                if (rb != null)
                {
                    var door = rb as Building_Door;
                    if (door != null)
                    {
                        switch (traverseParms.mode)
                        {
                        case TraverseMode.ByPawn:
                            if (!traverseParms.canBash && door.IsForbiddenToPass(traverseParms.pawn))
                            {
                                value = Edifice_NonTraversableDoor;
                            }
                            else if (!door.FreePassage)
                            {
                                value = door.PawnCanOpen(traverseParms.pawn) ? door.TicksToOpenNow : Edifice_NonTraversableDoor;
                            }
                            else
                            {
                                value = 0;
                            }
                            break;

                        case TraverseMode.NoPassClosedDoors:
                            value = !door.FreePassage ? Edifice_NonTraversableDoor : 0;
                            break;
                        }
                    }
                    else if ((rb as Building)?.PathFindCostFor(traverseParms.pawn) > 0)
                    {
                        value = Edifice_KnownArmedTrap;
                    }
                    else
                    {
                        value = Edifice_Impassible;
                    }
                }
                dumper.fakeEdificeGrid[cell] = (byte)value;
            }

            var savePath = Path.Combine(GenFilePaths.DevOutputFolderPath, $"{traverseParms.pawn} - {Find.TickManager.TicksAbs}");

            if (File.Exists(savePath + ".xml"))
            {
                savePath = savePath + " ";
                int saveNum = 1;
                while (File.Exists(savePath + saveNum + ".xml"))
                {
                    saveNum++;
                }
                savePath = savePath + saveNum;
            }
            try
            {
                SaveGame(savePath);
                try
                {
                    Scribe.InitWriting(savePath + ".xml", "PathDataLog");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("Stuff went wrong " + ex);
                    throw;
                }
                ScribeMetaHeaderUtility.WriteMetaHeader();

                Scribe_Deep.LookDeep(ref dumper, "PathData");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
            }
        }