From 68be93467e6725922b1f942eea9d97c978c6badb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 27 Apr 2023 12:05:11 +0200 Subject: [PATCH] Fix some checks around translation. --- Common/Data/Text/I18n.h | 3 ++- Common/UI/PopupScreens.cpp | 7 +++---- Common/UI/PopupScreens.h | 3 ++- GPU/Common/DepalettizeShaderCommon.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Common/Data/Text/I18n.h b/Common/Data/Text/I18n.h index 5c47960212..0756490f22 100644 --- a/Common/Data/Text/I18n.h +++ b/Common/Data/Text/I18n.h @@ -117,6 +117,8 @@ public: std::shared_ptr GetCategoryByName(const char *name); const char *T(I18NCat category, const char *key, const char *def = nullptr) { + if (category == I18NCat::NONE) + return def ? def : key; return cats_[(size_t)category]->T(key, def); } @@ -140,4 +142,3 @@ std::shared_ptr GetI18NCategory(I18NCat cat); inline const char *T(I18NCat category, const char *key, const char *def = nullptr) { return g_i18nrepo.T(category, key, def); } - diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index aea2f469e5..6ee96b9bda 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -115,12 +115,11 @@ void PopupMultiChoice::Update() { void PopupMultiChoice::UpdateText() { if (!choices_) return; - auto category = GetI18NCategory(category_); - // Clamp the value to be safe. - if (*value_ < minVal_ || *value_ > minVal_ + numChoices_ - 1) { + int index = *value_ - minVal_; + if (index < 0 || index >= numChoices_) { valueText_ = "(invalid choice)"; // Shouldn't happen. Should be no need to translate this. } else { - valueText_ = category ? category->T(choices_[*value_ - minVal_]) : choices_[*value_ - minVal_]; + valueText_ = T(category_, choices_[index]); } } diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index f0270b9a10..2cfbb23979 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -205,13 +205,14 @@ public: : AbstractChoiceWithValueDisplay(text, layoutParams), value_(value), choices_(choices), minVal_(minVal), numChoices_(numChoices), category_(category), screenManager_(screenManager) { if (choices) { + // If choices is nullptr, we're being called from PopupMultiChoiceDynamic where value doesn't yet point to anything valid. if (*value >= numChoices + minVal) *value = numChoices + minVal - 1; if (*value < minVal) *value = minVal; + UpdateText(); } OnClick.Handle(this, &PopupMultiChoice::HandleClick); - UpdateText(); } void Update() override; diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index 8bba36521d..f4e7e7a9fa 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -250,7 +250,7 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config) { case GE_FORMAT_5551: if (config.textureFormat == GE_TFMT_CLUT8 && mask == 0xFF && shift == 0) { // Follow the intent here, and ignore g (and let's not round unnecessarily). - sprintf(lookupMethod, "floor(floor(index.a) * 128.0 + index.b * 64.0)"); // we just skip A. + sprintf(lookupMethod, "floor(floor(index.a) * 128.0 + index.b * 64.0)"); index_multiplier = 1.0f / 256.0f; // SOCOM case. #16210 } else if ((mask & (mask + 1)) == 0 && shift < 16) {