Skip to content

Commit

Permalink
Merge pull request #2353 from JosJuice/wii-partition-cleanup
Browse files Browse the repository at this point in the history
VolumeWiiCrypted: Replace ChangePartition with a partition parameter
  • Loading branch information
JosJuice committed May 16, 2017
2 parents f4e8a01 + 2bcad57 commit fa06d10
Show file tree
Hide file tree
Showing 35 changed files with 653 additions and 671 deletions.
16 changes: 9 additions & 7 deletions Source/Core/Core/Boot/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ static const DiscIO::IVolume* SetDisc(std::unique_ptr<DiscIO::IVolume> volume)
}

bool CBoot::DVDRead(const DiscIO::IVolume& volume, u64 dvd_offset, u32 output_address, u32 length,
bool decrypt)
const DiscIO::Partition& partition)
{
std::vector<u8> buffer(length);
if (!volume.Read(dvd_offset, length, buffer.data(), decrypt))
if (!volume.Read(dvd_offset, length, buffer.data(), partition))
return false;
Memory::CopyToEmu(output_address, buffer.data(), length);
return true;
Expand All @@ -64,8 +64,10 @@ void CBoot::Load_FST(bool is_wii, const DiscIO::IVolume* volume)
if (!volume)
return;

const DiscIO::Partition partition = volume->GetGamePartition();

// copy first 32 bytes of disc to start of Mem 1
DVDRead(*volume, /*offset*/ 0, /*address*/ 0, /*length*/ 0x20, false);
DVDRead(*volume, /*offset*/ 0, /*address*/ 0, /*length*/ 0x20, DiscIO::PARTITION_NONE);

// copy of game id
Memory::Write_U32(Memory::Read_U32(0x0000), 0x3180);
Expand All @@ -78,15 +80,15 @@ void CBoot::Load_FST(bool is_wii, const DiscIO::IVolume* volume)
u32 fst_size = 0;
u32 max_fst_size = 0;

volume->ReadSwapped(0x0424, &fst_offset, is_wii);
volume->ReadSwapped(0x0428, &fst_size, is_wii);
volume->ReadSwapped(0x042c, &max_fst_size, is_wii);
volume->ReadSwapped(0x0424, &fst_offset, partition);
volume->ReadSwapped(0x0428, &fst_size, partition);
volume->ReadSwapped(0x042c, &max_fst_size, partition);

u32 arena_high = Common::AlignDown(0x817FFFFF - (max_fst_size << shift), 0x20);
Memory::Write_U32(arena_high, 0x00000034);

// load FST
DVDRead(*volume, fst_offset << shift, arena_high, fst_size << shift, is_wii);
DVDRead(*volume, fst_offset << shift, arena_high, fst_size << shift, partition);
Memory::Write_U32(arena_high, 0x00000038);
Memory::Write_U32(max_fst_size << shift, 0x0000003c);

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Boot/Boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace DiscIO
{
class IVolume;
struct Partition;
}

struct RegionSetting
Expand Down Expand Up @@ -46,7 +47,7 @@ class CBoot

private:
static bool DVDRead(const DiscIO::IVolume& volume, u64 dvd_offset, u32 output_address, u32 length,
bool decrypt);
const DiscIO::Partition& partition);
static void RunFunction(u32 address);

static void UpdateDebugger_MapLoaded();
Expand Down
24 changes: 14 additions & 10 deletions Source/Core/Core/Boot/Boot_BS2Emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,24 @@ void CBoot::SetupBAT(bool is_wii)

bool CBoot::RunApploader(bool is_wii, const DiscIO::IVolume& volume)
{
const DiscIO::Partition partition = volume.GetGamePartition();

// Load Apploader to Memory - The apploader is hardcoded to begin at 0x2440 on the disc,
// but the size can differ between discs. Compare with YAGCD chap 13.
const u32 apploader_offset = 0x2440;
u32 apploader_entry = 0;
u32 apploader_size = 0;
u32 apploader_trailer = 0;
if (!volume.ReadSwapped(apploader_offset + 0x10, &apploader_entry, is_wii) ||
!volume.ReadSwapped(apploader_offset + 0x14, &apploader_size, is_wii) ||
!volume.ReadSwapped(apploader_offset + 0x18, &apploader_trailer, is_wii) ||
if (!volume.ReadSwapped(apploader_offset + 0x10, &apploader_entry, partition) ||
!volume.ReadSwapped(apploader_offset + 0x14, &apploader_size, partition) ||
!volume.ReadSwapped(apploader_offset + 0x18, &apploader_trailer, partition) ||
apploader_entry == (u32)-1 || apploader_size + apploader_trailer == (u32)-1)
{
INFO_LOG(BOOT, "Invalid apploader. Your disc image is probably corrupted.");
return false;
}
DVDRead(volume, apploader_offset + 0x20, 0x01200000, apploader_size + apploader_trailer, is_wii);
DVDRead(volume, apploader_offset + 0x20, 0x01200000, apploader_size + apploader_trailer,
partition);

// TODO - Make Apploader(or just RunFunction()) debuggable!!!

Expand Down Expand Up @@ -132,7 +135,7 @@ bool CBoot::RunApploader(bool is_wii, const DiscIO::IVolume& volume)

INFO_LOG(MASTER_LOG, "DVDRead: offset: %08x memOffset: %08x length: %i", iDVDOffset,
iRamAddress, iLength);
DVDRead(volume, iDVDOffset, iRamAddress, iLength, is_wii);
DVDRead(volume, iDVDOffset, iRamAddress, iLength, partition);

} while (PowerPC::ppcState.gpr[3] != 0x00);

Expand Down Expand Up @@ -163,7 +166,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::IVolume* volume, bool skip_app_loader)

