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
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)) if (descriptor->riivolution && std::holds_alternative<Disc>(boot_params->parameters))
{ {
auto& disc = std::get<Disc>(boot_params->parameters); const auto& volume = *std::get<Disc>(boot_params->parameters).volume;
const auto& volume = *disc.volume; AddRiivolutionPatches(boot_params.get(),
boot_params->riivolution_patches = DiscIO::Riivolution::GenerateRiivolutionPatchesFromGameModDescriptor(
DiscIO::Riivolution::GenerateRiivolutionPatchesFromGameModDescriptor( *descriptor->riivolution, volume.GetGameID(),
*descriptor->riivolution, volume.GetGameID(), volume.GetRevision(), volume.GetRevision(), volume.GetDiscNumber()));
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);
}));
}
} }
return boot_params; return boot_params;
} }
} }
@ -643,3 +634,20 @@ void CreateSystemMenuTitleDirs()
const auto es = IOS::HLE::GetIOS()->GetES(); const auto es = IOS::HLE::GetIOS()->GetES();
es->CreateTitleDirectories(Titles::SYSTEM_MENU, IOS::SYSMENU_GID); 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, /// 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. /// but we cannot rely on this because we don't require any system titles to be installed.
void CreateSystemMenuTitleDirs(); 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()) if (!w.ShouldBoot())
return; return;
if (!w.GetPatches().empty()) AddRiivolutionPatches(boot_params.get(), std::move(w.GetPatches()));
{
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());
}
StartGame(std::move(boot_params)); StartGame(std::move(boot_params));
} }