Пример #1
0
        private bool TryGetHashEntry(string filename, out MpqHash hash)
        {
            if (!StormBuffer.TryGetHashString(filename, 0, out var index))
            {
                hash = default;
                return(false);
            }

            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);
        }
Пример #2
0
        private IEnumerable <MpqHash> GetHashEntries(string filename)
        {
            if (!StormBuffer.TryGetHashString(filename, 0, out var index))
            {
                yield break;
            }

            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;
                }
            }
        }