*Fixed launching channels on emulated nand

*Nand emulation will also work if emulated nand is on the same partition as the wiiflow executable
This commit is contained in:
overjoy.psm 2012-05-23 22:09:11 +00:00
parent 61926471ea
commit d6389153bf
6 changed files with 116 additions and 54 deletions

View File

@ -153,9 +153,12 @@ u32 LoadChannel(u8 *buffer)
int i; int i;
for(i = 0; i < 18; i++) for(i = 0; i < 18; i++)
{ {
if(!dolfile->section_size[i]) continue; if(!dolfile->section_size[i])
if(dolfile->section_pos[i] < sizeof(dolheader)) continue; continue;
if(!(dolfile->section_start[i] & 0x80000000)) dolfile->section_start[i] |= 0x80000000; if(dolfile->section_pos[i] < sizeof(dolheader))
continue;
if(!(dolfile->section_start[i] & 0x80000000))
dolfile->section_start[i] |= 0x80000000;
dolchunkoffset[dolchunkcount] = (void *)dolfile->section_start[i]; dolchunkoffset[dolchunkcount] = (void *)dolfile->section_start[i];
dolchunksize[dolchunkcount] = dolfile->section_size[i]; dolchunksize[dolchunkcount] = dolfile->section_size[i];
@ -285,7 +288,7 @@ bool Identify(u64 titleid, u32 *ios)
return ret < 0 ? false : true; return ret < 0 ? false : true;
} }
u8 * GetDol(u64 title, u32 bootcontent) u8 *GetDol(u64 title, u32 bootcontent)
{ {
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
sprintf(filepath, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(title), TITLE_LOWER(title), bootcontent); sprintf(filepath, "/title/%08x/%08x/content/%08x.app", TITLE_UPPER(title), TITLE_LOWER(title), bootcontent);

View File

@ -82,7 +82,7 @@ u32 Channels::Load(u64 title, u32 *ios)
if(!GetAppNameFromTmd(title, app, true, &bootcontent)) if(!GetAppNameFromTmd(title, app, true, &bootcontent))
return entry; return entry;
u8* data = GetDol(title, bootcontent); u8 *data = GetDol(title, bootcontent);
Identify(title, ios); Identify(title, ios);
entry = LoadChannel(data); entry = LoadChannel(data);
@ -148,7 +148,7 @@ u64* Channels::GetChannelList(u32* count)
return(u64*)MEM2_realloc(channels, *count * sizeof(u64)); return(u64*)MEM2_realloc(channels, *count * sizeof(u64));
} }
bool Channels::GetAppNameFromTmd(u64 title, char* app, bool dol, u32* bootcontent) bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootcontent)
{ {
bool ret = false; bool ret = false;

View File

@ -116,7 +116,8 @@ s32 Nand::Nand_Enable(NandDevice *Device)
{ {
gprintf("Enabling NAND Emulator\n"); gprintf("Enabling NAND Emulator\n");
s32 fd = IOS_Open("/dev/fs", 0); s32 fd = IOS_Open("/dev/fs", 0);
if (fd < 0) return fd; if (fd < 0)
return fd;
int NandPathlen = strlen(NandPath) + 1; int NandPathlen = strlen(NandPath) + 1;
@ -150,12 +151,6 @@ s32 Nand::Nand_Disable(void)
s32 Nand::Enable_Emu() s32 Nand::Enable_Emu()
{ {
if(MountedDevice == EmuDevice || Disabled)
{
gprintf("Fail 1\n");
return 0;
}
Disable_Emu(); Disable_Emu();
NandDevice *Device = &NandDeviceList[EmuDevice]; NandDevice *Device = &NandDeviceList[EmuDevice];

View File

@ -64,6 +64,8 @@ class Nand
void Set_Partition(u32 partition) { Partition = partition; }; void Set_Partition(u32 partition) { Partition = partition; };
void Set_FullMode(bool fullmode) { FullMode = fullmode ? 0x100 : 0; }; void Set_FullMode(bool fullmode) { FullMode = fullmode ? 0x100 : 0; };
void Set_RCMode(bool rcmode) { FullMode = rcmode ? 0x40 : 0; }; void Set_RCMode(bool rcmode) { FullMode = rcmode ? 0x40 : 0; };
void Set_SSMode(bool ssmode) { FullMode = ssmode ? 0x60 : 0; };
const char * Get_NandPath(void) { return NandPath; }; const char * Get_NandPath(void) { return NandPath; };
u32 Get_Partition(void) { return Partition; }; u32 Get_Partition(void) { return Partition; };

View File

@ -2016,7 +2016,7 @@ bool CMenu::_loadChannelList(void)
first = false; first = false;
} }
if(changed) if(changed && !disable_emu)
{ {
Nand::Instance()->Disable_Emu(); Nand::Instance()->Disable_Emu();
if(!DeviceHandler::Instance()->IsInserted(lastPartition)) if(!DeviceHandler::Instance()->IsInserted(lastPartition))

View File

@ -826,7 +826,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id)
// remap IOS to CIOS // remap IOS to CIOS
if(gameIOS < 0x64) if(gameIOS < 0x64)
{ {
if ( _installed_cios.size() <= 0) if(_installed_cios.size() <= 0)
{ {
error(sfmt("No cios found!")); error(sfmt("No cios found!"));
Sys_LoadMenu(); Sys_LoadMenu();
@ -859,7 +859,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id)
} }
} }
if (gameIOS != mainIOS) if(gameIOS != mainIOS)
{ {
gprintf("Reloading IOS into %d\n", gameIOS); gprintf("Reloading IOS into %d\n", gameIOS);
if(!loadIOS(gameIOS, true)) if(!loadIOS(gameIOS, true))
@ -881,6 +881,8 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
u32 ios = 0; u32 ios = 0;
u32 entry = 0; u32 entry = 0;
MEM1_wrap(0); MEM1_wrap(0);
Nand::Instance()->Disable_Emu();
string id = string((const char *) hdr->hdr.id); string id = string((const char *) hdr->hdr.id);
@ -895,10 +897,7 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
} }
forwarder = m_gcfg2.getBool(id, "custom", forwarder) || strncmp(id.c_str(), "WIMC", 4) == 0; forwarder = m_gcfg2.getBool(id, "custom", forwarder) || strncmp(id.c_str(), "WIMC", 4) == 0;
if(!forwarder)
entry = channel.Load(hdr->hdr.chantitle, &ios);
Nand::Instance()->Disable_Emu();
bool vipatch = m_gcfg2.testOptBool(id, "vipatch", m_cfg.getBool("GENERAL", "vipatch", false)); bool vipatch = m_gcfg2.testOptBool(id, "vipatch", m_cfg.getBool("GENERAL", "vipatch", false));
bool cheat = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("NAND", "cheat", false)); bool cheat = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("NAND", "cheat", false));
bool countryPatch = m_gcfg2.testOptBool(id, "country_patch", m_cfg.getBool("GENERAL", "country_patch", false)); bool countryPatch = m_gcfg2.testOptBool(id, "country_patch", m_cfg.getBool("GENERAL", "country_patch", false));
@ -927,56 +926,121 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
if(!forwarder && has_enabled_providers() && _initNetwork() == 0) if(!forwarder && has_enabled_providers() && _initNetwork() == 0)
add_game_to_card(id.c_str()); add_game_to_card(id.c_str());
string emuPath = m_cfg.getString("NAND", "path", "");
int emuPartition = m_cfg.getInt("NAND", "partition", 0);
bool emu_disabled = m_cfg.getBool("NAND", "disable", true); bool emu_disabled = m_cfg.getBool("NAND", "disable", true);
bool emulate_mode = false; int emulate_mode = min(max(0, m_cfg.getInt("NAND", "emulation", 0)), (int)ARRAY_SIZE(CMenu::_NandEmu) - 1);
int i = min(max(0, m_cfg.getInt("NAND", "emulation", 0)), (int)ARRAY_SIZE(CMenu::_NandEmu) - 1);
if (i==2)
emulate_mode = true;
int userIOS = 0; int userIOS = m_gcfg2.getInt(id, "ios", 0);
m_gcfg2.getInt(id, "ios", &userIOS);
m_gcfg1.save(true); m_gcfg1.save(true);
m_gcfg2.save(true); m_gcfg2.save(true);
m_cat.save(true); m_cat.save(true);
m_cfg.save(true); m_cfg.save(true);
if(!emu_disabled)
{
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false);
DeviceHandler::Instance()->UnMount(emuPartition);
bool iosLoaded = false; if(emulate_mode == 3)
Nand::Instance()->Set_RCMode(true);
else if(emulate_mode == 2)
Nand::Instance()->Set_FullMode(true);
else
Nand::Instance()->Set_FullMode(false);
if(Nand::Instance()->Enable_Emu() < 0)
{
Nand::Instance()->Disable_Emu();
error(L"Enabling emu failed!");
return;
}
DeviceHandler::Instance()->Mount(emuPartition);
}
if(!forwarder) if(!forwarder)
{ {
entry = channel.Load(hdr->hdr.chantitle, &ios);
setLanguage(language); setLanguage(language);
SmartBuf cheatFile; SmartBuf cheatFile;
u32 cheatSize = 0; u32 cheatSize = 0;
if (cheat) if (cheat)
_loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->hdr.id)); _loadFile(cheatFile, cheatSize, m_cheatDir.c_str(), fmt("%s.gct", hdr->hdr.id));
ocarina_load_code(cheatFile.get(), cheatSize); ocarina_load_code(cheatFile.get(), cheatSize);
int result = _loadIOS(channel.GetRequestedIOS(hdr->hdr.chantitle), userIOS, id); int gameIOS = userIOS == 0 ? channel.GetRequestedIOS(hdr->hdr.chantitle) : userIOS;
if (result == LOAD_IOS_FAILED)
return; gprintf("%s IOS %u\n", userIOS == 0 ? "Game requested" : "User requested", gameIOS);
if (result == LOAD_IOS_SUCCEEDED)
iosLoaded = true; if (gameIOS != mainIOS)
}
if(!emu_disabled)
{
if(iosLoaded) ISFS_Deinitialize();
ISFS_Initialize();
Nand::Instance()->Set_FullMode(emulate_mode);
if(Nand::Instance()->Enable_Emu() < 0)
{ {
Nand::Instance()->Disable_Emu(); u8 IOS[3];
error(L"Enabling emu after reload failed!"); IOS[0] = gameIOS;
if(iosLoaded) Sys_LoadMenu(); IOS[1] = 56;
return; IOS[2] = 57;
bool found = false;
for(u8 num = 0; num < 3; num++)
{
if(found)
break;
if(IOS[num] == 0)
continue;
for(CIOSItr itr = _installed_cios.begin(); itr != _installed_cios.end(); itr++)
{
if(itr->second == IOS[num] || itr->first == IOS[num])
{
gameIOS = itr->first;
found = true;
break;
}
}
}
if(!found)
{
error(sfmt("Couldn't find a cIOS using base %i, or 56/57", IOS[0]));
return;
}
} }
if(gameIOS != mainIOS)
{
gprintf("Reloading IOS into %d\n", gameIOS);
if(!loadIOS(gameIOS, false))
{
_reload_wifi_gecko();
error(sfmt("Couldn't reload to cIOS %i", gameIOS));
return;
}
if(!emu_disabled)
{
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false);
DeviceHandler::Instance()->UnMount(emuPartition);
if(emulate_mode == 3)
Nand::Instance()->Set_RCMode(true);
else if(emulate_mode == 2)
Nand::Instance()->Set_FullMode(true);
else
Nand::Instance()->Set_FullMode(false);
if(Nand::Instance()->Enable_Emu() < 0)
{
Nand::Instance()->Disable_Emu();
error(L"Enabling emu after reload failed!");
Sys_LoadMenu();
return;
}
DeviceHandler::Instance()->Mount(emuPartition);
}
}
} }
if (rtrn != NULL && strlen(rtrn) == 4) if(rtrn != NULL && strlen(rtrn) == 4)
{ {
int rtrnID = rtrn[0] << 24 | rtrn[1] << 16 | rtrn[2] << 8 | rtrn[3]; int rtrnID = rtrn[0] << 24 | rtrn[1] << 16 | rtrn[2] << 8 | rtrn[3];
@ -991,15 +1055,13 @@ void CMenu::_launchChannel(dir_discHdr *hdr)
IOS_Close(ESHandle); IOS_Close(ESHandle);
} }
if (disableIOSreload) IOSReloadBlock(IOS_GetVersion(), disableIOSreload);
IOSReloadBlock(IOS_GetVersion(), false);
else
IOSReloadBlock(IOS_GetVersion(), true);
CheckGameSoundThread(); CheckGameSoundThread();
cleanup(); cleanup();
Close_Inputs(); Close_Inputs();
USBStorage_Deinit(); USBStorage_Deinit();
if(currentPartition == 0 && !forwarder) if(currentPartition == 0 && !forwarder)
SDHC_Init(); SDHC_Init();
@ -1240,9 +1302,9 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
Nand::Instance()->Init(emuPath.c_str(), emuPartition, false); Nand::Instance()->Init(emuPath.c_str(), emuPartition, false);
DeviceHandler::Instance()->UnMount(emuPartition); DeviceHandler::Instance()->UnMount(emuPartition);
if (emuSave == 3) if(emuSave == 3)
Nand::Instance()->Set_RCMode(true); Nand::Instance()->Set_RCMode(true);
else if (emuSave == 4) else if(emuSave == 4)
Nand::Instance()->Set_FullMode(true); Nand::Instance()->Set_FullMode(true);
else else
Nand::Instance()->Set_FullMode(false); Nand::Instance()->Set_FullMode(false);