-changed the memory management yet again, now just use the mem

which has enough space left instead of fixed memory in most parts
-fixed alot of things about banner playing, now shouldnt randomly
codedump anymore or things like this, also some banner sounds
which did not play before should work fine now
-removed unused code and added better debug prints
-using some fixed voice for game banner and not always a new one
per banner
-fixed DIOS-MIOS cheats for sure now :P
-fixed possible memory allocation bug in wbfs alloc (thanks to
cfg-loader)
-removed MEM2_memalign since it did not work correctly
-fixed a few wrong memset sizes
This commit is contained in:
fix94.1 2012-07-27 17:26:49 +00:00
parent e55ab171c6
commit 88955e9461
51 changed files with 533 additions and 591 deletions

View File

@ -43,14 +43,14 @@ void AnimatedBanner::LoadFont(u8 *font1, u8 *font2)
void AnimatedBanner::Clear() void AnimatedBanner::Clear()
{ {
if(layout_banner) if(layout_banner != NULL)
{ {
delete layout_banner; delete layout_banner;
layout_banner = NULL; layout_banner = NULL;
} }
if(newBanner) if(newBanner != NULL)
{ {
delete newBanner; free(newBanner);
newBanner = NULL; newBanner = NULL;
} }
} }
@ -58,13 +58,15 @@ void AnimatedBanner::Clear()
bool AnimatedBanner::LoadBanner(Banner *banner) bool AnimatedBanner::LoadBanner(Banner *banner)
{ {
u32 banner_bin_size; u32 banner_bin_size;
const u8 *banner_bin = banner->GetFile((char*)"banner.bin", &banner_bin_size); u8 *banner_bin = banner->GetFile((char*)"banner.bin", &banner_bin_size);
if(banner_bin == NULL) if(banner_bin == NULL)
return false; return false;
return LoadBannerBin(banner_bin, banner_bin_size); bool ret = LoadBannerBin(banner_bin, banner_bin_size);
free(banner_bin);
return ret;
} }
bool AnimatedBanner::LoadBannerBin(const u8 *banner_bin, u32 banner_bin_size) bool AnimatedBanner::LoadBannerBin(u8 *banner_bin, u32 banner_bin_size)
{ {
Clear(); Clear();
layout_banner = LoadLayout(banner_bin, banner_bin_size, "banner", CONF_GetLanguageString()); layout_banner = LoadLayout(banner_bin, banner_bin_size, "banner", CONF_GetLanguageString());
@ -101,10 +103,12 @@ void AnimatedBanner::SetBannerTexture(const char *tex_name, const u8 *data, floa
} }
} }
Layout* AnimatedBanner::LoadLayout(const u8 *bnr, u32 bnr_size, const std::string& lyt_name, const std::string &language) Layout* AnimatedBanner::LoadLayout(u8 *bnr, u32 bnr_size, const std::string& lyt_name, const std::string &language)
{ {
u32 brlyt_size = 0; u32 brlyt_size = 0;
newBanner = DecompressCopy(bnr, bnr_size, &bnr_size); newBanner = DecompressCopy(bnr, bnr_size, &bnr_size);
if(newBanner == NULL)
return NULL;
const u8 *brlyt = u8_get_file(newBanner, (char*)fmt("%s.brlyt", lyt_name.c_str()), &brlyt_size); const u8 *brlyt = u8_get_file(newBanner, (char*)fmt("%s.brlyt", lyt_name.c_str()), &brlyt_size);
if(!brlyt) if(!brlyt)
@ -147,43 +151,39 @@ Layout* AnimatedBanner::LoadLayout(const u8 *bnr, u32 bnr_size, const std::strin
return layout; return layout;
} }
u8 *AnimatedBanner::DecompressCopy( const u8 * stuff, u32 len, u32 *size ) u8 *DecompressCopy(u8 *stuff, u32 len, u32 *size)
{ {
// check for IMD5 header and skip it // check for IMD5 header and skip it
if( len > 0x40 && *(u32*)stuff == 0x494d4435 )// IMD5 if(len > 0x40 && *(u32*)stuff == 0x494d4435) // IMD5
{ {
stuff += 0x20; stuff += 0x20;
len -= 0x20; len -= 0x20;
} }
u8* ret = NULL; u8 *ret = NULL;
// determine if it needs to be decompressed // determine if it needs to be decompressed
if( IsAshCompressed( stuff, len ) ) if(IsAshCompressed(stuff, len))
{ {
//u32 len2 = len; //u32 len2 = len;
// ASH0 // ASH0
ret = DecompressAsh( stuff, len ); ret = DecompressAsh(stuff, len);
if( !ret ) if(!ret)
{ {
gprintf( "out of memory\n" ); gprintf("out of memory\n");
return NULL; return NULL;
} }
} }
else if( isLZ77compressed( (u8*)stuff ) ) else if(isLZ77compressed(stuff))
{ {
// LZ77 with no magic word // LZ77 with no magic word
if( decompressLZ77content( (u8*)stuff, len, &ret, &len ) ) if(decompressLZ77content(stuff, len, &ret, &len))
{
return NULL; return NULL;
}
} }
else if( *(u32*)( stuff ) == 0x4C5A3737 )// LZ77 else if(*(u32*)(stuff) == 0x4C5A3737) // LZ77
{ {
// LZ77 with a magic word // LZ77 with a magic word
if( decompressLZ77content( (u8*)stuff + 4, len - 4, &ret, &len ) ) if(decompressLZ77content(stuff + 4, len - 4, &ret, &len ))
{
return NULL; return NULL;
}
} }
else else
{ {
@ -196,12 +196,10 @@ u8 *AnimatedBanner::DecompressCopy( const u8 * stuff, u32 len, u32 *size )
} }
memcpy( ret, stuff, len ); memcpy( ret, stuff, len );
} }
if( size ) if(size)
{
*size = len; *size = len;
}
// flush the cache so if there are any textures in this data, it will be ready for the GX // flush the cache so if there are any textures in this data, it will be ready for the GX
DCFlushRange( ret, len ); DCFlushRange(ret, len);
return ret; return ret;
} }

View File

@ -37,18 +37,18 @@ public:
void Clear(); void Clear();
bool LoadBanner(Banner *banner); bool LoadBanner(Banner *banner);
bool LoadBannerBin(const u8 *banner_bin, u32 banner_bin_size); bool LoadBannerBin(u8 *banner_bin, u32 banner_bin_size);
Layout *getBanner() const { return layout_banner; } Layout *getBanner() const { return layout_banner; }
void SetBannerTexture(const char *tex_name, const u8 *data, float width, float height, u8 fmt); void SetBannerTexture(const char *tex_name, const u8 *data, float width, float height, u8 fmt);
void SetBannerText(const char *text_name, const wchar_t *wText); void SetBannerText(const char *text_name, const wchar_t *wText);
protected: protected:
Layout* LoadLayout(const u8 *bnr, u32 bnr_size, const std::string& lyt_name, const std::string &language); Layout* LoadLayout(u8 *bnr, u32 bnr_size, const std::string& lyt_name, const std::string &language);
u8 *DecompressCopy( const u8 * stuff, u32 len, u32 *size );
Layout *layout_banner; Layout *layout_banner;
u8 *newBanner; u8 *newBanner;
u8 *sysFont1; u8 *sysFont1;
u8 *sysFont2; u8 *sysFont2;
}; };
u8 *DecompressCopy(u8 *stuff, u32 len, u32 *size);
#endif #endif

View File

@ -566,7 +566,7 @@ unsigned char * MD5fromFile(unsigned char *dst, const char *src)
else else
blksize = 1048576; blksize = 1048576;
unsigned char * buffer = MEM2_alloc(blksize); unsigned char * buffer = malloc(blksize);
if(buffer == NULL) if(buffer == NULL)
{ {
//no memory //no memory
@ -581,7 +581,7 @@ unsigned char * MD5fromFile(unsigned char *dst, const char *src)
} while(read > 0); } while(read > 0);
fclose(file); fclose(file);
MEM2_free(buffer); free(buffer);
(void)auth_md5CloseCtx( ctx, dst ); /* Close the context. */ (void)auth_md5CloseCtx( ctx, dst ); /* Close the context. */

View File

@ -49,10 +49,11 @@ Banner::Banner(u8 *bnr, u32 bnr_size, u64 title, bool custom)
opening_size = bnr_size; opening_size = bnr_size;
imet = NULL; imet = NULL;
if (opening == NULL) return; if(opening == NULL)
return;
IMET *imet = (IMET *) opening; IMET *imet = (IMET *)opening;
if (imet->sig != IMET_SIGNATURE) if(imet->sig != IMET_SIGNATURE)
imet = (IMET *) (opening + IMET_OFFSET); imet = (IMET *) (opening + IMET_OFFSET);
if(imet->sig == IMET_SIGNATURE) if(imet->sig == IMET_SIGNATURE)
@ -125,21 +126,29 @@ bool Banner::GetName(wchar_t *name, int language)
if (imet == NULL) return false; if (imet == NULL) return false;
u16 *channelname = GetName(language); u16 *channelname = GetName(language);
if (channelname) if(channelname)
{ {
for (int i = 0; i < IMET_MAX_NAME_LEN; i++) for(int i = 0; i < IMET_MAX_NAME_LEN; i++)
{
name[i] = channelname[i]; name[i] = channelname[i];
}
return true; return true;
} }
return false; return false;
} }
const u8 *Banner::GetFile(char *name, u32 *size) u8 *Banner::GetFile(char *name, u32 *size)
{ {
const u8 *bnrArc = (const u8 *)(((u8 *) imet) + sizeof(IMET)); const u8 *bnrArc = (const u8 *)(((u8 *) imet) + sizeof(IMET));
return u8_get_file(bnrArc, name, size); const u8* curfile = u8_get_file(bnrArc, name, size);
if(curfile == NULL || *size == 0)
return NULL;
//I like to have stuff in a separate memory region
u8 *file = (u8*)malloc(*size);
if(file == NULL)
return NULL;
memcpy(file, curfile, (*size));
return file;
} }
Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly) Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
@ -152,7 +161,7 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
if (size == 0) if (size == 0)
{ {
if(buf != NULL) if(buf != NULL)
MEM2_free(buf); free(buf);
return NULL; return NULL;
} }
} }
@ -170,7 +179,7 @@ Banner * Banner::GetBanner(u64 title, char *appname, bool isfs, bool imetOnly)
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
} }
buf = MEM2_alloc(size); buf = malloc(size);
if(!buf) if(!buf)
return NULL; return NULL;

View File

@ -67,19 +67,18 @@ class Banner
bool GetName(u8 *name, int language); bool GetName(u8 *name, int language);
bool GetName(wchar_t *name, int language); bool GetName(wchar_t *name, int language);
const u8 *GetFile(char *name, u32 *size); u8 *GetFile(char *name, u32 *size);
static Banner *GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false); static Banner *GetBanner(u64 title, char *appname, bool isfs, bool imetOnly = false);
u8 *GetBannerFile() { return opening; } u8 *GetBannerFile() { return opening; }
u32 GetBannerFileSize() { return opening_size; } u32 GetBannerFileSize() { return opening_size; }
private: protected:
u8 *opening; u8 *opening;
u32 opening_size; u32 opening_size;
u64 title; u64 title;
IMET *imet; IMET *imet;
u16 *GetName(int language);
u16 *GetName(int language);
static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language); static bool GetChannelNameFromApp(u64 title, wchar_t* name, int language);
}; };

View File

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <malloc.h>
#include "disc.h" #include "disc.h"
#include "patchcode.h" #include "patchcode.h"
@ -12,7 +13,6 @@
#include "utils.h" #include "utils.h"
#include "fs.h" #include "fs.h"
#include "gecko.h" #include "gecko.h"
#include "mem2.hpp"
void __Disc_SetLowMem(void); void __Disc_SetLowMem(void);
void __Disc_SetTime(void); void __Disc_SetTime(void);
@ -199,8 +199,9 @@ void PatchChannel(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryStrin
bool Identify_GenerateTik(signed_blob **outbuf, u32 *outlen) bool Identify_GenerateTik(signed_blob **outbuf, u32 *outlen)
{ {
signed_blob *buffer = (signed_blob *)MEM2_alloc(STD_SIGNED_TIK_SIZE); signed_blob *buffer = (signed_blob *)memalign(32, ALIGN32(STD_SIGNED_TIK_SIZE));
if (!buffer) return false; if(!buffer)
return false;
memset(buffer, 0, STD_SIGNED_TIK_SIZE); memset(buffer, 0, STD_SIGNED_TIK_SIZE);
sig_rsa2048 *signature = (sig_rsa2048 *)buffer; sig_rsa2048 *signature = (sig_rsa2048 *)buffer;
@ -249,8 +250,8 @@ bool Identify(u64 titleid)
if (certBuffer == NULL || certSize == 0) if (certBuffer == NULL || certSize == 0)
{ {
gprintf("Failed!\n"); gprintf("Failed!\n");
MEM2_free(tmdBuffer); free(tmdBuffer);
MEM2_free(tikBuffer); free(tikBuffer);
return false; return false;
} }
gprintf("Success!\n"); gprintf("Success!\n");
@ -279,9 +280,9 @@ bool Identify(u64 titleid)
} }
} }
MEM2_free(tmdBuffer); free(tmdBuffer);
MEM2_free(tikBuffer); free(tikBuffer);
MEM2_free(certBuffer); free(certBuffer);
return ret < 0 ? false : true; return ret < 0 ? false : true;
} }
@ -305,10 +306,10 @@ u8 *GetDol(u64 title, u32 bootcontent)
if (decompressLZ77content(data, contentSize, &decompressed, &size) < 0) if (decompressLZ77content(data, contentSize, &decompressed, &size) < 0)
{ {
gprintf("Decompression failed\n"); gprintf("Decompression failed\n");
MEM2_free(data); free(data);
return NULL; return NULL;
} }
MEM2_free(data); free(data);
data = decompressed; data = decompressed;
} }
return data; return data;

View File

@ -106,7 +106,7 @@ u8 Channels::GetRequestedIOS(u64 title)
if(size > 0x18B) if(size > 0x18B)
IOS = titleTMD[0x18B]; IOS = titleTMD[0x18B];
MEM2_free(titleTMD); free(titleTMD);
gprintf("Requested Game IOS: %i\n", IOS); gprintf("Requested Game IOS: %i\n", IOS);
return IOS; return IOS;
} }
@ -122,7 +122,7 @@ u64* Channels::GetChannelList(u32* count)
if(ES_GetTitles(titles, countall) < 0) if(ES_GetTitles(titles, countall) < 0)
{ {
MEM2_free(titles); free(titles);
return NULL; return NULL;
} }
@ -143,7 +143,7 @@ u64* Channels::GetChannelList(u32* count)
channels[(*count)++] = titles[i]; channels[(*count)++] = titles[i];
} }
} }
MEM2_free(titles); free(titles);
return(u64*)MEM2_realloc(channels, *count * sizeof(u64)); return(u64*)MEM2_realloc(channels, *count * sizeof(u64));
} }
@ -173,7 +173,7 @@ bool Channels::GetAppNameFromTmd(u64 title, char *app, bool dol, u32 *bootconten
} }
} }
MEM2_free(data); free(data);
return ret; return ret;
} }
@ -250,7 +250,7 @@ void Channels::Search(u32 channelType, string lang)
} }
} }
MEM2_free(list); free(list);
} }
wchar_t * Channels::GetName(int index) wchar_t * Channels::GetName(int index)

View File

