mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 18:01:56 +00:00
IOS/ES: Split ESDevice into ESCore and ESDevice.
ESCore implements the core functionality that can also be used outside of emulation. ESDevice implements the IOS device and is only available during emulation.
This commit is contained in:
parent
361a8b2c8e
commit
6a339cbdb3
24 changed files with 454 additions and 397 deletions
|
@ -49,7 +49,7 @@
|
|||
namespace WiiUtils
|
||||
{
|
||||
static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad,
|
||||
IOS::HLE::ESDevice::VerifySignature verify_signature)
|
||||
IOS::HLE::ESCore::VerifySignature verify_signature)
|
||||
{
|
||||
if (!wad.GetTicket().IsValid() || !wad.GetTMD().IsValid())
|
||||
{
|
||||
|
@ -58,20 +58,20 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad,
|
|||
}
|
||||
|
||||
const auto tmd = wad.GetTMD();
|
||||
const auto es = ios.GetES();
|
||||
auto& es = ios.GetESCore();
|
||||
const auto fs = ios.GetFS();
|
||||
|
||||
IOS::HLE::ESDevice::Context context;
|
||||
IOS::HLE::ESCore::Context context;
|
||||
IOS::HLE::ReturnCode ret;
|
||||
|
||||
// Ensure the common key index is correct, as it's checked by IOS.
|
||||
IOS::ES::TicketReader ticket = wad.GetTicketWithFixedCommonKey();
|
||||
|
||||
while ((ret = es->ImportTicket(ticket.GetBytes(), wad.GetCertificateChain(),
|
||||
IOS::HLE::ESDevice::TicketImportType::Unpersonalised,
|
||||
verify_signature)) < 0 ||
|
||||
(ret = es->ImportTitleInit(context, tmd.GetBytes(), wad.GetCertificateChain(),
|
||||
verify_signature)) < 0)
|
||||
while ((ret = es.ImportTicket(ticket.GetBytes(), wad.GetCertificateChain(),
|
||||
IOS::HLE::ESCore::TicketImportType::Unpersonalised,
|
||||
verify_signature)) < 0 ||
|
||||
(ret = es.ImportTitleInit(context, tmd.GetBytes(), wad.GetCertificateChain(),
|
||||
verify_signature)) < 0)
|
||||
{
|
||||
if (ret != IOS::HLE::IOSC_FAIL_CHECKVALUE)
|
||||
{
|
||||
|
@ -87,9 +87,9 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad,
|
|||
{
|
||||
const std::vector<u8> data = wad.GetContent(content.index);
|
||||
|
||||
if (es->ImportContentBegin(context, title_id, content.id) < 0 ||
|
||||
es->ImportContentData(context, 0, data.data(), static_cast<u32>(data.size())) < 0 ||
|
||||
es->ImportContentEnd(context, 0) < 0)
|
||||
if (es.ImportContentBegin(context, title_id, content.id) < 0 ||
|
||||
es.ImportContentData(context, 0, data.data(), static_cast<u32>(data.size())) < 0 ||
|
||||
es.ImportContentEnd(context, 0) < 0)
|
||||
{
|
||||
PanicAlertFmtT("WAD installation failed: Could not import content {0:08x}.", content.id);
|
||||
return false;
|
||||
|
@ -98,8 +98,8 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad,
|
|||
return true;
|
||||
}();
|
||||
|
||||
if ((contents_imported && es->ImportTitleDone(context) < 0) ||
|
||||
(!contents_imported && es->ImportTitleCancel(context) < 0))
|
||||
if ((contents_imported && es.ImportTitleDone(context) < 0) ||
|
||||
(!contents_imported && es.ImportTitleCancel(context) < 0))
|
||||
{
|
||||
PanicAlertFmtT("WAD installation failed: Could not finalise title import.");
|
||||
return false;
|
||||
|
@ -151,8 +151,8 @@ bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, InstallType
|
|||
const u64 title_id = wad.GetTMD().GetTitleId();
|
||||
|
||||
// Skip the install if the WAD is already installed.
|
||||
const auto installed_contents = ios.GetES()->GetStoredContentsFromTMD(
|
||||
wad.GetTMD(), IOS::HLE::ESDevice::CheckContentHashes::Yes);
|
||||
const auto installed_contents = ios.GetESCore().GetStoredContentsFromTMD(
|
||||
wad.GetTMD(), IOS::HLE::ESCore::CheckContentHashes::Yes);
|
||||
if (wad.GetTMD().GetContents() == installed_contents)
|
||||
{
|
||||
// Clear the "temporary title ID" flag in case the user tries to permanently install a title
|
||||
|
@ -164,7 +164,7 @@ bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, InstallType
|
|||
|
||||
// If a different version is currently installed, warn the user to make sure
|
||||
// they don't overwrite the current version by mistake.
|
||||
const IOS::ES::TMDReader installed_tmd = ios.GetES()->FindInstalledTMD(title_id);
|
||||
const IOS::ES::TMDReader installed_tmd = ios.GetESCore().FindInstalledTMD(title_id);
|
||||
const bool has_another_version =
|
||||
installed_tmd.IsValid() && installed_tmd.GetTitleVersion() != wad.GetTMD().GetTitleVersion();
|
||||
if (has_another_version &&
|
||||
|
@ -178,10 +178,10 @@ bool InstallWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, InstallType
|
|||
|
||||
// Delete a previous temporary title, if it exists.
|
||||
if (previous_temporary_title_id)
|
||||
ios.GetES()->DeleteTitleContent(previous_temporary_title_id);
|
||||
ios.GetESCore().DeleteTitleContent(previous_temporary_title_id);
|
||||
|
||||
// A lot of people use fakesigned WADs, so disable signature checking when installing a WAD.
|
||||
if (!ImportWAD(ios, wad, IOS::HLE::ESDevice::VerifySignature::No))
|
||||
if (!ImportWAD(ios, wad, IOS::HLE::ESCore::VerifySignature::No))
|
||||
return false;
|
||||
|
||||
// Keep track of the title ID so this title can be removed to make room for any future install.
|
||||
|
@ -207,7 +207,7 @@ bool InstallWAD(const std::string& wad_path)
|
|||
bool UninstallTitle(u64 title_id)
|
||||
{
|
||||
IOS::HLE::Kernel ios;
|
||||
return ios.GetES()->DeleteTitleContent(title_id) == IOS::HLE::IPC_SUCCESS;
|
||||
return ios.GetESCore().DeleteTitleContent(title_id) == IOS::HLE::IPC_SUCCESS;
|
||||
}
|
||||
|
||||
bool IsTitleInstalled(u64 title_id)
|
||||
|
@ -266,7 +266,7 @@ IOS::ES::TMDReader FindBackupTMD(IOS::HLE::FS::FileSystem& fs, u64 title_id)
|
|||
}
|
||||
}
|
||||
|
||||
bool EnsureTMDIsImported(IOS::HLE::FS::FileSystem& fs, IOS::HLE::ESDevice& es, u64 title_id)
|
||||
bool EnsureTMDIsImported(IOS::HLE::FS::FileSystem& fs, IOS::HLE::ESCore& es, u64 title_id)
|
||||
{
|
||||
if (IsTMDImported(fs, title_id))
|
||||
return true;
|
||||
|
@ -275,7 +275,7 @@ bool EnsureTMDIsImported(IOS::HLE::FS::FileSystem& fs, IOS::HLE::ESDevice& es, u
|
|||
if (!tmd.IsValid())
|
||||
return false;
|
||||
|
||||
IOS::HLE::ESDevice::Context context;
|
||||
IOS::HLE::ESCore::Context context;
|
||||
context.uid = IOS::SYSMENU_UID;
|
||||
context.gid = IOS::SYSMENU_GID;
|
||||
const auto import_result =
|
||||
|
@ -308,7 +308,7 @@ protected:
|
|||
std::string SystemUpdater::GetDeviceRegion()
|
||||
{
|
||||
// Try to determine the region from an installed system menu.
|
||||
const auto tmd = m_ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
|
||||
const auto tmd = m_ios.GetESCore().FindInstalledTMD(Titles::SYSTEM_MENU);
|
||||
if (tmd.IsValid())
|
||||
{
|
||||
const DiscIO::Region region = tmd.GetRegion();
|
||||
|
@ -325,7 +325,7 @@ std::string SystemUpdater::GetDeviceRegion()
|
|||
std::string SystemUpdater::GetDeviceId()
|
||||
{
|
||||
u32 ios_device_id;
|
||||
if (m_ios.GetES()->GetDeviceId(&ios_device_id) < 0)
|
||||
if (m_ios.GetESCore().GetDeviceId(&ios_device_id) < 0)
|
||||
return "";
|
||||
return std::to_string((u64(1) << 32) | ios_device_id);
|
||||
}
|
||||
|
@ -417,10 +417,10 @@ OnlineSystemUpdater::ParseTitlesResponse(const std::vector<u8>& response) const
|
|||
|
||||
bool OnlineSystemUpdater::ShouldInstallTitle(const TitleInfo& title)
|
||||
{
|
||||
const auto es = m_ios.GetES();
|
||||
const auto installed_tmd = es->FindInstalledTMD(title.id);
|
||||
const auto& es = m_ios.GetESCore();
|
||||
const auto installed_tmd = es.FindInstalledTMD(title.id);
|
||||
return !(installed_tmd.IsValid() && installed_tmd.GetTitleVersion() >= title.version &&
|
||||
es->GetStoredContentsFromTMD(installed_tmd).size() == installed_tmd.GetNumContents());
|
||||
es.GetStoredContentsFromTMD(installed_tmd).size() == installed_tmd.GetNumContents());
|
||||
}
|
||||
|
||||
constexpr const char* GET_SYSTEM_TITLES_REQUEST_PAYLOAD = R"(<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
@ -545,8 +545,8 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
|
||||
// Import the ticket.
|
||||
IOS::HLE::ReturnCode ret = IOS::HLE::IPC_SUCCESS;
|
||||
const auto es = m_ios.GetES();
|
||||
if ((ret = es->ImportTicket(ticket.first, ticket.second)) < 0)
|
||||
auto& es = m_ios.GetESCore();
|
||||
if ((ret = es.ImportTicket(ticket.first, ticket.second)) < 0)
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "Failed to import ticket: error {}", static_cast<u32>(ret));
|
||||
return UpdateResult::ImportFailed;
|
||||
|
@ -564,7 +564,7 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
const u64 ios_id = tmd.first.GetIOSId();
|
||||
if (ios_id != 0 && IOS::ES::IsTitleType(ios_id, IOS::ES::TitleType::System))
|
||||
{
|
||||
if (!es->FindInstalledTMD(ios_id).IsValid())
|
||||
if (!es.FindInstalledTMD(ios_id).IsValid())
|
||||
{
|
||||
WARN_LOG_FMT(CORE, "Importing required system title {:016x} first", ios_id);
|
||||
const UpdateResult res = InstallTitleFromNUS(prefix_url, {ios_id, 0}, updated_titles);
|
||||
|
@ -577,15 +577,15 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
}
|
||||
|
||||
// Initialise the title import.
|
||||
IOS::HLE::ESDevice::Context context;
|
||||
if ((ret = es->ImportTitleInit(context, tmd.first.GetBytes(), tmd.second)) < 0)
|
||||
IOS::HLE::ESCore::Context context;
|
||||
if ((ret = es.ImportTitleInit(context, tmd.first.GetBytes(), tmd.second)) < 0)
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "Failed to initialise title import: error {}", static_cast<u32>(ret));
|
||||
return UpdateResult::ImportFailed;
|
||||
}
|
||||
|
||||
// Now download and install contents listed in the TMD.
|
||||
const std::vector<IOS::ES::Content> stored_contents = es->GetStoredContentsFromTMD(tmd.first);
|
||||
const std::vector<IOS::ES::Content> stored_contents = es.GetStoredContentsFromTMD(tmd.first);
|
||||
const UpdateResult import_result = [&]() {
|
||||
for (const IOS::ES::Content& content : tmd.first.GetContents())
|
||||
{
|
||||
|
@ -598,7 +598,7 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
if (is_already_installed)
|
||||
continue;
|
||||
|
||||
if ((ret = es->ImportContentBegin(context, title.id, content.id)) < 0)
|
||||
if ((ret = es.ImportContentBegin(context, title.id, content.id)) < 0)
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "Failed to initialise import for content {:08x}: error {}", content.id,
|
||||
static_cast<u32>(ret));
|
||||
|
@ -612,8 +612,8 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
return UpdateResult::DownloadFailed;
|
||||
}
|
||||
|
||||
if (es->ImportContentData(context, 0, data->data(), static_cast<u32>(data->size())) < 0 ||
|
||||
es->ImportContentEnd(context, 0) < 0)
|
||||
if (es.ImportContentData(context, 0, data->data(), static_cast<u32>(data->size())) < 0 ||
|
||||
es.ImportContentEnd(context, 0) < 0)
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "Failed to import content {:08x}", content.id);
|
||||
return UpdateResult::ImportFailed;
|
||||
|
@ -623,8 +623,8 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
|
|||
}();
|
||||
const bool all_contents_imported = import_result == UpdateResult::Succeeded;
|
||||
|
||||
if ((all_contents_imported && (ret = es->ImportTitleDone(context)) < 0) ||
|
||||
(!all_contents_imported && (ret = es->ImportTitleCancel(context)) < 0))
|
||||
if ((all_contents_imported && (ret = es.ImportTitleDone(context)) < 0) ||
|
||||
(!all_contents_imported && (ret = es.ImportTitleCancel(context)) < 0))
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "Failed to finalise title import: error {}", static_cast<u32>(ret));
|
||||
return UpdateResult::ImportFailed;
|
||||
|
@ -742,7 +742,8 @@ UpdateResult DiscSystemUpdater::DoDiscUpdate()
|
|||
|
||||
// Do not allow mismatched regions, because installing an update will automatically change
|
||||
// the Wii's region and may result in semi/full system menu bricks.
|
||||
const IOS::ES::TMDReader system_menu_tmd = m_ios.GetES()->FindInstalledTMD(Titles::SYSTEM_MENU);
|
||||
const IOS::ES::TMDReader system_menu_tmd =
|
||||
m_ios.GetESCore().FindInstalledTMD(Titles::SYSTEM_MENU);
|
||||
if (system_menu_tmd.IsValid() && m_volume->GetRegion() != system_menu_tmd.GetRegion())
|
||||
return UpdateResult::RegionMismatch;
|
||||
|
||||
|
@ -826,8 +827,8 @@ UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs,
|
|||
if (type != 2 && type != 3 && type != 6 && type != 7)
|
||||
return UpdateResult::AlreadyUpToDate;
|
||||
|
||||
const IOS::ES::TMDReader tmd = m_ios.GetES()->FindInstalledTMD(title.id);
|
||||
const IOS::ES::TicketReader ticket = m_ios.GetES()->FindSignedTicket(title.id);
|
||||
const IOS::ES::TMDReader tmd = m_ios.GetESCore().FindInstalledTMD(title.id);
|
||||
const IOS::ES::TicketReader ticket = m_ios.GetESCore().FindSignedTicket(title.id);
|
||||
|
||||
// Optional titles can be skipped if the ticket is present, even when the title isn't installed.
|
||||
if (attrs.test(16) && ticket.IsValid())
|
||||
|
@ -846,7 +847,7 @@ UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs,
|
|||
return UpdateResult::DiscReadFailed;
|
||||
}
|
||||
const DiscIO::VolumeWAD wad{std::move(blob)};
|
||||
const bool success = ImportWAD(m_ios, wad, IOS::HLE::ESDevice::VerifySignature::Yes);
|
||||
const bool success = ImportWAD(m_ios, wad, IOS::HLE::ESCore::VerifySignature::Yes);
|
||||
return success ? UpdateResult::Succeeded : UpdateResult::ImportFailed;
|
||||
}
|
||||
|
||||
|
@ -865,7 +866,7 @@ UpdateResult DoDiscUpdate(UpdateCallback update_callback, const std::string& ima
|
|||
static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair)
|
||||
{
|
||||
NANDCheckResult result;
|
||||
const auto es = ios.GetES();
|
||||
const auto& es = ios.GetESCore();
|
||||
|
||||
// Check for NANDs that were used with old Dolphin versions.
|
||||
const std::string sys_replace_path =
|
||||
|
@ -892,7 +893,7 @@ static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair)
|
|||
result.bad = true;
|
||||
}
|
||||
|
||||
for (const u64 title_id : es->GetInstalledTitles())
|
||||
for (const u64 title_id : es.GetInstalledTitles())
|
||||
{
|
||||
const std::string title_dir = Common::GetTitlePath(title_id, Common::FROM_CONFIGURED_ROOT);
|
||||
const std::string content_dir = title_dir + "/content";
|
||||
|
@ -912,7 +913,7 @@ static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair)
|
|||
}
|
||||
|
||||
// Check for incomplete title installs (missing ticket, TMD or contents).
|
||||
const auto ticket = es->FindSignedTicket(title_id);
|
||||
const auto ticket = es.FindSignedTicket(title_id);
|
||||
if (!IOS::ES::IsDiscTitle(title_id) && !ticket.IsValid())
|
||||
{
|
||||
ERROR_LOG_FMT(CORE, "CheckNAND: Missing ticket for title {:016x}", title_id);
|
||||
|
@ -923,7 +924,7 @@ static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair)
|
|||
result.bad = true;
|
||||
}
|
||||
|
||||
const auto tmd = es->FindInstalledTMD(title_id);
|
||||
const auto tmd = es.FindInstalledTMD(title_id);
|
||||
if (!tmd.IsValid())
|
||||
{
|
||||
if (File::ScanDirectoryTree(content_dir, false).children.empty())
|
||||
|
@ -943,7 +944,7 @@ static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair)
|
|||
continue;
|
||||
}
|
||||
|
||||
const auto installed_contents = es->GetStoredContentsFromTMD(tmd);
|
||||
const auto installed_contents = es.GetStoredContentsFromTMD(tmd);
|
||||
const bool is_installed = std::any_of(installed_contents.begin(), installed_contents.end(),
|
||||
[](const auto& content) { return !content.IsShared(); });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue