diff options
| author | JosJuice <josjuice@gmail.com> | 2021-10-24 16:29:38 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2021-10-30 23:24:36 +0200 |
| commit | 34021b5ebc8d13478058e63b3d67cc1fccb9de29 (patch) | |
| tree | 4d6cae156e027f78b30b50895dc982ebdca21562 /Source/Core/DiscIO | |
| parent | 05b4aecf18cac8b49ee7ef7314d2fac97ec82363 (diff) | |
Android: Allow starting game with Riivolution patches from the GUI
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/RiivolutionParser.cpp | 43 | ||||
| -rw-r--r-- | Source/Core/DiscIO/RiivolutionParser.h | 5 |
2 files changed, 43 insertions, 5 deletions
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 <string_view> #include <vector> +#include <fmt/format.h> #include <pugixml.hpp> +#include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Common/StringUtil.h" @@ -354,7 +356,7 @@ std::vector<Patch> 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<Patch> GenerateRiivolutionPatchesFromGameModDescriptor( for (auto& p : parsed->GeneratePatches(game_id)) { - p.m_file_data_loader = std::make_shared<DiscIO::Riivolution::FileDataLoaderHostFS>( - patch_info.root, parsed->m_xml_path, p.m_root); + p.m_file_data_loader = + std::make_shared<FileDataLoaderHostFS>(patch_info.root, parsed->m_xml_path, p.m_root); result.emplace_back(std::move(p)); } } return result; } +std::vector<Patch> GenerateRiivolutionPatchesFromConfig(const std::string root_directory, + const std::string& game_id, + std::optional<u16> revision, + std::optional<u8> disc_number) +{ + std::vector<Patch> 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> 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<Disc> 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<FileDataLoaderHostFS>(root_directory, parsed->m_xml_path, patch.m_root); + result.emplace_back(std::move(patch)); + } + } + + return result; +} + std::optional<Config> 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) diff --git a/Source/Core/DiscIO/RiivolutionParser.h b/Source/Core/DiscIO/RiivolutionParser.h index d826425e5a..f9f03f67c1 100644 --- a/Source/Core/DiscIO/RiivolutionParser.h +++ b/Source/Core/DiscIO/RiivolutionParser.h @@ -143,7 +143,6 @@ struct Memory std::vector<u8> m_original; // If true, this memory patch is an ocarina-style patch. - // TODO: I'm unsure what this means exactly, need to check some examples... bool m_ocarina = false; // If true, the offset is not known, and instead we should search for the m_original bytes in @@ -223,6 +222,10 @@ std::optional<Disc> ParseString(std::string_view xml, std::string xml_path); std::vector<Patch> GenerateRiivolutionPatchesFromGameModDescriptor( const GameModDescriptorRiivolution& descriptor, const std::string& game_id, std::optional<u16> revision, std::optional<u8> disc_number); +std::vector<Patch> GenerateRiivolutionPatchesFromConfig(const std::string root_directory, + const std::string& game_id, + std::optional<u16> revision, + std::optional<u8> disc_number); std::optional<Config> ParseConfigFile(const std::string& filename); std::optional<Config> ParseConfigString(std::string_view xml); std::string WriteConfigString(const Config& config); |
