diff options
Diffstat (limited to 'src')
26 files changed, 595 insertions, 354 deletions
diff --git a/src/common/file_util.h b/src/common/file_util.h index 3d8fe6264..571503d2a 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -285,7 +285,7 @@ private: | |||
| 285 | template <typename T> | 285 | template <typename T> |
| 286 | void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) { | 286 | void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) { |
| 287 | #ifdef _MSC_VER | 287 | #ifdef _MSC_VER |
| 288 | fstream.open(Common::UTF8ToTStr(filename).c_str(), openmode); | 288 | fstream.open(Common::UTF8ToUTF16W(filename).c_str(), openmode); |
| 289 | #else | 289 | #else |
| 290 | fstream.open(filename.c_str(), openmode); | 290 | fstream.open(filename.c_str(), openmode); |
| 291 | #endif | 291 | #endif |
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index 05437c137..6a0605c63 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp | |||
| @@ -31,7 +31,7 @@ std::string FormatLogMessage(const Entry& entry) { | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | void PrintMessage(const Entry& entry) { | 33 | void PrintMessage(const Entry& entry) { |
| 34 | auto str = FormatLogMessage(entry) + '\n'; | 34 | const auto str = FormatLogMessage(entry).append(1, '\n'); |
| 35 | fputs(str.c_str(), stderr); | 35 | fputs(str.c_str(), stderr); |
| 36 | } | 36 | } |
| 37 | 37 | ||
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index c9a5425a7..731d1db34 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <cctype> | 6 | #include <cctype> |
| 7 | #include <cerrno> | 7 | #include <cerrno> |
| 8 | #include <codecvt> | ||
| 8 | #include <cstdio> | 9 | #include <cstdio> |
| 9 | #include <cstdlib> | 10 | #include <cstdlib> |
| 10 | #include <cstring> | 11 | #include <cstring> |
| @@ -13,11 +14,7 @@ | |||
| 13 | #include "common/string_util.h" | 14 | #include "common/string_util.h" |
| 14 | 15 | ||
| 15 | #ifdef _WIN32 | 16 | #ifdef _WIN32 |
| 16 | #include <codecvt> | ||
| 17 | #include <windows.h> | 17 | #include <windows.h> |
| 18 | #include "common/common_funcs.h" | ||
| 19 | #else | ||
| 20 | #include <iconv.h> | ||
| 21 | #endif | 18 | #endif |
| 22 | 19 | ||
| 23 | namespace Common { | 20 | namespace Common { |
| @@ -195,11 +192,9 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st | |||
| 195 | return result; | 192 | return result; |
| 196 | } | 193 | } |
| 197 | 194 | ||
| 198 | #ifdef _WIN32 | ||
| 199 | |||
| 200 | std::string UTF16ToUTF8(const std::u16string& input) { | 195 | std::string UTF16ToUTF8(const std::u16string& input) { |
| 201 | #if _MSC_VER >= 1900 | 196 | #ifdef _MSC_VER |
| 202 | // Workaround for missing char16_t/char32_t instantiations in MSVC2015 | 197 | // Workaround for missing char16_t/char32_t instantiations in MSVC2017 |
| 203 | std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; | 198 | std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; |
| 204 | std::basic_string<__int16> tmp_buffer(input.cbegin(), input.cend()); | 199 | std::basic_string<__int16> tmp_buffer(input.cbegin(), input.cend()); |
| 205 | return convert.to_bytes(tmp_buffer); | 200 | return convert.to_bytes(tmp_buffer); |
| @@ -210,8 +205,8 @@ std::string UTF16ToUTF8(const std::u16string& input) { | |||
| 210 | } | 205 | } |
| 211 | 206 | ||
| 212 | std::u16string UTF8ToUTF16(const std::string& input) { | 207 | std::u16string UTF8ToUTF16(const std::string& input) { |
| 213 | #if _MSC_VER >= 1900 | 208 | #ifdef _MSC_VER |
| 214 | // Workaround for missing char16_t/char32_t instantiations in MSVC2015 | 209 | // Workaround for missing char16_t/char32_t instantiations in MSVC2017 |
| 215 | std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; | 210 | std::wstring_convert<std::codecvt_utf8_utf16<__int16>, __int16> convert; |
| 216 | auto tmp_buffer = convert.from_bytes(input); | 211 | auto tmp_buffer = convert.from_bytes(input); |
| 217 | return std::u16string(tmp_buffer.cbegin(), tmp_buffer.cend()); | 212 | return std::u16string(tmp_buffer.cbegin(), tmp_buffer.cend()); |
| @@ -221,6 +216,7 @@ std::u16string UTF8ToUTF16(const std::string& input) { | |||
| 221 | #endif | 216 | #endif |
| 222 | } | 217 | } |
| 223 | 218 | ||
| 219 | #ifdef _WIN32 | ||
| 224 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) { | 220 | static std::wstring CPToUTF16(u32 code_page, const std::string& input) { |
| 225 | const auto size = | 221 | const auto size = |
| 226 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); | 222 | MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0); |
| @@ -261,124 +257,6 @@ std::wstring UTF8ToUTF16W(const std::string& input) { | |||
| 261 | return CPToUTF16(CP_UTF8, input); | 257 | return CPToUTF16(CP_UTF8, input); |
| 262 | } | 258 | } |
| 263 | 259 | ||
| 264 | std::string SHIFTJISToUTF8(const std::string& input) { | ||
| 265 | return UTF16ToUTF8(CPToUTF16(932, input)); | ||
| 266 | } | ||
| 267 | |||
| 268 | std::string CP1252ToUTF8(const std::string& input) { | ||
| 269 | return UTF16ToUTF8(CPToUTF16(1252, input)); | ||
| 270 | } | ||
| 271 | |||
| 272 | #else | ||
| 273 | |||
| 274 | template <typename T> | ||
| 275 | static std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input) { | ||
| 276 | iconv_t const conv_desc = iconv_open("UTF-8", fromcode); | ||
| 277 | if ((iconv_t)(-1) == conv_desc) { | ||
| 278 | LOG_ERROR(Common, "Iconv initialization failure [{}]: {}", fromcode, strerror(errno)); | ||
| 279 | iconv_close(conv_desc); | ||
| 280 | return {}; | ||
| 281 | } | ||
| 282 | |||
| 283 | const std::size_t in_bytes = sizeof(T) * input.size(); | ||
| 284 | // Multiply by 4, which is the max number of bytes to encode a codepoint | ||
| 285 | const std::size_t out_buffer_size = 4 * in_bytes; | ||
| 286 | |||
| 287 | std::string out_buffer(out_buffer_size, '\0'); | ||
| 288 | |||
| 289 | auto src_buffer = &input[0]; | ||
| 290 | std::size_t src_bytes = in_bytes; | ||
| 291 | auto dst_buffer = &out_buffer[0]; | ||
| 292 | std::size_t dst_bytes = out_buffer.size(); | ||
| 293 | |||
| 294 | while (0 != src_bytes) { | ||
| 295 | std::size_t const iconv_result = | ||
| 296 | iconv(conv_desc, (char**)(&src_buffer), &src_bytes, &dst_buffer, &dst_bytes); | ||
| 297 | |||
| 298 | if (static_cast<std::size_t>(-1) == iconv_result) { | ||
| 299 | if (EILSEQ == errno || EINVAL == errno) { | ||
| 300 | // Try to skip the bad character | ||
| 301 | if (0 != src_bytes) { | ||
| 302 | --src_bytes; | ||
| 303 | ++src_buffer; | ||
| 304 | } | ||
| 305 | } else { | ||
| 306 | LOG_ERROR(Common, "iconv failure [{}]: {}", fromcode, strerror(errno)); | ||
| 307 | break; | ||
| 308 | } | ||
| 309 | } | ||
| 310 | } | ||
| 311 | |||
| 312 | std::string result; | ||
| 313 | out_buffer.resize(out_buffer_size - dst_bytes); | ||
| 314 | out_buffer.swap(result); | ||
| 315 | |||
| 316 | iconv_close(conv_desc); | ||
| 317 | |||
| 318 | return result; | ||
| 319 | } | ||
| 320 | |||
| 321 | std::u16string UTF8ToUTF16(const std::string& input) { | ||
| 322 | iconv_t const conv_desc = iconv_open("UTF-16LE", "UTF-8"); | ||
| 323 | if ((iconv_t)(-1) == conv_desc) { | ||
| 324 | LOG_ERROR(Common, "Iconv initialization failure [UTF-8]: {}", strerror(errno)); | ||
| 325 | iconv_close(conv_desc); | ||
| 326 | return {}; | ||
| 327 | } | ||
| 328 | |||
| 329 | const std::size_t in_bytes = sizeof(char) * input.size(); | ||
| 330 | // Multiply by 4, which is the max number of bytes to encode a codepoint | ||
| 331 | const std::size_t out_buffer_size = 4 * sizeof(char16_t) * in_bytes; | ||
| 332 | |||
| 333 | std::u16string out_buffer(out_buffer_size, char16_t{}); | ||
| 334 | |||
| 335 | char* src_buffer = const_cast<char*>(&input[0]); | ||
| 336 | std::size_t src_bytes = in_bytes; | ||
| 337 | char* dst_buffer = (char*)(&out_buffer[0]); | ||
| 338 | std::size_t dst_bytes = out_buffer.size(); | ||
| 339 | |||
| 340 | while (0 != src_bytes) { | ||
| 341 | std::size_t const iconv_result = | ||
| 342 | iconv(conv_desc, &src_buffer, &src_bytes, &dst_buffer, &dst_bytes); | ||
| 343 | |||
| 344 | if (static_cast<std::size_t>(-1) == iconv_result) { | ||
| 345 | if (EILSEQ == errno || EINVAL == errno) { | ||
| 346 | // Try to skip the bad character | ||
| 347 | if (0 != src_bytes) { | ||
| 348 | --src_bytes; | ||
| 349 | ++src_buffer; | ||
| 350 | } | ||
| 351 | } else { | ||
| 352 | LOG_ERROR(Common, "iconv failure [UTF-8]: {}", strerror(errno)); | ||
| 353 | break; | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 358 | std::u16string result; | ||
| 359 | out_buffer.resize(out_buffer_size - dst_bytes); | ||
| 360 | out_buffer.swap(result); | ||
| 361 | |||
| 362 | iconv_close(conv_desc); | ||
| 363 | |||
| 364 | return result; | ||
| 365 | } | ||
| 366 | |||
| 367 | std::string UTF16ToUTF8(const std::u16string& input) { | ||
| 368 | return CodeToUTF8("UTF-16LE", input); | ||
| 369 | } | ||
| 370 | |||
| 371 | std::string CP1252ToUTF8(const std::string& input) { | ||
| 372 | // return CodeToUTF8("CP1252//TRANSLIT", input); | ||
| 373 | // return CodeToUTF8("CP1252//IGNORE", input); | ||
| 374 | return CodeToUTF8("CP1252", input); | ||
| 375 | } | ||
| 376 | |||
| 377 | std::string SHIFTJISToUTF8(const std::string& input) { | ||
| 378 | // return CodeToUTF8("CP932", input); | ||
| 379 | return CodeToUTF8("SJIS", input); | ||
| 380 | } | ||
| 381 | |||
| 382 | #endif | 260 | #endif |
| 383 | 261 | ||
| 384 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) { | 262 | std::string StringFromFixedZeroTerminatedBuffer(const char* buffer, std::size_t max_len) { |
diff --git a/src/common/string_util.h b/src/common/string_util.h index dcca6bc38..32bf6a19c 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -72,31 +72,10 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st | |||
| 72 | std::string UTF16ToUTF8(const std::u16string& input); | 72 | std::string UTF16ToUTF8(const std::u16string& input); |
| 73 | std::u16string UTF8ToUTF16(const std::string& input); | 73 | std::u16string UTF8ToUTF16(const std::string& input); |
| 74 | 74 | ||
| 75 | std::string CP1252ToUTF8(const std::string& str); | ||
| 76 | std::string SHIFTJISToUTF8(const std::string& str); | ||
| 77 | |||
| 78 | #ifdef _WIN32 | 75 | #ifdef _WIN32 |
| 79 | std::string UTF16ToUTF8(const std::wstring& input); | 76 | std::string UTF16ToUTF8(const std::wstring& input); |
| 80 | std::wstring UTF8ToUTF16W(const std::string& str); | 77 | std::wstring UTF8ToUTF16W(const std::string& str); |
| 81 | 78 | ||
| 82 | #ifdef _UNICODE | ||
| 83 | inline std::string TStrToUTF8(const std::wstring& str) { | ||
| 84 | return UTF16ToUTF8(str); | ||
| 85 | } | ||
| 86 | |||
| 87 | inline std::wstring UTF8ToTStr(const std::string& str) { | ||
| 88 | return UTF8ToUTF16W(str); | ||
| 89 | } | ||
| 90 | #else | ||
| 91 | inline std::string TStrToUTF8(const std::string& str) { | ||
| 92 | return str; | ||
| 93 | } | ||
| 94 | |||
| 95 | inline std::string UTF8ToTStr(const std::string& str) { | ||
| 96 | return str; | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #endif | 79 | #endif |
| 101 | 80 | ||
| 102 | /** | 81 | /** |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 23fd6e920..a98dbb9ab 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -34,6 +34,8 @@ add_library(core STATIC | |||
| 34 | file_sys/errors.h | 34 | file_sys/errors.h |
| 35 | file_sys/fsmitm_romfsbuild.cpp | 35 | file_sys/fsmitm_romfsbuild.cpp |
| 36 | file_sys/fsmitm_romfsbuild.h | 36 | file_sys/fsmitm_romfsbuild.h |
| 37 | file_sys/ips_layer.cpp | ||
| 38 | file_sys/ips_layer.h | ||
| 37 | file_sys/mode.h | 39 | file_sys/mode.h |
| 38 | file_sys/nca_metadata.cpp | 40 | file_sys/nca_metadata.cpp |
| 39 | file_sys/nca_metadata.h | 41 | file_sys/nca_metadata.h |
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp index edfc1bbd4..8f5142a07 100644 --- a/src/core/file_sys/card_image.cpp +++ b/src/core/file_sys/card_image.cpp | |||
| @@ -20,7 +20,9 @@ namespace FileSys { | |||
| 20 | 20 | ||
| 21 | constexpr std::array<const char*, 0x4> partition_names = {"update", "normal", "secure", "logo"}; | 21 | constexpr std::array<const char*, 0x4> partition_names = {"update", "normal", "secure", "logo"}; |
| 22 | 22 | ||
| 23 | XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) { | 23 | XCI::XCI(VirtualFile file_) |
| 24 | : file(std::move(file_)), program_nca_status{Loader::ResultStatus::ErrorXCIMissingProgramNCA}, | ||
| 25 | partitions(0x4) { | ||
| 24 | if (file->ReadObject(&header) != sizeof(GamecardHeader)) { | 26 | if (file->ReadObject(&header) != sizeof(GamecardHeader)) { |
| 25 | status = Loader::ResultStatus::ErrorBadXCIHeader; | 27 | status = Loader::ResultStatus::ErrorBadXCIHeader; |
| 26 | return; | 28 | return; |
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp new file mode 100644 index 000000000..df933ee36 --- /dev/null +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -0,0 +1,88 @@ | |||
| 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/assert.h" | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/file_sys/ips_layer.h" | ||
| 8 | #include "core/file_sys/vfs_vector.h" | ||
| 9 | |||
| 10 | namespace FileSys { | ||
| 11 | |||
| 12 | enum class IPSFileType { | ||
| 13 | IPS, | ||
| 14 | IPS32, | ||
| 15 | Error, | ||
| 16 | }; | ||
| 17 | |||
| 18 | static IPSFileType IdentifyMagic(const std::vector<u8>& magic) { | ||
| 19 | if (magic.size() != 5) | ||
| 20 | return IPSFileType::Error; | ||
| 21 | if (magic == std::vector<u8>{'P', 'A', 'T', 'C', 'H'}) | ||
| 22 | return IPSFileType::IPS; | ||
| 23 | if (magic == std::vector<u8>{'I', 'P', 'S', '3', '2'}) | ||
| 24 | return IPSFileType::IPS32; | ||
| 25 | return IPSFileType::Error; | ||
| 26 | } | ||
| 27 | |||
| 28 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { | ||
| 29 | if (in == nullptr || ips == nullptr) | ||
| 30 | return nullptr; | ||
| 31 | |||
| 32 | const auto type = IdentifyMagic(ips->ReadBytes(0x5)); | ||
| 33 | if (type == IPSFileType::Error) | ||
| 34 | return nullptr; | ||
| 35 | |||
| 36 | auto in_data = in->ReadAllBytes(); | ||
| 37 | |||
| 38 | std::vector<u8> temp(type == IPSFileType::IPS ? 3 : 4); | ||
| 39 | u64 offset = 5; // After header | ||
| 40 | while (ips->Read(temp.data(), temp.size(), offset) == temp.size()) { | ||
| 41 | offset += temp.size(); | ||
| 42 | if (type == IPSFileType::IPS32 && temp == std::vector<u8>{'E', 'E', 'O', 'F'} || | ||
| 43 | type == IPSFileType::IPS && temp == std::vector<u8>{'E', 'O', 'F'}) { | ||
| 44 | break; | ||
| 45 | } | ||
| 46 | |||
| 47 | u32 real_offset{}; | ||
| 48 | if (type == IPSFileType::IPS32) | ||
| 49 | real_offset = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]; | ||
| 50 | else | ||
| 51 | real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; | ||
| 52 | |||
| 53 | u16 data_size{}; | ||
| 54 | if (ips->ReadObject(&data_size, offset) != sizeof(u16)) | ||
| 55 | return nullptr; | ||
| 56 | data_size = Common::swap16(data_size); | ||
| 57 | offset += sizeof(u16); | ||
| 58 | |||
| 59 | if (data_size == 0) { // RLE | ||
| 60 | u16 rle_size{}; | ||
| 61 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) | ||
| 62 | return nullptr; | ||
| 63 | rle_size = Common::swap16(data_size); | ||
| 64 | offset += sizeof(u16); | ||
| 65 | |||
| 66 | const auto data = ips->ReadByte(offset++); | ||
| 67 | if (data == boost::none) | ||
| 68 | return nullptr; | ||
| 69 | |||
| 70 | if (real_offset + rle_size > in_data.size()) | ||
| 71 | rle_size = in_data.size() - real_offset; | ||
| 72 | std::memset(in_data.data() + real_offset, data.get(), rle_size); | ||
| 73 | } else { // Standard Patch | ||
| 74 | auto read = data_size; | ||
| 75 | if (real_offset + read > in_data.size()) | ||
| 76 | read = in_data.size() - real_offset; | ||
| 77 | if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) | ||
| 78 | return nullptr; | ||
| 79 | offset += data_size; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | if (temp != std::vector<u8>{'E', 'E', 'O', 'F'} && temp != std::vector<u8>{'E', 'O', 'F'}) | ||
| 84 | return nullptr; | ||
| 85 | return std::make_shared<VectorVfsFile>(in_data, in->GetName(), in->GetContainingDirectory()); | ||
| 86 | } | ||
| 87 | |||
| 88 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/ips_layer.h b/src/core/file_sys/ips_layer.h new file mode 100644 index 000000000..81c163494 --- /dev/null +++ b/src/core/file_sys/ips_layer.h | |||
| @@ -0,0 +1,15 @@ | |||
| 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 <memory> | ||
| 8 | |||
| 9 | #include "core/file_sys/vfs.h" | ||
| 10 | |||
| 11 | namespace FileSys { | ||
| 12 | |||
| 13 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips); | ||
| 14 | |||
| 15 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 4b3b5e665..539698f6e 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -2,22 +2,36 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <array> | 6 | #include <array> |
| 6 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <cstring> | ||
| 7 | 9 | ||
| 10 | #include "common/hex_util.h" | ||
| 8 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 9 | #include "core/file_sys/content_archive.h" | 12 | #include "core/file_sys/content_archive.h" |
| 10 | #include "core/file_sys/control_metadata.h" | 13 | #include "core/file_sys/control_metadata.h" |
| 14 | #include "core/file_sys/ips_layer.h" | ||
| 11 | #include "core/file_sys/patch_manager.h" | 15 | #include "core/file_sys/patch_manager.h" |
| 12 | #include "core/file_sys/registered_cache.h" | 16 | #include "core/file_sys/registered_cache.h" |
| 13 | #include "core/file_sys/romfs.h" | 17 | #include "core/file_sys/romfs.h" |
| 14 | #include "core/file_sys/vfs_layered.h" | 18 | #include "core/file_sys/vfs_layered.h" |
| 19 | #include "core/file_sys/vfs_vector.h" | ||
| 15 | #include "core/hle/service/filesystem/filesystem.h" | 20 | #include "core/hle/service/filesystem/filesystem.h" |
| 16 | #include "core/loader/loader.h" | 21 | #include "core/loader/loader.h" |
| 17 | 22 | ||
| 18 | namespace FileSys { | 23 | namespace FileSys { |
| 19 | 24 | ||
| 20 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; | 25 | constexpr u64 SINGLE_BYTE_MODULUS = 0x100; |
| 26 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; | ||
| 27 | |||
| 28 | struct NSOBuildHeader { | ||
| 29 | u32_le magic; | ||
| 30 | INSERT_PADDING_BYTES(0x3C); | ||
| 31 | std::array<u8, 0x20> build_id; | ||
| 32 | INSERT_PADDING_BYTES(0xA0); | ||
| 33 | }; | ||
| 34 | static_assert(sizeof(NSOBuildHeader) == 0x100, "NSOBuildHeader has incorrect size."); | ||
| 21 | 35 | ||
| 22 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | 36 | std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { |
| 23 | std::array<u8, sizeof(u32)> bytes{}; | 37 | std::array<u8, sizeof(u32)> bytes{}; |
| @@ -32,15 +46,6 @@ std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | |||
| 32 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); | 46 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); |
| 33 | } | 47 | } |
| 34 | 48 | ||
| 35 | constexpr std::array<const char*, 2> PATCH_TYPE_NAMES{ | ||
| 36 | "Update", | ||
| 37 | "LayeredFS", | ||
| 38 | }; | ||
| 39 | |||
| 40 | std::string FormatPatchTypeName(PatchType type) { | ||
| 41 | return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type)); | ||
| 42 | } | ||
| 43 | |||
| 44 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} | 49 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} |
| 45 | 50 | ||
| 46 | PatchManager::~PatchManager() = default; | 51 | PatchManager::~PatchManager() = default; |
| @@ -68,6 +73,79 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const { | |||
| 68 | return exefs; | 73 | return exefs; |
| 69 | } | 74 | } |
| 70 | 75 | ||
| 76 | static std::vector<VirtualFile> CollectIPSPatches(const std::vector<VirtualDir>& patch_dirs, | ||
| 77 | const std::string& build_id) { | ||
| 78 | std::vector<VirtualFile> ips; | ||
| 79 | ips.reserve(patch_dirs.size()); | ||
| 80 | for (const auto& subdir : patch_dirs) { | ||
| 81 | auto exefs_dir = subdir->GetSubdirectory("exefs"); | ||
| 82 | if (exefs_dir != nullptr) { | ||
| 83 | for (const auto& file : exefs_dir->GetFiles()) { | ||
| 84 | if (file->GetExtension() != "ips") | ||
| 85 | continue; | ||
| 86 | auto name = file->GetName(); | ||
| 87 | const auto p1 = name.substr(0, name.find('.')); | ||
| 88 | const auto this_build_id = p1.substr(0, p1.find_last_not_of('0') + 1); | ||
| 89 | |||
| 90 | if (build_id == this_build_id) | ||
| 91 | ips.push_back(file); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | return ips; | ||
| 97 | } | ||
| 98 | |||
| 99 | std::vector<u8> PatchManager::PatchNSO(const std::vector<u8>& nso) const { | ||
| 100 | if (nso.size() < 0x100) | ||
| 101 | return nso; | ||
| 102 | |||
| 103 | NSOBuildHeader header; | ||
| 104 | std::memcpy(&header, nso.data(), sizeof(NSOBuildHeader)); | ||
| 105 | |||
| 106 | if (header.magic != Common::MakeMagic('N', 'S', 'O', '0')) | ||
| 107 | return nso; | ||
| 108 | |||
| 109 | const auto build_id_raw = Common::HexArrayToString(header.build_id); | ||
| 110 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | ||
| 111 | |||
| 112 | LOG_INFO(Loader, "Patching NSO for build_id={}", build_id); | ||
| 113 | |||
| 114 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | ||
| 115 | auto patch_dirs = load_dir->GetSubdirectories(); | ||
| 116 | std::sort(patch_dirs.begin(), patch_dirs.end(), | ||
| 117 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | ||
| 118 | const auto ips = CollectIPSPatches(patch_dirs, build_id); | ||
| 119 | |||
| 120 | auto out = nso; | ||
| 121 | for (const auto& ips_file : ips) { | ||
| 122 | LOG_INFO(Loader, " - Appling IPS patch from mod \"{}\"", | ||
| 123 | ips_file->GetContainingDirectory()->GetParentDirectory()->GetName()); | ||
| 124 | const auto patched = PatchIPS(std::make_shared<VectorVfsFile>(out), ips_file); | ||
| 125 | if (patched != nullptr) | ||
| 126 | out = patched->ReadAllBytes(); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (out.size() < 0x100) | ||
| 130 | return nso; | ||
| 131 | std::memcpy(out.data(), &header, sizeof(NSOBuildHeader)); | ||
| 132 | return out; | ||
| 133 | } | ||
| 134 | |||
| 135 | bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | ||
| 136 | const auto build_id_raw = Common::HexArrayToString(build_id_); | ||
| 137 | const auto build_id = build_id_raw.substr(0, build_id_raw.find_last_not_of('0') + 1); | ||
| 138 | |||
| 139 | LOG_INFO(Loader, "Querying NSO patch existence for build_id={}", build_id); | ||
| 140 | |||
| 141 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | ||
| 142 | auto patch_dirs = load_dir->GetSubdirectories(); | ||
| 143 | std::sort(patch_dirs.begin(), patch_dirs.end(), | ||
| 144 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | ||
| 145 | |||
| 146 | return !CollectIPSPatches(patch_dirs, build_id).empty(); | ||
| 147 | } | ||
| 148 | |||
| 71 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { | 149 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { |
| 72 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 150 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 73 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { | 151 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { |
| @@ -135,31 +213,80 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | |||
| 135 | return romfs; | 213 | return romfs; |
| 136 | } | 214 | } |
| 137 | 215 | ||
| 138 | std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | 216 | static void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { |
| 139 | std::map<PatchType, std::string> out; | 217 | if (to.empty()) |
| 218 | to += with; | ||
| 219 | else | ||
| 220 | to += ", " + with; | ||
| 221 | } | ||
| 222 | |||
| 223 | static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { | ||
| 224 | return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); | ||
| 225 | } | ||
| 226 | |||
| 227 | std::map<std::string, std::string, std::less<>> PatchManager::GetPatchVersionNames() const { | ||
| 228 | std::map<std::string, std::string, std::less<>> out; | ||
| 140 | const auto installed = Service::FileSystem::GetUnionContents(); | 229 | const auto installed = Service::FileSystem::GetUnionContents(); |
| 141 | 230 | ||
| 231 | // Game Updates | ||
| 142 | const auto update_tid = GetUpdateTitleID(title_id); | 232 | const auto update_tid = GetUpdateTitleID(title_id); |
| 143 | PatchManager update{update_tid}; | 233 | PatchManager update{update_tid}; |
| 144 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); | 234 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); |
| 145 | 235 | ||
| 146 | if (nacp != nullptr) { | 236 | if (nacp != nullptr) { |
| 147 | out[PatchType::Update] = nacp->GetVersionString(); | 237 | out.insert_or_assign("Update", nacp->GetVersionString()); |
| 148 | } else { | 238 | } else { |
| 149 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { | 239 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { |
| 150 | const auto meta_ver = installed->GetEntryVersion(update_tid); | 240 | const auto meta_ver = installed->GetEntryVersion(update_tid); |
| 151 | if (meta_ver == boost::none || meta_ver.get() == 0) { | 241 | if (meta_ver == boost::none || meta_ver.get() == 0) { |
| 152 | out[PatchType::Update] = ""; | 242 | out.insert_or_assign("Update", ""); |
| 153 | } else { | 243 | } else { |
| 154 | out[PatchType::Update] = | 244 | out.insert_or_assign( |
| 155 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); | 245 | "Update", |
| 246 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements)); | ||
| 156 | } | 247 | } |
| 157 | } | 248 | } |
| 158 | } | 249 | } |
| 159 | 250 | ||
| 160 | const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 251 | // General Mods (LayeredFS and IPS) |
| 161 | if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) | 252 | const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 162 | out.insert_or_assign(PatchType::LayeredFS, ""); | 253 | if (mod_dir != nullptr && mod_dir->GetSize() > 0) { |
| 254 | for (const auto& mod : mod_dir->GetSubdirectories()) { | ||
| 255 | std::string types; | ||
| 256 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("exefs"))) | ||
| 257 | AppendCommaIfNotEmpty(types, "IPS"); | ||
| 258 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("romfs"))) | ||
| 259 | AppendCommaIfNotEmpty(types, "LayeredFS"); | ||
| 260 | |||
| 261 | if (types.empty()) | ||
| 262 | continue; | ||
| 263 | |||
| 264 | out.insert_or_assign(mod->GetName(), types); | ||
| 265 | } | ||
| 266 | } | ||
| 267 | |||
| 268 | // DLC | ||
| 269 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); | ||
| 270 | std::vector<RegisteredCacheEntry> dlc_match; | ||
| 271 | dlc_match.reserve(dlc_entries.size()); | ||
| 272 | std::copy_if(dlc_entries.begin(), dlc_entries.end(), std::back_inserter(dlc_match), | ||
| 273 | [this, &installed](const RegisteredCacheEntry& entry) { | ||
| 274 | return (entry.title_id & DLC_BASE_TITLE_ID_MASK) == title_id && | ||
| 275 | installed->GetEntry(entry)->GetStatus() == | ||
| 276 | Loader::ResultStatus::Success; | ||
| 277 | }); | ||
| 278 | if (!dlc_match.empty()) { | ||
| 279 | // Ensure sorted so DLC IDs show in order. | ||
| 280 | std::sort(dlc_match.begin(), dlc_match.end()); | ||
| 281 | |||
| 282 | std::string list; | ||
| 283 | for (size_t i = 0; i < dlc_match.size() - 1; ++i) | ||
| 284 | list += fmt::format("{}, ", dlc_match[i].title_id & 0x7FF); | ||
| 285 | |||
| 286 | list += fmt::format("{}", dlc_match.back().title_id & 0x7FF); | ||
| 287 | |||
| 288 | out.insert_or_assign("DLC", std::move(list)); | ||
| 289 | } | ||
| 163 | 290 | ||
| 164 | return out; | 291 | return out; |
| 165 | } | 292 | } |
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 464f17515..6a864ec43 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -24,13 +24,6 @@ enum class TitleVersionFormat : u8 { | |||
| 24 | std::string FormatTitleVersion(u32 version, | 24 | std::string FormatTitleVersion(u32 version, |
| 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); | 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); |
| 26 | 26 | ||
| 27 | enum class PatchType { | ||
| 28 | Update, | ||
| 29 | LayeredFS, | ||
| 30 | }; | ||
| 31 | |||
| 32 | std::string FormatPatchTypeName(PatchType type); | ||
| 33 | |||
| 34 | // A centralized class to manage patches to games. | 27 | // A centralized class to manage patches to games. |
| 35 | class PatchManager { | 28 | class PatchManager { |
| 36 | public: | 29 | public: |
| @@ -41,6 +34,14 @@ public: | |||
| 41 | // - Game Updates | 34 | // - Game Updates |
| 42 | VirtualDir PatchExeFS(VirtualDir exefs) const; | 35 | VirtualDir PatchExeFS(VirtualDir exefs) const; |
| 43 | 36 | ||
| 37 | // Currently tracked NSO patches: | ||
| 38 | // - IPS | ||
| 39 | std::vector<u8> PatchNSO(const std::vector<u8>& nso) const; | ||
| 40 | |||
| 41 | // Checks to see if PatchNSO() will have any effect given the NSO's build ID. | ||
| 42 | // Used to prevent expensive copies in NSO loader. | ||
| 43 | bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const; | ||
| 44 | |||
| 44 | // Currently tracked RomFS patches: | 45 | // Currently tracked RomFS patches: |
| 45 | // - Game Updates | 46 | // - Game Updates |
| 46 | // - LayeredFS | 47 | // - LayeredFS |
| @@ -48,8 +49,8 @@ public: | |||
| 48 | ContentRecordType type = ContentRecordType::Program) const; | 49 | ContentRecordType type = ContentRecordType::Program) const; |
| 49 | 50 | ||
| 50 | // Returns a vector of pairs between patch names and patch versions. | 51 | // Returns a vector of pairs between patch names and patch versions. |
| 51 | // i.e. Update v80 will return {Update, 80} | 52 | // i.e. Update 3.2.2 will return {"Update", "3.2.2"} |
| 52 | std::map<PatchType, std::string> GetPatchVersionNames() const; | 53 | std::map<std::string, std::string, std::less<>> GetPatchVersionNames() const; |
| 53 | 54 | ||
| 54 | // Given title_id of the program, attempts to get the control data of the update and parse it, | 55 | // Given title_id of the program, attempts to get the control data of the update and parse it, |
| 55 | // falling back to the base control data. | 56 | // falling back to the base control data. |
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index d027a8d59..4994c2532 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp | |||
| @@ -39,36 +39,35 @@ ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { | 41 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { |
| 42 | std::shared_ptr<NCA> res; | ||
| 43 | |||
| 42 | switch (storage) { | 44 | switch (storage) { |
| 43 | case StorageId::NandSystem: { | 45 | case StorageId::None: |
| 44 | const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type); | 46 | res = Service::FileSystem::GetUnionContents()->GetEntry(title_id, type); |
| 45 | if (res == nullptr) { | 47 | break; |
| 46 | // TODO(DarkLordZach): Find the right error code to use here | 48 | case StorageId::NandSystem: |
| 47 | return ResultCode(-1); | 49 | res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type); |
| 48 | } | 50 | break; |
| 49 | const auto romfs = res->GetRomFS(); | 51 | case StorageId::NandUser: |
| 50 | if (romfs == nullptr) { | 52 | res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type); |
| 51 | // TODO(DarkLordZach): Find the right error code to use here | 53 | break; |
| 52 | return ResultCode(-1); | 54 | case StorageId::SdCard: |
| 53 | } | 55 | res = Service::FileSystem::GetSDMCContents()->GetEntry(title_id, type); |
| 54 | return MakeResult<VirtualFile>(romfs); | 56 | break; |
| 55 | } | ||
| 56 | case StorageId::NandUser: { | ||
| 57 | const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type); | ||
| 58 | if (res == nullptr) { | ||
| 59 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 60 | return ResultCode(-1); | ||
| 61 | } | ||
| 62 | const auto romfs = res->GetRomFS(); | ||
| 63 | if (romfs == nullptr) { | ||
| 64 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 65 | return ResultCode(-1); | ||
| 66 | } | ||
| 67 | return MakeResult<VirtualFile>(romfs); | ||
| 68 | } | ||
| 69 | default: | 57 | default: |
| 70 | UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage)); | 58 | UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage)); |
| 71 | } | 59 | } |
| 60 | |||
| 61 | if (res == nullptr) { | ||
| 62 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 63 | return ResultCode(-1); | ||
| 64 | } | ||
| 65 | const auto romfs = res->GetRomFS(); | ||
| 66 | if (romfs == nullptr) { | ||
| 67 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 68 | return ResultCode(-1); | ||
| 69 | } | ||
| 70 | return MakeResult<VirtualFile>(romfs); | ||
| 72 | } | 71 | } |
| 73 | 72 | ||
| 74 | } // namespace FileSys | 73 | } // namespace FileSys |
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 11264878d..09bf077cd 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -18,6 +18,39 @@ | |||
| 18 | #include "core/loader/loader.h" | 18 | #include "core/loader/loader.h" |
| 19 | 19 | ||
| 20 | namespace FileSys { | 20 | namespace FileSys { |
| 21 | namespace { | ||
| 22 | void SetTicketKeys(const std::vector<VirtualFile>& files) { | ||
| 23 | Core::Crypto::KeyManager keys; | ||
| 24 | |||
| 25 | for (const auto& ticket_file : files) { | ||
| 26 | if (ticket_file == nullptr) { | ||
| 27 | continue; | ||
| 28 | } | ||
| 29 | |||
| 30 | if (ticket_file->GetExtension() != "tik") { | ||
| 31 | continue; | ||
| 32 | } | ||
| 33 | |||
| 34 | if (ticket_file->GetSize() < | ||
| 35 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 36 | continue; | ||
| 37 | } | ||
| 38 | |||
| 39 | Core::Crypto::Key128 key{}; | ||
| 40 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 41 | |||
| 42 | // We get the name without the extension in order to create the rights ID. | ||
| 43 | std::string name_only(ticket_file->GetName()); | ||
| 44 | name_only.erase(name_only.size() - 4); | ||
| 45 | |||
| 46 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 47 | u128 rights_id; | ||
| 48 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 49 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } // Anonymous namespace | ||
| 53 | |||
| 21 | NSP::NSP(VirtualFile file_) | 54 | NSP::NSP(VirtualFile file_) |
| 22 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, | 55 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, |
| 23 | pfs(std::make_shared<PartitionFilesystem>(file)) { | 56 | pfs(std::make_shared<PartitionFilesystem>(file)) { |
| @@ -26,83 +59,16 @@ NSP::NSP(VirtualFile file_) | |||
| 26 | return; | 59 | return; |
| 27 | } | 60 | } |
| 28 | 61 | ||
| 62 | const auto files = pfs->GetFiles(); | ||
| 63 | |||
| 29 | if (IsDirectoryExeFS(pfs)) { | 64 | if (IsDirectoryExeFS(pfs)) { |
| 30 | extracted = true; | 65 | extracted = true; |
| 31 | exefs = pfs; | 66 | InitializeExeFSAndRomFS(files); |
| 32 | |||
| 33 | const auto& files = pfs->GetFiles(); | ||
| 34 | const auto romfs_iter = | ||
| 35 | std::find_if(files.begin(), files.end(), [](const FileSys::VirtualFile& file) { | ||
| 36 | return file->GetName().find(".romfs") != std::string::npos; | ||
| 37 | }); | ||
| 38 | if (romfs_iter != files.end()) | ||
| 39 | romfs = *romfs_iter; | ||
| 40 | return; | 67 | return; |
| 41 | } | 68 | } |
| 42 | 69 | ||
| 43 | extracted = false; | 70 | SetTicketKeys(files); |
| 44 | const auto files = pfs->GetFiles(); | 71 | ReadNCAs(files); |
| 45 | |||
| 46 | Core::Crypto::KeyManager keys; | ||
| 47 | for (const auto& ticket_file : files) { | ||
| 48 | if (ticket_file->GetExtension() == "tik") { | ||
| 49 | if (ticket_file == nullptr || | ||
| 50 | ticket_file->GetSize() < | ||
| 51 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 52 | continue; | ||
| 53 | } | ||
| 54 | |||
| 55 | Core::Crypto::Key128 key{}; | ||
| 56 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 57 | std::string_view name_only(ticket_file->GetName()); | ||
| 58 | name_only.remove_suffix(4); | ||
| 59 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 60 | u128 rights_id; | ||
| 61 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 62 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | for (const auto& outer_file : files) { | ||
| 67 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) == ".cnmt.nca") { | ||
| 68 | const auto nca = std::make_shared<NCA>(outer_file); | ||
| 69 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | ||
| 70 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 71 | continue; | ||
| 72 | } | ||
| 73 | |||
| 74 | const auto section0 = nca->GetSubdirectories()[0]; | ||
| 75 | |||
| 76 | for (const auto& inner_file : section0->GetFiles()) { | ||
| 77 | if (inner_file->GetExtension() != "cnmt") | ||
| 78 | continue; | ||
| 79 | |||
| 80 | const CNMT cnmt(inner_file); | ||
| 81 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | ||
| 82 | |||
| 83 | ncas_title[ContentRecordType::Meta] = nca; | ||
| 84 | for (const auto& rec : cnmt.GetContentRecords()) { | ||
| 85 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | ||
| 86 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | ||
| 87 | if (next_file == nullptr) { | ||
| 88 | LOG_WARNING(Service_FS, | ||
| 89 | "NCA with ID {}.nca is listed in content metadata, but cannot " | ||
| 90 | "be found in PFS. NSP appears to be corrupted.", | ||
| 91 | id_string); | ||
| 92 | continue; | ||
| 93 | } | ||
| 94 | |||
| 95 | auto next_nca = std::make_shared<NCA>(next_file); | ||
| 96 | if (next_nca->GetType() == NCAContentType::Program) | ||
| 97 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 98 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 99 | ncas_title[rec.type] = std::move(next_nca); | ||
| 100 | } | ||
| 101 | |||
| 102 | break; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | 72 | } |
| 107 | 73 | ||
| 108 | NSP::~NSP() = default; | 74 | NSP::~NSP() = default; |
| @@ -242,4 +208,63 @@ VirtualDir NSP::GetParentDirectory() const { | |||
| 242 | bool NSP::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 208 | bool NSP::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 243 | return false; | 209 | return false; |
| 244 | } | 210 | } |
| 211 | |||
| 212 | void NSP::InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files) { | ||
| 213 | exefs = pfs; | ||
| 214 | |||
| 215 | const auto romfs_iter = std::find_if(files.begin(), files.end(), [](const VirtualFile& file) { | ||
| 216 | return file->GetName().rfind(".romfs") != std::string::npos; | ||
| 217 | }); | ||
| 218 | |||
| 219 | if (romfs_iter == files.end()) { | ||
| 220 | return; | ||
| 221 | } | ||
| 222 | |||
| 223 | romfs = *romfs_iter; | ||
| 224 | } | ||
| 225 | |||
| 226 | void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { | ||
| 227 | for (const auto& outer_file : files) { | ||
| 228 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { | ||
| 229 | continue; | ||
| 230 | } | ||
| 231 | |||
| 232 | const auto nca = std::make_shared<NCA>(outer_file); | ||
| 233 | if (nca->GetStatus() != Loader::ResultStatus::Success) { | ||
| 234 | program_status[nca->GetTitleId()] = nca->GetStatus(); | ||
| 235 | continue; | ||
| 236 | } | ||
| 237 | |||
| 238 | const auto section0 = nca->GetSubdirectories()[0]; | ||
| 239 | |||
| 240 | for (const auto& inner_file : section0->GetFiles()) { | ||
| 241 | if (inner_file->GetExtension() != "cnmt") | ||
| 242 | continue; | ||
| 243 | |||
| 244 | const CNMT cnmt(inner_file); | ||
| 245 | auto& ncas_title = ncas[cnmt.GetTitleID()]; | ||
| 246 | |||
| 247 | ncas_title[ContentRecordType::Meta] = nca; | ||
| 248 | for (const auto& rec : cnmt.GetContentRecords()) { | ||
| 249 | const auto id_string = Common::HexArrayToString(rec.nca_id, false); | ||
| 250 | const auto next_file = pfs->GetFile(fmt::format("{}.nca", id_string)); | ||
| 251 | if (next_file == nullptr) { | ||
| 252 | LOG_WARNING(Service_FS, | ||
| 253 | "NCA with ID {}.nca is listed in content metadata, but cannot " | ||
| 254 | "be found in PFS. NSP appears to be corrupted.", | ||
| 255 | id_string); | ||
| 256 | continue; | ||
| 257 | } | ||
| 258 | |||
| 259 | auto next_nca = std::make_shared<NCA>(next_file); | ||
| 260 | if (next_nca->GetType() == NCAContentType::Program) | ||
| 261 | program_status[cnmt.GetTitleID()] = next_nca->GetStatus(); | ||
| 262 | if (next_nca->GetStatus() == Loader::ResultStatus::Success) | ||
| 263 | ncas_title[rec.type] = std::move(next_nca); | ||
| 264 | } | ||
| 265 | |||
| 266 | break; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | } | ||
| 245 | } // namespace FileSys | 270 | } // namespace FileSys |
diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h index e85a2b76e..da3dc5e9f 100644 --- a/src/core/file_sys/submission_package.h +++ b/src/core/file_sys/submission_package.h | |||
| @@ -59,9 +59,12 @@ protected: | |||
| 59 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; | 59 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; |
| 60 | 60 | ||
| 61 | private: | 61 | private: |
| 62 | void InitializeExeFSAndRomFS(const std::vector<VirtualFile>& files); | ||
| 63 | void ReadNCAs(const std::vector<VirtualFile>& files); | ||
| 64 | |||
| 62 | VirtualFile file; | 65 | VirtualFile file; |
| 63 | 66 | ||
| 64 | bool extracted; | 67 | bool extracted = false; |
| 65 | Loader::ResultStatus status; | 68 | Loader::ResultStatus status; |
| 66 | std::map<u64, Loader::ResultStatus> program_status; | 69 | std::map<u64, Loader::ResultStatus> program_status; |
| 67 | 70 | ||
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp index d9eeac9ec..79580bcd9 100644 --- a/src/core/hle/service/aoc/aoc_u.cpp +++ b/src/core/hle/service/aoc/aoc_u.cpp | |||
| @@ -2,22 +2,57 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <numeric> | ||
| 7 | #include <vector> | ||
| 5 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/file_sys/content_archive.h" | ||
| 10 | #include "core/file_sys/nca_metadata.h" | ||
| 11 | #include "core/file_sys/partition_filesystem.h" | ||
| 12 | #include "core/file_sys/registered_cache.h" | ||
| 6 | #include "core/hle/ipc_helpers.h" | 13 | #include "core/hle/ipc_helpers.h" |
| 14 | #include "core/hle/kernel/process.h" | ||
| 7 | #include "core/hle/service/aoc/aoc_u.h" | 15 | #include "core/hle/service/aoc/aoc_u.h" |
| 16 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 17 | #include "core/loader/loader.h" | ||
| 8 | 18 | ||
| 9 | namespace Service::AOC { | 19 | namespace Service::AOC { |
| 10 | 20 | ||
| 11 | AOC_U::AOC_U() : ServiceFramework("aoc:u") { | 21 | constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000; |
| 22 | constexpr u64 DLC_BASE_TO_AOC_ID_MASK = 0x1000; | ||
| 23 | |||
| 24 | static bool CheckAOCTitleIDMatchesBase(u64 base, u64 aoc) { | ||
| 25 | return (aoc & DLC_BASE_TITLE_ID_MASK) == base; | ||
| 26 | } | ||
| 27 | |||
| 28 | static std::vector<u64> AccumulateAOCTitleIDs() { | ||
| 29 | std::vector<u64> add_on_content; | ||
| 30 | const auto rcu = FileSystem::GetUnionContents(); | ||
| 31 | const auto list = | ||
| 32 | rcu->ListEntriesFilter(FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); | ||
| 33 | std::transform(list.begin(), list.end(), std::back_inserter(add_on_content), | ||
| 34 | [](const FileSys::RegisteredCacheEntry& rce) { return rce.title_id; }); | ||
| 35 | add_on_content.erase( | ||
| 36 | std::remove_if( | ||
| 37 | add_on_content.begin(), add_on_content.end(), | ||
| 38 | [&rcu](u64 tid) { | ||
| 39 | return rcu->GetEntry(tid, FileSys::ContentRecordType::Data)->GetStatus() != | ||
| 40 | Loader::ResultStatus::Success; | ||
| 41 | }), | ||
| 42 | add_on_content.end()); | ||
| 43 | return add_on_content; | ||
| 44 | } | ||
| 45 | |||
| 46 | AOC_U::AOC_U() : ServiceFramework("aoc:u"), add_on_content(AccumulateAOCTitleIDs()) { | ||
| 12 | static const FunctionInfo functions[] = { | 47 | static const FunctionInfo functions[] = { |
| 13 | {0, nullptr, "CountAddOnContentByApplicationId"}, | 48 | {0, nullptr, "CountAddOnContentByApplicationId"}, |
| 14 | {1, nullptr, "ListAddOnContentByApplicationId"}, | 49 | {1, nullptr, "ListAddOnContentByApplicationId"}, |
| 15 | {2, &AOC_U::CountAddOnContent, "CountAddOnContent"}, | 50 | {2, &AOC_U::CountAddOnContent, "CountAddOnContent"}, |
| 16 | {3, &AOC_U::ListAddOnContent, "ListAddOnContent"}, | 51 | {3, &AOC_U::ListAddOnContent, "ListAddOnContent"}, |
| 17 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, | 52 | {4, nullptr, "GetAddOnContentBaseIdByApplicationId"}, |
| 18 | {5, nullptr, "GetAddOnContentBaseId"}, | 53 | {5, &AOC_U::GetAddOnContentBaseId, "GetAddOnContentBaseId"}, |
| 19 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, | 54 | {6, nullptr, "PrepareAddOnContentByApplicationId"}, |
| 20 | {7, nullptr, "PrepareAddOnContent"}, | 55 | {7, &AOC_U::PrepareAddOnContent, "PrepareAddOnContent"}, |
| 21 | {8, nullptr, "GetAddOnContentListChangedEvent"}, | 56 | {8, nullptr, "GetAddOnContentListChangedEvent"}, |
| 22 | }; | 57 | }; |
| 23 | RegisterHandlers(functions); | 58 | RegisterHandlers(functions); |
| @@ -28,15 +63,59 @@ AOC_U::~AOC_U() = default; | |||
| 28 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { | 63 | void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) { |
| 29 | IPC::ResponseBuilder rb{ctx, 4}; | 64 | IPC::ResponseBuilder rb{ctx, 4}; |
| 30 | rb.Push(RESULT_SUCCESS); | 65 | rb.Push(RESULT_SUCCESS); |
| 31 | rb.Push<u64>(0); | 66 | |
| 32 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 67 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); |
| 68 | rb.Push<u32>(std::count_if(add_on_content.begin(), add_on_content.end(), [¤t](u64 tid) { | ||
| 69 | return (tid & DLC_BASE_TITLE_ID_MASK) == current; | ||
| 70 | })); | ||
| 33 | } | 71 | } |
| 34 | 72 | ||
| 35 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { | 73 | void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) { |
| 74 | IPC::RequestParser rp{ctx}; | ||
| 75 | |||
| 76 | const auto offset = rp.PopRaw<u32>(); | ||
| 77 | auto count = rp.PopRaw<u32>(); | ||
| 78 | |||
| 79 | const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID(); | ||
| 80 | |||
| 81 | std::vector<u32> out; | ||
| 82 | for (size_t i = 0; i < add_on_content.size(); ++i) { | ||
| 83 | if ((add_on_content[i] & DLC_BASE_TITLE_ID_MASK) == current) | ||
| 84 | out.push_back(static_cast<u32>(add_on_content[i] & 0x7FF)); | ||
| 85 | } | ||
| 86 | |||
| 87 | if (out.size() < offset) { | ||
| 88 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 89 | // TODO(DarkLordZach): Find the correct error code. | ||
| 90 | rb.Push(ResultCode(-1)); | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | |||
| 94 | count = std::min<size_t>(out.size() - offset, count); | ||
| 95 | std::rotate(out.begin(), out.begin() + offset, out.end()); | ||
| 96 | out.resize(count); | ||
| 97 | |||
| 98 | ctx.WriteBuffer(out); | ||
| 99 | |||
| 100 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 101 | rb.Push(RESULT_SUCCESS); | ||
| 102 | } | ||
| 103 | |||
| 104 | void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) { | ||
| 36 | IPC::ResponseBuilder rb{ctx, 4}; | 105 | IPC::ResponseBuilder rb{ctx, 4}; |
| 37 | rb.Push(RESULT_SUCCESS); | 106 | rb.Push(RESULT_SUCCESS); |
| 38 | rb.Push<u64>(0); | 107 | rb.Push(Core::System::GetInstance().CurrentProcess()->GetTitleID() | DLC_BASE_TO_AOC_ID_MASK); |
| 39 | LOG_WARNING(Service_AOC, "(STUBBED) called"); | 108 | } |
| 109 | |||
| 110 | void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) { | ||
| 111 | IPC::RequestParser rp{ctx}; | ||
| 112 | |||
| 113 | const auto aoc_id = rp.PopRaw<u32>(); | ||
| 114 | |||
| 115 | LOG_WARNING(Service_AOC, "(STUBBED) called with aoc_id={:08X}", aoc_id); | ||
| 116 | |||
| 117 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 118 | rb.Push(RESULT_SUCCESS); | ||
| 40 | } | 119 | } |
| 41 | 120 | ||
| 42 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 121 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/aoc/aoc_u.h b/src/core/hle/service/aoc/aoc_u.h index 29ce8f488..b3c7cab7a 100644 --- a/src/core/hle/service/aoc/aoc_u.h +++ b/src/core/hle/service/aoc/aoc_u.h | |||
| @@ -16,6 +16,10 @@ public: | |||
| 16 | private: | 16 | private: |
| 17 | void CountAddOnContent(Kernel::HLERequestContext& ctx); | 17 | void CountAddOnContent(Kernel::HLERequestContext& ctx); |
| 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); | 18 | void ListAddOnContent(Kernel::HLERequestContext& ctx); |
| 19 | void GetAddOnContentBaseId(Kernel::HLERequestContext& ctx); | ||
| 20 | void PrepareAddOnContent(Kernel::HLERequestContext& ctx); | ||
| 21 | |||
| 22 | std::vector<u64> add_on_content; | ||
| 19 | }; | 23 | }; |
| 20 | 24 | ||
| 21 | /// Registers all AOC services with the specified service manager. | 25 | /// Registers all AOC services with the specified service manager. |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index cabaf5a55..d5dced429 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -468,6 +468,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { | |||
| 468 | {80, nullptr, "OpenSaveDataMetaFile"}, | 468 | {80, nullptr, "OpenSaveDataMetaFile"}, |
| 469 | {81, nullptr, "OpenSaveDataTransferManager"}, | 469 | {81, nullptr, "OpenSaveDataTransferManager"}, |
| 470 | {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, | 470 | {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, |
| 471 | {83, nullptr, "OpenSaveDataTransferProhibiterForCloudBackUp"}, | ||
| 471 | {100, nullptr, "OpenImageDirectoryFileSystem"}, | 472 | {100, nullptr, "OpenImageDirectoryFileSystem"}, |
| 472 | {110, nullptr, "OpenContentStorageFileSystem"}, | 473 | {110, nullptr, "OpenContentStorageFileSystem"}, |
| 473 | {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, | 474 | {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, |
| @@ -495,6 +496,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { | |||
| 495 | {613, nullptr, "VerifySaveDataFileSystemBySaveDataSpaceId"}, | 496 | {613, nullptr, "VerifySaveDataFileSystemBySaveDataSpaceId"}, |
| 496 | {614, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId"}, | 497 | {614, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId"}, |
| 497 | {615, nullptr, "QuerySaveDataInternalStorageTotalSize"}, | 498 | {615, nullptr, "QuerySaveDataInternalStorageTotalSize"}, |
| 499 | {616, nullptr, "GetSaveDataCommitId"}, | ||
| 498 | {620, nullptr, "SetSdCardEncryptionSeed"}, | 500 | {620, nullptr, "SetSdCardEncryptionSeed"}, |
| 499 | {630, nullptr, "SetSdCardAccessibility"}, | 501 | {630, nullptr, "SetSdCardAccessibility"}, |
| 500 | {631, nullptr, "IsSdCardAccessible"}, | 502 | {631, nullptr, "IsSdCardAccessible"}, |
diff --git a/src/core/hle/service/lbl/lbl.cpp b/src/core/hle/service/lbl/lbl.cpp index 8fc8b1057..7321584e1 100644 --- a/src/core/hle/service/lbl/lbl.cpp +++ b/src/core/hle/service/lbl/lbl.cpp | |||
| @@ -21,29 +21,29 @@ public: | |||
| 21 | {0, nullptr, "Unknown1"}, | 21 | {0, nullptr, "Unknown1"}, |
| 22 | {1, nullptr, "Unknown2"}, | 22 | {1, nullptr, "Unknown2"}, |
| 23 | {2, nullptr, "Unknown3"}, | 23 | {2, nullptr, "Unknown3"}, |
| 24 | {3, nullptr, "Unknown4"}, | 24 | {3, nullptr, "GetCurrentBacklightLevel"}, |
| 25 | {4, nullptr, "Unknown5"}, | 25 | {4, nullptr, "Unknown4"}, |
| 26 | {5, nullptr, "Unknown6"}, | 26 | {5, nullptr, "GetAlsComputedBacklightLevel"}, |
| 27 | {6, nullptr, "TurnOffBacklight"}, | 27 | {6, nullptr, "TurnOffBacklight"}, |
| 28 | {7, nullptr, "TurnOnBacklight"}, | 28 | {7, nullptr, "TurnOnBacklight"}, |
| 29 | {8, nullptr, "GetBacklightStatus"}, | 29 | {8, nullptr, "GetBacklightStatus"}, |
| 30 | {9, nullptr, "Unknown7"}, | 30 | {9, nullptr, "Unknown5"}, |
| 31 | {10, nullptr, "Unknown8"}, | 31 | {10, nullptr, "Unknown6"}, |
| 32 | {11, nullptr, "Unknown9"}, | 32 | {11, nullptr, "Unknown7"}, |
| 33 | {12, nullptr, "Unknown10"}, | 33 | {12, nullptr, "Unknown8"}, |
| 34 | {13, nullptr, "Unknown11"}, | 34 | {13, nullptr, "Unknown9"}, |
| 35 | {14, nullptr, "Unknown12"}, | 35 | {14, nullptr, "Unknown10"}, |
| 36 | {15, nullptr, "Unknown13"}, | 36 | {15, nullptr, "GetAutoBrightnessSetting"}, |
| 37 | {16, nullptr, "ReadRawLightSensor"}, | 37 | {16, nullptr, "ReadRawLightSensor"}, |
| 38 | {17, nullptr, "Unknown14"}, | 38 | {17, nullptr, "Unknown11"}, |
| 39 | {18, nullptr, "Unknown15"}, | 39 | {18, nullptr, "Unknown12"}, |
| 40 | {19, nullptr, "Unknown16"}, | 40 | {19, nullptr, "Unknown13"}, |
| 41 | {20, nullptr, "Unknown17"}, | 41 | {20, nullptr, "Unknown14"}, |
| 42 | {21, nullptr, "Unknown18"}, | 42 | {21, nullptr, "Unknown15"}, |
| 43 | {22, nullptr, "Unknown19"}, | 43 | {22, nullptr, "Unknown16"}, |
| 44 | {23, nullptr, "Unknown20"}, | 44 | {23, nullptr, "Unknown17"}, |
| 45 | {24, nullptr, "Unknown21"}, | 45 | {24, nullptr, "Unknown18"}, |
| 46 | {25, nullptr, "Unknown22"}, | 46 | {25, nullptr, "Unknown19"}, |
| 47 | {26, &LBL::EnableVrMode, "EnableVrMode"}, | 47 | {26, &LBL::EnableVrMode, "EnableVrMode"}, |
| 48 | {27, &LBL::DisableVrMode, "DisableVrMode"}, | 48 | {27, &LBL::DisableVrMode, "DisableVrMode"}, |
| 49 | {28, &LBL::GetVrMode, "GetVrMode"}, | 49 | {28, &LBL::GetVrMode, "GetVrMode"}, |
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index c1824b9c3..9a86e5824 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -130,6 +130,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | process.LoadFromMetadata(metadata); | 132 | process.LoadFromMetadata(metadata); |
| 133 | const FileSys::PatchManager pm(metadata.GetTitleID()); | ||
| 133 | 134 | ||
| 134 | // Load NSO modules | 135 | // Load NSO modules |
| 135 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 136 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| @@ -139,7 +140,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 139 | const FileSys::VirtualFile module_file = dir->GetFile(module); | 140 | const FileSys::VirtualFile module_file = dir->GetFile(module); |
| 140 | if (module_file != nullptr) { | 141 | if (module_file != nullptr) { |
| 141 | const VAddr load_addr = next_load_addr; | 142 | const VAddr load_addr = next_load_addr; |
| 142 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr); | 143 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm); |
| 143 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | 144 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); |
| 144 | // Register module with GDBStub | 145 | // Register module with GDBStub |
| 145 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | 146 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index cbe2a3e53..2186b02af 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "core/core.h" | 12 | #include "core/core.h" |
| 13 | #include "core/file_sys/patch_manager.h" | ||
| 13 | #include "core/gdbstub/gdbstub.h" | 14 | #include "core/gdbstub/gdbstub.h" |
| 14 | #include "core/hle/kernel/kernel.h" | 15 | #include "core/hle/kernel/kernel.h" |
| 15 | #include "core/hle/kernel/process.h" | 16 | #include "core/hle/kernel/process.h" |
| @@ -36,8 +37,7 @@ struct NsoHeader { | |||
| 36 | INSERT_PADDING_WORDS(1); | 37 | INSERT_PADDING_WORDS(1); |
| 37 | u8 flags; | 38 | u8 flags; |
| 38 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) | 39 | std::array<NsoSegmentHeader, 3> segments; // Text, RoData, Data (in that order) |
| 39 | u32_le bss_size; | 40 | std::array<u8, 0x20> build_id; |
| 40 | INSERT_PADDING_BYTES(0x1c); | ||
| 41 | std::array<u32_le, 3> segments_compressed_size; | 41 | std::array<u32_le, 3> segments_compressed_size; |
| 42 | 42 | ||
| 43 | bool IsSegmentCompressed(size_t segment_num) const { | 43 | bool IsSegmentCompressed(size_t segment_num) const { |
| @@ -93,7 +93,8 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 97 | boost::optional<FileSys::PatchManager> pm) { | ||
| 97 | if (file == nullptr) | 98 | if (file == nullptr) |
| 98 | return {}; | 99 | return {}; |
| 99 | 100 | ||
| @@ -142,6 +143,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { | |||
| 142 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; | 143 | const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; |
| 143 | program_image.resize(image_size); | 144 | program_image.resize(image_size); |
| 144 | 145 | ||
| 146 | // Apply patches if necessary | ||
| 147 | if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { | ||
| 148 | std::vector<u8> pi_header(program_image.size() + 0x100); | ||
| 149 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | ||
| 150 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | ||
| 151 | |||
| 152 | pi_header = pm->PatchNSO(pi_header); | ||
| 153 | |||
| 154 | std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size()); | ||
| 155 | } | ||
| 156 | |||
| 145 | // Load codeset for current process | 157 | // Load codeset for current process |
| 146 | codeset->name = file->GetName(); | 158 | codeset->name = file->GetName(); |
| 147 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 159 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 7f142405b..05353d4d9 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "core/file_sys/patch_manager.h" | ||
| 8 | #include "core/loader/linker.h" | 9 | #include "core/loader/linker.h" |
| 9 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 10 | 11 | ||
| @@ -26,7 +27,8 @@ public: | |||
| 26 | return IdentifyType(file); | 27 | return IdentifyType(file); |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base); | 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 31 | boost::optional<FileSys::PatchManager> pm = boost::none); | ||
| 30 | 32 | ||
| 31 | ResultStatus Load(Kernel::Process& process) override; | 33 | ResultStatus Load(Kernel::Process& process) override; |
| 32 | }; | 34 | }; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 14d82a7bc..587d9dffb 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -909,7 +909,10 @@ void RasterizerOpenGL::SyncTransformFeedback() { | |||
| 909 | void RasterizerOpenGL::SyncPointState() { | 909 | void RasterizerOpenGL::SyncPointState() { |
| 910 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; | 910 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; |
| 911 | 911 | ||
| 912 | state.point.size = regs.point_size; | 912 | // TODO(Rodrigo): Most games do not set a point size. I think this is a case of a |
| 913 | // register carrying a default value. For now, if the point size is zero, assume it's | ||
| 914 | // OpenGL's default (1). | ||
| 915 | state.point.size = regs.point_size == 0 ? 1 : regs.point_size; | ||
| 913 | } | 916 | } |
| 914 | 917 | ||
| 915 | } // namespace OpenGL | 918 | } // namespace OpenGL |
diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index 6ea59f2a3..eb1da0f9e 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp | |||
| @@ -21,9 +21,8 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) | |||
| 21 | ui->output_sink_combo_box->addItem(sink_detail.id); | 21 | ui->output_sink_combo_box->addItem(sink_detail.id); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | connect(ui->volume_slider, &QSlider::valueChanged, [this] { | 24 | connect(ui->volume_slider, &QSlider::valueChanged, this, |
| 25 | ui->volume_indicator->setText(tr("%1 %").arg(ui->volume_slider->sliderPosition())); | 25 | &ConfigureAudio::setVolumeIndicatorText); |
| 26 | }); | ||
| 27 | 26 | ||
| 28 | this->setConfiguration(); | 27 | this->setConfiguration(); |
| 29 | connect(ui->output_sink_combo_box, | 28 | connect(ui->output_sink_combo_box, |
| @@ -37,32 +36,48 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) | |||
| 37 | ConfigureAudio::~ConfigureAudio() = default; | 36 | ConfigureAudio::~ConfigureAudio() = default; |
| 38 | 37 | ||
| 39 | void ConfigureAudio::setConfiguration() { | 38 | void ConfigureAudio::setConfiguration() { |
| 39 | setOutputSinkFromSinkID(); | ||
| 40 | |||
| 41 | // The device list cannot be pre-populated (nor listed) until the output sink is known. | ||
| 42 | updateAudioDevices(ui->output_sink_combo_box->currentIndex()); | ||
| 43 | |||
| 44 | setAudioDeviceFromDeviceID(); | ||
| 45 | |||
| 46 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); | ||
| 47 | ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum()); | ||
| 48 | setVolumeIndicatorText(ui->volume_slider->sliderPosition()); | ||
| 49 | } | ||
| 50 | |||
| 51 | void ConfigureAudio::setOutputSinkFromSinkID() { | ||
| 40 | int new_sink_index = 0; | 52 | int new_sink_index = 0; |
| 53 | |||
| 54 | const QString sink_id = QString::fromStdString(Settings::values.sink_id); | ||
| 41 | for (int index = 0; index < ui->output_sink_combo_box->count(); index++) { | 55 | for (int index = 0; index < ui->output_sink_combo_box->count(); index++) { |
| 42 | if (ui->output_sink_combo_box->itemText(index).toStdString() == Settings::values.sink_id) { | 56 | if (ui->output_sink_combo_box->itemText(index) == sink_id) { |
| 43 | new_sink_index = index; | 57 | new_sink_index = index; |
| 44 | break; | 58 | break; |
| 45 | } | 59 | } |
| 46 | } | 60 | } |
| 47 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); | ||
| 48 | 61 | ||
| 49 | ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); | 62 | ui->output_sink_combo_box->setCurrentIndex(new_sink_index); |
| 50 | 63 | } | |
| 51 | // The device list cannot be pre-populated (nor listed) until the output sink is known. | ||
| 52 | updateAudioDevices(new_sink_index); | ||
| 53 | 64 | ||
| 65 | void ConfigureAudio::setAudioDeviceFromDeviceID() { | ||
| 54 | int new_device_index = -1; | 66 | int new_device_index = -1; |
| 67 | |||
| 68 | const QString device_id = QString::fromStdString(Settings::values.audio_device_id); | ||
| 55 | for (int index = 0; index < ui->audio_device_combo_box->count(); index++) { | 69 | for (int index = 0; index < ui->audio_device_combo_box->count(); index++) { |
| 56 | if (ui->audio_device_combo_box->itemText(index).toStdString() == | 70 | if (ui->audio_device_combo_box->itemText(index) == device_id) { |
| 57 | Settings::values.audio_device_id) { | ||
| 58 | new_device_index = index; | 71 | new_device_index = index; |
| 59 | break; | 72 | break; |
| 60 | } | 73 | } |
| 61 | } | 74 | } |
| 75 | |||
| 62 | ui->audio_device_combo_box->setCurrentIndex(new_device_index); | 76 | ui->audio_device_combo_box->setCurrentIndex(new_device_index); |
| 77 | } | ||
| 63 | 78 | ||
| 64 | ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum()); | 79 | void ConfigureAudio::setVolumeIndicatorText(int percentage) { |
| 65 | ui->volume_indicator->setText(tr("%1 %").arg(ui->volume_slider->sliderPosition())); | 80 | ui->volume_indicator->setText(tr("%1%", "Volume percentage (e.g. 50%)").arg(percentage)); |
| 66 | } | 81 | } |
| 67 | 82 | ||
| 68 | void ConfigureAudio::applyConfiguration() { | 83 | void ConfigureAudio::applyConfiguration() { |
| @@ -81,10 +96,10 @@ void ConfigureAudio::updateAudioDevices(int sink_index) { | |||
| 81 | ui->audio_device_combo_box->clear(); | 96 | ui->audio_device_combo_box->clear(); |
| 82 | ui->audio_device_combo_box->addItem(AudioCore::auto_device_name); | 97 | ui->audio_device_combo_box->addItem(AudioCore::auto_device_name); |
| 83 | 98 | ||
| 84 | std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString(); | 99 | const std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString(); |
| 85 | std::vector<std::string> device_list = AudioCore::GetSinkDetails(sink_id).list_devices(); | 100 | const std::vector<std::string> device_list = AudioCore::GetSinkDetails(sink_id).list_devices(); |
| 86 | for (const auto& device : device_list) { | 101 | for (const auto& device : device_list) { |
| 87 | ui->audio_device_combo_box->addItem(device.c_str()); | 102 | ui->audio_device_combo_box->addItem(QString::fromStdString(device)); |
| 88 | } | 103 | } |
| 89 | } | 104 | } |
| 90 | 105 | ||
diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index 4f0af4163..207f9dfb3 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h | |||
| @@ -26,6 +26,9 @@ public slots: | |||
| 26 | 26 | ||
| 27 | private: | 27 | private: |
| 28 | void setConfiguration(); | 28 | void setConfiguration(); |
| 29 | void setOutputSinkFromSinkID(); | ||
| 30 | void setAudioDeviceFromDeviceID(); | ||
| 31 | void setVolumeIndicatorText(int percentage); | ||
| 29 | 32 | ||
| 30 | std::unique_ptr<Ui::ConfigureAudio> ui; | 33 | std::unique_ptr<Ui::ConfigureAudio> ui; |
| 31 | }; | 34 | }; |
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 839d58f59..cd1549462 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -8,27 +8,7 @@ | |||
| 8 | #include "ui_configure_graphics.h" | 8 | #include "ui_configure_graphics.h" |
| 9 | #include "yuzu/configuration/configure_graphics.h" | 9 | #include "yuzu/configuration/configure_graphics.h" |
| 10 | 10 | ||
| 11 | ConfigureGraphics::ConfigureGraphics(QWidget* parent) | 11 | namespace { |
| 12 | : QWidget(parent), ui(new Ui::ConfigureGraphics) { | ||
| 13 | |||
| 14 | ui->setupUi(this); | ||
| 15 | this->setConfiguration(); | ||
| 16 | |||
| 17 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit); | ||
| 18 | connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, | ||
| 19 | &QSpinBox::setEnabled); | ||
| 20 | connect(ui->bg_button, &QPushButton::clicked, this, [this] { | ||
| 21 | const QColor new_bg_color = QColorDialog::getColor(bg_color); | ||
| 22 | if (!new_bg_color.isValid()) | ||
| 23 | return; | ||
| 24 | bg_color = new_bg_color; | ||
| 25 | ui->bg_button->setStyleSheet( | ||
| 26 | QString("QPushButton { background-color: %1 }").arg(bg_color.name())); | ||
| 27 | }); | ||
| 28 | } | ||
| 29 | |||
| 30 | ConfigureGraphics::~ConfigureGraphics() = default; | ||
| 31 | |||
| 32 | enum class Resolution : int { | 12 | enum class Resolution : int { |
| 33 | Auto, | 13 | Auto, |
| 34 | Scale1x, | 14 | Scale1x, |
| @@ -67,6 +47,28 @@ Resolution FromResolutionFactor(float factor) { | |||
| 67 | } | 47 | } |
| 68 | return Resolution::Auto; | 48 | return Resolution::Auto; |
| 69 | } | 49 | } |
| 50 | } // Anonymous namespace | ||
| 51 | |||
| 52 | ConfigureGraphics::ConfigureGraphics(QWidget* parent) | ||
| 53 | : QWidget(parent), ui(new Ui::ConfigureGraphics) { | ||
| 54 | |||
| 55 | ui->setupUi(this); | ||
| 56 | this->setConfiguration(); | ||
| 57 | |||
| 58 | ui->frame_limit->setEnabled(Settings::values.use_frame_limit); | ||
| 59 | connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, | ||
| 60 | &QSpinBox::setEnabled); | ||
| 61 | connect(ui->bg_button, &QPushButton::clicked, this, [this] { | ||
| 62 | const QColor new_bg_color = QColorDialog::getColor(bg_color); | ||
| 63 | if (!new_bg_color.isValid()) | ||
| 64 | return; | ||
| 65 | bg_color = new_bg_color; | ||
| 66 | ui->bg_button->setStyleSheet( | ||
| 67 | QString("QPushButton { background-color: %1 }").arg(bg_color.name())); | ||
| 68 | }); | ||
| 69 | } | ||
| 70 | |||
| 71 | ConfigureGraphics::~ConfigureGraphics() = default; | ||
| 70 | 72 | ||
| 71 | void ConfigureGraphics::setConfiguration() { | 73 | void ConfigureGraphics::setConfiguration() { |
| 72 | ui->resolution_factor_combobox->setCurrentIndex( | 74 | ui->resolution_factor_combobox->setCurrentIndex( |
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index d29abb74b..473937ea9 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp | |||
| @@ -152,9 +152,9 @@ ConfigureInput::ConfigureInput(QWidget* parent) | |||
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { | 154 | connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { |
| 155 | QMessageBox::information( | 155 | QMessageBox::information(this, tr("Information"), |
| 156 | this, "Information", | 156 | tr("After pressing OK, first move your joystick horizontally, " |
| 157 | "After pressing OK, first move your joystick horizontally, and then vertically."); | 157 | "and then vertically.")); |
| 158 | handleClick( | 158 | handleClick( |
| 159 | analog_map_stick[analog_id], | 159 | analog_map_stick[analog_id], |
| 160 | [=](const Common::ParamPackage& params) { analogs_param[analog_id] = params; }, | 160 | [=](const Common::ParamPackage& params) { analogs_param[analog_id] = params; }, |
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index e228d61bd..1947bdb93 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -60,14 +60,13 @@ QString FormatGameName(const std::string& physical_name) { | |||
| 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { | 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { |
| 61 | QString out; | 61 | QString out; |
| 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { | 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { |
| 63 | if (!updatable && kv.first == FileSys::PatchType::Update) | 63 | if (!updatable && kv.first == "Update") |
| 64 | continue; | 64 | continue; |
| 65 | 65 | ||
| 66 | if (kv.second.empty()) { | 66 | if (kv.second.empty()) { |
| 67 | out.append(fmt::format("{}\n", FileSys::FormatPatchTypeName(kv.first)).c_str()); | 67 | out.append(fmt::format("{}\n", kv.first).c_str()); |
| 68 | } else { | 68 | } else { |
| 69 | out.append(fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), kv.second) | 69 | out.append(fmt::format("{} ({})\n", kv.first, kv.second).c_str()); |
| 70 | .c_str()); | ||
| 71 | } | 70 | } |
| 72 | } | 71 | } |
| 73 | 72 | ||