Making things ready for official wiiflow svn ;)

-made wait animation faster
-removed a few unneeded lines in the wait message code
-fixed booting wii games from disc
-fixed possible bug in wii game launching in general
-gecko output again on wii game booting
-converted alot of spaces to tabs, fitting the general wiiflow
coding style
-general cleaning up things
This commit is contained in:
fix94.1 2012-07-25 22:12:17 +00:00
parent 6cb919c7ae
commit a36fab3cdd
39 changed files with 1649 additions and 1680 deletions

View File

@ -14,17 +14,9 @@
#include "gecko.h"
#include "mem2.hpp"
#define STACK_ALIGN(type, name, cnt, alignment) \
u8 _al__##name[((sizeof(type)*(cnt)) + (alignment) + \
(((sizeof(type)*(cnt))%(alignment)) > 0 ? ((alignment) - \
((sizeof(type)*(cnt))%(alignment))) : 0))]; \
type *name = (type*)(((u32)(_al__##name)) + ((alignment) - (( \
(u32)(_al__##name))&((alignment)-1))))
void __Disc_SetLowMem(void);
void __Disc_SetTime(void);
void _unstub_start();
u32 entryPoint;
extern void __exception_closeall();
@ -41,6 +33,8 @@ typedef struct _dolheader
u32 padding[7];
} __attribute__((packed)) dolheader;
u32 entryPoint;
s32 BootChannel(u32 entry, u64 chantitle, u32 ios, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio)
{
gprintf("Loading Channel...\n");

View File

@ -422,10 +422,10 @@ u32 Nand::__configsetsetting(const char *item, const char *val)
void Nand::__FATify(char *ptr, const char *str)
{
char ctr;
while ((ctr = *(str++)) != '\0')
while((ctr = *(str++)) != '\0')
{
const char *esc;
switch (ctr)
switch(ctr)
{
case '"':
esc = "&qt;";
@ -468,13 +468,20 @@ void Nand::__NANDify(char *str)
{
if(c == '&')
{
if(!strncmp(src, "qt;", 3)) c = '"';
else if (!strncmp(src, "st;", 3)) c = '*';
else if (!strncmp(src, "cl;", 3)) c = ':';
else if (!strncmp(src, "lt;", 3)) c = '<';
else if (!strncmp(src, "gt;", 3)) c = '>';
else if (!strncmp(src, "qm;", 3)) c = '?';
else if (!strncmp(src, "vb;", 3)) c = '|';
if(!strncmp(src, "qt;", 3))
c = '"';
else if(!strncmp(src, "st;", 3))
c = '*';
else if(!strncmp(src, "cl;", 3))
c = ':';
else if(!strncmp(src, "lt;", 3))
c = '<';
else if(!strncmp(src, "gt;", 3))
c = '>';
else if(!strncmp(src, "qm;", 3))
c = '?';
else if(!strncmp(src, "vb;", 3))
c = '|';
if (c != '&')
src += 3;
@ -862,9 +869,7 @@ s32 Nand::DoNandDump(const char *source, const char *dest, dump_callback_t i_dum
__DumpNandFile(source, ndest);
}
else
{
__DumpNandFolder(source, dest);
}
return 0;
}

View File

@ -12,8 +12,6 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24))
#define ERROR(x) do {wbfs_error(x);goto error;}while(0)
#define ALIGN_LBA(x) (((x)+p->hd_sec_sz-1)&(~(p->hd_sec_sz-1)))
@ -37,6 +35,8 @@ static u8 size_to_shift(u32 size)
return ret - 1;
}
#define read_le32_unaligned(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24))
wbfs_t *wbfs_open_hd(rw_sector_callback_t read_hdsector, rw_sector_callback_t write_hdsector, void *callback_data, int hd_sector_size, int num_hd_sector __attribute((unused)), int reset)
{
int i=num_hd_sector,ret;
@ -64,7 +64,6 @@ wbfs_t *wbfs_open_hd(rw_sector_callback_t read_hdsector, rw_sector_callback_t wr
wbfs_iofree(tmp_buffer);
if(reset)// XXX make a empty hd partition..
{
}
return 0;
}

View File

@ -382,6 +382,7 @@ void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len)
}
else fraction = 16;
// debug_printf("block %d: fraction = %d\n", blockno, fraction);
memcpy(block, inbuf + blockno * sizeof(block), fraction);
decrypt((char*) block);
u8 *ctext_ptr;
@ -391,6 +392,8 @@ void aes_decrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len)
for (i = 0; i < fraction; i++)
outbuf[blockno * sizeof(block) + i] = ctext_ptr[i] ^ block[i];
// debug_printf("Block %d output: ", blockno);
// hexdump(outbuf + blockno*sizeof(block), 16);
}
}
@ -400,6 +403,8 @@ void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len)
u8 block[16];
unsigned int blockno = 0, i;
// debug_printf("aes_decrypt(%p, %p, %p, %lld)\n", iv, inbuf, outbuf, len);
for (blockno = 0; blockno <= (len / sizeof(block)); blockno++)
{
unsigned int fraction;
@ -411,6 +416,7 @@ void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len)
}
else fraction = 16;
// debug_printf("block %d: fraction = %d\n", blockno, fraction);
memcpy(block, inbuf + blockno * sizeof(block), fraction);
for (i = 0; i < fraction; i++)
@ -419,6 +425,8 @@ void aes_encrypt(u8 *iv, u8 *inbuf, u8 *outbuf, unsigned long long len)
encrypt((char*) block);
memcpy(iv, block, sizeof(block));
memcpy(outbuf + blockno * sizeof(block), block, sizeof(block));
// debug_printf("Block %d output: ", blockno);
// hexdump(outbuf + blockno*sizeof(block), 16);
}
}

View File

