コード例 #1
0
        public byte[] doCompress(byte[] data)
        {
            byte[] buffer = new byte[data.Length];
            ByteHelper.Write_be((uint)0x524e4301, buffer, 0);
            ByteHelper.Write_be((uint)data.Length, buffer, 4);
            ByteHelper.Write_be(RNCCommon.crc(data, 0, data.Length), buffer, 12);
            this.bf = new BitBuffer(buffer, 0x12);
            byte num = 0;

            this.bf.writeBits(0, 2);
            this.ibuf = data;
            this.ipos = 0;
            while (this.ipos < this.ibuf.Length)
            {
                Tuple[] block = this.makeBlock();
                this.writeBlock(block);
                num = (byte)(num + 1);
            }
            this.bf.writeEnd();
            Array.Resize <byte>(ref buffer, this.bf.position);
            ByteHelper.Write_be((uint)(buffer.Length - 0x12), buffer, 8);
            ByteHelper.Write_be(RNCCommon.crc(buffer, 0x12, buffer.Length - 0x12), buffer, 14);
            buffer[0x10] = 0;
            buffer[0x11] = num;
            return(buffer);
        }
コード例 #2
0
        public byte[] doDecompress(byte[] data)
        {
            if (ByteHelper.Read32_be(data, 0) != 0x524e4301)
            {
                throw new ExBadFormat("signature");
            }
            uint   num2 = ByteHelper.Read32_be(data, 4);
            uint   num3 = ByteHelper.Read32_be(data, 8);
            ushort num4 = ByteHelper.Read16_be(data, 12);
            ushort num5 = ByteHelper.Read16_be(data, 14);
            byte   num6 = data[0x11];

            if (RNCCommon.crc(data, 0x12, (int)num3) != num5)
            {
                throw new ExBadCRC("packed");
            }
            this.bf = new BitBuffer(data, 0x12);
            byte[] destinationArray = new byte[num2];
            int    index            = 0;

            this.bf.readBits(2);
            do
            {
                RNCCommon.Huff[] table      = this.makeHuffTable();
                RNCCommon.Huff[] huffArray2 = this.makeHuffTable();
                RNCCommon.Huff[] huffArray3 = this.makeHuffTable();
                ushort           num8       = (ushort)this.bf.readBits(0x10);
                do
                {
                    uint num9 = this.inputValue(table);
                    if (num9 > 0)
                    {
                        Array.Copy(this.bf.getBytes((int)num9), 0L, destinationArray, (long)index, (long)num9);
                        index += (int)num9;
                    }
                    if (num8 > 1)
                    {
                        uint num10 = (uint)(this.inputValue(huffArray2) + 1);
                        num9 = (uint)(this.inputValue(huffArray3) + 2);
                        while (num9-- > 0)
                        {
                            destinationArray[index] = destinationArray[(int)((IntPtr)(index - num10))];
                            index++;
                        }
                    }
                }while ((num8 = (ushort)(num8 - 1)) != 0);
                if (num6 > 0)
                {
                    num6 = (byte)(num6 - 1);
                }
            }while (num6 > 0);
            if (RNCCommon.crc(destinationArray, 0, destinationArray.Length) != num4)
            {
                throw new ExBadCRC("unpacked");
            }
            return(destinationArray);
        }
コード例 #3
0
 private ushort inputValue(RNCCommon.Huff[] table)
 {
     int index = 0;
     while (table[index].code != this.bf.peekBits(table[index].len))
     {
         index++;
     }
     this.bf.readBits(table[index].len);
     ushort num2 = table[index].value;
     if (num2 >= 2)
     {
         num2 = (ushort)(num2 - 1);
         ushort num = (ushort)this.bf.readBits((byte)num2);
         num = (ushort)(num | ((ushort)(((int)1) << num2)));
         num2 = num;
     }
     return num2;
 }
コード例 #4
0
 private void writeHuffValue(RNCCommon.Huff[] table, ushort value)
 {
     int index = this.bitLen(value);
     this.bf.writeBits(table[index].code, table[index].len);
     if (index > 1)
     {
         this.bf.writeBits(value, (byte)(index - 1));
     }
 }
コード例 #5
0
 private void writeHuff(RNCCommon.Huff[] table)
 {
     this.bf.writeBits((uint)table.Length, 5);
     for (int i = 0; i < table.Length; i++)
     {
         this.bf.writeBits(table[i].len, 4);
     }
 }