diff --git a/include/ctrff/bcstm.hpp b/include/ctrff/bcstm.hpp index 6dcb913..93a41ca 100644 --- a/include/ctrff/bcstm.hpp +++ b/include/ctrff/bcstm.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace ctrff { class CTRFF_API BCSTM { diff --git a/include/ctrff/bcwav.hpp b/include/ctrff/bcwav.hpp index 6cebc6f..21bb473 100644 --- a/include/ctrff/bcwav.hpp +++ b/include/ctrff/bcwav.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace ctrff { class CTRFF_API BCWAV { diff --git a/include/ctrff/binutil.hpp b/include/ctrff/binutil.hpp index 0926e2f..66708f4 100644 --- a/include/ctrff/binutil.hpp +++ b/include/ctrff/binutil.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace ctrff { class BinFile { diff --git a/include/ctrff/helper.hpp b/include/ctrff/helper.hpp index d6985b9..b38d6d6 100644 --- a/include/ctrff/helper.hpp +++ b/include/ctrff/helper.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace ctrff { CTRFF_API void String2U16(ctrff::u16 *res, const std::string &src, size_t max); diff --git a/include/ctrff/lz11.hpp b/include/ctrff/lz11.hpp index f5ee57a..cce6b48 100644 --- a/include/ctrff/lz11.hpp +++ b/include/ctrff/lz11.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace ctrff { namespace LZ11 { diff --git a/include/ctrff/smdh.hpp b/include/ctrff/smdh.hpp index d471f99..ac2e516 100644 --- a/include/ctrff/smdh.hpp +++ b/include/ctrff/smdh.hpp @@ -24,7 +24,6 @@ struct CTRFF_API SMDH { } ~SMDH() = default; static SMDH Default(); - PD_SHARED(SMDH); enum Language { Language_Japanese, diff --git a/include/ctrff/types.hpp b/include/ctrff/types.hpp index 867890a..35ac3a7 100644 --- a/include/ctrff/types.hpp +++ b/include/ctrff/types.hpp @@ -50,6 +50,14 @@ SOFTWARE. #endif #include +#include +#include +#include +#include +#include +#include +#include +#include namespace ctrff { using u8 = unsigned char; diff --git a/source/bcstm.cpp b/source/bcstm.cpp index 4906301..a041a09 100644 --- a/source/bcstm.cpp +++ b/source/bcstm.cpp @@ -1,7 +1,7 @@ #include /** Using this a single time so inline it */ -inline PD::u32 Swap32(PD::u32 in) { +inline ctrff::u32 Swap32(ctrff::u32 in) { return (in >> 24) | ((in >> 8) & 0x0000FF00) | ((in << 8) & 0x00FF0000) | (in << 24); } @@ -28,7 +28,7 @@ CTRFF_API void BCSTM::LoadFile(const std::string& path) { pReader.Read(pHeader.FileSize); pReader.Read(pHeader.NumBlocks); pReader.Read(pHeader.Reserved); - for (PD::u16 i = 0; i < pHeader.NumBlocks; i++) { + for (ctrff::u16 i = 0; i < pHeader.NumBlocks; i++) { SizedReference ref; ReadSizedReference(ref); if (ref.Ref.TypeID == Ref_InfoBlock) { @@ -119,8 +119,8 @@ CTRFF_API void BCSTM::ReadSeekBlock(SD_Block& block) { } pSeekBlock.Data.reserve(pSeekBlock.Header.Size + 1); - for (PD::u32 i = 0; i < pSeekBlock.Header.Size; i++) { - PD::u8 v; + for (ctrff::u32 i = 0; i < pSeekBlock.Header.Size; i++) { + ctrff::u8 v; pReader.Read(v); pSeekBlock.Data.push_back(v); } @@ -129,7 +129,7 @@ CTRFF_API void BCSTM::ReadSeekBlock(SD_Block& block) { CTRFF_API void BCSTM::ReadReferenceTab(ReferenceTable& tab) { pReader.Read(tab.Count); tab.Refs.reserve(tab.Count + 1); - for (PD::u32 i = 0; i < tab.Count; i++) { + for (ctrff::u32 i = 0; i < tab.Count; i++) { Reference r; pReader.Read(r.TypeID); pReader.Read(r.Padding); @@ -155,7 +155,7 @@ 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(ctrff::u32 block, ctrff::u8* ref) { if (!ref) { throw std::runtime_error("BCSTM: pointer ref is nullptr!"); } diff --git a/source/bcwav.cpp b/source/bcwav.cpp index cea9f27..f10d51f 100644 --- a/source/bcwav.cpp +++ b/source/bcwav.cpp @@ -1,7 +1,7 @@ #include /** Using this a single time so inline it */ -inline PD::u32 Swap32(PD::u32 in) { +inline ctrff::u32 Swap32(ctrff::u32 in) { return (in >> 24) | ((in >> 8) & 0x0000FF00) | ((in << 8) & 0x00FF0000) | (in << 24); } @@ -28,7 +28,7 @@ CTRFF_API void BCWAV::LoadFile(const std::string& path) { pReader.Read(pHeader.FileSize); pReader.Read(pHeader.NumBlocks); pReader.Read(pHeader.Reserved); - for (PD::u16 i = 0; i < pHeader.NumBlocks; i++) { + for (ctrff::u16 i = 0; i < pHeader.NumBlocks; i++) { SizedReference ref; ReadSizedReference(ref); if (ref.Ref.TypeID == Ref_InfoBlock) { @@ -86,7 +86,7 @@ CTRFF_API void BCWAV::ReadInfoBlock(InfoBlock& block) { CTRFF_API void BCWAV::ReadReferenceTab(ReferenceTable& tab) { pReader.Read(tab.Count); tab.Refs.reserve(tab.Count + 1); - for (PD::u32 i = 0; i < tab.Count; i++) { + for (ctrff::u32 i = 0; i < tab.Count; i++) { Reference r; pReader.Read(r.TypeID); pReader.Read(r.Padding); @@ -111,7 +111,7 @@ CTRFF_API void BCWAV::ReadGotoBeginning(bool use_loop_beg) { } } -CTRFF_API void BCWAV::ReadBlock(PD::u32 block, PD::u8* ref) { +CTRFF_API void BCWAV::ReadBlock(ctrff::u32 block, ctrff::u8* ref) { // if (pFile.tellg() > pHeader.FileSize || block >= GetNumBlocks()) { // throw std::runtime_error("BCWAV: Decode block Out of range!"); // } diff --git a/source/binutil.cpp b/source/binutil.cpp index eeeb63a..e9042f2 100644 --- a/source/binutil.cpp +++ b/source/binutil.cpp @@ -2,22 +2,22 @@ namespace ctrff { /** Supported reads */ -template CTRFF_API void BinUtil::Read(PD::u8&); -template CTRFF_API void BinUtil::Read(PD::u16&); -template CTRFF_API void BinUtil::Read(PD::u32&); -template CTRFF_API void BinUtil::Read(PD::u64&); +template CTRFF_API void BinUtil::Read(ctrff::u8&); +template CTRFF_API void BinUtil::Read(ctrff::u16&); +template CTRFF_API void BinUtil::Read(ctrff::u32&); +template CTRFF_API void BinUtil::Read(ctrff::u64&); /** Supported writes */ -template CTRFF_API void BinUtil::Write(const PD::u8&); -template CTRFF_API void BinUtil::Write(const PD::u16&); -template CTRFF_API void BinUtil::Write(const PD::u32&); -template CTRFF_API void BinUtil::Write(const PD::u64&); +template CTRFF_API void BinUtil::Write(const ctrff::u8&); +template CTRFF_API void BinUtil::Write(const ctrff::u16&); +template CTRFF_API void BinUtil::Write(const ctrff::u32&); +template CTRFF_API void BinUtil::Write(const ctrff::u64&); template void BinUtil::Read(T& v) { // Check if Value could be Read static_assert(std::is_integral::value, "Cannot Read type T"); v = 0; // Set value to 0 (most cases a windows problem) - std::vector buf(sizeof(T), 0); // declare buffer + std::vector buf(sizeof(T), 0); // declare buffer // Read data into buffer m_file.read(reinterpret_cast(buf.data()), sizeof(T)); // Loop or in be reverse loop and chift the values @@ -29,11 +29,11 @@ template void BinUtil::Write(const T& v) { // Check if Value could Write static_assert(std::is_integral::value, "Cannot Write type T"); - std::vector buf(sizeof(T), 0); // declare buffer + std::vector buf(sizeof(T), 0); // declare buffer // Loop or in be reverse loop and write the values for (size_t i = 0; i < sizeof(T); i++) { buf[(m_big ? sizeof(T) - 1 - i : i)] = buf[m_big ? sizeof(T) - 1 - i : i] = - static_cast((v >> (8 * i)) & 0xFF); + static_cast((v >> (8 * i)) & 0xFF); } // Write buffer into file m_file.write(reinterpret_cast(buf.data()), sizeof(T)); diff --git a/source/helper.cpp b/source/helper.cpp index d048216..4f42243 100644 --- a/source/helper.cpp +++ b/source/helper.cpp @@ -2,31 +2,33 @@ #include #include -void MakePixelRGBA(PD::u8 &r, PD::u8 &g, PD::u8 &b, PD::u8 &a, PD::u16 px) { +void MakePixelRGBA(ctrff::u8 &r, ctrff::u8 &g, ctrff::u8 &b, ctrff::u8 &a, + ctrff::u16 px) { b = (px & 0x1f) << 3; g = ((px >> 0x5) & 0x3f) << 2; r = ((px >> 0xb) & 0x1f) << 3; a = 0xff; } -CTRFF_API PD::u16 MakePixel565(const PD::u8 &r, const PD::u8 &g, - const PD::u8 &b) { - PD::u16 res = 0; +CTRFF_API ctrff::u16 MakePixel565(const ctrff::u8 &r, const ctrff::u8 &g, + const ctrff::u8 &b) { + ctrff::u16 res = 0; res |= (r & ~0x7) << 8; res |= (g & ~0x3) << 3; res |= (b) >> 3; return res; } -CTRFF_API PD::u32 TileIndex(const int &x, const int &y, const int &w) { +CTRFF_API ctrff::u32 TileIndex(const int &x, const int &y, const int &w) { return (((y >> 3) * (w >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3)); } // TODO: Fix colors -CTRFF_API void ctrff::RGB565toRGBA(std::vector &img, PD::u16 *icon, - const int &w, const int &h) { +CTRFF_API void ctrff::RGB565toRGBA(std::vector &img, + ctrff::u16 *icon, const int &w, + const int &h) { if (img.size() != (48 * 48 * 4)) { img.resize(48 * 48 * 4); img.clear(); @@ -34,36 +36,37 @@ CTRFF_API void ctrff::RGB565toRGBA(std::vector &img, PD::u16 *icon, 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; + ctrff::u32 pos = (y * w + x) * 4; MakePixelRGBA(img[pos + 0], img[pos + 1], img[pos + 2], img[pos + 3], icon[idx]); } } } -CTRFF_API void ctrff::RGBA2RGB565(PD::u16 *out, const std::vector &img, +CTRFF_API void ctrff::RGBA2RGB565(ctrff::u16 *out, + const std::vector &img, const int &w, const int &h) { if (img.size() != size_t(w * h * 4)) return; - std::vector px8 = img; + std::vector px8 = img; 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; + ctrff::u32 pos = (y * w + x) * 4; out[idx] = MakePixel565(img[pos], img[pos + 1], img[pos + 2]); } } } -CTRFF_API std::vector ctrff::DownscaleImage( - const std::vector &img, int w, int h, int scale) { - std::vector res(((w / scale) * (h / scale)) * 4); +CTRFF_API std::vector ctrff::DownscaleImage( + const std::vector &img, int w, int h, int scale) { + std::vector res(((w / scale) * (h / scale)) * 4); int samples = scale * scale; for (int y = 0; y < h; y += scale) { for (int x = 0; x < w; x += scale) { - PD::u32 r = 0; - PD::u32 g = 0; - PD::u32 b = 0; - PD::u32 a = 0; + ctrff::u32 r = 0; + ctrff::u32 g = 0; + ctrff::u32 b = 0; + ctrff::u32 a = 0; for (int oy = 0; oy < scale; oy++) { for (int ox = 0; ox < scale; ox++) { int pos = ((y + oy) * w + (x + ox)) * 4; @@ -74,16 +77,16 @@ CTRFF_API std::vector ctrff::DownscaleImage( } } int pos = ((y / scale) * (w / scale) + (x / scale)) * 4; - res[pos++] = (PD::u8)(r / samples); - res[pos++] = (PD::u8)(g / samples); - res[pos++] = (PD::u8)(b / samples); - res[pos++] = (PD::u8)(a / samples); + res[pos++] = (ctrff::u8)(r / samples); + res[pos++] = (ctrff::u8)(g / samples); + res[pos++] = (ctrff::u8)(b / samples); + res[pos++] = (ctrff::u8)(a / samples); } } return res; } -CTRFF_API void ctrff::String2U16(PD::u16 *res, const std::string &src, +CTRFF_API void ctrff::String2U16(ctrff::u16 *res, const std::string &src, size_t max) { /// GOT FORCED TO REPLACE std::wstring_convert by some /// manual work as it got removed in cxx20 @@ -93,7 +96,7 @@ CTRFF_API void ctrff::String2U16(PD::u16 *res, const std::string &src, size_t len = 0; size_t i = 0; while (i < src.size() && len < max) { - PD::u8 c = src[i]; + ctrff::u8 c = src[i]; if (c < 0x80) { // 1byte @@ -116,8 +119,8 @@ CTRFF_API void ctrff::String2U16(PD::u16 *res, const std::string &src, // 4byte if (i + 3 >= src.size()) throw std::invalid_argument("Invalid UTF-8 sequence"); - PD::u32 codepoint = ((c & 0x07) << 18) | ((src[i + 1] & 0x3F) << 12) | - ((src[i + 2] & 0x3F) << 6) | (src[i + 3] & 0x3F); + ctrff::u32 codepoint = ((c & 0x07) << 18) | ((src[i + 1] & 0x3F) << 12) | + ((src[i + 2] & 0x3F) << 6) | (src[i + 3] & 0x3F); codepoint -= 0x10000; res[len++] = 0xD800 | ((codepoint >> 10) & 0x3FF); res[len++] = 0xDC00 | (codepoint & 0x3FF); @@ -128,7 +131,7 @@ CTRFF_API void ctrff::String2U16(PD::u16 *res, const std::string &src, } } -CTRFF_API std::string ctrff::U16toU8(PD::u16 *in, size_t max) { +CTRFF_API std::string ctrff::U16toU8(ctrff::u16 *in, size_t max) { /// GOT FORCED TO REPLACE std::wstring_convert by some /// manual work as it got removed in cxx20 if (!in || max == 0) { diff --git a/source/lz11.cpp b/source/lz11.cpp index 5b36eb6..6ee954c 100644 --- a/source/lz11.cpp +++ b/source/lz11.cpp @@ -5,14 +5,14 @@ namespace ctrff { namespace LZ11 { -PD::u32 GetOccurenceLength(const PD::u8* new_ptr, size_t new_len, - const PD::u8* old_ptr, size_t old_len, - PD::u32& disp) { +ctrff::u32 GetOccurenceLength(const ctrff::u8* new_ptr, size_t new_len, + const ctrff::u8* old_ptr, size_t old_len, + ctrff::u32& disp) { disp = 0; if (new_len == 0) { return 0; } - PD::u32 res = 0; + ctrff::u32 res = 0; if (old_len > 0) { for (size_t i = 0; i < old_len - 1; i++) { auto ref = old_ptr + i; @@ -35,20 +35,20 @@ PD::u32 GetOccurenceLength(const PD::u8* new_ptr, size_t new_len, return res; } -CTRFF_API std::vector Compress(const std::vector& in) { +CTRFF_API std::vector Compress(const std::vector& in) { if (in.size() > 0xFFFFFF) { std::cout << "ERROR: LZ11 input is too large!" << std::endl; - return std::vector(); + return std::vector(); } std::stringstream s; // SETUP HEADER // - s << static_cast(0x11); - s << static_cast(in.size() & 0xFF); - s << static_cast((in.size() >> 8) & 0xFF); - s << static_cast((in.size() >> 16) & 0xFF); + s << static_cast(0x11); + s << static_cast(in.size() & 0xFF); + s << static_cast((in.size() >> 8) & 0xFF); + s << static_cast((in.size() >> 16) & 0xFF); - size_t res_len = 4; // 4-byte header - PD::u8 out_buf[0x21]; // 33 bytes + size_t res_len = 4; // 4-byte header + ctrff::u8 out_buf[0x21]; // 33 bytes out_buf[0] = 0; size_t obl = 1; // out_buf_len size_t buf_blocks = 0; @@ -63,7 +63,7 @@ CTRFF_API std::vector Compress(const std::vector& in) { buf_blocks = 0; } - PD::u32 disp = 0; + ctrff::u32 disp = 0; size_t old_len = std::min(rb, static_cast(0x1000)); size_t len = LZ11::GetOccurenceLength( in.data() + rb, std::min(in.size() - rb, static_cast(0x10110)), @@ -73,21 +73,22 @@ CTRFF_API std::vector Compress(const std::vector& in) { out_buf[obl++] = in[rb++]; } else { rb += len; - out_buf[0] |= static_cast(1 << (7 - buf_blocks)); + out_buf[0] |= static_cast(1 << (7 - buf_blocks)); if (len > 0x110) { out_buf[obl++] = - 0x10 | static_cast(((len - 0x111) >> 12) & 0x0F); - out_buf[obl++] = static_cast(((len - 0x111) >> 4) & 0xFF); - out_buf[obl] = static_cast(((len - 0x111) << 4) & 0xF0); + 0x10 | static_cast(((len - 0x111) >> 12) & 0x0F); + out_buf[obl++] = static_cast(((len - 0x111) >> 4) & 0xFF); + out_buf[obl] = static_cast(((len - 0x111) << 4) & 0xF0); } else if (len > 0x10) { - out_buf[obl++] = 0x00 | static_cast(((len - 0x11) >> 4) & 0x0F); - out_buf[obl] = static_cast(((len - 0x11) << 4) & 0xF0); + out_buf[obl++] = + 0x00 | static_cast(((len - 0x11) >> 4) & 0x0F); + out_buf[obl] = static_cast(((len - 0x11) << 4) & 0xF0); } else { - out_buf[obl] |= static_cast(((len - 1) << 4) & 0xF0); + out_buf[obl] |= static_cast(((len - 1) << 4) & 0xF0); } obl++; - out_buf[obl++] = static_cast(((disp - 1) >> 8) & 0x0F); - out_buf[obl++] = static_cast((disp - 1) & 0xFF); + out_buf[obl++] = static_cast(((disp - 1) >> 8) & 0x0F); + out_buf[obl++] = static_cast((disp - 1) & 0xFF); } buf_blocks++; } @@ -98,13 +99,13 @@ CTRFF_API std::vector Compress(const std::vector& in) { } if (res_len % 4 != 0) { - PD::u32 pad_len = 4 - (res_len % 4); - PD::u8 pad[4] = {0}; + ctrff::u32 pad_len = 4 - (res_len % 4); + ctrff::u8 pad[4] = {0}; s.write(reinterpret_cast(pad), pad_len); res_len += pad_len; } - std::vector res(res_len); + std::vector res(res_len); s.read(reinterpret_cast(res.data()), res.size()); return res; } diff --git a/source/smdh.cpp b/source/smdh.cpp index 0edb7a0..db679e8 100644 --- a/source/smdh.cpp +++ b/source/smdh.cpp @@ -39,14 +39,14 @@ CTRFF_API void ctrff::SMDH::Read(std::fstream &f) { f.read(reinterpret_cast(&IconLarge), sizeof(IconLarge)); } -CTRFF_API void ctrff::SMDH::SetIcon(const std::vector &buf) { +CTRFF_API void ctrff::SMDH::SetIcon(const std::vector &buf) { RGBA2RGB565(IconLarge, buf, 48, 48); auto small_icon = DownscaleImage(buf, 48, 48, 2); RGBA2RGB565(IconSmall, small_icon, 24, 24); } -CTRFF_API std::vector ctrff::SMDH::GetIcon() { - std::vector res(48 * 48 * 4); +CTRFF_API std::vector ctrff::SMDH::GetIcon() { + std::vector res(48 * 48 * 4); ctrff::RGB565toRGBA(res, IconLarge, 48, 48); return res; } diff --git a/tool/main.cpp b/tool/main.cpp index bb45e81..f4a2579 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -121,7 +121,7 @@ void MakeSMDH(const cf7::command::ArgumentList &data) { smdh.SetAuthor(a); std::vector img; int w, h, c; - PD::u8 *buf = stbi_load(i.c_str(), &w, &h, &c, 4); + ctrff::u8 *buf = stbi_load(i.c_str(), &w, &h, &c, 4); if (buf == nullptr) { cf7::PrintFancy({ std::make_pair("Error", cf7::col(190, 0, 0)), diff --git a/tool/test.cpp b/tool/test.cpp index 221fe43..92ef7b1 100644 --- a/tool/test.cpp +++ b/tool/test.cpp @@ -16,20 +16,20 @@ void Result(const std::string& name, T a, T b) { void BinTest(bool be) { std::fstream s("test.bin", std::ios::out | std::ios::binary); - PD::u8 t8 = 0xdf; - PD::u16 t16 = 0x4564; - PD::u32 t32 = 0x58464743; - PD::u64 t64 = 1234567890123456789ULL; + ctrff::u8 t8 = 0xdf; + ctrff::u16 t16 = 0x4564; + ctrff::u32 t32 = 0x58464743; + ctrff::u64 t64 = 1234567890123456789ULL; ctrff::BinUtil u(s, be); u.Write(t8); u.Write(t16); u.Write(t32); u.Write(t64); s.close(); - PD::u8 r8 = 0; - PD::u16 r16 = 0; - PD::u32 r32 = 0; - PD::u64 r64 = 0; + ctrff::u8 r8 = 0; + ctrff::u16 r16 = 0; + ctrff::u32 r32 = 0; + ctrff::u64 r64 = 0; s.open("test.bin", std::ios::in | std::ios::binary); u.Read(r8); u.Read(r16);