From 3f1c26f2a6a6b6a9f58232ba6e8d7394e573cfe0 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 16 Jun 2026 01:51:05 -0600 Subject: [PATCH] Workaround CopyTex incremental ID leakage --- lib/gfx/texture.hpp | 4 ++++ lib/gfx/texture_replacement.cpp | 4 ++-- lib/gx/gx.cpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/gfx/texture.hpp b/lib/gfx/texture.hpp index 7f85864..18c2813 100644 --- a/lib/gfx/texture.hpp +++ b/lib/gfx/texture.hpp @@ -106,6 +106,10 @@ struct GXTexObj_ { // Custom flag for texture caching bool no_cache() const noexcept { return (flags & 0x80) != 0; } void set_no_cache(bool value) noexcept { flags = value ? flags | 0x80 : flags & ~0x80; } + + // Hacky workaround for an instances where incremental IDs are used for GXCopyTex, but the copy tex was invalidated + // and the texture reference is still present. + bool has_data() const noexcept { return reinterpret_cast(data) >= 0x10000; } }; static_assert(sizeof(GXTexObj_) <= sizeof(GXTexObj), "GXTexObj too small!"); struct GXTlutObj_ { diff --git a/lib/gfx/texture_replacement.cpp b/lib/gfx/texture_replacement.cpp index 09e4acd..0026417 100644 --- a/lib/gfx/texture_replacement.cpp +++ b/lib/gfx/texture_replacement.cpp @@ -270,7 +270,7 @@ uint32_t texture_base_level_size(const GXTexObj_& obj) noexcept { std::optional compute_referenced_tlut_hash(const GXTexObj_& obj, std::span tlutData) noexcept { const uint32_t textureSize = texture_base_level_size(obj); const auto* textureData = static_cast(obj.data); - if (!is_palette_format(obj.format()) || textureData == nullptr || textureSize == 0 || tlutData.empty()) { + if (!is_palette_format(obj.format()) || !obj.has_data() || textureSize == 0 || tlutData.empty()) { return std::nullopt; } @@ -350,7 +350,7 @@ aurora::texture::TextureSourceKey build_source_key_base(const GXTexObj_& obj) no }; const uint32_t textureSize = texture_base_level_size(obj); - if (obj.data != nullptr && textureSize != 0) { + if (obj.has_data() && textureSize != 0) { key.textureHash = XXH64(obj.data, textureSize, 0); } return key; diff --git a/lib/gx/gx.cpp b/lib/gx/gx.cpp index 22ff17d..2458a5f 100644 --- a/lib/gx/gx.cpp +++ b/lib/gx/gx.cpp @@ -461,14 +461,14 @@ void resolve_sampled_textures(const ShaderInfo& info) noexcept { if (tlut.data != nullptr) { if (copyRef != nullptr) { handle = resolve_dynamic_palette_texture(obj, *copyRef, tlut); - } else { + } else if (obj.has_data()) { handle = resolve_static_palette_texture(obj, tlut); } } } } else if (copyRef != nullptr) { handle = copyRef->handle; - } else if (obj.data != nullptr) { + } else if (obj.has_data()) { handle = resolve_static_texture(obj); }