@ -12,14 +12,13 @@
* ----------- * -----------
* *
******************************************************************************/ ******************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include "lz77.h" #include "lz77.h"
#include "mem2.hpp"
#include "utils.h" #include "utils.h"
u32 packBytes(int a, int b, int c, int d) u32 packBytes(int a, int b, int c, int d)
@ -47,7 +46,7 @@ s32 __decompressLZ77_11(u8 *in, u32 inputLen, u8 **output, u32 *outputLen)
//printf("Decompressed size : %i\n", decompressedSize); //printf("Decompressed size : %i\n", decompressedSize);
out = MEM2_alloc(ALIGN32(decompressedSize)); out = malloc(ALIGN32(decompressedSize));
if (out == NULL) if (out == NULL)
{ {
printf("Out of memory\n"); printf("Out of memory\n");
@ -134,7 +133,7 @@ s32 __decompressLZ77_10(u8 *in, u8 **output, u32 *outputLen)
//printf("Decompressed size : %i\n", decompressedSize); //printf("Decompressed size : %i\n", decompressedSize);
out = MEM2_alloc(ALIGN32(decompressedSize)); out = malloc(ALIGN32(decompressedSize));
if (out == NULL) if (out == NULL)
{ {
printf("Out of memory\n"); printf("Out of memory\n");

View File

@ -33,9 +33,9 @@
#include <cstdlib> #include <cstdlib>
#include <stdarg.h> #include <stdarg.h>
#include <dirent.h> #include <dirent.h>
#include <malloc.h>
#include "nand.hpp" #include "nand.hpp"
#include "mem2.hpp"
#include "wbfs.h" #include "wbfs.h"
#include "gecko.h" #include "gecko.h"
#include "fileOps.h" #include "fileOps.h"
@ -248,7 +248,7 @@ void Nand::__GetNameList(const char *source, namelist **entries, int *count)
char entrypath[ISFS_MAXPATH]; char entrypath[ISFS_MAXPATH];
s32 ret = ISFS_ReadDir(source, NULL, &numentries); s32 ret = ISFS_ReadDir(source, NULL, &numentries);
names = (char *)MEM2_alloc((ISFS_MAXPATH) * numentries); names = (char *)memalign(32, ALIGN32((ISFS_MAXPATH) * numentries));
if(names == NULL) if(names == NULL)
return; return;
@ -257,19 +257,22 @@ void Nand::__GetNameList(const char *source, namelist **entries, int *count)
if(*entries != NULL) if(*entries != NULL)
{ {
MEM2_free(*entries); free(*entries);
*entries = NULL; *entries = NULL;
} }
*entries = (namelist *)MEM2_alloc(sizeof(namelist) * numentries); *entries = (namelist *)malloc(sizeof(namelist) * numentries);
if(*entries == NULL) if(*entries == NULL)
{
free(names);
return; return;
}
for(i = 0, k = 0; i < numentries; i++) for(i = 0, k = 0; i < numentries; i++)
{ {
for(j = 0; names[k] != 0; j++, k++) for(j = 0; names[k] != 0; j++, k++)
curentry[j] = names[k]; curentry[j] = names[k];
curentry[j] = 0; curentry[j] = 0;
k++; k++;
@ -279,17 +282,17 @@ void Nand::__GetNameList(const char *source, namelist **entries, int *count)
snprintf(entrypath, sizeof(entrypath), "%s%s", source, curentry); snprintf(entrypath, sizeof(entrypath), "%s%s", source, curentry);
else else
snprintf(entrypath, sizeof(entrypath), "%s/%s", source, curentry); snprintf(entrypath, sizeof(entrypath), "%s/%s", source, curentry);
ret = ISFS_ReadDir(entrypath, NULL, &l); ret = ISFS_ReadDir(entrypath, NULL, &l);
(*entries)[i].type = ret < 0 ? 0 : 1; (*entries)[i].type = ret < 0 ? 0 : 1;
} }
MEM2_free(names); free(names);
} }
s32 Nand::__configread(void) s32 Nand::__configread(void)
{ {
confbuffer = (u8 *)MEM2_alloc(0x4000); confbuffer = (u8 *)malloc(0x4000);
txtbuffer = (char *)MEM2_alloc(0x100); txtbuffer = (char *)malloc(0x100);
if(confbuffer == NULL || txtbuffer == NULL) if(confbuffer == NULL || txtbuffer == NULL)
return -1; return -1;
@ -349,8 +352,8 @@ s32 Nand::__configwrite(void)
return 1; return 1;
} }
} }
MEM2_free(confbuffer); free(confbuffer);
MEM2_free(txtbuffer); free(txtbuffer);
return 0; return 0;
} }
@ -526,7 +529,7 @@ s32 Nand::__FlashNandFile(const char *source, const char *dest)
return fd; return fd;
} }
u8 *buffer = (u8 *)MEM2_alloc(BLOCK); u8 *buffer = (u8 *)memalign(32, ALIGN32(BLOCK));
if(buffer == NULL) if(buffer == NULL)
return -1; return -1;
@ -543,7 +546,7 @@ s32 Nand::__FlashNandFile(const char *source, const char *dest)
gprintf(" failed\nError: fread(%p, 1, %d, %s) %d\n", buffer, size, source, ret); gprintf(" failed\nError: fread(%p, 1, %d, %s) %d\n", buffer, size, source, ret);
ISFS_Close(fd); ISFS_Close(fd);
fclose(file); fclose(file);
MEM2_free(buffer); free(buffer);
return ret; return ret;
} }
@ -553,7 +556,7 @@ s32 Nand::__FlashNandFile(const char *source, const char *dest)
gprintf(" failed\nError: ISFS_Write(%d, %p, %d) %d\n", fd, buffer, size, ret); gprintf(" failed\nError: ISFS_Write(%d, %p, %d) %d\n", fd, buffer, size, ret);
ISFS_Close(fd); ISFS_Close(fd);
fclose(file); fclose(file);
MEM2_free(buffer); free(buffer);
return ret; return ret;
} }
toread -= size; toread -= size;
@ -574,7 +577,7 @@ s32 Nand::__FlashNandFile(const char *source, const char *dest)
dumper(NandDone, NandSize, fsize, FileDone, FilesDone, FoldersDone, (char *)file, data); dumper(NandDone, NandSize, fsize, FileDone, FilesDone, FoldersDone, (char *)file, data);
} }
ISFS_Close(fd); ISFS_Close(fd);
MEM2_free(buffer); free(buffer);
fclose(file); fclose(file);
return 1; return 1;
} }
@ -589,16 +592,16 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
return fd; return fd;
} }
fstats *status = (fstats *)MEM2_alloc(sizeof(fstats)); fstats *status = (fstats *)memalign(32, ALIGN32(sizeof(fstats)));
if(status == NULL) if(status == NULL)
return -1; return -1;
s32 ret = ISFS_GetFileStats(fd, status); s32 ret = ISFS_GetFileStats(fd, status);
if (ret < 0) if(ret < 0)
{ {
gprintf("Error: ISFS_GetFileStats(%d) %d\n", fd, ret); gprintf("Error: ISFS_GetFileStats(%d) %d\n", fd, ret);
ISFS_Close(fd); ISFS_Close(fd);
MEM2_free(status); free(status);
return ret; return ret;
} }
@ -608,7 +611,7 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
if(showprogress) if(showprogress)
dumper(NandSize, 0x1f400000, 0x1f400000, NandSize, FilesDone, FoldersDone, (char *)"", data); dumper(NandSize, 0x1f400000, 0x1f400000, NandSize, FilesDone, FoldersDone, (char *)"", data);
ISFS_Close(fd); ISFS_Close(fd);
MEM2_free(status); free(status);
return 0; return 0;
} }
@ -616,18 +619,22 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
fsop_deleteFile(dest); fsop_deleteFile(dest);
FILE *file = fopen(dest, "wb"); FILE *file = fopen(dest, "wb");
if (!file) if(!file)
{ {
gprintf("Error opening destination: \"%s\"\n", dest); gprintf("Error opening destination: \"%s\"\n", dest);
ISFS_Close(fd); ISFS_Close(fd);
free(status);
return 0; return 0;
} }
gprintf("Dumping: %s (%ukb)...", source, (status->file_length / 0x400)+1); gprintf("Dumping: %s (%ukb)...", source, (status->file_length / 0x400)+1);
u8 *buffer = (u8 *)MEM2_alloc(BLOCK); u8 *buffer = (u8 *)memalign(32, ALIGN32(BLOCK));
if(buffer == NULL) if(buffer == NULL)
{
free(status);
return -1; return -1;
}
u32 toread = status->file_length; u32 toread = status->file_length;
while(toread > 0) while(toread > 0)
@ -642,8 +649,8 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
gprintf(" failed\nError: ISFS_Read(%d, %p, %d) %d\n", fd, buffer, size, ret); gprintf(" failed\nError: ISFS_Read(%d, %p, %d) %d\n", fd, buffer, size, ret);
ISFS_Close(fd); ISFS_Close(fd);
fclose(file); fclose(file);
MEM2_free(status); free(status);
MEM2_free(buffer); free(buffer);
return ret; return ret;
} }
@ -653,8 +660,8 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
gprintf(" failed\nError writing to destination: \"%s\" (%d)\n", dest, ret); gprintf(" failed\nError writing to destination: \"%s\" (%d)\n", dest, ret);
ISFS_Close(fd); ISFS_Close(fd);
fclose(file); fclose(file);
MEM2_free(status); free(status);
MEM2_free(buffer); free(buffer);
return ret; return ret;
} }
toread -= size; toread -= size;
@ -676,8 +683,8 @@ s32 Nand::__DumpNandFile(const char *source, const char *dest)
gprintf(" done!\n"); gprintf(" done!\n");
fclose(file); fclose(file);
ISFS_Close(fd); ISFS_Close(fd);
MEM2_free(status); free(status);
MEM2_free(buffer); free(buffer);
return 0; return 0;
} }
@ -764,7 +771,7 @@ s32 Nand::__DumpNandFolder(const char *source, const char *dest)
__DumpNandFolder(nsource, dest); __DumpNandFolder(nsource, dest);
} }
} }
MEM2_free(names); free(names);
return 0; return 0;
} }
@ -822,7 +829,7 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr)
struct stat filestat; struct stat filestat;
if (stat(nandpath, &filestat) == 0) if (stat(nandpath, &filestat) == 0)
{ {
MEM2_free(titleTMD); free(titleTMD);
gprintf("%s Exists!\n", nandpath); gprintf("%s Exists!\n", nandpath);
return; return;
} }
@ -838,7 +845,7 @@ void Nand::CreateTitleTMD(const char *path, dir_discHdr *hdr)
else else
gprintf("Creating title TMD: %s failed (%i)\n", nandpath, file); gprintf("Creating title TMD: %s failed (%i)\n", nandpath, file);
MEM2_free(titleTMD); free(titleTMD);
} }
s32 Nand::FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data) s32 Nand::FlashToNAND(const char *source, const char *dest, dump_callback_t i_dumper, void *i_data)

View File

@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <gccore.h> #include <gccore.h>
#include <malloc.h>
#include "utils.h" #include "utils.h"
#include "mem2.hpp" #include "mem2.hpp"
@ -16,11 +17,18 @@
#define wbfs_fatal(x) do { gprintf(x); wd_last_error = 1; } while(0) #define wbfs_fatal(x) do { gprintf(x); wd_last_error = 1; } while(0)
#define wbfs_error(x) do { gprintf(x); wd_last_error = 2; } while(0) #define wbfs_error(x) do { gprintf(x); wd_last_error = 2; } while(0)
#define wbfs_malloc(x) MEM2_alloc(x) /* Thanks to cfg-loader */
#define wbfs_free(x) MEM2_free(x) #define wbfs_malloc(x) calloc(x, 1)
#define wbfs_free(x) free(x)
#define wbfs_ioalloc(x) MEM2_memalign(32, x) static inline void *wbfs_ioalloc(size_t x)
#define wbfs_iofree(x) MEM2_free(x) {
void *p = memalign(32, x);
if(p)
memset(p, 0, x);
return p;
}
#define wbfs_iofree(x) free(x)
#define wbfs_be16(x) (*((u16*)(x))) #define wbfs_be16(x) (*((u16*)(x)))
#define wbfs_be32(x) (*((u32*)(x))) #define wbfs_be32(x) (*((u32*)(x)))

View File

@ -12,13 +12,12 @@ en exposed s_fsop fsop structure can be used by callback to update operation sta
#include <math.h> #include <math.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include <malloc.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include "fileOps.h" #include "fileOps.h"
#include "memory/mem2.hpp"
#include "utils.h" #include "utils.h"
#include "gecko.h" #include "gecko.h"
@ -205,7 +204,7 @@ bool fsop_CopyFile(char *source, char *target, progress_callback_t spinner, void
u8 *threadStack = NULL; u8 *threadStack = NULL;
lwp_t hthread = LWP_THREAD_NULL; lwp_t hthread = LWP_THREAD_NULL;
buff = MEM2_alloc(block * 2); buff = malloc(block * 2);
if(buff == NULL) if(buff == NULL)
return false; return false;
@ -215,9 +214,12 @@ bool fsop_CopyFile(char *source, char *target, progress_callback_t spinner, void
blockInfo[1] = 0; blockInfo[1] = 0;
u32 bytes = 0; u32 bytes = 0;
threadStack = MEM2_alloc(STACKSIZE); threadStack = malloc(STACKSIZE);
if(threadStack == NULL) if(threadStack == NULL)
{
free(buff);
return false; return false;
}
LWP_CreateThread(&hthread, thread_CopyFileReader, NULL, threadStack, STACKSIZE, 30); LWP_CreateThread(&hthread, thread_CopyFileReader, NULL, threadStack, STACKSIZE, 30);
@ -259,14 +261,14 @@ bool fsop_CopyFile(char *source, char *target, progress_callback_t spinner, void
usleep(5); usleep(5);
LWP_JoinThread(hthread, NULL); LWP_JoinThread(hthread, NULL);
MEM2_free(threadStack); free(threadStack);
stopThread = 1; stopThread = 1;
DCFlushRange(&stopThread, sizeof(stopThread)); DCFlushRange(&stopThread, sizeof(stopThread));
fclose(fs); fclose(fs);
fclose(ft); fclose(ft);
MEM2_free(buff); free(buff);
if(err) if(err)
{ {

View File

@ -2,13 +2,8 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include <ogc/machine/processor.h> #include <ogc/machine/processor.h>
#include "gc.h"
#include "gecko.h"
#include "fileOps.h"
#include "utils.h"
#include "memory/mem2.hpp"
#include "loader/disc.h"
// for directory parsing and low-level file I/O // for directory parsing and low-level file I/O
#include <sys/types.h> #include <sys/types.h>
@ -16,14 +11,20 @@
#include <fcntl.h> #include <fcntl.h>
#include <dirent.h> #include <dirent.h>
#include "gc.h"
#include "gecko.h"
#include "fileOps.h"
#include "utils.h"
#include "loader/disc.h"
// DIOS-MIOS // DIOS-MIOS
DML_CFG *DMLCfg = NULL; DML_CFG *DMLCfg = NULL;
void DML_New_SetOptions(const char *GamePath, char *CheatPath, char *NewCheatPath, const char *partition, bool cheats, bool debugger, u8 NMM, u8 nodisc, u8 DMLvideoMode, u8 videoSetting, bool widescreen, bool new_dm_cfg) void DML_New_SetOptions(const char *GamePath, char *CheatPath, const char *NewCheatPath, const char *partition, bool cheats, bool debugger, u8 NMM, u8 nodisc, u8 DMLvideoMode, u8 videoSetting, bool widescreen, bool new_dm_cfg)
{ {
gprintf("Wiiflow GC: Launch game '%s' through memory (new method)\n", GamePath); gprintf("Wiiflow GC: Launch game '%s' through memory (new method)\n", GamePath);
DMLCfg = (DML_CFG*)MEM1_alloc(sizeof(DML_CFG)); DMLCfg = (DML_CFG*)malloc(sizeof(DML_CFG));
if(DMLCfg == NULL) if(DMLCfg == NULL)
return; return;
memset(DMLCfg, 0, sizeof(DML_CFG)); memset(DMLCfg, 0, sizeof(DML_CFG));
@ -55,12 +56,13 @@ void DML_New_SetOptions(const char *GamePath, char *CheatPath, char *NewCheatPat
char *ptr; char *ptr;
if(strstr(CheatPath, partition) == NULL) if(strstr(CheatPath, partition) == NULL)
{ {
fsop_CopyFile(CheatPath, NewCheatPath, NULL, NULL); fsop_CopyFile(CheatPath, (char*)NewCheatPath, NULL, NULL);
ptr = &NewCheatPath[3]; ptr = strstr(NewCheatPath, ":/") + 1;
} }
else else
ptr = &CheatPath[3]; ptr = strstr(CheatPath, ":/") + 1;
strncpy(DMLCfg->CheatPath, ptr, sizeof(DMLCfg->CheatPath)); strncpy(DMLCfg->CheatPath, ptr, sizeof(DMLCfg->CheatPath));
gprintf("Cheat Path: %s\n", ptr);
DMLCfg->Config |= DML_CFG_CHEAT_PATH; DMLCfg->Config |= DML_CFG_CHEAT_PATH;
} }
@ -86,7 +88,7 @@ void DML_New_SetOptions(const char *GamePath, char *CheatPath, char *NewCheatPat
DMLCfg->VideoMode |= DML_VID_PROG_PATCH; DMLCfg->VideoMode |= DML_VID_PROG_PATCH;
} }
void DML_Old_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, bool cheats) void DML_Old_SetOptions(const char *GamePath)
{ {
gprintf("Wiiflow GC: Launch game '%s' through boot.bin (old method)\n", GamePath); gprintf("Wiiflow GC: Launch game '%s' through boot.bin (old method)\n", GamePath);
FILE *f; FILE *f;
@ -94,9 +96,6 @@ void DML_Old_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, boo
fwrite(GamePath, 1, strlen(GamePath) + 1, f); fwrite(GamePath, 1, strlen(GamePath) + 1, f);
fclose(f); fclose(f);
if(cheats && strstr(CheatPath, NewCheatPath) == NULL)
fsop_CopyFile(CheatPath, NewCheatPath, NULL, NULL);
//Tell DML to boot the game from sd card //Tell DML to boot the game from sd card
*(vu32*)0x80001800 = 0xB002D105; *(vu32*)0x80001800 = 0xB002D105;
DCFlushRange((void *)(0x80001800), 4); DCFlushRange((void *)(0x80001800), 4);
@ -109,7 +108,7 @@ void DML_New_SetBootDiscOption(bool new_dm_cfg)
{ {
gprintf("Booting GC game\n"); gprintf("Booting GC game\n");
DMLCfg = (DML_CFG*)MEM1_alloc(sizeof(DML_CFG)); DMLCfg = (DML_CFG*)malloc(sizeof(DML_CFG));
if(DMLCfg == NULL) if(DMLCfg == NULL)
return; return;
memset(DMLCfg, 0, sizeof(DML_CFG)); memset(DMLCfg, 0, sizeof(DML_CFG));
@ -137,7 +136,7 @@ void DML_New_WriteOptions()
memcpy((void *)0x81200000, DMLCfg, sizeof(DML_CFG)); memcpy((void *)0x81200000, DMLCfg, sizeof(DML_CFG));
DCFlushRange((void *)(0x81200000), sizeof(DML_CFG)); DCFlushRange((void *)(0x81200000), sizeof(DML_CFG));
MEM1_free(DMLCfg); free(DMLCfg);
} }
@ -155,12 +154,12 @@ bool DEVO_Installed(const char* path)
FILE *f = fopen(loader_path, "rb"); FILE *f = fopen(loader_path, "rb");
if(f) if(f)
{ {
u8 *tbuf = (u8 *)MEM2_alloc(0x04); u8 *tbuf = (u8 *)malloc(0x04);
fread(tbuf, 1, 4, f); fread(tbuf, 1, 4, f);
if(*(vu32*)tbuf == 0x4800004c) if(*(vu32*)tbuf == 0x4800004c)
devo = true; devo = true;
MEM2_free(tbuf); free(tbuf);
fclose(f); fclose(f);
} }
return devo; return devo;
@ -205,7 +204,7 @@ void DEVO_SetOptions(const char *isopath, const char *partition, const char *loa
fclose(f); fclose(f);
// fill out the Devolution config struct // fill out the Devolution config struct
memset(DEVO_CONFIG, 0, sizeof(*DEVO_CONFIG)); memset(DEVO_CONFIG, 0, sizeof(gconfig));
DEVO_CONFIG->signature = 0x3EF9DB23; DEVO_CONFIG->signature = 0x3EF9DB23;
DEVO_CONFIG->version = 0x00000100; DEVO_CONFIG->version = 0x00000100;
DEVO_CONFIG->device_signature = st.st_dev; DEVO_CONFIG->device_signature = st.st_dev;

View File

@ -49,8 +49,8 @@ enum dmlvideomode
DML_VID_PROG_PATCH = (1<<4), DML_VID_PROG_PATCH = (1<<4),
}; };
void DML_New_SetOptions(const char *GamePath, char *CheatPath, char *NewCheatPath, const char *partition, bool cheats, bool debugger, u8 NMM, u8 nodisc, u8 DMLvideoMode, u8 videoSetting, bool widescreen, bool new_dm_cfg); void DML_New_SetOptions(const char *GamePath, char *CheatPath, const char *NewCheatPath, const char *partition, bool cheats, bool debugger, u8 NMM, u8 nodisc, u8 DMLvideoMode, u8 videoSetting, bool widescreen, bool new_dm_cfg);
void DML_Old_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, bool cheats); void DML_Old_SetOptions(const char *GamePath);
void DML_New_SetBootDiscOption(bool new_dm_cfg); void DML_New_SetBootDiscOption(bool new_dm_cfg);
void DML_New_WriteOptions(); void DML_New_WriteOptions();

View File

@ -55,13 +55,13 @@ void GC_Disc::init(char *path)
f = fopen(GamePath, "rb"); f = fopen(GamePath, "rb");
if(f == NULL) if(f == NULL)
return; return;
u8 *ReadBuffer = (u8*)MEM2_alloc(0x440); u8 *ReadBuffer = (u8*)malloc(0x440);
if(ReadBuffer == NULL) if(ReadBuffer == NULL)
return; return;
fread(ReadBuffer, 1, 0x440, f); fread(ReadBuffer, 1, 0x440, f);
u32 FSTOffset = *(vu32*)(ReadBuffer+0x424); u32 FSTOffset = *(vu32*)(ReadBuffer+0x424);
u32 FSTSize = *(vu32*)(ReadBuffer+0x428); u32 FSTSize = *(vu32*)(ReadBuffer+0x428);
MEM2_free(ReadBuffer); free(ReadBuffer);
fseek(f, FSTOffset, SEEK_SET); fseek(f, FSTOffset, SEEK_SET);
Read_FST(f, FSTSize); Read_FST(f, FSTSize);
fclose(f); fclose(f);
@ -72,19 +72,19 @@ void GC_Disc::clear()
{ {
if(opening_bnr) if(opening_bnr)
{ {
MEM2_free(opening_bnr); free(opening_bnr);
opening_bnr = NULL; opening_bnr = NULL;
} }
if(FSTable) if(FSTable)
{ {
MEM2_free(FSTable); free(FSTable);
FSTable = NULL; FSTable = NULL;
} }
} }
void GC_Disc::Read_FST(FILE *f, u32 FST_size) void GC_Disc::Read_FST(FILE *f, u32 FST_size)
{ {
FSTable = (u8*)MEM2_alloc(FST_size); FSTable = (u8*)malloc(FST_size);
if(FSTable == NULL) if(FSTable == NULL)
return; return;
fread(FSTable, 1, FST_size, f); fread(FSTable, 1, FST_size, f);
@ -119,7 +119,7 @@ u8 *GC_Disc::GetGameCubeBanner()
} }
if(f) if(f)
{ {
opening_bnr = (u8*)MEM2_alloc(fst[i].FileLength); opening_bnr = (u8*)malloc(fst[i].FileLength);
fread(opening_bnr, 1, fst[i].FileLength, f); fread(opening_bnr, 1, fst[i].FileLength, f);
fclose(f); fclose(f);
} }

View File

@ -20,6 +20,7 @@ bool bufferMessages = true;
bool WriteToSD = false; bool WriteToSD = false;
char *tmpfilebuffer = NULL; char *tmpfilebuffer = NULL;
u32 tmpbuffersize = filebuffer + 1 * sizeof(char);
static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len) static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len)
{ {
@ -71,7 +72,7 @@ void ClearLogBuffer()
{ {
if(tmpfilebuffer == NULL) if(tmpfilebuffer == NULL)
return; return;
MEM2_free(tmpfilebuffer); free(tmpfilebuffer);
tmpfilebuffer = NULL; tmpfilebuffer = NULL;
} }
@ -87,7 +88,7 @@ void WriteToFile(char* tmp)
} }
else else
{ {
MEM2_free(tmpfilebuffer); free(tmpfilebuffer);
tmpfilebuffer = NULL; tmpfilebuffer = NULL;
return; return;
} }
@ -98,7 +99,7 @@ void WriteToFile(char* tmp)
if(outfile) if(outfile)
{ {
fwrite(tmpfilebuffer, 1, strlen(tmpfilebuffer), outfile); fwrite(tmpfilebuffer, 1, strlen(tmpfilebuffer), outfile);
memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer)); memset(tmpfilebuffer, 0, tmpbuffersize);
fclose(outfile); fclose(outfile);
} }
} }
@ -183,7 +184,7 @@ bool InitGecko()
void AllocSDGeckoBuffer() void AllocSDGeckoBuffer()
{ {
tmpfilebuffer = (char*)MEM2_alloc(filebuffer + 1 * sizeof(char)); tmpfilebuffer = (char*)malloc(tmpbuffersize);
if(tmpfilebuffer != NULL) if(tmpfilebuffer != NULL)
memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer)); memset(tmpfilebuffer, 0, tmpbuffersize);
} }

View File

