From 2300f6d872f6473423a488f340fd9245321634b9 Mon Sep 17 00:00:00 2001 From: dimok789 <15055714+dimok789@users.noreply.github.com> Date: Sun, 15 Jul 2012 05:43:23 +0000 Subject: [PATCH] - added support for Yaz0 decompression on banners and system menu resources (This is needed by some Custom Wii System Menu Themes like the DarkWii Theme. Hopefully now all System Menu Themes are supported as layout.) (thx darkwii and atymick for the info about the used Yaz0 compression in those themes.) --- source/utils/U8Archive.cpp | 19 ++++++++++++++++++- source/utils/uncompress.c | 5 ++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/source/utils/U8Archive.cpp b/source/utils/U8Archive.cpp index 55e56f50..acfe9b22 100644 --- a/source/utils/U8Archive.cpp +++ b/source/utils/U8Archive.cpp @@ -23,6 +23,7 @@ #include "lz77.h" #include "gecko.h" #include "U8Archive.h" +#include "uncompress.h" #define RU(N, S) ((((N) + (S) - 1) / (S)) * (S)) @@ -160,6 +161,22 @@ u8 *U8Archive::DecompressCopy( const u8 * stuff, u32 len, u32 *size ) const return NULL; } } + else if( (len > 8) && *(u32*)( stuff ) == 0x59617a30 )// Yaz0 + { + // Yaz0 with a magic word + Yaz0_Header *header = (Yaz0_Header *) stuff; + // set decompress length + len = header->decompressed_size; + // allocate memory + ret = (u8*) memalign(32, ALIGN32(len)); + if(!ret) + { + gprintf("out of memory\n"); + return NULL; + } + // function can not fail at this point + uncompressYaz0(stuff, ret, len); + } else if( isLZ77compressed( stuff ) ) { // LZ77 with no magic word @@ -179,7 +196,7 @@ u8 *U8Archive::DecompressCopy( const u8 * stuff, u32 len, u32 *size ) const else { // just copy the data out of the archive - ret = (u8*)memalign( 32, len ); + ret = (u8*)memalign( 32, ALIGN32( len ) ); if( !ret ) { gprintf( "out of memory\n" ); diff --git a/source/utils/uncompress.c b/source/utils/uncompress.c index 02fea5fe..154a08cc 100644 --- a/source/utils/uncompress.c +++ b/source/utils/uncompress.c @@ -49,9 +49,12 @@ u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size) //the second 4 bytes in the Yaz0 header). void uncompressYaz0(const u8* srcBuf, u8* dst, int uncompressedSize) { + if(!srcBuf || !dst) + return; + const u8 * src = srcBuf; - if(memcmp(src, "Yaz0", 4) == 0) + if(*((u32*)src) == 'Yaz0') { src += sizeof(Yaz0_Header); }