hazzik / mpqtool-export

Automatically exported from code.google.com/p/mpqtool
0 stars 1 forks source link

A fix for GetHashEntry function #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
While opening files from mpq archive I've noticed that some files are not
found. After analysing the problem I've came to conclusion that
GetHashEntry function does not work in all cases, so I've opened StormLib
source codes and  compared it's GetHashEntry function code with yours.
There was a difference and I've fixed it and after that everything stared
to work normally. Here is the modified code of the GetHashEntry function:

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

    for (uint i = index; ; )
    {
        MpqHash hash = mHashes[i];
        if (hash.Name1 == name1 && hash.Name2 == name2) return hash;

        if (++i >= mHashes.Length) i = 0;
        if (i == index) break;
    }

    return MpqHash.InvalidHash();
}

only the "for" cycle was changed so that if it has reached the end of the
hash table, it starts from the beginning. Perhaps the entire funtion should
be optimized then, because if the file is not present in mpq this function
will check EVERY hash record. Maybe I'll use Dictionary class for this or
smth :).

Original issue reported on code.google.com by danat...@gmail.com on 17 Nov 2007 at 6:03

GoogleCodeExporter commented 9 years ago

Original comment by fool...@gmail.com on 19 Nov 2007 at 7:52

GoogleCodeExporter commented 9 years ago
?

I don't see any text in your comment fooleau

Original comment by danat...@gmail.com on 19 Nov 2007 at 11:09

GoogleCodeExporter commented 9 years ago
I was just assigning the issue to myself.

Thanks for the bug report.  I don't think I would have found that one.

This is now fixed in revision 12.  I tidied up the code a bit.  Let me know if 
it
still solves the problem.

Original comment by fool...@gmail.com on 21 Nov 2007 at 12:09

GoogleCodeExporter commented 9 years ago
Hi. Yes it works now, but I've decided to optimize it even more :) by
using the Dictionary  class (which is actually a Hashtable) like I
said in my comment. I've used the name1 and name2 as the Int64-key. It
should work a lot faster for finding files inside the mpq archive. In
case you're interested in this solution, i've attached the
MpqArchive.cs.

Original comment by danat...@gmail.com on 23 Nov 2007 at 12:31

Attachments: