示例#1
0
 public void Read(MemoryStreamReader br, int size)
 {
     GID     = br.ReadInt();
     Mapname = br.ReadBinaryString(16);
     IP      = new IPAddress(br.ReadBytes(4));
     Port    = br.ReadShort();
     br.Seek(128, System.IO.SeekOrigin.Current);
 }
示例#2
0
        public static SPR Load(MemoryStreamReader data)
        {
            var header = data.ReadBinaryString(2);

            if (!header.Equals(SPR.Header))
            {
                throw new Exception("SpriteLoader.Load: Header (" + header + ") is not \"SP\"");
            }

            SPR spr = new SPR();

            string subversion = Convert.ToString(data.ReadByte());
            string version    = Convert.ToString(data.ReadByte());

            version += "." + subversion;

            spr.version       = version;
            spr.indexedCount  = data.ReadUShort();
            spr._indexedCount = spr.indexedCount;

            var dversion = double.Parse(version, CultureInfo.InvariantCulture);

            if (dversion > 1.1)
            {
                spr.rgbaCount = data.ReadUShort();
            }

            spr.frames    = new SPR.Frame[spr.indexedCount + spr.rgbaCount];
            spr.rgbaIndex = spr.indexedCount;

            if (dversion < 2.1)
            {
                ReadIndexedImage(spr, data);
            }
            else
            {
                ReadIndexedImageRLE(spr, data);
            }

            ReadRgbaImage(spr, data);

            if (dversion > 1.0)
            {
                long position = data.Position;
                data.Seek(-1024, System.IO.SeekOrigin.End);
                spr.palette = data.ReadBytes(1024);
                data.Seek(position, System.IO.SeekOrigin.Begin);
            }

            return(spr);
        }
示例#3
0
 private static void ReadIndexedImage(SPR spr, MemoryStreamReader data)
 {
     for (int i = 0; i < spr.indexedCount; i++)
     {
         var width  = data.ReadUShort();
         var height = data.ReadUShort();
         spr.frames[i] = new SPR.Frame()
         {
             type   = SPR.TYPE_PAL,
             width  = width,
             height = height,
             data   = data.ReadBytes(width * height)
         };
     }
 }
示例#4
0
        private static void ReadRgbaImage(SPR spr, MemoryStreamReader data)
        {
            for (int i = 0; i < spr.rgbaCount; i++)
            {
                var width  = data.ReadShort();
                var height = data.ReadShort();

                spr.frames[i + spr.rgbaIndex] = new SPR.Frame()
                {
                    type   = SPR.TYPE_RGBA,
                    width  = width,
                    height = height,
                    data   = data.ReadBytes(width * height * 4)
                };
            }
        }