Ejemplo n.º 1
0
        public static ExternalHistory Load(string path)
        {
            ExternalHistory externalHistory = null;

            try
            {
                externalHistory = new ExternalHistory();
                Scribe.loader.InitLoading(path);
                try
                {
                    Scribe_Deep.Look(ref externalHistory, "externalHistory");
                    Scribe.loader.FinalizeLoading();
                    return(externalHistory);
                }
                catch
                {
                    Scribe.ForceStop();
                    throw;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Could not load external history (" + path + "): " + ex.Message);
                return(null);
            }
        }
        public static ExternalHistory Load(string path)
        {
            ExternalHistory result = null;

            try
            {
                result = new ExternalHistory();
                Scribe.loader.InitLoading(path);
                try
                {
                    Scribe_Deep.Look <ExternalHistory>(ref result, "externalHistory", new object[0]);
                    Scribe.loader.FinalizeLoading();
                }
                catch
                {
                    Scribe.ForceStop();
                    throw;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Could not load external history (" + path + "): " + ex.Message);
                return(null);
            }
            return(result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public GameXMLUtils()
 {
     Scribe.ForceStop();
     if (ScribeMetaHeaderUtility.loadedGameVersion == null)
     {
         ScribeMetaHeaderUtility.loadedGameVersion = "";
     }
 }
Ejemplo n.º 5
0
        public static bool Prefix(ScribeSaver __instance, string filePath, string documentElementName)
        {
            if (!Enable)
            {
                return(true);
            }

            Loger.Log("ScribeSaver_InitSaving_Patch Start");
            var that = Traverse.Create(__instance);

            if (Scribe.mode != 0)
            {
                Log.Error("Called InitSaving() but current mode is " + Scribe.mode);
                Scribe.ForceStop();
            }
            if (that.Field("curPath").GetValue <string>() != null)
            {
                Log.Error("Current path is not null in InitSaving");
                that.Field("curPath").SetValue(null);
                that.Field("savedNodes").GetValue <HashSet <string> >().Clear();
                that.Field("nextListElementTemporaryId").SetValue(0);
            }
            try
            {
                Scribe.mode = LoadSaveMode.Saving;
                var saveStream = SaveData = new MemoryStream();
                //var saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                File.WriteAllText(filePath, "Online save");
                that.Field("saveStream").SetValue(saveStream);

                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent      = true;
                xmlWriterSettings.IndentChars = "\t";
                var writer = XmlWriter.Create(saveStream, xmlWriterSettings);
                that.Field("writer").SetValue(writer);

                writer.WriteStartDocument();
                __instance.EnterNode(documentElementName);
            }
            catch (Exception ex)
            {
                Log.Error("Exception while init saving file: " + filePath + "\n" + ex);
                __instance.ForceStop();
                throw;
            }
            Loger.Log("ScribeSaver_InitSaving_Patch End");
            return(false);
        }
Ejemplo n.º 6
0
        public static bool Prefix(ScribeLoader __instance, string filePath)
        {
            if (!ScribeLoader_InitLoading_Patch.Enable)
            {
                return(true);
            }
            Loger.Log("ScribeLoader_InitLoadingMetaHeaderOnly_Patch Start");

            if (Scribe.mode != 0)
            {
                Log.Error("Called InitLoadingMetaHeaderOnly() but current mode is " + Scribe.mode);
                Scribe.ForceStop();
            }
            try
            {
                using (var input = new MemoryStream(ScribeLoader_InitLoading_Patch.LoadData))
                //using (StreamReader input = new StreamReader(filePath))
                {
                    using (XmlTextReader xmlTextReader = new XmlTextReader(input))
                    {
                        if (!ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader))
                        {
                            return(false);
                        }
                        using (XmlReader reader = xmlTextReader.ReadSubtree())
                        {
                            XmlDocument xmlDocument = new XmlDocument();
                            xmlDocument.Load(reader);
                            XmlElement xmlElement = xmlDocument.CreateElement("root");
                            xmlElement.AppendChild(xmlDocument.DocumentElement);
                            __instance.curXmlParent = xmlElement;
                        }
                    }
                }
                Scribe.mode = LoadSaveMode.LoadingVars;
            }
            catch (Exception ex)
            {
                Log.Error("Exception while init loading meta header: " + filePath + "\n" + ex);
                __instance.ForceStop();
                throw;
            }

            Loger.Log("ScribeLoader_InitLoadingMetaHeaderOnly_Patch End");
            return(false);
        }
Ejemplo n.º 7
0
 public static bool Prefix(ScribeLoader __instance, string filePath)
 {
     if (!Enable)
     {
         return(true);
     }
     Loger.Log("ScribeLoader_InitLoading_Patch Start");
     if (Scribe.mode != 0)
     {
         Log.Error("Called InitLoading() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     if (__instance.curParent != null)
     {
         Log.Error("Current parent is not null in InitLoading");
         __instance.curParent = null;
     }
     if (__instance.curPathRelToParent != null)
     {
         Log.Error("Current path relative to parent is not null in InitLoading");
         __instance.curPathRelToParent = null;
     }
     try
     {
         using (var input = new MemoryStream(LoadData))
         //using (StreamReader input = new StreamReader(filePath))
         {
             using (XmlTextReader reader = new XmlTextReader(input))
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(reader);
                 __instance.curXmlParent = xmlDocument.DocumentElement;
             }
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error("Exception while init loading file: " + filePath + "\n" + ex);
         __instance.ForceStop();
         throw;
     }
     Loger.Log("ScribeLoader_InitLoading_Patch End");
     return(false);
 }
Ejemplo n.º 8
0
        static ColonyLeadership()
        {
            try
            {
                Detour.Detours.TryDetourFromTo(typeof(ColonistBarColonistDrawer).GetMethod("DrawIcons", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance), typeof(Icon).GetMethod("DrawIconsModded"));
            }
            catch (Exception e)
            {
                //File.WriteAllText("logt.txt", e.Message.ToString());
            }

            govtypes.Add(new GovType("Democracy", "DemocracyDesc", "Leader"));
            govtypes.Add(new GovType("Dictatorship", "DictatorshipDesc", "Dictator"));
            //govtypes.Add(new GovType("Monarchy", "MonarchyDesc", "Ruler"));
            bool flag = File.Exists(Path.Combine(GenFilePaths.SaveDataFolderPath, "ColonyLeadershipGlobal.xml"));

            if (flag)
            {
                try
                {
                    Scribe.loader.InitLoading(Path.Combine(GenFilePaths.SaveDataFolderPath, "ColonyLeadershipGlobal.xml"));
                    Scribe_Values.Look <String>(ref lastReadVersion, "lastReadVersion", "none", false);
                    Scribe.loader.FinalizeLoading();


                    //PostLoadIniter.DoAllPostLoadInits();
                }
                catch (Exception ex)
                {
                    //File.WriteAllText("logt.txt", ex.Message.ToString());
                    Log.Error("Exception loading colony leadership userdata: " + ex.ToString());
                    Scribe.ForceStop();
                }
            }

            if (ColonyLeadership.lastReadVersion != ColonyLeadership.newVersion)
            {
                DefDatabase <MainButtonDef> .GetNamed("LeaderTab").label = "(!) " + "LeadershipTab";

                doUpdateNotes();
            }
            doHelpNotes();
        }
Ejemplo n.º 9
0
        public static void InitLoading(string[] filePaths)
        {
            if (Scribe.mode != LoadSaveMode.Inactive)
            {
                Log.Error("Called InitLoading() but current mode is " + Scribe.mode.ToString(), false);
                Scribe.ForceStop();
            }

            try
            {
                foreach (var filePath in filePaths)
                {
                    if (xmlParents.ContainsKey(filePath))
                    {
                        continue;
                    }

                    using (var streamReader = new StreamReader(filePath))
                    {
                        using (var xmlTextReader = new XmlTextReader(streamReader))
                        {
                            var xmlDocument = new XmlDocument();
                            xmlDocument.Load(xmlTextReader);
                            xmlParents.Add(filePath, xmlDocument.DocumentElement);
                        }
                    }
                }

                Scribe.mode = LoadSaveMode.LoadingVars;
            }
            catch (Exception e)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception while init loading files: ",
                    filePaths.ToCommaList(),
                    "\n",
                    e
                }), false);

                throw;
            }
        }
Ejemplo n.º 10
0
 // Performs the setup needed to begin a scribe loading operation, similar to ScribeLoader.InitLoad(), but
 // uses a StringReader instead of reading from a file.
 private static void InitLoadFromString(String value)
 {
     if (Scribe.mode != LoadSaveMode.Inactive)
     {
         Logger.Error("Called InitLoading() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     if (Scribe.loader.curParent != null)
     {
         Logger.Error("Current parent is not null in InitLoading");
         Scribe.loader.curParent = null;
     }
     if (Scribe.loader.curPathRelToParent != null)
     {
         Logger.Error("Current path relative to parent is not null in InitLoading");
         Scribe.loader.curPathRelToParent = null;
     }
     try {
         using (TextReader textReader = new StringReader(value)) {
             using (XmlTextReader xmlTextReader = new XmlTextReader(textReader)) {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(xmlTextReader);
                 Scribe.loader.curXmlParent = xmlDocument.DocumentElement;
             }
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex) {
         Logger.Error(string.Concat(new object[] {
             "Exception while unmarshalling XML",
             "\n",
             ex
         }));
         Scribe.loader.ForceStop();
         throw;
     }
 }
Ejemplo n.º 11
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();
        }