Core: Deduplicate Riivolution Patch to BootParameters apply logic.

This commit is contained in:
Admiral H. Curtiss 2021-10-21 03:08:54 +02:00
parent a76fdeee93
commit dd64c0e423
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
3 changed files with 27 additions and 25 deletions

View File

@ -233,22 +233,13 @@ BootParameters::GenerateFromFile(std::vector<std::string> paths,
if (descriptor->riivolution && std::holds_alternative<Disc>(boot_params->parameters))
{
auto& disc = std::get<Disc>(boot_params->parameters);
const auto& volume = *disc.volume;
boot_params->riivolution_patches =
DiscIO::Riivolution::GenerateRiivolutionPatchesFromGameModDescriptor(
*descriptor->riivolution, volume.GetGameID(), volume.GetRevision(),
volume.GetDiscNumber());
if (!boot_params->riivolution_patches.empty())
{
disc.volume = DiscIO::CreateDisc(DiscIO::DirectoryBlobReader::Create(
std::move(disc.volume),
[&](std::vector<DiscIO::FSTBuilderNode>* fst, DiscIO::FSTBuilderNode* dol_node) {
DiscIO::Riivolution::ApplyPatchesToFiles(boot_params->riivolution_patches, fst,
dol_node);
}));
}
const auto& volume = *std::get<Disc>(boot_params->parameters).volume;
AddRiivolutionPatches(boot_params.get(),
DiscIO::Riivolution::GenerateRiivolutionPatchesFromGameModDescriptor(
*descriptor->riivolution, volume.GetGameID(),
volume.GetRevision(), volume.GetDiscNumber()));
}
return boot_params;
}
}
@ -643,3 +634,20 @@ void CreateSystemMenuTitleDirs()
const auto es = IOS::HLE::GetIOS()->GetES();
es->CreateTitleDirectories(Titles::SYSTEM_MENU, IOS::SYSMENU_GID);
}
void AddRiivolutionPatches(BootParameters* boot_params,
std::vector<DiscIO::Riivolution::Patch> riivolution_patches)
{
if (riivolution_patches.empty())
return;
if (!std::holds_alternative<BootParameters::Disc>(boot_params->parameters))
return;
auto& disc = std::get<BootParameters::Disc>(boot_params->parameters);
disc.volume = DiscIO::CreateDisc(DiscIO::DirectoryBlobReader::Create(
std::move(disc.volume),
[&](std::vector<DiscIO::FSTBuilderNode>* fst, DiscIO::FSTBuilderNode* dol_node) {
DiscIO::Riivolution::ApplyPatchesToFiles(riivolution_patches, fst, dol_node);
}));
boot_params->riivolution_patches = std::move(riivolution_patches);
}

View File

@ -163,3 +163,6 @@ void UpdateStateFlags(std::function<void(StateFlags*)> update_function);
/// Normally, this is automatically done by ES when the System Menu is installed,
/// but we cannot rely on this because we don't require any system titles to be installed.
void CreateSystemMenuTitleDirs();
void AddRiivolutionPatches(BootParameters* boot_params,
std::vector<DiscIO::Riivolution::Patch> riivolution_patches);

View File

@ -1832,16 +1832,7 @@ void MainWindow::ShowRiivolutionBootWidget(const UICommon::GameFile& game)
if (!w.ShouldBoot())
return;
if (!w.GetPatches().empty())
{
disc.volume = DiscIO::CreateDisc(DiscIO::DirectoryBlobReader::Create(
std::move(disc.volume),
[&](std::vector<DiscIO::FSTBuilderNode>* fst, DiscIO::FSTBuilderNode* dol_node) {
DiscIO::Riivolution::ApplyPatchesToFiles(w.GetPatches(), fst, dol_node);
}));
boot_params->riivolution_patches = std::move(w.GetPatches());
}
AddRiivolutionPatches(boot_params.get(), std::move(w.GetPatches()));
StartGame(std::move(boot_params));
}