From e49c3cc04b757143f0abc3e407f0ef09aeadc38e Mon Sep 17 00:00:00 2001 From: Sun Daowen Date: Sun, 4 Dec 2016 15:24:09 +0800 Subject: [PATCH] compatible with yaz0 with alignment property --- CMakeLists.txt | 2 +- README.md | 1 + src/3dstool.cpp | 26 ++++++++++++++++++++++++-- src/3dstool.h | 1 + src/yaz0.cpp | 5 +++-- src/yaz0.h | 2 +- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b492dd0a..35d3f6cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ if(MSVC14) endif() set(_3DSTOOL_MAJOR 1) set(_3DSTOOL_MINOR 0) -set(_3DSTOOL_PATCHLEVEL 17) +set(_3DSTOOL_PATCHLEVEL 18) if(UNIX) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) endif() diff --git a/README.md b/README.md index 16e16fb5..9046a1e1 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ An all-in-one tool for extracting/creating 3ds roms. - v1.0.15 @ 2016.05.23 - Support auto encryption with ext key - v1.0.16 @ 2016.11.01 - Support huffman, runlength, yaz0 compression, romfs remap ignore and VS2008SP1 - v1.0.17 @ 2016.11.06 - Fix romfs hash bug +- v1.0.18 @ 2016.12.04 - Compatible with yaz0 with alignment property ## Platforms diff --git a/src/3dstool.cpp b/src/3dstool.cpp index 4ce3233f..522d3aa6 100644 --- a/src/3dstool.cpp +++ b/src/3dstool.cpp @@ -38,10 +38,12 @@ C3dsTool::SOption C3dsTool::s_Option[] = { "counter", 0, "the hex string of the counter used by the AES-CTR encryption" }, { "xor", 0, "the xor data file used by the xor encryption" }, { nullptr, 0, " compress:" }, - { "compress-align", 0, "[1|4|8|16|32]\n\t\tthe alignment of the compressed filesize" }, + { "compress-align", 0, "[1|4|8|16|32]\n\t\tthe alignment of the compressed filesize, optional" }, { nullptr, 0, " uncompress:" }, { "compress-type", 0, "[blz|lz(ex)|h4|h8|rl|yaz0]\n\t\tthe type of the compress" }, { "compress-out", 0, "the output file of uncompressed or compressed" }, + { nullptr, 0, " yaz0:" }, + { "yaz0-align", 0, "[0|128]\n\t\tthe alignment property of the yaz0 compressed file, optional" }, { nullptr, 0, " diff:" }, { "old", 0, "the old file" }, { "new", 0, "the new file" }, @@ -111,6 +113,7 @@ C3dsTool::C3dsTool() , m_nCompressAlign(1) , m_eCompressType(kCompressTypeNone) , m_pCompressOutFileName(nullptr) + , m_nYaz0Align(0) , m_pOldFileName(nullptr) , m_pNewFileName(nullptr) , m_pPatchFileName(nullptr) @@ -880,6 +883,21 @@ C3dsTool::EParseOptionReturn C3dsTool::parseOptions(const char* a_pName, int& a_ } m_pCompressOutFileName = a_pArgv[++a_nIndex]; } + else if (strcmp(a_pName, "yaz0-align") == 0) + { + if (a_nIndex + 1 >= a_nArgc) + { + return kParseOptionReturnNoArgument; + } + char* pYaz0Align = a_pArgv[++a_nIndex]; + n32 nYaz0Align = FSToN32(pYaz0Align); + if (nYaz0Align != 0 && nYaz0Align != 128) + { + m_pMessage = pYaz0Align; + return kParseOptionReturnUnknownArgument; + } + m_nYaz0Align = nYaz0Align; + } else if (strcmp(a_pName, "old") == 0) { if (a_nIndex + 1 >= a_nArgc) @@ -1563,7 +1581,7 @@ bool C3dsTool::compressFile() bReuslt = CRunLength::Compress(pUncompressed, uUncompressedSize, pCompressed, uCompressedSize, m_nCompressAlign); break; case kCompressTypeYaz0: - bReuslt = CYaz0::Compress(pUncompressed, uUncompressedSize, pCompressed, uCompressedSize, m_nCompressAlign); + bReuslt = CYaz0::Compress(pUncompressed, uUncompressedSize, pCompressed, uCompressedSize, m_nCompressAlign, m_nYaz0Align); break; default: break; @@ -1698,6 +1716,8 @@ int C3dsTool::sample() printf("3dstool -uvf input.lz --compress-type lz --compress-out output.bin\n\n"); printf("# compress file with LZ77, standalone\n"); printf("3dstool -zvf input.bin --compress-type lz --compress-out output.lz\n\n"); + printf("# compress file with LZ77 and align to 4 bytes, standalone\n"); + printf("3dstool -zvf input.bin --compress-type lz --compress-out output.lz --compress-align 4\n\n"); printf("# uncompress file with LZ77Ex, standalone\n"); printf("3dstool -uvf logo.bcma.lz --compress-type lzex --compress-out logo.bcma\n\n"); printf("# compress file with LZ77Ex, standalone\n"); @@ -1718,6 +1738,8 @@ int C3dsTool::sample() printf("3dstool -uvf input.szs --compress-type yaz0 --compress-out output.sarc\n\n"); printf("# compress file with Yaz0, standalone\n"); printf("3dstool -zvf input.sarc --compress-type yaz0 --compress-out output.szs\n\n"); + printf("# compress file with Yaz0 and set the alignment property, standalone\n"); + printf("3dstool -zvf input.sarc --compress-type yaz0 --compress-out output.szs --yaz0-align 128\n\n"); printf("# trim cci without pad\n"); printf("3dstool --trim -vtf cci input.3ds\n\n"); printf("# trim cci reserve partition 0~2\n"); diff --git a/src/3dstool.h b/src/3dstool.h index 21c1d700..fca36281 100644 --- a/src/3dstool.h +++ b/src/3dstool.h @@ -89,6 +89,7 @@ class C3dsTool n32 m_nCompressAlign; ECompressType m_eCompressType; const char* m_pCompressOutFileName; + n32 m_nYaz0Align; const char* m_pOldFileName; const char* m_pNewFileName; const char* m_pPatchFileName; diff --git a/src/yaz0.cpp b/src/yaz0.cpp index 3b15b9b0..8f12d0b8 100644 --- a/src/yaz0.cpp +++ b/src/yaz0.cpp @@ -113,7 +113,7 @@ bool CYaz0::Uncompress(const u8* a_pCompressed, u32 a_uCompressedSize, u8* a_pUn return bResult; } -bool CYaz0::Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_pCompressed, u32& a_uCompressedSize, n32 a_nCompressAlign) +bool CYaz0::Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_pCompressed, u32& a_uCompressedSize, n32 a_nCompressAlign, n32 a_nYaz0Align) { bool bResult = true; u8* pWork = new u8[s_nCompressWorkSize]; @@ -126,7 +126,8 @@ bool CYaz0::Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_p } *reinterpret_cast(a_pCompressed) = CONVERT_ENDIAN('Yaz0'); *reinterpret_cast(a_pCompressed + 4) = CONVERT_ENDIAN(a_uUncompressedSize); - *reinterpret_cast(a_pCompressed + 8) = 0; + *reinterpret_cast(a_pCompressed + 8) = CONVERT_ENDIAN(a_nYaz0Align); + *reinterpret_cast(a_pCompressed + 12) = 0; SCompressInfo info; initTable(&info, pWork); const int nMaxSize = 0xFF + 0xF + 3; diff --git a/src/yaz0.h b/src/yaz0.h index 68e624d1..5e73d4f8 100644 --- a/src/yaz0.h +++ b/src/yaz0.h @@ -9,7 +9,7 @@ class CYaz0 static bool GetUncompressedSize(const u8* a_pCompressed, u32 a_uCompressedSize, u32& a_uUncompressedSize); static u32 GetCompressBoundSize(u32 a_uUncompressedSize, n32 a_nCompressAlign); static bool Uncompress(const u8* a_pCompressed, u32 a_uCompressedSize, u8* a_pUncompressed, u32& a_uUncompressedSize); - static bool Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_pCompressed, u32& a_uCompressedSize, n32 a_nCompressAlign); + static bool Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_pCompressed, u32& a_uCompressedSize, n32 a_nCompressAlign, n32 a_nYaz0Align); private: struct SCompressInfo {