RiivolutionPatcher.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2021 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <optional>
  5. #include <span>
  6. #include <string>
  7. #include <string_view>
  8. #include <vector>
  9. #include "DiscIO/DirectoryBlob.h"
  10. #include "DiscIO/RiivolutionParser.h"
  11. namespace Core
  12. {
  13. class CPUThreadGuard;
  14. }
  15. namespace DiscIO::Riivolution
  16. {
  17. struct SavegameRedirect
  18. {
  19. std::string m_target_path;
  20. bool m_clone;
  21. };
  22. class FileDataLoader
  23. {
  24. public:
  25. struct Node
  26. {
  27. std::string m_filename;
  28. bool m_is_directory;
  29. };
  30. virtual ~FileDataLoader();
  31. virtual std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) = 0;
  32. virtual std::vector<u8> GetFileContents(std::string_view external_relative_path) = 0;
  33. virtual std::vector<Node> GetFolderContents(std::string_view external_relative_path) = 0;
  34. virtual BuilderContentSource MakeContentSource(std::string_view external_relative_path,
  35. u64 external_offset, u64 external_size,
  36. u64 disc_offset) = 0;
  37. virtual std::optional<std::string>
  38. ResolveSavegameRedirectPath(std::string_view external_relative_path) = 0;
  39. };
  40. class FileDataLoaderHostFS : public FileDataLoader
  41. {
  42. public:
  43. // sd_root should be an absolute path to the folder representing our virtual SD card
  44. // xml_path should be an absolute path to the parsed XML file
  45. // patch_root should be the 'root' attribute given in the 'patch' or 'wiiroot' XML element
  46. FileDataLoaderHostFS(std::string sd_root, const std::string& xml_path,
  47. std::string_view patch_root);
  48. std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) override;
  49. std::vector<u8> GetFileContents(std::string_view external_relative_path) override;
  50. std::vector<FileDataLoader::Node>
  51. GetFolderContents(std::string_view external_relative_path) override;
  52. BuilderContentSource MakeContentSource(std::string_view external_relative_path,
  53. u64 external_offset, u64 external_size,
  54. u64 disc_offset) override;
  55. std::optional<std::string>
  56. ResolveSavegameRedirectPath(std::string_view external_relative_path) override;
  57. private:
  58. std::optional<std::string> MakeAbsoluteFromRelative(std::string_view external_relative_path);
  59. std::string m_sd_root;
  60. std::string m_patch_root;
  61. };
  62. enum class PatchIndex
  63. {
  64. FileSystem,
  65. DolphinSysFiles,
  66. };
  67. void ApplyPatchesToFiles(std::span<const Patch> patches, PatchIndex index,
  68. std::vector<FSTBuilderNode>* fst, FSTBuilderNode* dol_node);
  69. void ApplyGeneralMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches);
  70. void ApplyApploaderMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches,
  71. u32 ram_address, u32 ram_length);
  72. std::optional<SavegameRedirect> ExtractSavegameRedirect(std::span<const Patch> riivolution_patches);
  73. } // namespace DiscIO::Riivolution