ConfigMenu: Block reading input from other threads while the config menu is opened

This commit is contained in:
Maschell 2024-05-03 13:00:18 +02:00
parent 340fdddf0b
commit a8fd0b64ac
4 changed files with 15 additions and 1 deletions

View File

@ -12,4 +12,6 @@ std::mutex gLoadedDataMutex;
std::map<std::string, OSDynLoad_Module> gUsedRPLs;
std::vector<void *> gAllocatedAddresses;
bool gNotificationModuleLoaded = false;
bool gNotificationModuleLoaded = false;
OSThread *gOnlyAcceptFromThread = nullptr;

View File

@ -26,3 +26,5 @@ extern std::map<std::string, OSDynLoad_Module> gUsedRPLs;
extern std::vector<void *> gAllocatedAddresses;
extern bool gNotificationModuleLoaded;
extern OSThread *gOnlyAcceptFromThread;

View File

@ -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) {

View File

@ -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();