From c4ba7030d9ba70796edd48bf160022820e89a8e9 Mon Sep 17 00:00:00 2001 From: "Daniel K. O." Date: Fri, 14 Feb 2025 13:59:06 -0300 Subject: [PATCH] Block on `VPADRead()` while the plugin menu is open in Hyrule Warriors. (#109) * Block on `VPADRead()` while the plugin menu is open. * Trying to please clang-format. * Block `VPADRead()` only for Hyrule Warriors. --------- Co-authored-by: Daniel K. O. (dkosmari) --- source/patcher/hooks_patcher_static.cpp | 13 +++++++++++++ source/utils/config/ConfigUtils.cpp | 2 ++ 2 files changed, 15 insertions(+) diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index 7cce514..6213b01 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -8,8 +8,11 @@ #include "plugin/SectionInfo.h" #include "utils/config/ConfigUtils.h" +#include #include #include +#include +#include #include #include @@ -21,9 +24,11 @@ DECL_FUNCTION(void, GX2SwapScanBuffers, void) { if (sWantsToOpenConfigMenu && !gConfigMenuOpened) { gConfigMenuOpened = true; + OSMemoryBarrier(); ConfigUtils::openConfigMenu(); gConfigMenuOpened = false; sWantsToOpenConfigMenu = false; + OSMemoryBarrier(); } } @@ -89,6 +94,14 @@ DECL_FUNCTION(int32_t, VPADRead, int32_t chan, VPADStatus *buffer, uint32_t buff if (gConfigMenuOpened) { // Ignore reading vpad input only from other threads if the config menu is opened if (OSGetCurrentThread() != gOnlyAcceptFromThread) { + // Quick fix for Hyrule Warriors: block VPADRead() in non-rendering threads. + switch (OSGetTitleID()) { + case 0x00050000'1017CD00: // Hyrule Warriors JPN + case 0x00050000'1017D800: // Hyrule Warriors USA + case 0x00050000'1017D900: // Hyrule Warriors EUR + while (gConfigMenuOpened) + OSSleepTicks(OSMillisecondsToTicks(10)); + } return 0; } } diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index c644203..7e764fc 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -166,6 +167,7 @@ void ConfigUtils::displayMenu() { gOnlyAcceptFromThread = OSGetCurrentThread(); ConfigSubState subStateReturnValue = SUB_STATE_ERROR; + OSMemoryBarrier(); while (true) { startTime = OSGetTime(); if (gConfigMenuShouldClose) {