summaryrefslogtreecommitdiff
path: root/src/core/loader
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp6
-rw-r--r--src/core/loader/loader.cpp27
-rw-r--r--src/core/loader/loader.h9
-rw-r--r--src/core/loader/nso.cpp2
-rw-r--r--src/core/loader/nsp.cpp19
-rw-r--r--src/core/loader/nsp.h13
-rw-r--r--src/core/loader/xci.cpp16
-rw-r--r--src/core/loader/xci.h13
8 files changed, 66 insertions, 39 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 394a1bf26..2002dc4f2 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -114,7 +114,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
114 } 114 }
115 115
116 if (override_update) { 116 if (override_update) {
117 const FileSys::PatchManager patch_manager(metadata.GetTitleID()); 117 const FileSys::PatchManager patch_manager(
118 metadata.GetTitleID(), system.GetFileSystemController(), system.GetContentProvider());
118 dir = patch_manager.PatchExeFS(dir); 119 dir = patch_manager.PatchExeFS(dir);
119 } 120 }
120 121
@@ -160,7 +161,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
160 modules.clear(); 161 modules.clear();
161 const VAddr base_address{process.PageTable().GetCodeRegionStart()}; 162 const VAddr base_address{process.PageTable().GetCodeRegionStart()};
162 VAddr next_load_addr{base_address}; 163 VAddr next_load_addr{base_address};
163 const FileSys::PatchManager pm{metadata.GetTitleID()}; 164 const FileSys::PatchManager pm{metadata.GetTitleID(), system.GetFileSystemController(),
165 system.GetContentProvider()};
164 for (const auto& module : static_modules) { 166 for (const auto& module : static_modules) {
165 const FileSys::VirtualFile module_file{dir->GetFile(module)}; 167 const FileSys::VirtualFile module_file{dir->GetFile(module)};
166 if (!module_file) { 168 if (!module_file) {
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 9bc3a8840..deffe7379 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -10,6 +10,7 @@
10#include "common/file_util.h" 10#include "common/file_util.h"
11#include "common/logging/log.h" 11#include "common/logging/log.h"
12#include "common/string_util.h" 12#include "common/string_util.h"
13#include "core/core.h"
13#include "core/hle/kernel/process.h" 14#include "core/hle/kernel/process.h"
14#include "core/loader/deconstructed_rom_directory.h" 15#include "core/loader/deconstructed_rom_directory.h"
15#include "core/loader/elf.h" 16#include "core/loader/elf.h"
@@ -194,15 +195,14 @@ AppLoader::~AppLoader() = default;
194 195
195/** 196/**
196 * Get a loader for a file with a specific type 197 * Get a loader for a file with a specific type
197 * @param file The file to load 198 * @param system The system context to use.
198 * @param type The type of the file 199 * @param file The file to retrieve the loader for
199 * @param file the file to retrieve the loader for 200 * @param type The file type
200 * @param type the file type
201 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type 201 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
202 */ 202 */
203static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileType type) { 203static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::VirtualFile file,
204 FileType type) {
204 switch (type) { 205 switch (type) {
205
206 // Standard ELF file format. 206 // Standard ELF file format.
207 case FileType::ELF: 207 case FileType::ELF:
208 return std::make_unique<AppLoader_ELF>(std::move(file)); 208 return std::make_unique<AppLoader_ELF>(std::move(file));
@@ -221,7 +221,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
221 221
222 // NX XCI (nX Card Image) file format. 222 // NX XCI (nX Card Image) file format.
223 case FileType::XCI: 223 case FileType::XCI:
224 return std::make_unique<AppLoader_XCI>(std::move(file)); 224 return std::make_unique<AppLoader_XCI>(std::move(file), system.GetFileSystemController(),
225 system.GetContentProvider());
225 226
226 // NX NAX (NintendoAesXts) file format. 227 // NX NAX (NintendoAesXts) file format.
227 case FileType::NAX: 228 case FileType::NAX:
@@ -229,7 +230,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
229 230
230 // NX NSP (Nintendo Submission Package) file format 231 // NX NSP (Nintendo Submission Package) file format
231 case FileType::NSP: 232 case FileType::NSP:
232 return std::make_unique<AppLoader_NSP>(std::move(file)); 233 return std::make_unique<AppLoader_NSP>(std::move(file), system.GetFileSystemController(),
234 system.GetContentProvider());
233 235
234 // NX KIP (Kernel Internal Process) file format 236 // NX KIP (Kernel Internal Process) file format
235 case FileType::KIP: 237 case FileType::KIP:
@@ -244,20 +246,21 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
244 } 246 }
245} 247}
246 248
247std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { 249std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file) {
248 FileType type = IdentifyFile(file); 250 FileType type = IdentifyFile(file);
249 FileType filename_type = GuessFromFilename(file->GetName()); 251 const FileType filename_type = GuessFromFilename(file->GetName());
250 252
251 // Special case: 00 is either a NCA or NAX. 253 // Special case: 00 is either a NCA or NAX.
252 if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) { 254 if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) {
253 LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); 255 LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName());
254 if (FileType::Unknown == type) 256 if (FileType::Unknown == type) {
255 type = filename_type; 257 type = filename_type;
258 }
256 } 259 }
257 260
258 LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); 261 LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type));
259 262
260 return GetFileLoader(std::move(file), type); 263 return GetFileLoader(system, std::move(file), type);
261} 264}
262 265
263} // namespace Loader 266} // namespace Loader
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index ac60b097a..8dc2d7615 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -290,9 +290,12 @@ protected:
290 290
291/** 291/**
292 * Identifies a bootable file and return a suitable loader 292 * Identifies a bootable file and return a suitable loader
293 * @param file The bootable file 293 *
294 * @return the best loader for this file 294 * @param system The system context.
295 * @param file The bootable file.
296 *
297 * @return the best loader for this file.
295 */ 298 */
296std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file); 299std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file);
297 300
298} // namespace Loader 301} // namespace Loader
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 497f438a1..aa85c1a29 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -149,7 +149,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S
149 // Apply cheats if they exist and the program has a valid title ID 149 // Apply cheats if they exist and the program has a valid title ID
150 if (pm) { 150 if (pm) {
151 system.SetCurrentProcessBuildID(nso_header.build_id); 151 system.SetCurrentProcessBuildID(nso_header.build_id);
152 const auto cheats = pm->CreateCheatList(system, nso_header.build_id); 152 const auto cheats = pm->CreateCheatList(nso_header.build_id);
153 if (!cheats.empty()) { 153 if (!cheats.empty()) {
154 system.RegisterCheatList(cheats, nso_header.build_id, load_base, image_size); 154 system.RegisterCheatList(cheats, nso_header.build_id, load_base, image_size);
155 } 155 }
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp
index 15e528fa8..e821937fd 100644
--- a/src/core/loader/nsp.cpp
+++ b/src/core/loader/nsp.cpp
@@ -21,26 +21,33 @@
21 21
22namespace Loader { 22namespace Loader {
23 23
24AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file) 24AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file,
25 const Service::FileSystem::FileSystemController& fsc,
26 const FileSys::ContentProvider& content_provider)
25 : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file)), 27 : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file)),
26 title_id(nsp->GetProgramTitleID()) { 28 title_id(nsp->GetProgramTitleID()) {
27 29
28 if (nsp->GetStatus() != ResultStatus::Success) 30 if (nsp->GetStatus() != ResultStatus::Success) {
29 return; 31 return;
32 }
30 33
31 if (nsp->IsExtractedType()) { 34 if (nsp->IsExtractedType()) {
32 secondary_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(nsp->GetExeFS()); 35 secondary_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(nsp->GetExeFS());
33 } else { 36 } else {
34 const auto control_nca = 37 const auto control_nca =
35 nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Control); 38 nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Control);
36 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) 39 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) {
37 return; 40 return;
41 }
38 42
39 std::tie(nacp_file, icon_file) = 43 std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] {
40 FileSys::PatchManager(nsp->GetProgramTitleID()).ParseControlNCA(*control_nca); 44 const FileSys::PatchManager pm{nsp->GetProgramTitleID(), fsc, content_provider};
45 return pm.ParseControlNCA(*control_nca);
46 }();
41 47
42 if (title_id == 0) 48 if (title_id == 0) {
43 return; 49 return;
50 }
44 51
45 secondary_loader = std::make_unique<AppLoader_NCA>( 52 secondary_loader = std::make_unique<AppLoader_NCA>(
46 nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program)); 53 nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program));
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h
index b27deb686..36e8e3533 100644
--- a/src/core/loader/nsp.h
+++ b/src/core/loader/nsp.h
@@ -9,15 +9,16 @@
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs.h"
10#include "core/loader/loader.h" 10#include "core/loader/loader.h"
11 11
12namespace Core {
13class System;
14}
15
16namespace FileSys { 12namespace FileSys {
13class ContentProvider;
17class NACP; 14class NACP;
18class NSP; 15class NSP;
19} // namespace FileSys 16} // namespace FileSys
20 17
18namespace Service::FileSystem {
19class FileSystemController;
20}
21
21namespace Loader { 22namespace Loader {
22 23
23class AppLoader_NCA; 24class AppLoader_NCA;
@@ -25,7 +26,9 @@ class AppLoader_NCA;
25/// Loads an XCI file 26/// Loads an XCI file
26class AppLoader_NSP final : public AppLoader { 27class AppLoader_NSP final : public AppLoader {
27public: 28public:
28 explicit AppLoader_NSP(FileSys::VirtualFile file); 29 explicit AppLoader_NSP(FileSys::VirtualFile file,
30 const Service::FileSystem::FileSystemController& fsc,
31 const FileSys::ContentProvider& content_provider);
29 ~AppLoader_NSP() override; 32 ~AppLoader_NSP() override;
30 33
31 /** 34 /**
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp
index 25e83af0f..536e721fc 100644
--- a/src/core/loader/xci.cpp
+++ b/src/core/loader/xci.cpp
@@ -20,18 +20,24 @@
20 20
21namespace Loader { 21namespace Loader {
22 22
23AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) 23AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file,
24 const Service::FileSystem::FileSystemController& fsc,
25 const FileSys::ContentProvider& content_provider)
24 : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)), 26 : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)),
25 nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { 27 nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) {
26 if (xci->GetStatus() != ResultStatus::Success) 28 if (xci->GetStatus() != ResultStatus::Success) {
27 return; 29 return;
30 }
28 31
29 const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control); 32 const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control);
30 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) 33 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) {
31 return; 34 return;
35 }
32 36
33 std::tie(nacp_file, icon_file) = 37 std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] {
34 FileSys::PatchManager(xci->GetProgramTitleID()).ParseControlNCA(*control_nca); 38 const FileSys::PatchManager pm{xci->GetProgramTitleID(), fsc, content_provider};
39 return pm.ParseControlNCA(*control_nca);
40 }();
35} 41}
36 42
37AppLoader_XCI::~AppLoader_XCI() = default; 43AppLoader_XCI::~AppLoader_XCI() = default;
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h
index 04aea286f..6dc1f9243 100644
--- a/src/core/loader/xci.h
+++ b/src/core/loader/xci.h
@@ -9,15 +9,16 @@
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs.h"
10#include "core/loader/loader.h" 10#include "core/loader/loader.h"
11 11
12namespace Core {
13class System;
14}
15
16namespace FileSys { 12namespace FileSys {
13class ContentProvider;
17class NACP; 14class NACP;
18class XCI; 15class XCI;
19} // namespace FileSys 16} // namespace FileSys
20 17
18namespace Service::FileSystem {
19class FileSystemController;
20}
21
21namespace Loader { 22namespace Loader {
22 23
23class AppLoader_NCA; 24class AppLoader_NCA;
@@ -25,7 +26,9 @@ class AppLoader_NCA;
25/// Loads an XCI file 26/// Loads an XCI file
26class AppLoader_XCI final : public AppLoader { 27class AppLoader_XCI final : public AppLoader {
27public: 28public:
28 explicit AppLoader_XCI(FileSys::VirtualFile file); 29 explicit AppLoader_XCI(FileSys::VirtualFile file,
30 const Service::FileSystem::FileSystemController& fsc,
31 const FileSys::ContentProvider& content_provider);
29 ~AppLoader_XCI() override; 32 ~AppLoader_XCI() override;
30 33
31 /** 34 /**