Exemple #1
0
		internal MpqStream(MpqArchive File, MpqBlock Block)
		{
			mBlock = Block;
			
			mStream = File.BaseStream;
			mBlockSize = File.BlockSize;
			
			if (mBlock.IsCompressed) LoadBlockPositions();
		}
Exemple #2
0
        internal MpqStream(MpqArchive File, MpqBlock Block)
        {
            mBlock = Block;

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

            if (mBlock.IsCompressed)
            {
                LoadBlockPositions();
            }
        }
Exemple #3
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
            {
                Console.WriteLine("Unable to find MPQ header");
                mStream.Close();
                return;
            }

            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];
            dcHashes = new Dictionary <UInt64, MpqHash>((int)mHeader.HashTableSize);

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

                // 63   32 31    0
                // |     | |     |
                // [name2] [name1]

                if (mpqHash.IsValid)
                {
                    dcHashes.Add((((UInt64)mpqHash.Name2) << 32) | mpqHash.Name1, mpqHash);
                }
            }

            // Load block table
            mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
            byte[] blockdata = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
            DecryptTable(blockdata, "(block table)");

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

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

            isValid = true;
        }
Exemple #4
0
        public uint GetFileSize(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            if (hash.IsValid)
            {
                MpqBlock block = mBlocks[hash.BlockIndex];
                return(block.FileSize);
            }

            return(0xFFFFFFFF);
        }
Exemple #5
0
        public MpqStream OpenFile(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            if (!hash.IsValid)
            {
                throw new FileNotFoundException("File not found: " + Filename);
            }

            MpqBlock block = mBlocks[hash.BlockIndex];

            return(new MpqStream(this, block));
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
                throw new MpqParserException("Unable to find MPQ header");

            var 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)");

            var 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));
            DecryptTable(blockdata, "(block table)");

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

            for (int i = 0; i < mHeader.BlockTableSize; i++)
                mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);
        }
Exemple #8
0
		private void Init()
		{
            if (LocateMpqHeader() == false)
            {
                Console.WriteLine("Unable to find MPQ header");
                mStream.Close();
                return;
            }

			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];
            dcHashes = new Dictionary<UInt64, MpqHash>((int)mHeader.HashTableSize);
            
            for (int i = 0; i < mHeader.HashTableSize; i++)
            {
                //mHashes[i] = new MpqHash(br2);
                MpqHash mpqHash = new MpqHash(br2);

                // 63   32 31    0
                // |     | |     |
                // [name2] [name1]

                if (mpqHash.IsValid)                                    
                    dcHashes.Add((((UInt64)mpqHash.Name2) << 32) | mpqHash.Name1, mpqHash);                
            }

			// Load block table
			mStream.Seek(mHeader.BlockTablePos, SeekOrigin.Begin);
			byte[] blockdata = br.ReadBytes((int)(mHeader.BlockTableSize * MpqBlock.Size));
			DecryptTable(blockdata, "(block table)");

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

			for (int i = 0; i < mHeader.BlockTableSize; i++)
				mBlocks[i] = new MpqBlock(br2, (uint)mHeaderOffset);

            isValid = true;
		}