WiiFlow_Lite/source/main.cpp

137 lines
3.3 KiB
C++
Raw Normal View History

2012-01-21 21:57:41 +01:00
#include <ogc/system.h>
#include <unistd.h>
#include "defines.h"
#include "svnrev.h"
2012-01-21 21:57:41 +01:00
#include "channel/nand.hpp"
#include "devicemounter/DeviceHandler.hpp"
#include "gecko/gecko.h"
#include "gecko/wifi_gecko.h"
#include "gui/video.hpp"
#include "gui/text.hpp"
#include "homebrew/homebrew.h"
#include "loader/external_booter.hpp"
#include "loader/wdvd.h"
#include "loader/alt_ios.h"
#include "loader/sys.h"
#include "loader/wbfs.h"
#include "loader/cios.h"
#include "loader/nk.h"
#include "menu/menu.hpp"
#include "memory/memory.h"
2012-01-21 21:57:41 +01:00
CMenu *mainMenu;
bool useMainIOS = false;
2012-01-21 21:57:41 +01:00
int main(int argc, char **argv)
{
__exception_setreload(5);
InitGecko();
2012-01-21 21:57:41 +01:00
// Init video
2012-01-21 21:57:41 +01:00
CVideo vid;
vid.init();
Nand::Instance()->Init_ISFS();
MEM_init(); //Inits both mem1lo and mem2
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);
2012-01-21 21:57:41 +01:00
char *gameid = NULL;
bool Emulator_boot = false;
bool iosOK = false;
2012-01-21 21:57:41 +01:00
for(u8 i = 0; i < argc; i++)
2012-01-21 21:57:41 +01:00
{
if(argv[i] != NULL && strcasestr(argv[i], "ios=") != NULL && strlen(argv[i]) > 4)
2012-01-21 21:57:41 +01:00
{
while(argv[i][0] && !isdigit(argv[i][0]))
argv[i]++;
2012-01-21 21:57:41 +01:00
if (atoi(argv[i]) < 254 && atoi(argv[i]) > 0)
mainIOS = atoi(argv[i]);
}
else if(strlen(argv[i]) == 6)
2012-01-21 21:57:41 +01:00
{
gameid = argv[i];
for(u8 i = 0; i < 5; i++)
{
if(!isalnum(gameid[i]))
2012-01-21 21:57:41 +01:00
gameid = NULL;
}
2012-01-21 21:57:41 +01:00
}
else if(argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL)
Emulator_boot = true;
2012-01-21 21:57:41 +01:00
}
#ifndef DOLPHIN
2012-01-21 21:57:41 +01:00
// Load Custom IOS
if(neek2o())
{
iosOK = true;
memset(&CurrentIOS, 0, sizeof(IOS_Info));
CurrentIOS.Version = 254;
CurrentIOS.Type = IOS_TYPE_NEEK2O;
CurrentIOS.Base = 254;
CurrentIOS.Revision = 999;
DCFlushRange(&CurrentIOS, sizeof(IOS_Info));
DeviceHandler::Instance()->SetModes();
}
else if(AHBRPOT_Patched() && IOS_GetVersion() == 58)
{
gprintf("AHBPROT patched out, use IOS58\n");
iosOK = loadIOS(58, false);
}
else
{
gprintf("Loading cIOS: %d\n", mainIOS);
iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type);
}
#else
iosOK = true;
#endif
2012-01-21 21:57:41 +01:00
// Init
Sys_Init();
Sys_ExitTo(EXIT_TO_HBC);
DeviceHandler::Instance()->MountAll();
vid.waitMessage(0.15f);
2012-01-21 21:57:41 +01:00
mainMenu = new CMenu(vid);
Open_Inputs();
mainMenu->init();
if(CurrentIOS.Version != mainIOS && !neek2o())
{
if(useMainIOS || !DeviceHandler::Instance()->UsablePartitionMounted())
{
iosOK = loadIOS(mainIOS, true) && CustomIOS(CurrentIOS.Type);
Open_Inputs();
mainMenu->init();
}
}
if(CurrentIOS.Version == mainIOS)
useMainIOS = true; //Needed for later checks
if(!iosOK)
mainMenu->terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games.");
else if(!DeviceHandler::Instance()->UsablePartitionMounted())
mainMenu->terror("errboot2", L"Could not find a device to save configuration files on!");
else if(WDVD_Init() < 0)
mainMenu->terror("errboot3", L"Could not initialize the DIP module!");
else
{
if(Emulator_boot)
mainMenu->m_Emulator_boot = true;
if(gameid != NULL && strlen(gameid) == 6)
mainMenu->directlaunch(gameid);
else
mainMenu->main();
}
//Exit WiiFlow, no game booted...
mainMenu->cleanup();
ShutdownBeforeExit();
2012-01-21 21:57:41 +01:00
Sys_Exit();
exit(1);
2012-01-21 21:57:41 +01:00
return 0;
}