Compare commits

3 Commits
Author SHA1 Message Date
tobid7 0ab0929746 started some work on cia/ncch 2025-11-28 17:49:05 +01:00
tobid7 8c1a48a527 updated to newer palladium 2025-11-28 17:48:54 +01:00
tobid7 6242a7565e fixes 2025-11-28 17:48:27 +01:00
6 changed files with 75 additions and 10 deletions
+3 -3
View File
@@ -29,13 +29,13 @@ class CTRFF_API BCSTM {
} }
bool IsLooping() const { return pInfoBlock.StreamInfo.Loop; } bool IsLooping() const { return pInfoBlock.StreamInfo.Loop; }
PD::u32 GetLoopStart() const { PD::u32 GetLoopStart() const {
return pInfoBlock.StreamInfo.LoopStartFrame / GetBlockSamples(); return pInfoBlock.StreamInfo.LoopStartFrame / GetNumBlocks();
} }
PD::u32 GetLoopEnd() const { PD::u32 GetLoopEnd() const {
/** Get temp references for better readability */ /** Get temp references for better readability */
const PD::u32& loop_end = pInfoBlock.StreamInfo.LoopEndFrame; const PD::u32& loop_end = pInfoBlock.StreamInfo.LoopEndFrame;
const PD::u32& block_samples = GetBlockSamples(); const PD::u32& block_samples = GetNumBlocks();
return (loop_end % block_samples ? GetNumBlocks() return (loop_end % block_samples ? block_samples
: loop_end / block_samples); : loop_end / block_samples);
} }
+24
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
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
+1 -4
View File
@@ -162,12 +162,9 @@ CTRFF_API void BCSTM::ReadGotoBeginning(bool use_loop_beg) {
} }
CTRFF_API void BCSTM::ReadBlock(PD::u32 block, PD::u8* ref) { CTRFF_API void BCSTM::ReadBlock(PD::u32 block, PD::u8* ref) {
if (!ref) {
throw std::runtime_error("BCSTM: pointer ref is nullptr!");
}
if (pFile.tellg() > pHeader.FileSize || block >= GetNumBlocks()) { if (pFile.tellg() > pHeader.FileSize || block >= GetNumBlocks()) {
throw std::runtime_error(std::format( throw std::runtime_error(std::format(
"BCSTM: Decode block out of range! ({}/{})", block, GetNumBlocks())); "BCSTM: Decode block Out of range! ({} > {})", block, GetNumBlocks()));
} }
pFile.read( pFile.read(
reinterpret_cast<char*>(ref), reinterpret_cast<char*>(ref),
+1 -1
View File
@@ -38,4 +38,4 @@ void BinUtil::Write(const T& v) {
// Write buffer into file // Write buffer into file
m_file.write(reinterpret_cast<const char*>(buf.data()), sizeof(T)); m_file.write(reinterpret_cast<const char*>(buf.data()), sizeof(T));
} }
} // namespace ctrff } // namespace ctrff
+2 -2
View File
@@ -148,7 +148,7 @@ CTRFF_API std::string ctrff::U16toU8(PD::u16 *in, size_t max) {
result.push_back(static_cast<char>(0x80 | (c & 0x3F))); result.push_back(static_cast<char>(0x80 | (c & 0x3F)));
} else if (c < 0x10000) { } else if (c < 0x10000) {
result.push_back(static_cast<char>(0xE0 | (c >> 12))); result.push_back(static_cast<char>(0xE0 | (c >> 12)));
result.push_back(static_cast<char>(0x80 | ((c >> 6) & 0x3F))); result.push_back(static_cast<char>(0x80 | ((c >> 6) & 0x3F)));
result.push_back(static_cast<char>(0x80 | (c & 0x3F))); result.push_back(static_cast<char>(0x80 | (c & 0x3F)));
} else { } else {
continue; continue;
@@ -156,4 +156,4 @@ result.push_back(static_cast<char>(0x80 | ((c >> 6) & 0x3F)));
} }
return result; return result;
} }