diff options
| author | 2018-07-23 12:33:24 -0400 | |
|---|---|---|
| committer | 2018-07-23 12:34:26 -0400 | |
| commit | e8f641a52de33b33e0d6c73ee7ca07f06dcd8aeb (patch) | |
| tree | 262ba8e104beb57733f0e7c8e0703b87ed013ce2 /src/core/file_sys | |
| parent | Merge pull request #769 from bunnei/shader-mask-fixes (diff) | |
| download | yuzu-e8f641a52de33b33e0d6c73ee7ca07f06dcd8aeb.tar.gz yuzu-e8f641a52de33b33e0d6c73ee7ca07f06dcd8aeb.tar.xz yuzu-e8f641a52de33b33e0d6c73ee7ca07f06dcd8aeb.zip | |
NRO Assets and NACP file format
Cleanup
Review fixes
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/control_metadata.cpp | 42 | ||||
| -rw-r--r-- | src/core/file_sys/control_metadata.h | 81 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/core/file_sys/control_metadata.cpp b/src/core/file_sys/control_metadata.cpp new file mode 100644 index 000000000..3ddc9f162 --- /dev/null +++ b/src/core/file_sys/control_metadata.cpp | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/string_util.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/file_sys/control_metadata.h" | ||
| 8 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | std::string LanguageEntry::GetApplicationName() const { | ||
| 12 | return Common::StringFromFixedZeroTerminatedBuffer(application_name.data(), 0x200); | ||
| 13 | } | ||
| 14 | |||
| 15 | std::string LanguageEntry::GetDeveloperName() const { | ||
| 16 | return Common::StringFromFixedZeroTerminatedBuffer(developer_name.data(), 0x100); | ||
| 17 | } | ||
| 18 | |||
| 19 | NACP::NACP(VirtualFile file_) : file(std::move(file_)), raw(std::make_unique<RawNACP>()) { | ||
| 20 | file->ReadObject(raw.get()); | ||
| 21 | } | ||
| 22 | |||
| 23 | const LanguageEntry& NACP::GetLanguageEntry(Language language) const { | ||
| 24 | return raw->language_entries.at(static_cast<u8>(language)); | ||
| 25 | } | ||
| 26 | |||
| 27 | std::string NACP::GetApplicationName(Language language) const { | ||
| 28 | return GetLanguageEntry(language).GetApplicationName(); | ||
| 29 | } | ||
| 30 | |||
| 31 | std::string NACP::GetDeveloperName(Language language) const { | ||
| 32 | return GetLanguageEntry(language).GetDeveloperName(); | ||
| 33 | } | ||
| 34 | |||
| 35 | u64 NACP::GetTitleId() const { | ||
| 36 | return raw->title_id; | ||
| 37 | } | ||
| 38 | |||
| 39 | std::string NACP::GetVersionString() const { | ||
| 40 | return Common::StringFromFixedZeroTerminatedBuffer(raw->version_string.data(), 0x10); | ||
| 41 | } | ||
| 42 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/control_metadata.h b/src/core/file_sys/control_metadata.h new file mode 100644 index 000000000..cc3b745f7 --- /dev/null +++ b/src/core/file_sys/control_metadata.h | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <memory> | ||
| 9 | #include <string> | ||
| 10 | #include "common/common_funcs.h" | ||
| 11 | #include "core/file_sys/vfs.h" | ||
| 12 | |||
| 13 | namespace FileSys { | ||
| 14 | |||
| 15 | // A localized entry containing strings within the NACP. | ||
| 16 | // One for each language of type Language. | ||
| 17 | struct LanguageEntry { | ||
| 18 | std::array<char, 0x200> application_name; | ||
| 19 | std::array<char, 0x100> developer_name; | ||
| 20 | |||
| 21 | std::string GetApplicationName() const; | ||
| 22 | std::string GetDeveloperName() const; | ||
| 23 | }; | ||
| 24 | static_assert(sizeof(LanguageEntry) == 0x300, "LanguageEntry has incorrect size."); | ||
| 25 | |||
| 26 | // The raw file format of a NACP file. | ||
| 27 | struct RawNACP { | ||
| 28 | std::array<LanguageEntry, 16> language_entries; | ||
| 29 | INSERT_PADDING_BYTES(0x38); | ||
| 30 | u64_le title_id; | ||
| 31 | INSERT_PADDING_BYTES(0x20); | ||
| 32 | std::array<char, 0x10> version_string; | ||
| 33 | u64_le dlc_base_title_id; | ||
| 34 | u64_le title_id_2; | ||
| 35 | INSERT_PADDING_BYTES(0x28); | ||
| 36 | u64_le product_code; | ||
| 37 | u64_le title_id_3; | ||
| 38 | std::array<u64_le, 0x7> title_id_array; | ||
| 39 | INSERT_PADDING_BYTES(0x8); | ||
| 40 | u64_le title_id_update; | ||
| 41 | std::array<u8, 0x40> bcat_passphrase; | ||
| 42 | INSERT_PADDING_BYTES(0xEC0); | ||
| 43 | }; | ||
| 44 | static_assert(sizeof(RawNACP) == 0x4000, "RawNACP has incorrect size."); | ||
| 45 | |||
| 46 | // A language on the NX. These are for names and icons. | ||
| 47 | enum class Language : u8 { | ||
| 48 | AmericanEnglish = 0, | ||
| 49 | BritishEnglish = 1, | ||
| 50 | Japanese = 2, | ||
| 51 | French = 3, | ||
| 52 | German = 4, | ||
| 53 | LatinAmericanSpanish = 5, | ||
| 54 | Spanish = 6, | ||
| 55 | Italian = 7, | ||
| 56 | Dutch = 8, | ||
| 57 | CanadianFrench = 9, | ||
| 58 | Portugese = 10, | ||
| 59 | Russian = 11, | ||
| 60 | Korean = 12, | ||
| 61 | Taiwanese = 13, | ||
| 62 | Chinese = 14, | ||
| 63 | }; | ||
| 64 | |||
| 65 | // A class representing the format used by NX metadata files, typically named Control.nacp. | ||
| 66 | // These store application name, dev name, title id, and other miscellaneous data. | ||
| 67 | class NACP { | ||
| 68 | public: | ||
| 69 | explicit NACP(VirtualFile file); | ||
| 70 | const LanguageEntry& GetLanguageEntry(Language language = Language::AmericanEnglish) const; | ||
| 71 | std::string GetApplicationName(Language language = Language::AmericanEnglish) const; | ||
| 72 | std::string GetDeveloperName(Language language = Language::AmericanEnglish) const; | ||
| 73 | u64 GetTitleId() const; | ||
| 74 | std::string GetVersionString() const; | ||
| 75 | |||
| 76 | private: | ||
| 77 | VirtualFile file; | ||
| 78 | std::unique_ptr<RawNACP> raw; | ||
| 79 | }; | ||
| 80 | |||
| 81 | } // namespace FileSys | ||