Skip to content
Permalink
Browse files
Merge pull request #6094 from leoetlino/drop-wad-hack
Drop the direct WAD launch hack
  • Loading branch information
leoetlino committed Oct 26, 2017
2 parents 5393575 + 4cc1bd9 commit c4914fb
Show file tree
Hide file tree
Showing 45 changed files with 460 additions and 844 deletions.
@@ -46,7 +46,6 @@
#include "Core/PowerPC/PowerPC.h"

#include "DiscIO/Enums.h"
#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/Volume.h"

BootParameters::BootParameters(Parameters&& parameters_) : parameters(std::move(parameters_))
@@ -100,8 +99,8 @@ std::unique_ptr<BootParameters> BootParameters::GenerateFromFile(const std::stri
if (extension == ".dff")
return std::make_unique<BootParameters>(DFF{path});

if (DiscIO::NANDContentManager::Access().GetNANDLoader(path).IsValid())
return std::make_unique<BootParameters>(NAND{path});
if (extension == ".wad")
return std::make_unique<BootParameters>(DiscIO::WiiWAD{path});

PanicAlertT("Could not recognize file %s", path.c_str());
return {};
@@ -339,7 +338,8 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
HID4.SBE = 1;
// Because there is no TMD to get the requested system (IOS) version from,
// we default to IOS58, which is the version used by the Homebrew Channel.
SetupWiiMemory(0x000000010000003a);
SetupWiiMemory();
IOS::HLE::GetIOS()->BootIOS(Titles::IOS(58));
}
else
{
@@ -356,11 +356,16 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
return true;
}

bool operator()(const BootParameters::NAND& nand) const
bool operator()(const DiscIO::WiiWAD& wad) const
{
NOTICE_LOG(BOOT, "Booting from NAND: %s", nand.content_path.c_str());
SetDefaultDisc();
return Boot_WiiWAD(nand.content_path);
return Boot_WiiWAD(wad);
}

bool operator()(const BootParameters::NANDTitle& nand_title) const
{
SetDefaultDisc();
return BootNANDTitle(nand_title.id);
}

bool operator()(const BootParameters::IPL& ipl) const
@@ -13,8 +13,10 @@
#include <vector>

#include "Common/CommonTypes.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include "DiscIO/WiiWad.h"

namespace File
{
@@ -45,9 +47,9 @@ struct BootParameters
std::unique_ptr<BootExecutableReader> reader;
};

struct NAND
struct NANDTitle
{
std::string content_path;
u64 id;
};

struct IPL
@@ -67,7 +69,7 @@ struct BootParameters

static std::unique_ptr<BootParameters> GenerateFromFile(const std::string& path);

using Parameters = std::variant<Disc, Executable, NAND, IPL, DFF>;
using Parameters = std::variant<Disc, Executable, DiscIO::WiiWAD, NANDTitle, IPL, DFF>;
BootParameters(Parameters&& parameters_);

Parameters parameters;
@@ -98,7 +100,8 @@ class CBoot

static void UpdateDebugger_MapLoaded();

static bool Boot_WiiWAD(const std::string& filename);
static bool Boot_WiiWAD(const DiscIO::WiiWAD& wad);
static bool BootNANDTitle(u64 title_id);

static void SetupMSR();
static void SetupBAT(bool is_wii);
@@ -109,7 +112,7 @@ class CBoot
static bool Load_BS2(const std::string& boot_rom_filename);

static void SetupGCMemory();
static bool SetupWiiMemory(u64 ios_title_id);
static bool SetupWiiMemory();
};

class BootExecutableReader
@@ -213,7 +213,7 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::Volume& volume)
return RunApploader(/*is_wii*/ false, volume);
}

bool CBoot::SetupWiiMemory(u64 ios_title_id)
bool CBoot::SetupWiiMemory()
{
static const std::map<DiscIO::Region, const RegionSetting> region_settings = {
{DiscIO::Region::NTSC_J, {"JPN", "NTSC", "JP", "LJ"}},
@@ -308,9 +308,6 @@ bool CBoot::SetupWiiMemory(u64 ios_title_id)
// It is fine to always use the latest value as apploaders work with all versions.
Memory::Write_U16(0x0113, 0x0000315e);

if (!IOS::HLE::GetIOS()->BootIOS(ios_title_id))
return false;

Memory::Write_U8(0x80, 0x0000315c); // OSInit
Memory::Write_U16(0x0000, 0x000030e0); // PADInit
Memory::Write_U32(0x80000000, 0x00003184); // GameID Address
@@ -367,7 +364,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& volume)
Memory::Write_U32(0, 0x3194);
Memory::Write_U32(static_cast<u32>(data_partition.offset >> 2), 0x3198);

if (!SetupWiiMemory(tmd.GetIOSId()))
if (!SetupWiiMemory() || !IOS::HLE::GetIOS()->BootIOS(tmd.GetIOSId()))
return false;

DVDRead(volume, 0x00000000, 0x00000000, 0x20, DiscIO::PARTITION_NONE); // Game Code
@@ -392,7 +389,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& 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(partition));
IOS::HLE::GetIOS()->GetES()->DIVerify(tmd, volume.GetTicket(partition));

return true;
}
@@ -18,49 +18,30 @@
#include "Core/IOS/ES/Formats.h"
#include "Core/IOS/FS/FileIO.h"
#include "Core/IOS/IOS.h"
#include "Core/WiiUtils.h"

