public void DoExposeWork()
 {
     byte[] arr = null;
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         int      num      = Mathf.RoundToInt(this.map.mapTemperature.OutdoorTemp);
         ushort   num2     = this.TempFloatToShort((float)num);
         ushort[] tempGrid = new ushort[this.map.cellIndices.NumGridCells];
         for (int i = 0; i < this.map.cellIndices.NumGridCells; i++)
         {
             tempGrid[i] = num2;
         }
         foreach (Region current in this.map.regionGrid.AllRegions_NoRebuild_InvalidAllowed)
         {
             if (current.Room != null)
             {
                 ushort num3 = this.TempFloatToShort(current.Room.Temperature);
                 foreach (IntVec3 current2 in current.Cells)
                 {
                     tempGrid[this.map.cellIndices.CellToIndex(current2)] = num3;
                 }
             }
         }
         arr = MapSerializeUtility.SerializeUshort(this.map, (IntVec3 c) => tempGrid[this.map.cellIndices.CellToIndex(c)]);
     }
     DataExposeUtility.ByteArray(ref arr, "temperatures");
     if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         this.tempGrid = new ushort[this.map.cellIndices.NumGridCells];
         MapSerializeUtility.LoadUshort(arr, this.map, delegate(IntVec3 c, ushort val)
         {
             this.tempGrid[this.map.cellIndices.CellToIndex(c)] = val;
         });
     }
 }
Exemple #2
0
 public static void ExposeUshort(Map map, Func <IntVec3, ushort> shortReader, Action <IntVec3, ushort> shortWriter, string label)
 {
     byte[] arr = null;
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         arr = MapSerializeUtility.SerializeUshort(map, shortReader);
     }
     DataExposeUtility.ByteArray(ref arr, label);
     if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         MapSerializeUtility.LoadUshort(arr, map, shortWriter);
     }
 }
        public IEnumerable <Thing> ThingsToSpawnAfterLoad()
        {
            Dictionary <ushort, ThingDef> thingDefsByShortHash = new Dictionary <ushort, ThingDef>();

            foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs)
            {
                if (thingDefsByShortHash.ContainsKey(current.shortHash))
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Hash collision between ",
                        current,
                        " and  ",
                        thingDefsByShortHash[current.shortHash],
                        ": both have short hash ",
                        current.shortHash
                    }));
                }
                else
                {
                    thingDefsByShortHash.Add(current.shortHash, current);
                }
            }
            List <Thing> loadables = new List <Thing>();

            MapSerializeUtility.LoadUshort(this.compressedData, this.map, delegate(IntVec3 c, ushort val)
            {
                if (val == 0)
                {
                    return;
                }
                ThingDef def = null;
                try
                {
                    def = thingDefsByShortHash[val];
                }
                catch (KeyNotFoundException)
                {
                    Log.Error("Map compressor decompression error: No thingDef with short hash " + val + ". Adding as null to dictionary.");
                    thingDefsByShortHash.Add(val, null);
                }
                Thing thing = ThingMaker.MakeThing(def, null);
                thing.SetPositionDirect(c);
                loadables.Add(thing);
            });
            return(loadables);
        }
        public IEnumerable <Thing> ThingsToSpawnAfterLoad()
        {
            Dictionary <ushort, ThingDef> thingDefsByShortHash = new Dictionary <ushort, ThingDef>();

            foreach (ThingDef current in DefDatabase <ThingDef> .AllDefs)
            {
                if (thingDefsByShortHash.ContainsKey(current.shortHash))
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Hash collision between ",
                        current,
                        " and  ",
                        thingDefsByShortHash[current.shortHash],
                        ": both have short hash ",
                        current.shortHash
                    }), false);
                }
                else
                {
                    thingDefsByShortHash.Add(current.shortHash, current);
                }
            }
            int          major     = VersionControl.MajorFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
            int          minor     = VersionControl.MinorFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
            List <Thing> loadables = new List <Thing>();

            MapSerializeUtility.LoadUshort(this.compressedData, this.map, delegate(IntVec3 c, ushort val)
            {
                if (val == 0)
                {
                    return;
                }
                ThingDef thingDef = BackCompatibility.BackCompatibleThingDefWithShortHash_Force(val, major, minor);
                if (thingDef == null)
                {
                    try
                    {
                        thingDef = thingDefsByShortHash[val];
                    }
                    catch (KeyNotFoundException)
                    {
                        ThingDef thingDef2 = BackCompatibility.BackCompatibleThingDefWithShortHash(val);
                        if (thingDef2 != null)
                        {
                            thingDef = thingDef2;
                            thingDefsByShortHash.Add(val, thingDef2);
                        }
                        else
                        {
                            Log.Error("Map compressor decompression error: No thingDef with short hash " + val + ". Adding as null to dictionary.", false);
                            thingDefsByShortHash.Add(val, null);
                        }
                    }
                }
                if (thingDef != null)
                {
                    try
                    {
                        Thing thing = ThingMaker.MakeThing(thingDef, null);
                        thing.SetPositionDirect(c);
                        loadables.Add(thing);
                    }
                    catch (Exception arg)
                    {
                        Log.Error("Could not instantiate compressed thing: " + arg, false);
                    }
                }
            });
            return(loadables);
        }
 public void BuildCompressedString()
 {
     this.compressibilityDecider = new CompressibilityDecider(this.map);
     this.compressibilityDecider.DetermineReferences();
     this.compressedData = MapSerializeUtility.SerializeUshort(this.map, new Func <IntVec3, ushort>(this.HashValueForSquare));
 }
 public void BuildCompressedString()
 {
     compressibilityDecider = new CompressibilityDecider(map);
     compressibilityDecider.DetermineReferences();
     compressedData = MapSerializeUtility.SerializeUshort(map, HashValueForSquare);
 }