3333#include <coreinit/dynload.h>
3434#include <coreinit/ios.h>
3535#include <coreinit/foreground.h>
36+ #include <coreinit/memory.h>
3637#include <coreinit/time.h>
3738#include <coreinit/title.h>
3839#include <proc_ui/procui.h>
40+ #include <proc_ui/memory.h>
3941#include <padscore/wpad.h>
4042#include <padscore/kpad.h>
4143#include <sysapp/launch.h>
@@ -228,6 +230,25 @@ static int frontend_wiiu_parse_drive_list(void *data, bool load_content)
228230 return 0 ;
229231}
230232
233+ static bool check_proc () {
234+ switch (ProcUIProcessMessages (true)) {
235+ case PROCUI_STATUS_EXITING : {
236+ return false;
237+ }
238+ case PROCUI_STATUS_RELEASE_FOREGROUND : {
239+ ProcUIDrawDoneRelease ();
240+ break ;
241+ }
242+ case PROCUI_STATUS_IN_FOREGROUND : {
243+ break ;
244+ }
245+ case PROCUI_STATUS_IN_BACKGROUND :
246+ default :
247+ break ;
248+ }
249+ return true;
250+ }
251+
231252static void frontend_wiiu_exec (const char * path , bool should_load_content )
232253{
233254 /* goal: make one big buffer with all the argv's, seperated by NUL. we can
@@ -317,6 +338,13 @@ static void frontend_wiiu_exec(const char *path, bool should_load_content)
317338
318339 in_exec = true;
319340
341+ if (!should_load_content ) {
342+ SYSLaunchMenu ();
343+ }
344+ while (check_proc ()) {
345+
346+ }
347+
320348 cleanup :
321349 free (argv_buf );
322350 argv_buf = NULL ;
@@ -451,7 +479,7 @@ int main(int argc, char **argv)
451479static void main_setup (void )
452480{
453481 memoryInitialize ();
454- init_os_exceptions ();
482+ // init_os_exceptions();
455483 init_logging ();
456484 init_filesystems ();
457485 init_pad_libraries ();
@@ -464,35 +492,16 @@ static void main_teardown(void)
464492 deinit_pad_libraries ();
465493 deinit_filesystems ();
466494 deinit_logging ();
467- deinit_os_exceptions ();
495+ // deinit_os_exceptions();
468496 memoryRelease ();
469497}
470498
471- // https://github.com/devkitPro/wut/blob/7d9fa9e416bffbcd747f1a8e5701fd6342f9bc3d/libraries/libwhb/src/proc.c
472-
473- #define HBL_TITLE_ID (0x0005000013374842)
474- #define MII_MAKER_JPN_TITLE_ID (0x000500101004A000)
475- #define MII_MAKER_USA_TITLE_ID (0x000500101004A100)
476- #define MII_MAKER_EUR_TITLE_ID (0x000500101004A200)
477-
478- static bool in_hbl = false;
479499static bool in_aroma = false;
500+ static void * procui_mem1Storage = NULL ;
501+ static void * procui_bucketStorage = NULL ;
480502
481503static void proc_setup (void )
482504{
483- uint64_t titleID = OSGetTitleID ();
484-
485- // Homebrew Launcher does not like the standard ProcUI application loop, sad!
486- if (titleID == HBL_TITLE_ID ||
487- titleID == MII_MAKER_JPN_TITLE_ID ||
488- titleID == MII_MAKER_USA_TITLE_ID ||
489- titleID == MII_MAKER_EUR_TITLE_ID )
490- {
491- // Important: OSEnableHomeButtonMenu must come before ProcUIInitEx.
492- OSEnableHomeButtonMenu (FALSE);
493- in_hbl = TRUE;
494- }
495-
496505 /* Detect Aroma explicitly (it's possible to run under H&S while using Tiramisu) */
497506 OSDynLoad_Module rpxModule ;
498507 if (OSDynLoad_Acquire ("homebrew_rpx_loader" , & rpxModule ) == OS_DYNLOAD_OK )
@@ -502,33 +511,33 @@ static void proc_setup(void)
502511 }
503512
504513 ProcUIInit (& proc_save_callback );
514+
515+ uint32_t addr = 0 ;
516+ uint32_t size = 0 ;
517+ if (OSGetMemBound (OS_MEM1 , & addr , & size ) == 0 ) {
518+ procui_mem1Storage = malloc (size );
519+ if (procui_mem1Storage ) {
520+ ProcUISetMEM1Storage (procui_mem1Storage , size );
521+ }
522+ }
523+ if (OSGetForegroundBucketFreeArea (& addr , & size )) {
524+ procui_bucketStorage = malloc (size );
525+ if (procui_bucketStorage ) {
526+ ProcUISetBucketStorage (procui_bucketStorage , size );
527+ }
528+ }
505529}
506530
507531static void proc_exit (void )
508532{
509- /* If we're doing a normal exit while running under HBL, we must SYSRelaunchTitle.
510- * If we're in an exec (i.e. launching mocha homebrew wrapper) we must *not* do that. yay! */
511- if (in_hbl && !in_exec )
512- SYSRelaunchTitle (0 , NULL );
513-
514- /* Similar deal for Aroma, but exit to menu. */
515- if (!in_hbl && !in_exec )
516- SYSLaunchMenu ();
517-
518- /* Now just tell the OS that we really are ok to exit */
519- if (!ProcUIInShutdown ())
520- {
521- for (;;)
522- {
523- ProcUIStatus status ;
524- status = ProcUIProcessMessages (TRUE);
525- if (status == PROCUI_STATUS_EXITING )
526- break ;
527- else if (status == PROCUI_STATUS_RELEASE_FOREGROUND )
528- ProcUIDrawDoneRelease ();
529- }
533+ if (procui_mem1Storage ) {
534+ free (procui_mem1Storage );
535+ procui_mem1Storage = NULL ;
536+ }
537+ if (procui_bucketStorage ) {
538+ free (procui_bucketStorage );
539+ procui_bucketStorage = NULL ;
530540 }
531-
532541 ProcUIShutdown ();
533542}
534543
@@ -600,7 +609,10 @@ static void main_loop(void)
600609 OSTime start_time ;
601610 int status ;
602611
603- for (;;)
612+ bool home_menu_allowed = true;
613+ OSEnableHomeButtonMenu (TRUE);
614+
615+ while (check_proc ())
604616 {
605617 if (video_driver_get_ptr ())
606618 {
@@ -612,8 +624,22 @@ static void main_loop(void)
612624
613625 status = runloop_iterate ();
614626
615- if (status == -1 )
627+ // TODO: make this less ugly...
628+ if ((runloop_get_flags () & RUNLOOP_FLAG_CORE_RUNNING )) {
629+ if (home_menu_allowed ) {
630+ OSEnableHomeButtonMenu (FALSE);
631+ home_menu_allowed = false;
632+ }
633+ } else {
634+ if (!home_menu_allowed ) {
635+ OSEnableHomeButtonMenu (TRUE);
636+ home_menu_allowed = true;
637+ }
638+ }
639+
640+ if (status == -1 ) {
616641 break ;
642+ }
617643 }
618644}
619645#endif
0 commit comments