// It's possible to boot DOL and ELF files without a disc inserted
if (volume)
DVDRead(*volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, false);
DVDRead(*volume, /*offset*/ 0x00000000, /*address*/ 0x00000000, 0x20, DiscIO::PARTITION_NONE);

// Booted from bootrom. 0xE5207C22 = booted from jtag
PowerPC::HostWrite_U32(0x0D15EA5E, 0x80000020);
Expand Down Expand Up @@ -280,7 +283,7 @@ bool CBoot::SetupWiiMemory(const DiscIO::IVolume* volume, u64 ios_title_id)

// When booting a WAD or the system menu, there will probably not be a disc inserted
if (volume)
DVDRead(*volume, 0x00000000, 0x00000000, 0x20, false); // Game Code
DVDRead(*volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code

Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word
Memory::Write_U32(0x00000001, 0x00000024); // Unknown
Expand Down Expand Up @@ -335,7 +338,8 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::IVolume* volume)
if (volume->GetVolumeType() != DiscIO::Platform::WII_DISC)
return false;

const IOS::ES::TMDReader tmd = volume->GetTMD();
const DiscIO::Partition partition = volume->GetGamePartition();
const IOS::ES::TMDReader tmd = volume->GetTMD(partition);

if (!SetupWiiMemory(volume, tmd.GetIOSId()))
return false;
Expand All @@ -344,7 +348,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::IVolume* volume)
// values as the game boots. This location keeps the 4 byte ID for as long
// as the game is running. The 6 byte ID at 0x00 is overwritten sometime
// after this check during booting.
DVDRead(*volume, 0, 0x3180, 4, true);
DVDRead(*volume, 0, 0x3180, 4, partition);

SetupBAT(/*is_wii*/ true);

Expand All @@ -359,7 +363,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::IVolume* volume)

// Warning: This call will set incorrect running game metadata if our volume parameter
// doesn't point to the same disc as the one that's inserted in the emulated disc drive!
IOS::HLE::Device::ES::DIVerify(tmd, volume->GetTicket());
IOS::HLE::Device::ES::DIVerify(tmd, volume->GetTicket(partition));

return true;
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "Core/FifoPlayer/FifoDataFile.h"
#include "Core/HLE/HLE.h"
#include "Core/HW/DVD/DVDInterface.h"
#include "Core/HW/DVD/DVDThread.h"
#include "Core/HW/SI/SI.h"
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/USB/Bluetooth/BTBase.h"
Expand Down Expand Up @@ -746,11 +745,12 @@ void SConfig::ResetRunningGameMetadata()
SetRunningGameMetadata("00000000", 0, 0);
}

void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume)
void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume,
const DiscIO::Partition& partition)
{
u64 title_id = 0;
volume.GetTitleID(&title_id);
SetRunningGameMetadata(volume.GetGameID(), title_id, volume.GetRevision());
volume.GetTitleID(&title_id, partition);
SetRunningGameMetadata(volume.GetGameID(partition), title_id, volume.GetRevision(partition));
}

void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd)
Expand All @@ -761,7 +761,7 @@ void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd)
// the disc header instead of the TMD. They can differ.
// (IOS HLE ES calls us with a TMDReader rather than a volume when launching
// a disc game, because ES has no reason to be accessing the disc directly.)
if (!DVDThread::UpdateRunningGameMetadata(tmd_title_id))
if (!DVDInterface::UpdateRunningGameMetadata(tmd_title_id))
{
// If not launching a disc game, just read everything from the TMD.
SetRunningGameMetadata(tmd.GetGameID(), tmd_title_id, tmd.GetTitleVersion());
Expand Down Expand Up @@ -935,7 +935,7 @@ bool SConfig::AutoSetup(EBootBS2 _BootBS2)
m_strFilename.c_str());
return false;
}
SetRunningGameMetadata(*pVolume);
SetRunningGameMetadata(*pVolume, pVolume->GetGamePartition());

// Check if we have a Wii disc
bWii = pVolume->GetVolumeType() == DiscIO::Platform::WII_DISC;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace DiscIO
{
enum class Language;
enum class Region;
struct Partition;
class IVolume;
}
namespace IOS
Expand Down Expand Up @@ -226,7 +227,7 @@ struct SConfig : NonCopyable
u64 GetTitleID() const { return m_title_id; }
u16 GetRevision() const { return m_revision; }
void ResetRunningGameMetadata();
void SetRunningGameMetadata(const DiscIO::IVolume& volume);
void SetRunningGameMetadata(const DiscIO::IVolume& volume, const DiscIO::Partition& partition);
void SetRunningGameMetadata(const IOS::ES::TMDReader& tmd);

void LoadDefaults();
Expand Down

0 comments on commit fa06d10

Please sign in to comment.