예제 #1
0
 public static bool TryLoadScenario(string absPath, ScenarioCategory category, out Scenario scen)
 {
     scen = null;
     try
     {
         Scribe.loader.InitLoading(absPath);
         try
         {
             ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Scenario, true);
             Scribe_Deep.Look <Scenario>(ref scen, "scenario", new object[0]);
             Scribe.loader.FinalizeLoading();
         }
         catch
         {
             Scribe.ForceStop();
             throw;
         }
         scen.fileName = Path.GetFileNameWithoutExtension(new FileInfo(absPath).Name);
         scen.Category = category;
     }
     catch (Exception ex)
     {
         Log.Error("Exception loading scenario: " + ex.ToString(), false);
         scen = null;
         Scribe.ForceStop();
     }
     return(scen != null);
 }
예제 #2
0
 public void InitLoadingMetaHeaderOnly(string filePath)
 {
     if (Scribe.mode != 0)
     {
         Log.Error("Called InitLoadingMetaHeaderOnly() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     try
     {
         using (StreamReader input = new StreamReader(filePath))
         {
             using XmlTextReader xmlTextReader = new XmlTextReader(input);
             if (!ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader))
             {
                 return;
             }
             using XmlReader reader = xmlTextReader.ReadSubtree();
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.Load(reader);
             XmlElement xmlElement = xmlDocument.CreateElement("root");
             xmlElement.AppendChild(xmlDocument.DocumentElement);
             curXmlParent = xmlElement;
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error("Exception while init loading meta header: " + filePath + "\n" + ex);
         ForceStop();
         throw;
     }
 }
예제 #3
0
        public static void LoadGameFromSaveFileNow(string fileName)
        {
            string str = (from mod in LoadedModManager.RunningMods
                          select mod.ToString()).ToCommaList();

            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();
            try
            {
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, logVersionConflictWarning: true);
                if (!Scribe.EnterNode("game"))
                {
                    Log.Error("Could not find game XML node.");
                    Scribe.ForceStop();
                    return;
                }
                Current.Game = new Game();
                Current.Game.LoadGame();
            }
            catch (Exception)
            {
                Scribe.ForceStop();
                throw;
            }
            PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
            DeepProfiler.End();
        }
예제 #4
0
 public static void LoadGameDataHeader(ScribeHeaderMode mode, bool logVersionConflictWarning)
 {
     ScribeMetaHeaderUtility.loadedGameVersion  = "Unknown";
     ScribeMetaHeaderUtility.loadedModIdsList   = null;
     ScribeMetaHeaderUtility.loadedModNamesList = null;
     ScribeMetaHeaderUtility.lastMode           = mode;
     if (Scribe.mode != 0 && Scribe.EnterNode("meta"))
     {
         try
         {
             Scribe_Values.Look <string>(ref ScribeMetaHeaderUtility.loadedGameVersion, "gameVersion", (string)null, false);
             Scribe_Collections.Look <string>(ref ScribeMetaHeaderUtility.loadedModIdsList, "modIds", LookMode.Undefined, new object[0]);
             Scribe_Collections.Look <string>(ref ScribeMetaHeaderUtility.loadedModNamesList, "modNames", LookMode.Undefined, new object[0]);
         }
         finally
         {
             Scribe.ExitNode();
         }
     }
     if (logVersionConflictWarning)
     {
         if (mode != ScribeHeaderMode.Map && UnityData.isEditor)
         {
             return;
         }
         if (!ScribeMetaHeaderUtility.VersionsMatch())
         {
             Log.Warning("Loaded file (" + mode + ") is from version " + ScribeMetaHeaderUtility.loadedGameVersion + ", we are running version " + VersionControl.CurrentVersionStringWithRev + ".");
         }
     }
 }
예제 #5
0
 public static string GameVersionOf(FileInfo file)
 {
     if (!file.Exists)
     {
         throw new ArgumentException();
     }
     try
     {
         using (StreamReader input = new StreamReader(file.FullName))
         {
             using (XmlTextReader xmlTextReader = new XmlTextReader(input))
             {
                 if (ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader) && xmlTextReader.ReadToDescendant("gameVersion"))
                 {
                     return(VersionControl.VersionStringWithoutRev(xmlTextReader.ReadString()));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error("Exception getting game version of " + file.Name + ": " + ex.ToString());
     }
     return(null);
 }
        public static void LoadGameFromSaveFile(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);
            if (Scribe.EnterNode("game"))
            {
                Current.Game = new Game();
                Current.Game.LoadGame();
                PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
                DeepProfiler.End();
            }
            else
            {
                Log.Error("Could not find game XML node.");
                Scribe.ForceStop();
            }
        }
        private static void <SaveGame> m__0()
        {
            ScribeMetaHeaderUtility.WriteMetaHeader();
            Game game = Current.Game;

            Scribe_Deep.Look <Game>(ref game, "game", new object[0]);
        }
예제 #8
0
        public static bool TryCreateDialogsForVersionMismatchWarnings(Action confirmedAction)
        {
            string text  = null;
            string text2 = null;

            if (!BackCompatibility.IsSaveCompatibleWith(ScribeMetaHeaderUtility.loadedGameVersion) && !ScribeMetaHeaderUtility.VersionsMatch())
            {
                text2 = "VersionMismatch".Translate();
                string text3 = (!ScribeMetaHeaderUtility.loadedGameVersion.NullOrEmpty()) ? ScribeMetaHeaderUtility.loadedGameVersion : ("(" + "UnknownLower".Translate() + ")");
                text = ((ScribeMetaHeaderUtility.lastMode != ScribeHeaderMode.Map) ? ((ScribeMetaHeaderUtility.lastMode != ScribeHeaderMode.World) ? "FileIncompatibleWarning".Translate(text3, VersionControl.CurrentVersionString) : "WorldFileVersionMismatch".Translate(text3, VersionControl.CurrentVersionString)) : "SaveGameIncompatibleWarningText".Translate(text3, VersionControl.CurrentVersionString));
            }
            bool   flag  = false;
            string text4 = default(string);
            string text5 = default(string);

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text4, out text5))
            {
                flag = true;
                string text6 = "ModsMismatchWarningText".Translate(text4, text5);
                text = ((text != null) ? (text + "\n\n" + text6) : text6);
                if (text2 == null)
                {
                    text2 = "ModsMismatchWarningTitle".Translate();
                }
            }
            if (text != null)
            {
                string            text7  = text;
                string            title  = text2;
                Dialog_MessageBox dialog = Dialog_MessageBox.CreateConfirmation(text7, confirmedAction, false, title);
                dialog.buttonAText = "LoadAnyway".Translate();
                if (flag)
                {
                    dialog.buttonCText   = "ChangeLoadedMods".Translate();
                    dialog.buttonCAction = delegate
                    {
                        int num = ModLister.InstalledModsListHash(false);
                        ModsConfig.SetActiveToList(ScribeMetaHeaderUtility.loadedModIdsList);
                        ModsConfig.Save();
                        if (num == ModLister.InstalledModsListHash(false))
                        {
                            IEnumerable <string> items = from id in Enumerable.Range(0, ScribeMetaHeaderUtility.loadedModIdsList.Count)
                                                         where ModLister.GetModWithIdentifier(ScribeMetaHeaderUtility.loadedModIdsList[id]) == null
                                                         select ScribeMetaHeaderUtility.loadedModNamesList[id];
                            Messages.Message(string.Format("{0}: {1}", "MissingMods".Translate(), GenText.ToCommaList(items, true)), MessageTypeDefOf.RejectInput);
                            dialog.buttonCClose = false;
                        }
                        else
                        {
                            ModsConfig.RestartFromChangedMods();
                        }
                    };
                }
                Find.WindowStack.Add(dialog);
                return(true);
            }
            return(false);
        }
