public static GameDataSnapshot CreateGameDataSnapshot(TempGameData data) { XmlNode gameNode = data.SaveData.DocumentElement["game"]; XmlNode mapsNode = gameNode["maps"]; var dataSnapshot = new GameDataSnapshot(); foreach (XmlNode mapNode in mapsNode) { int id = int.Parse(mapNode["uniqueID"].InnerText); byte[] mapData = ScribeUtil.XmlToByteArray(mapNode); dataSnapshot.mapData[id] = mapData; dataSnapshot.mapCmds[id] = new List <ScheduledCommand>(Find.Maps.First(m => m.uniqueID == id).AsyncTime().cmds); } gameNode["currentMapIndex"].RemoveFromParent(); mapsNode.RemoveAll(); byte[] gameData = ScribeUtil.XmlToByteArray(data.SaveData); dataSnapshot.cachedAtTime = TickPatch.Timer; dataSnapshot.gameData = gameData; dataSnapshot.semiPersistentData = data.SemiPersistent; dataSnapshot.mapCmds[ScheduledCommand.Global] = new List <ScheduledCommand>(Multiplayer.WorldComp.cmds); return(dataSnapshot); }
public static XmlDocument SaveGameToDoc() { SaveCompression.doSaveCompression = true; try { 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(); } finally { SaveCompression.doSaveCompression = false; } return(ScribeUtil.FinishWritingToDoc()); }