summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-27 15:43:10 -0400
committerGravatar GitHub2018-08-27 15:43:10 -0400
commit8c66a5a9a56d16b3b585d969a9c78f67ce02820d (patch)
tree13894fd5d49ac7d562191cc31029d247b7c09ced /src/core
parentMerge pull request #1168 from lioncash/header (diff)
parentAddressed plu TTF changes (diff)
downloadyuzu-8c66a5a9a56d16b3b585d969a9c78f67ce02820d.tar.gz
yuzu-8c66a5a9a56d16b3b585d969a9c78f67ce02820d.tar.xz
yuzu-8c66a5a9a56d16b3b585d969a9c78f67ce02820d.zip
Merge pull request #1162 from ogniK5377/ttf-plu
PL:U Added SharedFonts loading via TTF
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/ns/pl_u.cpp56
1 files changed, 51 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..923a52cc5 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
38static 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
40static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; 48static constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
@@ -76,6 +84,17 @@ 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
87static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& output,
88 size_t& offset) {
89 ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
90 const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT;
91 std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header
92 const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY;
93 std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32));
94 std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size());
95 offset += input.size() + (sizeof(u32) * 2);
96}
97
79static u32 GetU32Swapped(const u8* data) { 98static u32 GetU32Swapped(const u8* data) {
80 u32 value; 99 u32 value;
81 std::memcpy(&value, data, sizeof(value)); 100 std::memcpy(&value, data, sizeof(value));
@@ -109,10 +128,10 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
109 RegisterHandlers(functions); 128 RegisterHandlers(functions);
110 // Attempt to load shared font data from disk 129 // Attempt to load shared font data from disk
111 const auto nand = FileSystem::GetSystemNANDContents(); 130 const auto nand = FileSystem::GetSystemNANDContents();
131 size_t offset = 0;
112 // Rebuild shared fonts from data ncas 132 // Rebuild shared fonts from data ncas
113 if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), 133 if (nand->HasEntry(static_cast<u64>(FontArchives::Standard),
114 FileSys::ContentRecordType::Data)) { 134 FileSys::ContentRecordType::Data)) {
115 size_t offset = 0;
116 shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE); 135 shared_font = std::make_shared<std::vector<u8>>(SHARED_FONT_MEM_SIZE);
117 for (auto font : SHARED_FONTS) { 136 for (auto font : SHARED_FONTS) {
118 const auto nca = 137 const auto nca =
@@ -152,18 +171,45 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
152 DecryptSharedFont(font_data_u32, *shared_font, offset); 171 DecryptSharedFont(font_data_u32, *shared_font, offset);
153 SHARED_FONT_REGIONS.push_back(region); 172 SHARED_FONT_REGIONS.push_back(region);
154 } 173 }
174
155 } else { 175 } else {
156 const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + 176 shared_font = std::make_shared<std::vector<u8>>(
157 SHARED_FONT}; 177 SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size
178
179 const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir);
180 const std::string filepath{user_path + SHARED_FONT};
181
158 // Create path if not already created 182 // Create path if not already created
159 if (!FileUtil::CreateFullPath(filepath)) { 183 if (!FileUtil::CreateFullPath(filepath)) {
160 LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath); 184 LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath);
161 return; 185 return;
162 } 186 }
187
188 bool using_ttf = false;
189 for (const char* font_ttf : SHARED_FONTS_TTF) {
190 if (FileUtil::Exists(user_path + font_ttf)) {
191 using_ttf = true;
192 FileUtil::IOFile file(user_path + font_ttf, "rb");
193 if (file.IsOpen()) {
194 std::vector<u8> ttf_bytes(file.GetSize());
195 file.ReadBytes<u8>(ttf_bytes.data(), ttf_bytes.size());
196 FontRegion region{
197 static_cast<u32>(offset + 8),
198 static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account
199 // for the header
200 EncryptSharedFont(ttf_bytes, *shared_font, offset);
201 SHARED_FONT_REGIONS.push_back(region);
202 } else {
203 LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf);
204 }
205 } else if (using_ttf) {
206 LOG_WARNING(Service_NS, "Unable to find font: {}", font_ttf);
207 }
208 }
209 if (using_ttf)
210 return;
163 FileUtil::IOFile file(filepath, "rb"); 211 FileUtil::IOFile file(filepath, "rb");
164 212
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()) { 213 if (file.IsOpen()) {
168 // Read shared font data 214 // Read shared font data
169 ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE); 215 ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE);