From 34021b5ebc8d13478058e63b3d67cc1fccb9de29 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 24 Oct 2021 16:29:38 +0200 Subject: Android: Allow starting game with Riivolution patches from the GUI --- Source/Core/DiscIO/RiivolutionParser.cpp | 43 +++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'Source/Core/DiscIO/RiivolutionParser.cpp') diff --git a/Source/Core/DiscIO/RiivolutionParser.cpp b/Source/Core/DiscIO/RiivolutionParser.cpp index 92f37444a0..8a121d7e8b 100644 --- a/Source/Core/DiscIO/RiivolutionParser.cpp +++ b/Source/Core/DiscIO/RiivolutionParser.cpp @@ -9,8 +9,10 @@ #include #include +#include #include +#include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Common/StringUtil.h" @@ -354,7 +356,7 @@ std::vector GenerateRiivolutionPatchesFromGameModDescriptor( { for (auto& option : section.m_options) { - const auto* info = [&]() -> const DiscIO::GameModDescriptorRiivolutionPatchOption* { + const auto* info = [&]() -> const GameModDescriptorRiivolutionPatchOption* { for (const auto& o : patch_info.options) { if (o.section_name == section.m_name) @@ -374,14 +376,47 @@ std::vector GenerateRiivolutionPatchesFromGameModDescriptor( for (auto& p : parsed->GeneratePatches(game_id)) { - p.m_file_data_loader = std::make_shared( - patch_info.root, parsed->m_xml_path, p.m_root); + p.m_file_data_loader = + std::make_shared(patch_info.root, parsed->m_xml_path, p.m_root); result.emplace_back(std::move(p)); } } return result; } +std::vector GenerateRiivolutionPatchesFromConfig(const std::string root_directory, + const std::string& game_id, + std::optional revision, + std::optional disc_number) +{ + std::vector result; + + // The way Riivolution stores settings only makes sense for standard game IDs. + if (!(game_id.size() == 4 || game_id.size() == 6)) + return result; + + const std::optional config = ParseConfigFile( + fmt::format("{}/riivolution/config/{}.xml", root_directory, game_id.substr(0, 4))); + + for (const std::string& path : Common::DoFileSearch({root_directory + "riivolution"}, {".xml"})) + { + std::optional parsed = ParseFile(path); + if (!parsed || !parsed->IsValidForGame(game_id, revision, disc_number)) + continue; + if (config) + ApplyConfigDefaults(&*parsed, *config); + + for (auto& patch : parsed->GeneratePatches(game_id)) + { + patch.m_file_data_loader = + std::make_shared(root_directory, parsed->m_xml_path, patch.m_root); + result.emplace_back(std::move(patch)); + } + } + + return result; +} + std::optional ParseConfigFile(const std::string& filename) { ::File::IOFile f(filename, "rb"); @@ -460,7 +495,7 @@ void ApplyConfigDefaults(Disc* disc, const Config& config) { for (const auto& config_option : config.m_options) { - auto* matching_option = [&]() -> DiscIO::Riivolution::Option* { + auto* matching_option = [&]() -> Option* { for (auto& section : disc->m_sections) { for (auto& option : section.m_options) -- cgit v1.2.3