@ -1,25 +1,25 @@
/**************************************************************************** /****************************************************************************
*Copyright (C) 2010 * Copyright (C) 2010
*by Dimok * by Dimok
* *
*This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
*warranty. In no event will the authors be held liable for any * warranty. In no event will the authors be held liable for any
*damages arising from the use of this software. * damages arising from the use of this software.
* *
*Permission is granted to anyone to use this software for any * Permission is granted to anyone to use this software for any
*purpose, including commercial applications, and to alter it and * purpose, including commercial applications, and to alter it and
*redistribute it freely, subject to the following restrictions: * redistribute it freely, subject to the following restrictions:
* *
*1. The origin of this software must not be misrepresented; you * 1. The origin of this software must not be misrepresented; you
*must not claim that you wrote the original software. If you use * must not claim that you wrote the original software. If you use
*this software in a product, an acknowledgment in the product * this software in a product, an acknowledgment in the product
*documentation would be appreciated but is not required. * documentation would be appreciated but is not required.
* *
*2. Altered source versions must be plainly marked as such, and * 2. Altered source versions must be plainly marked as such, and
*must not be misrepresented as being the original software. * must not be misrepresented as being the original software.
* *
*3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
*distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -27,13 +27,13 @@
#include "Gekko.h" #include "Gekko.h"
#define HW_GPIO 0xCD0000C0; #define HW_GPIOB_OUT 0xCD0000C0;
#define DISC_SLOT_LED 0x20 #define DISC_SLOT_LED 0x20
lwp_t light_thread = LWP_THREAD_NULL; lwp_t light_thread = LWP_THREAD_NULL;
void *light_loop(); void *light_loop();
vu32 *light_reg = (u32*) HW_GPIO; vu32 *light_reg = (u32*)HW_GPIOB_OUT;
bool light_on = false; bool light_on = false;
u8 light_level = 0; u8 light_level = 0;
@ -43,7 +43,7 @@ struct timespec light_timeoff;
void wiiLightOn() void wiiLightOn()
{ {
light_on = true; light_on = true;
light_level = 0;
if(light_thread == LWP_THREAD_NULL) if(light_thread == LWP_THREAD_NULL)
LWP_CreateThread(&light_thread, light_loop, NULL, NULL, 0, LWP_PRIO_HIGHEST); LWP_CreateThread(&light_thread, light_loop, NULL, NULL, 0, LWP_PRIO_HIGHEST);
} }
@ -51,7 +51,7 @@ void wiiLightOn()
void wiiLightOff() void wiiLightOff()
{ {
light_on = false; light_on = false;
light_level = 0;
LWP_JoinThread(light_thread, NULL); LWP_JoinThread(light_thread, NULL);
light_thread = LWP_THREAD_NULL; light_thread = LWP_THREAD_NULL;
*light_reg &= ~DISC_SLOT_LED; *light_reg &= ~DISC_SLOT_LED;
@ -93,7 +93,7 @@ void *light_loop()
*light_reg |= DISC_SLOT_LED; *light_reg |= DISC_SLOT_LED;
nanosleep(&timeon); nanosleep(&timeon);
// Turn off the light (if required) and sleep for a bit // Turn off the light (if required) and sleep for a bit
if (timeoff.tv_nsec > 0) if(timeoff.tv_nsec > 0)
*light_reg &= ~DISC_SLOT_LED; *light_reg &= ~DISC_SLOT_LED;
nanosleep(&timeoff); nanosleep(&timeoff);
} }

View File

@ -75,7 +75,7 @@ WiiMovie::WiiMovie(const char * filepath)
} }
PlayThreadStack = NULL; PlayThreadStack = NULL;
ThreadStack = (u8 *)MEM2_alloc(32768); ThreadStack = (u8 *)malloc(32768);
if (!ThreadStack) if (!ThreadStack)
return; return;
@ -109,7 +109,7 @@ WiiMovie::~WiiMovie()
} }
if (ThreadStack != NULL) if (ThreadStack != NULL)
{ {
MEM2_free(ThreadStack); free(ThreadStack);
ThreadStack = NULL; ThreadStack = NULL;
} }
@ -127,7 +127,7 @@ bool WiiMovie::Play(bool loop)
gprintf("Start playing video\n"); gprintf("Start playing video\n");
PlayThreadStack = (u8 *)MEM2_alloc(32768); PlayThreadStack = (u8 *)malloc(32768);
if (PlayThreadStack == NULL) if (PlayThreadStack == NULL)
return false; return false;
@ -155,7 +155,7 @@ void WiiMovie::Stop()
gprintf("Playing thread stopped\n"); gprintf("Playing thread stopped\n");
if(PlayThreadStack != NULL) if(PlayThreadStack != NULL)
MEM2_free(PlayThreadStack); free(PlayThreadStack);
} }
void WiiMovie::SetVolume(int vol) void WiiMovie::SetVolume(int vol)

View File

@ -280,7 +280,7 @@ void VideoFrame::resize(int width, int height)
_p = 3*width; _p = 3*width;
_p += (4 - _p%4)%4; _p += (4 - _p%4)%4;
_data = (u8 *)MEM2_alloc(_p * _h); _data = (u8 *)malloc(_p * _h);
} }
int VideoFrame::getWidth() const int VideoFrame::getWidth() const
@ -301,7 +301,7 @@ const u8* VideoFrame::getData() const
void VideoFrame::dealloc() void VideoFrame::dealloc()
{ {
if(_data != NULL) if(_data != NULL)
MEM2_free(_data); free(_data);
_w = _h = _p = 0; _w = _h = _p = 0;
} }

View File

@ -59,7 +59,7 @@ IMGCTX PNGU_SelectImageFromBuffer (const void *buffer)
{ {
if (!buffer) return NULL; if (!buffer) return NULL;
IMGCTX ctx = MEM2_alloc(sizeof (struct _IMGCTX)); IMGCTX ctx = malloc(sizeof (struct _IMGCTX));
if (!ctx) return NULL; if (!ctx) return NULL;
ctx->buffer = (void *) buffer; ctx->buffer = (void *) buffer;
@ -79,7 +79,7 @@ IMGCTX PNGU_SelectImageFromDevice (const char *filename)
if (!filename) if (!filename)
return NULL; return NULL;
IMGCTX ctx = MEM2_alloc(sizeof (struct _IMGCTX)); IMGCTX ctx = malloc(sizeof (struct _IMGCTX));
if (ctx == NULL) if (ctx == NULL)
return NULL; return NULL;
@ -87,11 +87,11 @@ IMGCTX PNGU_SelectImageFromDevice (const char *filename)
ctx->source = PNGU_SOURCE_DEVICE; ctx->source = PNGU_SOURCE_DEVICE;
ctx->cursor = 0; ctx->cursor = 0;
ctx->filename = MEM2_alloc(strlen (filename) + 1); ctx->filename = malloc(strlen (filename) + 1);
if (ctx->filename == NULL) if (ctx->filename == NULL)
{ {
if(ctx != NULL) if(ctx != NULL)
MEM2_free(ctx); free(ctx);
return NULL; return NULL;
} }
strcpy(ctx->filename, filename); strcpy(ctx->filename, filename);
@ -109,14 +109,14 @@ void PNGU_ReleaseImageContext (IMGCTX ctx)
return; return;
if(ctx->filename) if(ctx->filename)
MEM2_free(ctx->filename); free(ctx->filename);
if((ctx->propRead) && (ctx->prop.trans)) if((ctx->propRead) && (ctx->prop.trans))
MEM2_free(ctx->prop.trans); free(ctx->prop.trans);
pngu_free_info(ctx); pngu_free_info(ctx);
MEM2_free(ctx); free(ctx);
} }
@ -156,8 +156,8 @@ int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buff
*(ctx->row_pointers[y]+x*6+3), *(ctx->row_pointers[y]+x*6+4), *(ctx->row_pointers[y]+x*6+5)); *(ctx->row_pointers[y]+x*6+3), *(ctx->row_pointers[y]+x*6+4), *(ctx->row_pointers[y]+x*6+5));
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -180,8 +180,8 @@ int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buff
(((PNGU_u16) (ctx->row_pointers[y][x*3+2] & 0xF8)) >> 3); (((PNGU_u16) (ctx->row_pointers[y][x*3+2] & 0xF8)) >> 3);
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -216,8 +216,8 @@ int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffe
} }
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -279,8 +279,8 @@ int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *b
} }
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -526,8 +526,8 @@ int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *b
} }
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -650,8 +650,8 @@ int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *bu
} }
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -768,8 +768,8 @@ int PNGU_DecodeToCMPR(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer)
outBuf += 4; outBuf += 4;
} }
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
// Success // Success
return PNGU_OK; return PNGU_OK;
@ -839,7 +839,7 @@ int PNGU_EncodeFromYCbYCr(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buf
if (rowbytes % 4) if (rowbytes % 4)
rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary
ctx->img_data = MEM2_alloc(rowbytes * height); ctx->img_data = malloc(rowbytes * height);
if (!ctx->img_data) if (!ctx->img_data)
{ {
png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL);
@ -848,7 +848,7 @@ int PNGU_EncodeFromYCbYCr(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buf
return PNGU_LIB_ERROR; return PNGU_LIB_ERROR;
} }
ctx->row_pointers = MEM2_alloc(sizeof (png_bytep) * height); ctx->row_pointers = malloc(sizeof (png_bytep) * height);
if (!ctx->row_pointers) if (!ctx->row_pointers)
{ {
png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL);
@ -880,8 +880,8 @@ int PNGU_EncodeFromYCbYCr(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buf
png_write_end (ctx->png_ptr, (png_infop) NULL); png_write_end (ctx->png_ptr, (png_infop) NULL);
// Free resources // Free resources
MEM2_free(ctx->img_data); free(ctx->img_data);
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
png_destroy_write_struct (&(ctx->png_ptr), &(ctx->info_ptr)); png_destroy_write_struct (&(ctx->png_ptr), &(ctx->info_ptr));
if (ctx->source == PNGU_SOURCE_DEVICE) if (ctx->source == PNGU_SOURCE_DEVICE)
fclose (ctx->fd); fclose (ctx->fd);
@ -1060,7 +1060,7 @@ int pngu_info (IMGCTX ctx)
{ {
if (ctx->prop.numTrans) if (ctx->prop.numTrans)
{ {
ctx->prop.trans = MEM2_alloc(sizeof (PNGUCOLOR) * ctx->prop.numTrans); ctx->prop.trans = malloc(sizeof (PNGUCOLOR) * ctx->prop.numTrans);
if (ctx->prop.trans) if (ctx->prop.trans)
{ {
for (i = 0; i < ctx->prop.numTrans; i++) for (i = 0; i < ctx->prop.numTrans; i++)
@ -1079,7 +1079,7 @@ int pngu_info (IMGCTX ctx)
{ {
if (ctx->prop.numTrans) if (ctx->prop.numTrans)
{ {
ctx->prop.trans = MEM2_alloc(sizeof (PNGUCOLOR) * ctx->prop.numTrans); ctx->prop.trans = malloc(sizeof (PNGUCOLOR) * ctx->prop.numTrans);
if (ctx->prop.trans) if (ctx->prop.trans)
for (i = 0; i < ctx->prop.numTrans; i++) for (i = 0; i < ctx->prop.numTrans; i++)
ctx->prop.trans[i].r = ctx->prop.trans[i].g = ctx->prop.trans[i].b = ctx->prop.trans[i].r = ctx->prop.trans[i].g = ctx->prop.trans[i].b =
@ -1126,8 +1126,8 @@ int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlph
{ {
error: error:
memcpy(png_jmpbuf(ctx->png_ptr), save_jmp, sizeof(save_jmp)); memcpy(png_jmpbuf(ctx->png_ptr), save_jmp, sizeof(save_jmp));
MEM2_free(ctx->row_pointers); free(ctx->row_pointers);
MEM2_free(ctx->img_data); free(ctx->img_data);
pngu_free_info (ctx); pngu_free_info (ctx);
//printf("*** This is a corrupted image!!\n"); sleep(5); //printf("*** This is a corrupted image!!\n"); sleep(5);
return mem_err ? PNGU_LIB_ERROR : -666; return mem_err ? PNGU_LIB_ERROR : -666;
@ -1161,14 +1161,14 @@ int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlph
if (rowbytes % 4) if (rowbytes % 4)
rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary
ctx->img_data = MEM2_alloc(rowbytes * ctx->prop.imgHeight); ctx->img_data = malloc(rowbytes * ctx->prop.imgHeight);
if (!ctx->img_data) if (!ctx->img_data)
{ {
mem_err = 1; mem_err = 1;
goto error; goto error;
} }
ctx->row_pointers = MEM2_alloc(sizeof (png_bytep) * ctx->prop.imgHeight); ctx->row_pointers = malloc(sizeof (png_bytep) * ctx->prop.imgHeight);
if (!ctx->row_pointers) if (!ctx->row_pointers)
{ {
mem_err = 1; mem_err = 1;

View File

@ -199,7 +199,7 @@ STexture::TexErr STexture::fromImageFile(const char *filename, u8 f, Alloc alloc
u8 *Image = NULL; u8 *Image = NULL;
if(fileSize) if(fileSize)
{ {
Image = (u8*)MEM2_alloc(fileSize); Image = (u8*)malloc(fileSize);
if(Image != NULL) if(Image != NULL)
fread(Image, 1, fileSize, file); fread(Image, 1, fileSize, file);
} }
@ -212,7 +212,7 @@ STexture::TexErr STexture::fromImageFile(const char *filename, u8 f, Alloc alloc
result = fromPNG(Image, f, alloc, minMipSize, maxMipSize); result = fromPNG(Image, f, alloc, minMipSize, maxMipSize);
else else
result = fromJPG(Image, fileSize, f, alloc, minMipSize, maxMipSize); result = fromJPG(Image, fileSize, f, alloc, minMipSize, maxMipSize);
MEM2_free(Image); free(Image);
} }
return result; return result;
} }

View File

@ -274,8 +274,8 @@ void CVideo::cleanup(void)
} }
free(MEM_K1_TO_K0(m_frameBuf[0])); free(MEM_K1_TO_K0(m_frameBuf[0]));
free(MEM_K1_TO_K0(m_frameBuf[1])); free(MEM_K1_TO_K0(m_frameBuf[1]));
MEM1_free(m_stencil); free(m_stencil);
MEM1_free(m_fifo); free(m_fifo);
} }
void CVideo::prepareAAPass(int aaStep) void CVideo::prepareAAPass(int aaStep)
@ -502,7 +502,6 @@ void CVideo::_showWaitMessages(CVideo *m)
m->prepare(); m->prepare();
m->setup2DProjection(); m->setup2DProjection();
GX_SetNumChans(0); GX_SetNumChans(0);
wiiLightSetLevel(0);
wiiLightOn(); wiiLightOn();
while(m->m_showWaitMessage) while(m->m_showWaitMessage)

View File

@ -167,7 +167,7 @@ static bool PrinceOfPersiaPatch()
if (memcmp("SPX", (char *) 0x80000000, 3) != 0 && memcmp("RPW", (char *) 0x80000000, 3) != 0) if (memcmp("SPX", (char *) 0x80000000, 3) != 0 && memcmp("RPW", (char *) 0x80000000, 3) != 0)
return false; return false;
WIP_Code * CodeList = MEM2_alloc(5 * sizeof(WIP_Code)); WIP_Code * CodeList = malloc(5 * sizeof(WIP_Code));
CodeList[0].offset = 0x007AAC6A; CodeList[0].offset = 0x007AAC6A;
CodeList[0].srcaddress = 0x7A6B6F6A; CodeList[0].srcaddress = 0x7A6B6F6A;
CodeList[0].dstaddress = 0x6F6A7A6B; CodeList[0].dstaddress = 0x6F6A7A6B;
@ -186,7 +186,7 @@ static bool PrinceOfPersiaPatch()
if (set_wip_list(CodeList, 5) == false) if (set_wip_list(CodeList, 5) == false)
{ {
MEM2_free(CodeList); free(CodeList);
CodeList = NULL; CodeList = NULL;
return false; return false;
} }
@ -200,7 +200,7 @@ static bool NewSuperMarioBrosPatch()
if (memcmp("SMNE01", (char *) 0x80000000, 6) == 0) if (memcmp("SMNE01", (char *) 0x80000000, 6) == 0)
{ {
CodeList = MEM2_alloc(3 * sizeof(WIP_Code)); CodeList = malloc(3 * sizeof(WIP_Code));
if(!CodeList) if(!CodeList)
return false; return false;
CodeList[0].offset = 0x001AB610; CodeList[0].offset = 0x001AB610;
@ -215,7 +215,7 @@ static bool NewSuperMarioBrosPatch()
} }
else if (memcmp("SMNP01", (char *) 0x80000000, 6) == 0) else if (memcmp("SMNP01", (char *) 0x80000000, 6) == 0)
{ {
CodeList = MEM2_alloc(3 * sizeof(WIP_Code)); CodeList = malloc(3 * sizeof(WIP_Code));
if(!CodeList) if(!CodeList)
return false; return false;
CodeList[0].offset = 0x001AB750; CodeList[0].offset = 0x001AB750;
@ -230,7 +230,7 @@ static bool NewSuperMarioBrosPatch()
} }
else if (memcmp("SMNJ01", (char *) 0x80000000, 6) == 0) else if (memcmp("SMNJ01", (char *) 0x80000000, 6) == 0)
{ {
CodeList = MEM2_alloc(3 * sizeof(WIP_Code)); CodeList = malloc(3 * sizeof(WIP_Code));
if(!CodeList) if(!CodeList)
return false; return false;
CodeList[0].offset = 0x001AB420; CodeList[0].offset = 0x001AB420;
@ -245,7 +245,7 @@ static bool NewSuperMarioBrosPatch()
} }
if (CodeList && set_wip_list(CodeList, 3) == false) if (CodeList && set_wip_list(CodeList, 3) == false)
{ {
MEM2_free(CodeList); free(CodeList);
CodeList = NULL; CodeList = NULL;
return false; return false;
} }

View File

@ -31,7 +31,6 @@
#include "cios.h" #include "cios.h"
#include "utils.h" #include "utils.h"
#include "mem2.hpp"
#include "gecko.h" #include "gecko.h"
#include "fs.h" #include "fs.h"
#include "mload.h" #include "mload.h"
@ -70,12 +69,12 @@ bool D2X(u8 ios, u8 *base)
|| info->version < 6 /* Version */ || info->version < 6 /* Version */
|| strncasecmp(info->name, "d2x", 3) != 0) /* Name */ || strncasecmp(info->name, "d2x", 3) != 0) /* Name */
{ {
MEM2_free(info); free(info);
return false; return false;
} }
*base = (u8)info->baseios; *base = (u8)info->baseios;
MEM2_free(info); free(info);
return true; return true;
} }
@ -84,13 +83,13 @@ signed_blob *GetTMD(u8 ios, u32 *TMD_Length)
if(ES_GetStoredTMDSize(TITLE_ID(1, ios), TMD_Length) < 0) if(ES_GetStoredTMDSize(TITLE_ID(1, ios), TMD_Length) < 0)
return NULL; return NULL;
signed_blob *TMD = (signed_blob*)MEM2_alloc(ALIGN32(*TMD_Length)); signed_blob *TMD = (signed_blob*)memalign(32, ALIGN32(*TMD_Length));
if(TMD == NULL) if(TMD == NULL)
return NULL; return NULL;
if(ES_GetStoredTMD(TITLE_ID(1, ios), TMD, *TMD_Length) < 0) if(ES_GetStoredTMD(TITLE_ID(1, ios), TMD, *TMD_Length) < 0)
{ {
MEM2_free(TMD); free(TMD);
return NULL; return NULL;
} }
return TMD; return TMD;
@ -111,7 +110,7 @@ iosinfo_t *GetInfo(u8 ios)
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
sprintf(filepath, "/title/00000001/%08x/content/%08x.app", ios, *(u8 *)((u32)TMD+0x1E7)); sprintf(filepath, "/title/00000001/%08x/content/%08x.app", ios, *(u8 *)((u32)TMD+0x1E7));
MEM2_free(TMD); free(TMD);
u32 size = 0; u32 size = 0;
u8 *buffer = ISFS_GetFile((u8 *)filepath, &size, sizeof(iosinfo_t)); u8 *buffer = ISFS_GetFile((u8 *)filepath, &size, sizeof(iosinfo_t));
@ -147,17 +146,17 @@ int get_ios_type(u8 slot)
tmd *iosTMD = (tmd*)SIGNATURE_PAYLOAD(TMD_Buffer); tmd *iosTMD = (tmd*)SIGNATURE_PAYLOAD(TMD_Buffer);
if(Title_GetSize_FromTMD(iosTMD) < 0x100000 || iosTMD->title_version == 65280) if(Title_GetSize_FromTMD(iosTMD) < 0x100000 || iosTMD->title_version == 65280)
{ {
MEM2_free(TMD_Buffer); free(TMD_Buffer);
return IOS_TYPE_NO_CIOS; return IOS_TYPE_NO_CIOS;
} }
iosinfo_t *info = GetInfo(slot); iosinfo_t *info = GetInfo(slot);
if(info == NULL) if(info == NULL)
{ {
MEM2_free(TMD_Buffer); free(TMD_Buffer);
return IOS_TYPE_NO_CIOS; return IOS_TYPE_NO_CIOS;
} }
MEM2_free(info); free(info);
u8 base = 0; u8 base = 0;
switch(slot) switch(slot)
@ -187,7 +186,7 @@ int get_ios_type(u8 slot)
else else
return IOS_TYPE_NO_CIOS; return IOS_TYPE_NO_CIOS;
} }
MEM2_free(TMD_Buffer); free(TMD_Buffer);
} }
int is_ios_type(int type, u8 slot) int is_ios_type(int type, u8 slot)

View File

@ -193,18 +193,19 @@ void __Disc_SetTime(void)
s32 Disc_FindPartition(u64 *outbuf) s32 Disc_FindPartition(u64 *outbuf)
{ {
u8 TMP_Buffer_size = 0x20;
u64 offset = 0; u64 offset = 0;
u32 cnt; u32 cnt;
u32 *TMP_Buffer = (u32*)MEM2_alloc(0x20); u32 *TMP_Buffer = (u32*)malloc(TMP_Buffer_size);
if(!TMP_Buffer) if(!TMP_Buffer)
return -1; return -1;
/* Read partition info */ /* Read partition info */
s32 ret = WDVD_UnencryptedRead(TMP_Buffer, 0x20, PTABLE_OFFSET); s32 ret = WDVD_UnencryptedRead(TMP_Buffer, TMP_Buffer_size, PTABLE_OFFSET);
if(ret < 0) if(ret < 0)
{ {
MEM2_free(TMP_Buffer); free(TMP_Buffer);
return ret; return ret;
} }
@ -214,17 +215,17 @@ s32 Disc_FindPartition(u64 *outbuf)
if(nb_partitions > 8) if(nb_partitions > 8)
{ {
MEM2_free(TMP_Buffer); free(TMP_Buffer);
return -1; return -1;
} }
memset(TMP_Buffer, 0, sizeof(TMP_Buffer)); memset(TMP_Buffer, 0, TMP_Buffer_size);
/* Read partition table */ /* Read partition table */
ret = WDVD_UnencryptedRead(TMP_Buffer, 0x20, table_offset); ret = WDVD_UnencryptedRead(TMP_Buffer, TMP_Buffer_size, table_offset);
if (ret < 0) if (ret < 0)
{ {
MEM2_free(TMP_Buffer); free(TMP_Buffer);
return ret; return ret;
} }
@ -237,7 +238,7 @@ s32 Disc_FindPartition(u64 *outbuf)
if(!type) if(!type)
offset = TMP_Buffer[cnt * 2] << 2; offset = TMP_Buffer[cnt * 2] << 2;
} }
MEM2_free(TMP_Buffer); free(TMP_Buffer);
/* No game partition found */ /* No game partition found */
if (!offset) if (!offset)

View File

@ -169,9 +169,9 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
bool isWBFS = wbfs_part_fs != PART_FS_WBFS && strcasestr(strrchr(fname,'.'), ".wbfs") != 0; bool isWBFS = wbfs_part_fs != PART_FS_WBFS && strcasestr(strrchr(fname,'.'), ".wbfs") != 0;
struct stat st; struct stat st;
FragList *fs = MEM2_alloc(sizeof(FragList)); FragList *fs = malloc(sizeof(FragList));
FragList *fa = MEM2_alloc(sizeof(FragList)); FragList *fa = malloc(sizeof(FragList));
FragList *fw = MEM2_alloc(sizeof(FragList)); FragList *fw = malloc(sizeof(FragList));
if(fs == NULL || fa == NULL || fw == NULL) if(fs == NULL || fa == NULL || fw == NULL)
goto out; goto out;
@ -241,7 +241,7 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
frag_concat(fa, fs); frag_concat(fa, fs);
} }
frag_list = MEM1_alloc(ALIGN32(sizeof(FragList))); frag_list = malloc(ALIGN32(sizeof(FragList)));
if(frag_list == NULL) if(frag_list == NULL)
goto out; goto out;
@ -276,22 +276,22 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
out: out:
if(ret_val && frag_list != NULL) if(ret_val && frag_list != NULL)
{ {
MEM1_free(frag_list); free(frag_list);
frag_list = NULL; frag_list = NULL;
} }
if(fs != NULL) if(fs != NULL)
{ {
MEM2_free(fs); free(fs);
fs = NULL; fs = NULL;
} }
if(fa != NULL) if(fa != NULL)
{ {
MEM2_free(fa); free(fa);
fa = NULL; fa = NULL;
} }
if(fw != NULL) if(fw != NULL)
{ {
MEM2_free(fw); free(fw);
fw = NULL; fw = NULL;
} }
return ret_val; return ret_val;

View File

