Example #1
0
        private bool TryGetHashEntry(string filename, out MpqHash hash)
        {
            uint index = HashString(filename, 0);

            index &= _mpqHeader.HashTableSize - 1;
            uint name1 = HashString(filename, 0x100);
            uint name2 = HashString(filename, 0x200);

            for (uint i = index; i < _hashes.Length; ++i)
            {
                hash = _hashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(true);
                }
            }
            for (uint i = 0; i < index; i++)
            {
                hash = _hashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(true);
                }
            }

            hash = new MpqHash();
            return(false);
        }
Example #2
0
        private MpqHash GetHashEntry(string Filename)
        {
            uint index = HashString(Filename, 0);

            index &= mHeader.HashTableSize - 1;
            uint name1 = HashString(Filename, 0x100);
            uint name2 = HashString(Filename, 0x200);

            uint i = index;

            do
            {
                MpqHash hash = mHashes[i];
                if (hash.Name1 == name1 && hash.Name2 == name2)
                {
                    return(hash);
                }
                if (++i >= mHashes.Length)
                {
                    i = 0;
                }
            } while (i != index);

            return(MpqHash.InvalidHash());
        }
        public static MpqHash InvalidHash()
        {
            MpqHash invalid = new MpqHash();

            invalid.Name1 = uint.MaxValue;
            invalid.Name2 = uint.MaxValue;
            return(invalid);
        }
Example #4
0
        private void Init()
        {
            if (LocateMpqHeader() == false)
            {
                throw new MpqParserException("Unable to find MPQ header");
            }

            if (_mpqHeader.HashTableOffsetHigh != 0 || _mpqHeader.ExtendedBlockTableOffset != 0 || _mpqHeader.BlockTableOffsetHigh != 0)
            {
                throw new MpqParserException("MPQ format version 1 features are not supported");
            }

            BinaryReader br = new BinaryReader(BaseStream);

            BlockSize = 0x200 << _mpqHeader.BlockSize;

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

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

            _hashes = new MpqHash[_mpqHeader.HashTableSize];

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

            // Load entry table
            BaseStream.Seek(_mpqHeader.BlockTablePos, SeekOrigin.Begin);
            byte[] entrydata = br.ReadBytes((int)(_mpqHeader.BlockTableSize * MpqEntry.Size));
            DecryptTable(entrydata, "(block table)");

            br2      = new BinaryReader(new MemoryStream(entrydata));
            _entries = new MpqEntry[_mpqHeader.BlockTableSize];

            for (int i = 0; i < _mpqHeader.BlockTableSize; i++)
            {
                _entries[i] = new MpqEntry(br2, (uint)_headerOffset);
            }
        }
Example #5
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);
            }
        }
Example #6
0
        public bool FileExists(string Filename)
        {
            MpqHash hash = GetHashEntry(Filename);

            return(hash.IsValid);
        }