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

            index &= _mpqHeader.HashTableSize - 1;
            var name = MpqHash.GetHashedFileName(filename);

            for (var i = index; i < _hashTable.Size; ++i)
            {
                hash = _hashTable[i];
                if (hash.Name == name)
                {
                    return(true);
                }
            }

            for (uint i = 0; i < index; ++i)
            {
                hash = _hashTable[i];
                if (hash.Name == name)
                {
                    return(true);
                }
            }

            hash = default;
            return(false);
        }
Example #2
0
        public static ulong GetHashedFileName(string fileName)
        {
            if (fileName.Any(c => c >= 0x200))
            {
                throw new ArgumentException($"One or more of the characters in the input string have a numerical value of 0x200 or larger.", nameof(fileName));
            }

            return(CombineNames(StormBuffer.HashString(fileName, 0x100), StormBuffer.HashString(fileName, 0x200)));
        }
Example #3
0
        public static uint GetIndex(string path)
        {
            if (path.Any(c => c >= 0x200))
            {
                throw new ArgumentException($"One or more of the characters in the input string have a numerical value of 0x200 or larger.", nameof(path));
            }

            return(StormBuffer.HashString(path, 0));
        }
Example #4
0
        private IEnumerable <MpqHash> GetHashEntries(string filename)
        {
            var index = StormBuffer.HashString(filename, 0);

            index &= _mpqHeader.HashTableSize - 1;
            var name = MpqHash.GetHashedFileName(filename);

            var foundAnyHash = false;

            for (var i = index; i < _hashTable.Size; ++i)
            {
                var hash = _hashTable[i];
                if (hash.Name == name)
                {
                    yield return(hash);

                    foundAnyHash = true;
                }
                else if (hash.IsEmpty && foundAnyHash)
                {
                    yield break;
                }
            }

            for (uint i = 0; i < index; ++i)
            {
                var hash = _hashTable[i];
                if (hash.Name == name)
                {
                    yield return(hash);

                    foundAnyHash = true;
                }
                else if (hash.IsEmpty && foundAnyHash)
                {
                    yield break;
                }
            }
        }
Example #5
0
 /// <summary>
 /// Decrypts the contents of the <see cref="MpqTable"/>.
 /// </summary>
 /// <param name="data">The encrypted entries in the table.</param>
 internal void Decrypt(byte[] data)
 {
     StormBuffer.DecryptBlock(data, StormBuffer.HashString(Key, 0x300));
 }
Example #6
0
 /// <summary>
 /// Encrypts the contents of the <see cref="MpqTable"/>.
 /// </summary>
 /// <param name="data">The unencrypted entries in the table.</param>
 public void Encrypt(byte[] data)
 {
     StormBuffer.EncryptBlock(data, StormBuffer.HashString(Key, 0x300));
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MpqHash"/> struct.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="mask"></param>
 /// <param name="locale"></param>
 /// <param name="blockIndex"></param>
 public MpqHash(string fileName, uint mask, MpqLocale locale, uint blockIndex)
     : this(StormBuffer.HashString(fileName, 0x100), StormBuffer.HashString(fileName, 0x200), locale, blockIndex, mask)
 {
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="path"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public static uint GetIndex(string path, uint mask)
 {
     return(StormBuffer.HashString(path, 0) & mask);
 }
Example #9
0
 public static ulong GetHashedFileName(string fileName)
 {
     return(CombineNames(StormBuffer.HashString(fileName, 0x100), StormBuffer.HashString(fileName, 0x200)));
 }