2012-08-12 23:26:24 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2012 FIX94
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <string.h>
|
2012-10-13 00:25:22 +02:00
|
|
|
#include <ogc/machine/processor.h>
|
2012-10-13 18:57:03 +02:00
|
|
|
#include <ogc/lwp_threads.h>
|
|
|
|
#include <ogc/cache.h>
|
2012-08-12 23:26:24 +02:00
|
|
|
#include "external_booter.hpp"
|
2012-10-13 00:25:22 +02:00
|
|
|
#include "Config.h"
|
2012-08-22 17:29:42 +02:00
|
|
|
#include "channel/nand.hpp"
|
2012-09-02 13:51:26 +02:00
|
|
|
#include "devicemounter/DeviceHandler.hpp"
|
2013-11-19 16:27:52 +01:00
|
|
|
#include "fileOps/fileOps.h"
|
2012-12-22 21:57:23 +01:00
|
|
|
#include "gecko/wifi_gecko.hpp"
|
2012-09-29 13:30:47 +02:00
|
|
|
#include "gui/text.hpp"
|
2012-10-13 00:25:22 +02:00
|
|
|
#include "loader/fst.h"
|
|
|
|
#include "loader/mload.h"
|
|
|
|
#include "loader/wdvd.h"
|
2012-12-22 21:57:23 +01:00
|
|
|
#include "loader/sys.h"
|
2012-08-12 23:26:24 +02:00
|
|
|
#include "homebrew/homebrew.h"
|
2012-09-29 13:30:47 +02:00
|
|
|
#include "memory/mem2.hpp"
|
2013-09-06 01:52:21 +02:00
|
|
|
#include "network/FTP_Dir.hpp"
|
2012-12-22 21:57:23 +01:00
|
|
|
#include "network/http.h"
|
2012-10-13 00:25:22 +02:00
|
|
|
#include "plugin/crc32.h"
|
2012-08-12 23:26:24 +02:00
|
|
|
|
2012-10-13 00:25:22 +02:00
|
|
|
/* External WiiFlow Game Booter */
|
|
|
|
static the_CFG *BooterConfig = (the_CFG*)0x93100000;
|
2013-11-19 16:27:52 +01:00
|
|
|
#define EXT_ADDR ((u8*)0x80B00000)
|
|
|
|
#define EXT_ENTRY ((entry)EXT_ADDR)
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
u8 configbytes[2];
|
|
|
|
u32 hooktype;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern u8 *code_buf;
|
|
|
|
extern u32 code_size;
|
|
|
|
extern void *codelist;
|
|
|
|
extern u8 *codelistend;
|
|
|
|
extern u32 gameconfsize;
|
|
|
|
extern u32 *gameconf;
|
|
|
|
|
2013-12-24 16:35:59 +01:00
|
|
|
u8 *booter_ptr = NULL;
|
2013-11-19 16:27:52 +01:00
|
|
|
size_t booter_size = 0;
|
2012-09-29 13:30:47 +02:00
|
|
|
the_CFG normalCFG;
|
2013-11-19 16:27:52 +01:00
|
|
|
|
2013-01-19 21:48:07 +01:00
|
|
|
void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode,
|
|
|
|
int aspectRatio, u32 returnTo, u8 BootType, bool use_led)
|
2012-08-12 23:26:24 +02:00
|
|
|
{
|
|
|
|
normalCFG.vidMode = vidMode;
|
|
|
|
normalCFG.vipatch = vipatch;
|
|
|
|
normalCFG.countryString = countryString;
|
|
|
|
normalCFG.patchVidMode = patchVidMode;
|
|
|
|
normalCFG.aspectRatio = aspectRatio;
|
|
|
|
normalCFG.returnTo = returnTo;
|
|
|
|
normalCFG.configbytes[0] = configbytes[0];
|
|
|
|
normalCFG.configbytes[1] = configbytes[1];
|
|
|
|
normalCFG.IOS = CurrentIOS;
|
|
|
|
normalCFG.codelist = codelist;
|
|
|
|
normalCFG.codelistend = codelistend;
|
|
|
|
normalCFG.cheats = code_buf;
|
|
|
|
normalCFG.cheatSize = code_size;
|
|
|
|
normalCFG.hooktype = hooktype;
|
|
|
|
normalCFG.debugger = debuggerselect;
|
|
|
|
normalCFG.gameconf = gameconf;
|
|
|
|
normalCFG.gameconfsize = gameconfsize;
|
|
|
|
normalCFG.BootType = BootType;
|
2013-01-19 21:48:07 +01:00
|
|
|
normalCFG.use_led = use_led;
|
2012-10-20 00:01:30 +02:00
|
|
|
normalCFG.wip_list = get_wip_list();
|
|
|
|
normalCFG.wip_count = get_wip_count();
|
2013-11-19 16:27:52 +01:00
|
|
|
/* Unmount devices etc */
|
2013-01-27 13:12:44 +01:00
|
|
|
ShutdownBeforeExit();
|
2013-11-19 16:27:52 +01:00
|
|
|
/* Copy in booter */
|
2013-12-24 16:35:59 +01:00
|
|
|
memcpy(EXT_ADDR, booter_ptr, booter_size);
|
2013-11-19 16:27:52 +01:00
|
|
|
DCFlushRange(EXT_ADDR, booter_size);
|
2012-09-29 13:30:47 +02:00
|
|
|
/* Copy CFG into new memory region */
|
2012-10-13 00:25:22 +02:00
|
|
|
memcpy(BooterConfig, &normalCFG, sizeof(the_CFG));
|
|
|
|
DCFlushRange(BooterConfig, sizeof(the_CFG));
|
2012-12-27 02:08:16 +01:00
|
|
|
/* Wii Games will need it */
|
|
|
|
net_wc24cleanup();
|
2013-12-18 19:33:40 +01:00
|
|
|
/* Set proper time */
|
|
|
|
settime(secs_to_ticks(time(NULL) - 946684800));
|
2012-10-20 15:24:30 +02:00
|
|
|
/* Boot it */
|
2012-12-08 19:45:48 +01:00
|
|
|
JumpToEntry(EXT_ENTRY);
|
2012-08-12 23:26:24 +02:00
|
|
|
}
|
|
|
|
|
2013-11-19 16:27:52 +01:00
|
|
|
bool ExternalBooter_LoadBooter(const char *booter_path)
|
|
|
|
{
|
|
|
|
fsop_GetFileSizeBytes(booter_path, &booter_size);
|
|
|
|
if(booter_size > 0)
|
|
|
|
{
|
2013-12-24 16:35:59 +01:00
|
|
|
booter_ptr = fsop_ReadFile(booter_path, &booter_size);
|
|
|
|
if(booter_ptr != NULL)
|
|
|
|
return true;
|
2013-11-19 16:27:52 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-28 19:24:04 +02:00
|
|
|
extern FragList *frag_list;
|
|
|
|
extern s32 wbfsDev;
|
|
|
|
extern u32 wbfs_part_idx;
|
|
|
|
void ExternalBooter_WiiGameSetup(bool wbfs, bool dvd, const char *ID)
|
|
|
|
{
|
2012-09-29 13:30:47 +02:00
|
|
|
memset(&normalCFG, 0, sizeof(the_CFG));
|
2012-09-28 19:24:04 +02:00
|
|
|
normalCFG.GameBootType = dvd ? TYPE_WII_DISC : (wbfs ? TYPE_WII_WBFS : TYPE_WII_WBFS_EXT);
|
|
|
|
strncpy(normalCFG.gameID, ID, 6);
|
|
|
|
normalCFG.fragments = frag_list;
|
|
|
|
normalCFG.wbfsDevice = wbfsDev;
|
|
|
|
normalCFG.wbfsPart = wbfs_part_idx;
|
|
|
|
}
|
|
|
|
|
2013-01-05 18:12:13 +01:00
|
|
|
void ExternalBooter_ChannelSetup(u64 title, bool dol)
|
2012-08-12 23:26:24 +02:00
|
|
|
{
|
2012-09-29 13:30:47 +02:00
|
|
|
memset(&normalCFG, 0, sizeof(the_CFG));
|
|
|
|
memcpy(&normalCFG.title, &title, sizeof(u64));
|
2013-01-05 18:12:13 +01:00
|
|
|
normalCFG.use_dol = dol;
|
2012-08-12 23:26:24 +02:00
|
|
|
}
|
2012-09-02 13:51:26 +02:00
|
|
|
|
2013-01-27 13:12:44 +01:00
|
|
|
void ShutdownBeforeExit(void)
|
2012-09-02 13:51:26 +02:00
|
|
|
{
|
2012-09-22 15:47:52 +02:00
|
|
|
DeviceHandle.UnMountAll();
|
2013-01-27 13:12:44 +01:00
|
|
|
NandHandle.DeInit_ISFS();
|
2012-09-02 13:51:26 +02:00
|
|
|
WDVD_Close();
|
2012-12-27 02:08:16 +01:00
|
|
|
Close_Inputs();
|
2012-12-22 21:57:23 +01:00
|
|
|
/* Deinit network */
|
|
|
|
if(networkInit == true)
|
|
|
|
{
|
|
|
|
while(net_get_status() == -EBUSY)
|
|
|
|
usleep(50);
|
|
|
|
WiFiDebugger.Close();
|
2013-09-06 01:52:21 +02:00
|
|
|
ftp_endTread();
|
2012-12-22 21:57:23 +01:00
|
|
|
net_deinit();
|
|
|
|
networkInit = false;
|
|
|
|
}
|
2012-09-02 13:51:26 +02:00
|
|
|
}
|