예제 #9
0
        public static bool TryCreateDialogsForVersionMismatchWarnings(Action confirmedAction)
        {
            string text  = null;
            string text2 = null;

            if (!BackCompatibility.IsSaveCompatibleWith(ScribeMetaHeaderUtility.loadedGameVersion) && !ScribeMetaHeaderUtility.VersionsMatch())
            {
                text2 = "VersionMismatch".Translate();
                string value = (!ScribeMetaHeaderUtility.loadedGameVersion.NullOrEmpty()) ? ScribeMetaHeaderUtility.loadedGameVersion : ("(" + "UnknownLower".Translate() + ")");
                if (ScribeMetaHeaderUtility.lastMode == ScribeMetaHeaderUtility.ScribeHeaderMode.Map)
                {
                    text = "SaveGameIncompatibleWarningText".Translate(value, VersionControl.CurrentVersionString);
                }
                else if (ScribeMetaHeaderUtility.lastMode == ScribeMetaHeaderUtility.ScribeHeaderMode.World)
                {
                    text = "WorldFileVersionMismatch".Translate(value, VersionControl.CurrentVersionString);
                }
                else
                {
                    text = "FileIncompatibleWarning".Translate(value, VersionControl.CurrentVersionString);
                }
            }
            bool   flag = false;
            string value2;
            string value3;

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out value2, out value3))
            {
                flag = true;
                string text3 = "ModsMismatchWarningText".Translate(value2, value3);
                if (text == null)
                {
                    text = text3;
                }
                else
                {
                    text = text + "\n\n" + text3;
                }
                if (text2 == null)
                {
                    text2 = "ModsMismatchWarningTitle".Translate();
                }
            }
            if (text != null)
            {
                ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0 <TryCreateDialogsForVersionMismatchWarnings> c__AnonStorey = new ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0();
                ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0 arg_14A_0 = < TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey;
                string text4 = text;
                string title = text2;
                arg_14A_0.dialog = Dialog_MessageBox.CreateConfirmation(text4, confirmedAction, false, title);
예제 #10
0
        public static void ErrorWhileLoadingGame(Exception e)
        {
            string text  = "ErrorWhileLoadingMap".Translate();
            string text2 = default(string);
            string text3 = default(string);

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text2, out text3))
            {
                text = text + "\n\n" + "ModsMismatchWarningText".Translate(text2, text3);
            }
            DelayedErrorWindowRequest.Add(text, "ErrorWhileLoadingMapTitle".Translate());
            Scribe.ForceStop();
            GenScene.GoToMainMenu();
        }
