Merge branch 'master' into sd-card

This commit is contained in:
wheremyfoodat
2023-09-05 17:02:40 +03:00
9 changed files with 3126 additions and 3099 deletions
+1
View File
@@ -9,6 +9,7 @@ public:
u64 getFreeBytes() override { Helpers::panic("ExtSaveData::GetFreeBytes unimplemented"); return 0; } u64 getFreeBytes() override { Helpers::panic("ExtSaveData::GetFreeBytes unimplemented"); return 0; }
std::string name() override { return "ExtSaveData::" + backingFolder; } std::string name() override { return "ExtSaveData::" + backingFolder; }
HorizonResult createDirectory(const FSPath& path) override;
HorizonResult createFile(const FSPath& path, u64 size) override; HorizonResult createFile(const FSPath& path, u64 size) override;
HorizonResult deleteFile(const FSPath& path) override; HorizonResult deleteFile(const FSPath& path) override;
+1 -2
View File
@@ -18,8 +18,7 @@ public:
// Returns whether the cart has a RomFS // Returns whether the cart has a RomFS
bool hasRomFS() { bool hasRomFS() {
auto cxi = mem.getCXI(); auto cxi = mem.getCXI();
auto hb3dsx = mem.get3DSX(); return (cxi != nullptr && cxi->hasRomFS());
return (cxi != nullptr && cxi->hasRomFS()) || (hb3dsx != nullptr && hb3dsx->hasRomFs());
} }
// Returns whether the cart has an ExeFS (All executable carts should have an ExeFS. This is just here to be safe) // Returns whether the cart has an ExeFS (All executable carts should have an ExeFS. This is just here to be safe)
+3088 -3085
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -137,7 +137,7 @@ namespace Helpers {
return getBits<offset, bits, ValueT, ValueT>(value); return getBits<offset, bits, ValueT, ValueT>(value);
} }
#if defined(HELPERS_APPLE_CLANG) || defined(__ANDROID__) #if defined(HELPERS_APPLE_CLANG) || defined(__ANDROID__) || !defined(__cpp_lib_bit_cast)
template <class To, class From> template <class To, class From>
constexpr To bit_cast(const From& from) noexcept { constexpr To bit_cast(const From& from) noexcept {
return *reinterpret_cast<const To*>(&from); return *reinterpret_cast<const To*>(&from);
+1
View File
@@ -84,6 +84,7 @@ class ServiceManager {
void receiveNotification(u32 messagePointer); void receiveNotification(u32 messagePointer);
void registerClient(u32 messagePointer); void registerClient(u32 messagePointer);
void subscribe(u32 messagePointer); void subscribe(u32 messagePointer);
void unsubscribe(u32 messagePointer);
public: public:
ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel, const EmulatorConfig& config); ServiceManager(std::span<u32, 16> regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel, const EmulatorConfig& config);
+21
View File
@@ -87,6 +87,27 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
return FileError; return FileError;
} }
HorizonResult ExtSaveDataArchive::createDirectory(const FSPath& path) {
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path)) {
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
}
fs::path p = IOFile::getAppData() / backingFolder;
p += fs::path(path.utf16_string).make_preferred();
if (fs::is_directory(p)) return Result::FS::AlreadyExists;
if (fs::is_regular_file(p)) {
Helpers::panic("File path passed to ExtSaveData::CreateDirectory");
}
bool success = fs::create_directory(p);
return success ? Result::Success : Result::FS::UnexpectedFileOrDir;
} else {
Helpers::panic("Unimplemented ExtSaveData::CreateDirectory");
}
}
std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) { std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) {
// TODO: Remove punning here // TODO: Remove punning here
const u32 mediaType = *(u32*)&path.binary[0]; const u32 mediaType = *(u32*)&path.binary[0];
+3 -8
View File
@@ -131,16 +131,12 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
} }
auto cxi = mem.getCXI(); auto cxi = mem.getCXI();
auto hb3dsx = mem.get3DSX();
// If isCXI is true then we've loaded a CXI/3DS file, else it's 3DSX
bool isCXI = cxi != nullptr;
// Seek to file offset depending on if we're reading from RomFS, ExeFS, etc // Seek to file offset depending on if we're reading from RomFS, ExeFS, etc
switch (type) { switch (type) {
case PathType::RomFS: { case PathType::RomFS: {
const u64 romFSSize = isCXI ? cxi->romFS.size : hb3dsx->romFSSize; const u64 romFSSize = cxi->romFS.size;
const u64 romFSOffset = isCXI ? cxi->romFS.offset : hb3dsx->romFSOffset; const u64 romFSOffset = cxi->romFS.offset;
if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) { if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) {
Helpers::panic("Tried to read from NCCH with too big of an offset"); Helpers::panic("Tried to read from NCCH with too big of an offset");
} }
@@ -154,8 +150,7 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
} }
std::unique_ptr<u8[]> data(new u8[size]); std::unique_ptr<u8[]> data(new u8[size]);
auto [success, bytesRead] = auto [success, bytesRead] = cxi->readFromFile(mem.CXIFile, cxi->romFS, &data[0], offset, size);
isCXI ? cxi->readFromFile(mem.CXIFile, cxi->romFS, &data[0], offset, size) : hb3dsx->readRomFSBytes(&data[0], offset, size);
if (!success) { if (!success) {
Helpers::panic("Failed to read from NCCH archive"); Helpers::panic("Failed to read from NCCH archive");
+1 -3
View File
@@ -71,7 +71,7 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
bool success = false; bool success = false;
std::size_t bytesRead = 0; std::size_t bytesRead = 0;
std::vector<u8> data; std::unique_ptr<u8[]> data(new u8[size]);
if (auto cxi = mem.getCXI(); cxi != nullptr) { if (auto cxi = mem.getCXI(); cxi != nullptr) {
IOFile& ioFile = mem.CXIFile; IOFile& ioFile = mem.CXIFile;
@@ -122,7 +122,6 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
default: Helpers::panic("Unimplemented file path type for SelfNCCH archive"); default: Helpers::panic("Unimplemented file path type for SelfNCCH archive");
} }
data.resize(size);
std::tie(success, bytesRead) = cxi->readFromFile(ioFile, fsInfo, &data[0], offset, size); std::tie(success, bytesRead) = cxi->readFromFile(ioFile, fsInfo, &data[0], offset, size);
} }
@@ -139,7 +138,6 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
default: Helpers::panic("Unimplemented file path type for 3DSX SelfNCCH archive"); default: Helpers::panic("Unimplemented file path type for 3DSX SelfNCCH archive");
} }
data.resize(size);
std::tie(success, bytesRead) = hb3dsx->readRomFSBytes(&data[0], offset, size); std::tie(success, bytesRead) = hb3dsx->readRomFSBytes(&data[0], offset, size);
} }
+9
View File
@@ -79,6 +79,7 @@ void ServiceManager::handleSyncRequest(u32 messagePointer) {
case Commands::RegisterClient: registerClient(messagePointer); break; case Commands::RegisterClient: registerClient(messagePointer); break;
case Commands::GetServiceHandle: getServiceHandle(messagePointer); break; case Commands::GetServiceHandle: getServiceHandle(messagePointer); break;
case Commands::Subscribe: subscribe(messagePointer); break; case Commands::Subscribe: subscribe(messagePointer); break;
case Commands::Unsubscribe: unsubscribe(messagePointer); break;
default: Helpers::panic("Unknown \"srv:\" command: %08X", header); default: Helpers::panic("Unknown \"srv:\" command: %08X", header);
} }
} }
@@ -178,6 +179,14 @@ void ServiceManager::subscribe(u32 messagePointer) {
mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 4, Result::Success);
} }
void ServiceManager::unsubscribe(u32 messagePointer) {
u32 id = mem.read32(messagePointer + 4);
log("srv::Unsubscribe (id = %d) (stubbed)\n", id);
mem.write32(messagePointer, IPC::responseHeader(0xA, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}
void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) { void ServiceManager::sendCommandToService(u32 messagePointer, Handle handle) {
switch (handle) { switch (handle) {
// Breaking alphabetical order a bit to place the ones I think are most common at the top // Breaking alphabetical order a bit to place the ones I think are most common at the top