diff --git a/source/fceugx.cpp b/source/fceugx.cpp index 1dfc429..939bffa 100644 --- a/source/fceugx.cpp +++ b/source/fceugx.cpp @@ -98,26 +98,6 @@ static void ExitCleanup() void (*PSOReload) () = (void (*)()) 0x80001800; #endif -void ExitToWiiflow() -{ - ShutoffRumble(); - SavePrefs(SILENT); - if (romLoaded && !ConfigRequested && GCSettings.AutoSave == 1) - SaveRAMAuto(SILENT); - ExitCleanup(); - - if( !!*(u32*)0x80001800 ) - { - // Were we launched via HBC? (or via wiiflows stub replacement? :P) - exit(1); - } - else - { - // Wii channel support - SYS_ResetSystem( SYS_RETURNTOMENU, 0, 0 ); - } -} - void ExitApp() { #ifdef HW_RVL @@ -131,49 +111,63 @@ void ExitApp() ExitCleanup(); - if(ShutdownRequested) - SYS_ResetSystem(SYS_POWEROFF, 0, 0); - - #ifdef HW_RVL - if(GCSettings.ExitAction == 0) // Auto - { - char * sig = (char *)0x80001804; - if( - sig[0] == 'S' && - sig[1] == 'T' && - sig[2] == 'U' && - sig[3] == 'B' && - sig[4] == 'H' && - sig[5] == 'A' && - sig[6] == 'X' && - sig[7] == 'X') - GCSettings.ExitAction = 3; // Exit to HBC + if(ShutdownRequested) { + SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0); + } + else if(GCSettings.AutoloadGame) { + if( !!*(u32*)0x80001800 ) + { + // Were we launched via HBC? (or via WiiFlow's stub replacement) + exit(1); + } else - GCSettings.ExitAction = 1; // HBC not found + { + // Wii channel support + SYS_ResetSystem( SYS_RETURNTOMENU, 0, 0 ); + } } - #endif + else { + #ifdef HW_RVL + if(GCSettings.ExitAction == 0) // Auto + { + char * sig = (char *)0x80001804; + if( + sig[0] == 'S' && + sig[1] == 'T' && + sig[2] == 'U' && + sig[3] == 'B' && + sig[4] == 'H' && + sig[5] == 'A' && + sig[6] == 'X' && + sig[7] == 'X') + GCSettings.ExitAction = 3; // Exit to HBC + else + GCSettings.ExitAction = 1; // HBC not found + } + #endif - if(GCSettings.ExitAction == 1) // Exit to Menu - { - #ifdef HW_RVL - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - #else - #define SOFTRESET_ADR ((volatile u32*)0xCC003024) - *SOFTRESET_ADR = 0x00000000; - #endif - } - else if(GCSettings.ExitAction == 2) // Shutdown Wii - { - SYS_ResetSystem(SYS_POWEROFF, 0, 0); - } - else // Exit to Loader - { - #ifdef HW_RVL - exit(0); - #else - if (psoid[0] == PSOSDLOADID) - PSOReload(); - #endif + if(GCSettings.ExitAction == 1) // Exit to Menu + { + #ifdef HW_RVL + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + #else + #define SOFTRESET_ADR ((volatile u32*)0xCC003024) + *SOFTRESET_ADR = 0x00000000; + #endif + } + else if(GCSettings.ExitAction == 2) // Shutdown Wii + { + SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0); + } + else // Exit to Loader + { + #ifdef HW_RVL + exit(0); + #else + if (psoid[0] == PSOSDLOADID) + PSOReload(); + #endif + } } } @@ -436,10 +430,8 @@ int main(int argc, char *argv[]) int currentTiming = 0; bool autoboot = false; - if(argc > 2 && argv[1] != NULL && argv[2] != NULL) - { - autoboot = true; - ResetBrowser(); + + if(argc > 2 && argv[1] != NULL && argv[2] != NULL) { LoadPrefs(); if(strcasestr(argv[1], "sd:/") != NULL) { @@ -452,69 +444,25 @@ int main(int argc, char *argv[]) GCSettings.LoadMethod = DEVICE_USB; } SavePrefs(SILENT); - selectLoadedFile = 1; - std::string dir(argv[1]); - dir.assign(&dir[dir.find_last_of(":") + 2]); - char arg_filename[1024]; - strncpy(arg_filename, argv[2], sizeof(arg_filename)); - strncpy(GCSettings.LoadFolder, dir.c_str(), sizeof(GCSettings.LoadFolder)); - OpenGameList(); - strncpy(GCSettings.Exit_Dol_File, argc > 3 && argv[3] != NULL ? argv[3] : "", sizeof(GCSettings.Exit_Dol_File)); - if(argc > 5 && argv[4] != NULL && argv[5] != NULL) - { - sscanf(argv[4], "%08x", &GCSettings.Exit_Channel[0]); - sscanf(argv[5], "%08x", &GCSettings.Exit_Channel[1]); - } - else - { - GCSettings.Exit_Channel[0] = 0x00010008; - GCSettings.Exit_Channel[1] = 0x57494948; - } - if(argc > 6 && argv[6] != NULL) - strncpy(GCSettings.LoaderName, argv[6], sizeof(GCSettings.LoaderName)); - else - snprintf(GCSettings.LoaderName, sizeof(GCSettings.LoaderName), "WiiFlow"); - for(int i = 0; i < browser.numEntries; i++) - { - // Skip it - if (strcmp(browserList[i].filename, ".") == 0 || strcmp(browserList[i].filename, "..") == 0) - continue; - if(strcasestr(browserList[i].filename, arg_filename) != NULL) - { - browser.selIndex = i; - if(IsSz()) - { - BrowserLoadSz(); - browser.selIndex = 1; - } - break; - } - } - BrowserLoadFile(); + + GCSettings.AutoloadGame = AutoloadGame(argv[1], argv[2]); + autoboot = GCSettings.AutoloadGame; } while (1) // main loop { - // go back to checking if devices were inserted/removed - // since we're entering the menu - ResumeDeviceThread(); + if(!autoboot) { + // go back to checking if devices were inserted/removed + // since we're entering the menu + ResumeDeviceThread(); - SwitchAudioMode(1); + SwitchAudioMode(1); - if(!autoboot) - { if(!romLoaded) MainMenu(MENU_GAMESELECTION); else MainMenu(MENU_GAME); - - ConfigRequested = 0; - ScreenshotRequested = 0; } - else if(romLoaded && autoboot) - autoboot = false; - else - ExitApp(); if(currentTiming != GCSettings.timing) { @@ -523,6 +471,7 @@ int main(int argc, char *argv[]) } currentTiming = GCSettings.timing; + autoboot = false; ConfigRequested = 0; ScreenshotRequested = 0; SwitchAudioMode(0); diff --git a/source/fceugx.h b/source/fceugx.h index 23b721d..43d8506 100644 --- a/source/fceugx.h +++ b/source/fceugx.h @@ -89,11 +89,8 @@ struct SGCSettings char LastFileLoaded[MAXPATHLEN]; //Last file loaded filename char SaveFolder[MAXPATHLEN]; // Path to save files char CheatFolder[MAXPATHLEN]; // Path to cheat files - char ScreenshotsFolder[MAXPATHLEN]; //Path to screenshots files - - char Exit_Dol_File[MAXPATHLEN]; // Exit Path - char LoaderName[20]; // Menu Loader Name - u32 Exit_Channel[2]; // Exit Channel + char ScreenshotsFolder[MAXPATHLEN]; // Path to screenshot files + int AutoloadGame; char smbip[80]; char smbuser[20]; diff --git a/source/filebrowser.cpp b/source/filebrowser.cpp index 215cb71..0f202d1 100644 --- a/source/filebrowser.cpp +++ b/source/filebrowser.cpp @@ -34,6 +34,10 @@ #include "pocketnes/goombasav.h" #include "pocketnes/pocketnesrom.h" +extern "C" { +extern char* strcasestr(const char *, const char *); +} + BROWSERINFO browser; BROWSERENTRY * browserList = NULL; // list of files/folders in browser @@ -681,3 +685,32 @@ OpenGameList () BrowserChangeFolder(); return browser.numEntries; } + +bool AutoloadGame(char* filepath, char* filename) { + ResetBrowser(); + + selectLoadedFile = 1; + std::string dir(filepath); + dir.assign(&dir[dir.find_last_of(":") + 2]); + strncpy(GCSettings.LoadFolder, dir.c_str(), sizeof(GCSettings.LoadFolder)); + OpenGameList(); + + for(int i = 0; i < browser.numEntries; i++) { + // Skip it + if (strcmp(browserList[i].filename, ".") == 0 || strcmp(browserList[i].filename, "..") == 0) { + continue; + } + if(strcasestr(browserList[i].filename, filename) != NULL) { + browser.selIndex = i; + if(IsSz()) { + BrowserLoadSz(); + browser.selIndex = 1; + } + break; + } + } + if(BrowserLoadFile() > 0) { + return true; + } + return false; +} diff --git a/source/filebrowser.h b/source/filebrowser.h index 50abb2b..d017008 100644 --- a/source/filebrowser.h +++ b/source/filebrowser.h @@ -72,5 +72,6 @@ bool IsDeviceRoot(char * path); int BrowserLoadSz(); int BrowserChangeFolder(); int BrowserLoadFile(); +bool AutoloadGame(char* filepath, char* filename); #endif diff --git a/source/menu.cpp b/source/menu.cpp index e106fbe..ef5005e 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -1298,6 +1298,9 @@ static int MenuGame() gameSettingsBtn.SetEffectGrow(); GuiText mainmenuBtnTxt("Main Menu", 22, (GXColor){0, 0, 0, 255}); + if(GCSettings.AutoloadGame) { + mainmenuBtnTxt.SetText("Exit"); + } GuiImage mainmenuBtnImg(&btnOutline); GuiImage mainmenuBtnImgOver(&btnOutlineOver); GuiButton mainmenuBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); @@ -1495,14 +1498,19 @@ static int MenuGame() gameScreen = NULL; free(gameScreenPng); gameScreenPng = NULL; - gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){240, 225, 230, 255}); - gameScreenImg->ColorStripe(10); - mainWindow->Insert(gameScreenImg, 0); - ResumeGui(); - #ifndef NO_SOUND - bgMusic->Play(); // startup music - #endif - menu = MENU_GAMESELECTION; + if(GCSettings.AutoloadGame) { + ExitApp(); + } + else { + gameScreenImg = new GuiImage(screenwidth, screenheight, (GXColor){240, 225, 230, 255}); + gameScreenImg->ColorStripe(10); + mainWindow->Insert(gameScreenImg, 0); + ResumeGui(); + #ifndef NO_SOUND + bgMusic->Play(); // startup music + #endif + menu = MENU_GAMESELECTION; + } } } else if(closeBtn.GetState() == STATE_CLICKED) diff --git a/source/preferences.cpp b/source/preferences.cpp index d103384..a06cb53 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -416,6 +416,7 @@ DefaultSettings () GCSettings.yshift = 0; // vertical video shift GCSettings.WiimoteOrientation = 0; + GCSettings.AutoloadGame = 0; GCSettings.ExitAction = 0; // Auto GCSettings.MusicVolume = 20; GCSettings.SFXVolume = 40;