#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/WiiWad.h"

bool CBoot::Boot_WiiWAD(const std::string& _pFilename)
bool CBoot::BootNANDTitle(const u64 title_id)
{
UpdateStateFlags([](StateFlags* state) {
state->type = 0x03; // TYPE_RETURN
});

const DiscIO::NANDContentLoader& ContentLoader =
DiscIO::NANDContentManager::Access().GetNANDLoader(_pFilename);
if (!ContentLoader.IsValid())
return false;

u64 titleID = ContentLoader.GetTMD().GetTitleId();

if (!IOS::ES::IsChannel(titleID))
{
PanicAlertT("This WAD is not bootable.");
return false;
}

// create data directory
File::CreateFullPath(Common::GetTitleDataPath(titleID, Common::FROM_SESSION_ROOT));

if (titleID == Titles::SYSTEM_MENU)
if (title_id == Titles::SYSTEM_MENU)
IOS::HLE::CreateVirtualFATFilesystem();
// setup Wii memory

if (!SetupWiiMemory(ContentLoader.GetTMD().GetIOSId()))
return false;

IOS::HLE::Device::ES::LoadWAD(_pFilename);

// TODO: kill these manual calls and just use ES_Launch here, as soon as the direct WAD
// launch hack is dropped.
SetupWiiMemory();
auto* ios = IOS::HLE::GetIOS();
IOS::ES::UIDSys uid_map{Common::FROM_SESSION_ROOT};
ios->SetUidForPPC(uid_map.GetOrInsertUIDForTitle(titleID));
ios->SetGidForPPC(ContentLoader.GetTMD().GetGroupId());
return ios->GetES()->LaunchTitle(title_id);
}

if (!ios->BootstrapPPC(ContentLoader))
bool CBoot::Boot_WiiWAD(const DiscIO::WiiWAD& wad)
{
if (!WiiUtils::InstallWAD(*IOS::HLE::GetIOS(), wad, WiiUtils::InstallType::Temporary))
{
PanicAlertT("Cannot boot this WAD because it could not be installed to the NAND.");
return false;

return true;
}
return BootNANDTitle(wad.GetTMD().GetTitleId());
}
@@ -12,11 +12,16 @@ constexpr u64 BOOT2 = 0x0000000100000001;

constexpr u64 SYSTEM_MENU = 0x0000000100000002;

// IOS used by the latest System Menu (4.3). Corresponds to IOS80.
constexpr u64 SYSTEM_MENU_IOS = 0x0000000100000050;
constexpr u64 SHOP = 0x0001000248414241;

constexpr u64 IOS(u32 major_version)
{
return 0x0000000100000000 | major_version;
}

constexpr u64 BC = 0x0000000100000100;
constexpr u64 MIOS = 0x0000000100000101;
// IOS used by the latest System Menu (4.3). Corresponds to IOS80.
constexpr u64 SYSTEM_MENU_IOS = IOS(80);

constexpr u64 SHOP = 0x0001000248414241;
constexpr u64 BC = IOS(0x100);
constexpr u64 MIOS = IOS(0x101);
} // namespace Titles
@@ -43,8 +43,8 @@
#include "VideoCommon/HiresTextures.h"

#include "DiscIO/Enums.h"
#include "DiscIO/NANDContentLoader.h"
#include "DiscIO/Volume.h"
#include "DiscIO/WiiWad.h"

SConfig* SConfig::m_Instance;

@@ -888,14 +888,35 @@ struct SetGameMetadata
return true;
}

bool operator()(const BootParameters::NAND& nand) const
bool operator()(const DiscIO::WiiWAD& wad) const
{
const auto& loader = DiscIO::NANDContentManager::Access().GetNANDLoader(nand.content_path);
if (!loader.IsValid())
if (!wad.IsValid() || !wad.GetTMD().IsValid())
{
PanicAlertT("This WAD is not valid.");
return false;
}
if (!IOS::ES::IsChannel(wad.GetTMD().GetTitleId()))
{
PanicAlertT("This WAD is not bootable.");
return false;
}

const IOS::ES::TMDReader& tmd = loader.GetTMD();
const IOS::ES::TMDReader& tmd = wad.GetTMD();
config->SetRunningGameMetadata(tmd);
config->bWii = true;
*region = tmd.GetRegion();
return true;
}

bool operator()(const BootParameters::NANDTitle& nand_title) const
{
IOS::HLE::Kernel ios;
const IOS::ES::TMDReader tmd = ios.GetES()->FindInstalledTMD(nand_title.id);
if (!tmd.IsValid() || !IOS::ES::IsChannel(nand_title.id))
{
PanicAlertT("This title cannot be booted.");
return false;
}
config->SetRunningGameMetadata(tmd);
config->bWii = true;
*region = tmd.GetRegion();
@@ -113,7 +113,7 @@ IPCCommandResult DI::IOCtlV(const IOCtlVRequest& request)
const IOS::ES::TMDReader tmd = DVDThread::GetTMD(partition);
const std::vector<u8>& raw_tmd = tmd.GetBytes();
Memory::CopyToEmu(request.io_vectors[0].address, raw_tmd.data(), raw_tmd.size());
ES::DIVerify(tmd, DVDThread::GetTicket(partition));
m_ios.GetES()->DIVerify(tmd, DVDThread::GetTicket(partition));

return_value = 1;
break;

0 comments on commit c4914fb

Please sign in to comment.