@ -16,7 +16,6 @@
/* init-globals */
bool geckoinit = false;
bool textVideoInit = false;
bool geckoDisable = false;
bool bufferMessages = true;
bool WriteToSD = false;
@ -108,8 +107,6 @@ void WriteToFile(char* tmp)
//using the gprintf from crediar because it is smaller than mine
void gprintf( const char *format, ... )
{
if(geckoDisable)
return;
char *tmp = NULL;
va_list va;
va_start(va, format);
@ -184,11 +181,6 @@ bool InitGecko()
return false;
}
void GeckoDisable()
{
geckoDisable = true;
}
void AllocSDGeckoBuffer()
{
tmpfilebuffer = (char*)MEM2_alloc(filebuffer + 1 * sizeof(char));

View File

@ -1,5 +1,4 @@
#ifndef _GECKO_H_
#define _GECKO_H_
@ -7,17 +6,16 @@
extern "C" {
#endif
extern bool geckoinit;
extern bool bufferMessages;
extern bool WriteToSD;
extern bool geckoinit;
extern bool bufferMessages;
extern bool WriteToSD;
//use this just like printf();
void gprintf(const char *format, ...);
void ghexdump(void *d, int len);
bool InitGecko();
void AllocSDGeckoBuffer();
void ClearLogBuffer();
void GeckoDisable();
//use this just like printf();
void gprintf(const char *format, ...);
void ghexdump(void *d, int len);
bool InitGecko();
void AllocSDGeckoBuffer();
void ClearLogBuffer();
#ifdef __cplusplus
}

View File

@ -1,25 +1,25 @@
/****************************************************************************
* Copyright (C) 2010
* by Dimok
*Copyright (C) 2010
*by Dimok
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any
* damages arising from the use of this software.
*This software is provided 'as-is', without any express or implied
*warranty. In no event will the authors be held liable for any
*damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any
* purpose, including commercial applications, and to alter it and
* redistribute it freely, subject to the following restrictions:
*Permission is granted to anyone to use this software for any
*purpose, including commercial applications, and to alter it and
*redistribute it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you
* must not claim that you wrote the original software. If you use
* this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required.
*1. The origin of this software must not be misrepresented; you
*must not claim that you wrote the original software. If you use
*this software in a product, an acknowledgment in the product
*documentation would be appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software.
*2. Altered source versions must be plainly marked as such, and
*must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*3. This notice may not be removed or altered from any source
*distribution.
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
@ -33,11 +33,11 @@
#include "text.hpp"
#define NAME_OFFSET_DB "gametdb_offsets.bin"
#define MAXREADSIZE 1024*1024 // Cache size only for parsing the offsets: 1MB
#define MAXREADSIZE 1024*1024 //Cache size only for parsing the offsets: 1MB
typedef struct _ReplaceStruct
{
const char * orig;
const char *orig;
char replace;
short size;
} ReplaceStruct;
@ -58,7 +58,7 @@ GameTDB::GameTDB()
{
}
GameTDB::GameTDB(const char * filepath)
GameTDB::GameTDB(const char *filepath)
: isLoaded(false), isParsed(false), file(0), filepath(0), LangCode("EN"), GameNodeCache(0)
{
OpenFile(filepath);
@ -69,9 +69,10 @@ GameTDB::~GameTDB()
CloseFile();
}
bool GameTDB::OpenFile(const char * filepath)
bool GameTDB::OpenFile(const char *filepath)
{
if(!filepath) return false;
if(!filepath)
return false;
gprintf("Trying to open '%s'...", filepath);
file = fopen(filepath, "rb");
@ -110,7 +111,8 @@ void GameTDB::CloseFile()
delete [] GameNodeCache;
GameNodeCache = NULL;
if(file) fclose(file);
if(file)
fclose(file);
file = NULL;
}
@ -119,22 +121,23 @@ void GameTDB::Refresh()
gprintf("Refreshing file '%s'\n", filepath);
CloseFile();
if (filepath == NULL)
if(filepath == NULL)
return;
OpenFile(filepath);
}
bool GameTDB::LoadGameOffsets(const char * path)
bool GameTDB::LoadGameOffsets(const char *path)
{
if(!path) return false;
if(!path)
return false;
string OffsetDBPath = path;
if(strlen(path) > 0 && path[strlen(path)-1] != '/')
OffsetDBPath += '/';
OffsetDBPath += NAME_OFFSET_DB;
FILE * fp = fopen(OffsetDBPath.c_str(), "rb");
FILE *fp = fopen(OffsetDBPath.c_str(), "rb");
if(!fp)
{
bool result = ParseFile();
@ -144,9 +147,9 @@ bool GameTDB::LoadGameOffsets(const char * path)
return result;
}
unsigned long long ExistingVersion = GetGameTDBVersion();
unsigned long long Version = 0;
unsigned int NodeCount = 0;
u64 ExistingVersion = GetGameTDBVersion();
u64 Version = 0;
u32 NodeCount = 0;
fread(&Version, 1, sizeof(Version), fp);
@ -189,16 +192,17 @@ bool GameTDB::LoadGameOffsets(const char * path)
return true;
}
bool GameTDB::SaveGameOffsets(const char * path)
bool GameTDB::SaveGameOffsets(const char *path)
{
if(OffsetMap.size() == 0 || !path)
return false;
FILE * fp = fopen(path, "wb");
if(!fp) return false;
FILE *fp = fopen(path, "wb");
if(!fp)
return false;
unsigned long long ExistingVersion = GetGameTDBVersion();
unsigned int NodeCount = OffsetMap.size();
u64 ExistingVersion = GetGameTDBVersion();
u32 NodeCount = OffsetMap.size();
if(fwrite(&ExistingVersion, 1, sizeof(ExistingVersion), fp) != sizeof(ExistingVersion))
{
@ -223,7 +227,7 @@ bool GameTDB::SaveGameOffsets(const char * path)
return true;
}
unsigned long long GameTDB::GetGameTDBVersion()
u64 GameTDB::GetGameTDBVersion()
{
if(!file)
return 0;
@ -233,14 +237,14 @@ unsigned long long GameTDB::GetGameTDBVersion()
if(GetData(TmpText, 0, sizeof(TmpText)) < 0)
return 0;
char * VersionText = GetNodeText(TmpText, "<GameTDB version=\"", "/>");
char *VersionText = GetNodeText(TmpText, "<GameTDB version=\"", "/>");
if(!VersionText)
return 0;
return strtoull(VersionText, NULL, 10);
}
int GameTDB::GetData(char * data, int offset, int size)
int GameTDB::GetData(char *data, int offset, int size)
{
if(!file || !data)
return -1;
@ -250,15 +254,15 @@ int GameTDB::GetData(char * data, int offset, int size)
return fread(data, 1, size, file);
}
char * GameTDB::LoadGameNode(const char * id)
char *GameTDB::LoadGameNode(const char *id)
{
unsigned int read = 0;
u32 read = 0;
GameOffsets * offset = this->GetGameOffset(id);
GameOffsets *offset = this->GetGameOffset(id);
if(!offset)
return NULL;
char * data = new (std::nothrow) char[offset->nodesize+1];
char *data = new (std::nothrow) char[offset->nodesize+1];
if(!data)
return NULL;
@ -273,9 +277,9 @@ char * GameTDB::LoadGameNode(const char * id)
return data;
}
char * GameTDB::GetGameNode(const char * id)
char *GameTDB::GetGameNode(const char *id)
{
char * data = NULL;
char *data = NULL;
if(GameNodeCache != 0 && strncmp(id, GameIDCache, strlen(GameIDCache)) == 0)
{
@ -302,9 +306,9 @@ char * GameTDB::GetGameNode(const char * id)
return data;
}
GameOffsets * GameTDB::GetGameOffset(const char * gameID)
GameOffsets *GameTDB::GetGameOffset(const char *gameID)
{
for(unsigned int i = 0; i < OffsetMap.size(); ++i)
for(u32 i = 0; i < OffsetMap.size(); ++i)
{
if(strncmp(gameID, OffsetMap[i].gameID, strlen(OffsetMap[i].gameID)) == 0)
return &OffsetMap[i];
@ -313,13 +317,13 @@ GameOffsets * GameTDB::GetGameOffset(const char * gameID)
return 0;
}
static inline char * CleanText(char * in_text)
static inline char *CleanText(char *in_text)
{
if(!in_text)
return NULL;
const char * ptr = in_text;
char * text = in_text;
const char *ptr = in_text;
char *text = in_text;
while(*ptr != '\0')
{
@ -351,18 +355,18 @@ static inline char * CleanText(char * in_text)
return in_text;
}
char * GameTDB::GetNodeText(char * data, const char * nodestart, const char * nodeend)
char *GameTDB::GetNodeText(char *data, const char *nodestart, const char *nodeend)
{
if(!data || !nodestart || !nodeend)
return NULL;
char * position = strstr(data, nodestart);
char *position = strstr(data, nodestart);
if(!position)
return NULL;
position += strlen(nodestart);
char * end = strstr(position, nodeend);
char *end = strstr(position, nodeend);
if(!end)
return NULL;
@ -371,11 +375,12 @@ char * GameTDB::GetNodeText(char * data, const char * nodestart, const char * no
return CleanText(position);
}
char * GameTDB::SeekLang(char * text, const char * langcode)
char *GameTDB::SeekLang(char *text, const char *langcode)
{
if(!text || !langcode) return NULL;
if(!text || !langcode)
return NULL;
char * ptr = text;
char *ptr = text;
while((ptr = strstr(ptr, "<locale lang=")) != NULL)
{
ptr += strlen("<locale lang=\"");
@ -383,7 +388,7 @@ char * GameTDB::SeekLang(char * text, const char * langcode)
if(strncmp(ptr, langcode, strlen(langcode)) == 0)
{
//! Cut off all the other languages
char * end = strstr(ptr, "</locale>");
char *end = strstr(ptr, "</locale>");
if(!end)
return NULL;
@ -404,16 +409,16 @@ bool GameTDB::ParseFile()
if(!file)
return false;
char * Line = new (std::nothrow) char[MAXREADSIZE+1];
char *Line = new (std::nothrow) char[MAXREADSIZE+1];
if(!Line)
return false;
bool readnew = false;
int i, currentPos = 0;
int read = 0;
const char * gameNode = NULL;
const char * idNode = NULL;
const char * gameEndNode = NULL;
const char *gameNode = NULL;
const char *idNode = NULL;
const char *gameEndNode = NULL;
while((read = GetData(Line, currentPos, MAXREADSIZE)) > 0)
{
@ -461,23 +466,19 @@ bool GameTDB::ParseFile()
return true;
}
bool GameTDB::FindTitle(char * data, string & title, string langCode)
bool GameTDB::FindTitle(char *data, string & title, string langCode)
{
char * language = SeekLang(data, langCode.c_str());
char *language = SeekLang(data, langCode.c_str());
if(!language)
{
language = SeekLang(data, "EN");
if(!language)
{
return false;
}
}
char * the_title = GetNodeText(language, "<title>", "</title>");
char *the_title = GetNodeText(language, "<title>", "</title>");
if(!the_title)
{
return false;
}
char tmp[64];
strncpy(tmp, the_title, sizeof(tmp) - 1);
@ -486,13 +487,15 @@ bool GameTDB::FindTitle(char * data, string & title, string langCode)
return true;
}
bool GameTDB::GetTitle(const char * id, string & title)
bool GameTDB::GetTitle(const char *id, string & title)
{
title = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
bool retval = FindTitle(data, title, LangCode);
@ -501,15 +504,17 @@ bool GameTDB::GetTitle(const char * id, string & title)
return retval;
}
bool GameTDB::GetSynopsis(const char * id, string & synopsis)
bool GameTDB::GetSynopsis(const char *id, string & synopsis)
{
synopsis = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * language = SeekLang(data, LangCode.c_str());
char *language = SeekLang(data, LangCode.c_str());
if(!language)
{
language = SeekLang(data, "EN");
@ -520,7 +525,7 @@ bool GameTDB::GetSynopsis(const char * id, string & synopsis)
}
}
char * the_synopsis = GetNodeText(language, "<synopsis>", "</synopsis>");
char *the_synopsis = GetNodeText(language, "<synopsis>", "</synopsis>");
if(!the_synopsis)
{
delete [] data;
@ -534,15 +539,17 @@ bool GameTDB::GetSynopsis(const char * id, string & synopsis)
return true;
}
bool GameTDB::GetRegion(const char * id, string & region)
bool GameTDB::GetRegion(const char *id, string & region)
{
region = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * the_region = GetNodeText(data, "<region>", "</region>");
char *the_region = GetNodeText(data, "<region>", "</region>");
if(!the_region)
{
delete [] data;
@ -556,15 +563,17 @@ bool GameTDB::GetRegion(const char * id, string & region)
return true;
}
bool GameTDB::GetDeveloper(const char * id, string & dev)
bool GameTDB::GetDeveloper(const char *id, string & dev)
{
dev = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * the_dev = GetNodeText(data, "<developer>", "</developer>");
char *the_dev = GetNodeText(data, "<developer>", "</developer>");
if(!the_dev)
{
delete [] data;
@ -578,15 +587,17 @@ bool GameTDB::GetDeveloper(const char * id, string & dev)
return true;
}
bool GameTDB::GetPublisher(const char * id, string & pub)
bool GameTDB::GetPublisher(const char *id, string & pub)
{
pub = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * the_pub = GetNodeText(data, "<publisher>", "</publisher>");
char *the_pub = GetNodeText(data, "<publisher>", "</publisher>");
if(!the_pub)
{
delete [] data;
@ -600,25 +611,27 @@ bool GameTDB::GetPublisher(const char * id, string & pub)
return true;
}
unsigned int GameTDB::GetPublishDate(const char * id)
u32 GameTDB::GetPublishDate(const char *id)
{
if(!id) return 0;
if(!id)
return 0;
char * data = GetGameNode(id);
if(!data) return 0;
char *data = GetGameNode(id);
if(!data)
return 0;
char * year_string = GetNodeText(data, "<date year=\"", "/>");
char *year_string = GetNodeText(data, "<date year=\"", "/>");
if(!year_string)
{
delete [] data;
return 0;
}
unsigned int year, day, month;
u32 year, day, month;
year = atoi(year_string);
char * month_string = strstr(year_string, "month=\"");
char *month_string = strstr(year_string, "month=\"");
if(!month_string)
{
delete [] data;
@ -629,7 +642,7 @@ unsigned int GameTDB::GetPublishDate(const char * id)
month = atoi(month_string);
char * day_string = strstr(month_string, "day=\"");
char *day_string = strstr(month_string, "day=\"");
if(!day_string)
{
delete [] data;
@ -645,25 +658,27 @@ unsigned int GameTDB::GetPublishDate(const char * id)
return ((year & 0xFFFF) << 16 | (month & 0xFF) << 8 | (day & 0xFF));
}
bool GameTDB::GetGenres(const char * id, string & gen)
bool GameTDB::GetGenres(const char *id, string & gen)
{
vector<string> genre;
gen = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * the_genre = GetNodeText(data, "<genre>", "</genre>");
char *the_genre = GetNodeText(data, "<genre>", "</genre>");
if(!the_genre)
{
delete [] data;
return false;
}
unsigned int genre_num = 0;
const char * ptr = the_genre;
u32 genre_num = 0;
const char *ptr = the_genre;
while(*ptr != '\0')
{
@ -673,7 +688,8 @@ bool GameTDB::GetGenres(const char * id, string & gen)
if(*ptr == ',' || *ptr == '/' || *ptr == ';')
{
ptr++;
while(*ptr == ' ') ptr++;
while(*ptr == ' ')
ptr++;
genre_num++;
continue;
}
@ -694,7 +710,7 @@ bool GameTDB::GetGenres(const char * id, string & gen)
return true;
}
const char * GameTDB::RatingToString(int rating)
const char *GameTDB::RatingToString(int rating)
{
switch(rating)
{
@ -713,16 +729,18 @@ const char * GameTDB::RatingToString(int rating)
return NULL;
}
int GameTDB::GetRating(const char * id)
int GameTDB::GetRating(const char *id)
{
int rating = -1;
if(!id) return rating;
if(!id)
return rating;
char * data = GetGameNode(id);
if(!data) return rating;
char *data = GetGameNode(id);
if(!data)
return rating;
char * rating_text = GetNodeText(data, "<rating type=\"", "/>");
char *rating_text = GetNodeText(data, "<rating type=\"", "/>");
if(!rating_text)
{
delete [] data;
@ -731,13 +749,10 @@ int GameTDB::GetRating(const char * id)
if(strncmp(rating_text, "CERO", 4) == 0)
rating = GAMETDB_RATING_TYPE_CERO;
else if(strncmp(rating_text, "ESRB", 4) == 0)
rating = GAMETDB_RATING_TYPE_ESRB;
else if(strncmp(rating_text, "PEGI", 4) == 0)
rating = GAMETDB_RATING_TYPE_PEGI;
else if(strncmp(rating_text, "GRB", 4) == 0)
rating = GAMETDB_RATING_TYPE_GRB;
@ -746,22 +761,24 @@ int GameTDB::GetRating(const char * id)
return rating;
}
bool GameTDB::GetRatingValue(const char * id, string & rating_value)
bool GameTDB::GetRatingValue(const char *id, string & rating_value)
{
rating_value = "";
if(!id) return false;
if(!id)
return false;
char * data = GetGameNode(id);
if(!data) return false;
char *data = GetGameNode(id);
if(!data)
return false;
char * rating_text = GetNodeText(data, "<rating type=\"", "/>");
char *rating_text = GetNodeText(data, "<rating type=\"", "/>");
if(!rating_text)
{
delete [] data;
return false;
}
char * value_text = GetNodeText(rating_text, "value=\"", "\"");
char *value_text = GetNodeText(rating_text, "value=\"", "\"");
if(!value_text)
{
delete [] data;
@ -775,24 +792,24 @@ bool GameTDB::GetRatingValue(const char * id, string & rating_value)
return true;
}
int GameTDB::GetRatingDescriptors(const char * id, vector<string> & desc_list)
int GameTDB::GetRatingDescriptors(const char *id, vector<string> & desc_list)
{
desc_list.clear();
if(!id)
return -1;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return -1;
char * descriptor_text = GetNodeText(data, "<descriptor>", "</rating>");
char *descriptor_text = GetNodeText(data, "<descriptor>", "</rating>");
if(!descriptor_text)
{
delete [] data;
return -1;
}
unsigned int list_num = 0;
u32 list_num = 0;
while(*descriptor_text != '\0')
{
@ -819,18 +836,18 @@ int GameTDB::GetRatingDescriptors(const char * id, vector<string> & desc_list)
return desc_list.size();
}
int GameTDB::GetWifiPlayers(const char * id)
int GameTDB::GetWifiPlayers(const char *id)
{
int players = -1;
if(!id)
return players;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return players;
char * PlayersNode = GetNodeText(data, "<wi-fi players=\"", "\">");
char *PlayersNode = GetNodeText(data, "<wi-fi players=\"", "\">");
if(!PlayersNode)
{
delete [] data;
@ -842,24 +859,24 @@ int GameTDB::GetWifiPlayers(const char * id)
return players;
}
int GameTDB::GetWifiFeatures(const char * id, vector<string> & feat_list)
int GameTDB::GetWifiFeatures(const char *id, vector<string> & feat_list)
{
feat_list.clear();
if(!id)
return -1;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return -1;
char * feature_text = GetNodeText(data, "<feature>", "</wi-fi>");
char *feature_text = GetNodeText(data, "<feature>", "</wi-fi>");
if(!feature_text)
{
delete [] data;
return -1;
}
unsigned int list_num = 0;
u32 list_num = 0;
while(*feature_text != '\0')
{
@ -877,7 +894,6 @@ int GameTDB::GetWifiFeatures(const char * id, vector<string> & feat_list)
if(list_num >= feat_list.size())
feat_list.resize(list_num+1);
if(feat_list[list_num].size() == 0)
feat_list[list_num].push_back(toupper((int)*feature_text));
else
@ -891,18 +907,18 @@ int GameTDB::GetWifiFeatures(const char * id, vector<string> & feat_list)
return feat_list.size();
}
int GameTDB::GetPlayers(const char * id)
int GameTDB::GetPlayers(const char *id)
{
int players = -1;
if(!id)
return players;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return players;
char * PlayersNode = GetNodeText(data, "<input players=\"", "\">");
char *PlayersNode = GetNodeText(data, "<input players=\"", "\">");
if(!PlayersNode)
{
delete [] data;
@ -914,36 +930,35 @@ int GameTDB::GetPlayers(const char * id)
return players;
}
int GameTDB::GetAccessories(const char * id, vector<Accessory> & acc_list)
int GameTDB::GetAccessories(const char *id, vector<Accessory> & acc_list)
{
acc_list.clear();
if(!id)
return -1;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return -1;
char * ControlsNode = GetNodeText(data, "<control type=\"", "</input>");
char *ControlsNode = GetNodeText(data, "<control type=\"", "</input>");
if(!ControlsNode)
{
delete [] data;
return -1;
}
unsigned int list_num = 0;
u32 list_num = 0;
while(ControlsNode && *ControlsNode != '\0')
{
if(list_num >= acc_list.size())
acc_list.resize(list_num+1);
for(const char * ptr = ControlsNode; *ptr != '"' && *ptr != '\0'; ptr++)
for(const char *ptr = ControlsNode; *ptr != '"' && *ptr != '\0'; ptr++)
acc_list[list_num].Name.push_back(*ptr);
acc_list[list_num].Name.push_back('\0');
char * requiredField = strstr(ControlsNode, "required=\"");
char *requiredField = strstr(ControlsNode, "required=\"");
if(!requiredField)
{
delete [] data;
@ -966,14 +981,12 @@ int GameTDB::GetAccessories(const char * id, vector<Accessory> & acc_list)
return acc_list.size();
}
unsigned int GameTDB::FindCaseColor(char * data)
u32 GameTDB::FindCaseColor(char *data)
{
unsigned int color = -1;
u32 color = -1;
char * ColorNode = GetNodeText(data, "<case color=\"", "\"");
if(!ColorNode)
return color;
if(strlen(ColorNode) == 0)
char *ColorNode = GetNodeText(data, "<case color=\"", "\"");
if(!ColorNode || strlen(ColorNode) == 0)
return color;
char format[8];
@ -982,41 +995,40 @@ unsigned int GameTDB::FindCaseColor(char * data)
return strtoul(format, NULL, 16);
}
unsigned int GameTDB::GetCaseColor(const char * id)
u32 GameTDB::GetCaseColor(const char *id)
{
unsigned int color = -1;
u32 color = -1;
if(!id)
return color;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
return color;
color = FindCaseColor(data);
if( color != 0xffffffff )
if(color != 0xffffffff)
gprintf("GameTDB: Found alternate color(%x) for: %s\n", color, id);
delete [] data;
return color;
}
int GameTDB::GetCaseVersions(const char * id)
int GameTDB::GetCaseVersions(const char *id)
{
int altcase = -1;
if(!id)
return altcase;
char * data = GetGameNode(id);
char *data = GetGameNode(id);
if(!data)
{
gprintf("GameTDB: GameNode for %s not found\n", id);
return altcase;
}
char * PlayersNode = GetNodeText(data, "case versions=\"", "\"");
char *PlayersNode = GetNodeText(data, "case versions=\"", "\"");
if(!PlayersNode)
{
delete [] data;
@ -1028,7 +1040,7 @@ int GameTDB::GetCaseVersions(const char * id)
return altcase;
}
bool GameTDB::GetGameXMLInfo(const char * id, GameXMLInfo * gameInfo)
bool GameTDB::GetGameXMLInfo(const char *id, GameXMLInfo *gameInfo)
{
if(!id || !gameInfo)
return false;

View File

@ -497,10 +497,11 @@ void CVideo::_showWaitMessages(CVideo *m)
vector<STexture>::iterator waitItr = m->m_waitMessages.begin();
gprintf("Going to show a wait message screen, delay: %d, # images: %d\n", waitFrames, m->m_waitMessages.size());
m->_clearScreen();
m->waitMessage(*waitItr);
waitItr += PNGfadeDirection;
m->prepare();
m->setup2DProjection();
GX_SetNumChans(0);
wiiLightSetLevel(0);
wiiLightOn();
@ -523,16 +524,15 @@ void CVideo::_showWaitMessages(CVideo *m)
{
m->waitMessage(*waitItr);
waitItr += PNGfadeDirection;
if(waitItr == m->m_waitMessages.end())
waitItr = m->m_waitMessages.begin();
waitFrames = frames;
}
waitFrames--;
VIDEO_WaitVSync();
waitFrames--;
}
wiiLightOff();
GX_SetNumChans(1);
m->m_showingWaitMessages = false;
gprintf("Stop showing images\n");
}
@ -584,26 +584,23 @@ void CVideo::waitMessage(float delay)
void CVideo::waitMessage(const vector<STexture> &tex, float delay)
{
hideWaitMessage();
if(tex.size() == 0)
{
m_waitMessages = m_defaultWaitMessages;
m_waitMessageDelay = 0.2f;
m_waitMessageDelay = 0.1f;
}
else
{
m_waitMessages = tex;
m_waitMessageDelay = delay;
}
_clearScreen();
if (m_waitMessages.size() == 1)
if(m_waitMessages.size() == 1)
waitMessage(m_waitMessages[0]);
else if(m_waitMessages.size() > 1)
{
CheckWaitThread();
m_showWaitMessage = true;
unsigned int stack_size = (unsigned int)32768;
u32 stack_size = (u32)32768;
waitThreadStack = smartMem2Alloc(stack_size);
LWP_CreateThread(&waitThread, (void *(*)(void *))CVideo::_showWaitMessages, (void *)this, waitThreadStack.get(), stack_size, LWP_PRIO_IDLE);
}
@ -614,9 +611,6 @@ void CVideo::waitMessage(const STexture &tex)
Mtx modelViewMtx;
GXTexObj texObj;
prepare();
setup2DProjection();
GX_SetNumChans(0);
GX_ClearVtxDesc();
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
@ -648,7 +642,6 @@ void CVideo::waitMessage(const STexture &tex)
GX_TexCoord2f32(0.f, 1.f);
GX_End();
render();
GX_SetNumChans(1);
}
s32 CVideo::TakeScreenshot(const char *path)

View File

@ -64,6 +64,7 @@ public:
bool wide(void) const { return m_wide; }
bool vid_50hz(void) const { return m_50hz; }
u8 getAA(void) const { return m_aa; }
bool showingWaitMessage() { return m_showingWaitMessages; }
void set2DViewport(u32 w, u32 h, int x, int y);
void prepareStencil(void);
void renderStencil(void);

View File

@ -22,7 +22,7 @@ typedef void *(*app_final)();
typedef void (*app_entry)(void (**init)(void (*report)(const char *fmt, ...)), int (**main)(), void *(**final)());
/* Apploader pointers */
static u8 *appldr = (u8 *) 0x81200000;
static u8 *appldr = (u8 *)0x81200000;
/* Constants */
#define APPLDR_OFFSET 0x2440
@ -57,11 +57,15 @@ s32 Apploader_Run(entry_point *entry, u8 vidMode, GXRModeObj *vmode, bool vipatc
/* Calculate apploader length */
appldr_len = buffer[5] + buffer[6];
SYS_SetArena1Hi((void *)0x816FFFF0); //Kills the possibility of codedumps with gprintf
/* Read apploader code */
ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20);
if (ret < 0)
if(ret < 0)
return ret;
DCFlushRange(appldr, appldr_len);
/* Set apploader entry function */
app_entry appldr_entry = (app_entry)buffer[4];

View File

@ -241,7 +241,7 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size)
frag_concat(fa, fs);
}
frag_list = MEM1_memalign(32, sizeof(FragList));
frag_list = MEM1_alloc(ALIGN32(sizeof(FragList)));
if(frag_list == NULL)
goto out;
@ -307,10 +307,12 @@ int set_frag_list(u8 *id)
DCFlushRange(frag_list, size);
gprintf("Calling WDVD_SetFragList, frag list size %d\n", size);
/* if (size > 400) ghexdump(frag_list, 400);
else ghexdump(frag_list, size); */
int ret = WDVD_SetFragList(wbfsDev, frag_list, size);
MEM1_free(frag_list);
free(frag_list);
frag_list = NULL;
if(ret)

