patch_manager.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. namespace FileSys {
  12. class NCA;
  13. class NACP;
  14. enum class TitleVersionFormat : u8 {
  15. ThreeElements, ///< vX.Y.Z
  16. FourElements, ///< vX.Y.Z.W
  17. };
  18. std::string FormatTitleVersion(u32 version,
  19. TitleVersionFormat format = TitleVersionFormat::ThreeElements);
  20. // A centralized class to manage patches to games.
  21. class PatchManager {
  22. public:
  23. explicit PatchManager(u64 title_id);
  24. ~PatchManager();
  25. // Currently tracked ExeFS patches:
  26. // - Game Updates
  27. VirtualDir PatchExeFS(VirtualDir exefs) const;
  28. // Currently tracked NSO patches:
  29. // - IPS
  30. std::vector<u8> PatchNSO(const std::vector<u8>& nso) const;
  31. // Checks to see if PatchNSO() will have any effect given the NSO's build ID.
  32. // Used to prevent expensive copies in NSO loader.
  33. bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const;
  34. // Currently tracked RomFS patches:
  35. // - Game Updates
  36. // - LayeredFS
  37. VirtualFile PatchRomFS(VirtualFile base, u64 ivfc_offset,
  38. ContentRecordType type = ContentRecordType::Program) const;
  39. // Returns a vector of pairs between patch names and patch versions.
  40. // i.e. Update 3.2.2 will return {"Update", "3.2.2"}
  41. std::map<std::string, std::string, std::less<>> GetPatchVersionNames() const;
  42. // Given title_id of the program, attempts to get the control data of the update and parse it,
  43. // falling back to the base control data.
  44. std::pair<std::shared_ptr<NACP>, VirtualFile> GetControlMetadata() const;
  45. // Version of GetControlMetadata that takes an arbitrary NCA
  46. std::pair<std::shared_ptr<NACP>, VirtualFile> ParseControlNCA(
  47. const std::shared_ptr<NCA>& nca) const;
  48. private:
  49. u64 title_id;
  50. };
  51. } // namespace FileSys