diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 94bd4ef2b8..9d12c2188d 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -100,8 +100,8 @@ std::unique_ptr BootParameters::GenerateFromFile(const std::stri if (extension == ".dff") return std::make_unique(DFF{path}); - if (DiscIO::NANDContentManager::Access().GetNANDLoader(path).IsValid()) - return std::make_unique(NAND{path}); + if (extension == ".wad") + return std::make_unique(DiscIO::WiiWAD{path}); PanicAlertT("Could not recognize file %s", path.c_str()); return {}; @@ -357,11 +357,10 @@ bool CBoot::BootUp(std::unique_ptr 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 diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index b3bc5fab36..9295244bcb 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -13,8 +13,10 @@ #include #include "Common/CommonTypes.h" +#include "DiscIO/Blob.h" #include "DiscIO/Enums.h" #include "DiscIO/Volume.h" +#include "DiscIO/WiiWad.h" namespace File { @@ -45,11 +47,6 @@ struct BootParameters std::unique_ptr reader; }; - struct NAND - { - std::string content_path; - }; - struct NANDTitle { u64 id; @@ -72,7 +69,7 @@ struct BootParameters static std::unique_ptr GenerateFromFile(const std::string& path); - using Parameters = std::variant; + using Parameters = std::variant; BootParameters(Parameters&& parameters_); Parameters parameters; @@ -103,7 +100,7 @@ private: 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(); diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index de4275c14a..1aa8193fff 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -18,8 +18,10 @@ #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::BootNANDTitle(const u64 title_id) { @@ -35,46 +37,12 @@ bool CBoot::BootNANDTitle(const u64 title_id) return ios->GetES()->LaunchTitle(title_id); } -bool CBoot::Boot_WiiWAD(const std::string& _pFilename) +bool CBoot::Boot_WiiWAD(const DiscIO::WiiWAD& wad) { - 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)) + if (!WiiUtils::InstallWAD(*IOS::HLE::GetIOS(), wad)) { - PanicAlertT("This WAD is not bootable."); + PanicAlertT("Cannot boot this WAD because it could not be installed to the NAND."); return false; } - - // create data directory - File::CreateFullPath(Common::GetTitleDataPath(titleID, Common::FROM_SESSION_ROOT)); - - if (titleID == 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. - 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()); - - if (!ios->BootstrapPPC(ContentLoader)) - return false; - - return true; + return BootNANDTitle(wad.GetTMD().GetTitleId()); } diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index c5d39b5530..5c074768d0 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -45,6 +45,7 @@ #include "DiscIO/Enums.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" +#include "DiscIO/WiiWad.h" SConfig* SConfig::m_Instance; @@ -888,14 +889,20 @@ 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(); diff --git a/Source/Core/DiscIO/WiiWad.h b/Source/Core/DiscIO/WiiWad.h index 6f3f4a97bc..1bdd40f698 100644 --- a/Source/Core/DiscIO/WiiWad.h +++ b/Source/Core/DiscIO/WiiWad.h @@ -20,6 +20,8 @@ class WiiWAD public: explicit WiiWAD(const std::string& name); explicit WiiWAD(std::unique_ptr blob_reader); + WiiWAD(WiiWAD&&) = default; + WiiWAD& operator=(WiiWAD&&) = default; ~WiiWAD(); bool IsValid() const { return m_valid; }