Skip to content

Commit

Permalink
Merge pull request #14341 from Banh-Canh/fix-hashes-w-reduceHashranges
Browse files Browse the repository at this point in the history
Fix: remove filename prefix for reducehashranges
  • Loading branch information
hrydgard authored Apr 17, 2021
2 parents 8314a80 + 5dbf393 commit 73fb004
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions Core/TextureReplacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void TextureReplacer::PopulateReplacement(ReplacedTexture *result, u64 cachekey,
}

for (int i = 0; i < MAX_MIP_LEVELS; ++i) {
const std::string hashfile = LookupHashFile(cachekey, hash, i, w, h);
const std::string hashfile = LookupHashFile(cachekey, hash, i);
const std::string filename = basePath_ + hashfile;
if (hashfile.empty() || !File::Exists(filename)) {
// Out of valid mip levels. Bail out.
Expand Down Expand Up @@ -472,7 +472,7 @@ void TextureReplacer::NotifyTextureDecoded(const ReplacedTextureDecodeInfo &repl
return;
}

std::string hashfile = LookupHashFile(cachekey, replacedInfo.hash, level, w, h);
std::string hashfile = LookupHashFile(cachekey, replacedInfo.hash, level);
const std::string filename = basePath_ + hashfile;
const std::string saveFilename = basePath_ + NEW_TEXTURE_DIR + hashfile;

Expand Down Expand Up @@ -638,32 +638,25 @@ bool TextureReplacer::FindFiltering(u64 cachekey, u32 hash, TextureFiltering *fo
return false;
}

std::string TextureReplacer::LookupHashFile(u64 cachekey, u32 hash, int level, int w, int h) {
std::string TextureReplacer::LookupHashFile(u64 cachekey, u32 hash, int level) {
ReplacementAliasKey key(cachekey, hash, level);
auto alias = LookupWildcard(aliases_, key, cachekey, hash, ignoreAddress_);
if (alias != aliases_.end()) {
// Note: this will be blank if explicitly ignored.
return alias->second;
}

return HashName(cachekey, hash, level, w, h) + ".png";
return HashName(cachekey, hash, level) + ".png";
}

std::string TextureReplacer::HashName(u64 cachekey, u32 hash, int level, int w, int h) {
std::string TextureReplacer::HashName(u64 cachekey, u32 hash, int level) {
char hashname[16 + 8 + 1 + 11 + 1] = {};
if (level > 0) {
snprintf(hashname, sizeof(hashname), "%016llx%08x_%d", cachekey, hash, level);
} else {
snprintf(hashname, sizeof(hashname), "%016llx%08x", cachekey, hash);
}

if ((reduceHash_) && (reduceHashSize != reduceHashGlobalValue))
{
// if a reducehashrange is specified, add a prefix with their dimension to prevent overwriting dump with the global reducehash value ex : 128x256_hashname.png.
// Add only a prefix for value that are different to the reducehashglobalvalue
return std::to_string(w) + "x" + std::to_string(h) + "_" + hashname;
}

return hashname;
}

Expand Down Expand Up @@ -776,6 +769,8 @@ bool TextureReplacer::GenerateIni(const std::string &gameID, std::string *genera
fs << "[hashranges]\n";
fs << "\n";
fs << "[filtering]\n";
fs << "\n";
fs << "[reducehashranges]\n";
fs.close();
}
return File::Exists(texturesDirectory + INI_FILENAME);
Expand Down
4 changes: 2 additions & 2 deletions Core/TextureReplacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class TextureReplacer {
void ParseReduceHashRange(const std::string& key, const std::string& value);
bool LookupHashRange(u32 addr, int &w, int &h);
float LookupReduceHashRange(int& w, int& h);
std::string LookupHashFile(u64 cachekey, u32 hash, int level, int w, int h);
std::string HashName(u64 cachekey, u32 hash, int level, int w, int h);
std::string LookupHashFile(u64 cachekey, u32 hash, int level);
std::string HashName(u64 cachekey, u32 hash, int level);
void PopulateReplacement(ReplacedTexture *result, u64 cachekey, u32 hash, int w, int h);

SimpleBuf<u32> saveBuf;
Expand Down

0 comments on commit 73fb004

Please sign in to comment.