diff --git a/.gitmodules b/.gitmodules index 942f534..8debfd6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "vendor/cli-fancy"] path = vendor/cli-fancy url = https://dev.npid7.de/tobid7/cli-fancy -[submodule "vendor/palladium"] - path = vendor/palladium - url = https://dev.npid7.de/tobid7/palladium.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 814d96f..5f1af06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ if(${CTRFF_3DS}) endif() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O3") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti") endif() add_library(ctrff STATIC @@ -32,7 +31,6 @@ add_library(ctrff STATIC source/3dsx.cpp ) target_include_directories(ctrff PUBLIC include) -target_include_directories(ctrff PRIVATE vendor/palladium/include) if(${CTRFF_DESKTOP}) add_executable(ctrff-cli tool/main.cpp) diff --git a/include/ctrff/3dsx.hpp b/include/ctrff/3dsx.hpp index b660f22..8dc23bb 100644 --- a/include/ctrff/3dsx.hpp +++ b/include/ctrff/3dsx.hpp @@ -1,9 +1,8 @@ #pragma once #include -#include #include -#include +#include namespace ctrff { class CTRFF_API _3dsx : public BinFile { @@ -23,24 +22,24 @@ class CTRFF_API _3dsx : public BinFile { void Write(std::fstream& f) const override; void Read(std::fstream& f) override; - PD::u32 Magic; - PD::u16 HeaderSize; - PD::u16 RelocHeaderSize; - PD::u32 FormatVersion; - PD::u32 Flags; + ctrff::u32 Magic; + ctrff::u16 HeaderSize; + ctrff::u16 RelocHeaderSize; + ctrff::u32 FormatVersion; + ctrff::u32 Flags; // Sizes of the code, rodata and data segments + // size of the BSS section (uninitialized latter half of the data segment) - PD::u32 CodeSegSize; - PD::u32 RodataSegSize; - PD::u32 DataSegSize; - PD::u32 BssSize; + ctrff::u32 CodeSegSize; + ctrff::u32 RodataSegSize; + ctrff::u32 DataSegSize; + ctrff::u32 BssSize; /// Extended Header /// // smdh offset - PD::u32 SMDHOff; + ctrff::u32 SMDHOff; // smdh size - PD::u32 SMDHSize; + ctrff::u32 SMDHSize; // fs offset - PD::u32 FsOff; + ctrff::u32 FsOff; SMDH Meta; }; /** Probably only germen people will understand */ diff --git a/include/ctrff/bcstm.hpp b/include/ctrff/bcstm.hpp index 91dbf73..6dcb913 100644 --- a/include/ctrff/bcstm.hpp +++ b/include/ctrff/bcstm.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include +#include +#include namespace ctrff { class CTRFF_API BCSTM { @@ -13,38 +13,44 @@ class CTRFF_API BCSTM { void LoadFile(const std::string& path); void CleanUp(); void ReadGotoBeginning(bool use_loop_beg = false); - void ReadBlock(PD::u32 block, PD::u8* ref); + void ReadBlock(ctrff::u32 block, ctrff::u8* ref); /** Some useful Getters */ - PD::u8 GetNumChannels() const { return pInfoBlock.StreamInfo.ChannelCount; } - PD::u32 GetSampleRate() const { return pInfoBlock.StreamInfo.SampleRate; } - PD::u32 GetBlockSize() const { return pInfoBlock.StreamInfo.SampleBlockSize; } - PD::u32 GetNumBlocks() const { return pInfoBlock.StreamInfo.SampleBlockNum; } - PD::u32 GetBlockSamples() const { + ctrff::u8 GetNumChannels() const { + return pInfoBlock.StreamInfo.ChannelCount; + } + ctrff::u32 GetSampleRate() const { return pInfoBlock.StreamInfo.SampleRate; } + ctrff::u32 GetBlockSize() const { + return pInfoBlock.StreamInfo.SampleBlockSize; + } + ctrff::u32 GetNumBlocks() const { + return pInfoBlock.StreamInfo.SampleBlockNum; + } + ctrff::u32 GetBlockSamples() const { return pInfoBlock.StreamInfo.SampleBlockSampleNum; } - PD::u32 GetLastBlockSamples() const { + ctrff::u32 GetLastBlockSamples() const { return pInfoBlock.StreamInfo.LastSampleBlockSampleNum; } bool IsLooping() const { return pInfoBlock.StreamInfo.Loop; } - PD::u32 GetLoopStart() const { + ctrff::u32 GetLoopStart() const { return pInfoBlock.StreamInfo.LoopStartFrame / GetBlockSamples(); } - PD::u32 GetLoopEnd() const { + ctrff::u32 GetLoopEnd() const { /** Get temp references for better readability */ - const PD::u32& loop_end = pInfoBlock.StreamInfo.LoopEndFrame; - const PD::u32& block_samples = GetBlockSamples(); + const ctrff::u32& loop_end = pInfoBlock.StreamInfo.LoopEndFrame; + const ctrff::u32& block_samples = GetBlockSamples(); return (loop_end % block_samples ? GetNumBlocks() : loop_end / block_samples); } /** Internal Data (can be made private with private: but public by default) */ - enum Endianness : PD::u16 { + enum Endianness : ctrff::u16 { Big = 0xfffe, ///< Big Endian Little = 0xfeff, ///< Little Endian }; - enum ReferenceTypes : PD::u16 { + enum ReferenceTypes : ctrff::u16 { Ref_ByteTable = 0x0100, Ref_ReferenceTable = 0x0101, Ref_DSP_ADPCM_Info = 0x0300, @@ -58,7 +64,7 @@ class CTRFF_API BCSTM { Ref_ChannelInfo = 0x4102, }; - enum Encoding : PD::u8 { + enum Encoding : ctrff::u8 { PCM8 = 0, PCM16 = 1, /** Only supported encoding in BCSTM-Player */ @@ -68,50 +74,50 @@ class CTRFF_API BCSTM { struct Reference { Reference() : TypeID(0), Padding(0), Offset(0) {} - Reference(PD::u16 t, PD::u16 p, PD::u32 o) + Reference(ctrff::u16 t, ctrff::u16 p, ctrff::u32 o) : TypeID(t), Padding(p), Offset(o) {} - PD::u16 TypeID; - PD::u16 Padding; - PD::u32 Offset; /** null -> uint32_max */ + ctrff::u16 TypeID; + ctrff::u16 Padding; + ctrff::u32 Offset; /** null -> uint32_max */ }; struct ReferenceTable { ReferenceTable() : Count(0) {} - PD::u32 Count; + ctrff::u32 Count; std::vector Refs; }; struct SizedReference { SizedReference() : Size(0) {} Reference Ref; - PD::u32 Size; + ctrff::u32 Size; }; struct StreamInfo { StreamInfo(); - PD::u8 Encoding; - PD::u8 Loop; - PD::u8 ChannelCount; - PD::u8 Padding; - PD::u32 SampleRate; - PD::u32 LoopStartFrame; - PD::u32 LoopEndFrame; - PD::u32 SampleBlockNum; - PD::u32 SampleBlockSize; - PD::u32 SampleBlockSampleNum; - PD::u32 LastSampleBlockSize; - PD::u32 LastSampleBlockSampleNum; - PD::u32 LastSampleBlockPaddedSize; - PD::u32 SeekDataSize; - PD::u32 SeekIntervalSampleNum; + ctrff::u8 Encoding; + ctrff::u8 Loop; + ctrff::u8 ChannelCount; + ctrff::u8 Padding; + ctrff::u32 SampleRate; + ctrff::u32 LoopStartFrame; + ctrff::u32 LoopEndFrame; + ctrff::u32 SampleBlockNum; + ctrff::u32 SampleBlockSize; + ctrff::u32 SampleBlockSampleNum; + ctrff::u32 LastSampleBlockSize; + ctrff::u32 LastSampleBlockSampleNum; + ctrff::u32 LastSampleBlockPaddedSize; + ctrff::u32 SeekDataSize; + ctrff::u32 SeekIntervalSampleNum; Reference SampleDataRef; }; struct BlockHeader { BlockHeader() : Magic(0), Size(0) {} - BlockHeader(PD::u32 m, PD::u32 s) : Magic(m), Size(s) {} - PD::u32 Magic; - PD::u32 Size; + BlockHeader(ctrff::u32 m, ctrff::u32 s) : Magic(m), Size(s) {} + ctrff::u32 Magic; + ctrff::u32 Size; }; struct InfoBlock { @@ -130,13 +136,13 @@ class CTRFF_API BCSTM { struct SD_Block { SD_Block() {} BlockHeader Header; - std::vector Data; + std::vector Data; }; struct DSP_ADPCM_Param { // Lets keep this not clean here :/ DSP_ADPCM_Param() {} - PD::u16 Coefficients[0x10]; + ctrff::u16 Coefficients[0x10]; }; struct DSP_ADPCM_Context { @@ -145,10 +151,10 @@ class CTRFF_API BCSTM { Reserved(0), PreviousSample(0), SecondPreviousSample(0) {} - PD::u8 PredictorScale; - PD::u8 Reserved; - PD::u16 PreviousSample; - PD::u16 SecondPreviousSample; + ctrff::u8 PredictorScale; + ctrff::u8 Reserved; + ctrff::u16 PreviousSample; + ctrff::u16 SecondPreviousSample; }; struct DSP_ADPCM_Info { @@ -156,20 +162,20 @@ class CTRFF_API BCSTM { DSP_ADPCM_Param Param; DSP_ADPCM_Context Context; DSP_ADPCM_Context LoopContext; - PD::u16 Padding; + ctrff::u16 Padding; }; struct ByteTable { - ByteTable(PD::u32 size = 0) : Size(size) {} - PD::u32 Size; - std::vector Table; + ByteTable(ctrff::u32 size = 0) : Size(size) {} + ctrff::u32 Size; + std::vector Table; }; struct TrackInfo { TrackInfo() : Volume(0), Pan(0), Padding(0) {} - PD::u8 Volume; - PD::u8 Pan; - PD::u16 Padding; + ctrff::u8 Volume; + ctrff::u8 Pan; + ctrff::u16 Padding; Reference ChennelIndexTabRef; ByteTable ChannelIndexTab; }; @@ -184,13 +190,13 @@ class CTRFF_API BCSTM { FileSize(0), NumBlocks(0), Reserved(0) {} - PD::u32 Magic; /** CSTM */ - PD::u16 Endianness = Little; /** Default */ - PD::u16 HeaderSize; /** Header Size probably */ - PD::u32 Version; /** Format Version? */ - PD::u32 FileSize; /** File Size */ - PD::u16 NumBlocks; /** Number of blocks */ - PD::u16 Reserved; /** Reserved */ + ctrff::u32 Magic; /** CSTM */ + ctrff::u16 Endianness = Little; /** Default */ + ctrff::u16 HeaderSize; /** Header Size probably */ + ctrff::u32 Version; /** Format Version? */ + ctrff::u32 FileSize; /** File Size */ + ctrff::u16 NumBlocks; /** Number of blocks */ + ctrff::u16 Reserved; /** Reserved */ }; Header pHeader; diff --git a/include/ctrff/bcwav.hpp b/include/ctrff/bcwav.hpp index dc3059d..6cebc6f 100644 --- a/include/ctrff/bcwav.hpp +++ b/include/ctrff/bcwav.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include +#include +#include namespace ctrff { class CTRFF_API BCWAV { @@ -13,15 +13,15 @@ class CTRFF_API BCWAV { void LoadFile(const std::string& path); void CleanUp(); void ReadGotoBeginning(bool use_loop_beg = false); - void ReadBlock(PD::u32 block, PD::u8* ref); + void ReadBlock(ctrff::u32 block, ctrff::u8* ref); /** Internal Data (can be made private with private: but public by default) */ - enum Endianness : PD::u16 { + enum Endianness : ctrff::u16 { Big = 0xfffe, ///< Big Endian Little = 0xfeff, ///< Little Endian }; - enum ReferenceTypes : PD::u16 { + enum ReferenceTypes : ctrff::u16 { Ref_DSP_ADPCM_Info = 0x0300, Ref_IMA_ADPCM_Info = 0x0301, Ref_SampleData = 0x1f00, @@ -30,7 +30,7 @@ class CTRFF_API BCWAV { Ref_ChannelInfo = 0x7100, }; - enum Encoding : PD::u8 { + enum Encoding : ctrff::u8 { PCM8 = 0, PCM16 = 1, /** Only supported encoding in BCSTM-Player */ @@ -40,27 +40,27 @@ class CTRFF_API BCWAV { struct Reference { Reference() : TypeID(0), Padding(0), Offset(0) {} - PD::u16 TypeID; - PD::u16 Padding; - PD::u32 Offset; /** null -> uint32_max */ + ctrff::u16 TypeID; + ctrff::u16 Padding; + ctrff::u32 Offset; /** null -> uint32_max */ }; struct ReferenceTable { ReferenceTable() : Count(0) {} - PD::u32 Count; + ctrff::u32 Count; std::vector Refs; }; struct SizedReference { SizedReference() : Size(0) {} Reference Ref; - PD::u32 Size; + ctrff::u32 Size; }; struct BlockHeader { BlockHeader() : Magic(0), Size(0) {} - PD::u32 Magic; - PD::u32 Size; + ctrff::u32 Magic; + ctrff::u32 Size; }; struct InfoBlock { @@ -73,13 +73,13 @@ class CTRFF_API BCWAV { LoopEndFrame(0), Reserved(0) {} BlockHeader Header; - PD::u8 Encoding; - PD::u8 Loop; - PD::u16 Padding; - PD::u32 SampleRate; - PD::u32 LoopStartFrame; - PD::u32 LoopEndFrame; - PD::u32 Reserved; + ctrff::u8 Encoding; + ctrff::u8 Loop; + ctrff::u16 Padding; + ctrff::u32 SampleRate; + ctrff::u32 LoopStartFrame; + ctrff::u32 LoopEndFrame; + ctrff::u32 Reserved; ReferenceTable ChannelInfoTab; std::vector ChannelInfoRefs; /** The refs of the refs ?? */ }; @@ -91,12 +91,12 @@ class CTRFF_API BCWAV { } } BlockHeader Header; - PD::u32 Padding[3]; - std::vector Data; + ctrff::u32 Padding[3]; + std::vector Data; }; struct DSP_ADPCM_Param { - PD::u16 Coefficients[0x10]; + ctrff::u16 Coefficients[0x10]; }; struct DSP_ADPCM_Context { DSP_ADPCM_Context() @@ -104,10 +104,10 @@ class CTRFF_API BCWAV { Reserved(0), PreviousSample(0), SecondPreviousSample(0) {} - PD::u8 PredictorScale; - PD::u8 Reserved; - PD::u16 PreviousSample; - PD::u16 SecondPreviousSample; + ctrff::u8 PredictorScale; + ctrff::u8 Reserved; + ctrff::u16 PreviousSample; + ctrff::u16 SecondPreviousSample; }; struct DSP_ADPCM_Info { @@ -115,7 +115,7 @@ class CTRFF_API BCWAV { DSP_ADPCM_Param Param; DSP_ADPCM_Context Context; DSP_ADPCM_Context LoopContext; - PD::u16 Padding; + ctrff::u16 Padding; }; struct Header { @@ -127,13 +127,13 @@ class CTRFF_API BCWAV { FileSize(0), NumBlocks(0), Reserved(0) {} - PD::u32 Magic; /** CWAV */ - PD::u16 Endianness = Little; /** Default */ - PD::u16 HeaderSize; /** Header Size probably */ - PD::u32 Version; /** Format Version? */ - PD::u32 FileSize; /** File Size */ - PD::u16 NumBlocks; /** Number of blocks */ - PD::u16 Reserved; /** Reserved */ + ctrff::u32 Magic; /** CWAV */ + ctrff::u16 Endianness = Little; /** Default */ + ctrff::u16 HeaderSize; /** Header Size probably */ + ctrff::u32 Version; /** Format Version? */ + ctrff::u32 FileSize; /** File Size */ + ctrff::u16 NumBlocks; /** Number of blocks */ + ctrff::u16 Reserved; /** Reserved */ }; Header pHeader; diff --git a/include/ctrff/binutil.hpp b/include/ctrff/binutil.hpp index b08a3b9..0926e2f 100644 --- a/include/ctrff/binutil.hpp +++ b/include/ctrff/binutil.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include namespace ctrff { class BinFile { diff --git a/include/ctrff/helper.hpp b/include/ctrff/helper.hpp index 6fc33d2..d6985b9 100644 --- a/include/ctrff/helper.hpp +++ b/include/ctrff/helper.hpp @@ -1,16 +1,16 @@ #pragma once -#include -#include +#include +#include namespace ctrff { -CTRFF_API void String2U16(PD::u16 *res, const std::string &src, size_t max); -CTRFF_API std::string U16toU8(PD::u16 *in, size_t max); -CTRFF_API void RGB565toRGBA(std::vector &img, PD::u16 *icon, +CTRFF_API void String2U16(ctrff::u16 *res, const std::string &src, size_t max); +CTRFF_API std::string U16toU8(ctrff::u16 *in, size_t max); +CTRFF_API void RGB565toRGBA(std::vector &img, ctrff::u16 *icon, const int &w, const int &h); // Image can only be rgba8888 -CTRFF_API void RGBA2RGB565(PD::u16 *out, const std::vector &img, +CTRFF_API void RGBA2RGB565(ctrff::u16 *out, const std::vector &img, const int &w, const int &h); -CTRFF_API std::vector DownscaleImage(const std::vector &img, - int w, int h, int scale); +CTRFF_API std::vector DownscaleImage( + const std::vector &img, int w, int h, int scale); } // namespace ctrff \ No newline at end of file diff --git a/include/ctrff/lz11.hpp b/include/ctrff/lz11.hpp index de13c69..f5ee57a 100644 --- a/include/ctrff/lz11.hpp +++ b/include/ctrff/lz11.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include +#include namespace ctrff { namespace LZ11 { -CTRFF_API std::vector Compress(const std::vector& in); +CTRFF_API std::vector Compress(const std::vector& in); } } // namespace ctrff \ No newline at end of file diff --git a/include/ctrff/smdh.hpp b/include/ctrff/smdh.hpp index 68a3b90..d471f99 100644 --- a/include/ctrff/smdh.hpp +++ b/include/ctrff/smdh.hpp @@ -2,8 +2,7 @@ #include #include -#include -#include +#include // Basic Info // language_slots: 16 @@ -16,16 +15,16 @@ namespace ctrff { // SMDH Size (Note that this needs to be declared here as // a sizeof(SMDH) will not return the expected size due to // use of Serializable) -constexpr PD::u32 SMDH_Size = 0x36C0; +constexpr ctrff::u32 SMDH_Size = 0x36C0; struct CTRFF_API SMDH { SMDH() { - std::fill_n(Magic, PD::ArraySize(Magic), 0); - std::fill_n(IconSmall, PD::ArraySize(IconSmall), 0); - std::fill_n(IconLarge, PD::ArraySize(IconLarge), 0); + std::fill_n(Magic, ctrff::ArraySize(Magic), 0); + std::fill_n(IconSmall, ctrff::ArraySize(IconSmall), 0); + std::fill_n(IconLarge, ctrff::ArraySize(IconLarge), 0); } ~SMDH() = default; static SMDH Default(); - PD_SMART_CTOR(SMDH); + PD_SHARED(SMDH); enum Language { Language_Japanese, @@ -97,8 +96,8 @@ struct CTRFF_API SMDH { void Write(std::fstream &f) const; void Read(std::fstream &f); - void SetIcon(const std::vector &buf); - std::vector GetIcon(); + void SetIcon(const std::vector &buf); + std::vector GetIcon(); void SetShortTitle(const std::string &t, Language l = Language_All); void SetLongTitle(const std::string &t, Language l = Language_All); void SetAuthor(const std::string &t, Language l = Language_All); @@ -108,36 +107,36 @@ struct CTRFF_API SMDH { struct CTRFF_API Title { Title() { - std::fill_n(ShortTitle, PD::ArraySize(ShortTitle), 0); - std::fill_n(LongTitle, PD::ArraySize(LongTitle), 0); - std::fill_n(Author, PD::ArraySize(Author), 0); + std::fill_n(ShortTitle, ctrff::ArraySize(ShortTitle), 0); + std::fill_n(LongTitle, ctrff::ArraySize(LongTitle), 0); + std::fill_n(Author, ctrff::ArraySize(Author), 0); }; - PD::u16 ShortTitle[0x40]; - PD::u16 LongTitle[0x80]; - PD::u16 Author[0x40]; + ctrff::u16 ShortTitle[0x40]; + ctrff::u16 LongTitle[0x80]; + ctrff::u16 Author[0x40]; }; struct CTRFF_API Settings { - Settings() { std::fill_n(Ratings, PD::ArraySize(Ratings), 0); }; - PD::u8 Ratings[16]; - PD::u32 RegionLock = 0; - PD::u32 MatchmakerID = 0; - PD::u64 MatchmakerBitID = 0; - PD::u32 Flags = 0; - PD::u16 EulaVersion = 0; - PD::u16 Reserved = 0; - PD::u32 OptimalBannerFrame = 0; - PD::u32 StreetpassID = 0; + Settings() { std::fill_n(Ratings, ctrff::ArraySize(Ratings), 0); }; + ctrff::u8 Ratings[16]; + ctrff::u32 RegionLock = 0; + ctrff::u32 MatchmakerID = 0; + ctrff::u64 MatchmakerBitID = 0; + ctrff::u32 Flags = 0; + ctrff::u16 EulaVersion = 0; + ctrff::u16 Reserved = 0; + ctrff::u32 OptimalBannerFrame = 0; + ctrff::u32 StreetpassID = 0; }; char Magic[4]; - PD::u16 Version = 0; - PD::u16 Reserved = 0; + ctrff::u16 Version = 0; + ctrff::u16 Reserved = 0; Title Titles[16]; Settings Settings; - PD::u64 Reserved1 = 0; - PD::u16 IconSmall[0x240]; // 24x24 - PD::u16 IconLarge[0x900]; // 48x48 + ctrff::u64 Reserved1 = 0; + ctrff::u16 IconSmall[0x240]; // 24x24 + ctrff::u16 IconLarge[0x900]; // 48x48 }; } // namespace ctrff \ No newline at end of file diff --git a/include/ctrff/pd_p_api.hpp b/include/ctrff/types.hpp similarity index 72% rename from include/ctrff/pd_p_api.hpp rename to include/ctrff/types.hpp index ebd393e..867890a 100644 --- a/include/ctrff/pd_p_api.hpp +++ b/include/ctrff/types.hpp @@ -47,4 +47,27 @@ SOFTWARE. #define CTRFF_API #else #define CTRFF_API -#endif \ No newline at end of file +#endif + +#include + +namespace ctrff { +using u8 = unsigned char; +using u16 = unsigned short; +using u32 = unsigned int; +using u64 = unsigned long long; + +/** + * Function to get Arraysize for any type using modern c++ to + * get the size at compiletime instead of runtime + * @note this function only works for Arrays declared as + * type arr[size] and not for pointer references. + * This function will precalculate the size at compile time + * while keeping the code clean to not hardcode arraysizes + * into functions like std::fill_n + */ +template +constexpr size_t ArraySize(T (&)[N]) noexcept { + return N; +} +} // namespace ctrff \ No newline at end of file diff --git a/vendor/palladium b/vendor/palladium deleted file mode 160000 index a0960bd..0000000 --- a/vendor/palladium +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a0960bd717bce6a659d17e157e59c9bf16486c04