diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/ns/pl_u.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index 53cbf1a6e..77f6da478 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -35,6 +35,14 @@ static constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONT | |||
| 35 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), | 35 | std::make_pair(FontArchives::Extension, "nintendo_ext_003.bfttf"), |
| 36 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")}; | 36 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf")}; |
| 37 | 37 | ||
| 38 | static constexpr std::array<const char*, 7> SHARED_FONTS_TTF{"FontStandard.ttf", | ||
| 39 | "FontChineseSimplified.ttf", | ||
| 40 | "FontExtendedChineseSimplified.ttf", | ||
| 41 | "FontChineseTraditional.ttf", | ||
| 42 | "FontKorean.ttf", | ||
| 43 | "FontNintendoExtended.ttf", | ||
| 44 | "FontNintendoExtended2.ttf"}; | ||
| 45 | |||
| 38 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 | 46 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 |
| 39 | // Virtual address and offsets/sizes likely will vary by dump | 47 | // Virtual address and offsets/sizes likely will vary by dump |
| 40 | static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; | 48 | static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; |
| @@ -76,6 +84,16 @@ void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, s | |||
| 76 | offset += transformed_font.size() * sizeof(u32); | 84 | offset += transformed_font.size() * sizeof(u32); |
| 77 | } | 85 | } |
| 78 | 86 | ||
| 87 | void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& output, size_t& offset) { | ||
| 88 | ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!"); | ||
| 89 | const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT; | ||
| 90 | std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header | ||
| 91 | const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY; | ||
| 92 | std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32)); | ||
| 93 | std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size()); | ||
| 94 | offset += input.size() + (sizeof(u32) * 2); | ||
| 95 | } | ||
| 96 | |||
| 79 | static u32 GetU32Swapped(const u8* data) { | 97 | static u32 GetU32Swapped(const u8* data) { |
| 80 | u32 value; | 98 | u32 value; |
| 81 | std::memcpy(&value, data, sizeof(value)); | 99 | std::memcpy(&value, data, sizeof(value)); |
| @@ -109,10 +127,10 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 109 | RegisterHandlers(functions); | 127 | RegisterHandlers(functions); |
| 110 | // Attempt to load shared font data from disk | 128 | // Attempt to load shared font data from disk |
| 111 | const auto nand = FileSystem::GetSystemNANDContents(); | 129 | const auto nand = FileSystem::GetSystemNANDContents(); |
| 130 | size_t offset = 0; | ||
| 112 | // Rebuild shared fonts from data ncas | 131 | // Rebuild shared fonts from data ncas |
| 113 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), | 132 | if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), |
| 114 | FileSys::ContentRecordType::Data)) { | 133 | FileSys::ContentRecordType::Data)) { |
| 115 | size_t offset = 0; | ||
| 116 | shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); | 134 | shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); |
| 117 | for (auto font : SHARED_FONTS) { | 135 | for (auto font : SHARED_FONTS) { |
| 118 | const auto nca = | 136 | const auto nca = |
| @@ -152,18 +170,45 @@ PL_U::PL_U() : ServiceFramework("pl:u") { | |||
| 152 | DecryptSharedFont(font_data_u32, *shared_font, offset); | 170 | DecryptSharedFont(font_data_u32, *shared_font, offset); |
| 153 | SHARED_FONT_REGIONS.push_back(region); | 171 | SHARED_FONT_REGIONS.push_back(region); |
| 154 | } | 172 | } |
| 173 | |||
| 155 | } else { | 174 | } else { |
| 156 | const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + | 175 | shared_font = std::make_shared<std::vector<u8>>( |
| 157 | SHARED_FONT}; | 176 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size |
| 177 | |||
| 178 | const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir); | ||
| 179 | const std::string filepath{user_path + SHARED_FONT}; | ||
| 180 | |||
| 158 | // Create path if not already created | 181 | // Create path if not already created |
| 159 | if (!FileUtil::CreateFullPath(filepath)) { | 182 | if (!FileUtil::CreateFullPath(filepath)) { |
| 160 | LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath); | 183 | LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath); |
| 161 | return; | 184 | return; |
| 162 | } | 185 | } |
| 186 | |||
| 187 | bool using_ttf = false; | ||
| 188 | for (auto FontTTF : SHARED_FONTS_TTF) { | ||
| 189 | if (FileUtil::Exists(user_path + FontTTF)) { | ||
| 190 | using_ttf = true; | ||
| 191 | FileUtil::IOFile file(user_path + FontTTF, "rb"); | ||
| 192 | if (file.IsOpen()) { | ||
| 193 | std::vector<u8> ttf_bytes(file.GetSize()); | ||
| 194 | file.ReadBytes<u8>(ttf_bytes.data(), ttf_bytes.size()); | ||
| 195 | FontRegion region{ | ||
| 196 | static_cast<u32>(offset + 8), | ||
| 197 | static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account | ||
| 198 | // for the header | ||
| 199 | EncryptSharedFont(ttf_bytes, *shared_font, offset); | ||
| 200 | SHARED_FONT_REGIONS.push_back(region); | ||
| 201 | } else { | ||
| 202 | LOG_WARNING(Service_NS, "Unable to load font: {}", FontTTF); | ||
| 203 | } | ||
| 204 | } else if (using_ttf) { | ||
| 205 | LOG_WARNING(Service_NS, "Unable to find font: {}", FontTTF); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | if (using_ttf) | ||
| 209 | return; | ||
| 163 | FileUtil::IOFile file(filepath, "rb"); | 210 | FileUtil::IOFile file(filepath, "rb"); |
| 164 | 211 | ||
| 165 | shared_font = std::make_shared<std::vector<u8>>( | ||
| 166 | SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size | ||
| 167 | if (file.IsOpen()) { | 212 | if (file.IsOpen()) { |
| 168 | // Read shared font data | 213 | // Read shared font data |
| 169 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); | 214 | ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); |