Example #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();

            width = 0; height = 0;

            // Map width in 128 pixel units
            // In RSDKvB it's two bytes long, little-endian

            reader.Read(buffer, 0, 2); //Read Map Width
            width = (ushort)(buffer[0] + (buffer[1] << 8));

            reader.Read(buffer, 0, 2); //Read Height
            height = (ushort)(buffer[0] + (buffer[1] << 8));

            Console.WriteLine("Width " + width + " Height " + height);

            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
                    //Little-Endian in RSDKv4
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8));
                }
            }

            // Read object data
            int ObjCount = 0;

            // 4 bytes, little-endian, unsigned
            byte t1 = reader.ReadByte();
            byte t2 = reader.ReadByte();

            ObjCount = (t2 << 8) + t1;

            Console.WriteLine("Object Count = " + ObjCount);

            Object.cur_id = 0;

            int n = 0;

            try
            {
                for (n = 0; n < ObjCount; n++)
                {
                    // Add object
                    objects.Add(new Object(reader));
                }
                //Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position));
            }
            catch (Exception ex)
            {
                if (reader.IsEof)
                {
                    Console.WriteLine("F**k, not the end! Objects Left: " + (ObjCount - n));
                    Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position));
                    reader.Close();
                    return;
                }
            }

            Console.WriteLine("Current Reader Position = " + reader.BaseStream.Position + " Current File Length = " + reader.BaseStream.Length + " Data Left = " + (reader.BaseStream.Length - reader.BaseStream.Position));
            reader.Close();
        }
Example #2
0
            public BGLayer(Reader reader)
            {
                byte[] buffer = new byte[2];

                reader.Read(buffer, 0, 2); //Read width
                width = (ushort)(buffer[0] + (buffer[1] << 8));

                reader.Read(buffer, 0, 2); //Read height
                height = (ushort)(buffer[0] + (buffer[1] << 8));

                reader.Read(buffer, 0, 2); //Read height
                RelativeSpeed = (short)(buffer[0] + (buffer[1] << 8));
                ConstantSpeed = reader.ReadByte();
                Behaviour     = 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] == 255)
                    {
                        buf[1] = reader.ReadByte();
                        if (buf[1] == 255)
                        {
                            finished = true;
                            break;
                        }
                        else
                        {
                            buf[2] = (byte)(reader.ReadByte() - 1);
                            loop   = 0;

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

                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++)
                    {
                        //128x128 Block number is 16-bit
                        //Little-Endian in RSDKvB
                        reader.Read(buffer, 0, 2); //Read size
                        MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8));
                    }
                }
            }
Example #3
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();

            width = 0; height = 0;

            // Map width in 128 pixel units
            // In RSDKvB it's two bytes long, little-endian

            reader.Read(buffer, 0, 2); //Read Map Width
            width = (ushort)(buffer[0] + (buffer[1] << 8));

            reader.Read(buffer, 0, 2); //Read Height
            height = (ushort)(buffer[0] + (buffer[1] << 8));

            //Console.WriteLine("Width " + width + " Height " + height);

            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
                    //Little-Endian in RSDKvB
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[0] + (buffer[1] << 8));
                }
            }

            // Read object data
            int ObjCount = 0;

            // 2 bytes, little-endian, unsigned
            byte t1 = reader.ReadByte();
            byte t2 = reader.ReadByte();

            ObjCount = (t2 << 8) + t1;

            Object.cur_id = 0;

            int n = 0;

            for (n = 0; n < ObjCount; n++)
            {
                // Add object
                objects.Add(new Object(reader));
            }

            reader.Close();
        }