diff --git a/resources/wiiflow_game_booter/source/ChannelHandler.cpp b/resources/wiiflow_game_booter/source/ChannelHandler.cpp index 33a1a754..dc2d4b71 100644 --- a/resources/wiiflow_game_booter/source/ChannelHandler.cpp +++ b/resources/wiiflow_game_booter/source/ChannelHandler.cpp @@ -72,7 +72,7 @@ static u8 *GetDol(u32 bootcontent, u64 title) } free(data); data = decompressed; - } + } return data; } return NULL; diff --git a/resources/wiiflow_game_booter/source/disc.c b/resources/wiiflow_game_booter/source/disc.c index 716aeadc..ffcb8785 100644 --- a/resources/wiiflow_game_booter/source/disc.c +++ b/resources/wiiflow_game_booter/source/disc.c @@ -72,6 +72,22 @@ void Disc_SetLowMem(u32 IOS) DCFlushRange((void*)0x80000000, 0x3f00); } +/* Thanks to triiforce for that code */ +void Disc_SetLowMemChan() +{ + /* Setup low mem */ + *Arena_H = 0x00000000; // Arena High, the appldr does this too + *BI2 = 0x817FE000; // BI2, the appldr does this too + *GameID_Address = 0x81000000; // Game id address, 0s at 0x81000000 with appldr + + /* Flush low mem */ + DCFlushRange((void*)0x80000000, 0x3f00); + + /* Clear BI2 */ + memset((void *)0x817FE000, 0, 0x2000); + DCFlushRange((void*)0x817FE000, 0x2000); +} + /* Thanks Tinyload */ static struct { u32 offset; diff --git a/resources/wiiflow_game_booter/source/disc.h b/resources/wiiflow_game_booter/source/disc.h index b6771ce7..5983dd65 100644 --- a/resources/wiiflow_game_booter/source/disc.h +++ b/resources/wiiflow_game_booter/source/disc.h @@ -11,6 +11,7 @@ s32 Disc_FindPartition(u32 *outbuf); s32 Disc_SetUSB(const u8 *id, bool frag); void Disc_SetLowMemPre(); void Disc_SetLowMem(u32 IOS); +void Disc_SetLowMemChan(); void Disc_SetTime(); GXRModeObj *Disc_SelectVMode(u8 videoselected, u32 *rmode_reg); diff --git a/resources/wiiflow_game_booter/source/lz77.c b/resources/wiiflow_game_booter/source/lz77.c index f44230c3..a31c09a2 100644 --- a/resources/wiiflow_game_booter/source/lz77.c +++ b/resources/wiiflow_game_booter/source/lz77.c @@ -1,215 +1,177 @@ -/******************************************************************************* - * lz77.c - * - * Copyright (c) 2009 The Lemon Man - * Copyright (c) 2009 Nicksasa - * Copyright (c) 2009 WiiPower - * - * Distributed under the terms of the GNU General Public License (v2) - * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. - * - * Description: - * ----------- - * - ******************************************************************************/ -#include -#include -#include -#include -#include - -#include "lz77.h" -#include "utils.h" - -u32 packBytes(int a, int b, int c, int d) -{ - return (d << 24) | (c << 16) | (b << 8) | (a); -} - -s32 __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen) -{ - int x, y; - - u8 *out = NULL; - - u32 compressedPos = 0x4; - u32 decompressedPos = 0x0; - u32 decompressedSize = 0; - - decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8; - - if (!decompressedSize) - { - decompressedSize = packBytes(in[4], in[5], in[6], in[7]); - compressedPos += 0x4; - } - - //printf("Decompressed size : %i\n", decompressedSize); - - out = malloc(ALIGN32(decompressedSize)); - if (out == NULL) - { - printf("Out of memory\n"); - return -1; - } - - while (compressedPos < inputLen && decompressedPos < decompressedSize) - { - u8 byteFlag = in[compressedPos]; - compressedPos++; - - for (x = 7; x >= 0; x--) - { - if ((byteFlag & (1 << x)) > 0) - { - u8 first = in[compressedPos]; - u8 second = in[compressedPos + 1]; - - u32 pos, copyLen; - - if (first < 0x20) - { - u8 third = in[compressedPos + 2]; - - if (first >= 0x10) - { - u32 fourth = in[compressedPos + 3]; - - pos = (u32)(((third & 0xF) << 8) | fourth) + 1; - copyLen = (u32)((second << 4) | ((first & 0xF) << 12) | (third >> 4)) + 273; - - compressedPos += 4; - } else - { - pos = (u32)(((second & 0xF) << 8) | third) + 1; - copyLen = (u32)(((first & 0xF) << 4) | (second >> 4)) + 17; - - compressedPos += 3; - } - } else - { - pos = (u32)(((first & 0xF) << 8) | second) + 1; - copyLen = (u32)(first >> 4) + 1; - - compressedPos += 2; - } - - for (y = 0; y < (int)copyLen; y++) - { - out[decompressedPos + y] = out[decompressedPos - pos + y]; - } - - decompressedPos += copyLen; - } else - { - out[decompressedPos] = in[compressedPos]; - - decompressedPos++; - compressedPos++; - } - - if (compressedPos >= inputLen || decompressedPos >= decompressedSize) - break; - } - } - *output = out; - *outputLen = decompressedSize; - return 0; -} - -s32 __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen) -{ - int x, y; - - u8 *out = NULL; - - u32 compressedPos = 0; - u32 decompressedSize = 0x4; - u32 decompressedPos = 0; - - decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8; - - //int compressionType = (packBytes(in[0], in[1], in[2], in[3]) >> 4) & 0xF; - - //printf("Decompressed size : %i\n", decompressedSize); - - out = malloc(ALIGN32(decompressedSize)); - if (out == NULL) - { - printf("Out of memory\n"); - return -1; - } - - compressedPos += 0x4; - - while (decompressedPos < decompressedSize) - { - u8 flag = *(u8*)(in + compressedPos); - compressedPos += 1; - - for (x = 0; x < 8; x++) - { - if (flag & 0x80) - { - u8 first = in[compressedPos]; - u8 second = in[compressedPos + 1]; - - u16 pos = (u16)((((first << 8) + second) & 0xFFF) + 1); - u8 copyLen = (u8)(3 + ((first >> 4) & 0xF)); - - for (y = 0; y < copyLen; y++) - { - out[decompressedPos + y] = out[decompressedPos - pos + (y % pos)]; - } - - compressedPos += 2; - decompressedPos += copyLen; - } else - { - out[decompressedPos] = in[compressedPos]; - compressedPos += 1; - decompressedPos += 1; - } - - flag <<= 1; - - if (decompressedPos >= decompressedSize) - break; - } - } - - *output = out; - *outputLen = decompressedSize; - return 0; -} - -int isLZ77compressed(u8 *buffer) -{ - if ((buffer[0] == LZ77_0x10_FLAG) || (buffer[0] == LZ77_0x11_FLAG)) - { - return 1; - } - - return 0; -} - -int decompressLZ77content(u8 *buffer, u32 length, u8 **output, u32 *outputLen) -{ - int ret; - switch (buffer[0]) - { - case LZ77_0x10_FLAG: - //printf("LZ77 variant 0x10 compressed content...unpacking may take a while...\n"); - ret = __decompressLZ77_10(buffer, output, outputLen); - break; - case LZ77_0x11_FLAG: - //printf("LZ77 variant 0x11 compressed content...unpacking may take a while...\n"); - ret = __decompressLZ77_11(buffer, length, output, outputLen); - break; - default: - //printf("Not compressed ...\n"); - ret = -1; - break; - } - return ret; -} +/******************************************************************************* + * lz77.c + * + * Copyright (c) 2009 The Lemon Man + * Copyright (c) 2009 Nicksasa + * Copyright (c) 2009 WiiPower + * + * Distributed under the terms of the GNU General Public License (v2) + * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. + * + * Description: + * ----------- + * + ******************************************************************************/ +#include +#include +#include +#include "lz77.h" + +static inline u32 packBytes(int a, int b, int c, int d) +{ + return (d << 24) | (c << 16) | (b << 8) | (a); +} + +static int __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen) +{ + int x = 0; + u32 y = 0; + u32 compressedPos = 0x4; + u32 decompressedPos = 0; + u32 decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8; + if(decompressedSize == 0) + { + decompressedSize = packBytes(in[4], in[5], in[6], in[7]); + compressedPos += 0x4; + } + //printf("Decompressed size : %i\n", decompressedSize); + + u8 *out = (u8*)malloc(decompressedSize); + if(out == NULL) + { + //printf("Out of memory\n"); + return -1; + } + + while(compressedPos < inputLen && decompressedPos < decompressedSize) + { + u8 byteFlag = in[compressedPos]; + compressedPos++; + + for(x = 7; x >= 0; x--) + { + if((byteFlag & (1 << x)) > 0) + { + u8 first = in[compressedPos]; + u8 second = in[compressedPos + 1]; + + u32 pos, copyLen; + if(first < 0x20) + { + u8 third = in[compressedPos + 2]; + if(first >= 0x10) + { + u32 fourth = in[compressedPos + 3]; + pos = (u32)(((third & 0xF) << 8) | fourth) + 1; + copyLen = (u32)((second << 4) | ((first & 0xF) << 12) | (third >> 4)) + 273; + compressedPos += 4; + } + else + { + pos = (u32)(((second & 0xF) << 8) | third) + 1; + copyLen = (u32)(((first & 0xF) << 4) | (second >> 4)) + 17; + compressedPos += 3; + } + } + else + { + pos = (u32)(((first & 0xF) << 8) | second) + 1; + copyLen = (u32)(first >> 4) + 1; + compressedPos += 2; + } + for(y = 0; y < copyLen; y++) + out[decompressedPos + y] = out[decompressedPos - pos + y]; + decompressedPos += copyLen; + } + else + { + out[decompressedPos] = in[compressedPos]; + decompressedPos++; + compressedPos++; + } + if(compressedPos >= inputLen || decompressedPos >= decompressedSize) + break; + } + } + *output = out; + *outputLen = decompressedSize; + return 0; +} + +static int __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen) +{ + int x = 0; + u32 y = 0; + u32 compressedPos = 0x4; + u32 decompressedPos = 0; + u32 decompressedSize = packBytes(in[0], in[1], in[2], in[3]) >> 8; + //printf("Decompressed size : %i\n", decompressedSize); + + u8 *out = (u8*)malloc(decompressedSize); + if(out == NULL) + { + //printf("Out of memory\n"); + return -1; + } + + while(decompressedPos < decompressedSize) + { + u8 byteFlag = in[compressedPos]; + compressedPos ++; + + for(x = 0; x < 8; ++x) + { + if(byteFlag & 0x80) + { + u8 first = in[compressedPos]; + u8 second = in[compressedPos + 1]; + u16 pos = (u16)((((first << 8) + second) & 0xFFF) + 1); + u8 copyLen = (u8)(3 + ((first >> 4) & 0xF)); + for(y = 0; y < copyLen; y++) + out[decompressedPos + y] = out[decompressedPos - pos + (y % pos)]; + compressedPos += 2; + decompressedPos += copyLen; + } + else + { + out[decompressedPos] = in[compressedPos]; + compressedPos += 1; + decompressedPos += 1; + } + byteFlag <<= 1; + if(decompressedPos >= decompressedSize) + break; + } + } + *output = out; + *outputLen = decompressedSize; + return 0; +} + +int isLZ77compressed(u8 *buffer) +{ + if((buffer[0] == LZ77_0x10_FLAG) || (buffer[0] == LZ77_0x11_FLAG)) + return 1; + return 0; +} + +int decompressLZ77content(u8 *buffer, u32 length, u8 **output, u32 *outputLen) +{ + int ret = 0; + switch(buffer[0]) + { + case LZ77_0x10_FLAG: + //printf("LZ77 variant 0x10 compressed content...unpacking may take a while...\n"); + ret = __decompressLZ77_10(buffer, output, outputLen); + break; + case LZ77_0x11_FLAG: + //printf("LZ77 variant 0x11 compressed content...unpacking may take a while...\n"); + ret = __decompressLZ77_11(buffer, length, output, outputLen); + break; + default: + //printf("Not compressed ...\n"); + ret = -1; + break; + } + return ret; +} diff --git a/resources/wiiflow_game_booter/source/lz77.h b/resources/wiiflow_game_booter/source/lz77.h index ebaf0b5e..ac5c5048 100644 --- a/resources/wiiflow_game_booter/source/lz77.h +++ b/resources/wiiflow_game_booter/source/lz77.h @@ -1,34 +1,34 @@ -/******************************************************************************* - * lz77.h - * - * Copyright (c) 2009 The Lemon Man - * Copyright (c) 2009 Nicksasa - * Copyright (c) 2009 WiiPower - * - * Distributed under the terms of the GNU General Public License (v2) - * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. - * - * Description: - * ----------- - * - ******************************************************************************/ - -#ifndef _LZ77_MODULE -#define _LZ77_MODULE - -#define LZ77_0x10_FLAG 0x10 -#define LZ77_0x11_FLAG 0x11 - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int isLZ77compressed(u8 *buffer); -int decompressLZ77content(u8 *buffer, u32 length, u8 **output, u32 *outputLen); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif - +/******************************************************************************* + * lz77.h + * + * Copyright (c) 2009 The Lemon Man + * Copyright (c) 2009 Nicksasa + * Copyright (c) 2009 WiiPower + * + * Distributed under the terms of the GNU General Public License (v2) + * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. + * + * Description: + * ----------- + * + ******************************************************************************/ + +#ifndef _LZ77_MODULE +#define _LZ77_MODULE + +#define LZ77_0x10_FLAG 0x10 +#define LZ77_0x11_FLAG 0x11 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int isLZ77compressed(u8 *buffer); +int decompressLZ77content(u8 *buffer, u32 length, u8 **output, u32 *outputLen); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif + diff --git a/resources/wiiflow_game_booter/source/main.cpp b/resources/wiiflow_game_booter/source/main.cpp index f80c2f3d..5e295391 100644 --- a/resources/wiiflow_game_booter/source/main.cpp +++ b/resources/wiiflow_game_booter/source/main.cpp @@ -121,6 +121,8 @@ int main() /* Setup Low Memory */ Disc_SetLowMem(GameIOS); + if(normalCFG.BootType == TYPE_CHANNEL && AppEntrypoint != 0x3400) + Disc_SetLowMemChan(); /* Real DOL without appldr */ /* Set time */ Disc_SetTime(); @@ -136,10 +138,10 @@ int main() /* Originally from tueidj - taken from NeoGamma (thx) */ *(vu32*)0xCC003024 = 1; - if(AppEntrypoint == 0x3400) + if(AppEntrypoint == 0x3400) { - if(hooktype) - { + if(hooktype) + { asm volatile ( "lis %r3, returnpoint@h\n" "ori %r3, %r3, returnpoint@l\n" @@ -160,24 +162,24 @@ int main() "mtsrr0 %r4\n" "rfi\n" ); - } - else - { - asm volatile ( - "isync\n" + } + else + { + asm volatile ( + "isync\n" "lis %r3, AppEntrypoint@h\n" "ori %r3, %r3, AppEntrypoint@l\n" - "lwz %r3, 0(%r3)\n" - "mtsrr0 %r3\n" - "mfmsr %r3\n" - "li %r4, 0x30\n" - "andc %r3, %r3, %r4\n" - "mtsrr1 %r3\n" - "rfi\n" - ); - } + "lwz %r3, 0(%r3)\n" + "mtsrr0 %r3\n" + "mfmsr %r3\n" + "li %r4, 0x30\n" + "andc %r3, %r3, %r4\n" + "mtsrr1 %r3\n" + "rfi\n" + ); + } } - else if(hooktype) + else if(hooktype) { asm volatile ( "lis %r3, AppEntrypoint@h\n"