diff options
| author | TakaRikka <38417346+TakaRikka@users.noreply.github.com> | 2025-12-16 06:55:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-16 16:55:07 +0200 |
| commit | 8185d87f855baff0d55d0e3ffc1a3cbdcfc4b5e2 (patch) | |
| tree | 2a3c01f1a2a8b81de5a0748a5bcb187a97e7a114 /src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp | |
| parent | c8104b6d62cc424318c7e0c44c92d94234bfef15 (diff) | |
copy homebuttonLib from oot-vc (#2960)
* initial copy of hbm from sdk_2009-12-11
* some more nw4hbm cleanup
* nw4hbm db mostly done
* nw4hbm snd copied from oot-vc
* nw4hbm ut copied
* nw4hbm lyt copied
* nw4hbm copied, mostly matching usa 1.0
* setup nw4hbm debug define
* fix HBMDataInfo struct
* add rvl sdk card lib
Diffstat (limited to 'src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp')
| -rw-r--r-- | src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp b/src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp new file mode 100644 index 0000000000..4bc3a7b181 --- /dev/null +++ b/src/revolution/homebuttonLib/nw4hbm/ut/ut_binaryFileFormat.cpp @@ -0,0 +1,63 @@ +#include "binaryFileFormat.h" + +#include "../db/assert.h" + +namespace nw4hbm { + namespace ut { + + bool IsValidBinaryFile(const BinaryFileHeader* header, u32 signature, u16 version, + u16 minBlocks) { + NW4HBM_ASSERT_VALID_PTR(48, header); + + if (header->signature != signature) { + s8 signature1 = (header->signature >> 24) & 0xFF; + s8 signature2 = (header->signature >> 16) & 0xFF; + s8 signature3 = (header->signature >> 8) & 0xFF; + s8 signature4 = (header->signature & 0xFF); + + s8 signature5 = (signature >> 24) & 0xFF; + s8 signature6 = (signature >> 16) & 0xFF; + s8 signature7 = (signature >> 8) & 0xFF; + s8 signature8 = (signature & 0xFF); + + NW4R_DB_WARNING(60, false, + "Signature check failed ('%c%c%c%c' must be '%c%c%c%c').", + signature1, signature2, signature3, signature4, signature5, + signature6, signature7, signature8); + return false; + } + + // U+FEFF * BYTE ORDER MARK + if (header->byteOrder != 0xFEFF) { + NW4R_DB_WARNING(65, false, "Unsupported byte order."); + return false; + } + + if (header->version != version) { + NW4R_DB_WARNING(75, false, "Version check faild ('%d.%d' must be '%d.%d').", + (header->version >> 8) & 0xFF, header->version & 0xFF, + (version >> 8) & 0xFF, version & 0xFF); + return false; + } + + if (header->fileSize < sizeof(*header) + sizeof(BinaryBlockHeader) * minBlocks) { + NW4R_DB_WARNING(80, false, "Too small file size(=%d).", header->fileSize); + return false; + } + + if (header->dataBlocks < minBlocks) { + NW4R_DB_WARNING(85, false, "Too small number of data blocks(=%d).", + header->dataBlocks); + return false; + } + + return true; + } + + // required to match .data + void dummy(const BinaryFileHeader* fileHeader) { + NW4HBM_ASSERT_VALID_PTR(0, fileHeader); + } + + } // namespace ut +} // namespace nw4hbm |
