From 8b857fc7c2908aad389e65963e0ddf5003daf795 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 5 Jul 2019 18:51:41 -0400 Subject: [PATCH] system_archive: Synthesize shared fonts system archives --- .../file_sys/system_archive/shared_font.cpp | 78 +++++++++++++++++++ .../file_sys/system_archive/shared_font.h | 17 ++++ .../system_archive/system_archive.cpp | 11 +-- 3 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/core/file_sys/system_archive/shared_font.cpp create mode 100644 src/core/file_sys/system_archive/shared_font.h diff --git a/src/core/file_sys/system_archive/shared_font.cpp b/src/core/file_sys/system_archive/shared_font.cpp new file mode 100644 index 000000000..2c05eb42e --- /dev/null +++ b/src/core/file_sys/system_archive/shared_font.cpp @@ -0,0 +1,78 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/file_sys/system_archive/data/font_chinese_simplified.h" +#include "core/file_sys/system_archive/data/font_chinese_traditional.h" +#include "core/file_sys/system_archive/data/font_extended_chinese_simplified.h" +#include "core/file_sys/system_archive/data/font_korean.h" +#include "core/file_sys/system_archive/data/font_nintendo_extended.h" +#include "core/file_sys/system_archive/data/font_standard.h" +#include "core/file_sys/system_archive/shared_font.h" +#include "core/file_sys/vfs_vector.h" +#include "core/hle/service/ns/pl_u.h" + +namespace FileSys::SystemArchive { + +namespace { + +template +VirtualFile PackBFTTF(const std::array& data, const std::string& name) { + std::vector vec(Size / sizeof(u32)); + std::memcpy(vec.data(), data.data(), vec.size() * sizeof(u32)); + + std::vector bfttf(Size + sizeof(u64)); + + u64 offset = 0; + Service::NS::EncryptSharedFont(vec, bfttf, offset); + return std::make_shared(std::move(bfttf), name); +} + +} // Anonymous namespace + +VirtualDir FontNintendoExtension() { + return std::make_shared( + std::vector{ + PackBFTTF(SharedFontData::FONT_NINTENDO_EXTENDED, "nintendo_ext_003.bfttf"), + PackBFTTF(SharedFontData::FONT_NINTENDO_EXTENDED, "nintendo_ext2_003.bfttf"), + }, + std::vector{}); +} + +VirtualDir FontStandard() { + return std::make_shared( + std::vector{ + PackBFTTF(SharedFontData::FONT_STANDARD, "nintendo_udsg-r_std_003.bfttf"), + }, + std::vector{}); +} + +VirtualDir FontKorean() { + return std::make_shared( + std::vector{ + PackBFTTF(SharedFontData::FONT_KOREAN, "nintendo_udsg-r_ko_003.bfttf"), + }, + std::vector{}); +} + +VirtualDir FontChineseTraditional() { + return std::make_shared( + std::vector{ + PackBFTTF(SharedFontData::FONT_CHINESE_TRADITIONAL, + "nintendo_udjxh-db_zh-tw_003.bfttf"), + }, + std::vector{}); +} + +VirtualDir FontChineseSimple() { + return std::make_shared( + std::vector{ + PackBFTTF(SharedFontData::FONT_CHINESE_SIMPLIFIED, + "nintendo_udsg-r_org_zh-cn_003.bfttf"), + PackBFTTF(SharedFontData::FONT_EXTENDED_CHINESE_SIMPLIFIED, + "nintendo_udsg-r_ext_zh-cn_003.bfttf"), + }, + std::vector{}); +} + +} // namespace FileSys::SystemArchive diff --git a/src/core/file_sys/system_archive/shared_font.h b/src/core/file_sys/system_archive/shared_font.h new file mode 100644 index 000000000..6d8de565b --- /dev/null +++ b/src/core/file_sys/system_archive/shared_font.h @@ -0,0 +1,17 @@ +// Copyright 2019 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/file_sys/vfs_types.h" + +namespace FileSys::SystemArchive { + +VirtualDir FontNintendoExtension(); +VirtualDir FontStandard(); +VirtualDir FontKorean(); +VirtualDir FontChineseTraditional(); +VirtualDir FontChineseSimple(); + +} // namespace FileSys::SystemArchive diff --git a/src/core/file_sys/system_archive/system_archive.cpp b/src/core/file_sys/system_archive/system_archive.cpp index 6d8445383..e93d100a5 100644 --- a/src/core/file_sys/system_archive/system_archive.cpp +++ b/src/core/file_sys/system_archive/system_archive.cpp @@ -6,6 +6,7 @@ #include "core/file_sys/romfs.h" #include "core/file_sys/system_archive/mii_model.h" #include "core/file_sys/system_archive/ng_word.h" +#include "core/file_sys/system_archive/shared_font.h" #include "core/file_sys/system_archive/system_archive.h" #include "core/file_sys/system_archive/system_version.h" @@ -39,11 +40,11 @@ constexpr std::array SYSTEM_ARCHI {0x010000000000080D, "UrlBlackList", nullptr}, {0x010000000000080E, "TimeZoneBinary", nullptr}, {0x010000000000080F, "CertStoreCruiser", nullptr}, - {0x0100000000000810, "FontNintendoExtension", nullptr}, - {0x0100000000000811, "FontStandard", nullptr}, - {0x0100000000000812, "FontKorean", nullptr}, - {0x0100000000000813, "FontChineseTraditional", nullptr}, - {0x0100000000000814, "FontChineseSimple", nullptr}, + {0x0100000000000810, "FontNintendoExtension", &FontNintendoExtension}, + {0x0100000000000811, "FontStandard", &FontStandard}, + {0x0100000000000812, "FontKorean", &FontKorean}, + {0x0100000000000813, "FontChineseTraditional", &FontChineseTraditional}, + {0x0100000000000814, "FontChineseSimple", &FontChineseSimple}, {0x0100000000000815, "FontBfcpx", nullptr}, {0x0100000000000816, "SystemUpdate", nullptr}, {0x0100000000000817, "0100000000000817", nullptr},