3 Commits
main ... indev

Author SHA1 Message Date
0ab0929746 started some work on cia/ncch 2025-11-28 17:49:05 +01:00
8c1a48a527 updated to newer palladium 2025-11-28 17:48:54 +01:00
6242a7565e fixes 2025-11-28 17:48:27 +01:00
6 changed files with 76 additions and 7 deletions

24
include/ctrff/cia.hpp Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include <ctrff/helper.hpp>
#include <ctrff/pd_p_api.hpp>
#include <ctrff/smdh.hpp>
#include <pd.hpp>
namespace ctrff {
class Cia : public BinFile {
public:
Cia() {}
~Cia() {}
PD::u32 HeaderSize;
PD::u16 Type;
PD::u16 Version;
PD::u32 CertChainSize;
PD::u32 TikSize;
PD::u32 TmdFileSize;
PD::u32 MetaSize;
PD::u64 ContentSize;
PD::u8 ContentIndex[0x2000];
};
} // namespace ctrff

44
include/ctrff/ncch.hpp Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
#include <ctrff/helper.hpp>
#include <ctrff/pd_p_api.hpp>
#include <ctrff/smdh.hpp>
#include <pd.hpp>
namespace ctrff {
class NCCH : public BinFile {
public:
NCCH() {}
~NCCH() {}
PD::u8 Sig[0x100];
PD::u32 Magic;
PD::u32 ContentLen; // 1 (Media Unit) = 0x200 bytes
PD::u64 PartitionID;
PD::u16 MarkerCode;
PD::u16 Version;
PD::u32 Wtf;
PD::u64 ProgramID;
PD::u8 Reserved[0x10];
PD::u8 LogoHash[0x20]; // Firm 5.0.0-11+
PD::u8 ProdCode[0x10];
PD::u8 ExHeaderHash[0x20];
PD::u32 ExHeaderLen;
PD::u32 Reserved1;
PD::u64 Flags;
PD::u32 PlainRegionOff; // In Media Units
PD::u32 PlainRegionSize;
PD::u32 LogoRegionOff;
PD::u32 LogoRegionSize;
PD::u32 ExeFsOff;
PD::u32 ExeFsSize;
PD::u32 ExeFsHashRegionSize;
PD::u32 Reserved2;
PD::u32 RomFsOff;
PD::u32 RomFsSize;
PD::u32 RomFsHashRegionSize;
PD::u32 Reserved;
PD::u8 ExeFsSuperBlockHash[0x20];
PD::u8 RomFsSuperBlockHash[0x20];
};
} // namespace ctrff

View File

@@ -163,7 +163,8 @@ CTRFF_API void BCSTM::ReadGotoBeginning(bool use_loop_beg) {
CTRFF_API void BCSTM::ReadBlock(PD::u32 block, PD::u8* ref) {
if (pFile.tellg() > pHeader.FileSize || block >= GetNumBlocks()) {
throw std::runtime_error("BCSTM: Decode block Out of range!");
throw std::runtime_error(std::format(
"BCSTM: Decode block Out of range! ({} > {})", block, GetNumBlocks()));
}
pFile.read(
reinterpret_cast<char*>(ref),

View File

@@ -21,7 +21,7 @@ void BinUtil::Read(T& v) {
// Read data into buffer
m_file.read(reinterpret_cast<char*>(buf.data()), sizeof(T));
// Loop or in be reverse loop and chift the values
for (int i = 0; i < sizeof(T); i++) {
for (size_t i = 0; i < sizeof(T); i++) {
v |= static_cast<T>(buf[m_big ? sizeof(T) - 1 - i : i]) << (8 * i);
}
}

View File

@@ -31,8 +31,8 @@ CTRFF_API void ctrff::RGB565toRGBA(std::vector<PD::u8> &img, PD::u16 *icon,
img.resize(48 * 48 * 4);
img.clear();
}
for (PD::u32 y = 0; y < h; y++) {
for (PD::u32 x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
auto idx = TileIndex(x, y, w);
PD::u32 pos = (y * w + x) * 4;
MakePixelRGBA(img[pos + 0], img[pos + 1], img[pos + 2], img[pos + 3],
@@ -45,8 +45,8 @@ CTRFF_API void ctrff::RGBA2RGB565(PD::u16 *out, const std::vector<PD::u8> &img,
const int &w, const int &h) {
if (img.size() != size_t(w * h * 4)) return;
std::vector<PD::u8> px8 = img;
for (PD::u32 y = 0; y < h; y++) {
for (PD::u32 x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
auto idx = TileIndex(x, y, w);
PD::u32 pos = (y * w + x) * 4;
out[idx] = MakePixel565(img[pos], img[pos + 1], img[pos + 2]);