Skip to content

Commit

Permalink
Close config menu if "release foreground" message is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed May 3, 2024
1 parent f1a33df commit be24d2c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion source/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ std::vector<void *> gAllocatedAddresses;

bool gNotificationModuleLoaded = false;

OSThread *gOnlyAcceptFromThread = nullptr;
OSThread *gOnlyAcceptFromThread = nullptr;

bool gConfigMenuShouldClose = false;
4 changes: 3 additions & 1 deletion source/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ extern std::vector<void *> gAllocatedAddresses;

extern bool gNotificationModuleLoaded;

extern OSThread *gOnlyAcceptFromThread;
extern OSThread *gOnlyAcceptFromThread;

extern bool gConfigMenuShouldClose;
13 changes: 13 additions & 0 deletions source/patcher/hooks_patcher_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 6 additions & 1 deletion source/utils/config/ConfigUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -186,7 +190,6 @@ void ConfigUtils::displayMenu() {
OSSleepTicks(OSMicrosecondsToTicks(16000 - diffTime));
}
}
gOnlyAcceptFromThread = nullptr;

for (const auto &plugin : gLoadedPlugins) {
const auto configData = plugin.getConfigData();
Expand All @@ -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();
Expand Down Expand Up @@ -302,6 +306,7 @@ void ConfigUtils::openConfigMenu() {
if (!skipScreen1Free && screenbuffer1) {
MEMFreeToMappedMemory(screenbuffer1);
}
gOnlyAcceptFromThread = nullptr;
}

void ConfigUtils::renderBasicScreen(std::string_view text) {
Expand Down

0 comments on commit be24d2c

Please # to comment.