コード例 #1
0
        private static void WriteSpriteSetHeader(BinaryWriter writer, SpriteSetHeader header, int spritesCount)
        {
            writer.Write((UInt16)header.Version);
            writer.Write((char[])SpriteSetSignature.ToCharArray());

            if (header.Version >= 6)
            {
                writer.Write((byte)header.Compression);
                writer.Write((UInt32)header.FileID);
            }

            if (header.Version < 5)
            {
                AGSGraphics.WritePalette(writer, header.Palette);
            }

            if (header.Version < 11)
            {
                writer.Write((UInt16)spritesCount);
            }
            else
            {
                writer.Write((Int32)spritesCount);
            }
        }
コード例 #2
0
        public static SpriteSetHeader ReadFromFile(string filepath)
        {
            SpriteSetHeader header = new SpriteSetHeader();

            using (FileStream stream = new FileStream(filepath, FileMode.Open))
            {
                using (BinaryReader reader = new BinaryReader(stream, Encoding.Latin1))
                {
                    header.Version = reader.ReadInt16();

                    header.Compression = CompressionType.Unknown;
                    byte compressionType = reader.ReadByte();
                    if (Enum.IsDefined(typeof(CompressionType), (int)compressionType))
                    {
                        header.Compression = (CompressionType)compressionType;
                    }

                    header.FileID       = reader.ReadUInt32();
                    header.SpritesCount = reader.ReadUInt16();

                    if (header.Version < 5)
                    {
                        header.Palette = AGSGraphics.ReadPalette(reader);
                    }
                }
            }

            return(header);
        }
コード例 #3
0
        public void WriteMetaFile(string folderpath)
        {
            string filepath = Path.Combine(folderpath, FileName);

            using (FileStream stream = new FileStream(filepath, FileMode.Create))
            {
                using (BinaryWriter writer = new BinaryWriter(stream, Encoding.Latin1))
                {
                    writer.Write((UInt16)Version);
                    writer.Write((byte)Compression);
                    writer.Write((UInt32)FileID);
                    writer.Write((UInt16)SpritesCount);

                    if (Version < 5)
                    {
                        AGSGraphics.WritePalette(writer, Palette);
                    }
                }
            }
        }
コード例 #4
0
        private static SpriteSetHeader ReadSpriteSetHeader(BinaryReader reader)
        {
            int version = reader.ReadInt16();
            // FIXME(adm244): should probably use ReadFixedString instead; there are many cases like this
            string signature = reader.ReadFixedCString(SpriteSetSignature.Length);

            //Debug.Assert(signature == SpriteSetSignature);

            if (signature != SpriteSetSignature)
            {
                throw new InvalidDataException("Sprite set file signature mismatch!");
            }

            if (version < 4 || version > 11)
            {
                throw new NotSupportedException(
                          $"Sprite set version is not supported.\n\nGot: {version}\nMin supported: {4}\nMax supported: {11}");
            }

            CompressionType compression = SpriteSetHeader.DefaultCompression;
            UInt32          fileID      = SpriteSetHeader.DefaultFileID;

            if (version == 4)
            {
                compression = CompressionType.Uncompressed;
            }
            else if (version == 5)
            {
                compression = CompressionType.RLE;
            }
            else if (version >= 6)
            {
                compression = CompressionType.Unknown;
                byte compressionType = reader.ReadByte();
                if (Enum.IsDefined(typeof(CompressionType), (int)compressionType))
                {
                    compression = (CompressionType)compressionType;
                }

                fileID = reader.ReadUInt32();
            }

            // TODO(adm244): for correct results we should get palette from a DTA file instead
            Palette palette = SpriteSetHeader.DefaultPalette;

            if (version < 5)
            {
                palette = AGSGraphics.ReadPalette(reader);
                // NOTE(adm244): first 17 colors are locked and cannot be changed in pre 6
                // but for some reason palette in sprite set file differs from game data (2.72)
                // Here we try to restore what we can, but it's not enought to be fully correct
                // AGS. When everything's a stress.
                for (int i = 0; i < 17; ++i)
                {
                    palette.Entries[i] = SpriteSetHeader.DefaultPalette[i];
                }
            }

            int spritesCount;

            if (version < 11)
            {
                spritesCount = reader.ReadUInt16();
            }
            else
            {
                spritesCount = reader.ReadInt32();
            }

            return(new SpriteSetHeader(version, compression, fileID, spritesCount, palette));
        }