From be24d2c67ad19671c7d04224a5e8f896422291bc Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 3 May 2024 15:08:24 +0200 Subject: [PATCH] Close config menu if "release foreground" message is detected --- source/globals.cpp | 4 +++- source/globals.h | 4 +++- source/patcher/hooks_patcher_static.cpp | 13 +++++++++++++ source/utils/config/ConfigUtils.cpp | 7 ++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/source/globals.cpp b/source/globals.cpp index afaea61..7c16568 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -14,4 +14,6 @@ std::vector gAllocatedAddresses; bool gNotificationModuleLoaded = false; -OSThread *gOnlyAcceptFromThread = nullptr; \ No newline at end of file +OSThread *gOnlyAcceptFromThread = nullptr; + +bool gConfigMenuShouldClose = false; \ No newline at end of file diff --git a/source/globals.h b/source/globals.h index 8dc2671..ebf4da9 100644 --- a/source/globals.h +++ b/source/globals.h @@ -27,4 +27,6 @@ extern std::vector gAllocatedAddresses; extern bool gNotificationModuleLoaded; -extern OSThread *gOnlyAcceptFromThread; \ No newline at end of file +extern OSThread *gOnlyAcceptFromThread; + +extern bool gConfigMenuShouldClose; \ No newline at end of file diff --git a/source/patcher/hooks_patcher_static.cpp b/source/patcher/hooks_patcher_static.cpp index b3ace15..5e9a84a 100644 --- a/source/patcher/hooks_patcher_static.cpp +++ b/source/patcher/hooks_patcher_static.cpp @@ -44,6 +44,18 @@ DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_ static uint32_t lastData0 = 0; + +DECL_FUNCTION(BOOL, OSSendMessage, OSMessageQueue *queue, OSMessage *message, OSMessageFlags flags) { + if (sConfigMenuOpened && queue == OSGetSystemMessageQueue()) { + if (message != nullptr) { + if (message->args[0] == 0xfacebacc) { // Release foreground + gConfigMenuShouldClose = true; + } + } + } + return real_OSSendMessage(queue, message, flags); +} + DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) { uint32_t res = real_OSReceiveMessage(queue, message, flags); if (queue == OSGetSystemMessageQueue()) { @@ -197,6 +209,7 @@ function_replacement_data_t method_hooks_static[] __attribute__((section(".data" REPLACE_FUNCTION(GX2SwapScanBuffers, LIBRARY_GX2, GX2SwapScanBuffers), REPLACE_FUNCTION(GX2SetTVBuffer, LIBRARY_GX2, GX2SetTVBuffer), REPLACE_FUNCTION(GX2SetDRCBuffer, LIBRARY_GX2, GX2SetDRCBuffer), + REPLACE_FUNCTION(OSSendMessage, LIBRARY_COREINIT, OSSendMessage), REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage), REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground), REPLACE_FUNCTION(VPADRead, LIBRARY_VPAD, VPADRead), diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index f7e4616..ad2c057 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -139,6 +139,10 @@ void ConfigUtils::displayMenu() { gOnlyAcceptFromThread = OSGetCurrentThread(); while (true) { + if (gConfigMenuShouldClose) { + gConfigMenuShouldClose = false; + break; + } baseInput.reset(); if (vpadInput.update(1280, 720)) { baseInput.combine(vpadInput); @@ -186,7 +190,6 @@ void ConfigUtils::displayMenu() { OSSleepTicks(OSMicrosecondsToTicks(16000 - diffTime)); } } - gOnlyAcceptFromThread = nullptr; for (const auto &plugin : gLoadedPlugins) { const auto configData = plugin.getConfigData(); @@ -205,6 +208,7 @@ void ConfigUtils::displayMenu() { #define __SetDCPitchReg ((void (*)(uint32_t, uint32_t))(0x101C400 + 0x1e714)) void ConfigUtils::openConfigMenu() { + gOnlyAcceptFromThread = OSGetCurrentThread(); bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled(); OSScreenInit(); @@ -302,6 +306,7 @@ error_exit: if (!skipScreen1Free && screenbuffer1) { MEMFreeToMappedMemory(screenbuffer1); } + gOnlyAcceptFromThread = nullptr; } void ConfigUtils::renderBasicScreen(std::string_view text) {