Custom buttons: sanitize image/shape on the one screen that didn't

CustomButtonMappingScreen indexes customKeyImages[36] and customKeyShapes[11] with
values read straight from the ini, and it's reachable from the main menu - so
neither GamepadEmu nor TouchControlLayoutScreen, which both sanitize first, need
have run. Those two had the same fixup copy-pasted; hoisted it into a Sanitize()
next to the tables and called it from all three.
This commit is contained in:
Henrik Rydgård committed 2026-09-02 18:06:47 +02:00
1 parent 329b7a15bd
commit dcbfa7d3ee
4 files changed
+17 -12

No files matched your search

+3
View File
@@ -138,6 +138,9 @@ void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) {
bool *show = nullptr;
memset(array, 0, sizeof(array));
cfg = &g_Config.CustomButton[id_];
// This screen is reachable from the main menu, so neither GamepadEmu nor the layout screen
// need have sanitized these yet - and everything below indexes the tables with them.
CustomKeyData::Sanitize(*cfg);
show = &touch.touchCustom[id_].show;
for (int i = 0; i < ARRAY_SIZE(g_customKeyList); i++)
array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01));
+1 -6
View File
@@ -1106,12 +1106,7 @@ GamepadEmuView::GamepadEmuView(const TouchControlConfig &config, float xres, flo
// Sanitize custom button images, while adding them.
for (int i = 0; i < TouchControlConfig::CUSTOM_BUTTON_COUNT; i++) {
if (g_Config.CustomButton[i].shape >= ARRAY_SIZE(CustomKeyData::customKeyShapes)) {
g_Config.CustomButton[i].shape = 0;
}
if (g_Config.CustomButton[i].image >= ARRAY_SIZE(CustomKeyData::customKeyImages)) {
g_Config.CustomButton[i].image = 0;
}
CustomKeyData::Sanitize(g_Config.CustomButton[i]);
char temp[64];
snprintf(temp, sizeof(temp), "Custom %d button", i + 1);
+12
View File
@@ -22,6 +22,7 @@
#include "Common/UI/View.h"
#include "Common/UI/ViewGroup.h"
#include "Core/ConfigValues.h"
#include "Core/CoreParameter.h"
#include "Core/HLE/sceCtrl.h"
#include "UI/EmuScreen.h"
@@ -366,6 +367,17 @@ namespace CustomKeyData {
// IMPORTANT: Only add at the end!
};
static_assert(ARRAY_SIZE(g_customKeyList) <= 64, "Too many key for a uint64_t bit mask");
// image and shape come straight from the ini and index the tables above, so anything that
// reads them has to run this first.
inline void Sanitize(ConfigCustomButton &cfg) {
if (cfg.image < 0 || cfg.image >= (int)ARRAY_SIZE(customKeyImages)) {
cfg.image = 0;
}
if (cfg.shape < 0 || cfg.shape >= (int)ARRAY_SIZE(customKeyShapes)) {
cfg.shape = 0;
}
}
};
// Gesture key only have virtual button that can work without constant press
+1 -6
View File
@@ -537,12 +537,7 @@ void ControlLayoutView::CreateViews() {
for (int i = 0; i < TouchControlConfig::CUSTOM_BUTTON_COUNT; i++) {
// Similar to GamepadEmu, we sanitize the images for valid values.
if (g_Config.CustomButton[i].shape >= ARRAY_SIZE(CustomKeyData::customKeyShapes)) {
g_Config.CustomButton[i].shape = 0;
}
if (g_Config.CustomButton[i].image >= ARRAY_SIZE(CustomKeyData::customKeyImages)) {
g_Config.CustomButton[i].image = 0;
}
CustomKeyData::Sanitize(g_Config.CustomButton[i]);
char temp[64];
snprintf(temp, sizeof(temp), "Custom %d button", i);