Esempio n. 1
0
        public Bytecode(Reader reader)
        {
            int scriptCodePos = 0;
            int jumpTablePos  = 0;

            // Bytecode
            for (int scriptCodeSize = reader.ReadInt32(); scriptCodeSize > 0;)
            {
                int buffer    = reader.ReadByte();
                int blockSize = buffer & 0x7F;

                if ((buffer & 0x80) == 0)
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        scriptCode[scriptCodePos++] = reader.ReadByte();
                    }
                    scriptCodeSize -= blockSize;
                }
                else
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        scriptCode[scriptCodePos++] = reader.ReadInt32();
                    }
                    scriptCodeSize -= blockSize;
                }
            }

            for (int jumpTableSize = reader.ReadInt32(); jumpTableSize > 0;)
            {
                int buffer    = reader.ReadByte();
                int blockSize = buffer & 0x7F;

                if ((buffer & 0x80) == 0)
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        jumpTable[jumpTablePos++] = reader.ReadByte();
                    }
                    jumpTableSize -= blockSize;
                }
                else
                {
                    for (int i = 0; i < blockSize; i++)
                    {
                        jumpTable[jumpTablePos++] = reader.ReadInt32();
                    }
                    jumpTableSize -= blockSize;
                }
            }

            // Scripts
            int scriptCount = reader.ReadInt16();

            for (int i = 0; i < scriptCount; i++)
            {
                ScriptInfo info = new ScriptInfo();
                info.scriptCodePos_main    = reader.ReadInt32();
                info.scriptCodePos_draw    = reader.ReadInt32();
                info.scriptCodePos_startup = reader.ReadInt32();
                scripts.Add(info);
            }

            foreach (ScriptInfo info in scripts)
            {
                info.jumpTablePos_main    = reader.ReadInt32();
                info.jumpTablePos_draw    = reader.ReadInt32();
                info.jumpTablePos_startup = reader.ReadInt32();
            }

            // Functions
            int functionCount = reader.ReadInt16();

            for (int i = 0; i < functionCount; i++)
            {
                FunctionScript info = new FunctionScript();
                info.scriptCodePos = reader.ReadInt32();
                functionList.Add(info);
            }
            foreach (FunctionScript info in functionList)
            {
                info.jumpTablePos = reader.ReadInt32();
            }

            scriptCodeLength = scriptCodePos;
            jumpTableLength  = jumpTablePos;
        }
Esempio n. 2
0
        public void read(Reader reader)
        {
            reader.ReadInt16(); // "BM"
            reader.ReadInt32(); // totalFileSize
            reader.ReadInt32(); // Unused
            int pixelPos = reader.ReadInt32();

            reader.seek(14 + 4, System.IO.SeekOrigin.Begin);

            width  = reader.ReadByte();
            width |= reader.ReadByte() << 8;
            width |= reader.ReadByte() << 16;
            width |= reader.ReadByte() << 24;

            height  = reader.ReadByte();
            height |= reader.ReadByte() << 8;
            height |= reader.ReadByte() << 16;
            height |= reader.ReadByte() << 24;

            reader.BaseStream.Position += sizeof(ushort);
            bool indexed = reader.ReadUInt16() <= 8; //bpp

            if (!indexed)
            {
                throw new Exception("RSDK-Formatted Bitmap files must be indexed!");
            }

            reader.BaseStream.Position += 4 * sizeof(int);
            int clrCount = reader.ReadInt32(); // how many colours used

            reader.seek(14 + 40, System.IO.SeekOrigin.Begin);

            for (int c = 0; c < clrCount; c++)
            {
                palette[c].B = reader.ReadByte();
                palette[c].G = reader.ReadByte();
                palette[c].R = reader.ReadByte();
                reader.ReadByte(); // unused
            }

            long expectedPixelPos = (reader.BaseStream.Length - height * width);

            if (pixelPos != expectedPixelPos)
            {
                throw new Exception("RSDK-Formatted Bitmap files must end with the pixel data!");
            }

            // This is how RSDK does it but there's a small chance it could maybe be wrong
            reader.seek(expectedPixelPos, System.IO.SeekOrigin.Begin);

            pixels = new byte[width * height];
            int gfxPos = width * (height - 1);

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    pixels[gfxPos++] = reader.ReadByte();
                }
                gfxPos -= 2 * width;
            }

            reader.Close();
        }