Exemplo n.º 1
0
        /// <summary>
        /// Pre-condition: stream's file position must be at the beginning of a new section, marked with 4/8 byte ascii strings
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static SaveSection ParseSaveSection(FileStream stream, SimCity2000Save save)
        {
            byte[] name = new byte[4];

            stream.Read(name, 0, 4);
            string sectionName = BytesToString(name);

            SaveSection newSection = null;

            switch (sectionName)
            {
                case "MISC":
                    newSection = new MiscSection();
                    break;
                case "ALTM":
                    newSection = new AltitudeSection();
                    break;
                case "XTER":
                    newSection = new TerrainSection();
                    break;
                case "XBLD":
                    newSection = new BuildingSection();
                    break;
                case "XZON":
                    newSection = new ZoneSection();
                    ((ZoneSection)newSection).MiscSection = save.MiscSection;
                    break;
                default:
                    newSection = new SaveSection(sectionName);
                    break;
            }

            newSection.ParseSection(stream);
            return newSection;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Base implementation of diffing that just works on the raw data.
        /// Eventually, each specializing class should understand the data and diff
        /// actual fields
        /// </summary>
        /// <param name="oldSection"></param>
        /// <returns></returns>
        public virtual List<SectionDifference> Diff(SaveSection oldSection)
        {
            List<SectionDifference> diffs = new List<SectionDifference>();

            if (RawData.Length != oldSection.RawData.Length)
            {
                diffs.Add(new SectionDifference("Length", oldSection.Length.ToString("x8"), Length.ToString("x8")));
            }

            for (int i = 0; i < RawData.Length; i++)
            {
                // Handle this data section being larger
                if (i >= oldSection.RawData.Length)
                {
                    diffs.Add(new SectionDifference((i + RawDataFileOffset).ToString("x8"), "", RawData[i].ToString("x2")));
                }
                else if (RawData[i] != oldSection.RawData[i])
                {
                    diffs.Add(new SectionDifference((i + RawDataFileOffset).ToString("x8"), oldSection.RawData[i].ToString("x2"), RawData[i].ToString("x2")));
                }
            }

            // Handle oldSection's data section being larger
            if (oldSection.RawData.Length > RawData.Length)
            {
                for (int i = oldSection.RawData.Length; i < oldSection.RawData.Length; i++)
                {
                    diffs.Add(new SectionDifference((i + oldSection.RawDataFileOffset).ToString("x2"), oldSection.RawData[i].ToString("x2"), ""));
                }
            }

            return diffs;
        }
Exemplo n.º 3
0
        public override List<SectionDifference> Diff(SaveSection oldSection)
        {
            var oldMiscSection = oldSection as MiscSection;

            List<SectionDifference> diffs = new List<SectionDifference>();
            for (int i = 0; i < Data.Count; i++)
            {
                if (Data[i] != oldMiscSection.Data[i])
                {
                    diffs.Add(new SectionDifference(i.ToString(), oldMiscSection.Data[i].ToString(), Data[i].ToString()));
                }
            }

            return diffs;
        }
Exemplo n.º 4
0
        public override List<SectionDifference> Diff(SaveSection oldSection)
        {
            AltitudeSection oldAltitudeSection = oldSection as AltitudeSection;
            List<SectionDifference> sds = new List<SectionDifference>();

            for (int i = 0; i < 128; i++)
            {
                for (int j = 0; j < 128; j++)
                {
                    if (!oldAltitudeSection.AltitudeData[i, j].Equals(AltitudeData[i, j]))
                    {
                        SectionDifference sd = new SectionDifference(j.ToString() + ", " + i.ToString(), oldAltitudeSection.AltitudeData[i, j].Altitude.ToString() + ", Water: " + oldAltitudeSection.AltitudeData[i, j].WaterCovered.ToString(), AltitudeData[i, j].Altitude.ToString() + ", Water: " + AltitudeData[i, j].WaterCovered.ToString());
                        sds.Add(sd);
                    }
                }
            }
            return sds;
        }