summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2016-05-25 16:40:36 -0400
committerGravatar bunnei2016-05-25 16:40:36 -0400
commitf50a32bfce099eeff510e5e314b91dcf65d317ac (patch)
tree5bc0347199d722861ba09897e6c6e9015cf026bc /src
parentNew3DS: Minor style cleanup to #1520. (diff)
parentLoader: Split SMDH into its own header and import helpers from QGameList (diff)
downloadyuzu-f50a32bfce099eeff510e5e314b91dcf65d317ac.tar.gz
yuzu-f50a32bfce099eeff510e5e314b91dcf65d317ac.tar.xz
yuzu-f50a32bfce099eeff510e5e314b91dcf65d317ac.zip
Merge pull request #1817 from linkmauve/smdh-stuff
Improve SMDH support in loaders and frontends
Diffstat (limited to 'src')
-rw-r--r--src/citra/citra.cpp8
-rw-r--r--src/citra_qt/game_list.cpp22
-rw-r--r--src/citra_qt/game_list_p.h53
-rw-r--r--src/citra_qt/main.cpp10
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/loader/3dsx.cpp3
-rw-r--r--src/core/loader/3dsx.h8
-rw-r--r--src/core/loader/elf.h8
-rw-r--r--src/core/loader/loader.cpp60
-rw-r--r--src/core/loader/loader.h69
-rw-r--r--src/core/loader/ncch.cpp9
-rw-r--r--src/core/loader/ncch.h8
-rw-r--r--src/core/loader/smdh.cpp54
-rw-r--r--src/core/loader/smdh.h82
14 files changed, 229 insertions, 167 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index b4501eb2e..e01216734 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -114,7 +114,13 @@ int main(int argc, char **argv) {
114 System::Init(emu_window.get()); 114 System::Init(emu_window.get());
115 SCOPE_EXIT({ System::Shutdown(); }); 115 SCOPE_EXIT({ System::Shutdown(); });
116 116
117 Loader::ResultStatus load_result = Loader::LoadFile(boot_filename); 117 std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename);
118 if (!loader) {
119 LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str());
120 return -1;
121 }
122
123 Loader::ResultStatus load_result = loader->Load();
118 if (Loader::ResultStatus::Success != load_result) { 124 if (Loader::ResultStatus::Success != load_result) {
119 LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); 125 LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result);
120 return -1; 126 return -1;
diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp
index d4ac9c96e..570647539 100644
--- a/src/citra_qt/game_list.cpp
+++ b/src/citra_qt/game_list.cpp
@@ -132,30 +132,16 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, bool d
132 if (deep_scan && FileUtil::IsDirectory(physical_name)) { 132 if (deep_scan && FileUtil::IsDirectory(physical_name)) {
133 AddFstEntriesToGameList(physical_name, true); 133 AddFstEntriesToGameList(physical_name, true);
134 } else { 134 } else {
135 std::string filename_filename, filename_extension; 135 std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
136 Common::SplitPath(physical_name, nullptr, &filename_filename, &filename_extension); 136 if (!loader)
137
138 Loader::FileType guessed_filetype = Loader::GuessFromExtension(filename_extension);
139 if (guessed_filetype == Loader::FileType::Unknown)
140 return true;
141 Loader::FileType filetype = Loader::IdentifyFile(physical_name);
142 if (filetype == Loader::FileType::Unknown) {
143 LOG_WARNING(Frontend, "File %s is of indeterminate type and is possibly corrupted.", physical_name.c_str());
144 return true; 137 return true;
145 }
146 if (guessed_filetype != filetype) {
147 LOG_WARNING(Frontend, "Filetype and extension of file %s do not match.", physical_name.c_str());
148 }
149 138
150 std::vector<u8> smdh; 139 std::vector<u8> smdh;
151 std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(FileUtil::IOFile(physical_name, "rb"), filetype, filename_filename, physical_name); 140 loader->ReadIcon(smdh);
152
153 if (loader)
154 loader->ReadIcon(smdh);
155 141
156 emit EntryReady({ 142 emit EntryReady({
157 new GameListItemPath(QString::fromStdString(physical_name), smdh), 143 new GameListItemPath(QString::fromStdString(physical_name), smdh),
158 new GameListItem(QString::fromStdString(Loader::GetFileTypeString(filetype))), 144 new GameListItem(QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))),
159 new GameListItemSize(FileUtil::GetSize(physical_name)), 145 new GameListItemSize(FileUtil::GetSize(physical_name)),
160 }); 146 });
161 } 147 }
diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h
index 284f5da81..121f90b0c 100644
--- a/src/citra_qt/game_list_p.h
+++ b/src/citra_qt/game_list_p.h
@@ -15,52 +15,21 @@
15#include "common/string_util.h" 15#include "common/string_util.h"
16#include "common/color.h" 16#include "common/color.h"
17 17
18#include "core/loader/loader.h" 18#include "core/loader/smdh.h"
19 19
20#include "video_core/utils.h" 20#include "video_core/utils.h"
21 21
22/** 22/**
23 * Tests if data is a valid SMDH by its length and magic number.
24 * @param smdh_data data buffer to test
25 * @return bool test result
26 */
27static bool IsValidSMDH(const std::vector<u8>& smdh_data) {
28 if (smdh_data.size() < sizeof(Loader::SMDH))
29 return false;
30
31 u32 magic;
32 memcpy(&magic, smdh_data.data(), 4);
33
34 return Loader::MakeMagic('S', 'M', 'D', 'H') == magic;
35}
36
37/**
38 * Gets game icon from SMDH 23 * Gets game icon from SMDH
39 * @param sdmh SMDH data 24 * @param sdmh SMDH data
40 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24) 25 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24)
41 * @return QPixmap game icon 26 * @return QPixmap game icon
42 */ 27 */
43static QPixmap GetIconFromSMDH(const Loader::SMDH& smdh, bool large) { 28static QPixmap GetQPixmapFromSMDH(const Loader::SMDH& smdh, bool large) {
44 u32 size; 29 std::vector<u16> icon_data = smdh.GetIcon(large);
45 const u8* icon_data; 30 const uchar* data = reinterpret_cast<const uchar*>(icon_data.data());
46 31 int size = large ? 48 : 24;
47 if (large) { 32 QImage icon(data, size, size, QImage::Format::Format_RGB16);
48 size = 48;
49 icon_data = smdh.large_icon.data();
50 } else {
51 size = 24;
52 icon_data = smdh.small_icon.data();
53 }
54
55 QImage icon(size, size, QImage::Format::Format_RGB888);
56 for (u32 x = 0; x < size; ++x) {
57 for (u32 y = 0; y < size; ++y) {
58 u32 coarse_y = y & ~7;
59 auto v = Color::DecodeRGB565(
60 icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2);
61 icon.setPixel(x, y, qRgb(v.r(), v.g(), v.b()));
62 }
63 }
64 return QPixmap::fromImage(icon); 33 return QPixmap::fromImage(icon);
65} 34}
66 35
@@ -82,8 +51,8 @@ static QPixmap GetDefaultIcon(bool large) {
82 * @param language title language 51 * @param language title language
83 * @return QString short title 52 * @return QString short title
84 */ 53 */
85static QString GetShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) { 54static QString GetQStringShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) {
86 return QString::fromUtf16(smdh.titles[static_cast<int>(language)].short_title.data()); 55 return QString::fromUtf16(smdh.GetShortTitle(language).data());
87} 56}
88 57
89class GameListItem : public QStandardItem { 58class GameListItem : public QStandardItem {
@@ -112,7 +81,7 @@ public:
112 { 81 {
113 setData(game_path, FullPathRole); 82 setData(game_path, FullPathRole);
114 83
115 if (!IsValidSMDH(smdh_data)) { 84 if (!Loader::IsValidSMDH(smdh_data)) {
116 // SMDH is not valid, set a default icon 85 // SMDH is not valid, set a default icon
117 setData(GetDefaultIcon(true), Qt::DecorationRole); 86 setData(GetDefaultIcon(true), Qt::DecorationRole);
118 return; 87 return;
@@ -122,10 +91,10 @@ public:
122 memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); 91 memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH));
123 92
124 // Get icon from SMDH 93 // Get icon from SMDH
125 setData(GetIconFromSMDH(smdh, true), Qt::DecorationRole); 94 setData(GetQPixmapFromSMDH(smdh, true), Qt::DecorationRole);
126 95
127 // Get title form SMDH 96 // Get title form SMDH
128 setData(GetShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole); 97 setData(GetQStringShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole);
129 } 98 }
130 99
131 QVariant data(int role) const override { 100 QVariant data(int role) const override {
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index a85c94a4b..6239160bc 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -272,7 +272,15 @@ bool GMainWindow::InitializeSystem() {
272} 272}
273 273
274bool GMainWindow::LoadROM(const std::string& filename) { 274bool GMainWindow::LoadROM(const std::string& filename) {
275 Loader::ResultStatus result = Loader::LoadFile(filename); 275 std::unique_ptr<Loader::AppLoader> app_loader = Loader::GetLoader(filename);
276 if (!app_loader) {
277 LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str());
278 QMessageBox::critical(this, tr("Error while loading ROM!"),
279 tr("The ROM format is not supported."));
280 return false;
281 }
282
283 Loader::ResultStatus result = app_loader->Load();
276 if (Loader::ResultStatus::Success != result) { 284 if (Loader::ResultStatus::Success != result) {
277 LOG_CRITICAL(Frontend, "Failed to load ROM!"); 285 LOG_CRITICAL(Frontend, "Failed to load ROM!");
278 System::Shutdown(); 286 System::Shutdown();
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 12080a802..ed80cf0e4 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -121,6 +121,7 @@ set(SRCS
121 loader/elf.cpp 121 loader/elf.cpp
122 loader/loader.cpp 122 loader/loader.cpp
123 loader/ncch.cpp 123 loader/ncch.cpp
124 loader/smdh.cpp
124 tracer/recorder.cpp 125 tracer/recorder.cpp
125 memory.cpp 126 memory.cpp
126 settings.cpp 127 settings.cpp
@@ -256,6 +257,7 @@ set(HEADERS
256 loader/elf.h 257 loader/elf.h
257 loader/loader.h 258 loader/loader.h
258 loader/ncch.h 259 loader/ncch.h
260 loader/smdh.h
259 tracer/recorder.h 261 tracer/recorder.h
260 tracer/citrace.h 262 tracer/citrace.h
261 memory.h 263 memory.h
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index 98e7ab48f..a16411e14 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -10,6 +10,7 @@
10#include "core/file_sys/archive_romfs.h" 10#include "core/file_sys/archive_romfs.h"
11#include "core/hle/kernel/process.h" 11#include "core/hle/kernel/process.h"
12#include "core/hle/kernel/resource_limit.h" 12#include "core/hle/kernel/resource_limit.h"
13#include "core/hle/service/fs/archive.h"
13#include "core/loader/3dsx.h" 14#include "core/loader/3dsx.h"
14#include "core/memory.h" 15#include "core/memory.h"
15 16
@@ -263,6 +264,8 @@ ResultStatus AppLoader_THREEDSX::Load() {
263 264
264 Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); 265 Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE);
265 266
267 Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), Service::FS::ArchiveIdCode::RomFS);
268
266 is_loaded = true; 269 is_loaded = true;
267 return ResultStatus::Success; 270 return ResultStatus::Success;
268} 271}
diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h
index 3ee686703..90b20c61c 100644
--- a/src/core/loader/3dsx.h
+++ b/src/core/loader/3dsx.h
@@ -28,6 +28,14 @@ public:
28 static FileType IdentifyType(FileUtil::IOFile& file); 28 static FileType IdentifyType(FileUtil::IOFile& file);
29 29
30 /** 30 /**
31 * Returns the type of this file
32 * @return FileType corresponding to the loaded file
33 */
34 FileType GetFileType() override {
35 return IdentifyType(file);
36 }
37
38 /**
31 * Load the bootable file 39 * Load the bootable file
32 * @return ResultStatus result of function 40 * @return ResultStatus result of function
33 */ 41 */
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h
index c6a5ebe99..cb3724f9d 100644
--- a/src/core/loader/elf.h
+++ b/src/core/loader/elf.h
@@ -28,6 +28,14 @@ public:
28 static FileType IdentifyType(FileUtil::IOFile& file); 28 static FileType IdentifyType(FileUtil::IOFile& file);
29 29
30 /** 30 /**
31 * Returns the type of this file
32 * @return FileType corresponding to the loaded file
33 */
34 FileType GetFileType() override {
35 return IdentifyType(file);
36 }
37
38 /**
31 * Load the bootable file 39 * Load the bootable file
32 * @return ResultStatus result of function 40 * @return ResultStatus result of function
33 */ 41 */
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index af3f62248..9719d30d5 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -8,9 +8,7 @@
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "common/string_util.h" 9#include "common/string_util.h"
10 10
11#include "core/file_sys/archive_romfs.h"
12#include "core/hle/kernel/process.h" 11#include "core/hle/kernel/process.h"
13#include "core/hle/service/fs/archive.h"
14#include "core/loader/3dsx.h" 12#include "core/loader/3dsx.h"
15#include "core/loader/elf.h" 13#include "core/loader/elf.h"
16#include "core/loader/ncch.h" 14#include "core/loader/ncch.h"
@@ -67,6 +65,9 @@ FileType GuessFromExtension(const std::string& extension_) {
67 if (extension == ".3dsx") 65 if (extension == ".3dsx")
68 return FileType::THREEDSX; 66 return FileType::THREEDSX;
69 67
68 if (extension == ".cia")
69 return FileType::CIA;
70
70 return FileType::Unknown; 71 return FileType::Unknown;
71} 72}
72 73
@@ -90,7 +91,15 @@ const char* GetFileTypeString(FileType type) {
90 return "unknown"; 91 return "unknown";
91} 92}
92 93
93std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, 94/**
95 * Get a loader for a file with a specific type
96 * @param file The file to load
97 * @param type The type of the file
98 * @param filename the file name (without path)
99 * @param filepath the file full path (with name)
100 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
101 */
102static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type,
94 const std::string& filename, const std::string& filepath) { 103 const std::string& filename, const std::string& filepath) {
95 switch (type) { 104 switch (type) {
96 105
@@ -108,15 +117,15 @@ std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type,
108 return std::make_unique<AppLoader_NCCH>(std::move(file), filepath); 117 return std::make_unique<AppLoader_NCCH>(std::move(file), filepath);
109 118
110 default: 119 default:
111 return std::unique_ptr<AppLoader>(); 120 return nullptr;
112 } 121 }
113} 122}
114 123
115ResultStatus LoadFile(const std::string& filename) { 124std::unique_ptr<AppLoader> GetLoader(const std::string& filename) {
116 FileUtil::IOFile file(filename, "rb"); 125 FileUtil::IOFile file(filename, "rb");
117 if (!file.IsOpen()) { 126 if (!file.IsOpen()) {
118 LOG_ERROR(Loader, "Failed to load file %s", filename.c_str()); 127 LOG_ERROR(Loader, "Failed to load file %s", filename.c_str());
119 return ResultStatus::Error; 128 return nullptr;
120 } 129 }
121 130
122 std::string filename_filename, filename_extension; 131 std::string filename_filename, filename_extension;
@@ -133,44 +142,7 @@ ResultStatus LoadFile(const std::string& filename) {
133 142
134 LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type)); 143 LOG_INFO(Loader, "Loading file %s as %s...", filename.c_str(), GetFileTypeString(type));
135 144
136 std::unique_ptr<AppLoader> app_loader = GetLoader(std::move(file), type, filename_filename, filename); 145 return GetFileLoader(std::move(file), type, filename_filename, filename);
137
138 switch (type) {
139
140 // 3DSX file format...
141 // or NCCH/NCSD container formats...
142 case FileType::THREEDSX:
143 case FileType::CXI:
144 case FileType::CCI:
145 {
146 // Load application and RomFS
147 ResultStatus result = app_loader->Load();
148 if (ResultStatus::Success == result) {
149 Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*app_loader), Service::FS::ArchiveIdCode::RomFS);
150 return ResultStatus::Success;
151 }
152 return result;
153 }
154
155 // Standard ELF file format...
156 case FileType::ELF:
157 return app_loader->Load();
158
159 // CIA file format...
160 case FileType::CIA:
161 return ResultStatus::ErrorNotImplemented;
162
163 // Error occurred durring IdentifyFile...
164 case FileType::Error:
165
166 // IdentifyFile could know identify file type...
167 case FileType::Unknown:
168 {
169 LOG_CRITICAL(Loader, "File %s is of unknown type.", filename.c_str());
170 return ResultStatus::ErrorInvalidFormat;
171 }
172 }
173 return ResultStatus::Error;
174} 146}
175 147
176} // namespace Loader 148} // namespace Loader
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 9d3e9ed3b..77d87afe1 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -10,10 +10,8 @@
10#include <string> 10#include <string>
11#include <vector> 11#include <vector>
12 12
13#include "common/common_funcs.h"
14#include "common/common_types.h" 13#include "common/common_types.h"
15#include "common/file_util.h" 14#include "common/file_util.h"
16#include "common/swap.h"
17 15
18namespace Kernel { 16namespace Kernel {
19struct AddressMapping; 17struct AddressMapping;
@@ -80,51 +78,6 @@ constexpr u32 MakeMagic(char a, char b, char c, char d) {
80 return a | b << 8 | c << 16 | d << 24; 78 return a | b << 8 | c << 16 | d << 24;
81} 79}
82 80
83/// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH
84struct SMDH {
85 u32_le magic;
86 u16_le version;
87 INSERT_PADDING_BYTES(2);
88
89 struct Title {
90 std::array<u16, 0x40> short_title;
91 std::array<u16, 0x80> long_title;
92 std::array<u16, 0x40> publisher;
93 };
94 std::array<Title, 16> titles;
95
96 std::array<u8, 16> ratings;
97 u32_le region_lockout;
98 u32_le match_maker_id;
99 u64_le match_maker_bit_id;
100 u32_le flags;
101 u16_le eula_version;
102 INSERT_PADDING_BYTES(2);
103 float_le banner_animation_frame;
104 u32_le cec_id;
105 INSERT_PADDING_BYTES(8);
106
107 std::array<u8, 0x480> small_icon;
108 std::array<u8, 0x1200> large_icon;
109
110 /// indicates the language used for each title entry
111 enum class TitleLanguage {
112 Japanese = 0,
113 English = 1,
114 French = 2,
115 German = 3,
116 Italian = 4,
117 Spanish = 5,
118 SimplifiedChinese = 6,
119 Korean= 7,
120 Dutch = 8,
121 Portuguese = 9,
122 Russian = 10,
123 TraditionalChinese = 11
124 };
125};
126static_assert(sizeof(SMDH) == 0x36C0, "SMDH structure size is wrong");
127
128/// Interface for loading an application 81/// Interface for loading an application
129class AppLoader : NonCopyable { 82class AppLoader : NonCopyable {
130public: 83public:
@@ -132,6 +85,12 @@ public:
132 virtual ~AppLoader() { } 85 virtual ~AppLoader() { }
133 86
134 /** 87 /**
88 * Returns the type of this file
89 * @return FileType corresponding to the loaded file
90 */
91 virtual FileType GetFileType() = 0;
92
93 /**
135 * Load the application 94 * Load the application
136 * @return ResultStatus result of function 95 * @return ResultStatus result of function
137 */ 96 */
@@ -197,20 +156,10 @@ protected:
197extern const std::initializer_list<Kernel::AddressMapping> default_address_mappings; 156extern const std::initializer_list<Kernel::AddressMapping> default_address_mappings;
198 157
199/** 158/**
200 * Get a loader for a file with a specific type 159 * Identifies a bootable file and return a suitable loader
201 * @param file The file to load
202 * @param type The type of the file
203 * @param filename the file name (without path)
204 * @param filepath the file full path (with name)
205 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
206 */
207std::unique_ptr<AppLoader> GetLoader(FileUtil::IOFile&& file, FileType type, const std::string& filename, const std::string& filepath);
208
209/**
210 * Identifies and loads a bootable file
211 * @param filename String filename of bootable file 160 * @param filename String filename of bootable file
212 * @return ResultStatus result of function 161 * @return best loader for this file
213 */ 162 */
214ResultStatus LoadFile(const std::string& filename); 163std::unique_ptr<AppLoader> GetLoader(const std::string& filename);
215 164
216} // namespace 165} // namespace
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 7391bdb26..fca091ff9 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -10,8 +10,10 @@
10#include "common/string_util.h" 10#include "common/string_util.h"
11#include "common/swap.h" 11#include "common/swap.h"
12 12
13#include "core/file_sys/archive_romfs.h"
13#include "core/hle/kernel/process.h" 14#include "core/hle/kernel/process.h"
14#include "core/hle/kernel/resource_limit.h" 15#include "core/hle/kernel/resource_limit.h"
16#include "core/hle/service/fs/archive.h"
15#include "core/loader/ncch.h" 17#include "core/loader/ncch.h"
16#include "core/memory.h" 18#include "core/memory.h"
17 19
@@ -303,7 +305,12 @@ ResultStatus AppLoader_NCCH::Load() {
303 305
304 is_loaded = true; // Set state to loaded 306 is_loaded = true; // Set state to loaded
305 307
306 return LoadExec(); // Load the executable into memory for booting 308 result = LoadExec(); // Load the executable into memory for booting
309 if (ResultStatus::Success != result)
310 return result;
311
312 Service::FS::RegisterArchiveType(std::make_unique<FileSys::ArchiveFactory_RomFS>(*this), Service::FS::ArchiveIdCode::RomFS);
313 return ResultStatus::Success;
307} 314}
308 315
309ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) { 316ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) {
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h
index fd852c3de..75609ee57 100644
--- a/src/core/loader/ncch.h
+++ b/src/core/loader/ncch.h
@@ -174,6 +174,14 @@ public:
174 static FileType IdentifyType(FileUtil::IOFile& file); 174 static FileType IdentifyType(FileUtil::IOFile& file);
175 175
176 /** 176 /**
177 * Returns the type of this file
178 * @return FileType corresponding to the loaded file
179 */
180 FileType GetFileType() override {
181 return IdentifyType(file);
182 }
183
184 /**
177 * Load the application 185 * Load the application
178 * @return ResultStatus result of function 186 * @return ResultStatus result of function
179 */ 187 */
diff --git a/src/core/loader/smdh.cpp b/src/core/loader/smdh.cpp
new file mode 100644
index 000000000..2d014054a
--- /dev/null
+++ b/src/core/loader/smdh.cpp
@@ -0,0 +1,54 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstring>
6#include <vector>
7
8#include "common/common_types.h"
9
10#include "core/loader/loader.h"
11#include "core/loader/smdh.h"
12
13#include "video_core/utils.h"
14
15namespace Loader {
16
17bool IsValidSMDH(const std::vector<u8>& smdh_data) {
18 if (smdh_data.size() < sizeof(Loader::SMDH))
19 return false;
20
21 u32 magic;
22 memcpy(&magic, smdh_data.data(), sizeof(u32));
23
24 return Loader::MakeMagic('S', 'M', 'D', 'H') == magic;
25}
26
27std::vector<u16> SMDH::GetIcon(bool large) const {
28 u32 size;
29 const u8* icon_data;
30
31 if (large) {
32 size = 48;
33 icon_data = large_icon.data();
34 } else {
35 size = 24;
36 icon_data = small_icon.data();
37 }
38
39 std::vector<u16> icon(size * size);
40 for (u32 x = 0; x < size; ++x) {
41 for (u32 y = 0; y < size; ++y) {
42 u32 coarse_y = y & ~7;
43 const u8* pixel = icon_data + VideoCore::GetMortonOffset(x, y, 2) + coarse_y * size * 2;
44 icon[x + size * y] = (pixel[1] << 8) + pixel[0];
45 }
46 }
47 return icon;
48}
49
50std::array<u16, 0x40> SMDH::GetShortTitle(Loader::SMDH::TitleLanguage language) const {
51 return titles[static_cast<int>(language)].short_title;
52}
53
54} // namespace
diff --git a/src/core/loader/smdh.h b/src/core/loader/smdh.h
new file mode 100644
index 000000000..2011abda2
--- /dev/null
+++ b/src/core/loader/smdh.h
@@ -0,0 +1,82 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <vector>
9
10#include "common/common_funcs.h"
11#include "common/common_types.h"
12#include "common/swap.h"
13
14namespace Loader {
15
16/**
17 * Tests if data is a valid SMDH by its length and magic number.
18 * @param smdh_data data buffer to test
19 * @return bool test result
20 */
21bool IsValidSMDH(const std::vector<u8>& smdh_data);
22
23/// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH
24struct SMDH {
25 u32_le magic;
26 u16_le version;
27 INSERT_PADDING_BYTES(2);
28
29 struct Title {
30 std::array<u16, 0x40> short_title;
31 std::array<u16, 0x80> long_title;
32 std::array<u16, 0x40> publisher;
33 };
34 std::array<Title, 16> titles;
35
36 std::array<u8, 16> ratings;
37 u32_le region_lockout;
38 u32_le match_maker_id;
39 u64_le match_maker_bit_id;
40 u32_le flags;
41 u16_le eula_version;
42 INSERT_PADDING_BYTES(2);
43 float_le banner_animation_frame;
44 u32_le cec_id;
45 INSERT_PADDING_BYTES(8);
46
47 std::array<u8, 0x480> small_icon;
48 std::array<u8, 0x1200> large_icon;
49
50 /// indicates the language used for each title entry
51 enum class TitleLanguage {
52 Japanese = 0,
53 English = 1,
54 French = 2,
55 German = 3,
56 Italian = 4,
57 Spanish = 5,
58 SimplifiedChinese = 6,
59 Korean= 7,
60 Dutch = 8,
61 Portuguese = 9,
62 Russian = 10,
63 TraditionalChinese = 11
64 };
65
66 /**
67 * Gets game icon from SMDH
68 * @param large If true, returns large icon (48x48), otherwise returns small icon (24x24)
69 * @return vector of RGB565 data
70 */
71 std::vector<u16> GetIcon(bool large) const;
72
73 /**
74 * Gets the short game title from SMDH
75 * @param language title language
76 * @return UTF-16 array of the short title
77 */
78 std::array<u16, 0x40> GetShortTitle(Loader::SMDH::TitleLanguage language) const;
79};
80static_assert(sizeof(SMDH) == 0x36C0, "SMDH structure size is wrong");
81
82} // namespace