From a8fd0b64acd639f2e444d2083f670d0ac92ca3e8 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 3 May 2024 13:00:18 +0200 Subject: [PATCH] ConfigMenu: Block reading input from other threads while the config menu is opened --- source/globals.cpp | 4 +++- source/globals.h | 2 ++ source/patcher/hooks_patcher_static.cpp | 7 +++++++ source/utils/config/ConfigUtils.cpp | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/globals.cpp b/source/globals.cpp index c14ec4c..afaea61 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -12,4 +12,6 @@ std::mutex gLoadedDataMutex; std::map gUsedRPLs; std::vector gAllocatedAddresses; -bool gNotificationModuleLoaded = false; \ No newline at end of file +bool gNotificationModuleLoaded = false; + +OSThread *gOnlyAcceptFromThread = nullptr; \ No newline at end of file diff --git a/source/globals.h b/source/globals.h index e674816..8dc2671 100644 --- a/source/globals.h +++ b/source/globals.h @@ -26,3 +26,5 @@ extern std::map gUsedRPLs; extern std::vector gAllocatedAddresses; extern bool gNotificationModuleLoaded; + +extern OSThread *gOnlyAcceptFromThread; \ No newline at end of file diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index d3243d9..3291fd7 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -69,11 +69,18 @@ DECL_FUNCTION(void, OSReleaseForeground) { } DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buffer_size, int32_t *error) { + if (configMenuOpened) { + // Ignore reading vpad input only from other threads if the config menu is opened + if (OSGetCurrentThread() != gOnlyAcceptFromThread) { + return 0; + } + } int32_t result = real_VPADRead(chan, buffer, buffer_size, error); if (result > 0 && ((buffer[0].hold & 0xFFFFF) == (VPAD_BUTTON_L | VPAD_BUTTON_DOWN | VPAD_BUTTON_MINUS)) && vpadPressCooldown == 0 && !configMenuOpened) { wantsToOpenConfigMenu = true; vpadPressCooldown = 0x3C; + return 0; } if (vpadPressCooldown > 0) { diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index 5b5dafe..f7e4616 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -136,6 +136,8 @@ void ConfigUtils::displayMenu() { auto startTime = OSGetTime(); bool skipFirstInput = true; + + gOnlyAcceptFromThread = OSGetCurrentThread(); while (true) { baseInput.reset(); if (vpadInput.update(1280, 720)) { @@ -184,6 +186,7 @@ void ConfigUtils::displayMenu() { OSSleepTicks(OSMicrosecondsToTicks(16000 - diffTime)); } } + gOnlyAcceptFromThread = nullptr; for (const auto &plugin : gLoadedPlugins) { const auto configData = plugin.getConfigData();