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

@ -15,3 +15,5 @@ std::vector<void *> gAllocatedAddresses;
bool gNotificationModuleLoaded = false;
OSThread *gOnlyAcceptFromThread = nullptr;
bool gConfigMenuShouldClose = false;

View File

@ -28,3 +28,5 @@ extern std::vector<void *> gAllocatedAddresses;
extern bool gNotificationModuleLoaded;
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;
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),

View File

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