Modify state.dat before launching wads. Fixes Liight, maybe others. If in doubt, install the wad to the nand.

This commit is contained in:
Matthew Parlane 2012-04-21 16:21:13 +12:00
parent c08510baa8
commit 0fc390b552
3 changed files with 58 additions and 4 deletions

View File

@ -121,6 +121,8 @@
#define GC_MEMCARDA "MemoryCardA"
#define GC_MEMCARDB "MemoryCardB"
#define WII_STATE "state.dat"
#define WII_SETTING "setting.txt"
#define WII_EUR_SETTING "setting-eur.txt"
#define WII_USA_SETTING "setting-usa.txt"

View File

@ -32,8 +32,57 @@
#include "VolumeCreator.h"
#include "CommonPaths.h"
static u32 state_checksum(u32 *buf, int len)
{
u32 checksum = 0;
len = len>>2;
for(int i=0; i<len; i++)
{
checksum += buf[i];
}
return checksum;
}
typedef struct {
u32 checksum;
u8 flags;
u8 type;
u8 discstate;
u8 returnto;
u32 unknown[6];
} StateFlags;
bool CBoot::Boot_WiiWAD(const char* _pFilename)
{
std::string state_filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_STATE);
if (File::Exists(state_filename))
{
File::IOFile state_file(state_filename, "r+b");
StateFlags state;
state_file.ReadBytes(&state, sizeof(StateFlags));
state.type = 0x03; // TYPE_RETURN
state.checksum = state_checksum((u32*)&state.flags, sizeof(StateFlags)-4);
state_file.Seek(0, SEEK_SET);
state_file.WriteBytes(&state, sizeof(StateFlags));
}
else
{
File::CreateFullPath(state_filename);
File::IOFile state_file(state_filename, "a+b");
StateFlags state;
memset(&state,0,sizeof(StateFlags));
state.type = 0x03; // TYPE_RETURN
state.discstate = 0x01; // DISCSTATE_WII
state.checksum = state_checksum((u32*)&state.flags, sizeof(StateFlags)-4);
state_file.WriteBytes(&state, sizeof(StateFlags));
}
const DiscIO::INANDContentLoader& ContentLoader = DiscIO::CNANDContentManager::Access().GetNANDLoader(_pFilename);
if (!ContentLoader.IsValid())
return false;

View File

@ -266,8 +266,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
m_ContentAccessMap[CFD].m_Position = 0;
m_ContentAccessMap[CFD].m_pContent = AccessContentDevice(m_TitleID).GetContentByIndex(Index);
_dbg_assert_(WII_IPC_ES, m_ContentAccessMap[CFD].m_pContent != NULL);
if (m_ContentAccessMap[CFD].m_pContent == NULL)
CFD = 0xffffffff; //TODO: what is the correct error value here?
@ -740,6 +739,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
{
_dbg_assert_(WII_IPC_ES, Buffer.NumberInBuffer == 2);
bool bSuccess = false;
bool reloadIOS = false;
u16 IOSv = 0xffff;
u64 TitleID = Memory::Read_U64(Buffer.InBuffer[0].m_Address);
@ -776,14 +776,16 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
// Lie to mem about loading a different ios
// someone with an affected game should test
IOSv = TitleID & 0xffff;
reloadIOS = true;
}
if (!bSuccess)
{
PanicAlertT("IOCTL_ES_LAUNCH: Game tried to reload ios or a title that is not available in your nand dump\n"
"TitleID %016llx.\n Dolphin will likely hang now", TitleID);
}
else
else if (reloadIOS)
{
std::string tContentFile(m_ContentFile.c_str());
WII_IPC_HLE_Interface::Reset(true);
WII_IPC_HLE_Interface::Init();
@ -800,7 +802,8 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
s_Usb->m_WiiMotes[i].Activate(false);
}
}
WII_IPC_HLE_Interface::SetDefaultContentFile(tContentFile);
}
// Pass the "#002 check"
// Apploader should write the IOS version and revision to 0x3140, and compare it