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

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

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

            hash = new MpqHash();
            return(false);
        }
        private bool TryGetHashEntry(string filename, out MpqHash hash)
        {
            uint num  = HashString(filename, 0) & (this._mpqHeader.HashTableSize - 1);
            uint num2 = HashString(filename, 0x100);
            uint num3 = HashString(filename, 0x200);

            for (uint i = num; i < this._hashes.Length; i++)
            {
                hash = this._hashes[i];
                if ((hash.Name1 == num2) && (hash.Name2 == num3))
                {
                    return(true);
                }
            }
            for (uint j = 0; j < num; j++)
            {
                hash = this._hashes[j];
                if ((hash.Name1 == num2) && (hash.Name2 == num3))
                {
                    return(true);
                }
            }
            hash = new MpqHash();
            return(false);
        }
 public MpqHash(BinaryReader br)
 {
     this            = new MpqHash();
     this.Name1      = br.ReadUInt32();
     this.Name2      = br.ReadUInt32();
     this.Locale     = br.ReadUInt32();
     this.BlockIndex = br.ReadUInt32();
 }
Example #4
0
        // Use this contructor for files that came from another archive, and for which the filename is unknown.
        public MpqFile(Stream sourceStream, MpqHash mpqHash, uint hashIndex, uint hashCollisions, MpqFileFlags flags, ushort blockSize)
            : this(sourceStream, null, flags, blockSize)
        {
            if (mpqHash.Mask == 0)
            {
                throw new ArgumentException("Expected the Mask value of mpqHash argument to be set to a non-zero value.", nameof(mpqHash));
            }

            _hash           = mpqHash;
            _hashIndex      = hashIndex;
            _hashCollisions = hashCollisions;
        }
Example #5
0
        private int TryGetHashEntry(int entryIndex, out MpqHash hash)
        {
            for (var i = 0; i < _hashTable.Size; i++)
            {
                if (_hashTable[i].BlockIndex == entryIndex)
                {
                    hash = _hashTable[i];
                    return(i);
                }
            }

            hash = MpqHash.NULL;
            return(-1);
        }
        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 #7
0
        internal HashTable(BinaryReader reader, uint size) : base(size)
        {
            _mask   = _size - 1;
            _hashes = new MpqHash[_size];

            var hashdata = reader.ReadBytes((int)(size * MpqHash.Size));

            Decrypt(hashdata, TableKey);

            using (var stream = new MemoryStream(hashdata))
            {
                using (var streamReader = new BinaryReader(stream))
                {
                    for (var i = 0; i < size; i++)
                    {
                        _hashes[i] = new MpqHash(streamReader, _mask);
                    }
                }
            }
        }