예제 #11
0
 public static void SaveScenario(Scenario scen, string absFilePath)
 {
     try
     {
         scen.fileName = Path.GetFileNameWithoutExtension(absFilePath);
         SafeSaver.Save(absFilePath, "savedscenario", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Scribe_Deep.Look <Scenario>(ref scen, "scenario", new object[0]);
         }, false);
     }
     catch (Exception ex)
     {
         Log.Error("Exception while saving world: " + ex.ToString(), false);
     }
 }
예제 #12
0
 public static bool ReadToMetaElement(XmlTextReader textReader)
 {
     if (!ScribeMetaHeaderUtility.ReadToNextElement(textReader))
     {
         return(false);
     }
     if (!ScribeMetaHeaderUtility.ReadToNextElement(textReader))
     {
         return(false);
     }
     if (textReader.Name != "meta")
     {
         return(false);
     }
     return(true);
 }
예제 #13
0
 public static void SaveGame(string fileName)
 {
     try
     {
         SafeSaver.Save(GenFilePaths.FilePathForSavedGame(fileName), "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game target = Current.Game;
             Scribe_Deep.Look(ref target, "game");
         }, Find.GameInfo.permadeathMode);
         lastSaveTick = Find.TickManager.TicksGame;
     }
     catch (Exception arg)
     {
         Log.Error("Exception while saving game: " + arg);
     }
 }
