From 59ada74deb0c4df1476d2e1e83b40889e8cb63a7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 30 Apr 2016 15:41:12 -0700 Subject: [PATCH] Allow hashes to be ignored explicitly. Still need the actual ini hookup. --- Core/TextureReplacer.cpp | 39 +++++++++++++++++++++++++++------------ Core/TextureReplacer.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index 54144dfe0b..274a9ac5f8 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -81,7 +81,12 @@ ReplacedTexture TextureReplacer::FindReplacement(u64 cachekey, u32 hash) { // Only actually replace if we're replacing. We might just be saving. if (g_Config.bReplaceTextures) { - // TODO + std::string hashfile = LookupHashFile(cachekey, hash, 0); + const std::string filename = basePath_ + hashfile; + + if (!hashfile.empty() && File::Exists(filename)) { + // TODO: Count levels that exist, etc. + } } return result; } @@ -116,18 +121,12 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con return; } - char hashname[16 + 8 + 4 + 1 + 11 + 1] = {}; - if (level > 0) { - snprintf(hashname, sizeof(hashname), "%016llx%08x_%d.png", cachekey, hash, level); - } else { - snprintf(hashname, sizeof(hashname), "%016llx%08x.png", cachekey, hash); - } - const std::string filename = basePath_ + hashname; + std::string hashfile = LookupHashFile(cachekey, hash, level); + const std::string filename = basePath_ + hashfile; - // TODO: Check for ini ignored or aliased textures. - - if (File::Exists(filename)) { - // Must've been decoded and saved as a new texture already. + // If it's empty, it's an ignored hash, we intentionally don't save. + if (hashfile.empty() || File::Exists(filename)) { + // If it exists, must've been decoded and saved as a new texture already. return; } @@ -174,6 +173,22 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con #endif } +std::string TextureReplacer::LookupHashFile(u64 cachekey, u32 hash, int level) { + // TODO: Look up via ini for alias / ignored. + return HashName(cachekey, hash, level) + ".png"; +} + +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.png", cachekey, hash, level); + } else { + snprintf(hashname, sizeof(hashname), "%016llx%08x.png", cachekey, hash); + } + + return hashname; +} + bool TextureReplacer::LookupHashRange(u32 addr, int &w, int &h) { // TODO: Pull from table loaded via ini. return false; diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index e155bd5b11..0e6a5bff58 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include "Common/Common.h" #include "Common/MemoryUtil.h" @@ -105,6 +106,8 @@ public: protected: bool LookupHashRange(u32 addr, int &w, int &h); + std::string LookupHashFile(u64 cachekey, u32 hash, int level); + std::string HashName(u64 cachekey, u32 hash, int level); SimpleBuf saveBuf; bool enabled_;