Exemplo n.º 1
0
            public void Load(ExtendedBinaryReader reader)
            {
                LayerName = reader.ReadSignature(0x20);
                uint unknown20 = reader.ReadUInt32();

                TextureID = reader.ReadInt32();
                uint Offset    = reader.ReadUInt32();
                uint unknown2C = reader.ReadUInt32();

                //
                uint oldpos = (uint)reader.GetPosition();

                reader.JumpTo(Offset);

                reader.JumpAhead(0x164);
                LayerOffX = reader.ReadSingle();
                LayerOffY = reader.ReadSingle();
                reader.JumpAhead(4);
                LayerWidth  = reader.ReadSingle();
                LayerHeight = reader.ReadSingle();

                reader.JumpAhead(0x88); // Unknown

                /*
                 * Top Left
                 * Top Right
                 * Bottom Left
                 * Bottom Right
                 */

                for (int i = 0; i < 4; ++i)
                {
                    Verts.Add(new MAVert(reader));
                }

                reader.JumpTo(oldpos);

                reader.JumpAhead(0x84); // Unknown
            }
Exemplo n.º 2
0
        public static byte[] DecompressLZ77(this byte[] compressed)
        {
            byte[] buffer = null;
            using (var reader = new ExtendedBinaryReader(new MemoryStream(compressed)))
            {
                int  position     = 0;
                long flagPosition = 0;
                if (reader.ReadSignature() == "LZ77")
                {
                    int uncompressedSize = reader.ReadInt32();
                    int lz77Step         = reader.ReadInt32();
                    int offset           = reader.ReadInt32();
                    flagPosition = reader.GetPosition();
                    reader.JumpTo(offset);
                    buffer = new byte[uncompressedSize];
                }

                int flagCount = 0;
                int flag      = 0;
                while (true)
                {
                    if (flagCount == 0)
                    {
                        if (flagPosition >= compressed.Length)
                        {
                            break;
                        }
                        if (flagPosition == reader.GetPosition())
                        {
                            reader.JumpAhead(1);
                        }
                        flag      = compressed[flagPosition++];
                        flagCount = 8;
                    }
                    if ((flag & 0x80) != 0)
                    {
                        if (reader.GetPosition() + 2 > compressed.Length)
                        {
                            break;
                        }
                        int backStep = reader.ReadByte();
                        int amount   = reader.ReadByte();
                        for (amount += 3; (amount--) != 0; position++)
                        {
                            if (position >= buffer.Length)
                            {
                                break;
                            }
                            buffer[position] = buffer[position - backStep];
                        }
                    }
                    else
                    {
                        if (position >= buffer.Length)
                        {
                            break;
                        }
                        buffer[position++] = reader.ReadByte();
                    }
                    flag <<= 1;
                    flagCount--;
                }
            }
            return(buffer);
        }