예제 #14
0
 public static void CheckVersionAndLoad(string path, ScribeMetaHeaderUtility.ScribeHeaderMode mode, Action loadAct)
 {
     try
     {
         Scribe.loader.InitLoadingMetaHeaderOnly(path);
         ScribeMetaHeaderUtility.LoadGameDataHeader(mode, logVersionConflictWarning: false);
         Scribe.loader.FinalizeLoading();
     }
     catch (Exception ex)
     {
         Log.Warning("Exception loading " + path + ": " + ex);
         Scribe.ForceStop();
     }
     if (!ScribeMetaHeaderUtility.TryCreateDialogsForVersionMismatchWarnings(loadAct))
     {
         loadAct();
     }
 }
예제 #15
0
 public static void SaveGame(string fileName)
 {
     try
     {
         string path = GenFilePaths.FilePathForSavedGame(fileName);
         SafeSaver.Save(path, "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game game = Current.Game;
             Scribe_Deep.Look <Game>(ref game, "game", new object[0]);
         }, Find.GameInfo.permadeathMode);
         GameDataSaveLoader.lastSaveTick = Find.TickManager.TicksGame;
     }
     catch (Exception arg)
     {
         Log.Error("Exception while saving game: " + arg, false);
     }
 }
예제 #16
0
 public void InitLoadingMetaHeaderOnly(string filePath)
 {
     if (Scribe.mode != LoadSaveMode.Inactive)
     {
         Log.Error("Called InitLoadingMetaHeaderOnly() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     try
     {
         using (StreamReader streamReader = new StreamReader(filePath))
         {
             using (XmlTextReader xmlTextReader = new XmlTextReader(streamReader))
             {
                 if (!ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader))
                 {
                     return;
                 }
                 using (XmlReader xmlReader = xmlTextReader.ReadSubtree())
                 {
                     XmlDocument xmlDocument = new XmlDocument();
                     xmlDocument.Load(xmlReader);
                     XmlElement xmlElement = xmlDocument.CreateElement("root");
                     xmlElement.AppendChild(xmlDocument.DocumentElement);
                     this.curXmlParent = xmlElement;
                 }
             }
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat(new object[]
         {
             "Exception while init loading meta header: ",
             filePath,
             "\n",
             ex
         }));
         this.ForceStop();
         throw;
     }
 }
 public static void LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode mode, bool logVersionConflictWarning)
 {
     ScribeMetaHeaderUtility.loadedGameVersion  = "Unknown";
     ScribeMetaHeaderUtility.loadedModIdsList   = null;
     ScribeMetaHeaderUtility.loadedModNamesList = null;
     ScribeMetaHeaderUtility.lastMode           = mode;
     if (Scribe.mode != LoadSaveMode.Inactive && Scribe.EnterNode("meta"))
     {
         try
         {
             Scribe_Values.Look <string>(ref ScribeMetaHeaderUtility.loadedGameVersion, "gameVersion", null, false);
             Scribe_Collections.Look <string>(ref ScribeMetaHeaderUtility.loadedModIdsList, "modIds", LookMode.Undefined, new object[0]);
             Scribe_Collections.Look <string>(ref ScribeMetaHeaderUtility.loadedModNamesList, "modNames", LookMode.Undefined, new object[0]);
         }
         finally
         {
             Scribe.ExitNode();
         }
     }
     if (logVersionConflictWarning)
     {
         if (mode == ScribeMetaHeaderUtility.ScribeHeaderMode.Map || !UnityData.isEditor)
         {
             if (!ScribeMetaHeaderUtility.VersionsMatch())
             {
                 Log.Warning(string.Concat(new object[]
                 {
                     "Loaded file (",
                     mode,
                     ") is from version ",
                     ScribeMetaHeaderUtility.loadedGameVersion,
                     ", we are running version ",
                     VersionControl.CurrentVersionStringWithRev,
                     "."
                 }), false);
             }
         }
     }
 }