View File

@ -12,7 +12,7 @@
#include <ctype.h>
#include "splits.h"
#include "gecko/gecko.h"
#include "gecko.h"
#define off64_t off_t
#define FMT_llu "%llu"
@ -21,7 +21,7 @@
#define split_error(x) do { gprintf("\nsplit error: %s\n\n",x); } while(0)
// 1 cluster less than 4gb
u64 OPT_split_size = (u64) 4LL * 1024 * 1024 * 1024 - 32 * 1024;
u64 OPT_split_size = (u64)4LL * 1024 * 1024 * 1024 - 32 * 1024;
// 1 cluster less than 2gb
//u64 OPT_split_size = (u64)2LL * 1024 * 1024 * 1024 - 32 * 1024;
@ -88,7 +88,7 @@ int split_fill(split_info_t *s, int idx, u64 size)
int fd = split_open_file(s, idx);
off64_t fsize = lseek(fd, 0, SEEK_END);
if ((u64)fsize < size)
if((u64)fsize < size)
{
// gprintf("TRUNC %d "FMT_lld" "FMT_lld"\n", idx, size, fsize); // Wpad_WaitButtons();
ftruncate(fd, size);

View File

@ -53,6 +53,8 @@ wbfs_disc_t* WBFS_Ext_OpenDisc(u8 *discid, char *fname)
if (fd == -1) return NULL;
wbfs_disc_t *iso_file = MEM2_alloc(sizeof(wbfs_disc_t));
memset(iso_file, 0, sizeof(wbfs_disc_t));
if (iso_file == NULL)
return NULL;

View File

@ -58,7 +58,7 @@ void do_wip_code(u8 * dst, u32 len)
//! if set was successful the codelist will be freed when it's done
bool set_wip_list(WIP_Code * list, int size)
{
if (!CodeList && size > 0)
if(!CodeList && size > 0)
{
CodeList = list;
CodesCount = size;
@ -92,8 +92,8 @@ int load_wip_patches(u8 *dir, u8 *gameid)
memcpy(GameID, gameid, 6);
snprintf(filepath, sizeof(filepath), "%s/%s.wip", dir, GameID);
FILE * fp = fopen(filepath, "rb");
if (!fp)
FILE *fp = fopen(filepath, "rb");
if(!fp)
{
memset(GameID, 0, sizeof(GameID));
memcpy(GameID, gameid, 3);
@ -101,17 +101,16 @@ int load_wip_patches(u8 *dir, u8 *gameid)
fp = fopen(filepath, "rb");
}
if (!fp)
if(!fp)
return -1;
char line[255];
gprintf("\nLoading WIP code from %s.\n", filepath);
while (fgets(line, sizeof(line), fp))
while(fgets(line, sizeof(line), fp))
{
if (line[0] == '#') continue;
if(strlen(line) < 26) continue;
if(line[0] == '#' || strlen(line) < 26)
continue;
u32 offset = (u32) strtoul(line, NULL, 16);
u32 srcaddress = (u32) strtoul(line+9, NULL, 16);

View File

@ -37,7 +37,7 @@ int main(int argc, char **argv)
vid.init();
MEM2_init(47); //Should be safe to use
vid.waitMessage(0.2f);
vid.waitMessage(0.1f);
AllocSDGeckoBuffer();
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);

View File

@ -1812,8 +1812,9 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting)
m_btnMgr.draw();
ScanInput();
if(!m_vid.showingWaitMessage())
m_vid.render();
if(!blockReboot)
{
if(withCF && Sys_Exiting())

View File

@ -1427,7 +1427,6 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
if(currentPartition == 0)
SDHC_Init();
GeckoDisable();
#endif
RunApploader(offset, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio, returnTo);

View File

@ -188,11 +188,12 @@ int CMenu::GetCoverStatusAsync(CMenu *m)
void CMenu::LoadView(void)
{
_showWaitMessage();
_hideMain();
m_curGameId = m_cf.getId();
_hideMain(true);
m_cf.clear();
_showWaitMessage();
_loadList();
_showMain();
_initCF();
@ -418,8 +419,10 @@ int CMenu::main(void)
}
else if(m_btnMgr.selected(m_mainBtnDVD))
{
_showWaitMessage();
_hideMain(true);
m_cf.clear();
_showWaitMessage();
dir_discHdr hdr;
memset(&hdr, 0, sizeof(dir_discHdr));
memcpy(&hdr.id, "dvddvd", 6);

View File

@ -53,37 +53,39 @@ typedef struct
# define UnsignedToFloat(u) (((double)((long)(u - 2147483647L - 1))) + 2147483648.0)
static double ConvertFromIeeeExtended(const unsigned char* bytes)
static double ConvertFromIeeeExtended(const u8* bytes)
{
double f;
int expon;
unsigned long hiMant, loMant;
u64 hiMant, loMant;
expon = ((bytes[0] & 0x7F) << 8) | (bytes[1] & 0xFF);
hiMant = ((unsigned long)(bytes[2] & 0xFF) << 24)
| ((unsigned long)(bytes[3] & 0xFF) << 16)
| ((unsigned long)(bytes[4] & 0xFF) << 8)
| ((unsigned long)(bytes[5] & 0xFF));
loMant = ((unsigned long)(bytes[6] & 0xFF) << 24)
| ((unsigned long)(bytes[7] & 0xFF) << 16)
| ((unsigned long)(bytes[8] & 0xFF) << 8)
| ((unsigned long)(bytes[9] & 0xFF));
if (expon == 0 && hiMant == 0 && loMant == 0) {
hiMant = ((u64)(bytes[2] & 0xFF) << 24)
| ((u64)(bytes[3] & 0xFF) << 16)
| ((u64)(bytes[4] & 0xFF) << 8)
| ((u64)(bytes[5] & 0xFF));
loMant = ((u64)(bytes[6] & 0xFF) << 24)
| ((u64)(bytes[7] & 0xFF) << 16)
| ((u64)(bytes[8] & 0xFF) << 8)
| ((u64)(bytes[9] & 0xFF));
if(expon == 0 && hiMant == 0 && loMant == 0)
f = 0;
}
else {
if (expon == 0x7FFF) {
else
{
if(expon == 0x7FFF)
f = HUGE_VAL;
}
else {
else
{
expon -= 16383;
f = ldexp(UnsignedToFloat(hiMant), expon-=31);
f += ldexp(UnsignedToFloat(loMant), expon-=32);
}
}
if (bytes[0] & 0x80)
if(bytes[0] & 0x80)
return -f;
else
return f;
@ -227,9 +229,7 @@ int AifDecoder::Read(u8 * buffer, int buffer_size, int)
int read = file_fd->read(buffer, buffer_size);
if(read > 0)
{
CurPos += read;
}
return read;
}

View File

@ -31,14 +31,14 @@
class AifDecoder : public SoundDecoder
{
public:
AifDecoder(const char * filepath);
AifDecoder(const u8 * snd, int len);
public:
AifDecoder(const char *filepath);
AifDecoder(const u8 *snd, int len);
~AifDecoder();
int GetFormat() { return Format; };
int GetSampleRate() { return SampleRate; };
int Read(u8 * buffer, int buffer_size, int pos);
protected:
int Read(u8 *buffer, int buffer_size, int pos);
protected:
void OpenFile();
void CloseFile();
u32 DataOffset;

View File

@ -66,7 +66,7 @@ BNSDecoder::~BNSDecoder()
void BNSDecoder::OpenFile()
{
u8 * tempbuff = new (std::nothrow) u8[file_fd->size()];
u8 *tempbuff = new (std::nothrow) u8[file_fd->size()];
if(!tempbuff)
{
CloseFile();

View File

@ -30,7 +30,7 @@
typedef struct _SoundBlock
{
u8 * buffer;
u8 *buffer;
u32 size;
u8 format;
u32 frequency;
@ -41,14 +41,14 @@ typedef struct _SoundBlock
class BNSDecoder : public SoundDecoder
{
public:
public:
BNSDecoder(const char * filepath);
BNSDecoder(const u8 * snd, int len);
~BNSDecoder();
int GetFormat() { return SoundData.format; };
int GetSampleRate() { return SoundData.frequency; };
int Read(u8 * buffer, int buffer_size, int pos);
protected:
protected:
void OpenFile();
void CloseFile();
SoundBlock SoundData;

View File

@ -32,7 +32,7 @@
class BufferCircle
{
public:
public:
//!> Constructor
BufferCircle();
//!> Destructor
@ -79,7 +79,7 @@ class BufferCircle
void SetBufferSize(int pos, int size);
//!> Get the current position in the circle
u16 Which() { return which; };
protected:
protected:
//!> Check if the position is a valid position in the vector
bool Valid(int pos) { return !(pos < 0 || pos >= Size()); };

View File

@ -112,17 +112,11 @@ int CFile::seek(long int offset, int origin)
int ret = 0;
if(origin == SEEK_SET)
{
Pos = offset;
}
else if(origin == SEEK_CUR)
{
Pos += offset;
}
else if(origin == SEEK_END)
{
Pos = filesize+offset;
}
if(Pos < 0)
{
Pos = 0;
@ -132,14 +126,11 @@ int CFile::seek(long int offset, int origin)
if(file_fd)
ret = fseek(file_fd, Pos, SEEK_SET);
if(mem_file != NULL)
{
if(Pos > (long int) filesize)
if(mem_file != NULL && Pos > (long int)filesize)
{
Pos = filesize;
return -1;
}
}
return ret;
}

View File

@ -6,7 +6,7 @@
class CFile
{
public:
public:
CFile();
CFile(const char * filepath, const char * mode);
CFile(const u8 * memory, int memsize);
@ -20,7 +20,7 @@ class CFile
long int tell() { return Pos; };
long int size() { return filesize; };
void rewind() { seek(0, SEEK_SET); };
protected:
protected:
FILE * file_fd;
const u8 * mem_file;
u64 filesize;

View File

@ -155,12 +155,12 @@ int Mp3Decoder::Read(u8 * buffer, int buffer_size, int)
if(write_pos >= write_end)
return write_pos-buffer;
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
*((s16 *)write_pos) = FixedToShort(Synth.pcm.samples[0][SynthPos]);
write_pos += 2;
if(MAD_NCHANNELS(&Frame.header) == 2)
{
*((s16 *) write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
*((s16 *)write_pos) = FixedToShort(Synth.pcm.samples[1][SynthPos]);
write_pos += 2;
}
SynthPos++;
@ -168,7 +168,7 @@ int Mp3Decoder::Read(u8 * buffer, int buffer_size, int)
if(Stream.buffer == NULL || Stream.error == MAD_ERROR_BUFLEN)
{
u8 * ReadStart = ReadBuffer;
u8 *ReadStart = ReadBuffer;
int ReadSize = SoundBlockSize*SoundBlocks;
int Remaining = 0;

View File

@ -29,7 +29,7 @@
class Mp3Decoder : public SoundDecoder
{
public:
public:
Mp3Decoder(const char * filepath);
Mp3Decoder(const u8 * sound, int len);
~Mp3Decoder();
@ -37,7 +37,7 @@ class Mp3Decoder : public SoundDecoder
int GetSampleRate() { return SampleRate; };
int Rewind();
int Read(u8 * buffer, int buffer_size, int pos);
protected:
protected:
void OpenFile();
struct mad_stream Stream;
struct mad_frame Frame;

View File

@ -38,13 +38,13 @@ extern "C" int ogg_seek(int *f, ogg_int64_t offset, int mode)
extern "C" int ogg_close(int *f)
{
((CFile *) f)->close();
((CFile*)f)->close();
return 0;
}
extern "C" long ogg_tell(int *f)
{
return (long) ((CFile *) f)->tell();
return (long)((CFile *)f)->tell();
}
static ov_callbacks callbacks = {
@ -88,7 +88,7 @@ OggDecoder::~OggDecoder()
void OggDecoder::OpenFile()
{
if (ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
if(ov_open_callbacks(file_fd, &ogg_file, NULL, 0, callbacks) < 0)
{
delete file_fd;
file_fd = NULL;

View File

@ -30,7 +30,7 @@
class OggDecoder : public SoundDecoder
{
public:
public:
OggDecoder(const char * filepath);
OggDecoder(const u8 * snd, int len);
~OggDecoder();
@ -38,7 +38,7 @@ class OggDecoder : public SoundDecoder
int GetSampleRate();
int Rewind();
int Read(u8 * buffer, int buffer_size, int pos);
protected:
protected:
void OpenFile();
OggVorbis_File ogg_file;
vorbis_info *ogg_info;

View File

@ -97,7 +97,7 @@ void SoundDecoder::Decode()
u16 newWhich = SoundBuffer.Which();
u16 i = 0;
for (i = 0; i < SoundBuffer.Size()-2; i++)
for(i = 0; i < SoundBuffer.Size()-2; i++)
{
if(!SoundBuffer.IsBufferReady(newWhich))
break;
@ -111,7 +111,7 @@ void SoundDecoder::Decode()
Decoding = true;
int done = 0;
u8 * write_buf = SoundBuffer.GetBuffer(newWhich);
u8 *write_buf = SoundBuffer.GetBuffer(newWhich);
if(!write_buf)
{
ExitRequested = true;

View File

@ -34,7 +34,7 @@
class SoundHandler
{
public:
public:
static SoundHandler * Instance();
static void DestroyInstance();
@ -46,7 +46,7 @@ class SoundHandler
SoundDecoder * Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); };
void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); };
bool IsDecoding() { return Decoding; };
protected:
protected:
SoundHandler();
~SoundHandler();
static void * UpdateThread(void *arg);

View File

@ -54,6 +54,7 @@ WavDecoder::WavDecoder(const u8 * snd, int len)
WavDecoder::~WavDecoder()
{
CloseFile();
}
void WavDecoder::OpenFile()
@ -66,7 +67,7 @@ void WavDecoder::OpenFile()
file_fd->read((u8 *) &Header, sizeof(SWaveHdr));
file_fd->read((u8 *) &FmtChunk, sizeof(SWaveFmtChunk));
if (Header.magicRIFF != 'RIFF')
if(Header.magicRIFF != 'RIFF')
{
CloseFile();
return;
@ -104,13 +105,13 @@ void WavDecoder::OpenFile()
Is16Bit = (le16(FmtChunk.bps) == 16);
SampleRate = le32(FmtChunk.freq);
if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
if(le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 1)
Format = VOICE_MONO_8BIT;
else if (le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 2)
else if(le16(FmtChunk.channels) == 1 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 2)
Format = VOICE_MONO_16BIT;
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 2)
else if(le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 8 && le16(FmtChunk.alignment) <= 2)
Format = VOICE_STEREO_8BIT;
else if (le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
else if(le16(FmtChunk.channels) == 2 && le16(FmtChunk.bps) == 16 && le16(FmtChunk.alignment) <= 4)
Format = VOICE_STEREO_16BIT;
Decode();
@ -140,12 +141,12 @@ int WavDecoder::Read(u8 * buffer, int buffer_size, int)
int read = file_fd->read(buffer, buffer_size);
if(read > 0)
{
if (Is16Bit)
if(Is16Bit)
{
read &= ~0x0001;
for (u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
((u16 *) buffer)[i] = le16(((u16 *) buffer)[i]);
for(u32 i = 0; i < (u32) (read / sizeof (u16)); ++i)
((u16 *)buffer)[i] = le16(((u16 *)buffer)[i]);
}
CurPos += read;
}

View File

@ -55,14 +55,14 @@ typedef struct
class WavDecoder : public SoundDecoder
{
public:
public:
WavDecoder(const char * filepath);
WavDecoder(const u8 * snd, int len);
~WavDecoder();
int GetFormat() { return Format; };
int GetSampleRate() { return SampleRate; };
int Read(u8 * buffer, int buffer_size, int pos);
protected:
protected:
void OpenFile();
void CloseFile();
u32 DataOffset;

View File

@ -55,8 +55,9 @@ static inline int GetFirstUnusedVoice()
extern "C" void SoundCallback(s32 voice)
{
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder) return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
return;
if(decoder->IsBufferReady())
{
@ -98,11 +99,12 @@ GuiSound::GuiSound(GuiSound *g)
voice = -1;
Init();
if (g == NULL) return;
if(g == NULL)
return;
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);
Load(snd, g->length, true);
}
@ -161,7 +163,8 @@ bool GuiSound::Load(const char * filepath)
FILE * f = fopen(filepath, "rb");
if(!f)
{ gprintf("Failed to load file %s!!\n", filepath);
{
gprintf("Failed to load file %s!!\n", filepath);
return false;
}
@ -173,12 +176,14 @@ bool GuiSound::Load(const char * filepath)
gprintf("Loading %s using voice %d\n", filepath, voice);
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
{ gprintf("No Decoder!!!\n");
{
gprintf("No Decoder!!!\n");
return false;
}
if(!decoder->IsBufferReady())
{ gprintf("Buffer not ready!!n");
{
gprintf("Buffer not ready!!\n");
SoundHandler::Instance()->RemoveDecoder(voice);
return false;
}
@ -194,15 +199,14 @@ bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
FreeMemory();
this->voice = voice;
if(!snd) return false;
if(!snd)
return false;
if(!isallocated && *((u32 *) snd) == 'RIFF')
return LoadSoundEffect(snd, len);
if(*((u32 *) snd) == 'IMD5')
{
UncompressSoundbin(snd, len, isallocated);
}
else
{
sound = (u8 *) snd;
@ -214,9 +218,7 @@ bool GuiSound::Load(const u8 * snd, u32 len, bool isallocated)
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
{
return false;
}
if(!decoder->IsBufferReady())
{
@ -274,10 +276,12 @@ void GuiSound::Play(int vol, bool restart)
return;
}
if((IsPlaying() && !restart) || voice < 0 || voice >= 16) return;
if((IsPlaying() && !restart) || voice < 0 || voice >= 16)
return;
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder) return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
return;
ASND_StopVoice(voice);
if(decoder->IsEOF())
@ -303,13 +307,14 @@ void GuiSound::Play()
void GuiSound::Stop()
{
volume = 0;
if (!IsPlaying() || voice < 0 || voice >= 16)
if(!IsPlaying() || voice < 0 || voice >= 16)
return;
ASND_StopVoice(voice);
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder) return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
return;
decoder->ClearBuffer();
Rewind();
@ -361,16 +366,18 @@ void GuiSound::SetLoop(u8 l)
{
loop = l;
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder) return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
return;
decoder->SetLoop(l == 1);
}
void GuiSound::Rewind()
{
SoundDecoder * decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder) return;
SoundDecoder *decoder = SoundHandler::Instance()->Decoder(voice);
if(!decoder)
return;
decoder->Rewind();
}
@ -397,24 +404,25 @@ u8 * uncompressLZ77(const u8 *inBuf, u32 inLength, u32 * size)
buffer = (u8 *)malloc(uncSize);
if (!buffer) return buffer;
if(!buffer)
return buffer;
u8 *bufCur = buffer;
u8 *bufEnd = buffer + uncSize;
while (bufCur < bufEnd && inBuf < inBufEnd)
while(bufCur < bufEnd && inBuf < inBufEnd)
{
u8 flags = *inBuf;
++inBuf;
int i = 0;
for (i = 0; i < 8 && bufCur < bufEnd && inBuf < inBufEnd; ++i)
for(i = 0; i < 8 && bufCur < bufEnd && inBuf < inBufEnd; ++i)
{
if ((flags & 0x80) != 0)
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)
if(bufCur - info->offset - 1 < buffer || bufCur + length > bufEnd)
return buffer;
memcpy(bufCur, bufCur - info->offset - 1, length);
bufCur += length;
@ -439,7 +447,8 @@ void GuiSound::UncompressSoundbin(const u8 * snd, u32 len, bool isallocated)
const u8 * file = snd+32;
length = len-32;
if (length <= 0) return;
if(length <= 0)
return;
if(*((u32 *) file) == 'LZ77')
{

View File

@ -32,7 +32,7 @@
//!Sound conversion and playback. A wrapper for other sound libraries - ASND, libmad, ltremor, etc
class GuiSound
{
public:
public:
//!Constructor
GuiSound();
//!Copy Constructor
@ -81,12 +81,12 @@ class GuiSound
void SetVolume(int v);
//!\param l Loop (true to loop)
void SetLoop(u8 l);
private:
private:
//!Initializes the GuiSound object by setting the default values
void Init();
//!Special sound case for sound.bin
void UncompressSoundbin(const u8 * snd, u32 len, bool isallocated);
protected:
protected:
std::string filepath;
u8 *sound; //!< Pointer to the sound data
u32 length; //!< Length of sound data

View File

@ -40,7 +40,8 @@
ZipFile::ZipFile(const char *filepath)
{
File = unzOpen(filepath);
if (File) this->LoadList();
if(File)
this->LoadList();
}
ZipFile::~ZipFile()
@ -52,82 +53,34 @@ bool ZipFile::LoadList()
{
return true;
}
/*
bool ZipFile::FindFile(const char *file)
{
if (!File) return false;
char filename[MAXPATHLEN];
int ret = unzGoToFirstFile(File);
if (ret != UNZ_OK) return false;
do
{
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
continue;
const char *realfilename = strrchr(filename, '/');
if(!realfilename || strlen(realfilename) == 0)
realfilename = filename;
if(strcasecmp(realfilename, file) == 0)
return true;
}
while(unzGoToNextFile(File) == UNZ_OK);
return false;
}
bool ZipFile::FindFilePart(const char *partfilename, std::string &realname)
{
if (!File) return false;
char filename[MAXPATHLEN];
int ret = unzGoToFirstFile(File);
if (ret != UNZ_OK) return false;
do
{
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
continue;
if(strcasestr(filename, partfilename) != 0)
{
realname = filename;
return true;
}
}
while(unzGoToNextFile(File) == UNZ_OK);
return false;
}
*/
bool ZipFile::ExtractAll(const char *dest)
{
if (!File) return false;
if(!File)
return false;
bool Stop = false;
u32 blocksize = 1024 * 50;
u8 *buffer = new u8[blocksize];
if (!buffer) return false;
if(!buffer)
return false;
char writepath[MAXPATHLEN];
char filename[MAXPATHLEN];
memset(filename, 0, sizeof(filename));
int ret = unzGoToFirstFile(File);
if (ret != UNZ_OK) Stop = true;
while (!Stop)
{
if (unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
if(ret != UNZ_OK)
Stop = true;
if (!Stop && filename[strlen(filename) - 1] != '/')
while(!Stop)
{
if(unzGetCurrentFileInfo(File, &cur_file_info, filename, sizeof(filename), NULL, 0, NULL, 0) != UNZ_OK)
Stop = true;
if(!Stop && filename[strlen(filename) - 1] != '/')
{
u32 uncompressed_size = cur_file_info.uncompressed_size;
@ -146,29 +99,32 @@ bool ZipFile::ExtractAll(const char *dest)
fsop_MakeFolder(temppath);
if (ret == UNZ_OK)
if(ret == UNZ_OK)
{
FILE *pfile = fopen(writepath, "wb");
do
{
if (uncompressed_size - done < blocksize) blocksize = uncompressed_size - done;
if(uncompressed_size - done < blocksize)
blocksize = uncompressed_size - done;
ret = unzReadCurrentFile(File, buffer, blocksize);
if (ret == 0) break;
if(ret == 0)
break;
fwrite(buffer, 1, blocksize, pfile);
done += ret;
} while (done < uncompressed_size);
} while(done < uncompressed_size);
fclose(pfile);
unzCloseCurrentFile(File);
}
}
if (unzGoToNextFile(File) != UNZ_OK) Stop = true;
if(unzGoToNextFile(File) != UNZ_OK)
Stop = true;
}
delete[] buffer;

View File

@ -40,7 +40,7 @@ typedef struct
class ZipFile
{
public:
public:
//!Constructor
ZipFile(const char *filepath);
//!Destructor
@ -48,7 +48,7 @@ class ZipFile
//!Extract all files from a zip file to a directory
//!\param dest Destination path to where to extract
bool ExtractAll(const char *dest);
protected:
protected:
bool LoadList();
unzFile File;
unz_file_info cur_file_info;