From dd64c0e4233a4d545448431f4c1ee62840ef830e Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Thu, 21 Oct 2021 03:08:54 +0200 Subject: [PATCH] Core: Deduplicate Riivolution Patch to BootParameters apply logic. --- Source/Core/Core/Boot/Boot.cpp | 38 +++++++++++++++++----------- Source/Core/Core/Boot/Boot.h | 3 +++ Source/Core/DolphinQt/MainWindow.cpp | 11 +------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index ba437b6e54..a67609a592 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -233,22 +233,13 @@ BootParameters::GenerateFromFile(std::vector paths, if (descriptor->riivolution && std::holds_alternative(boot_params->parameters)) { - auto& disc = std::get(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* fst, DiscIO::FSTBuilderNode* dol_node) { - DiscIO::Riivolution::ApplyPatchesToFiles(boot_params->riivolution_patches, fst, - dol_node); - })); - } + const auto& volume = *std::get(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 riivolution_patches) +{ + if (riivolution_patches.empty()) + return; + if (!std::holds_alternative(boot_params->parameters)) + return; + + auto& disc = std::get(boot_params->parameters); + disc.volume = DiscIO::CreateDisc(DiscIO::DirectoryBlobReader::Create( + std::move(disc.volume), + [&](std::vector* fst, DiscIO::FSTBuilderNode* dol_node) { + DiscIO::Riivolution::ApplyPatchesToFiles(riivolution_patches, fst, dol_node); + })); + boot_params->riivolution_patches = std::move(riivolution_patches); +} diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 4c27151c06..410b408b44 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -163,3 +163,6 @@ void UpdateStateFlags(std::function 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 riivolution_patches); diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index a581f9516b..7e442398dd 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -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* 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)); }