Close config menu if "release foreground" message is detected

This commit is contained in:
Maschell 2024-05-03 15:08:24 +02:00
parent f1a33df12d
commit be24d2c67a
4 changed files with 25 additions and 3 deletions

View File

@ -14,4 +14,6 @@ std::vector<void *> gAllocatedAddresses;
bool gNotificationModuleLoaded = false; bool gNotificationModuleLoaded = false;
OSThread *gOnlyAcceptFromThread = nullptr; OSThread *gOnlyAcceptFromThread = nullptr;
bool gConfigMenuShouldClose = false;

View File

@ -27,4 +27,6 @@ extern std::vector<void *> gAllocatedAddresses;
extern bool gNotificationModuleLoaded; extern bool gNotificationModuleLoaded;
extern OSThread *gOnlyAcceptFromThread; extern OSThread *gOnlyAcceptFromThread;
extern bool gConfigMenuShouldClose;

View File

@ -44,6 +44,18 @@ DECL_FUNCTION(void, GX2SetDRCBuffer, void *buffer, uint32_t buffer_size, uint32_
static uint32_t lastData0 = 0; 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) { DECL_FUNCTION(uint32_t, OSReceiveMessage, OSMessageQueue *queue, OSMessage *message, uint32_t flags) {
uint32_t res = real_OSReceiveMessage(queue, message, flags); uint32_t res = real_OSReceiveMessage(queue, message, flags);
if (queue == OSGetSystemMessageQueue()) { 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(GX2SwapScanBuffers, LIBRARY_GX2, GX2SwapScanBuffers),
REPLACE_FUNCTION(GX2SetTVBuffer, LIBRARY_GX2, GX2SetTVBuffer), REPLACE_FUNCTION(GX2SetTVBuffer, LIBRARY_GX2, GX2SetTVBuffer),
REPLACE_FUNCTION(GX2SetDRCBuffer, LIBRARY_GX2, GX2SetDRCBuffer), REPLACE_FUNCTION(GX2SetDRCBuffer, LIBRARY_GX2, GX2SetDRCBuffer),
REPLACE_FUNCTION(OSSendMessage, LIBRARY_COREINIT, OSSendMessage),
REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage), REPLACE_FUNCTION(OSReceiveMessage, LIBRARY_COREINIT, OSReceiveMessage),
REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground), REPLACE_FUNCTION(OSReleaseForeground, LIBRARY_COREINIT, OSReleaseForeground),
REPLACE_FUNCTION(VPADRead, LIBRARY_VPAD, VPADRead), REPLACE_FUNCTION(VPADRead, LIBRARY_VPAD, VPADRead),

View File

@ -139,6 +139,10 @@ void ConfigUtils::displayMenu() {
gOnlyAcceptFromThread = OSGetCurrentThread(); gOnlyAcceptFromThread = OSGetCurrentThread();
while (true) { while (true) {
if (gConfigMenuShouldClose) {
gConfigMenuShouldClose = false;
break;
}
baseInput.reset(); baseInput.reset();
if (vpadInput.update(1280, 720)) { if (vpadInput.update(1280, 720)) {
baseInput.combine(vpadInput); baseInput.combine(vpadInput);
@ -186,7 +190,6 @@ void ConfigUtils::displayMenu() {
OSSleepTicks(OSMicrosecondsToTicks(16000 - diffTime)); OSSleepTicks(OSMicrosecondsToTicks(16000 - diffTime));
} }
} }
gOnlyAcceptFromThread = nullptr;
for (const auto &plugin : gLoadedPlugins) { for (const auto &plugin : gLoadedPlugins) {
const auto configData = plugin.getConfigData(); const auto configData = plugin.getConfigData();
@ -205,6 +208,7 @@ void ConfigUtils::displayMenu() {
#define __SetDCPitchReg ((void (*)(uint32_t, uint32_t))(0x101C400 + 0x1e714)) #define __SetDCPitchReg ((void (*)(uint32_t, uint32_t))(0x101C400 + 0x1e714))
void ConfigUtils::openConfigMenu() { void ConfigUtils::openConfigMenu() {
gOnlyAcceptFromThread = OSGetCurrentThread();
bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled(); bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled();
OSScreenInit(); OSScreenInit();
@ -302,6 +306,7 @@ error_exit:
if (!skipScreen1Free && screenbuffer1) { if (!skipScreen1Free && screenbuffer1) {
MEMFreeToMappedMemory(screenbuffer1); MEMFreeToMappedMemory(screenbuffer1);
} }
gOnlyAcceptFromThread = nullptr;
} }
void ConfigUtils::renderBasicScreen(std::string_view text) { void ConfigUtils::renderBasicScreen(std::string_view text) {