mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-19 20:19:13 +12:00
[FS] Cleanup, stub SDMC, start implementing SaveData
This commit is contained in:
parent
8cf55162d0
commit
b6a1da21a9
13 changed files with 135 additions and 15 deletions
61
src/core/fs/archive_ncch.cpp
Normal file
61
src/core/fs/archive_ncch.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "fs/archive_ncch.hpp"
|
||||
#include <memory>
|
||||
|
||||
bool SelfNCCHArchive::openFile(const FSPath& path) {
|
||||
if (path.type != PathType::Binary) {
|
||||
printf("Invalid SelfNCCH path type");
|
||||
return false;
|
||||
}
|
||||
|
||||
// We currently only know how to read from an NCCH's RomFS
|
||||
if (mem.read32(path.pointer) != 0) {
|
||||
Helpers::panic("Read from NCCH's non-RomFS section!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ArchiveBase* SelfNCCHArchive::openArchive(const FSPath& path) {
|
||||
if (path.type != PathType::Empty) {
|
||||
printf("Invalid path type for SelfNCCH archive: %d\n", path.type);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) {
|
||||
auto cxi = mem.getCXI();
|
||||
if (cxi == nullptr) {
|
||||
Helpers::panic("Tried to read file from non-existent CXI");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!cxi->hasRomFS()) {
|
||||
Helpers::panic("Tried to read from CXI without RomFS");
|
||||
}
|
||||
|
||||
const u32 romFSSize = cxi->romFS.size;
|
||||
const u32 romFSOffset = cxi->romFS.offset;
|
||||
if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) {
|
||||
Helpers::panic("Tried to read from SelfNCCH with too big of an offset");
|
||||
}
|
||||
|
||||
IOFile& ioFile = mem.CXIFile;
|
||||
if (!ioFile.seek(cxi->fileOffset + romFSOffset + offset + 0x1000)) {
|
||||
Helpers::panic("Failed to seek while reading from RomFS");
|
||||
}
|
||||
|
||||
std::unique_ptr<u8[]> data(new u8[size]);
|
||||
auto [success, bytesRead] = ioFile.readBytes(&data[0], size);
|
||||
|
||||
if (!success) {
|
||||
Helpers::panic("Failed to read from RomFS");
|
||||
}
|
||||
|
||||
for (u64 i = 0; i < bytesRead; i++) {
|
||||
mem.write8(dataPointer + i, data[i]);
|
||||
}
|
||||
|
||||
return bytesRead;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue