Skip to content
Permalink
Browse files

Merge pull request #8243 from JosJuice/merge-wad-classes

DiscIO: Merge WiiWAD into VolumeWAD
  • Loading branch information...
leoetlino committed Jul 21, 2019
2 parents cd7a374 + 34f3289 commit da1fbbc5d5d0eda5fcdccadd20207b4b525f8a7e
@@ -59,6 +59,7 @@ namespace fs = std::filesystem;

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

static std::vector<std::string> ReadM3UFile(const std::string& m3u_path,
const std::string& folder_path)
@@ -161,10 +162,10 @@ BootParameters::GenerateFromFile(std::vector<std::string> paths,
{".gcm", ".iso", ".tgc", ".wbfs", ".ciso", ".gcz", ".dol", ".elf"}};
if (disc_image_extensions.find(extension) != disc_image_extensions.end() || is_drive)
{
std::unique_ptr<DiscIO::Volume> volume = DiscIO::CreateVolumeFromFilename(path);
if (volume)
std::unique_ptr<DiscIO::VolumeDisc> disc = DiscIO::CreateDisc(path);
if (disc)
{
return std::make_unique<BootParameters>(Disc{std::move(path), std::move(volume), paths},
return std::make_unique<BootParameters>(Disc{std::move(path), std::move(disc), paths},
savestate_path);
}

@@ -201,7 +202,11 @@ BootParameters::GenerateFromFile(std::vector<std::string> paths,
return std::make_unique<BootParameters>(DFF{std::move(path)}, savestate_path);

if (extension == ".wad")
return std::make_unique<BootParameters>(DiscIO::WiiWAD{std::move(path)}, savestate_path);
{
std::unique_ptr<DiscIO::VolumeWAD> wad = DiscIO::CreateWAD(std::move(path));
if (wad)
return std::make_unique<BootParameters>(std::move(*wad), savestate_path);
}

PanicAlertT("Could not recognize file %s", path.c_str());
return {};
@@ -221,19 +226,19 @@ BootParameters::IPL::IPL(DiscIO::Region region_, Disc&& disc_) : IPL(region_)
// Inserts a disc into the emulated disc drive and returns a pointer to it.
// The returned pointer must only be used while we are still booting,
// because DVDThread can do whatever it wants to the disc after that.
static const DiscIO::Volume* SetDisc(std::unique_ptr<DiscIO::Volume> volume,
std::vector<std::string> auto_disc_change_paths = {})
static const DiscIO::VolumeDisc* SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
std::vector<std::string> auto_disc_change_paths = {})
{
const DiscIO::Volume* pointer = volume.get();
DVDInterface::SetDisc(std::move(volume), auto_disc_change_paths);
const DiscIO::VolumeDisc* pointer = disc.get();
DVDInterface::SetDisc(std::move(disc), auto_disc_change_paths);
return pointer;
}

bool CBoot::DVDRead(const DiscIO::Volume& volume, u64 dvd_offset, u32 output_address, u32 length,
bool CBoot::DVDRead(const DiscIO::VolumeDisc& disc, u64 dvd_offset, u32 output_address, u32 length,
const DiscIO::Partition& partition)
{
std::vector<u8> buffer(length);
if (!volume.Read(dvd_offset, length, buffer.data(), partition))
if (!disc.Read(dvd_offset, length, buffer.data(), partition))
return false;
Memory::CopyToEmu(output_address, buffer.data(), length);
return true;
@@ -365,7 +370,7 @@ static void SetDefaultDisc()
{
const std::string default_iso = Config::Get(Config::MAIN_DEFAULT_ISO);
if (!default_iso.empty())
SetDisc(DiscIO::CreateVolumeFromFilename(default_iso));
SetDisc(DiscIO::CreateDisc(default_iso));
}

static void CopyDefaultExceptionHandlers()
@@ -401,7 +406,8 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
bool operator()(BootParameters::Disc& disc) const
{
NOTICE_LOG(BOOT, "Booting from disc: %s", disc.path.c_str());
const DiscIO::Volume* volume = SetDisc(std::move(disc.volume), disc.auto_disc_change_paths);
const DiscIO::VolumeDisc* volume =
SetDisc(std::move(disc.volume), disc.auto_disc_change_paths);

if (!volume)
return false;
@@ -465,7 +471,7 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
return true;
}

bool operator()(const DiscIO::WiiWAD& wad) const
bool operator()(const DiscIO::VolumeWAD& wad) const
{
SetDefaultDisc();
return Boot_WiiWAD(wad);
@@ -495,7 +501,7 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
if (ipl.disc)
{
NOTICE_LOG(BOOT, "Inserting disc: %s", ipl.disc->path.c_str());
SetDisc(DiscIO::CreateVolumeFromFilename(ipl.disc->path), ipl.disc->auto_disc_change_paths);
SetDisc(DiscIO::CreateDisc(ipl.disc->path), ipl.disc->auto_disc_change_paths);
}

if (LoadMapFromFilename())
@@ -17,7 +17,7 @@
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include "DiscIO/WiiWad.h"
#include "DiscIO/VolumeWad.h"

namespace File
{
@@ -39,7 +39,7 @@ struct BootParameters
struct Disc
{
std::string path;
std::unique_ptr<DiscIO::Volume> volume;
std::unique_ptr<DiscIO::VolumeDisc> volume;
std::vector<std::string> auto_disc_change_paths;
};

@@ -75,7 +75,7 @@ struct BootParameters
GenerateFromFile(std::vector<std::string> paths,
const std::optional<std::string>& savestate_path = {});

using Parameters = std::variant<Disc, Executable, DiscIO::WiiWAD, NANDTitle, IPL, DFF>;
using Parameters = std::variant<Disc, Executable, DiscIO::VolumeWAD, NANDTitle, IPL, DFF>;
BootParameters(Parameters&& parameters_, const std::optional<std::string>& savestate_path_ = {});

Parameters parameters;
@@ -102,21 +102,21 @@ class CBoot
static bool LoadMapFromFilename();

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

static void UpdateDebugger_MapLoaded();

static bool Boot_WiiWAD(const DiscIO::WiiWAD& wad);
static bool Boot_WiiWAD(const DiscIO::VolumeWAD& wad);
static bool BootNANDTitle(u64 title_id);

static void SetupMSR();
static void SetupBAT(bool is_wii);
static bool RunApploader(bool is_wii, const DiscIO::Volume& volume);
static bool EmulatedBS2_GC(const DiscIO::Volume& volume);
static bool EmulatedBS2_Wii(const DiscIO::Volume& volume);
static bool EmulatedBS2(bool is_wii, const DiscIO::Volume& volume);
static bool RunApploader(bool is_wii, const DiscIO::VolumeDisc& volume);
static bool EmulatedBS2_GC(const DiscIO::VolumeDisc& volume);
static bool EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume);
static bool EmulatedBS2(bool is_wii, const DiscIO::VolumeDisc& volume);
static bool Load_BS2(const std::string& boot_rom_filename);

static void SetupGCMemory();
@@ -85,7 +85,7 @@ void CBoot::SetupBAT(bool is_wii)
PowerPC::IBATUpdated();
}

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

@@ -200,7 +200,7 @@ void CBoot::SetupGCMemory()
// GameCube Bootstrap 2 HLE:
// copy the apploader to 0x81200000
// execute the apploader, function by function, using the above utility.
bool CBoot::EmulatedBS2_GC(const DiscIO::Volume& volume)
bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume)
{
INFO_LOG(BOOT, "Faking GC BS2...");

@@ -366,7 +366,7 @@ static void WriteEmptyPlayRecord()
// Wii Bootstrap 2 HLE:
// copy the apploader to 0x81200000
// execute the apploader
bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& volume)
bool CBoot::EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume)
{
INFO_LOG(BOOT, "Faking Wii BS2...");
if (volume.GetVolumeType() != DiscIO::Platform::WiiDisc)
@@ -426,7 +426,7 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::Volume& volume)

// Returns true if apploader has run successfully. If is_wii is true, the disc
// that volume refers to must currently be inserted into the emulated disc drive.
bool CBoot::EmulatedBS2(bool is_wii, const DiscIO::Volume& volume)
bool CBoot::EmulatedBS2(bool is_wii, const DiscIO::VolumeDisc& volume)
{
return is_wii ? EmulatedBS2_Wii(volume) : EmulatedBS2_GC(volume);
}
@@ -15,7 +15,7 @@
#include "Core/IOS/IOS.h"
#include "Core/IOS/IOSC.h"
#include "Core/WiiUtils.h"
#include "DiscIO/WiiWad.h"
#include "DiscIO/VolumeWad.h"

bool CBoot::BootNANDTitle(const u64 title_id)
{
@@ -34,7 +34,7 @@ bool CBoot::BootNANDTitle(const u64 title_id)
return es->LaunchTitle(title_id);
}

bool CBoot::Boot_WiiWAD(const DiscIO::WiiWAD& wad)
bool CBoot::Boot_WiiWAD(const DiscIO::VolumeWAD& wad)
{
if (!WiiUtils::InstallWAD(*IOS::HLE::GetIOS(), wad, WiiUtils::InstallType::Temporary))
{
@@ -49,7 +49,7 @@

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

SConfig* SConfig::m_Instance;

@@ -888,9 +888,9 @@ struct SetGameMetadata
return true;
}

bool operator()(const DiscIO::WiiWAD& wad) const
bool operator()(const DiscIO::VolumeWAD& wad) const
{
if (!wad.IsValid() || !wad.GetTMD().IsValid())
if (!wad.GetTMD().IsValid())
{
PanicAlertT("This WAD is not valid.");
return false;
@@ -470,7 +470,7 @@ void Shutdown()
DVDThread::Stop();
}

void SetDisc(std::unique_ptr<DiscIO::Volume> disc,
void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
std::optional<std::vector<std::string>> auto_disc_change_paths = {})
{
if (disc)
@@ -506,11 +506,10 @@ static void EjectDiscCallback(u64 userdata, s64 cyclesLate)

static void InsertDiscCallback(u64 userdata, s64 cyclesLate)
{
std::unique_ptr<DiscIO::Volume> new_volume =
DiscIO::CreateVolumeFromFilename(s_disc_path_to_insert);
std::unique_ptr<DiscIO::VolumeDisc> new_disc = DiscIO::CreateDisc(s_disc_path_to_insert);

if (new_volume)
SetDisc(std::move(new_volume), {});
if (new_disc)
SetDisc(std::move(new_disc), {});
else
PanicAlertT("The disc that was about to be inserted couldn't be found.");

@@ -14,7 +14,7 @@
class PointerWrap;
namespace DiscIO
{
class Volume;
class VolumeDisc;
struct Partition;
} // namespace DiscIO
namespace MMIO
@@ -81,7 +81,7 @@ void DoState(PointerWrap& p);

void RegisterMMIO(MMIO::Mapping* mmio, u32 base);

void SetDisc(std::unique_ptr<DiscIO::Volume> disc,
void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
std::optional<std::vector<std::string>> auto_disc_change_paths);
bool IsDiscInside();
void EjectDisc(); // Must only be called on the CPU thread
@@ -42,13 +42,13 @@
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeFileBlobReader.h"
#include "DiscIO/WiiWad.h"
#include "DiscIO/VolumeWad.h"

namespace WiiUtils
{
static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::WiiWAD& wad)
static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad)
{
if (!wad.IsValid())
if (!wad.GetTicket().IsValid() || !wad.GetTMD().IsValid())
{
PanicAlertT("WAD installation failed: The selected file is not a valid WAD.");
return false;
@@ -110,7 +110,7 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::WiiWAD& wad)
return true;
}

bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::WiiWAD& wad, InstallType install_type)
bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, InstallType install_type)
{
if (!wad.GetTMD().IsValid())
return false;
@@ -164,8 +164,12 @@ bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::WiiWAD& wad, InstallType in

bool InstallWAD(const std::string& wad_path)
{
std::unique_ptr<DiscIO::VolumeWAD> wad = DiscIO::CreateWAD(wad_path);
if (!wad)
return false;

IOS::HLE::Kernel ios;
return InstallWAD(ios, DiscIO::WiiWAD{wad_path}, InstallType::Permanent);
return InstallWAD(ios, *wad, InstallType::Permanent);
}

bool UninstallTitle(u64 title_id)
@@ -581,8 +585,7 @@ class DiscSystemUpdater final : public SystemUpdater
{
public:
DiscSystemUpdater(UpdateCallback update_callback, const std::string& image_path)
: m_update_callback{std::move(update_callback)}, m_volume{DiscIO::CreateVolumeFromFilename(
image_path)}
: m_update_callback{std::move(update_callback)}, m_volume{DiscIO::CreateDisc(image_path)}
{
}
UpdateResult DoDiscUpdate();
@@ -621,7 +624,7 @@ class DiscSystemUpdater final : public SystemUpdater
std::string_view path);

UpdateCallback m_update_callback;
std::unique_ptr<DiscIO::Volume> m_volume;
std::unique_ptr<DiscIO::VolumeDisc> m_volume;
DiscIO::Partition m_partition;
};

@@ -735,7 +738,7 @@ UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs,
ERROR_LOG(CORE, "Could not find %s", std::string(path).c_str());
return UpdateResult::DiscReadFailed;
}
const DiscIO::WiiWAD wad{std::move(blob)};
const DiscIO::VolumeWAD wad{std::move(blob)};
return ImportWAD(m_ios, wad) ? UpdateResult::Succeeded : UpdateResult::ImportFailed;
}

@@ -15,7 +15,7 @@

namespace DiscIO
{
class WiiWAD;
class VolumeWAD;
}

namespace IOS::HLE
@@ -31,8 +31,8 @@ enum class InstallType
Temporary,
};

bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::WiiWAD& wad, InstallType type);
// Same as the above, but constructs a temporary IOS and WiiWAD instance for importing
bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, InstallType type);
// Same as the above, but constructs a temporary IOS and VolumeWAD instance for importing
// and does a permanent install.
bool InstallWAD(const std::string& wad_path);

@@ -41,8 +41,6 @@ add_library(discio
WbfsBlob.h
WiiSaveBanner.cpp
WiiSaveBanner.h
WiiWad.cpp
WiiWad.h
)

target_link_libraries(discio
@@ -182,10 +182,10 @@ bool CompressFileToBlob(const std::string& infile_path, const std::string& outfi
}

DiscScrubber disc_scrubber;
std::unique_ptr<Volume> volume;
std::unique_ptr<VolumeDisc> volume;
if (sub_type == 1)
{
volume = CreateVolumeFromFilename(infile_path);
volume = CreateDisc(infile_path);
if (!volume || !disc_scrubber.SetupScrub(volume.get(), block_size))
{
PanicAlertT("\"%s\" failed to be scrubbed. Probably the image is corrupt.",
@@ -57,7 +57,6 @@
<ClCompile Include="VolumeWii.cpp" />
<ClCompile Include="WbfsBlob.cpp" />
<ClCompile Include="WiiSaveBanner.cpp" />
<ClCompile Include="WiiWad.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Blob.h" />
@@ -81,7 +80,6 @@
<ClInclude Include="VolumeWii.h" />
<ClInclude Include="WbfsBlob.h" />
<ClInclude Include="WiiSaveBanner.h" />
<ClInclude Include="WiiWad.h" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />

0 comments on commit da1fbbc

Please sign in to comment.
You can’t perform that action at this time.