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);
        }
 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));
     }
 }
 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);
     }
 }