mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2024-12-28 12:51:52 +01:00
-made configuration alot of more safe
-corrected some other possible bugs with the external booter
This commit is contained in:
parent
d8ee3c1b68
commit
c387ea2c0f
Binary file not shown.
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 148 KiB |
@ -32,9 +32,7 @@
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "Config.hpp"
|
||||
#include "ChannelHandler.hpp"
|
||||
|
||||
#include "patchcode.h"
|
||||
#include "cios.h"
|
||||
#include "fs.h"
|
||||
@ -52,10 +50,10 @@ u32 bootcontent;
|
||||
|
||||
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
|
||||
|
||||
static u8 *GetDol(u32 bootcontent)
|
||||
static u8 *GetDol(u32 bootcontent, u64 title)
|
||||
{
|
||||
memset(filepath, 0, ISFS_MAXPATH);
|
||||
sprintf(filepath, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(conf->title), TITLE_LOWER(conf->title), bootcontent);
|
||||
sprintf(filepath, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(title), TITLE_LOWER(title), bootcontent);
|
||||
|
||||
u32 contentSize = 0;
|
||||
|
||||
@ -79,12 +77,12 @@ static u8 *GetDol(u32 bootcontent)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool GetAppNameFromTmd(bool dol, u32 *bootcontent)
|
||||
static bool GetAppNameFromTmd(bool dol, u32 *bootcontent, u64 title)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
memset(filepath, 0, ISFS_MAXPATH);
|
||||
sprintf(filepath, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(conf->title), TITLE_LOWER(conf->title));
|
||||
sprintf(filepath, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(title), TITLE_LOWER(title));
|
||||
|
||||
u32 size;
|
||||
u8 *data = ISFS_GetFile((u8 *) &filepath, &size, -1);
|
||||
@ -140,19 +138,19 @@ static u32 MoveDol(u8 *buffer)
|
||||
return dolfile->entry_point;
|
||||
}
|
||||
|
||||
u32 LoadChannel()
|
||||
u32 LoadChannel(u64 title)
|
||||
{
|
||||
u32 entry = 0;
|
||||
|
||||
GetAppNameFromTmd(true, &bootcontent);
|
||||
u8 *data = GetDol(bootcontent);
|
||||
GetAppNameFromTmd(true, &bootcontent, title);
|
||||
u8 *data = GetDol(bootcontent, title);
|
||||
entry = MoveDol(data);
|
||||
free(data);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio)
|
||||
void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio, u64 title)
|
||||
{
|
||||
bool hook = false;
|
||||
for(u8 i = 0; i < dolchunkcount; i++)
|
||||
@ -168,5 +166,5 @@ void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryStrin
|
||||
ICInvalidateRange(dolchunkoffset[i], dolchunksize[i]);
|
||||
}
|
||||
if(hook)
|
||||
ocarina_do_code(conf->title);
|
||||
ocarina_do_code(title);
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ typedef struct _dolheader
|
||||
u32 padding[7];
|
||||
} __attribute__((packed)) dolheader;
|
||||
|
||||
void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio);
|
||||
u32 LoadChannel();
|
||||
void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString,
|
||||
u8 patchVidModes, int aspectRatio, u64 title);
|
||||
u32 LoadChannel(u64 title);
|
||||
|
||||
#endif /* __CHANHANDLE_HPP_ */
|
||||
|
@ -50,6 +50,4 @@ typedef struct _the_CFG {
|
||||
u32 returnTo;
|
||||
} the_CFG;
|
||||
|
||||
static the_CFG *conf = (the_CFG*)0x90000000;
|
||||
|
||||
#endif /* _CFG_HPP_ */
|
||||
|
@ -48,59 +48,65 @@ extern u32 wbfs_part_idx;
|
||||
extern FragList *frag_list;
|
||||
}
|
||||
|
||||
int main()
|
||||
the_CFG normalCFG;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(!argc)
|
||||
return 0;
|
||||
memcpy(&normalCFG, (void*)strtoul(argv[0], NULL, 16), sizeof(the_CFG));
|
||||
|
||||
VIDEO_Init();
|
||||
InitGecko();
|
||||
gprintf("WiiFlow External Booter by FIX94\n");
|
||||
|
||||
configbytes[0] = conf->configbytes[0];
|
||||
configbytes[1] = conf->configbytes[1];
|
||||
hooktype = conf->hooktype;
|
||||
debuggerselect = conf->debugger;
|
||||
CurrentIOS = conf->IOS;
|
||||
app_gameconfig_set(conf->gameconf, conf->gameconfsize);
|
||||
ocarina_set_codes(conf->codelist, conf->codelistend, conf->cheats, conf->cheatSize);
|
||||
frag_list = conf->fragments;
|
||||
wbfsDev = conf->wbfsDevice;
|
||||
wbfs_part_idx = conf->wbfsPart;
|
||||
configbytes[0] = normalCFG.configbytes[0];
|
||||
configbytes[1] = normalCFG.configbytes[1];
|
||||
hooktype = normalCFG.hooktype;
|
||||
debuggerselect = normalCFG.debugger;
|
||||
CurrentIOS = normalCFG.IOS;
|
||||
app_gameconfig_set(normalCFG.gameconf, normalCFG.gameconfsize);
|
||||
ocarina_set_codes(normalCFG.codelist, normalCFG.codelistend, normalCFG.cheats, normalCFG.cheatSize);
|
||||
frag_list = normalCFG.fragments;
|
||||
wbfsDev = normalCFG.wbfsDevice;
|
||||
wbfs_part_idx = normalCFG.wbfsPart;
|
||||
|
||||
if(conf->BootType == TYPE_WII_GAME)
|
||||
if(normalCFG.BootType == TYPE_WII_GAME)
|
||||
{
|
||||
WDVD_Init();
|
||||
if(conf->GameBootType == TYPE_WII_DISC)
|
||||
if(normalCFG.GameBootType == TYPE_WII_DISC)
|
||||
{
|
||||
Disc_SetUSB(NULL, false);
|
||||
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
||||
Hermes_Disable_EHC();
|
||||
}
|
||||
else
|
||||
Disc_SetUSB((u8*)conf->gameID, conf->GameBootType == TYPE_WII_WBFS_EXT);
|
||||
{
|
||||
Disc_SetUSB((u8*)normalCFG.gameID, normalCFG.GameBootType == TYPE_WII_WBFS_EXT);
|
||||
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
||||
Hermes_shadow_mload(normalCFG.mload_rev);
|
||||
}
|
||||
Disc_Open();
|
||||
Disc_SetLowMem();
|
||||
u64 offset = 0;
|
||||
Disc_FindPartition(&offset);
|
||||
gprintf("Partition Offset: %08x\n", offset);
|
||||
WDVD_OpenPartition(offset);
|
||||
vmode = Disc_SelectVMode(conf->vidMode, &vmode_reg);
|
||||
Apploader_Run(&p_entry, conf->vidMode, vmode, conf->vipatch, conf->countryString, conf->patchVidMode,
|
||||
conf->aspectRatio, conf->returnTo);
|
||||
vmode = Disc_SelectVMode(normalCFG.vidMode, &vmode_reg);
|
||||
Apploader_Run(&p_entry, normalCFG.vidMode, vmode, normalCFG.vipatch, normalCFG.countryString, normalCFG.patchVidMode,
|
||||
normalCFG.aspectRatio, normalCFG.returnTo);
|
||||
AppEntrypoint = (u32)p_entry;
|
||||
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
||||
{
|
||||
if(conf->GameBootType == TYPE_WII_DISC)
|
||||
Hermes_Disable_EHC();
|
||||
else
|
||||
Hermes_shadow_mload(conf->mload_rev);
|
||||
}
|
||||
WDVD_Close();
|
||||
}
|
||||
else if(conf->BootType == TYPE_CHANNEL)
|
||||
else if(normalCFG.BootType == TYPE_CHANNEL)
|
||||
{
|
||||
ISFS_Initialize();
|
||||
AppEntrypoint = LoadChannel();
|
||||
Disc_SetLowMem();
|
||||
vmode = Disc_SelectVMode(conf->vidMode, &vmode_reg);
|
||||
PatchChannel(conf->vidMode, vmode, conf->vipatch, conf->countryString,
|
||||
conf->patchVidMode, conf->aspectRatio);
|
||||
AppEntrypoint = LoadChannel(normalCFG.title);
|
||||
vmode = Disc_SelectVMode(normalCFG.vidMode, &vmode_reg);
|
||||
PatchChannel(normalCFG.vidMode, vmode, normalCFG.vipatch, normalCFG.countryString,
|
||||
normalCFG.patchVidMode, normalCFG.aspectRatio, normalCFG.title);
|
||||
ISFS_Deinitialize();
|
||||
}
|
||||
gprintf("Entrypoint: %08x\n", AppEntrypoint);
|
||||
|
||||
/* Set time */
|
||||
Disc_SetTime();
|
||||
|
@ -336,7 +336,7 @@ s32 WDVD_Read_Disc_BCA(void *buf)
|
||||
|
||||
s32 WDVD_SetFragList(int device, void *fraglist, int size)
|
||||
{
|
||||
gprintf("WDVD_SetFragList, Device: %i, Size %d\n", device, size);
|
||||
gprintf("WDVD_SetFragList, Device: %i, Size: %i\n", device, size);
|
||||
memset(inbuf, 0, sizeof(inbuf));
|
||||
memset(outbuf, 0, sizeof(outbuf));
|
||||
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "wdvd.h"
|
||||
#include "channel/nand.hpp"
|
||||
#include "devicemounter/DeviceHandler.hpp"
|
||||
#include "gui/text.hpp"
|
||||
#include "homebrew/homebrew.h"
|
||||
#include "memory/mem2.hpp"
|
||||
|
||||
/* External WiiFlow Game Booter */
|
||||
#define EXECUTE_ADDR ((u8 *)0x92000000)
|
||||
@ -36,8 +38,6 @@ u8 configbytes[2];
|
||||
u32 hooktype;
|
||||
};
|
||||
|
||||
the_CFG normalCFG;
|
||||
|
||||
extern u8 *code_buf;
|
||||
extern u32 code_size;
|
||||
extern void *codelist;
|
||||
@ -45,6 +45,7 @@ extern u8 *codelistend;
|
||||
extern u32 gameconfsize;
|
||||
extern u32 *gameconf;
|
||||
|
||||
the_CFG normalCFG;
|
||||
void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio, u32 returnTo, u8 BootType)
|
||||
{
|
||||
normalCFG.vidMode = vidMode;
|
||||
@ -65,10 +66,14 @@ void WiiFlow_ExternalBooter(u8 vidMode, bool vipatch, bool countryString, u8 pat
|
||||
normalCFG.gameconf = gameconf;
|
||||
normalCFG.gameconfsize = gameconfsize;
|
||||
normalCFG.BootType = BootType;
|
||||
memcpy((void *)0x90000000, &normalCFG, sizeof(the_CFG));
|
||||
DCFlushRange((void *)(0x90000000), sizeof(the_CFG));
|
||||
|
||||
ShutdownBeforeExit(true);
|
||||
/* Copy CFG into new memory region */
|
||||
void *GameCFG = MEM1_lo_alloc(sizeof(the_CFG));
|
||||
memcpy(GameCFG, &normalCFG, sizeof(the_CFG));
|
||||
DCFlushRange(GameCFG, sizeof(the_CFG));
|
||||
AddBootArgument(fmt("%08x", GameCFG));
|
||||
/* Copy booter into apploader region */
|
||||
memcpy(EXECUTE_ADDR, wii_game_booter_dol, wii_game_booter_dol_size);
|
||||
DCFlushRange(EXECUTE_ADDR, wii_game_booter_dol_size);
|
||||
BootHomebrew();
|
||||
@ -79,6 +84,7 @@ extern s32 wbfsDev;
|
||||
extern u32 wbfs_part_idx;
|
||||
void ExternalBooter_WiiGameSetup(bool wbfs, bool dvd, const char *ID)
|
||||
{
|
||||
memset(&normalCFG, 0, sizeof(the_CFG));
|
||||
normalCFG.GameBootType = dvd ? TYPE_WII_DISC : (wbfs ? TYPE_WII_WBFS : TYPE_WII_WBFS_EXT);
|
||||
strncpy(normalCFG.gameID, ID, 6);
|
||||
normalCFG.fragments = frag_list;
|
||||
@ -89,7 +95,8 @@ void ExternalBooter_WiiGameSetup(bool wbfs, bool dvd, const char *ID)
|
||||
|
||||
void ExternalBooter_ChannelSetup(u64 title)
|
||||
{
|
||||
normalCFG.title = title;
|
||||
memset(&normalCFG, 0, sizeof(the_CFG));
|
||||
memcpy(&normalCFG.title, &title, sizeof(u64));
|
||||
}
|
||||
|
||||
void ShutdownBeforeExit(bool KeepPatches)
|
||||
|
@ -169,9 +169,9 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
|
||||
bool isWBFS = wbfs_part_fs != PART_FS_WBFS && strcasestr(strrchr(fname,'.'), ".wbfs") != 0;
|
||||
|
||||
struct stat st;
|
||||
FragList *fs = malloc(sizeof(FragList));
|
||||
FragList *fa = malloc(sizeof(FragList));
|
||||
FragList *fw = malloc(sizeof(FragList));
|
||||
FragList *fs = MEM1_lo_alloc(sizeof(FragList));
|
||||
FragList *fa = MEM1_lo_alloc(sizeof(FragList));
|
||||
FragList *fw = MEM1_lo_alloc(sizeof(FragList));
|
||||
if(fs == NULL || fa == NULL || fw == NULL)
|
||||
goto out;
|
||||
|
||||
@ -241,7 +241,7 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
|
||||
frag_concat(fa, fs);
|
||||
}
|
||||
|
||||
frag_list = malloc(sizeof(FragList));
|
||||
frag_list = MEM1_lo_alloc(sizeof(FragList));
|
||||
if(frag_list == NULL)
|
||||
goto out;
|
||||
|
||||
@ -270,50 +270,29 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
|
||||
}
|
||||
else
|
||||
memcpy(frag_list, fa, sizeof(FragList)); // .iso files do not need a remap, just copy
|
||||
|
||||
DCFlushRange(frag_list, sizeof(FragList));
|
||||
ret_val = 0;
|
||||
|
||||
out:
|
||||
if(ret_val && frag_list != NULL)
|
||||
{
|
||||
free(frag_list);
|
||||
MEM1_lo_free(frag_list);
|
||||
frag_list = NULL;
|
||||
}
|
||||
if(fs != NULL)
|
||||
{
|
||||
free(fs);
|
||||
MEM1_lo_free(fs);
|
||||
fs = NULL;
|
||||
}
|
||||
if(fa != NULL)
|
||||
{
|
||||
free(fa);
|
||||
MEM1_lo_free(fa);
|
||||
fa = NULL;
|
||||
}
|
||||
if(fw != NULL)
|
||||
{
|
||||
free(fw);
|
||||
MEM1_lo_free(fw);
|
||||
fw = NULL;
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
int set_frag_list()
|
||||
{
|
||||
if (frag_list == NULL)
|
||||
return -2;
|
||||
|
||||
// (+1 for header which is same size as fragment)
|
||||
int size = sizeof(Fragment) * (frag_list->num + 1);
|
||||
DCFlushRange(frag_list, size);
|
||||
|
||||
gprintf("Calling WDVD_SetFragList, frag list size %d\n", size);
|
||||
/* if (size > 400) ghexdump(frag_list, 400);
|
||||
else ghexdump(frag_list, size); */
|
||||
|
||||
int ret = WDVD_SetFragList(wbfsDev, frag_list, size);
|
||||
/* free(frag_list);
|
||||
frag_list = NULL; */
|
||||
if(ret)
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1431,6 +1431,8 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
|
||||
wbfs_partition = (DeviceHandle.GetFSType(currentPartition) == PART_FS_WBFS);
|
||||
if(!wbfs_partition && get_frag_list((u8 *)id.c_str(), (char*)path.c_str(), currentPartition == 0 ? 0x200 : USBStorage2_GetSectorSize()) < 0)
|
||||
Sys_Exit();
|
||||
if(currentPartition == 0)
|
||||
USBStorage2_WBFS_SetDevice(1);
|
||||
WBFS_Close();
|
||||
}
|
||||
if(gameconfig.get() != NULL)
|
||||
@ -1443,8 +1445,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
|
||||
ocarina_load_code(cheatFile.get(), cheatSize);
|
||||
cheatFile.release();
|
||||
}
|
||||
if(CurrentIOS.Type == IOS_TYPE_HERMES && currentPartition == 0)
|
||||
USBStorage2_WBFS_SetDevice(1);
|
||||
ExternalBooter_WiiGameSetup(wbfs_partition, dvd, id.c_str());
|
||||
WiiFlow_ExternalBooter(videoMode, vipatch, countryPatch, patchVidMode, aspectRatio, returnTo, TYPE_WII_GAME);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user