Skip to content

Commit

Permalink
DiscIO/Riivolution: Add dolphin-specific extensions "dolphin_sys_file…
Browse files Browse the repository at this point in the history
…" and "dolphin_sys_folder" to patch sys files like you would patch regular files.
  • Loading branch information
AdmiralCurtiss committed Jul 18, 2022
1 parent f5c1325 commit cc315cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Source/Core/Core/Boot/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@ void AddRiivolutionPatches(BootParameters* boot_params,
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);
DiscIO::Riivolution::ApplyPatchesToFiles(
riivolution_patches, DiscIO::Riivolution::PatchIndex::FileSystem, fst, dol_node);
}));
boot_params->riivolution_patches = std::move(riivolution_patches);
}
11 changes: 7 additions & 4 deletions Source/Core/DiscIO/RiivolutionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ std::optional<Disc> ParseString(std::string_view xml, std::string xml_path)
for (const auto& patch_subnode : patch_node.children())
{
const std::string_view patch_name(patch_subnode.name());
if (patch_name == "file")
if (patch_name == "file" || patch_name == "dolphin_sys_file")
{
auto& file = patch.m_file_patches.emplace_back();
auto& file = patch_name == "dolphin_sys_file" ? patch.m_sys_file_patches.emplace_back() :
patch.m_file_patches.emplace_back();
file.m_disc = patch_subnode.attribute("disc").as_string();
file.m_external = patch_subnode.attribute("external").as_string();
file.m_resize = patch_subnode.attribute("resize").as_bool(true);
Expand All @@ -183,9 +184,11 @@ std::optional<Disc> ParseString(std::string_view xml, std::string xml_path)
file.m_fileoffset = patch_subnode.attribute("fileoffset").as_uint(0);
file.m_length = patch_subnode.attribute("length").as_uint(0);
}
else if (patch_name == "folder")
else if (patch_name == "folder" || patch_name == "dolphin_sys_folder")
{
auto& folder = patch.m_folder_patches.emplace_back();
auto& folder = patch_name == "dolphin_sys_folder" ?
patch.m_sys_folder_patches.emplace_back() :
patch.m_folder_patches.emplace_back();
folder.m_disc = patch_subnode.attribute("disc").as_string();
folder.m_external = patch_subnode.attribute("external").as_string();
folder.m_resize = patch_subnode.attribute("resize").as_bool(true);
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DiscIO/RiivolutionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ struct Patch

std::vector<File> m_file_patches;
std::vector<Folder> m_folder_patches;
std::vector<File> m_sys_file_patches;
std::vector<Folder> m_sys_folder_patches;
std::vector<Savegame> m_savegame_patches;
std::vector<Memory> m_memory_patches;

Expand Down
11 changes: 8 additions & 3 deletions Source/Core/DiscIO/RiivolutionPatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,15 +458,20 @@ static void ApplyFolderPatchToFST(const Patch& patch, const Folder& folder,
ApplyFolderPatchToFST(patch, folder, fst, dol_node, folder.m_disc, folder.m_external);
}

void ApplyPatchesToFiles(const std::vector<Patch>& patches,
void ApplyPatchesToFiles(const std::vector<Patch>& patches, PatchIndex index,
std::vector<DiscIO::FSTBuilderNode>* fst, DiscIO::FSTBuilderNode* dol_node)
{
for (const auto& patch : patches)
{
for (const auto& file : patch.m_file_patches)
const auto& file_patches =
index == PatchIndex::DolphinSysFiles ? patch.m_sys_file_patches : patch.m_file_patches;
const auto& folder_patches =
index == PatchIndex::DolphinSysFiles ? patch.m_sys_folder_patches : patch.m_folder_patches;

for (const auto& file : file_patches)
ApplyFilePatchToFST(patch, file, fst, dol_node);

for (const auto& folder : patch.m_folder_patches)
for (const auto& folder : folder_patches)
ApplyFolderPatchToFST(patch, folder, fst, dol_node);
}
}
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/DiscIO/RiivolutionPatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ class FileDataLoaderHostFS : public FileDataLoader
std::string m_patch_root;
};

void ApplyPatchesToFiles(const std::vector<Patch>& patches,
enum class PatchIndex
{
FileSystem,
DolphinSysFiles,
};

void ApplyPatchesToFiles(const std::vector<Patch>& patches, PatchIndex index,
std::vector<DiscIO::FSTBuilderNode>* fst,
DiscIO::FSTBuilderNode* dol_node);
void ApplyGeneralMemoryPatches(const std::vector<Patch>& patches);
Expand Down

0 comments on commit cc315cb

Please sign in to comment.