@ -3,32 +3,32 @@
#include <ogc/isfs.h> #include <ogc/isfs.h>
#include <malloc.h> #include <malloc.h>
#include "utils.h" #include "utils.h"
#include "mem2.hpp"
#include "fs.h" #include "fs.h"
u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length)
{ {
*size = 0; *size = 0;
s32 fd = ISFS_Open((const char *) path, ISFS_OPEN_READ); s32 fd = ISFS_Open((const char *)path, ISFS_OPEN_READ);
u8 *buf = NULL; u8 *buf = NULL;
static fstats stats ATTRIBUTE_ALIGN(32); static fstats stats ATTRIBUTE_ALIGN(32);
if (fd >= 0) if(fd >= 0)
{ {
if (ISFS_GetFileStats(fd, &stats) >= 0) if(ISFS_GetFileStats(fd, &stats) >= 0)
{ {
if (length <= 0) length = stats.file_length; if(length <= 0)
if (length > 0) length = stats.file_length;
buf = (u8 *)MEM2_alloc(ALIGN32(length)); if(length > 0)
buf = (u8 *)memalign(32, ALIGN32(length));
if (buf) if(buf)
{ {
*size = stats.file_length; *size = stats.file_length;
if (ISFS_Read(fd, (char*)buf, length) != length) if(ISFS_Read(fd, (char*)buf, length) != length)
{ {
*size = 0; *size = 0;
MEM2_free(buf); free(buf);
} }
} }
} }

View File

@ -68,7 +68,7 @@ int app_gameconfig_load(u8 *discid, const u8 *gameconfig, u32 tempgameconfsize)
if (gameconf == NULL) if (gameconf == NULL)
{ {
gameconf = MEM2_alloc(65536); gameconf = malloc(65536);
if (gameconf == NULL) if (gameconf == NULL)
return -1; return -1;
} }
@ -242,7 +242,7 @@ int app_gameconfig_load(u8 *discid, const u8 *gameconfig, u32 tempgameconfsize)
if (i != tempgameconfsize) while ((tempgameconf[i] != 10 && tempgameconf[i] != 13) && (i != 0)) i--; if (i != tempgameconfsize) while ((tempgameconf[i] != 10 && tempgameconf[i] != 13) && (i != 0)) i--;
} }
} }
MEM2_free(gameconf); free(gameconf);
return 0; return 0;
} }
@ -443,7 +443,7 @@ int ocarina_do_code(u64 chantitle)
{ {
memcpy(codelist, code_buf, code_size); memcpy(codelist, code_buf, code_size);
DCFlushRange(codelist, (u32)codelistend - (u32)codelist); DCFlushRange(codelist, (u32)codelistend - (u32)codelist);
MEM2_free(code_buf); free(code_buf);
} }
// TODO What's this??? // TODO What's this???

View File

@ -39,6 +39,7 @@
#include "gecko.h" #include "gecko.h"
#include "fileOps.h" #include "fileOps.h"
#include "defines.h" #include "defines.h"
#include "Gekko.h"
using namespace std; using namespace std;
@ -46,7 +47,7 @@ static u8 *FSTable ALIGNED(32);
void GCDump::__AnalizeMultiDisc() void GCDump::__AnalizeMultiDisc()
{ {
u8 *Buffer = (u8 *)MEM2_alloc(0x10); u8 *Buffer = (u8 *)malloc(0x10);
if(Buffer == NULL) if(Buffer == NULL)
return; return;
@ -64,17 +65,18 @@ void GCDump::__AnalizeMultiDisc()
} }
MultiGameCnt++; MultiGameCnt++;
} }
MEM2_free(Buffer); free(Buffer);
} }
s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length) s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length)
{ {
wiiLightOn();
wiiLightSetLevel(255);
while(1) while(1)
{ {
*(u32*)0xCD0000C0 |= 0x20;
gc_error = 0; gc_error = 0;
s32 ret = WDVD_UnencryptedRead(outbuf, length, offset); s32 ret = WDVD_UnencryptedRead(outbuf, length, offset);
if( ret != 0 ) if(ret != 0)
{ {
WDVD_LowRequestError(&gc_error); WDVD_LowRequestError(&gc_error);
if(gc_error == 0x30200 || gc_error == 0x30201 || gc_error == 0x31100) if(gc_error == 0x30200 || gc_error == 0x30201 || gc_error == 0x31100)
@ -91,17 +93,14 @@ s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length)
} }
if(gc_retry >= gc_nbrretry) if(gc_retry >= gc_nbrretry)
{ {
wiiLightOff();
if(!skiponerror) if(!skiponerror)
{
*(u32*)0xCD0000C0 &= ~0x20;
return gc_error; return gc_error;
}
else else
{ {
gc_retry = 0; gc_retry = 0;
gc_skipped++; gc_skipped++;
gprintf("Read error (%x) at offset: 0x%08x. Skipping %d bytes\n", gc_error, offset, length); gprintf("Read error (%x) at offset: 0x%08x. Skipping %d bytes\n", gc_error, offset, length);
*(u32*)0xCD0000C0 &= ~0x20;
return 1; return 1;
} }
} }
@ -118,17 +117,18 @@ s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length)
else else
{ {
gprintf("Read error(%x) at offset: 0x%08x.\n", gc_error, offset); gprintf("Read error(%x) at offset: 0x%08x.\n", gc_error, offset);
*(u32*)0xCD0000C0 &= ~0x20; wiiLightOff();
return 0; return 0;
} }
} }
else else
{ {
*(u32*)0xCD0000C0 &= ~0x20; wiiLightOff();
gc_retry = 0; gc_retry = 0;
return ret; return ret;
} }
} }
wiiLightOff();
return -1; return -1;
} }
@ -170,21 +170,22 @@ s32 GCDump::__DiscWriteFile(FILE *f, u64 offset, u32 length, u8 *ReadBuffer)
bool GCDump::__WaitForDisc(u8 dsc, u32 msg) bool GCDump::__WaitForDisc(u8 dsc, u32 msg)
{ {
u8 *ReadBuffer = (u8 *)MEM2_alloc(0x440); u8 *ReadBuffer = (u8 *)malloc(0x440);
if(ReadBuffer == NULL) if(ReadBuffer == NULL)
return false; return false;
u32 cover = 0; u32 cover = 0;
bool done = false; bool done = false;
while(!done) while(!done)
{ {
message( msg, dsc+1, minfo, u_data); message(msg, dsc+1, minfo, u_data);
while(1) while(1)
{ {
*(u32*)0xCD0000C0 |= 0x20; wiiLightOn();
usleep( 1000000 ); wiiLightSetLevel(255);
*(u32*)0xCD0000C0 &= ~0x20; usleep(1000000);
usleep( 1000000 ); wiiLightOff();
usleep(1000000);
WDVD_GetCoverStatus(&cover); WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2)) if(!(cover & 0x2))
break; break;
@ -192,16 +193,17 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg)
while(1) while(1)
{ {
*(u32*)0xCD0000C0 |= 0x20; wiiLightOn();
usleep( 1000000 ); wiiLightSetLevel(255);
*(u32*)0xCD0000C0 &= ~0x20; usleep(1000000);
usleep( 1000000 ); wiiLightOff();
usleep(1000000);
if(Disc_Wait() < 0) if(Disc_Wait() < 0)
continue; continue;
if(Disc_Open(true) < 0) if(Disc_Open(true) < 0)
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
return false; return false;
} }
@ -210,7 +212,7 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg)
s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440); s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
if(ret > 0) if(ret > 0)
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
return false; return false;
} }
@ -250,7 +252,7 @@ bool GCDump::__WaitForDisc(u8 dsc, u32 msg)
} }
} }
} }
MEM2_free(ReadBuffer); free(ReadBuffer);
return done; return done;
} }
@ -277,7 +279,7 @@ s32 GCDump::DumpGame()
{ {
static gc_discHdr gcheader ATTRIBUTE_ALIGN(32); static gc_discHdr gcheader ATTRIBUTE_ALIGN(32);
u8 *ReadBuffer = (u8 *)MEM2_alloc(gc_readsize); u8 *ReadBuffer = (u8 *)malloc(gc_readsize);
if(ReadBuffer == NULL) if(ReadBuffer == NULL)
return 0x31100; return 0x31100;
@ -341,7 +343,7 @@ s32 GCDump::DumpGame()
ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440); ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
if(ret > 0) if(ret > 0)
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
return 0x31100; return 0x31100;
} }
@ -358,7 +360,7 @@ s32 GCDump::DumpGame()
DOLSize = FSTOffset - DOLOffset; DOLSize = FSTOffset - DOLOffset;
DiscSize = DataSize + GamePartOffset; DiscSize = DataSize + GamePartOffset;
FSTBuffer = (u8 *)MEM2_alloc(ALIGN32(FSTSize)); FSTBuffer = (u8 *)malloc(ALIGN32(FSTSize));
if(FSTBuffer == NULL) if(FSTBuffer == NULL)
return 0x31100; return 0x31100;
@ -366,8 +368,8 @@ s32 GCDump::DumpGame()
if(ret > 0) if(ret > 0)
{ {
MEM2_free(FSTBuffer); free(FSTBuffer);
MEM2_free(ReadBuffer); free(ReadBuffer);
return 0x31100; return 0x31100;
} }
@ -484,8 +486,8 @@ s32 GCDump::DumpGame()
} }
else else
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
MEM2_free(FSTBuffer); free(FSTBuffer);
fclose(f); fclose(f);
return gc_error; return gc_error;
} }
@ -504,13 +506,13 @@ s32 GCDump::DumpGame()
ret = __DiscWrite(gamepath, NextOffset, DiscSize, ReadBuffer); ret = __DiscWrite(gamepath, NextOffset, DiscSize, ReadBuffer);
if( ret < 0 ) if( ret < 0 )
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
MEM2_free(FSTBuffer); free(FSTBuffer);
return gc_error; return gc_error;
} }
gprintf("Done!! Disc size: %d\n", DiscSize); gprintf("Done!! Disc size: %d\n", DiscSize);
} }
MEM2_free(FSTBuffer); free(FSTBuffer);
if((FSTTotal > FSTSize || __CheckMDHack(ID)) && !multigamedisc) if((FSTTotal > FSTSize || __CheckMDHack(ID)) && !multigamedisc)
{ {
@ -541,7 +543,7 @@ s32 GCDump::DumpGame()
gamedone = true; gamedone = true;
} }
MEM2_free(ReadBuffer); free(ReadBuffer);
return gc_skipped; return gc_skipped;
} }
@ -550,7 +552,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
{ {
static gc_discHdr gcheader ATTRIBUTE_ALIGN(32); static gc_discHdr gcheader ATTRIBUTE_ALIGN(32);
u8 *ReadBuffer = (u8 *)MEM2_alloc(0x440); u8 *ReadBuffer = (u8 *)malloc(0x440);
if(ReadBuffer == NULL) if(ReadBuffer == NULL)
return 1; return 1;
@ -582,7 +584,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440); s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
if(ret > 0) if(ret > 0)
{ {
MEM2_free(ReadBuffer); free(ReadBuffer);
return 1; return 1;
} }
@ -614,14 +616,14 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
} }
else else
{ {
u8 *FSTBuffer = (u8 *)MEM2_alloc(ALIGN32(FSTSize)); u8 *FSTBuffer = (u8 *)malloc(ALIGN32(FSTSize));
if(FSTBuffer == NULL) if(FSTBuffer == NULL)
return 1; return 1;
ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, ALIGN32(FSTSize)); ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, ALIGN32(FSTSize));
if(ret > 0) if(ret > 0)
{ {
MEM2_free(FSTBuffer); free(FSTBuffer);
return 1; return 1;
} }
@ -657,7 +659,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
multisize += fst[i].FileLength; multisize += fst[i].FileLength;
} }
} }
MEM2_free(FSTBuffer); free(FSTBuffer);
} }
size += multisize; size += multisize;
Gamesize[MultiGameDump] = multisize; Gamesize[MultiGameDump] = multisize;
@ -694,7 +696,7 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp)
else else
gamedone = true; gamedone = true;
} }
MEM2_free(ReadBuffer); free(ReadBuffer);
DiscSizeCalculated = size/0x400; DiscSizeCalculated = size/0x400;
*needed = (size/0x8000) >> 2; *needed = (size/0x8000) >> 2;
gprintf("Free space needed: %d Mb (%d blocks)\n", size/0x100000, (size/0x8000) >> 2); gprintf("Free space needed: %d Mb (%d blocks)\n", size/0x100000, (size/0x8000) >> 2);

View File

@ -23,10 +23,10 @@
* nk.c * nk.c
* *
***************************************************************************/ ***************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include "mem2.hpp" #include "mem2.hpp"
#include "nk.h" #include "nk.h"
@ -58,13 +58,11 @@ s32 Launch_nk(u64 TitleID, const char *nandpath)
DCFlushRange((void *)0x91000000, fsize); DCFlushRange((void *)0x91000000, fsize);
} }
else else
{
return 0; return 0;
}
fclose(file); fclose(file);
memcfg *MC = (memcfg*)MEM1_alloc(sizeof(memcfg)); memcfg *MC = (memcfg*)malloc(sizeof(memcfg));
if(MC == NULL) if(MC == NULL)
return 0; return 0;
@ -81,7 +79,7 @@ s32 Launch_nk(u64 TitleID, const char *nandpath)
memcpy((void *)0x81200000, MC, sizeof(memcfg)); memcpy((void *)0x81200000, MC, sizeof(memcfg));
DCFlushRange((void *)(0x81200000), sizeof(memcfg)); DCFlushRange((void *)(0x81200000), sizeof(memcfg));
MEM1_free(MC); free(MC);
/*** Thnx giantpune! ***/ /*** Thnx giantpune! ***/
void *mini = MEM1_memalign(32, armboot_size); void *mini = MEM1_memalign(32, armboot_size);

View File

@ -67,7 +67,7 @@ s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf)
if (mod) if (mod)
{ {
/* Allocate memory */ /* Allocate memory */
fp = MEM2_alloc(0x20); fp = malloc(0x20);
if (!fp) if (!fp)
return -1; return -1;
@ -85,7 +85,7 @@ s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf)
out: out:
/* Free memory */ /* Free memory */
MEM2_free(fp); free(fp);
return ret; return ret;
} }

View File

@ -52,7 +52,7 @@ wbfs_disc_t* WBFS_Ext_OpenDisc(u8 *discid, char *fname)
int fd = open(fname, O_RDONLY); int fd = open(fname, O_RDONLY);
if (fd == -1) return NULL; if (fd == -1) return NULL;
wbfs_disc_t *iso_file = MEM2_alloc(sizeof(wbfs_disc_t)); wbfs_disc_t *iso_file = malloc(sizeof(wbfs_disc_t));
memset(iso_file, 0, sizeof(wbfs_disc_t)); memset(iso_file, 0, sizeof(wbfs_disc_t));
if (iso_file == NULL) if (iso_file == NULL)
@ -81,7 +81,7 @@ void WBFS_Ext_CloseDisc(wbfs_disc_t* disc)
if (part == &wbfs_iso_file) if (part == &wbfs_iso_file)
{ {
close((int)disc->header); close((int)disc->header);
MEM2_free(disc); free(disc);
return; return;
} }

View File

@ -78,7 +78,7 @@ void wip_reset_counter()
void free_wip() void free_wip()
{ {
if(CodeList) if(CodeList)
MEM2_free(CodeList); free(CodeList);
CodesCount = 0; CodesCount = 0;
ProcessedLength = 0; ProcessedLength = 0;
@ -122,7 +122,7 @@ int load_wip_patches(u8 *dir, u8 *gameid)
WIP_Code *tmp = MEM2_realloc(CodeList, (CodesCount+1)*sizeof(WIP_Code)); WIP_Code *tmp = MEM2_realloc(CodeList, (CodesCount+1)*sizeof(WIP_Code));
if(!tmp) if(!tmp)
{ {
MEM2_free(CodeList); free(CodeList);
fclose(fp); fclose(fp);
return -1; return -1;
} }

View File

@ -74,11 +74,6 @@ void *MEM2_alloc(unsigned int s)
return g_mem2gp.allocate(s); return g_mem2gp.allocate(s);
} }
void *MEM2_memalign(unsigned int a, unsigned int s)
{
return g_mem2gp.allocate(ALIGN(a, s));
}
void *MEM2_realloc(void *p, unsigned int s) void *MEM2_realloc(void *p, unsigned int s)
{ {
return g_mem2gp.reallocate(p, s); return g_mem2gp.reallocate(p, s);
@ -138,15 +133,19 @@ void *__wrap_memalign(size_t a, size_t size)
void *p; void *p;
if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE) if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE)
{ {
p = MEM2_memalign(a, size); if(a <= 32 && 32 % a == 0)
if (p != 0) {
return p; p = g_mem2gp.allocate(size);
if (p != 0)
return p;
}
return __real_memalign(a, size); return __real_memalign(a, size);
} }
p = __real_memalign(a, size); p = __real_memalign(a, size);
if(p != 0) if(p != 0 || a > 32 || 32 % a != 0)
return p; return p;
return MEM2_memalign(a, size);
return g_mem2gp.allocate(size);
} }
void __wrap_free(void *p) void __wrap_free(void *p)

View File

@ -22,7 +22,6 @@ void MEM2_cleanup(void);
void MEM2_clear(void); void MEM2_clear(void);
void MEM2_free(void *p); void MEM2_free(void *p);
void *MEM2_alloc(unsigned int s); void *MEM2_alloc(unsigned int s);
void *MEM2_memalign(unsigned int a, unsigned int s);
void *MEM2_realloc(void *p, unsigned int s); void *MEM2_realloc(void *p, unsigned int s);
unsigned int MEM2_usableSize(void *p); unsigned int MEM2_usableSize(void *p);
unsigned int MEM2_freesize(); unsigned int MEM2_freesize();

View File

