コード例 #1
0
        static SaveGameHeader LoadSaveGameHeader(BinaryReader reader)
        {
            var hdr = new SaveGameHeader();
            hdr.Type = ScummHelper.SwapBytes(reader.ReadUInt32());
            if (hdr.Type != ScummHelper.MakeTag('S', 'C', 'V', 'M'))
                throw new NotSupportedException("Invalid savegame");
            hdr.Size = reader.ReadUInt32();
            hdr.Version = reader.ReadUInt32();
            // In older versions of ScummVM, the header version was not endian safe.
            // We account for that by retrying once with swapped byte order in case
            // we see a version that is higher than anything we'd expect...
            if (hdr.Version > 0xFFFFFF)
                hdr.Version = ScummHelper.SwapBytes(hdr.Version);

            // Reject save games which are too old or too new. Note that
            // We do not really support V7 games, but still accept them here
            // to work around a bug from the stone age (see below for more
            // information).
            if (hdr.Version < 7 || hdr.Version > CurrentVersion)
            {
                throw new NotSupportedException("Invalid version");
            }

			hdr.Name = reader.ReadBytes(32).GetText();

            // Since version 52 a thumbnail is saved directly after the header.
            if (hdr.Version >= 52)
            {
                // Prior to version 75 we always required an thumbnail to be present
                if (hdr.Version <= 74)
                {
                    if (!CheckThumbnailHeader(reader))
                    {
                        throw new NotSupportedException("Cannot load thumbnail");
                    }
                }
                SkipThumbnail(reader);
            }

            return hdr;
        }
コード例 #2
0
        static void SaveHeader(string name, BinaryWriter bw)
        {
            var hdr = new SaveGameHeader();
            hdr.Type = ScummHelper.MakeTag('S', 'C', 'V', 'M');
            hdr.Size = 0;
            hdr.Version = SaveCurrentVersion;

            bw.WriteUInt32BigEndian(hdr.Type);
            bw.Write(hdr.Size);
            bw.Write(hdr.Version);

            var data = Encoding.UTF8.GetBytes(name);
            var data2 = new byte[32];
            int length = Math.Min(data.Length, 31);
            Array.Copy(data, data2, Math.Min(data.Length, 31));
            data2[length] = 0;
            bw.Write(data2);
        }