Ejemplo n.º 1
0
        /// <summary>
        /// Reads a Stream header and returns a decompressed Refpack body.
        /// </summary>
        public Stream Decompress()
        {
            byte BodyType         = ReadByte();
            uint DecompressedSize = ReadUInt32();

            if (BodyType == 0)
            {
                return(new MemoryStream(ReadBytes((int)DecompressedSize)));
            }
            else
            {
                uint CompressedSize = ReadUInt32();
                //This is *always* in little endian, regardless of the rest
                //of the stream, probably to avoid switching, because its
                //value is the same as the above field.
                uint StreamSize = ReadUInt32();

                Decompresser Dec = new Decompresser();
                byte[]       DecompressedData = Dec.Decompress(ReadBytes((int)CompressedSize));

                return(new MemoryStream(DecompressedData));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a Stream header and returns a decompressed Refpack body.
        /// </summary>
        public Stream Decompress()
        {
            try
            {
                byte BodyType         = ReadByte();
                uint DecompressedSize = ReadUInt32();

                if (BodyType == 0)
                {
                    return(new MemoryStream(ReadBytes((int)DecompressedSize)));
                }
                else
                {
                    uint CompressedSize = ReadUInt32();
                    //This is *always* in little endian, regardless of the rest
                    //of the stream, probably to avoid switching, because its
                    //value is the same as the above field.
                    uint StreamSize = ReadUInt32();

                    //This is the RefPak header. For some reason, reading it inside the Decompresser
                    //causes the Decompresser to crash. So read it here instead.
                    ReadBytes(5);

                    Decompresser Dec = new Decompresser();
                    Dec.DecompressedSize = DecompressedSize;
                    //CompressedSize includes the size of itself (4 bytes) and the RefPak header (5 bytes).
                    byte[] DecompressedData = Dec.Decompress(ReadBytes((int)CompressedSize - 9));

                    return(new MemoryStream(DecompressedData));
                }
            }
            catch (Exception E)
            {
                throw new Exception(E.ToString());
            }
        }