@ -145,7 +145,8 @@ CMenu::CMenu(CVideo &vid) :
m_current_view = COVERFLOW_USB; m_current_view = COVERFLOW_USB;
m_Emulator_boot = false; m_Emulator_boot = false;
m_banner = new BannerWindow; m_banner = new BannerWindow;
m_music = new MusicPlayer; m_music = new MusicPlayer; //Voice 0
m_gameSound = new GuiSound; //Voice 1
} }
void CMenu::init(void) void CMenu::init(void)
@ -1827,17 +1828,17 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting)
Sys_Test(); Sys_Test();
} }
if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound.IsPlaying() && m_music->GetVolume() == 0) if(withCF && m_gameSelected && m_gamesound_changed && (m_gameSoundHdr == NULL) && !m_gameSound->IsPlaying() && m_music->GetVolume() == 0)
{ {
CheckGameSoundThread(); CheckGameSoundThread();
m_gameSound.Play(m_bnrSndVol); m_gameSound->Play(m_bnrSndVol);
m_gamesound_changed = false; m_gamesound_changed = false;
} }
else if(!m_gameSelected) else if(!m_gameSelected)
m_gameSound.Stop(); m_gameSound->Stop();
m_music->Tick(m_video_playing || (m_gameSelected && m_music->Tick(m_video_playing || (m_gameSelected &&
m_gameSound.IsLoaded()) || m_gameSound.IsPlaying()); m_gameSound->IsLoaded()) || m_gameSound->IsPlaying());
//Take Screenshot //Take Screenshot
if(gc_btnsPressed & PAD_TRIGGER_Z) if(gc_btnsPressed & PAD_TRIGGER_Z)
@ -2258,11 +2259,11 @@ void CMenu::_stopSounds(void)
if(!m_music->IsStopped()) if(!m_music->IsStopped())
{ {
while(m_music->GetVolume() > 0 || m_gameSound.GetVolume() > 0) while(m_music->GetVolume() > 0 || m_gameSound->GetVolume() > 0)
{ {
m_music->Tick(true); m_music->Tick(true);
if(m_gameSound.GetVolume() > 0) if(m_gameSound->GetVolume() > 0)
m_gameSound.SetVolume(m_gameSound.GetVolume() < fade_rate ? 0 : m_gameSound.GetVolume() - fade_rate); m_gameSound->SetVolume(m_gameSound->GetVolume() < fade_rate ? 0 : m_gameSound->GetVolume() - fade_rate);
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
} }
@ -2270,7 +2271,7 @@ void CMenu::_stopSounds(void)
m_cf.stopSound(); m_cf.stopSound();
m_music->Stop(); m_music->Stop();
m_gameSound.Stop(); m_gameSound->Stop();
} }
bool CMenu::_loadFile(SmartBuf &buffer, u32 &size, const char *path, const char *file) bool CMenu::_loadFile(SmartBuf &buffer, u32 &size, const char *path, const char *file)
@ -2379,7 +2380,7 @@ retry:
memcpy(m_base_font.get(), font_file, size); memcpy(m_base_font.get(), font_file, size);
if(!!m_base_font) if(!!m_base_font)
m_base_font_size = size; m_base_font_size = size;
MEM2_free(u8_font_archive); free(u8_font_archive);
} }
break; break;
} }
@ -2400,7 +2401,7 @@ retry:
m_wbf2_font = smartMem2Alloc(size); m_wbf2_font = smartMem2Alloc(size);
memcpy(m_wbf2_font.get(), font_file2, size); memcpy(m_wbf2_font.get(), font_file2, size);
MEM2_free(u8_font_archive); free(u8_font_archive);
} }
} }
} }
@ -2411,7 +2412,7 @@ retry:
goto retry; goto retry;
} }
MEM2_free(content); free(content);
} }
void CMenu::_cleanupDefaultFont() void CMenu::_cleanupDefaultFont()
@ -2491,16 +2492,16 @@ int CMenu::MIOSisDML()
if(*(vu32*)(appfile+j) == 0x4C697465) if(*(vu32*)(appfile+j) == 0x4C697465)
{ {
gprintf("DIOS-MIOS Lite is installed as MIOS\n"); gprintf("DIOS-MIOS Lite is installed as MIOS\n");
MEM2_free(appfile); free(appfile);
return 2; return 2;
} }
} }
gprintf("DIOS-MIOS is installed as MIOS\n"); gprintf("DIOS-MIOS is installed as MIOS\n");
MEM2_free(appfile); free(appfile);
return 1; return 1;
} }
} }
MEM2_free(appfile); free(appfile);
} }
gprintf("DIOS-MIOS (Lite) not found\n"); gprintf("DIOS-MIOS (Lite) not found\n");
return 0; return 0;

View File

@ -682,7 +682,7 @@ private:
volatile float m_fileProgress; volatile float m_fileProgress;
volatile bool m_thrdMessageAdded; volatile bool m_thrdMessageAdded;
volatile bool m_gameSelected; volatile bool m_gameSelected;
GuiSound m_gameSound; GuiSound *m_gameSound;
SmartGuiSound m_cameraSound; SmartGuiSound m_cameraSound;
dir_discHdr *m_gameSoundHdr; dir_discHdr *m_gameSoundHdr;
lwp_t m_gameSoundThread; lwp_t m_gameSoundThread;

View File

@ -120,12 +120,13 @@ void CMenu::_textAbout(void)
{ {
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
u32 fsize = ftell(f); u32 fsize = ftell(f);
char *help = (char*)MEM2_alloc(fsize+1); //+1 for null character char *help = (char*)malloc(fsize + 1); //+1 for null character
memset(help, 0, fsize + 1);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
fread(help, 1, fsize, f); fread(help, 1, fsize, f);
help[fsize] = '\0'; help[fsize] = '\0';
help_text.fromUTF8(help); help_text.fromUTF8(help);
MEM2_free(help); free(help);
fclose(f); fclose(f);
} }
else else
@ -163,6 +164,6 @@ void CMenu::_textAbout(void)
if(iosInfo != NULL) if(iosInfo != NULL)
{ {
m_btnMgr.setText(m_aboutLblIOS, wfmt(_fmt("ios", L"IOS%i base %i v%i"), mainIOS, iosInfo->baseios, iosInfo->version), true); m_btnMgr.setText(m_aboutLblIOS, wfmt(_fmt("ios", L"IOS%i base %i v%i"), mainIOS, iosInfo->baseios, iosInfo->version), true);
MEM2_free(iosInfo); free(iosInfo);
} }
} }

View File

@ -404,7 +404,7 @@ bool CMenu::_isNetworkAvailable()
if (buf && size > 4) if (buf && size > 4)
{ {
retval = buf[4] > 0; // There is a valid connection defined. retval = buf[4] > 0; // There is a valid connection defined.
MEM2_free(buf); free(buf);
} }
return retval; return retval;
} }

View File

@ -426,13 +426,13 @@ void CMenu::_game(bool launch)
m_banner->DeleteBanner(); m_banner->DeleteBanner();
_CategorySettings(true); _CategorySettings(true);
_showGame(); _showGame();
if (!m_gameSound.IsPlaying()) if (!m_gameSound->IsPlaying())
startGameSound = -6; startGameSound = -6;
continue; continue;
} }
if(BTN_HOME_PRESSED || BTN_B_PRESSED) if(BTN_HOME_PRESSED || BTN_B_PRESSED)
{ {
m_gameSound.FreeMemory(); m_gameSound->FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
@ -445,7 +445,7 @@ void CMenu::_game(bool launch)
m_gameSelected = true; m_gameSelected = true;
_gameinfo(); _gameinfo();
_showGame(); _showGame();
if (!m_gameSound.IsPlaying()) if (!m_gameSound->IsPlaying())
startGameSound = -6; startGameSound = -6;
} }
else if(BTN_MINUS_PRESSED) else if(BTN_MINUS_PRESSED)
@ -476,7 +476,7 @@ void CMenu::_game(bool launch)
_showGame(); _showGame();
m_music->Play(); m_music->Play();
m_video_playing = false; m_video_playing = false;
//m_gameSound.play(m_bnrSndVol); //m_gameSound->play(m_bnrSndVol);
} }
} }
else if((BTN_1_PRESSED) || (BTN_2_PRESSED)) else if((BTN_1_PRESSED) || (BTN_2_PRESSED))
@ -499,7 +499,7 @@ void CMenu::_game(bool launch)
_hideGame(); _hideGame();
if(_wbfsOp(CMenu::WO_REMOVE_GAME)) if(_wbfsOp(CMenu::WO_REMOVE_GAME))
{ {
m_gameSound.Stop(); m_gameSound->Stop();
CheckGameSoundThread(); CheckGameSoundThread();
break; break;
} }
@ -512,7 +512,7 @@ void CMenu::_game(bool launch)
m_gcfg1.setBool("ADULTONLY", id, !m_gcfg1.getBool("ADULTONLY", id, false)); m_gcfg1.setBool("ADULTONLY", id, !m_gcfg1.getBool("ADULTONLY", id, false));
else if(m_btnMgr.selected(m_gameBtnBack) || m_btnMgr.selected(m_gameBtnBackFull)) else if(m_btnMgr.selected(m_gameBtnBack) || m_btnMgr.selected(m_gameBtnBackFull))
{ {
m_gameSound.FreeMemory(); m_gameSound->FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack(); ClearGameSoundThreadStack();
m_banner->DeleteBanner(); m_banner->DeleteBanner();
@ -534,7 +534,7 @@ void CMenu::_game(bool launch)
m_banner->ToogleGameSettings(); m_banner->ToogleGameSettings();
_showGame(); _showGame();
if(!m_gameSound.IsPlaying()) if(!m_gameSound->IsPlaying())
startGameSound = -6; startGameSound = -6;
} }
else if(launch || m_btnMgr.selected(m_gameBtnPlay) || m_btnMgr.selected(m_gameBtnPlayFull) || (!WPadIR_Valid(0) && !WPadIR_Valid(1) && !WPadIR_Valid(2) && !WPadIR_Valid(3) && m_btnMgr.selected((u16)-1))) else if(launch || m_btnMgr.selected(m_gameBtnPlay) || m_btnMgr.selected(m_gameBtnPlayFull) || (!WPadIR_Valid(0) && !WPadIR_Valid(1) && !WPadIR_Valid(2) && !WPadIR_Valid(3) && m_btnMgr.selected((u16)-1)))
@ -637,7 +637,7 @@ void CMenu::_game(bool launch)
} }
if(startGameSound == -10) if(startGameSound == -10)
{ {
m_gameSound.Stop(); m_gameSound->Stop();
m_gameSelected = false; m_gameSelected = false;
m_fa.unload(); m_fa.unload();
m_banner->DeleteBanner(true); m_banner->DeleteBanner(true);
@ -824,31 +824,31 @@ void CMenu::_launchGC(dir_discHdr *hdr, bool disc)
loader = 1; loader = 1;
m_cfg.setString("DML", "current_item", id); m_cfg.setString("DML", "current_item", id);
char CheatPath[256]; char CheatPath[256];
char NewCheatPath[255];
u8 NMM = min((u32)m_gcfg2.getInt(id, "dml_nmm", 0), ARRAY_SIZE(CMenu::_NMM) - 1u); u8 NMM = min((u32)m_gcfg2.getInt(id, "dml_nmm", 0), ARRAY_SIZE(CMenu::_NMM) - 1u);
NMM = (NMM == 0) ? m_cfg.getInt("DML", "dml_nmm", 0) : NMM-1; NMM = (NMM == 0) ? m_cfg.getInt("DML", "dml_nmm", 0) : NMM-1;
u8 nodisc = min((u32)m_gcfg2.getInt(id, "no_disc_patch", 0), ARRAY_SIZE(CMenu::_NoDVD) - 1u); u8 nodisc = min((u32)m_gcfg2.getInt(id, "no_disc_patch", 0), ARRAY_SIZE(CMenu::_NoDVD) - 1u);
nodisc = (nodisc == 0) ? m_cfg.getInt("DML", "no_disc_patch", 0) : nodisc-1; nodisc = (nodisc == 0) ? m_cfg.getInt("DML", "no_disc_patch", 0) : nodisc-1;
bool cheats = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("DML", "cheat", false)); bool cheats = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("DML", "cheat", false));
string NewCheatPath;
bool DML_debug = m_gcfg2.getBool(id, "debugger", false); bool DML_debug = m_gcfg2.getBool(id, "debugger", false);
bool DM_Widescreen = m_gcfg2.getBool(id, "dm_widescreen", false); bool DM_Widescreen = m_gcfg2.getBool(id, "dm_widescreen", false);
if(cheats)
{
snprintf(CheatPath, sizeof(CheatPath), "%s/%s", m_cheatDir.c_str(), fmt("%s.gct", id.c_str()));
snprintf(NewCheatPath, sizeof(NewCheatPath), "%s/%s/%s", fmt(DML_DIR, DeviceName[currentPartition]), path.c_str(), fmt("%s.gct", id.c_str()));
}
string newPath;
if(strcasestr(path.c_str(), "boot.bin") != NULL) if(strcasestr(path.c_str(), "boot.bin") != NULL)
{ {
newPath = &path[path.find_first_of(":/")+1]; path.erase(path.end() - 12, path.end());
newPath.erase(newPath.end() - 12, newPath.end()); NewCheatPath = sfmt("%s%s", path.c_str(), fmt("%s.gct", id.c_str()));
} }
else else
newPath = &path[path.find_first_of(":/")+1]; {
NewCheatPath = sfmt("%s%s", path.c_str(), fmt("%s.gct", id.c_str()));
path.erase(path.end() - 19, path.end() - 11);
}
if(cheats)
snprintf(CheatPath, sizeof(CheatPath), "%s/%s", m_cheatDir.c_str(), fmt("%s.gct", id.c_str()));
string newPath = &path[path.find_first_of(":/")+1];
if(m_new_dml) if(m_new_dml)
DML_New_SetOptions(newPath.c_str(), CheatPath, NewCheatPath, DeviceName[currentPartition], cheats, DML_debug, NMM, nodisc, videoMode, videoSetting, DM_Widescreen, m_new_dm_cfg); DML_New_SetOptions(newPath.c_str(), CheatPath, NewCheatPath.c_str(), DeviceName[currentPartition], cheats, DML_debug, NMM, nodisc, videoMode, videoSetting, DM_Widescreen, m_new_dm_cfg);
else else
DML_Old_SetOptions((char*)path.c_str(), CheatPath, NewCheatPath, cheats); DML_Old_SetOptions(newPath.c_str());
if(!nodisc || !m_new_dml) if(!nodisc || !m_new_dml)
{ {
@ -1193,10 +1193,10 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
else else
{ {
/* Read GC disc header */ /* Read GC disc header */
struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr)); struct gc_discHdr *gcHeader = (struct gc_discHdr *)malloc(sizeof(struct gc_discHdr));
Disc_ReadGCHeader(gcHeader); Disc_ReadGCHeader(gcHeader);
strncpy(hdr->id, (char*)gcHeader->id, 6); strncpy(hdr->id, (char*)gcHeader->id, 6);
MEM2_free(gcHeader); free(gcHeader);
/* Launching GC Game */ /* Launching GC Game */
_launchGC(hdr, true); _launchGC(hdr, true);
} }
@ -1204,10 +1204,10 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
else else
{ {
/* Read header */ /* Read header */
struct discHdr *header = (struct discHdr *)MEM2_alloc(sizeof(struct discHdr)); struct discHdr *header = (struct discHdr *)malloc(sizeof(struct discHdr));
Disc_ReadHeader(header); Disc_ReadHeader(header);
id = string((const char*)header->id); id = string((const char*)header->id);
MEM2_free(header); free(header);
} }
gprintf("Game ID: %s\n", id.c_str()); gprintf("Game ID: %s\n", id.c_str());
} }
@ -1518,10 +1518,11 @@ u32 gameSoundThreadStackSize = (u32)32768;
void CMenu::_gameSoundThread(CMenu *m) void CMenu::_gameSoundThread(CMenu *m)
{ {
m->m_gameSoundHdr = m->m_cf.getHdr(); m->m_gameSoundHdr = m->m_cf.getHdr();
if(m->m_cf.getHdr()->type == TYPE_PLUGIN) if(m->m_cf.getHdr()->type == TYPE_PLUGIN)
{ {
m_banner->DeleteBanner(); m_banner->DeleteBanner();
m->m_gameSound.Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize(), false); m->m_gameSound->Load(m->m_plugin.GetBannerSound(m->m_cf.getHdr()->settings[0]), m->m_plugin.GetBannerSoundSize(), false);
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
return; return;
@ -1547,7 +1548,13 @@ void CMenu::_gameSoundThread(CMenu *m)
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
cached_bnr_size = ftell(fp); cached_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
cached_bnr_file = (u8*)MEM2_alloc(cached_bnr_size); cached_bnr_file = (u8*)malloc(cached_bnr_size);
if(cached_bnr_file == NULL)
{
m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL;
return;
}
fread(cached_bnr_file, 1, cached_bnr_size, fp); fread(cached_bnr_file, 1, cached_bnr_size, fp);
fclose(fp); fclose(fp);
} }
@ -1567,64 +1574,79 @@ void CMenu::_gameSoundThread(CMenu *m)
u8 *opening_bnr = disc.GetGameCubeBanner(); u8 *opening_bnr = disc.GetGameCubeBanner();
if(opening_bnr != NULL) if(opening_bnr != NULL)
m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title); m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title);
m->m_gameSound.Load(gc_ogg, gc_ogg_size, false); m->m_gameSound->Load(gc_ogg, gc_ogg_size, false);
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
disc.clear();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
disc.clear();
return; return;
} }
} }
if(fp) if(fp)
{ {
custom = true; custom = true;
gprintf("Custom Banner detected for: %s\n", m->m_cf.getHdr()->id);
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
custom_bnr_size = ftell(fp); custom_bnr_size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
custom_bnr_file = (u8*)MEM2_alloc(custom_bnr_size); custom_bnr_file = (u8*)malloc(custom_bnr_size);
if(custom_bnr_file == NULL)
{
m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL;
return;
}
fread(custom_bnr_file, 1, custom_bnr_size, fp); fread(custom_bnr_file, 1, custom_bnr_size, fp);
fclose(fp); fclose(fp);
} }
} }
m->m_gamesound_changed = false; m->m_gamesound_changed = false;
u32 sndSize = 0; u32 sndSize = 0;
u8 *soundBin = NULL;
Banner *banner = cached ? new Banner((u8 *)cached_bnr_file, cached_bnr_size) : Banner *banner = cached ? new Banner(cached_bnr_file, cached_bnr_size) :
(custom ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) : (custom ? new Banner((u8 *)custom_bnr_file, custom_bnr_size, 0, true) :
(m->m_gameSoundHdr->type == TYPE_WII_GAME ? _extractBnr(m->m_gameSoundHdr) : (m->m_gameSoundHdr->type == TYPE_CHANNEL ? (m->m_gameSoundHdr->type == TYPE_WII_GAME ? _extractBnr(m->m_gameSoundHdr) : (m->m_gameSoundHdr->type == TYPE_CHANNEL ?
_extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL))); _extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL)));
if(banner != NULL && banner->IsValid())
if (banner == NULL || !banner->IsValid()) {
m_banner->LoadBanner(banner, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get());
soundBin = banner->GetFile((char *)"sound.bin", &sndSize);
}
if(banner == NULL || soundBin == NULL || sndSize == 0)
{ {
gprintf("no valid banner found\n");
m_banner->DeleteBanner(); m_banner->DeleteBanner();
delete banner;
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
delete banner;
return; return;
} }
else if(!custom && !cached) if(!custom && !cached)
{ {
FILE *fp = fopen(cached_banner, "wb"); FILE *fp = fopen(cached_banner, "wb");
fwrite(banner->GetBannerFile(), 1, banner->GetBannerFileSize(), fp); fwrite(banner->GetBannerFile(), 1, banner->GetBannerFileSize(), fp);
fclose(fp); fclose(fp);
} }
_extractBannerTitle(banner, GetLanguage(m->m_loc.getString(m->m_curLanguage, "gametdb_code", "EN").c_str()));
const u8 *soundBin = banner->GetFile((char *) "sound.bin", &sndSize);
m_banner->LoadBanner(banner, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get());
delete banner; delete banner;
if (soundBin == NULL || (((IMD5Header *)soundBin)->fcc != 'IMD5' && ((IMD5Header *)soundBin)->fcc != 'RIFF')) if(((IMD5Header *)soundBin)->fcc == 'IMD5')
{ {
gprintf("Failed to load banner sound!\n\n"); u32 newSize = 0;
if(soundBin != NULL) u8 *newSound = DecompressCopy(soundBin, sndSize, &newSize);
delete soundBin; if(newSound == NULL || newSize == 0 || !m->m_gameSound->Load(newSound, newSize))
m->m_gameSoundHdr = NULL; {
return; if(newSound != NULL)
free(newSound);
m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL;
return;
}
free(soundBin);
} }
else
m->m_gameSound->Load(soundBin, sndSize);
m->m_gameSound.Load(soundBin, sndSize, false); if(m->m_gameSound->IsLoaded())
m->m_gamesound_changed = true; m->m_gamesound_changed = true;
else
m_banner->DeleteBanner();
m->m_gameSoundHdr = NULL; m->m_gameSoundHdr = NULL;
} }
@ -1638,17 +1660,20 @@ void CMenu::_playGameSound(void)
CheckGameSoundThread(); CheckGameSoundThread();
if(!gameSoundThreadStack.get()) if(!gameSoundThreadStack.get())
gameSoundThreadStack = smartMem2Alloc(gameSoundThreadStackSize); gameSoundThreadStack = smartMem2Alloc(gameSoundThreadStackSize);
LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, gameSoundThreadStack.get(), gameSoundThreadStackSize, 60); LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, gameSoundThreadStack.get(), gameSoundThreadStackSize, 60);
} }
void CMenu::CheckGameSoundThread() void CMenu::CheckGameSoundThread()
{ {
if(m_gameSoundThread == LWP_THREAD_NULL)
return;
if(LWP_ThreadIsSuspended(m_gameSoundThread)) if(LWP_ThreadIsSuspended(m_gameSoundThread))
LWP_ResumeThread(m_gameSoundThread); LWP_ResumeThread(m_gameSoundThread);
while(m_gameSoundHdr != NULL) while(m_gameSoundHdr != NULL)
usleep(50); usleep(50);
LWP_JoinThread(m_gameSoundThread, NULL); LWP_JoinThread(m_gameSoundThread, NULL);
m_gameSoundThread = LWP_THREAD_NULL; m_gameSoundThread = LWP_THREAD_NULL;
} }

