patch_manager.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <map>
  6. #include <memory>
  7. #include <string>
  8. #include "common/common_types.h"
  9. #include "core/file_sys/nca_metadata.h"
  10. #include "core/file_sys/vfs.h"
  11. #include "core/memory/dmnt_cheat_types.h"
  12. namespace Core {
  13. class System;
  14. }
  15. namespace FileSys {
  16. class NCA;
  17. class NACP;
  18. enum class TitleVersionFormat : u8 {
  19. ThreeElements, ///< vX.Y.Z
  20. FourElements, ///< vX.Y.Z.W
  21. };
  22. std::string FormatTitleVersion(u32 version,
  23. TitleVersionFormat format = TitleVersionFormat::ThreeElements);
  24. // A centralized class to manage patches to games.
  25. class PatchManager {
  26. public:
  27. explicit PatchManager(u64 title_id);
  28. ~PatchManager();
  29. u64 GetTitleID() const;
  30. // Currently tracked ExeFS patches:
  31. // - Game Updates
  32. VirtualDir PatchExeFS(VirtualDir exefs) const;
  33. // Currently tracked NSO patches:
  34. // - IPS
  35. // - IPSwitch
  36. std::vector<u8> PatchNSO(const std::vector<u8>& nso, const std::string& name) const;
  37. // Checks to see if PatchNSO() will have any effect given the NSO's build ID.
  38. // Used to prevent expensive copies in NSO loader.
  39. bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const;
  40. // Creates a CheatList object with all
  41. std::vector<Memory::CheatEntry> CreateCheatList(const Core::System& system,
  42. const std::array<u8, 0x20>& build_id) const;
  43. // Currently tracked RomFS patches:
  44. // - Game Updates
  45. // - LayeredFS
  46. VirtualFile PatchRomFS(VirtualFile base, u64 ivfc_offset,
  47. ContentRecordType type = ContentRecordType::Program,
  48. VirtualFile update_raw = nullptr) const;
  49. // Returns a vector of pairs between patch names and patch versions.
  50. // i.e. Update 3.2.2 will return {"Update", "3.2.2"}
  51. std::map<std::string, std::string, std::less<>> GetPatchVersionNames(
  52. VirtualFile update_raw = nullptr) const;
  53. // If the game update exists, returns the u32 version field in its Meta-type NCA. If that fails,
  54. // it will fallback to the Meta-type NCA of the base game. If that fails, the result will be
  55. // std::nullopt
  56. std::optional<u32> GetGameVersion() const;
  57. // Given title_id of the program, attempts to get the control data of the update and parse
  58. // it, falling back to the base control data.
  59. std::pair<std::unique_ptr<NACP>, VirtualFile> GetControlMetadata() const;
  60. // Version of GetControlMetadata that takes an arbitrary NCA
  61. std::pair<std::unique_ptr<NACP>, VirtualFile> ParseControlNCA(const NCA& nca) const;
  62. private:
  63. std::vector<VirtualFile> CollectPatches(const std::vector<VirtualDir>& patch_dirs,
  64. const std::string& build_id) const;
  65. u64 title_id;
  66. };
  67. } // namespace FileSys