예제 #18
0
        public static bool LoadedModsMatchesActiveMods(out string loadedModsSummary, out string runningModsSummary)
        {
            loadedModsSummary  = null;
            runningModsSummary = null;
            List <string> list = (from mod in LoadedModManager.RunningMods
                                  select mod.Identifier).ToList();

            if (ScribeMetaHeaderUtility.ModListsMatch(ScribeMetaHeaderUtility.loadedModIdsList, list))
            {
                return(true);
            }
            if (ScribeMetaHeaderUtility.loadedModNamesList == null)
            {
                loadedModsSummary = "None".Translate();
            }
            else
            {
                loadedModsSummary = GenText.ToCommaList(ScribeMetaHeaderUtility.loadedModNamesList, true);
            }
            runningModsSummary = GenText.ToCommaList(from id in list
                                                     select ModLister.GetModWithIdentifier(id).Name, true);
            return(false);
        }
예제 #19
0
 public static void CheckVersionAndLoad(string path, ScribeMetaHeaderUtility.ScribeHeaderMode mode, Action loadAct)
 {
     try
     {
         Scribe.loader.InitLoadingMetaHeaderOnly(path);
         ScribeMetaHeaderUtility.LoadGameDataHeader(mode, false);
         Scribe.loader.FinalizeLoading();
     }
     catch (Exception ex)
     {
         Log.Warning(string.Concat(new object[]
         {
             "Exception loading ",
             path,
             ": ",
             ex
         }), false);
         Scribe.ForceStop();
     }
     if (!ScribeMetaHeaderUtility.TryCreateDialogsForVersionMismatchWarnings(loadAct))
     {
         loadAct();
     }
 }
        public static bool TryCreateDialogsForVersionMismatchWarnings(Action confirmedAction)
        {
            string text  = null;
            string text2 = null;

            if (!BackCompatibility.IsSaveCompatibleWith(ScribeMetaHeaderUtility.loadedGameVersion) && !ScribeMetaHeaderUtility.VersionsMatch())
            {
                text2 = "VersionMismatch".Translate();
                string text3 = (!ScribeMetaHeaderUtility.loadedGameVersion.NullOrEmpty()) ? ScribeMetaHeaderUtility.loadedGameVersion : ("(" + "UnknownLower".Translate() + ")");
                if (ScribeMetaHeaderUtility.lastMode == ScribeMetaHeaderUtility.ScribeHeaderMode.Map)
                {
                    text = "SaveGameIncompatibleWarningText".Translate(new object[]
                    {
                        text3,
                        VersionControl.CurrentVersionString
                    });
                }
                else if (ScribeMetaHeaderUtility.lastMode == ScribeMetaHeaderUtility.ScribeHeaderMode.World)
                {
                    text = "WorldFileVersionMismatch".Translate(new object[]
                    {
                        text3,
                        VersionControl.CurrentVersionString
                    });
                }
                else
                {
                    text = "FileIncompatibleWarning".Translate(new object[]
                    {
                        text3,
                        VersionControl.CurrentVersionString
                    });
                }
            }
            bool   flag = false;
            string text4;
            string text5;

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text4, out text5))
            {
                flag = true;
                string text6 = "ModsMismatchWarningText".Translate(new object[]
                {
                    text4,
                    text5
                });
                if (text == null)
                {
                    text = text6;
                }
                else
                {
                    text = text + "\n\n" + text6;
                }
                if (text2 == null)
                {
                    text2 = "ModsMismatchWarningTitle".Translate();
                }
            }
            bool result;

            if (text != null)
            {
                ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0 <TryCreateDialogsForVersionMismatchWarnings> c__AnonStorey = new ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0();
                ScribeMetaHeaderUtility.< TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey0 <TryCreateDialogsForVersionMismatchWarnings> c__AnonStorey2 = < TryCreateDialogsForVersionMismatchWarnings > c__AnonStorey;
                string text7 = text;
                string title = text2;
 internal void <> m__0()
 {
     ScribeMetaHeaderUtility.WriteMetaHeader();
     Scribe_Deep.Look <Scenario>(ref this.scen, "scenario", new object[0]);
 }
예제 #22
0
 public SaveFileInfo(FileInfo fileInfo)
 {
     this.fileInfo = fileInfo;
     gameVersion   = ScribeMetaHeaderUtility.GameVersionOf(fileInfo);
 }