1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

Rewrite compressed BSA hash calculation again

This commit is contained in:
Alexei Dobrohotov 2020-10-23 20:18:08 +03:00
parent f592aca6d3
commit 45c155b054

View file

@ -461,38 +461,28 @@ std::uint64_t CompressedBSAFile::generateHash(std::string stem, std::string exte
size_t len = stem.length(); size_t len = stem.length();
if (len == 0) if (len == 0)
return 0; return 0;
std::uint64_t hash = 0; std::replace(stem.begin(), stem.end(), '/', '\\');
unsigned int hash2 = 0;
Misc::StringUtils::lowerCaseInPlace(stem); Misc::StringUtils::lowerCaseInPlace(stem);
if (extension.empty()) // It's a folder. uint64_t result = stem[len-1] | (len >= 3 ? (stem[len-2] << 8) : 0) | (len << 16) | (stem[0] << 24);
std::replace(stem.begin(), stem.end(), '/', '\\');
else
{
Misc::StringUtils::lowerCaseInPlace(extension);
for (const char &c : extension)
hash = hash * 0x1003f + c;
}
if (len >= 4) if (len >= 4)
{ {
for (size_t i = 1; i < len-2; i++) uint32_t hash = 0;
hash2 = hash2 * 0x1003f + stem[i]; for (size_t i = 1; i <= len-3; ++i)
hash = hash * 0x1003f + stem[i];
result += static_cast<uint64_t>(hash) << 32;
} }
hash = (hash + hash2) << 32; if (extension.empty())
hash2 = (stem[0] << 24) | (len << 16); return result;
if (len >= 2) Misc::StringUtils::lowerCaseInPlace(extension);
{ if (extension == ".kf") result |= 0x80;
if (len >= 3) else if (extension == ".nif") result |= 0x8000;
hash2 |= stem[len-2] << 8; else if (extension == ".dds") result |= 0x8080;
hash2 |= stem[len-1]; else if (extension == ".wav") result |= 0x80000000;
} uint32_t hash = 0;
if (!extension.empty()) for (const char &c : extension)
{ hash = hash * 0x1003f + c;
if (extension == ".kf") hash2 |= 0x80; result += static_cast<uint64_t>(hash) << 32;
else if (extension == ".nif") hash2 |= 0x8000; return result;
else if (extension == ".dds") hash2 |= 0x8080;
else if (extension == ".wav") hash2 |= 0x80000000;
}
return hash + hash2;
} }
} //namespace Bsa } //namespace Bsa