public static GlobalTargetInfo GlobalTargetInfoFromNode(XmlNode node, string label, GlobalTargetInfo defaultValue) { LoadIDsWantedBank loadIDs = Scribe.loader.crossRefs.loadIDs; if (node != null && Scribe.EnterNode(label)) { try { string innerText = node.InnerText; if (innerText.Length != 0 && innerText[0] == '(') { string str = default(string); string targetLoadID = default(string); ScribeExtractor.ExtractCellAndMapPairFromTargetInfo(innerText, out str, out targetLoadID); loadIDs.RegisterLoadIDReadFromXml(null, typeof(Thing), "thing"); loadIDs.RegisterLoadIDReadFromXml(targetLoadID, typeof(Map), "map"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(WorldObject), "worldObject"); return(new GlobalTargetInfo(IntVec3.FromString(str), null, true)); } int tile = default(int); if (int.TryParse(innerText, out tile)) { loadIDs.RegisterLoadIDReadFromXml(null, typeof(Thing), "thing"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(Map), "map"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(WorldObject), "worldObject"); return(new GlobalTargetInfo(tile)); } if (innerText.Length != 0 && innerText[0] == '@') { loadIDs.RegisterLoadIDReadFromXml(null, typeof(Thing), "thing"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(Map), "map"); loadIDs.RegisterLoadIDReadFromXml(innerText.Substring(1), typeof(WorldObject), "worldObject"); return(GlobalTargetInfo.Invalid); } loadIDs.RegisterLoadIDReadFromXml(innerText, typeof(Thing), "thing"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(Map), "map"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(WorldObject), "worldObject"); return(GlobalTargetInfo.Invalid); } finally { Scribe.ExitNode(); } } loadIDs.RegisterLoadIDReadFromXml(null, typeof(Thing), label + "/thing"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(Map), label + "/map"); loadIDs.RegisterLoadIDReadFromXml(null, typeof(WorldObject), label + "/worldObject"); return(defaultValue); }
public void Expose() { if (Scribe.EnterNode("cameraMap")) { try { Scribe_Values.Look <Vector3>(ref this.rootPos, "camRootPos", default(Vector3), false); Scribe_Values.Look <float>(ref this.desiredSize, "desiredSize", 0f, false); this.rootSize = this.desiredSize; } finally { Scribe.ExitNode(); } } }
public void Expose() { if (Scribe.EnterNode("cameraMap")) { try { Scribe_Values.Look(ref rootPos, "camRootPos"); Scribe_Values.Look(ref desiredSize, "desiredSize", 0f); rootSize = desiredSize; } finally { Scribe.ExitNode(); } } }
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(); } }
public static void ErrorWhileLoadingGame(Exception e) { string text = "ErrorWhileLoadingMap".Translate(); string text2; string text3; if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text2, out text3)) { text = text + "\n\n" + "ModsMismatchWarningText".Translate(new object[] { text2, text3 }); } DelayedErrorWindowRequest.Add(text, "ErrorWhileLoadingMapTitle".Translate()); Scribe.ForceStop(); GenScene.GoToMainMenu(); }
public static GlobalTargetInfo ResolveGlobalTargetInfo(GlobalTargetInfo loaded, string label) { if (Scribe.EnterNode(label)) { try { Thing thing = Scribe.loader.crossRefs.TakeResolvedRef <Thing>("thing"); Map map = Scribe.loader.crossRefs.TakeResolvedRef <Map>("map"); WorldObject worldObject = Scribe.loader.crossRefs.TakeResolvedRef <WorldObject>("worldObject"); IntVec3 cell = loaded.Cell; int tile = loaded.Tile; if (thing != null) { return(new GlobalTargetInfo(thing)); } if (worldObject != null) { return(new GlobalTargetInfo(worldObject)); } if (cell.IsValid) { if (map != null) { return(new GlobalTargetInfo(cell, map, false)); } return(GlobalTargetInfo.Invalid); } else { if (tile >= 0) { return(new GlobalTargetInfo(tile)); } return(GlobalTargetInfo.Invalid); } } finally { Scribe.ExitNode(); } return(loaded); } return(loaded); }
public void InitLoading(string filePath) { if (Scribe.mode != LoadSaveMode.Inactive) { Log.Error("Called InitLoading() but current mode is " + Scribe.mode); Scribe.ForceStop(); } if (this.curParent != null) { Log.Error("Current parent is not null in InitLoading"); this.curParent = null; } if (this.curPathRelToParent != null) { Log.Error("Current path relative to parent is not null in InitLoading"); this.curPathRelToParent = null; } try { using (StreamReader streamReader = new StreamReader(filePath)) { using (XmlTextReader xmlTextReader = new XmlTextReader(streamReader)) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(xmlTextReader); this.curXmlParent = xmlDocument.DocumentElement; } } Scribe.mode = LoadSaveMode.LoadingVars; } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception while init loading file: ", filePath, "\n", ex })); this.ForceStop(); throw; } }
public static void WriteMetaHeader() { if (Scribe.EnterNode("meta")) { try { string value = VersionControl.CurrentVersionStringWithRev; Scribe_Values.Look(ref value, "gameVersion"); List <string> list = LoadedModManager.RunningMods.Select((ModContentPack mod) => mod.PackageId).ToList(); Scribe_Collections.Look(ref list, "modIds", LookMode.Undefined); List <string> list2 = LoadedModManager.RunningMods.Select((ModContentPack mod) => mod.Name).ToList(); Scribe_Collections.Look(ref list2, "modNames", LookMode.Undefined); } finally { Scribe.ExitNode(); } } }
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 WriteMetaHeader() { if (Scribe.EnterNode("meta")) { try { string currentVersionStringWithRev = VersionControl.CurrentVersionStringWithRev; Scribe_Values.Look <string>(ref currentVersionStringWithRev, "gameVersion", null, false); List <string> list = (from mod in LoadedModManager.RunningMods select mod.Identifier).ToList <string>(); Scribe_Collections.Look <string>(ref list, "modIds", LookMode.Undefined, new object[0]); List <string> list2 = (from mod in LoadedModManager.RunningMods select mod.Name).ToList <string>(); Scribe_Collections.Look <string>(ref list2, "modNames", LookMode.Undefined, new object[0]); } finally { Scribe.ExitNode(); } } }
public static LocalTargetInfo ResolveLocalTargetInfo(LocalTargetInfo loaded, string label) { if (Scribe.EnterNode(label)) { try { Thing thing = Scribe.loader.crossRefs.TakeResolvedRef <Thing>("thing"); IntVec3 cell = loaded.Cell; if (thing != null) { return(new LocalTargetInfo(thing)); } return(new LocalTargetInfo(cell)); } finally { Scribe.ExitNode(); } } return(loaded); }
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); } } } }
public void InitSaving(string filePath, string documentElementName) { if (Scribe.mode != LoadSaveMode.Inactive) { Log.Error("Called InitSaving() but current mode is " + Scribe.mode, false); Scribe.ForceStop(); } if (this.curPath != null) { Log.Error("Current path is not null in InitSaving", false); this.curPath = null; this.savedNodes.Clear(); this.nextListElementTemporaryId = 0; } try { Scribe.mode = LoadSaveMode.Saving; this.saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Indent = true; xmlWriterSettings.IndentChars = "\t"; this.writer = XmlWriter.Create(this.saveStream, xmlWriterSettings); this.writer.WriteStartDocument(); this.EnterNode(documentElementName); } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception while init saving file: ", filePath, "\n", ex }), false); this.ForceStop(); throw; } }
public static BodyPartRecord BodyPartFromNode(XmlNode node, string label, BodyPartRecord defaultValue) { if (node != null && Scribe.EnterNode(label)) { try { XmlAttribute xmlAttribute = node.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { return(null); } BodyDef bodyDef = DefFromNode <BodyDef>(Scribe.loader.curXmlParent["body"]); XmlElement xmlElement = Scribe.loader.curXmlParent["index"]; int index = (xmlElement == null) ? (-1) : int.Parse(xmlElement.InnerText); return(bodyDef?.GetPartAtIndex(index)); } finally { Scribe.ExitNode(); } } return(defaultValue); }
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(); return; } Log.Error("Could not find game XML node."); Scribe.ForceStop(); }
public void InitLoading(string filePath) { if (Scribe.mode != 0) { Log.Error("Called InitLoading() but current mode is " + Scribe.mode); Scribe.ForceStop(); } if (curParent != null) { Log.Error("Current parent is not null in InitLoading"); curParent = null; } if (curPathRelToParent != null) { Log.Error("Current path relative to parent is not null in InitLoading"); curPathRelToParent = null; } try { using (StreamReader input = new StreamReader(filePath)) { using (XmlTextReader reader = new XmlTextReader(input)) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); curXmlParent = xmlDocument.DocumentElement; } } Scribe.mode = LoadSaveMode.LoadingVars; } catch (Exception ex) { Log.Error("Exception while init loading file: " + filePath + "\n" + ex); ForceStop(); throw; } }
public void FinalizeLoading() { if (Scribe.mode != LoadSaveMode.LoadingVars) { Log.Error("Called FinalizeLoading() but current mode is " + Scribe.mode); return; } try { Scribe.ExitNode(); this.curXmlParent = null; this.curParent = null; this.curPathRelToParent = null; Scribe.mode = LoadSaveMode.Inactive; this.crossRefs.ResolveAllCrossReferences(); this.initer.DoAllPostLoadInits(); } catch (Exception arg) { Log.Error("Exception in FinalizeLoading(): " + arg); this.ForceStop(); throw; } }
public static void LoadGameDataHeader(ScribeHeaderMode mode, bool logVersionConflictWarning) { loadedGameVersion = "Unknown"; loadedModIdsList = null; loadedModNamesList = null; lastMode = mode; if (Scribe.mode != 0 && Scribe.EnterNode("meta")) { try { Scribe_Values.Look(ref loadedGameVersion, "gameVersion"); Scribe_Collections.Look(ref loadedModIdsList, "modIds", LookMode.Undefined); Scribe_Collections.Look(ref loadedModNamesList, "modNames", LookMode.Undefined); } finally { Scribe.ExitNode(); } } if (logVersionConflictWarning && (mode == ScribeHeaderMode.Map || !UnityData.isEditor) && !VersionsMatch()) { Log.Warning("Loaded file (" + mode + ") is from version " + loadedGameVersion + ", we are running version " + VersionControl.CurrentVersionStringWithRev + "."); } }
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 void ExposeData() { Scribe_Values.Look <int>(ref this.uniqueID, "uniqueID", -1, false); Scribe_Deep.Look <MapInfo>(ref this.info, "mapInfo", new object[0]); if (Scribe.mode == LoadSaveMode.Saving) { this.compressor = new MapFileCompressor(this); this.compressor.BuildCompressedString(); this.ExposeComponents(); this.compressor.ExposeData(); HashSet <string> hashSet = new HashSet <string>(); if (Scribe.EnterNode("things")) { try { foreach (Thing thing in this.listerThings.AllThings) { try { if (thing.def.isSaveable && !thing.IsSaveCompressible()) { if (hashSet.Contains(thing.ThingID)) { Log.Error("Saving Thing with already-used ID " + thing.ThingID, false); } else { hashSet.Add(thing.ThingID); } Thing thing2 = thing; Scribe_Deep.Look <Thing>(ref thing2, "thing", new object[0]); } } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception saving ", thing, ": ", ex }), false); } } } finally { Scribe.ExitNode(); } } else { Log.Error("Could not enter the things node while saving.", false); } this.compressor = null; } else { if (Scribe.mode == LoadSaveMode.LoadingVars) { this.ConstructComponents(); this.regionAndRoomUpdater.Enabled = false; this.compressor = new MapFileCompressor(this); } this.ExposeComponents(); DeepProfiler.Start("Load compressed things"); this.compressor.ExposeData(); DeepProfiler.End(); DeepProfiler.Start("Load non-compressed things"); Scribe_Collections.Look <Thing>(ref this.loadedFullThings, "things", LookMode.Deep, new object[0]); DeepProfiler.End(); } }
public static void ErrorWhileGeneratingMap(Exception e) { DelayedErrorWindowRequest.Add("ErrorWhileGeneratingMap".Translate(), "ErrorWhileGeneratingMapTitle".Translate()); Scribe.ForceStop(); GenScene.GoToMainMenu(); }
public void ExposeData() { Scribe_Values.Look(ref uniqueID, "uniqueID", -1); Scribe_Values.Look(ref generationTick, "generationTick", 0); Scribe_Deep.Look(ref info, "mapInfo"); if (Scribe.mode == LoadSaveMode.Saving) { compressor = new MapFileCompressor(this); compressor.BuildCompressedString(); ExposeComponents(); compressor.ExposeData(); HashSet <string> hashSet = new HashSet <string>(); if (Scribe.EnterNode("things")) { try { foreach (Thing allThing in listerThings.AllThings) { try { if (allThing.def.isSaveable && !allThing.IsSaveCompressible()) { if (hashSet.Contains(allThing.ThingID)) { Log.Error("Saving Thing with already-used ID " + allThing.ThingID); } else { hashSet.Add(allThing.ThingID); } Thing target = allThing; Scribe_Deep.Look(ref target, "thing"); } } catch (OutOfMemoryException) { throw; } catch (Exception ex2) { Log.Error(string.Concat("Exception saving ", allThing, ": ", ex2)); } } } finally { Scribe.ExitNode(); } } else { Log.Error("Could not enter the things node while saving."); } compressor = null; } else { if (Scribe.mode == LoadSaveMode.LoadingVars) { ConstructComponents(); regionAndRoomUpdater.Enabled = false; compressor = new MapFileCompressor(this); } ExposeComponents(); DeepProfiler.Start("Load compressed things"); compressor.ExposeData(); DeepProfiler.End(); DeepProfiler.Start("Load non-compressed things"); Scribe_Collections.Look(ref loadedFullThings, "things", LookMode.Deep); DeepProfiler.End(); } }
public void LoadGame() { if (this.maps.Any <Map>()) { Log.Error("Called LoadGame() but there already is a map. There should be 0 maps...", false); return; } MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; this.ExposeSmallComponents(); LongEventHandler.SetCurrentEventText("LoadingWorld".Translate()); if (Scribe.EnterNode("world")) { try { this.World = new World(); this.World.ExposeData(); } finally { Scribe.ExitNode(); } this.World.FinalizeInit(); LongEventHandler.SetCurrentEventText("LoadingMap".Translate()); Scribe_Collections.Look <Map>(ref this.maps, "maps", LookMode.Deep, new object[0]); if (this.maps.RemoveAll((Map x) => x == null) != 0) { Log.Warning("Some maps were null after loading.", false); } int num = -1; Scribe_Values.Look <int>(ref num, "currentMapIndex", -1, false); if (num < 0 && this.maps.Any <Map>()) { Log.Error("Current map is null after loading but there are maps available. Setting current map to [0].", false); num = 0; } if (num >= this.maps.Count) { Log.Error("Current map index out of bounds after loading.", false); if (this.maps.Any <Map>()) { num = 0; } else { num = -1; } } this.currentMapIndex = -128; this.CurrentMap = ((num < 0) ? null : this.maps[num]); LongEventHandler.SetCurrentEventText("InitializingGame".Translate()); Find.CameraDriver.Expose(); DeepProfiler.Start("FinalizeLoading"); Scribe.loader.FinalizeLoading(); DeepProfiler.End(); LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate()); for (int i = 0; i < this.maps.Count; i++) { try { this.maps[i].FinalizeLoading(); } catch (Exception arg) { Log.Error("Error in Map.FinalizeLoading(): " + arg, false); } try { this.maps[i].Parent.FinalizeLoading(); } catch (Exception arg2) { Log.Error("Error in MapParent.FinalizeLoading(): " + arg2, false); } } this.FinalizeInit(); if (Prefs.PauseOnLoad) { LongEventHandler.ExecuteWhenFinished(delegate { Find.TickManager.DoSingleTick(); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; }); } GameComponentUtility.LoadedGame(); return; } Log.Error("Could not find world XML node.", false); }
public static void Look <K, V>(ref Dictionary <K, V> dict, string label, LookMode keyLookMode, LookMode valueLookMode, ref List <K> keysWorkingList, ref List <V> valuesWorkingList) where K : new() { if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving || Scribe.mode == LoadSaveMode.LoadingVars) { keysWorkingList = new List <K>(); valuesWorkingList = new List <V>(); } if (Scribe.mode == LoadSaveMode.Saving) { foreach (KeyValuePair <K, V> item in dict) { keysWorkingList.Add(item.Key); valuesWorkingList.Add(item.Value); } } Scribe_Collections.Look <K>(ref keysWorkingList, "keys", keyLookMode, new object[0]); Scribe_Collections.Look <V>(ref valuesWorkingList, "values", valueLookMode, new object[0]); if (Scribe.mode == LoadSaveMode.Saving) { if (keysWorkingList != null) { keysWorkingList.Clear(); keysWorkingList = null; } if (valuesWorkingList != null) { valuesWorkingList.Clear(); valuesWorkingList = null; } } bool flag = keyLookMode == LookMode.Reference || valueLookMode == LookMode.Reference; if (flag && Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { goto IL_0118; } if (!flag && Scribe.mode == LoadSaveMode.LoadingVars) { goto IL_0118; } goto IL_0279; IL_0118: dict.Clear(); if (keysWorkingList == null) { Log.Error("Cannot fill dictionary because there are no keys."); } else if (valuesWorkingList == null) { Log.Error("Cannot fill dictionary because there are no values."); } else { if (keysWorkingList.Count != valuesWorkingList.Count) { Log.Error("Keys count does not match the values count while loading a dictionary (maybe keys and values were resolved during different passes?). Some elements will be skipped. keys=" + keysWorkingList.Count + ", values=" + valuesWorkingList.Count); } int num = Math.Min(keysWorkingList.Count, valuesWorkingList.Count); for (int i = 0; i < num; i++) { if (keysWorkingList[i] == null) { Log.Error("Null key while loading dictionary of " + typeof(K) + " and " + typeof(V) + "."); } else { try { dict.Add(keysWorkingList[i], valuesWorkingList[i]); } catch (Exception ex) { Log.Error("Exception in LookDictionary(node=" + label + "): " + ex); } } } } goto IL_0279; IL_0279: if (Scribe.mode == LoadSaveMode.PostLoadInit) { if (keysWorkingList != null) { keysWorkingList.Clear(); keysWorkingList = null; } if (valuesWorkingList != null) { valuesWorkingList.Clear(); valuesWorkingList = null; } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { dict = null; } }
public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined) { if (ParseHelper.HandlesType(typeof(T))) { lookMode = LookMode.Value; } else if (typeof(T) == typeof(LocalTargetInfo)) { lookMode = LookMode.LocalTargetInfo; } else if (typeof(T) == typeof(TargetInfo)) { lookMode = LookMode.TargetInfo; } else if (typeof(T) == typeof(GlobalTargetInfo)) { lookMode = LookMode.GlobalTargetInfo; } else if (typeof(Def).IsAssignableFrom(typeof(T))) { lookMode = LookMode.Def; } else if (typeof(T) == typeof(BodyPartRecord)) { lookMode = LookMode.BodyPart; } else { if (!typeof(IExposable).IsAssignableFrom(typeof(T)) || typeof(ILoadReferenceable).IsAssignableFrom(typeof(T))) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly."); return; } lookMode = LookMode.Deep; } } if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T item8 in list) { switch (lookMode) { case LookMode.Value: { T value5 = item8; Scribe_Values.Look(ref value5, "li", default(T), forceSave: true); break; } case LookMode.LocalTargetInfo: { LocalTargetInfo value4 = (LocalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value4, saveDestroyedThings, "li"); break; } case LookMode.TargetInfo: { TargetInfo value3 = (TargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value3, saveDestroyedThings, "li"); break; } case LookMode.GlobalTargetInfo: { GlobalTargetInfo value2 = (GlobalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value2, saveDestroyedThings, "li"); break; } case LookMode.Def: { Def value = (Def)(object)item8; Scribe_Defs.Look(ref value, "li"); break; } case LookMode.BodyPart: { BodyPartRecord part = (BodyPartRecord)(object)item8; Scribe_BodyParts.Look(ref part, "li"); break; } case LookMode.Deep: { T target = item8; Scribe_Deep.Look(ref target, saveDestroyedThings, "li", ctorArgs); break; } case LookMode.Reference: { ILoadReferenceable refee = (ILoadReferenceable)(object)item8; Scribe_References.Look(ref refee, "li", saveDestroyedThings); break; } } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute == null || !(xmlAttribute.Value.ToLower() == "true")) { switch (lookMode) { case LookMode.Value: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator3 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator3.MoveNext()) { XmlNode subNode = (XmlNode)enumerator3.Current; T item = ScribeExtractor.ValueFromNode(subNode, default(T)); list.Add(item); } } finally { IDisposable disposable2; if ((disposable2 = (enumerator3 as IDisposable)) != null) { disposable2.Dispose(); } } break; } case LookMode.Deep: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator9 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator9.MoveNext()) { XmlNode subNode3 = (XmlNode)enumerator9.Current; T item7 = ScribeExtractor.SaveableFromNode <T>(subNode3, ctorArgs); list.Add(item7); } } finally { IDisposable disposable8; if ((disposable8 = (enumerator9 as IDisposable)) != null) { disposable8.Dispose(); } } break; } case LookMode.Def: { list = new List <T>(curXmlParent.ChildNodes.Count); IEnumerator enumerator8 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator8.MoveNext()) { XmlNode subNode2 = (XmlNode)enumerator8.Current; T item6 = ScribeExtractor.DefFromNodeUnsafe <T>(subNode2); list.Add(item6); } } finally { IDisposable disposable7; if ((disposable7 = (enumerator8 as IDisposable)) != null) { disposable7.Dispose(); } } break; } case LookMode.BodyPart: { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; IEnumerator enumerator7 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator7.MoveNext()) { XmlNode node4 = (XmlNode)enumerator7.Current; T item5 = (T)(object)ScribeExtractor.BodyPartFromNode(node4, num4.ToString(), null); list.Add(item5); num4++; } } finally { IDisposable disposable6; if ((disposable6 = (enumerator7 as IDisposable)) != null) { disposable6.Dispose(); } } break; } case LookMode.LocalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; IEnumerator enumerator6 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator6.MoveNext()) { XmlNode node3 = (XmlNode)enumerator6.Current; LocalTargetInfo localTargetInfo = ScribeExtractor.LocalTargetInfoFromNode(node3, num3.ToString(), LocalTargetInfo.Invalid); T item4 = (T)(object)localTargetInfo; list.Add(item4); num3++; } } finally { IDisposable disposable5; if ((disposable5 = (enumerator6 as IDisposable)) != null) { disposable5.Dispose(); } } break; } case LookMode.TargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; IEnumerator enumerator5 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator5.MoveNext()) { XmlNode node2 = (XmlNode)enumerator5.Current; TargetInfo targetInfo = ScribeExtractor.TargetInfoFromNode(node2, num2.ToString(), TargetInfo.Invalid); T item3 = (T)(object)targetInfo; list.Add(item3); num2++; } } finally { IDisposable disposable4; if ((disposable4 = (enumerator5 as IDisposable)) != null) { disposable4.Dispose(); } } break; } case LookMode.GlobalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; IEnumerator enumerator4 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator4.MoveNext()) { XmlNode node = (XmlNode)enumerator4.Current; GlobalTargetInfo globalTargetInfo = ScribeExtractor.GlobalTargetInfoFromNode(node, num.ToString(), GlobalTargetInfo.Invalid); T item2 = (T)(object)globalTargetInfo; list.Add(item2); num++; } } finally { IDisposable disposable3; if ((disposable3 = (enumerator4 as IDisposable)) != null) { disposable3.Dispose(); } } break; } case LookMode.Reference: { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); IEnumerator enumerator2 = curXmlParent.ChildNodes.GetEnumerator(); try { while (enumerator2.MoveNext()) { XmlNode xmlNode = (XmlNode)enumerator2.Current; list2.Add(xmlNode.InnerText); } } finally { IDisposable disposable; if ((disposable = (enumerator2 as IDisposable)) != null) { disposable.Dispose(); } } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, string.Empty); break; } } } else { list = null; } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { switch (lookMode) { case LookMode.Reference: list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(string.Empty); break; case LookMode.LocalTargetInfo: if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)(object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)(object)list[j], j.ToString()); } } break; case LookMode.TargetInfo: if (list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)(object)ScribeExtractor.ResolveTargetInfo((TargetInfo)(object)list[k], k.ToString()); } } break; case LookMode.GlobalTargetInfo: if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)(object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)(object)list[i], i.ToString()); } } break; } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public static void Look <T>(ref T target, bool saveDestroyedThings, string label, params object[] ctorArgs) { if (Scribe.mode == LoadSaveMode.Saving) { Thing thing = target as Thing; if (thing != null && thing.Destroyed) { if (!saveDestroyedThings) { Log.Warning(string.Concat(new object[] { "Deep-saving destroyed thing ", thing, " with saveDestroyedThings==false. label=", label }), false); } else if (thing.Discarded) { Log.Warning(string.Concat(new object[] { "Deep-saving discarded thing ", thing, ". This mode means that the thing is no longer managed by anything in the code and should not be deep-saved anywhere. (even with saveDestroyedThings==true) , label=", label }), false); } } IExposable exposable = target as IExposable; if (target != null && exposable == null) { Log.Error(string.Concat(new object[] { "Cannot use LookDeep to save non-IExposable non-null ", label, " of type ", typeof(T) }), false); return; } if (target == null) { if (Scribe.EnterNode(label)) { try { Scribe.saver.WriteAttribute("IsNull", "True"); } finally { Scribe.ExitNode(); } } } else if (Scribe.EnterNode(label)) { try { if (target.GetType() != typeof(T) || typeof(T).IsGenericTypeDefinition) { Scribe.saver.WriteAttribute("Class", GenTypes.GetTypeNameWithoutIgnoredNamespaces(target.GetType())); } exposable.ExposeData(); } catch (OutOfMemoryException) { throw; } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception while saving ", exposable.ToStringSafe <IExposable>(), ": ", ex }), false); } finally { Scribe.ExitNode(); } } Scribe.saver.loadIDsErrorsChecker.RegisterDeepSaved(target, label); } else if (Scribe.mode == LoadSaveMode.LoadingVars) { try { target = ScribeExtractor.SaveableFromNode <T>(Scribe.loader.curXmlParent[label], ctorArgs); } catch (Exception ex2) { Log.Error(string.Concat(new object[] { "Exception while loading ", Scribe.loader.curXmlParent[label].ToStringSafe <XmlElement>(), ": ", ex2 }), false); target = default(T); } } }
public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined && !Scribe_Universal.TryResolveLookMode(typeof(T), out lookMode)) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly."); } else if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T item8 in list) { switch (lookMode) { case LookMode.Value: { T value5 = item8; Scribe_Values.Look(ref value5, "li", default(T), forceSave: true); break; } case LookMode.LocalTargetInfo: { LocalTargetInfo value4 = (LocalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value4, saveDestroyedThings, "li"); break; } case LookMode.TargetInfo: { TargetInfo value3 = (TargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value3, saveDestroyedThings, "li"); break; } case LookMode.GlobalTargetInfo: { GlobalTargetInfo value2 = (GlobalTargetInfo)(object)item8; Scribe_TargetInfo.Look(ref value2, saveDestroyedThings, "li"); break; } case LookMode.Def: { Def value = (Def)(object)item8; Scribe_Defs.Look(ref value, "li"); break; } case LookMode.BodyPart: { BodyPartRecord part = (BodyPartRecord)(object)item8; Scribe_BodyParts.Look(ref part, "li"); break; } case LookMode.Deep: { T target = item8; Scribe_Deep.Look(ref target, saveDestroyedThings, "li", ctorArgs); break; } case LookMode.Reference: { ILoadReferenceable refee = (ILoadReferenceable)(object)item8; Scribe_References.Look(ref refee, "li", saveDestroyedThings); break; } } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, null); } list = null; } else { switch (lookMode) { case LookMode.Value: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode in curXmlParent.ChildNodes) { T item = ScribeExtractor.ValueFromNode(childNode, default(T)); list.Add(item); } break; case LookMode.Deep: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode2 in curXmlParent.ChildNodes) { T item7 = ScribeExtractor.SaveableFromNode <T>(childNode2, ctorArgs); list.Add(item7); } break; case LookMode.Def: list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode3 in curXmlParent.ChildNodes) { T item6 = ScribeExtractor.DefFromNodeUnsafe <T>(childNode3); list.Add(item6); } break; case LookMode.BodyPart: { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; foreach (XmlNode childNode4 in curXmlParent.ChildNodes) { T item5 = (T)(object)ScribeExtractor.BodyPartFromNode(childNode4, num4.ToString(), null); list.Add(item5); num4++; } break; } case LookMode.LocalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; foreach (XmlNode childNode5 in curXmlParent.ChildNodes) { T item4 = (T)(object)ScribeExtractor.LocalTargetInfoFromNode(childNode5, num3.ToString(), LocalTargetInfo.Invalid); list.Add(item4); num3++; } break; } case LookMode.TargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; foreach (XmlNode childNode6 in curXmlParent.ChildNodes) { T item3 = (T)(object)ScribeExtractor.TargetInfoFromNode(childNode6, num2.ToString(), TargetInfo.Invalid); list.Add(item3); num2++; } break; } case LookMode.GlobalTargetInfo: { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; foreach (XmlNode childNode7 in curXmlParent.ChildNodes) { T item2 = (T)(object)ScribeExtractor.GlobalTargetInfoFromNode(childNode7, num.ToString(), GlobalTargetInfo.Invalid); list.Add(item2); num++; } break; } case LookMode.Reference: { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); foreach (XmlNode childNode8 in curXmlParent.ChildNodes) { list2.Add(childNode8.InnerText); } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, ""); break; } } } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { switch (lookMode) { case LookMode.Reference: list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(""); break; case LookMode.LocalTargetInfo: if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)(object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)(object)list[j], j.ToString()); } } break; case LookMode.TargetInfo: if (list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)(object)ScribeExtractor.ResolveTargetInfo((TargetInfo)(object)list[k], k.ToString()); } } break; case LookMode.GlobalTargetInfo: if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)(object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)(object)list[i], i.ToString()); } } break; } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public static void Look <K, V>(ref Dictionary <K, V> dict, string label, LookMode keyLookMode, LookMode valueLookMode, ref List <K> keysWorkingList, ref List <V> valuesWorkingList) { if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving && dict == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlAttribute xmlAttribute = Scribe.loader.curXmlParent.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { dict = null; } else { dict = new Dictionary <K, V>(); } } if (Scribe.mode == LoadSaveMode.Saving || Scribe.mode == LoadSaveMode.LoadingVars) { keysWorkingList = new List <K>(); valuesWorkingList = new List <V>(); if (Scribe.mode == LoadSaveMode.Saving && dict != null) { foreach (KeyValuePair <K, V> current in dict) { keysWorkingList.Add(current.Key); valuesWorkingList.Add(current.Value); } } } Scribe_Collections.Look <K>(ref keysWorkingList, "keys", keyLookMode, new object[0]); Scribe_Collections.Look <V>(ref valuesWorkingList, "values", valueLookMode, new object[0]); if (Scribe.mode == LoadSaveMode.Saving) { if (keysWorkingList != null) { keysWorkingList.Clear(); keysWorkingList = null; } if (valuesWorkingList != null) { valuesWorkingList.Clear(); valuesWorkingList = null; } } bool flag = keyLookMode == LookMode.Reference || valueLookMode == LookMode.Reference; if (((flag && Scribe.mode == LoadSaveMode.ResolvingCrossRefs) || (!flag && Scribe.mode == LoadSaveMode.LoadingVars)) && dict != null) { if (keysWorkingList == null) { Log.Error("Cannot fill dictionary because there are no keys. label=" + label, false); } else if (valuesWorkingList == null) { Log.Error("Cannot fill dictionary because there are no values. label=" + label, false); } else { if (keysWorkingList.Count != valuesWorkingList.Count) { Log.Error(string.Concat(new object[] { "Keys count does not match the values count while loading a dictionary (maybe keys and values were resolved during different passes?). Some elements will be skipped. keys=", keysWorkingList.Count, ", values=", valuesWorkingList.Count, ", label=", label }), false); } int num = Math.Min(keysWorkingList.Count, valuesWorkingList.Count); for (int i = 0; i < num; i++) { if (keysWorkingList[i] == null) { Log.Error(string.Concat(new object[] { "Null key while loading dictionary of ", typeof(K), " and ", typeof(V), ". label=", label }), false); } else { try { dict.Add(keysWorkingList[i], valuesWorkingList[i]); } catch (OutOfMemoryException) { throw; } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception in LookDictionary(label=", label, "): ", ex }), false); } } } } } if (Scribe.mode == LoadSaveMode.PostLoadInit) { if (keysWorkingList != null) { keysWorkingList.Clear(); keysWorkingList = null; } if (valuesWorkingList != null) { valuesWorkingList.Clear(); valuesWorkingList = null; } } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { dict = null; } }
public static void Look <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs) { if (lookMode == LookMode.Undefined) { if (ParseHelper.HandlesType(typeof(T))) { lookMode = LookMode.Value; } else if (typeof(T) == typeof(LocalTargetInfo)) { lookMode = LookMode.LocalTargetInfo; } else if (typeof(T) == typeof(TargetInfo)) { lookMode = LookMode.TargetInfo; } else if (typeof(T) == typeof(GlobalTargetInfo)) { lookMode = LookMode.GlobalTargetInfo; } else if (typeof(Def).IsAssignableFrom(typeof(T))) { lookMode = LookMode.Def; } else if (typeof(T) == typeof(BodyPartRecord)) { lookMode = LookMode.BodyPart; } else { if (!typeof(IExposable).IsAssignableFrom(typeof(T)) || typeof(ILoadReferenceable).IsAssignableFrom(typeof(T))) { Log.Error("LookList call with a list of " + typeof(T) + " must have lookMode set explicitly.", false); return; } lookMode = LookMode.Deep; } } if (Scribe.EnterNode(label)) { try { if (Scribe.mode == LoadSaveMode.Saving) { if (list == null) { Scribe.saver.WriteAttribute("IsNull", "True"); } else { foreach (T current in list) { if (lookMode == LookMode.Value) { T t = current; Scribe_Values.Look <T>(ref t, "li", default(T), true); } else if (lookMode == LookMode.LocalTargetInfo) { LocalTargetInfo localTargetInfo = (LocalTargetInfo)((object)current); Scribe_TargetInfo.Look(ref localTargetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.TargetInfo) { TargetInfo targetInfo = (TargetInfo)((object)current); Scribe_TargetInfo.Look(ref targetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.GlobalTargetInfo) { GlobalTargetInfo globalTargetInfo = (GlobalTargetInfo)((object)current); Scribe_TargetInfo.Look(ref globalTargetInfo, saveDestroyedThings, "li"); } else if (lookMode == LookMode.Def) { Def def = (Def)((object)current); Scribe_Defs.Look <Def>(ref def, "li"); } else if (lookMode == LookMode.BodyPart) { BodyPartRecord bodyPartRecord = (BodyPartRecord)((object)current); Scribe_BodyParts.Look(ref bodyPartRecord, "li", null); } else if (lookMode == LookMode.Deep) { T t2 = current; Scribe_Deep.Look <T>(ref t2, saveDestroyedThings, "li", ctorArgs); } else if (lookMode == LookMode.Reference) { ILoadReferenceable loadReferenceable = (ILoadReferenceable)((object)current); Scribe_References.Look <ILoadReferenceable>(ref loadReferenceable, "li", saveDestroyedThings); } } } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { XmlNode curXmlParent = Scribe.loader.curXmlParent; XmlAttribute xmlAttribute = curXmlParent.Attributes["IsNull"]; if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true") { list = null; } else if (lookMode == LookMode.Value) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode in curXmlParent.ChildNodes) { T item = ScribeExtractor.ValueFromNode <T>(subNode, default(T)); list.Add(item); } } else if (lookMode == LookMode.Deep) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode2 in curXmlParent.ChildNodes) { T item2 = ScribeExtractor.SaveableFromNode <T>(subNode2, ctorArgs); list.Add(item2); } } else if (lookMode == LookMode.Def) { list = new List <T>(curXmlParent.ChildNodes.Count); foreach (XmlNode subNode3 in curXmlParent.ChildNodes) { T item3 = ScribeExtractor.DefFromNodeUnsafe <T>(subNode3); list.Add(item3); } } else if (lookMode == LookMode.BodyPart) { list = new List <T>(curXmlParent.ChildNodes.Count); int num = 0; foreach (XmlNode node in curXmlParent.ChildNodes) { T item4 = (T)((object)ScribeExtractor.BodyPartFromNode(node, num.ToString(), null)); list.Add(item4); num++; } } else if (lookMode == LookMode.LocalTargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num2 = 0; foreach (XmlNode node2 in curXmlParent.ChildNodes) { LocalTargetInfo localTargetInfo2 = ScribeExtractor.LocalTargetInfoFromNode(node2, num2.ToString(), LocalTargetInfo.Invalid); T item5 = (T)((object)localTargetInfo2); list.Add(item5); num2++; } } else if (lookMode == LookMode.TargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num3 = 0; foreach (XmlNode node3 in curXmlParent.ChildNodes) { TargetInfo targetInfo2 = ScribeExtractor.TargetInfoFromNode(node3, num3.ToString(), TargetInfo.Invalid); T item6 = (T)((object)targetInfo2); list.Add(item6); num3++; } } else if (lookMode == LookMode.GlobalTargetInfo) { list = new List <T>(curXmlParent.ChildNodes.Count); int num4 = 0; foreach (XmlNode node4 in curXmlParent.ChildNodes) { GlobalTargetInfo globalTargetInfo2 = ScribeExtractor.GlobalTargetInfoFromNode(node4, num4.ToString(), GlobalTargetInfo.Invalid); T item7 = (T)((object)globalTargetInfo2); list.Add(item7); num4++; } } else if (lookMode == LookMode.Reference) { List <string> list2 = new List <string>(curXmlParent.ChildNodes.Count); foreach (XmlNode xmlNode in curXmlParent.ChildNodes) { list2.Add(xmlNode.InnerText); } Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(list2, string.Empty); } } else if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { if (lookMode == LookMode.Reference) { list = Scribe.loader.crossRefs.TakeResolvedRefList <T>(string.Empty); } else if (lookMode == LookMode.LocalTargetInfo) { if (list != null) { for (int i = 0; i < list.Count; i++) { list[i] = (T)((object)ScribeExtractor.ResolveLocalTargetInfo((LocalTargetInfo)((object)list[i]), i.ToString())); } } } else if (lookMode == LookMode.TargetInfo) { if (list != null) { for (int j = 0; j < list.Count; j++) { list[j] = (T)((object)ScribeExtractor.ResolveTargetInfo((TargetInfo)((object)list[j]), j.ToString())); } } } else if (lookMode == LookMode.GlobalTargetInfo && list != null) { for (int k = 0; k < list.Count; k++) { list[k] = (T)((object)ScribeExtractor.ResolveGlobalTargetInfo((GlobalTargetInfo)((object)list[k]), k.ToString())); } } } } finally { Scribe.ExitNode(); } } else if (Scribe.mode == LoadSaveMode.LoadingVars) { if (lookMode == LookMode.Reference) { Scribe.loader.crossRefs.loadIDs.RegisterLoadIDListReadFromXml(null, label); } list = null; } }
public void LoadGame() { if (maps.Any()) { Log.Error("Called LoadGame() but there already is a map. There should be 0 maps..."); } else { MemoryUtility.UnloadUnusedUnityAssets(); Current.ProgramState = ProgramState.MapInitializing; ExposeSmallComponents(); LongEventHandler.SetCurrentEventText("LoadingWorld".Translate()); if (!Scribe.EnterNode("world")) { Log.Error("Could not find world XML node."); } else { try { World = new World(); World.ExposeData(); } finally { Scribe.ExitNode(); } World.FinalizeInit(); LongEventHandler.SetCurrentEventText("LoadingMap".Translate()); Scribe_Collections.Look(ref maps, "maps", LookMode.Deep); if (maps.RemoveAll((Map x) => x == null) != 0) { Log.Warning("Some maps were null after loading."); } int value = -1; Scribe_Values.Look(ref value, "currentMapIndex", -1); if (value < 0 && maps.Any()) { Log.Error("Current map is null after loading but there are maps available. Setting current map to [0]."); value = 0; } if (value >= maps.Count) { Log.Error("Current map index out of bounds after loading."); value = ((!maps.Any()) ? (-1) : 0); } currentMapIndex = sbyte.MinValue; CurrentMap = ((value < 0) ? null : maps[value]); LongEventHandler.SetCurrentEventText("InitializingGame".Translate()); Find.CameraDriver.Expose(); DeepProfiler.Start("FinalizeLoading"); Scribe.loader.FinalizeLoading(); DeepProfiler.End(); LongEventHandler.SetCurrentEventText("SpawningAllThings".Translate()); for (int i = 0; i < maps.Count; i++) { try { maps[i].FinalizeLoading(); } catch (Exception arg) { Log.Error("Error in Map.FinalizeLoading(): " + arg); } try { maps[i].Parent.FinalizeLoading(); } catch (Exception arg2) { Log.Error("Error in MapParent.FinalizeLoading(): " + arg2); } } FinalizeInit(); if (Prefs.PauseOnLoad) { LongEventHandler.ExecuteWhenFinished(delegate { Find.TickManager.DoSingleTick(); Find.TickManager.CurTimeSpeed = TimeSpeed.Paused; }); } GameComponentUtility.LoadedGame(); } } }