mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 07:05:40 +12:00
Add IOFile and headers for NCSD/NCCH
This commit is contained in:
parent
7ba5c5a1bc
commit
9a040e1cde
4 changed files with 116 additions and 1 deletions
|
@ -66,7 +66,7 @@ set(HEADER_FILES include/emulator.hpp include/helpers.hpp include/opengl.hpp inc
|
||||||
include/services/gsp_gpu.hpp include/services/gsp_lcd.hpp include/arm_defs.hpp
|
include/services/gsp_gpu.hpp include/services/gsp_lcd.hpp include/arm_defs.hpp
|
||||||
include/PICA/gpu.hpp include/PICA/regs.hpp include/services/ndm.hpp
|
include/PICA/gpu.hpp include/PICA/regs.hpp include/services/ndm.hpp
|
||||||
include/PICA/shader.hpp include/PICA/shader_unit.hpp include/PICA/float_types.hpp
|
include/PICA/shader.hpp include/PICA/shader_unit.hpp include/PICA/float_types.hpp
|
||||||
include/logger.hpp
|
include/logger.hpp include/loader/ncch.hpp include/loader/ncsd.hpp include/io_file.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp
|
set(THIRD_PARTY_SOURCE_FILES third_party/imgui/imgui.cpp
|
||||||
|
|
82
include/io_file.hpp
Normal file
82
include/io_file.hpp
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
// 64 bit offsets for MSVC
|
||||||
|
#define fseeko _fseeki64
|
||||||
|
#define ftello _ftelli64
|
||||||
|
#define fileno _fileno
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _CRT_SECURE_NO_WARNINGS
|
||||||
|
#undef _CRT_SECURE_NO_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class IOFile {
|
||||||
|
FILE* handle = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool isOpen() {
|
||||||
|
return handle != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool open(const std::filesystem::path& path, const char* permissions = "rb") {
|
||||||
|
const auto str = path.string(); // For some reason converting paths directly with c_str() doesn't work
|
||||||
|
return open(str.c_str(), permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool open(const char* filename, const char* permissions = "rb") {
|
||||||
|
handle = std::fopen(filename, permissions);
|
||||||
|
return isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
if (isOpen()) {
|
||||||
|
fclose(handle);
|
||||||
|
handle = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<bool, std::size_t> read(void* data, std::size_t length, std::size_t dataSize) {
|
||||||
|
if (!isOpen()) {
|
||||||
|
return { false, std::numeric_limits<std::size_t>::max() };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length == 0) return { true, 0 };
|
||||||
|
return { true, std::fread(data, dataSize, length, handle) };
|
||||||
|
}
|
||||||
|
|
||||||
|
auto readBytes(void* data, std::size_t count) {
|
||||||
|
return read(data, count, sizeof(std::uint8_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint64_t size() {
|
||||||
|
if (!isOpen()) return 0;
|
||||||
|
|
||||||
|
std::uint64_t pos = ftello(handle);
|
||||||
|
if (fseeko(handle, 0, SEEK_END) != 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint64_t size = ftello(handle);
|
||||||
|
if ((size != pos) && (fseeko(handle, pos, SEEK_SET) != 0)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool seek(std::int64_t offset, int origin = 0) {
|
||||||
|
if (!isOpen() || fseeko(handle, offset, origin) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rewind() {
|
||||||
|
return seek(0, 0);
|
||||||
|
}
|
||||||
|
};
|
15
include/loader/ncch.hpp
Normal file
15
include/loader/ncch.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include "helpers.hpp"
|
||||||
|
|
||||||
|
struct NCCH {
|
||||||
|
bool isNew3DS = false;
|
||||||
|
bool initialized = false;
|
||||||
|
bool mountRomFS = false;
|
||||||
|
bool encrypted = false;
|
||||||
|
|
||||||
|
static constexpr u64 mediaUnit = 0x200;
|
||||||
|
u64 size = 0; // Size of NCCH converted to bytes
|
||||||
|
|
||||||
|
// Header: 0x200 byte NCCH header
|
||||||
|
// Returns true on success, false on failure
|
||||||
|
bool loadFromHeader(u8* header);
|
||||||
|
};
|
18
include/loader/ncsd.hpp
Normal file
18
include/loader/ncsd.hpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include <array>
|
||||||
|
#include "helpers.hpp"
|
||||||
|
#include "io_file.hpp"
|
||||||
|
#include "loader/ncch.hpp"
|
||||||
|
|
||||||
|
struct NCSD {
|
||||||
|
static constexpr u64 mediaUnit = 0x200;
|
||||||
|
|
||||||
|
struct Partition {
|
||||||
|
u64 offset = 0; // Offset of partition converted to bytes
|
||||||
|
u64 length = 0; // Length of partition converted to bytes
|
||||||
|
NCCH ncch;
|
||||||
|
};
|
||||||
|
|
||||||
|
IOFile file;
|
||||||
|
u64 size = 0; // Image size according to the header converted to bytes
|
||||||
|
std::array<Partition, 8> partitions; // NCCH partitions
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue