Skip to content

Commit

Permalink
Fix for aroma
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Sep 7, 2022
1 parent 5805b89 commit 16dcdcf
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 10 deletions.
10 changes: 10 additions & 0 deletions include/state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <coreinit/core.h>
#include <coreinit/dynload.h>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>

bool AppRunning();
void initState();
void shutdownState();
13 changes: 6 additions & 7 deletions src/log_freetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ static uint32_t FreetypeProcCallbackAcquired(void *context) {

MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1);
if (frameBufferTVSize) {
frameBufferTVFrontPtr = (uint8_t*)MEMAllocFromFrmHeapEx(heap, frameBufferTVSize, 0x100);
frameBufferTVBackPtr = (uint8_t*)frameBufferTVFrontPtr + (1*(1280*720*4));
frameBufferTVFrontPtr = (uint8_t *) MEMAllocFromFrmHeapEx(heap, frameBufferTVSize, 0x100);
frameBufferTVBackPtr = (uint8_t *) frameBufferTVFrontPtr + (1 * (1280 * 720 * 4));
}

if (frameBufferDRCSize) {
frameBufferDRCFrontPtr = (uint8_t*)MEMAllocFromFrmHeapEx(heap, frameBufferDRCSize, 0x100);
frameBufferDRCBackPtr = (uint8_t*)frameBufferDRCFrontPtr + (1*(896*480*4));
frameBufferDRCFrontPtr = (uint8_t *) MEMAllocFromFrmHeapEx(heap, frameBufferDRCSize, 0x100);
frameBufferDRCBackPtr = (uint8_t *) frameBufferDRCFrontPtr + (1 * (896 * 480 * 4));
}

OSScreenSetBufferEx(SCREEN_TV, frameBufferTVFrontPtr);
Expand All @@ -65,8 +65,8 @@ static uint32_t FreetypeProcCallbackAcquired(void *context) {
OSScreenPutPixelEx(SCREEN_DRC, 0, 0, 0xABCDEFFF);
DCFlushRange(frameBufferTVFrontPtr, frameBufferTVSize);
DCFlushRange(frameBufferDRCFrontPtr, frameBufferDRCSize);
currTVFrameBuffer = (((uint32_t*)frameBufferTVFrontPtr)[0] == 0xABCDEFFF) ? frameBufferTVFrontPtr : frameBufferTVBackPtr;
currDRCFrameBuffer = (((uint32_t*)frameBufferTVFrontPtr)[0] == 0xABCDEFFF) ? frameBufferDRCFrontPtr : frameBufferDRCBackPtr;
currTVFrameBuffer = (((uint32_t *) frameBufferTVFrontPtr)[0] == 0xABCDEFFF) ? frameBufferTVFrontPtr : frameBufferTVBackPtr;
currDRCFrameBuffer = (((uint32_t *) frameBufferTVFrontPtr)[0] == 0xABCDEFFF) ? frameBufferDRCFrontPtr : frameBufferDRCBackPtr;
return 0;
}

Expand Down Expand Up @@ -148,7 +148,6 @@ void WHBLogFreetypeFree() {
FT_Done_FreeType(fontLibrary);

if (freetypeHasForeground) {
OSScreenShutdown();
FreetypeProcCallbackReleased(NULL);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "language.h"
#include "log_freetype.h"
#include "savemng.h"
#include "state.h"
#include "string.hpp"

#define VERSION_MAJOR 1
Expand Down Expand Up @@ -415,6 +416,7 @@ int main() {
KPADInit();
WPADEnableURCC(1);
loadWiiUTitles(0);
initState();

int res = romfsInit();
if (res) {
Expand Down Expand Up @@ -447,7 +449,7 @@ int main() {

bool redraw = true;
int entrycount = 0;
while (WHBProcIsRunning()) {
while (AppRunning()) {
Title *titles = mode != 0 ? wiititles : wiiutitles;
int count = mode != 0 ? titlesvwii : titleswiiu;

Expand Down Expand Up @@ -1051,9 +1053,9 @@ int main() {
gettextCleanUp();
romfsExit();

OSScreenShutdown();
WHBLogFreetypeFree();
shutdownState();
WHBProcShutdown();

ProcUIShutdown();
return 0;
}
72 changes: 72 additions & 0 deletions src/state.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "state.h"

typedef enum {
APP_STATE_STOPPING = 0,
APP_STATE_STOPPED,
APP_STATE_RUNNING,
APP_STATE_BACKGROUND,
APP_STATE_RETURNING,
} APP_STATE;

static bool aroma;
static volatile APP_STATE app = APP_STATE_RUNNING;

bool isAroma() {
OSDynLoad_Module mod;
aroma = OSDynLoad_Acquire("homebrew_kernel", &mod) == OS_DYNLOAD_OK;
if (aroma)
OSDynLoad_Release(mod);
return aroma;
}

static uint32_t homeButtonCallback(void *dummy) {
app = APP_STATE_STOPPING;
return 0;
}

bool AppRunning() {
if (OSIsMainCore() && app != APP_STATE_STOPPED) {
switch (ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING:
// Being closed, prepare to exit
app = APP_STATE_STOPPED;
break;
case PROCUI_STATUS_RELEASE_FOREGROUND:
// Free up MEM1 to next foreground app, deinit screen, etc.
ProcUIDrawDoneRelease();
if (app != APP_STATE_STOPPING)
app = APP_STATE_BACKGROUND;
break;
case PROCUI_STATUS_IN_FOREGROUND:
// Executed while app is in foreground
if (app == APP_STATE_STOPPING)
break;
if (app == APP_STATE_BACKGROUND) {
app = APP_STATE_RETURNING;
} else
app = APP_STATE_RUNNING;

break;
case PROCUI_STATUS_IN_BACKGROUND:
if (app != APP_STATE_STOPPING)
app = APP_STATE_BACKGROUND;
break;
}
}

return app;
}

void initState() {
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &homeButtonCallback, NULL, 100);
OSEnableHomeButtonMenu(false);
}

void shutdownState() {
if (isAroma()) {
SYSLaunchMenu();
while (app != APP_STATE_STOPPED) {
AppRunning();
}
}
}

0 comments on commit 16dcdcf

Please sign in to comment.