View File

@ -23,14 +23,14 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <malloc.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include "mem2.hpp"
#include "BNSDecoder.hpp" #include "BNSDecoder.hpp"
SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
BNSDecoder::BNSDecoder(const char * filepath) BNSDecoder::BNSDecoder(const char * filepath)
: SoundDecoder(filepath) : SoundDecoder(filepath)
{ {
@ -61,12 +61,15 @@ BNSDecoder::~BNSDecoder()
while(Decoding) while(Decoding)
usleep(100); usleep(100);
MEM2_free(SoundData.buffer); if(SoundData.buffer != NULL)
free(SoundData.buffer);
SoundData.buffer = NULL;
} }
void BNSDecoder::OpenFile() void BNSDecoder::OpenFile()
{ {
u8 *tempbuff = new (std::nothrow) u8[file_fd->size()]; u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
if(!tempbuff) if(!tempbuff)
{ {
CloseFile(); CloseFile();
@ -77,7 +80,7 @@ void BNSDecoder::OpenFile()
while(done < file_fd->size()) while(done < file_fd->size())
{ {
int read = file_fd->read(tempbuff, file_fd->size()); int read = file_fd->read(tempbuff+done, file_fd->size()-done);
if(read > 0) if(read > 0)
done += read; done += read;
else else
@ -264,7 +267,7 @@ static u8 * decodeBNS(u32 &size, const BNSInfo &bnsInfo, const BNSData &bnsData)
int numBlocks = (bnsData.size - 8) / 8; int numBlocks = (bnsData.size - 8) / 8;
int numSamples = numBlocks * 14; int numSamples = numBlocks * 14;
const BNSADPCMBlock *inputBuf = (const BNSADPCMBlock *)&bnsData.data; const BNSADPCMBlock *inputBuf = (const BNSADPCMBlock *)&bnsData.data;
u8 * buffer = (u8 *)MEM2_alloc(numSamples * sizeof (s16)); u8 * buffer = (u8 *) malloc(numSamples * sizeof (s16));
s16 *outputBuf; s16 *outputBuf;
if (!buffer) if (!buffer)
@ -321,7 +324,7 @@ SoundBlock DecodefromBNS(const u8 *buffer, u32 size)
// Check sizes // Check sizes
if (size < hdr.size || size < hdr.infoOffset + hdr.infoSize || size < hdr.dataOffset + hdr.dataSize if (size < hdr.size || size < hdr.infoOffset + hdr.infoSize || size < hdr.dataOffset + hdr.dataSize
|| hdr.infoSize < 0x60 || hdr.dataSize < sizeof dataChunk || hdr.infoSize < 0x60 || hdr.dataSize < sizeof dataChunk
|| infoChunk.size != hdr.infoSize || dataChunk.size != hdr.dataSize) || infoChunk.size != hdr.infoSize || dataChunk.size > hdr.dataSize)
return OutBlock; return OutBlock;
// Check format // Check format
if (infoChunk.codecNum != 0) // Only codec i've found : 0 = ADPCM. Maybe there's also 1 and 2 for PCM 8 or 16 bits ? if (infoChunk.codecNum != 0) // Only codec i've found : 0 = ADPCM. Maybe there's also 1 and 2 for PCM 8 or 16 bits ?
@ -344,7 +347,7 @@ SoundBlock DecodefromBNS(const u8 *buffer, u32 size)
} }
else else
{ {
OutBlock.buffer = (u8*)MEM2_alloc(dataChunk.size); OutBlock.buffer = (u8*) malloc(dataChunk.size);
if (!OutBlock.buffer) if (!OutBlock.buffer)
return OutBlock; return OutBlock;
memcpy(OutBlock.buffer, &dataChunk.data, dataChunk.size); memcpy(OutBlock.buffer, &dataChunk.data, dataChunk.size);

View File

@ -30,7 +30,7 @@
typedef struct _SoundBlock typedef struct _SoundBlock
{ {
u8 *buffer; u8 * buffer;
u32 size; u32 size;
u8 format; u8 format;
u32 frequency; u32 frequency;
@ -44,7 +44,7 @@ class BNSDecoder : public SoundDecoder
public: public:
BNSDecoder(const char * filepath); BNSDecoder(const char * filepath);
BNSDecoder(const u8 * snd, int len); BNSDecoder(const u8 * snd, int len);
~BNSDecoder(); virtual ~BNSDecoder();
int GetFormat() { return SoundData.format; }; int GetFormat() { return SoundData.format; };
int GetSampleRate() { return SoundData.frequency; }; int GetSampleRate() { return SoundData.frequency; };
int Read(u8 * buffer, int buffer_size, int pos); int Read(u8 * buffer, int buffer_size, int pos);
@ -54,6 +54,4 @@ protected:
SoundBlock SoundData; SoundBlock SoundData;
}; };
SoundBlock DecodefromBNS(const u8 *buffer, u32 size);
#endif #endif

View File

@ -23,7 +23,8 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include "mem2.hpp" #include <malloc.h>
#include "BufferCircle.hpp" #include "BufferCircle.hpp"
#include "utils.h" #include "utils.h"
@ -51,10 +52,10 @@ void BufferCircle::SetBufferBlockSize(int size)
for(int i = 0; i < Size(); i++) for(int i = 0; i < Size(); i++)
{ {
if(SoundBuffer[i] != NULL) if(SoundBuffer[i] != NULL)
MEM2_free(SoundBuffer[i]); free(SoundBuffer[i]);
SoundBuffer[i] = (u8 *)MEM2_memalign(32, BufferBlockSize); SoundBuffer[i] = (u8 *)malloc(BufferBlockSize);
memset(SoundBuffer[i], 0, sizeof(SoundBuffer[i])); memset(SoundBuffer[i], 0, BufferBlockSize);
BufferSize[i] = 0; BufferSize[i] = 0;
BufferReady[i] = false; BufferReady[i] = false;
} }
@ -75,8 +76,8 @@ void BufferCircle::Resize(int size)
{ {
if(BufferBlockSize > 0) if(BufferBlockSize > 0)
{ {
SoundBuffer[i] = (u8 *)MEM2_memalign(32, BufferBlockSize); SoundBuffer[i] = (u8 *)malloc(BufferBlockSize);
memset(SoundBuffer[i], 0, sizeof(SoundBuffer[i])); memset(SoundBuffer[i], 0, BufferBlockSize);
} }
else else
SoundBuffer[i] = NULL; SoundBuffer[i] = NULL;
@ -91,7 +92,7 @@ void BufferCircle::RemoveBuffer(int pos)
return; return;
if(SoundBuffer[pos] != NULL) if(SoundBuffer[pos] != NULL)
MEM2_free(SoundBuffer[pos]); free(SoundBuffer[pos]);
SoundBuffer.erase(SoundBuffer.begin()+pos); SoundBuffer.erase(SoundBuffer.begin()+pos);
BufferSize.erase(BufferSize.begin()+pos); BufferSize.erase(BufferSize.begin()+pos);
@ -113,7 +114,7 @@ void BufferCircle::FreeBuffer()
for(int i = 0; i < Size(); i++) for(int i = 0; i < Size(); i++)
{ {
if(SoundBuffer[i] != NULL) if(SoundBuffer[i] != NULL)
MEM2_free(SoundBuffer[i]); free(SoundBuffer[i]);
BufferSize[i] = 0; BufferSize[i] = 0;
BufferReady[i] = false; BufferReady[i] = false;
} }

View File

@ -28,9 +28,9 @@
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <malloc.h>
#include "Mp3Decoder.hpp" #include "Mp3Decoder.hpp"
#include "mem2.hpp"
Mp3Decoder::Mp3Decoder(const char * filepath) Mp3Decoder::Mp3Decoder(const char * filepath)
: SoundDecoder(filepath) : SoundDecoder(filepath)
@ -74,13 +74,13 @@ Mp3Decoder::~Mp3Decoder()
mad_frame_finish(&Frame); mad_frame_finish(&Frame);
mad_stream_finish(&Stream); mad_stream_finish(&Stream);
MEM2_free(ReadBuffer); free(ReadBuffer);
} }
void Mp3Decoder::OpenFile() void Mp3Decoder::OpenFile()
{ {
GuardPtr = NULL; GuardPtr = NULL;
ReadBuffer = (u8 *)MEM2_alloc(SoundBlockSize * SoundBlocks); ReadBuffer = (u8 *)malloc(SoundBlockSize * SoundBlocks);
if(!ReadBuffer) if(!ReadBuffer)
{ {
if(file_fd) if(file_fd)

View File

@ -24,15 +24,15 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include "SoundHandler.hpp" #include "SoundHandler.hpp"
#include "Mp3Decoder.hpp" #include "Mp3Decoder.hpp"
#include "OggDecoder.hpp" #include "OggDecoder.hpp"
#include "WavDecoder.hpp" #include "WavDecoder.hpp"
#include "AifDecoder.hpp" #include "AifDecoder.hpp"
#include "BNSDecoder.hpp" #include "BNSDecoder.hpp"
#include "gecko/gecko.h" #include "gecko/gecko.h"
#include "mem2.hpp"
SoundHandler * SoundHandler::instance = NULL; SoundHandler * SoundHandler::instance = NULL;
@ -43,11 +43,11 @@ SoundHandler::SoundHandler()
for(u32 i = 0; i < MAX_DECODERS; ++i) for(u32 i = 0; i < MAX_DECODERS; ++i)
DecoderList[i] = NULL; DecoderList[i] = NULL;
ThreadStack = (u8 *)MEM2_memalign(32, 32768); ThreadStack = (u8 *)memalign(32, 32768);
if(!ThreadStack) if(!ThreadStack)
return; return;
LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80); LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST);
gprintf("SHND: Running sound thread\n"); gprintf("SHND: Running sound thread\n");
} }
@ -61,7 +61,7 @@ SoundHandler::~SoundHandler()
SoundThread = LWP_THREAD_NULL; SoundThread = LWP_THREAD_NULL;
if(ThreadStack != NULL) if(ThreadStack != NULL)
{ {
MEM2_free(ThreadStack); free(ThreadStack);
ThreadStack = NULL; ThreadStack = NULL;
} }
@ -99,13 +99,19 @@ void SoundHandler::AddDecoder(int voice, const char * filepath)
void SoundHandler::AddDecoder(int voice, const u8 * snd, int len) void SoundHandler::AddDecoder(int voice, const u8 * snd, int len)
{ {
if(voice < 0 || voice >= MAX_DECODERS) if(voice < 0 || voice >= MAX_DECODERS)
{
gprintf("SoundHandler: Invalid voice!\n");
return; return;
}
if (snd == NULL || len == 0) if(snd == NULL || len == 0)
{
gprintf("SoundHandler: Invalid sound!\n");
return; return;
}
if(DecoderList[voice] != NULL) if(DecoderList[voice] != NULL)
RemoveDecoder(voice); RemoveDecoder(voice);
DecoderList[voice] = GetSoundDecoder(snd, len); DecoderList[voice] = GetSoundDecoder(snd, len);
} }

View File

@ -30,6 +30,7 @@
#include "musicplayer.h" #include "musicplayer.h"
#include "WavDecoder.hpp" #include "WavDecoder.hpp"
#include "loader/sys.h" #include "loader/sys.h"
#include "banner/AnimatedBanner.h"
#define MAX_SND_VOICES 16 #define MAX_SND_VOICES 16
@ -37,19 +38,19 @@ using namespace std;
static bool VoiceUsed[MAX_SND_VOICES] = static bool VoiceUsed[MAX_SND_VOICES] =
{ {
true, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false false, false, false, false
}; };
static inline int GetFirstUnusedVoice() static inline int GetFirstUnusedVoice()
{ {
for(int i = 1; i < MAX_SND_VOICES; i++) for(u8 i = 0; i < MAX_SND_VOICES; i++)
{ {
if(VoiceUsed[i] == false) if(VoiceUsed[i] == false)
return i; return i;
} }
gprintf("ALL VOICES USED UP!!\n"); gprintf("gui_sound.cpp: ALL VOICES USED UP!!\n");
return -1; return -1;
} }
@ -75,20 +76,20 @@ extern "C" void SoundCallback(s32 voice)
GuiSound::GuiSound() GuiSound::GuiSound()
{ {
voice = -1; this->voice = -1;
Init(); Init();
} }
GuiSound::GuiSound(string filepath, int v) GuiSound::GuiSound(string filepath, int v)
{ {
voice = v; this->voice = v;
Init(); Init();
Load(filepath.c_str()); Load(filepath.c_str());
} }
GuiSound::GuiSound(const u8 * snd, u32 len, string name, bool isallocated, int v) GuiSound::GuiSound(const u8 * snd, u32 len, string name, bool isallocated, int v)
{ {
voice = v; this->voice = v;
Init(); Init();
Load(snd, len, isallocated); Load(snd, len, isallocated);
this->filepath = name; this->filepath = name;
@ -96,7 +97,7 @@ GuiSound::GuiSound(const u8 * snd, u32 len, string name, bool isallocated, int v
GuiSound::GuiSound(GuiSound *g) GuiSound::GuiSound(GuiSound *g)
{ {
voice = -1; this->voice = -1;
Init(); Init();
if(g == NULL) if(g == NULL)
@ -104,7 +105,7 @@ GuiSound::GuiSound(GuiSound *g)
if(g->sound != NULL) if(g->sound != NULL)
{ {
u8 *snd = (u8 *) malloc(g->length); u8 *snd = (u8 *)malloc(g->length);
memcpy(snd, g->sound, g->length); memcpy(snd, g->sound, g->length);
Load(snd, g->length, true); Load(snd, g->length, true);
} }
@ -115,7 +116,7 @@ GuiSound::GuiSound(GuiSound *g)
GuiSound::~GuiSound() GuiSound::~GuiSound()
{ {
FreeMemory(); FreeMemory();
VoiceUsed[voice] = false; VoiceUsed[this->voice] = false;
} }
void GuiSound::Init() void GuiSound::Init()
@ -123,10 +124,10 @@ void GuiSound::Init()
sound = NULL; sound = NULL;
length = 0; length = 0;
if (voice == -1) if(this->voice == -1)
voice = GetFirstUnusedVoice(); this->voice = GetFirstUnusedVoice();
if(voice > 0) if(this->voice != -1)
VoiceUsed[voice] = true; VoiceUsed[this->voice] = true;
volume = 255; volume = 255;
SoundEffectLength = 0; SoundEffectLength = 0;
@ -139,14 +140,12 @@ void GuiSound::FreeMemory()
Stop(); Stop();
// Prevent reinitialization of SoundHandler since we're exiting // Prevent reinitialization of SoundHandler since we're exiting
if (!Sys_Exiting()) if(!Sys_Exiting())
SoundHandler::Instance()->RemoveDecoder(voice); SoundHandler::Instance()->RemoveDecoder(this->voice);
if(allocated) if(allocated && sound != NULL)
{
free(sound); free(sound);
allocated = false; allocated = false;
}
sound = NULL; sound = NULL;
length = 0; length = 0;
filepath = ""; filepath = "";
@ -164,7 +163,7 @@ bool GuiSound::Load(const char * filepath)
FILE * f = fopen(filepath, "rb"); FILE * f = fopen(filepath, "rb");
if(!f) if(!f)
{ {
gprintf("Failed to load file %s!!\n", filepath); gprintf("gui_sound.cpp: Failed to load file %s!!\n", filepath);
return false; return false;
} }
@ -172,19 +171,19 @@ bool GuiSound::Load(const char * filepath)
fread(&magic, 1, 4, f); fread(&magic, 1, 4, f);
fclose(f); fclose(f);
SoundHandler::Instance()->AddDecoder(voice, filepath); SoundHandler::Instance()->AddDecoder(this->voice, filepath);
gprintf("Loading %s using voice %d\n", filepath, voice); gprintf("gui_sound.cpp: Loading %s using voice %d\n", filepath, this->voice);
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder * decoder = SoundHandler::Instance()->Decoder(this->voice);
if(!decoder) if(!decoder)
{ {
gprintf("No Decoder!!!\n"); gprintf("gui_sound.cpp: No Decoder!\n");
return false; return false;
} }
if(!decoder->IsBufferReady()) if(!decoder->IsBufferReady())
{ {
gprintf("Buffer not ready!!\n"); gprintf("gui_sound.cpp: Buffer not ready!\n");
SoundHandler::Instance()->RemoveDecoder(voice); SoundHandler::Instance()->RemoveDecoder(this->voice);
return false; return false;
} }
@ -197,7 +196,6 @@ bool GuiSound::Load(const char * filepath)
bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated) bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
{ {
FreeMemory(); FreeMemory();
this->voice = voice;
if(!snd) if(!snd)
return false; return false;
@ -205,24 +203,15 @@ bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
if(!isallocated && *((u32 *) snd) == 'RIFF') if(!isallocated && *((u32 *) snd) == 'RIFF')
return LoadSoundEffect(snd, len); return LoadSoundEffect(snd, len);
if(*((u32 *) snd) == 'IMD5') sound = (u8*)snd;
UncompressSoundbin(snd, len, isallocated); length = len;
else allocated = isallocated;
{
sound = (u8 *) snd;
length = len;
allocated = isallocated;
}
SoundHandler::Instance()->AddDecoder(this->voice, sound, length); SoundHandler::Instance()->AddDecoder(this->voice, sound, length);
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice);
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice); if(!decoder || !decoder->IsBufferReady())
if(!decoder)
return false;
if(!decoder->IsBufferReady())
{ {
SoundHandler::Instance()->RemoveDecoder(voice); SoundHandler::Instance()->RemoveDecoder(this->voice);
return false; return false;
} }
@ -271,19 +260,19 @@ void GuiSound::Play(int vol, bool restart)
{ {
if(SoundEffectLength > 0) if(SoundEffectLength > 0)
{ {
ASND_StopVoice(voice); ASND_StopVoice(this->voice);
ASND_SetVoice(voice, VOICE_MONO_16BIT, 22050, 0, sound, SoundEffectLength, vol, vol, NULL); ASND_SetVoice(this->voice, VOICE_MONO_16BIT, 22050, 0, sound, SoundEffectLength, vol, vol, NULL);
return; return;
} }
if((IsPlaying() && !restart) || voice < 0 || voice >= 16) if((IsPlaying() && !restart) || this->voice < 0 || this->voice >= 16)
return; return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
ASND_StopVoice(voice); ASND_StopVoice(this->voice);
if(decoder->IsEOF()) if(decoder->IsEOF())
{ {
decoder->ClearBuffer(); decoder->ClearBuffer();
@ -296,7 +285,7 @@ void GuiSound::Play(int vol, bool restart)
decoder->LoadNext(); decoder->LoadNext();
SoundHandler::Instance()->ThreadSignal(); SoundHandler::Instance()->ThreadSignal();
ASND_SetVoice(voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback); ASND_SetVoice(this->voice, decoder->GetFormat(), decoder->GetSampleRate(), 0, curbuffer, bufsize, vol, vol, SoundCallback);
} }
void GuiSound::Play() void GuiSound::Play()
@ -307,12 +296,12 @@ void GuiSound::Play()
void GuiSound::Stop() void GuiSound::Stop()
{ {
volume = 0; volume = 0;
if(!IsPlaying() || voice < 0 || voice >= 16) if(!IsPlaying() || this->voice < 0 || this->voice >= 16)
return; return;
ASND_StopVoice(voice); ASND_StopVoice(this->voice);
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
@ -324,10 +313,10 @@ void GuiSound::Stop()
void GuiSound::Pause() void GuiSound::Pause()
{ {
if(voice < 0 || voice >= 16) if(this->voice < 0 || this->voice >= 16)
return; return;
ASND_StopVoice(voice); ASND_StopVoice(this->voice);
} }
void GuiSound::Resume() void GuiSound::Resume()
@ -337,10 +326,10 @@ void GuiSound::Resume()
bool GuiSound::IsPlaying() bool GuiSound::IsPlaying()
{ {
if(voice < 0 || voice >= 16) if(this->voice < 0 || this->voice >= 16)
return false; return false;
int result = ASND_StatusVoice(voice); int result = ASND_StatusVoice(this->voice);
if(result == SND_WORKING || result == SND_WAITING) if(result == SND_WORKING || result == SND_WAITING)
return true; return true;
@ -355,18 +344,18 @@ int GuiSound::GetVolume()
void GuiSound::SetVolume(int vol) void GuiSound::SetVolume(int vol)
{ {
if(voice < 0 || voice >= 16 || vol < 0) if(this->voice < 0 || this->voice >= 16 || vol < 0)
return; return;
volume = vol; volume = vol;
ASND_ChangeVolumeVoice(voice, volume, volume); ASND_ChangeVolumeVoice(this->voice, volume, volume);
} }
void GuiSound::SetLoop(u8 l) void GuiSound::SetLoop(u8 l)
{ {
loop = l; loop = l;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
@ -375,112 +364,13 @@ void GuiSound::SetLoop(u8 l)
void GuiSound::Rewind() void GuiSound::Rewind()
{ {
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice); SoundDecoder *decoder = SoundHandler::Instance()->Decoder(this->voice);
if(!decoder) if(!decoder)
return; return;
decoder->Rewind(); decoder->Rewind();
} }
struct _LZ77Info
{
u16 length : 4;
u16 offset : 12;
} __attribute__((packed));
typedef struct _LZ77Info LZ77Info;
u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size)
{
u8 *buffer = NULL;
if (inLength <= 0x8 || *((const u32 *)inBuf) != 0x4C5A3737 /*"LZ77"*/ || inBuf[4] != 0x10)
return NULL;
u32 uncSize = le32(((const u32 *)inBuf)[1] << 8);
if(uncSize <= 0) return 0;
const u8 *inBufEnd = inBuf + inLength;
inBuf += 8;
buffer = (u8 *)malloc(uncSize);
if(!buffer)
return buffer;
u8 *bufCur = buffer;
u8 *bufEnd = buffer + uncSize;
while(bufCur < bufEnd && inBuf < inBufEnd)
{
u8 flags = *inBuf;
++inBuf;
int i = 0;
for(i = 0; i < 8 && bufCur < bufEnd && inBuf < inBufEnd; ++i)
{
if((flags & 0x80) != 0)
{
const LZ77Info * info = (const LZ77Info *)inBuf;
inBuf += sizeof (LZ77Info);
int length = info->length + 3;
if(bufCur - info->offset - 1 < buffer || bufCur + length > bufEnd)
return buffer;
memcpy(bufCur, bufCur - info->offset - 1, length);
bufCur += length;
}
else
{
*bufCur = *inBuf;
++inBuf;
++bufCur;
}
flags <<= 1;
}
}
*size = uncSize;
return buffer;
}
void GuiSound::UncompressSoundbin(const u8 * snd, u32 len, bool isallocated)
{
const u8 * file = snd+32;
length = len-32;
if(length <= 0)
return;
if(*((u32 *) file) == 'LZ77')
{
u32 size = 0;
sound = uncompressLZ77(file, length, &size);
if (!sound)
{
length = 0;
return;
}
length = size;
}
else
{
sound = (u8 *)malloc(length);
if (!sound)
{
length = 0;
return;
}
memcpy(sound, file, length);
}
if(isallocated)
{
void *p = (void *)snd;
free(p);
}
allocated = true;
}
void soundInit(void) void soundInit(void)
{ {
ASND_Init(); ASND_Init();

View File

@ -84,13 +84,11 @@ public:
private: private:
//!Initializes the GuiSound object by setting the default values //!Initializes the GuiSound object by setting the default values
void Init(); void Init();
//!Special sound case for sound.bin
void UncompressSoundbin(const u8 * snd, u32 len, bool isallocated);
protected: protected:
std::string filepath; std::string filepath;
u8 *sound; //!< Pointer to the sound data u8 *sound; //!< Pointer to the sound data
u32 length; //!< Length of sound data u32 length; //!< Length of sound data
s32 voice; //!< Currently assigned ASND voice channel s8 voice; //!< Currently assigned ASND voice channel
int volume; //!< Sound volume (0-100) int volume; //!< Sound volume (0-100)
u8 loop; //!< Loop sound playback u8 loop; //!< Loop sound playback
u32 SoundEffectLength; //!< Check if it is an app soundeffect for faster playback u32 SoundEffectLength; //!< Check if it is an app soundeffect for faster playback

View File

@ -1,5 +1,5 @@
#include <malloc.h>
#include "dns.h" #include "dns.h"
#include "mem2.hpp"
/** /**
* Resolves a domainname to an ip address * Resolves a domainname to an ip address
@ -70,14 +70,14 @@ u32 getipbynamecached(char *domain)
u32 ip = getipbyname(domain); u32 ip = getipbyname(domain);
//No cache of this domain could be found, create a cache node and add it to the front of the cache //No cache of this domain could be found, create a cache node and add it to the front of the cache
struct dnsentry *newnode = MEM2_alloc(sizeof(struct dnsentry)); struct dnsentry *newnode = malloc(sizeof(struct dnsentry));
if(newnode == NULL) return ip; if(newnode == NULL) return ip;
newnode->ip = ip; newnode->ip = ip;
newnode->domain = MEM2_alloc(strlen(domain)+1); newnode->domain = malloc(strlen(domain)+1);
if(newnode->domain == NULL) if(newnode->domain == NULL)
{ {
MEM2_free(newnode); free(newnode);
return ip; return ip;
} }
strcpy(newnode->domain, domain); strcpy(newnode->domain, domain);
@ -110,8 +110,8 @@ u32 getipbynamecached(char *domain)
previousnode->nextnode = NULL; previousnode->nextnode = NULL;
} }
MEM2_free(node->domain); free(node->domain);
MEM2_free(node); free(node);
dnsentrycount--; dnsentrycount--;
} }

View File

@ -1,11 +1,10 @@
#include <string.h>
#include <malloc.h>
#include "gcard.h" #include "gcard.h"
#include "http.h" #include "http.h"
#include "utils.h" #include "utils.h"
#include "gecko/gecko.h" #include "gecko/gecko.h"
#include "mem2.hpp"
#include <string.h>
#define MAX_URL_SIZE 178 // 128 + 48 + 6 #define MAX_URL_SIZE 178 // 128 + 48 + 6
@ -45,7 +44,7 @@ void add_game_to_card(const char *gameid)
{ {
int i; int i;
char *url = (char *)MEM2_alloc(MAX_URL_SIZE); // Too much memory, but only like 10 bytes char *url = (char *)malloc(MAX_URL_SIZE); // Too much memory, but only like 10 bytes
memset(url, 0, sizeof(url)); memset(url, 0, sizeof(url));
for (i = 0; i < amount_of_providers && providers != NULL; i++) for (i = 0; i < amount_of_providers && providers != NULL; i++)
@ -57,5 +56,5 @@ void add_game_to_card(const char *gameid)
gprintf("Gamertag URL:\n%s\n",(char*)url); gprintf("Gamertag URL:\n%s\n",(char*)url);
downloadfile(NULL, 0, (char *) url, NULL, NULL); downloadfile(NULL, 0, (char *) url, NULL, NULL);
} }
MEM2_free(url); free(url);
} }

View File

@ -18,9 +18,9 @@
#include <ogcsys.h> #include <ogcsys.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include "plugin.hpp" #include "plugin.hpp"
#include "memory/mem2.hpp"
#include "gui/text.hpp" #include "gui/text.hpp"
#include "gecko/gecko.h" #include "gecko/gecko.h"
#include "devicemounter/PartitionHandle.h" #include "devicemounter/PartitionHandle.h"
@ -51,7 +51,7 @@ void Plugin::Cleanup()
for(u8 pos = 0; pos < Plugins.size(); pos++) for(u8 pos = 0; pos < Plugins.size(); pos++)
{ {
if(Plugins[pos].BannerSound != NULL) if(Plugins[pos].BannerSound != NULL)
MEM2_free(Plugins[pos].BannerSound); free(Plugins[pos].BannerSound);
} }
} }
@ -86,7 +86,7 @@ bool Plugin::AddPlugin(Config &plugin)
size = infile.tellg(); size = infile.tellg();
infile.seekg(0, ios::beg); infile.seekg(0, ios::beg);
//Don't free that, otherwise you would delete the sound //Don't free that, otherwise you would delete the sound
char* FileReadBuffer = (char*)MEM2_alloc(size); char* FileReadBuffer = (char*)malloc(size);
infile.read(FileReadBuffer, size); infile.read(FileReadBuffer, size);
NewPlugin.BannerSound = (u8*)FileReadBuffer; NewPlugin.BannerSound = (u8*)FileReadBuffer;
NewPlugin.BannerSoundSize = size; NewPlugin.BannerSoundSize = size;

File diff suppressed because one or more lines are too long