WiiFlow_Lite/source/main.cpp

229 lines
6.7 KiB
C++
Raw Permalink Normal View History

2012-01-21 21:57:41 +01:00
#include <ogc/system.h>
#include <unistd.h>
#include <sys/stat.h>
#include "defines.h"
#include "booter/external_booter.hpp"
#include "channel/nand.hpp"
#include "channel/nand_save.hpp"
#include "devicemounter/DeviceHandler.hpp"
#include "gecko/gecko.hpp"
#include "gui/video.hpp"
#include "gui/text.hpp"
#include "homebrew/homebrew.h"
#include "loader/alt_ios_gen.h"
#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"
bool isWiiVC = false;
bool useMainIOS = false;
volatile bool NANDemuView = false;
volatile bool networkInit = false;
/* quick check if we will be using a USB device. */
/* if not then we can skip the 20 second cycle trying to connect a USB device. */
/* this is nice for SD only users */
bool isUsingUSB() {
if(isWiiVC)
return false;
/* First check if the app path exists on the SD card, if not then we're using USB */
struct stat dummy;
string appPath = fmt("%s:/%s", DeviceName[SD], APPS_DIR);
if(DeviceHandle.IsInserted(SD) && DeviceHandle.GetFSType(SD) != PART_FS_WBFS && stat(appPath.c_str(), &dummy) != 0)
{
// No app path exists on SD card, so assuming we're using USB.
return true;
}
/* Check that the config file exists, or we can't do the following checks */
string configPath = fmt("%s/" CFG_FILENAME, appPath.c_str());
if(stat(configPath.c_str(), &dummy) != 0)
{
// The app path is on SD but no config file exists, so assuming we might need USB.
return true;
}
/* Load the config file */
Config m_cfg;// = new Config();
if(!m_cfg.load(configPath.c_str()))
{
// The app path is on SD and a config file exists, but we can't load it, so assuming we might need USB.
return true;
}
/* if sd_only is false, then we're using USB */
if(!m_cfg.getBool("general", "sd_only", true))
{
// sd_only is false, so assuming we're using USB.
return true;
}
/* If any of the sections have partition set > 0, we're on USB */
const char *domains[] = {WII_DOMAIN, GC_DOMAIN, CHANNEL_DOMAIN, PLUGIN_DOMAIN, HOMEBREW_DOMAIN};
for(int i = 0; i < 5; i++)
{
if(!m_cfg.getBool(domains[i], "disable", false) && m_cfg.getInt(domains[i], "partition", SD) != SD)
{
// a domain is enabled and partition is not SD, so assuming we're using USB.
return true;
}
}
gprintf("using SD only, no need for USB mounting.\n");
return false;
}
2012-01-21 21:57:41 +01:00
int main(int argc, char **argv)
{
MEM_init(); //Inits both mem1lo and mem2
-fixed displaying errors on source menu -removed vipatch, country patch, private server and cheats defaults from wiiflow.ini. no need for default/global setting for those options. they all default to off internally in wiiflow. -now on file explorer menu pressing home btn returns you to device select so you don't have to keep backing up to get back to devices. -fixed a few minor problems with game configs, especially gc games. now all game config options should work properly. -now using bitwise operators and expressions on m_current_view to control which sources are selected. no more source= under each domain. just sources= under GENERAL. -replaced ocarina option from main settings pg3 with channels type option. no need for a global/default ocarina setting. channels type allows you to select real, emu, or both channels types for channels coverflow. which means no more pressing B on config icon to cycle thru the choices. -fixed a minor bug when downloading covers -changed newid.ini to use only one domain name "[NEWID]". this fixes a possible problem when downloading covers and using newid.ini and multisource. -added install wad option to nand emulation settings menu. I know you can do it via file explorer but this makes it easier for newbies to find. plus you can select which nand to install to. -fixed extract game saves. -fixed extract nand and install GC game by stopping music and controller input while doing these functions. -Install wii game is broke. added a error msg stating this and keeping users from using it. funny the code is almost identical to usbloader gx which works and wiiflow doesn't. -now showing all btns on game selected screen. if wiiflow is locked a error msg appears stating this. -changed makeDir to make the whole path not just one folder. thanks to usbloader gx code. -added .ciso extension to gamecube list maker so you can use them with nintendont.
2016-12-01 01:05:39 +01:00
mainIOS = DOL_MAIN_IOS;// 249
__exception_setreload(10);
Gecko_Init(); //USB Gecko and SD/WiFi buffer
gprintf(" \nWelcome to %s %s!\nThis is the debug output.\n", APP_NAME, APP_VERSION);
bool iosOK = true;
char *gameid = NULL;
bool showFlashImg = true;
bool wait_loop = false;
char wait_dir[256];
memset(&wait_dir, 0, sizeof(wait_dir));
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]++;
-updated NIN_CFG_VERSION to 7 for Nintendont argsboot and added triforce arcade option to game settings menu. tested and working. -fixed wii u widescreen option in game config menu. should properly work now. thanks pBullet! -added a fix for coverflow titles display when coverflow has 3 or more rows. for some reason 3 or more rows caused the title to display improperly. -removed **disabled** message from source menu. no need for it - was a stupid idea. if you don't want it to display then remove it from your source menu or don't add it. when a view is disabled in wiiflow_lite.ini then only that view icon is disabled from showing on the main menu screen. -removed titles.ini which wasn't really used except for displaying the return to channel in settings. I googled it and nothing really showed up. it seemed to be the same as custom_titles.ini - it seemed useless. -removed cacheing sourceflow list. the list is never big enuff to worry about cacheing. plus if you add or remove source btns you won't have to reload cache for the changes to take effect. -removed max_source_btns from wiiflow_lite.ini - added code to get highest source menu btn so now source menu can have as many buttons as you like. -removed Manage Languages Menu - restored option to just change wiiflow language. no need for downloading languages and the google link didn't work anyway. when i make a pack all the languages will be included. -added flat cover options for sourceflow and homebrew view. can be turned on/off via their config menu's accessed via 'HOME' btn. -added config menu for homebrew view - press 'HOME' btn while in homebrew view to access it. config menu options are - switch apps partition, adjust coverflow, smallbox on/off, and flat covers on/off. -updated config menu for source menu/flow. options include - sourceflow on/off, adjust coverflow, smallbox on/off, flat covers on/off, and for source menu only - multisource on/off. -added coverflow layouts/versions for individual plugins - which means each plugin can have its own coverflow layout without affecting the others. -set HQ cover to default to ON -made it so coverflow doesn't reload every time you access another menu or change favorites or whatever. -added error messages to game and app launching if any of the bin files needed for launching are missing. previously whenever these errors occurred wiiflow would just exit without the user knowing why. Now the error message should display before exit so the user has an idea what went wrong. had to move cleanup() back some for the errors to show. hopefully that doesn't cause out of mem issues for users with large game collections. -added error messages to game config menu. now all config options will show but if you can't use it then a error shows telling you. such as 'use neek2o' will be available but if you set it to on and neek2o isn't installed then an error message shows. added error msgs for extracting and flashing saves too. -added show_mem=yes/no option to wiiflow_lite.ini under [DEBUG]. manually edit wiiflow_lite.ini to turn it on/off. if set to 'yes' wiiflow will show how much free mem is available on screen. no need to compile wiiflow for this option anymore. -cleaned up some of the boot up code. -starting a random game - just hold 'B' and press '-'. no longer press'B' on config or question mark icon and no need to allow it in wiiflow_lite.ini
2016-11-07 16:06:00 +01:00
if(atoi(argv[i]) < 254 && atoi(argv[i]) > 0)
2012-01-21 21:57:41 +01:00
mainIOS = atoi(argv[i]);
}
else if(strcasestr(argv[i], "waitdir=") != NULL)
{
char *ptr = strcasestr(argv[i], "waitdir=");
strncpy(wait_dir, ptr+strlen("waitdir="), sizeof(wait_dir) - 1);
}
else if(strcasestr(argv[i], "Waitloop") != NULL)
wait_loop = true;
else if(strcasestr(argv[i], "noflash") != NULL)
showFlashImg = false;
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
}
/* Init video */
m_vid.init();
if(showFlashImg)
m_vid.startImage();
/* check if WiiVC */
WiiDRC_Init();
isWiiVC = WiiDRC_Inited();
if(IsOnWiiU())
{
gprintf("WiiU\n");
if(isWiiVC)
gprintf("WiiVC\n");
else
gprintf("vWii Mode\n");
}
else
gprintf("Real Wii\n");
gprintf("AHBPROT disabled = %s\n", AHBPROT_Patched() ? "yes" : "no");
/* Init device partition handlers */
DeviceHandle.Init();
/* Init NAND handlers */
NandHandle.Init();
if(isWiiVC)
{
NandHandle.Init_ISFS();
IOS_GetCurrentIOSInfo();
DeviceHandle.SetModes();
}
else
{
NandHandle.LoadDefaultIOS(); /* safe reload to preferred IOS */
/* load and check wiiflow save for possible new IOS and Port settings */
if(InternalSave.CheckSave())
InternalSave.LoadSettings();
/* Handle (c)IOS Loading */
if(useMainIOS && CustomIOS(IOS_GetType(mainIOS))) /* Requested */
iosOK = loadIOS(mainIOS, false) && CustomIOS(CurrentIOS.Type);
else
gprintf("Using IOS58\n");
}
/* sys inits */
Sys_Init();// set reset and power button callbacks
Sys_ExitTo(EXIT_TO_HBC);// set exit to in case of failed launch
/* mount SD */
DeviceHandle.MountSD();// mount SD before calling isUsingUSB() duh!
/* mount USB if needed */
DeviceHandle.SetMountUSB(isUsingUSB());
DeviceHandle.MountAllUSB();// only mounts any USB if isUsingUSB()
/* init wait images and show wait animation */
m_vid.setCustomWaitImgs(wait_dir, wait_loop);
m_vid.waitMessage(0.15f);
2012-01-21 21:57:41 +01:00
/* init controllers for input */
Open_Inputs();// WPAD_SetVRes() is called later in mainMenu.init() during cursor init which gets the theme pointer images
/* init configs, folders, coverflow, gui and more */
if(mainMenu.init())
{
if(CurrentIOS.Version != mainIOS)
{
if(useMainIOS || !DeviceHandle.UsablePartitionMounted())// if useMainIOS or there's isn't a FAT or NTFS partition
{
useMainIOS = false;
mainMenu.TempLoadIOS();
iosOK = CustomIOS(CurrentIOS.Type);
}
}
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(!DeviceHandle.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 // alls good lets start wiiflow
{
if(!isWiiVC)
writeStub();// copy return stub to memory
if(gameid != NULL && strlen(gameid) == 6)// if argv game ID then launch it
mainMenu.directlaunch(gameid);
else
mainMenu.main();// start wiiflow with main menu displayed
}
//Exit WiiFlow, no game booted...
mainMenu.cleanup();// removes all sounds, fonts, images, coverflow, plugin stuff, source menu and clear memory
}
-updating wiiflow lite to beta 4.3.0 -fixed using categories to hide GC disc 2's. Apparently this has never really worked right for some time or ever. -fixed deleting the cached cover texture file for plugin games. Delete cover for plugins only deletes the cached texture file (.wfc) -fixed favorites and adultonly (parental lock) for plugin games. Apparently I may have broke this a few revisions back. -favorites and adultonly for plugin games now have their own domains in gamecfg1- [FAVORITES_PLUGINS] and [ADULTONLY_PLUGINS]. just makes it more organized. -only wii, GC, channels are added to [PLAYCOUNT] and [LAST_PLAYED] in gamecfg1. -now loading gamecfg1 at startup and leaving it loaded till exit. no more loading it and unloading all the time. -fixed scrolling for game_info synopsis, credits, and help text. -made source menu buttons wider for wiiflow default. old 80x80, now 100x80. looks better. -display music info now defaults to off -screensaver_disabled now defaults to yes -show GC view button is now on by default no matter what. the only way it is disabled is if you edit wiiflow.ini manually. this is how all the view buttons work. -removed hiding homebrew button but if wiiflow locked it won't work or in sourceflow it won't show. -dump_list is now under [GENERAL] instead of each view. Also only works for Wii, GC, and channels. -sorting only works for Wii, GC, and Channels now. disabled for sourceflow, plugins, homebrew, and combined view. -now if no games are found a message is shown with the current path so you can see where wiiflow is looking. (except for plugins) -removed auto create emuNAND for emuNAND view if gamelist is empty. just go to settings>NAND settings if you want to extract or disable it. -now when no games are found all buttons at bottom are still accessible allowing you to change the view or go to settings and change current partition or path and even extract your NAND to create a EmuNAND. Or go to Home Menu and Install a Wii or GC game. -removed auto extract NAND to emuNAND when launching a Wii game with EmuNAND save. Now a message is diplayed saying 'emuNAND for saves not found - using real NAND'. -made the speed at which cover titles fade in/out almost instantly. -removed update button from Home Menu. online update code is still there but not used and probably won't be used any more as there just isn't a need for it now. -removed ftp button from Home Menu and all code for the FTP server. I just use WiiXplorer's FTP server. it seems to work better for me. -disabled keep USB Alive thread for now. i think there's a possibilty it might be the cause of my SD/USB files getting corrupted. -removed Btn B and - combo to switch partitions. didn't seem useful anymore. -redid nand emulation settings menu. looks like this now: pg1 Select EmuNAND EmuNAND Enulation Select SaveNAND SaveNAND Emulation pg2 Extract Saves All Missing Extract NAND Select Saves Partition -no longer blocking Select Plugin menu and View icons when using source menu combined view -now Select Plugins Menu is like switching to plugin view but you get to choose the plugins first -now [PLUGIN] partition= is the default partition for all plugins. to change individual plugins add 'romPartition=x' to the plugin ini. x is the partition number 0 thru 8 with SD being 0. this is how my usbloadergx plugin mod works.
2016-10-05 01:44:13 +02:00
ShutdownBeforeExit();// unmount devices and close inputs
2012-01-21 21:57:41 +01:00
Sys_Exit();
return 0;
}