internal MpqStream(MpqArchive File, MpqBlock Block)
        {
            mBlock = Block;

            mStream = File.BaseStream;
            mBlockSize = File.BlockSize;

            if (mBlock.IsCompressed)
                LoadBlockPositions();
        }
Beispiel #2
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
            {
                throw new MpqParserException("Unable to find MPQ header");
            }

            BinaryReader br = new BinaryReader(mStream);

            mBlockSize = 0x200 << mHeader.BlockSize;

            // Load hash table
            mStream.Seek(mHeader.HashTablePos, SeekOrigin.Begin);
            byte[] hashdata = br.ReadBytes((int)(mHeader.HashTableSize * MpqHash.Size));
            DecryptTable(hashdata, "(hash table)");

            BinaryReader br2 = new BinaryReader(new MemoryStream(hashdata));

            mHashes = new MpqHash[mHeader.HashTableSize];

            for (int i = 0; i < mHeader.HashTableSize; i++)
            {
                mHashes[i] = new MpqHash(br2);
            }

            // Load block table
            mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
            byte[] blockdata  = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
            int    blockcount = (int)(blockdata.Length / MpqBlock.Size); // This is not always mHeader.BlockTableSize

            DecryptTable(blockdata, "(block table)");

            br2     = new BinaryReader(new MemoryStream(blockdata));
            mBlocks = new MpqBlock[mHeader.BlockTableSize];

            for (int i = 0; i < blockcount; i++)
            {
                mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);
            }
        }