2010-10-28 11:00:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "GameTitles.h"
|
2010-12-03 19:38:57 +01:00
|
|
|
#include "CSettings.h"
|
|
|
|
#include "usbloader/GameList.h"
|
|
|
|
#include "xml/WiiTDB.hpp"
|
2010-10-28 11:00:52 +02:00
|
|
|
|
|
|
|
CGameTitles GameTitles;
|
|
|
|
|
|
|
|
void CGameTitles::SetGameTitle(const char * id, const char * title)
|
|
|
|
{
|
|
|
|
if(!id || !title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(u32 i = 0; i < TitleList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
|
|
|
|
{
|
|
|
|
TitleList[i].Title = title;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GameTitle newTitle;
|
|
|
|
newTitle.Title = title;
|
2011-02-11 18:41:52 +01:00
|
|
|
snprintf(newTitle.GameID, sizeof(newTitle.GameID), id);
|
2010-10-28 11:00:52 +02:00
|
|
|
|
|
|
|
TitleList.push_back(newTitle);
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
const char * CGameTitles::GetTitle(const char * id) const
|
2010-10-28 11:00:52 +02:00
|
|
|
{
|
|
|
|
if(!id)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for(u32 i = 0; i < TitleList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
|
|
|
|
return TitleList[i].Title.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
const char * CGameTitles::GetTitle(const struct discHdr *header) const
|
2010-10-28 11:00:52 +02:00
|
|
|
{
|
|
|
|
if(!header)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for(u32 i = 0; i < TitleList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp((const char *) header->id, TitleList[i].GameID, 6) == 0)
|
|
|
|
return TitleList[i].Title.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return header->title;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:05:31 +01:00
|
|
|
int CGameTitles::GetParentalRating(const char * id) const
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
{
|
|
|
|
if(!id)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for(u32 i = 0; i < TitleList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
|
|
|
|
return TitleList[i].ParentalRating;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-02 19:30:15 +01:00
|
|
|
|
|
|
|
int CGameTitles::GetPlayersCount(const char * id) const
|
|
|
|
{
|
|
|
|
if(!id)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for(u32 i = 0; i < TitleList.size(); ++i)
|
|
|
|
{
|
|
|
|
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
|
|
|
|
return TitleList[i].PlayersCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-10-28 11:00:52 +02:00
|
|
|
void CGameTitles::SetDefault()
|
|
|
|
{
|
|
|
|
TitleList.clear();
|
|
|
|
//! Free vector memory
|
|
|
|
std::vector<GameTitle>().swap(TitleList);
|
|
|
|
}
|
2010-12-03 19:38:57 +01:00
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
typedef struct _CacheTitle
|
|
|
|
{
|
|
|
|
char GameID[7];
|
|
|
|
char Title[100];
|
|
|
|
int ParentalRating;
|
|
|
|
int PlayersCount;
|
|
|
|
|
|
|
|
} ATTRIBUTE_PACKED CacheTitle;
|
|
|
|
|
|
|
|
u32 CGameTitles::ReadCachedTitles(const char * path)
|
|
|
|
{
|
|
|
|
//! Load cached least so that the titles are preloaded before reading list
|
|
|
|
FILE * f = fopen(path, "rb");
|
|
|
|
if(!f) return 0;
|
|
|
|
|
|
|
|
char LangCode[11];
|
|
|
|
memset(LangCode, 0, sizeof(LangCode));
|
|
|
|
|
|
|
|
fread(LangCode, 1, 10, f);
|
|
|
|
|
|
|
|
//! Check if cache has correct language code
|
|
|
|
if(strcmp(LangCode, Settings.db_language) != 0)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 count = 0;
|
|
|
|
fread(&count, 1, 4, f);
|
|
|
|
|
|
|
|
std::vector<CacheTitle> CachedList(count);
|
|
|
|
TitleList.resize(count);
|
|
|
|
|
|
|
|
fread(&CachedList[0], 1, count*sizeof(CacheTitle), f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
for(u32 i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
strcpy(TitleList[i].GameID, CachedList[i].GameID);
|
|
|
|
TitleList[i].Title = CachedList[i].Title;
|
|
|
|
TitleList[i].ParentalRating = CachedList[i].ParentalRating;
|
|
|
|
TitleList[i].PlayersCount = CachedList[i].PlayersCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTitles::WriteCachedTitles(const char * path)
|
|
|
|
{
|
|
|
|
FILE *f = fopen(path, "wb");
|
|
|
|
if(!f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CacheTitle Cache;
|
|
|
|
u32 count = TitleList.size();
|
|
|
|
|
|
|
|
fwrite(Settings.db_language, 1, 10, f);
|
|
|
|
fwrite(&count, 1, 4, f);
|
|
|
|
|
|
|
|
for(u32 i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
memset(&Cache, 0, sizeof(CacheTitle));
|
|
|
|
|
|
|
|
strcpy(Cache.GameID, TitleList[i].GameID);
|
|
|
|
snprintf(Cache.Title, sizeof(Cache.Title), TitleList[i].Title.c_str());
|
|
|
|
Cache.ParentalRating = TitleList[i].ParentalRating;
|
|
|
|
Cache.PlayersCount = TitleList[i].PlayersCount;
|
|
|
|
|
|
|
|
fwrite(&Cache, 1, sizeof(CacheTitle), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameTitles::RemoveUnusedCache(std::vector<std::string> &MissingTitles)
|
|
|
|
{
|
|
|
|
std::vector<bool> UsedCachedList(TitleList.size(), false);
|
|
|
|
|
|
|
|
for(int i = 0; i < gameList.GameCount(); ++i)
|
|
|
|
{
|
|
|
|
bool isCached = false;
|
|
|
|
|
|
|
|
for(u32 n = 0; n < TitleList.size(); ++n)
|
|
|
|
{
|
2011-03-20 17:24:32 +01:00
|
|
|
if(strncasecmp(TitleList[n].GameID, (const char *) gameList[i]->id, 6) == 0)
|
2011-02-11 18:41:52 +01:00
|
|
|
{
|
|
|
|
UsedCachedList[n] = true;
|
|
|
|
isCached = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isCached)
|
|
|
|
{
|
|
|
|
char gameID[7];
|
|
|
|
snprintf(gameID, sizeof(gameID), (const char *) gameList[i]->id);
|
|
|
|
MissingTitles.push_back(std::string(gameID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(u32 n = 0; n < TitleList.size(); ++n)
|
|
|
|
{
|
|
|
|
if(!UsedCachedList[n])
|
|
|
|
TitleList.erase(TitleList.begin()+n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-14 22:19:21 +01:00
|
|
|
void CGameTitles::LoadTitlesFromWiiTDB(const char * path, bool forceCacheReload)
|
2010-12-03 19:38:57 +01:00
|
|
|
{
|
|
|
|
this->SetDefault();
|
|
|
|
|
|
|
|
if(!path || !Settings.titlesOverride)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string Filepath = path;
|
|
|
|
if(path[strlen(path)-1] != '/')
|
|
|
|
Filepath += '/';
|
2011-02-11 18:41:52 +01:00
|
|
|
|
|
|
|
std::string Cachepath = Filepath;
|
|
|
|
Cachepath += "TitlesCache.bin";
|
2010-12-03 19:38:57 +01:00
|
|
|
Filepath += "wiitdb.xml";
|
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
//! Read game titles cache database
|
2011-03-14 22:19:21 +01:00
|
|
|
if(!forceCacheReload && Settings.CacheTitles)
|
2011-02-12 10:50:35 +01:00
|
|
|
ReadCachedTitles(Cachepath.c_str());
|
2011-02-11 18:41:52 +01:00
|
|
|
|
|
|
|
//! Read game list
|
|
|
|
gameList.LoadUnfiltered();
|
|
|
|
|
|
|
|
//! Removed unused cache titles and get the still missing ones
|
|
|
|
std::vector<std::string> MissingTitles;
|
|
|
|
RemoveUnusedCache(MissingTitles);
|
|
|
|
if(MissingTitles.size() == 0)
|
|
|
|
{
|
|
|
|
WriteCachedTitles(Cachepath.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Title;
|
|
|
|
|
2010-12-03 19:38:57 +01:00
|
|
|
WiiTDB XML_DB(Filepath.c_str());
|
|
|
|
XML_DB.SetLanguageCode(Settings.db_language);
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
int Rating;
|
|
|
|
std::string RatValTxt;
|
2010-12-03 19:38:57 +01:00
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
for(u32 i = 0; i < MissingTitles.size(); ++i)
|
2010-12-03 19:38:57 +01:00
|
|
|
{
|
2011-02-11 18:41:52 +01:00
|
|
|
if(!XML_DB.GetTitle(MissingTitles[i].c_str(), Title))
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
continue;
|
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
this->SetGameTitle(MissingTitles[i].c_str(), Title.c_str());
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
|
|
|
|
TitleList[TitleList.size()-1].ParentalRating = -1;
|
2011-02-02 19:30:15 +01:00
|
|
|
TitleList[TitleList.size()-1].PlayersCount = 1;
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
Rating = XML_DB.GetRating(MissingTitles[i].c_str());
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
if(Rating < 0)
|
|
|
|
continue;
|
|
|
|
|
2011-02-11 18:41:52 +01:00
|
|
|
if(!XML_DB.GetRatingValue(MissingTitles[i].c_str(), RatValTxt))
|
*Completely rewrote the asynchron GuiImageData class (problems from switch Carousel<->Grid layour should be fixed now)
*Fixed bug mounting a wbfs partition which was formatted from an ext partition
*Rewrote the parental control feature. Removed loading pin or settings from the Wii Settings. Parental control is now completely managed in the loader from the settings selected and the password set.
*Saving password in config file is now encrypted
*Added loop to wait for usb when reloading the cIOS before game start
The parental control feature is filtering games like following when usb loader is locked:
level 0 (everyone 0+) > shows only games with lvl 0
level 1 (childs 7+) > shows games with lvl 0, 1
level 2 (teens 12+) > shows games with lvl 0, 1, 2
level 3 (mature 16+) > shows games with lvl 0, 1, 2, 3
level 4 (adults only 18+) > shows all games (lvl 0, 1, 2, 3, 4)
level 4 is default when creating new configs
2010-12-19 19:20:33 +01:00
|
|
|
continue;
|
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
TitleList[TitleList.size()-1].ParentalRating = WiiTDB::ConvertRating(RatValTxt.c_str(), WiiTDB::RatingToString(Rating), "PEGI");
|
2011-02-11 18:41:52 +01:00
|
|
|
int ret = XML_DB.GetPlayers(MissingTitles[i].c_str());
|
2011-02-02 19:30:15 +01:00
|
|
|
if(ret > 0)
|
|
|
|
TitleList[TitleList.size()-1].PlayersCount = ret;
|
2010-12-03 19:38:57 +01:00
|
|
|
}
|
2011-02-11 18:41:52 +01:00
|
|
|
|
2011-02-12 10:50:35 +01:00
|
|
|
if(Settings.CacheTitles)
|
|
|
|
WriteCachedTitles(Cachepath.c_str());
|
2010-12-03 19:38:57 +01:00
|
|
|
}
|