Skip to content

Commit

Permalink
compatible with yaz0 with alignment property
Browse files Browse the repository at this point in the history
  • Loading branch information
dnasdw committed Dec 4, 2016
1 parent 2e4e6da commit e49c3cc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 24 additions & 2 deletions src/3dstool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/3dstool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/yaz0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -126,7 +126,8 @@ bool CYaz0::Compress(const u8* a_pUncompressed, u32 a_uUncompressedSize, u8* a_p
}
*reinterpret_cast<u32*>(a_pCompressed) = CONVERT_ENDIAN('Yaz0');
*reinterpret_cast<u32*>(a_pCompressed + 4) = CONVERT_ENDIAN(a_uUncompressedSize);
*reinterpret_cast<u64*>(a_pCompressed + 8) = 0;
*reinterpret_cast<u32*>(a_pCompressed + 8) = CONVERT_ENDIAN(a_nYaz0Align);
*reinterpret_cast<u32*>(a_pCompressed + 12) = 0;
SCompressInfo info;
initTable(&info, pWork);
const int nMaxSize = 0xFF + 0xF + 3;
Expand Down
2 changes: 1 addition & 1 deletion src/yaz0.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit e49c3cc

Please sign in to comment.