2010-09-24 01:47:51 +02:00
|
|
|
#include <gctypes.h>
|
|
|
|
#include <ogc/system.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-24 01:47:51 +02:00
|
|
|
#include "mload/mload.h"
|
2010-12-31 00:49:22 +01:00
|
|
|
#include "Controls/DeviceHandler.hpp"
|
2010-12-31 17:18:48 +01:00
|
|
|
#include "FileOperations/fileops.h"
|
2011-01-22 17:10:36 +01:00
|
|
|
#include "homebrewboot/BootHomebrew.h"
|
2010-09-24 01:47:51 +02:00
|
|
|
#include "settings/CSettings.h"
|
2011-01-12 20:30:04 +01:00
|
|
|
#include "settings/GameTitles.h"
|
2010-11-06 16:30:14 +01:00
|
|
|
#include "settings/newtitles.h"
|
|
|
|
#include "language/gettext.h"
|
2010-12-05 20:24:32 +01:00
|
|
|
#include "network/networkops.h"
|
2010-09-26 11:25:11 +02:00
|
|
|
#include "utils/ResourceManager.h"
|
2010-12-27 10:44:27 +01:00
|
|
|
#include "usbloader/playlog.h"
|
2010-12-28 18:02:10 +01:00
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#include "themes/CTheme.h"
|
2011-01-02 14:56:24 +01:00
|
|
|
#include "SoundOperations/SoundHandler.hpp"
|
2010-12-31 14:13:14 +01:00
|
|
|
#include "utils/ThreadedTask.hpp"
|
2010-05-29 09:38:54 +02:00
|
|
|
#include "audio.h"
|
2010-09-16 21:59:41 +02:00
|
|
|
#include "lstub.h"
|
2010-09-24 01:47:51 +02:00
|
|
|
#include "menu.h"
|
|
|
|
#include "video.h"
|
2010-11-06 16:30:14 +01:00
|
|
|
#include "gecko.h"
|
2011-01-22 17:10:36 +01:00
|
|
|
#include "wad/nandtitle.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-01-14 16:39:42 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
extern s32 MagicPatches(s32);
|
2011-01-14 16:39:42 +01:00
|
|
|
}
|
|
|
|
|
2010-05-29 09:38:54 +02:00
|
|
|
//Wiilight stuff
|
2010-09-24 02:48:03 +02:00
|
|
|
void wiilight(int enable) // Toggle wiilight (thanks Bool for wiilight source)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-09-10 22:08:12 +02:00
|
|
|
static vu32 *_wiilight_reg = (u32*) 0xCD0000C0;
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 val = (*_wiilight_reg & ~0x20);
|
|
|
|
if (enable && Settings.wiilight) val |= 0x20;
|
|
|
|
*_wiilight_reg = val;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Variables */
|
|
|
|
u8 shutdown = 0;
|
|
|
|
u8 reset = 0;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void __Sys_ResetCallback(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Reboot console */
|
|
|
|
reset = 1;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void __Sys_PowerCallback(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Poweroff console */
|
|
|
|
shutdown = 1;
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_Init(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Initialize video subsytem */
|
|
|
|
//VIDEO_Init();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Set RESET/POWER button callback */
|
|
|
|
SYS_SetResetCallback(__Sys_ResetCallback);
|
|
|
|
SYS_SetPowerCallback(__Sys_PowerCallback);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-11-06 16:30:14 +01:00
|
|
|
void AppCleanUp(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
static bool app_clean = false;
|
|
|
|
if(app_clean)
|
|
|
|
return;
|
2011-01-16 14:12:07 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
app_clean = true;
|
2010-11-06 16:30:14 +01:00
|
|
|
extern u8 mountMethod;
|
2011-07-26 00:28:22 +02:00
|
|
|
gprintf("Exiting main GUI. mountMethod = %d\n", mountMethod);
|
2010-11-06 16:30:14 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
Settings.Save();
|
2010-11-13 23:34:53 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitGUIThreads();
|
|
|
|
StopGX();
|
2011-12-20 22:41:00 +01:00
|
|
|
wiilight(0);
|
2010-11-06 16:30:14 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
delete btnSoundClick;
|
|
|
|
delete btnSoundOver;
|
|
|
|
delete btnSoundClick2;
|
|
|
|
delete bgMusic;
|
|
|
|
delete background;
|
|
|
|
delete bgImg;
|
|
|
|
delete mainWindow;
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
delete pointer[i];
|
2010-12-18 14:20:45 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
gettextCleanUp();
|
|
|
|
Theme::CleanUp();
|
|
|
|
NewTitles::DestroyInstance();
|
|
|
|
ThreadedTask::DestroyInstance();
|
|
|
|
SoundHandler::DestroyInstance();
|
|
|
|
DeinitNetwork();
|
|
|
|
GameTitles.SetDefault();
|
2010-11-06 16:30:14 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ShutdownAudio();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ResourceManager::DestroyInstance();
|
2010-09-26 11:25:11 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
WPAD_Shutdown();
|
2011-12-22 23:44:48 +01:00
|
|
|
ISFS_Deinitialize();
|
2010-11-06 16:30:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExitApp(void)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
AppCleanUp();
|
|
|
|
WBFS_CloseAll();
|
|
|
|
DeviceHandler::DestroyInstance();
|
|
|
|
USB_Deinitialize();
|
|
|
|
if(Settings.PlaylogUpdate)
|
|
|
|
Playlog_Delete(); // Don't show USB Loader GX in the Wii message board
|
2011-01-14 16:39:42 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
MagicPatches(0);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_Reboot(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Restart console */
|
|
|
|
ExitApp();
|
|
|
|
STM_RebootSystem();
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
#define ShutdownToDefault 0
|
2011-07-26 00:28:22 +02:00
|
|
|
#define ShutdownToIdle 1
|
2010-09-19 01:16:05 +02:00
|
|
|
#define ShutdownToStandby 2
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
static void _Sys_Shutdown(int SHUTDOWN_MODE)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitApp();
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Poweroff console */
|
|
|
|
if ((CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby) || SHUTDOWN_MODE
|
|
|
|
== ShutdownToIdle)
|
|
|
|
{
|
|
|
|
s32 ret;
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Set LED mode */
|
|
|
|
ret = CONF_GetIdleLedMode();
|
|
|
|
if (ret >= 0 && ret <= 2) STM_SetLedMode(ret);
|
2010-05-29 09:38:54 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Shutdown to idle */
|
|
|
|
STM_ShutdownToIdle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Shutdown to standby */
|
|
|
|
STM_ShutdownToStandby();
|
|
|
|
}
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
2010-09-24 01:47:51 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_Shutdown(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
_Sys_Shutdown(ShutdownToDefault);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
2010-09-24 01:47:51 +02:00
|
|
|
|
2010-12-12 17:31:13 +01:00
|
|
|
void Sys_ShutdownToIdle(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
_Sys_Shutdown(ShutdownToIdle);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_ShutdownToStandby(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
_Sys_Shutdown(ShutdownToStandby);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_LoadMenu(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitApp();
|
2011-09-10 22:08:12 +02:00
|
|
|
|
2011-12-20 22:41:00 +01:00
|
|
|
// Priiloader shutup
|
|
|
|
if (Settings.godmode || !(Settings.ParentalBlocks & BLOCK_PRIILOADER_OVERRIDE))
|
|
|
|
{
|
|
|
|
*(u32 *)0x8132fffb = 0x50756e65;
|
|
|
|
DCFlushRange((u32 *)0x8132fffb, 4);
|
|
|
|
}
|
2011-09-10 22:08:12 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Return to the Wii system menu */
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void Sys_BackToLoader(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitApp();
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if (hbcStubAvailable())
|
|
|
|
exit(0);
|
|
|
|
// Channel Version
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2010-12-29 16:42:26 +01:00
|
|
|
}
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
#define HBC_HAXX 0x0001000148415858LL
|
|
|
|
#define HBC_JODI 0x000100014A4F4449LL
|
2010-12-29 16:42:26 +01:00
|
|
|
#define HBC_1_0_7 0x00010001AF1BF516LL
|
|
|
|
|
|
|
|
void Sys_LoadHBC(void)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitApp();
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
WII_Initialize();
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
int ret = WII_LaunchTitle(HBC_1_0_7);
|
|
|
|
if(ret < 0)
|
|
|
|
WII_LaunchTitle(HBC_JODI);
|
|
|
|
if(ret < 0)
|
|
|
|
WII_LaunchTitle(HBC_HAXX);
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
//Back to system menu if all fails
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|
|
|
|
|
2011-01-22 17:10:36 +01:00
|
|
|
bool RebootApp(void)
|
|
|
|
{
|
|
|
|
#ifdef FULLCHANNEL
|
|
|
|
ExitApp();
|
|
|
|
WII_Initialize();
|
|
|
|
return !(WII_LaunchTitle(TITLE_ID(0x00010001, 0x554c4e52)) < 0);
|
|
|
|
#else
|
|
|
|
char filepath[255];
|
|
|
|
snprintf(filepath, sizeof(filepath), "%s/boot.dol", Settings.update_path);
|
|
|
|
return !(BootHomebrew(filepath) < 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-29 09:38:54 +02:00
|
|
|
void ScreenShot()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
time_t rawtime;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
char buffer[150];
|
|
|
|
char buffer2[300];
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
time(&rawtime);
|
|
|
|
timeinfo = localtime(&rawtime);
|
|
|
|
//USBLoader_GX_ScreenShot-Month_Day_Hour_Minute_Second_Year.png
|
|
|
|
strftime(buffer, 80, "USBLoader_GX_ScreenShot-%b%d%H%M%S%y.png", timeinfo);
|
|
|
|
sprintf(buffer2, "%s%s", Settings.ConfigPath, buffer);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!CreateSubfolder(Settings.ConfigPath))
|
|
|
|
{
|
|
|
|
gprintf("Can't create screenshot folder\n");
|
|
|
|
return;
|
|
|
|
}
|
2010-12-31 17:18:48 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
TakeScreenshot(buffer2);
|
2010-05-29 09:38:54 +02:00
|
|
|
}
|