summaryrefslogtreecommitdiff
path: root/src/core/loader/3dsx.cpp
diff options
context:
space:
mode:
authorGravatar Cruel2015-09-21 01:30:06 -0400
committerGravatar Cruel2015-09-21 13:03:18 -0400
commitd60a9be5c6332da6e6ff82125e53b1365a389ae0 (patch)
tree2b2ec9ae8db37137e5fd9c2a6c93f7d7c38984b7 /src/core/loader/3dsx.cpp
parentMerge pull request #1097 from yuriks/cfg-blocks (diff)
downloadyuzu-d60a9be5c6332da6e6ff82125e53b1365a389ae0.tar.gz
yuzu-d60a9be5c6332da6e6ff82125e53b1365a389ae0.tar.xz
yuzu-d60a9be5c6332da6e6ff82125e53b1365a389ae0.zip
Implement 3dsx RomFS
Diffstat (limited to 'src/core/loader/3dsx.cpp')
-rw-r--r--src/core/loader/3dsx.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index 530837d08..111b6a409 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -62,6 +62,10 @@ struct THREEDSX_Header
62 // Sizes of the code, rodata and data segments + 62 // Sizes of the code, rodata and data segments +
63 // size of the BSS section (uninitialized latter half of the data segment) 63 // size of the BSS section (uninitialized latter half of the data segment)
64 u32 code_seg_size, rodata_seg_size, data_seg_size, bss_size; 64 u32 code_seg_size, rodata_seg_size, data_seg_size, bss_size;
65 // offset and size of smdh
66 u32 smdh_offset, smdh_size;
67 // offset to filesystem
68 u32 fs_offset;
65}; 69};
66 70
67// Relocation header: all fields (even extra unknown fields) are guaranteed to be relocation counts. 71// Relocation header: all fields (even extra unknown fields) are guaranteed to be relocation counts.
@@ -267,4 +271,40 @@ ResultStatus AppLoader_THREEDSX::Load() {
267 return ResultStatus::Success; 271 return ResultStatus::Success;
268} 272}
269 273
274ResultStatus AppLoader_THREEDSX::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) {
275 if (!file.IsOpen())
276 return ResultStatus::Error;
277
278 // Reset read pointer in case this file has been read before.
279 file.Seek(0, SEEK_SET);
280
281 THREEDSX_Header hdr;
282 if (file.ReadBytes(&hdr, sizeof(THREEDSX_Header)) != sizeof(THREEDSX_Header))
283 return ResultStatus::Error;
284
285 if (hdr.header_size != sizeof(THREEDSX_Header))
286 return ResultStatus::Error;
287
288 // Check if the 3DSX has a RomFS...
289 if (hdr.fs_offset != 0) {
290 u32 romfs_offset = hdr.fs_offset;
291 u32 romfs_size = file.GetSize() - hdr.fs_offset;
292
293 LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
294 LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
295
296 // We reopen the file, to allow its position to be independent from file's
297 romfs_file = std::make_shared<FileUtil::IOFile>(filepath, "rb");
298 if (!romfs_file->IsOpen())
299 return ResultStatus::Error;
300
301 offset = romfs_offset;
302 size = romfs_size;
303
304 return ResultStatus::Success;
305 }
306 LOG_DEBUG(Loader, "3DSX has no RomFS");
307 return ResultStatus::ErrorNotUsed;
308}
309
270} // namespace Loader 310} // namespace Loader