Ejemplo n.º 1
0
        public Scene(Reader reader)
        {
            Title = reader.ReadRSDKString();
            //Console.WriteLine(Title);
            byte[] buffer = new byte[5];

            ActiveLayer0 = reader.ReadByte();
            ActiveLayer1 = reader.ReadByte();
            ActiveLayer2 = reader.ReadByte();
            ActiveLayer3 = reader.ReadByte();
            Midpoint     = reader.ReadByte();

            reader.Read(buffer, 0, 2); //Read size

            width = 0; height = 0;


            // Map width in 128 pixel units
            // In RSDKv2, it's one byte long
            width  = buffer[0];
            height = buffer[1];

            MapLayout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                MapLayout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2 and RSDKv3
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                }
            }


            // Read number of object types, Only RSDKv1 and RSDKv2 support this feature
            int ObjTypeCount = reader.ReadByte();

            for (int n = 0; n < ObjTypeCount; n++)
            {
                string name = reader.ReadRSDKString();

                objectTypeNames.Add(name);
            }
            // Read object data

            int ObjCount = 0;

            // 2 bytes, big-endian, unsigned
            ObjCount  = reader.ReadByte() << 8;
            ObjCount |= reader.ReadByte();

            Object.cur_id = 0;

            for (int n = 0; n < ObjCount; n++)
            {
                // Add object
                objects.Add(new Object(reader));
            }
            reader.Close();
        }
Ejemplo n.º 2
0
            public void read(Reader reader, ushort width, ushort height)
            {
                int frameSize = reader.ReadInt32();

                byte[] gifData = new byte[frameSize + 13];

                // Write Header
                gifData[0] = (byte)'G';
                gifData[1] = (byte)'I';
                gifData[2] = (byte)'F';
                gifData[3] = (byte)'8';
                gifData[4] = (byte)'9';
                gifData[5] = (byte)'a';

                byte[] bytes = BitConverter.GetBytes(width);
                gifData[6] = bytes[0];
                gifData[7] = bytes[1];

                bytes      = BitConverter.GetBytes(height);
                gifData[8] = bytes[0];
                gifData[9] = bytes[1];

                // 1 == hasColours, 6 == paletteSize of 128, 7 == 8bpp
                gifData[10] = (1 << 7) | (6 << 4) | 6;
                gifData[11] = 0;
                gifData[12] = 0;

                // Read Data
                reader.Read(gifData, 13, (int)frameSize);

                List <Color> globalPalette = new List <Color>();
                List <Color> localPalette  = new List <Color>();

                using (var gifStream = new System.IO.MemoryStream(gifData))
                {
                    using (var gifReader = new Reader(gifStream))
                    {
                        reader.BaseStream.Position = 13;
                        for (int i = 0; i < 0x80; ++i)
                        {
                            byte r = reader.ReadByte();
                            byte g = reader.ReadByte();
                            byte b = reader.ReadByte();
                            globalPalette.Add(Color.FromArgb(r, g, b));
                        }

                        byte buffer = reader.ReadByte();
                        while (buffer != (byte)',')
                        {
                            buffer = reader.ReadByte();
                        }
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        byte info = reader.ReadByte();
                        if (info >> 7 == 1)
                        {
                            for (int i = 0; i < 0x80; ++i)
                            {
                                byte r = reader.ReadByte();
                                byte g = reader.ReadByte();
                                byte b = reader.ReadByte();
                                localPalette.Add(Color.FromArgb(r, g, b));
                            }
                        }
                    }
                }

                using (var gifStream = new System.IO.MemoryStream(gifData))
                    image = Image.FromStream(gifStream);

                // ColorPalette pal = new ColorPalette();
                // pal.Entries[0]]

                // image.Palette = pal;

                videoFilePos += frameSize;
                reader.BaseStream.Position = videoFilePos;
            }
            public BGLayer(Reader reader)
            {
                width          = reader.ReadByte();
                height         = reader.ReadByte();
                Behaviour      = reader.ReadByte();
                RelativeSpeed  = (short)(reader.ReadByte() << 8);
                RelativeSpeed |= (short)reader.ReadByte();
                ConstantSpeed  = reader.ReadByte();

                byte[] buf      = new byte[3];
                bool   finished = false;
                int    cnt      = 0;
                int    loop     = 0;

                LineIndexes = new byte[height * 128];

                while (!finished)
                {
                    buf[0] = reader.ReadByte();
                    if (buf[0] == 0xFF)
                    {
                        buf[1] = reader.ReadByte();
                        if (buf[1] == 0xFF)
                        {
                            finished = true;
                            break;
                        }
                        else
                        {
                            buf[2] = (byte)(reader.ReadByte() - 1);
                            loop   = 0;

                            while (loop < buf[2] && !reader.IsEof)
                            {
                                LineIndexes[cnt++] = buf[1];
                                loop++;
                            }
                        }
                    }
                    else
                    {
                        LineIndexes[cnt++] = buf[0];
                    }
                }

                byte[] buffer = new byte[2];

                MapLayout = new ushort[height][];
                for (int m = 0; m < height; m++)
                {
                    MapLayout[m] = new ushort[width];
                }
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        reader.Read(buffer, 0, 2); //Read size
                        MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                    }
                }
            }
Ejemplo n.º 4
0
        public Level(Reader reader)
        {
            Title = reader.ReadRSDKString();
            Console.WriteLine(Title);
            byte[] buffer = new byte[5];
            reader.Read(displayBytes, 0, 5); //Waste 5 bytes, I don't care about them right now.
            //The first 4 bytes are loaded into StageSystem.ActiveTileLayers. 5th byte is tLayerMidPoint.
            //If you want to know the values then look at the values for "DisplayBytes"
            reader.Read(buffer, 0, 2); //Read size

            width = 0; height = 0;


            // Map width in 128 pixel units
            // In RSDKv2, it's one byte long
            width  = buffer[0];
            height = buffer[1];

            MapLayout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                MapLayout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2 and RSDKv3
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                }
            }


            // Read number of object types, Only RSDKv2 and RSDKv3 support this feature
            int ObjTypeCount = reader.ReadByte();

            for (int n = 0; n < ObjTypeCount; n++)
            {
                string name = reader.ReadRSDKString();

                objectTypeNames.Add(name);
                Console.WriteLine(name);
            }
            // Read object data

            int ObjCount = 0;

            // 2 bytes, big-endian, unsigned
            ObjCount  = reader.ReadByte() << 8;
            ObjCount |= reader.ReadByte();

            int obj_type    = 0;
            int obj_subtype = 0;
            int obj_xPos    = 0;
            int obj_yPos    = 0;

            for (int n = 0; n < ObjCount; n++)
            {
                // Object type, 1 byte, unsigned
                obj_type = reader.ReadByte();
                // Object subtype, 1 byte, unsigned
                obj_subtype = reader.ReadByte();

                // X Position, 2 bytes, big-endian, signed
                obj_xPos  = reader.ReadSByte() << 8;
                obj_xPos |= reader.ReadByte();

                // Y Position, 2 bytes, big-endian, signed
                obj_yPos  = reader.ReadSByte() << 8;
                obj_yPos |= reader.ReadByte();

                // Add object
                objects.Add(new Object(obj_type, obj_subtype, obj_xPos, obj_yPos));
            }
            reader.Close();
        }