Improve region info accuracy

This commit is contained in:
wiidev 2023-01-01 17:00:12 +00:00
parent 921f67438b
commit 201813f6f9
4 changed files with 101 additions and 38 deletions

View File

@ -33,6 +33,7 @@
#include "utils/ShowError.h" #include "utils/ShowError.h"
#include "utils/tools.h" #include "utils/tools.h"
#include "utils/PasswordCheck.h" #include "utils/PasswordCheck.h"
#include "xml/GameTDB.hpp"
#include "gecko.h" #include "gecko.h"
#include "menus.h" #include "menus.h"
#include "wpad.h" #include "wpad.h"
@ -1354,7 +1355,7 @@ int GameBrowseMenu::MainLoop()
{ {
struct discHdr *header = gameList[gameSelected]; struct discHdr *header = gameList[gameSelected];
LoadCover(header); LoadCover(header);
UpdateGameInfoText(header->id); UpdateGameInfoText(header);
} }
} }
@ -1463,9 +1464,9 @@ void GameBrowseMenu::UpdateClock()
} }
} }
void GameBrowseMenu::UpdateGameInfoText(const u8 * gameId) void GameBrowseMenu::UpdateGameInfoText(struct discHdr *header)
{ {
if(!gameId) if (!header)
{ {
Remove(GameRegionTxt); Remove(GameRegionTxt);
delete GameRegionTxt; delete GameRegionTxt;
@ -1476,35 +1477,70 @@ void GameBrowseMenu::UpdateGameInfoText(const u8 * gameId)
return; return;
} }
char gameregion[10]; std::string gameregion;
char IDfull[7]; char IDfull[7];
snprintf(IDfull, sizeof(IDfull), (char *) gameId); snprintf(IDfull, sizeof(IDfull), (char *) header->id);
switch (IDfull[3]) const char *region = GameTitles.GetRegion(IDfull);
if (strcmp(region, "NULL") != 0)
gameregion = region;
else
{ {
case 'A': char sys[2];
case 'B': char reg[2];
case 'U': snprintf(sys, sizeof(sys), "%c", IDfull[0]);
case 'X': snprintf(reg, sizeof(reg), "%c", IDfull[3]);
strcpy(gameregion, tr("Region Free")); if (header->type >= TYPE_GAME_NANDCHAN)
break; {
case 'E': // Force some homebrew to display as region free
case 'N': char regions[] = "ABDEFHIJKLMNPQRSTUVW";
strcpy(gameregion, "NTSC U"); char systems[] = "CEFHJLMNPQWX";
break; if (!(strstr(systems, sys) && strstr(regions, reg)))
case 'J': reg[0] = 'A';
strcpy(gameregion, "NTSC J"); if (memcmp(IDfull, "JODI", 4) == 0)
break; reg[0] = 'A';
case 'K': if (memcmp(IDfull, "IDCL", 4) == 0)
case 'Q': reg[0] = 'A';
case 'T': }
strcpy(gameregion, "NTSC K");
break; switch (reg[0])
case 'W': {
strcpy(gameregion, "NTSC T"); case 'P': // Europe
break; case 'D': // Germany
default: case 'F': // France
strcpy(gameregion, " PAL "); case 'H': // Netherlands
case 'I': // Italy
case 'L': // Japanese import to Europe
case 'M': // American import to Europe
case 'R': // Russia
case 'S': // Spain
case 'U': // Australia
case 'V': // Scandinavia
gameregion = "PAL";
break;
case 'E': // USA
case 'N': // Japanese import to USA
gameregion = "NTSC-U";
break;
case 'J': // Japan
gameregion = "NTSC-J";
break;
case 'K': // Korea
case 'Q': // Japanese import to Korea
case 'T': // American import to Korea
gameregion = "NTSC-K";
break;
case 'W': // Taiwan / Hong Kong / Macau
gameregion = "NTSC-T";
break;
case 'X': // Europe / USA special releases
case 'Y': // Europe / USA special releases
case 'Z': // Europe / USA special releases
gameregion = "PAL / NTSC-U";
break;
default:
gameregion = tr("Region Free");
}
} }
HaltGui(); HaltGui();
@ -1523,7 +1559,7 @@ void GameBrowseMenu::UpdateGameInfoText(const u8 * gameId)
{ {
Remove(GameRegionTxt); Remove(GameRegionTxt);
delete GameRegionTxt; delete GameRegionTxt;
GameRegionTxt = new GuiText(gameregion, 22, thColor("r=55 g=190 b=237 a=255 - region info text color")); GameRegionTxt = new GuiText(gameregion.c_str(), 22, thColor("r=55 g=190 b=237 a=255 - region info text color"));
GameRegionTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); GameRegionTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
GameRegionTxt->SetPosition(thInt("68 - region info text pos x"), thInt("30 - region info text pos y")); GameRegionTxt->SetPosition(thInt("68 - region info text pos x"), thInt("30 - region info text pos y"));
GameRegionTxt->SetEffect(EFFECT_FADE, 20); GameRegionTxt->SetEffect(EFFECT_FADE, 20);

View File

@ -17,7 +17,7 @@ class GameBrowseMenu : public GuiWindow
int MainLoop(); int MainLoop();
int OpenClickedGame(struct discHdr *header); int OpenClickedGame(struct discHdr *header);
int GetSelectedGame() { return (gameBrowser ? gameBrowser->GetSelectedOption() : -1); } int GetSelectedGame() { return (gameBrowser ? gameBrowser->GetSelectedOption() : -1); }
void UpdateGameInfoText(const u8 * gameId); void UpdateGameInfoText(struct discHdr *header);
void LoadCover(struct discHdr *header); void LoadCover(struct discHdr *header);
void CheckDiscSlotUpdate(); void CheckDiscSlotUpdate();
void UpdateFreeSpace(void *arg); void UpdateFreeSpace(void *arg);

View File

@ -7,11 +7,11 @@
#include "svnrev.h" #include "svnrev.h"
#include "gecko.h" #include "gecko.h"
#define VALID_CACHE_REVISION 1148 #define VALID_CACHE_REVISION 1280
CGameTitles GameTitles; CGameTitles GameTitles;
void CGameTitles::SetGameTitle(const char * id, const char * title) void CGameTitles::SetGameTitle(const char * id, const char * title, const std::string region)
{ {
if(!id || !title) if(!id || !title)
return; return;
@ -21,6 +21,7 @@ void CGameTitles::SetGameTitle(const char * id, const char * title)
if(strncasecmp(id, TitleList[i].GameID, 6) == 0) if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
{ {
TitleList[i].Title = title; TitleList[i].Title = title;
TitleList[i].Region = region;
return; return;
} }
} }
@ -28,6 +29,7 @@ void CGameTitles::SetGameTitle(const char * id, const char * title)
GameTitle newTitle; GameTitle newTitle;
snprintf(newTitle.GameID, sizeof(newTitle.GameID), id); snprintf(newTitle.GameID, sizeof(newTitle.GameID), id);
newTitle.Title = title; newTitle.Title = title;
newTitle.Region = region;
newTitle.ParentalRating = -1; newTitle.ParentalRating = -1;
newTitle.PlayersCount = 1; newTitle.PlayersCount = 1;
newTitle.FromWiiTDB = 0; newTitle.FromWiiTDB = 0;
@ -70,6 +72,20 @@ const char * CGameTitles::GetTitle(const struct discHdr *header) const
return header->title; return header->title;
} }
const char * CGameTitles::GetRegion(const char * id) const
{
if(!id || !Settings.titlesOverride)
return "NULL";
for(u32 i = 0; i < TitleList.size(); ++i)
{
if(strncasecmp(id, TitleList[i].GameID, 6) == 0)
return TitleList[i].Region.c_str();
}
return "NULL";
}
int CGameTitles::GetParentalRating(const char * id) const int CGameTitles::GetParentalRating(const char * id) const
{ {
if(!id) if(!id)
@ -109,7 +125,8 @@ void CGameTitles::SetDefault()
typedef struct _CacheTitle typedef struct _CacheTitle
{ {
char GameID[7]; char GameID[7];
char Title[100]; char Title[130]; // long titles e.g. RGOJJ9 & DLSP64
char Region[7];
char FromWiiTDB; char FromWiiTDB;
int ParentalRating; int ParentalRating;
int PlayersCount; int PlayersCount;
@ -123,7 +140,7 @@ u32 CGameTitles::ReadCachedTitles(const char * path)
Cachepath += '/'; Cachepath += '/';
Cachepath += "TitlesCache.bin"; Cachepath += "TitlesCache.bin";
//! Load cached least so that the titles are preloaded before reading list //! Load cached last so that the titles are preloaded before reading list
FILE * f = fopen(Cachepath.c_str(), "rb"); FILE * f = fopen(Cachepath.c_str(), "rb");
if(!f) return 0; if(!f) return 0;
@ -162,6 +179,7 @@ u32 CGameTitles::ReadCachedTitles(const char * path)
{ {
strcpy(TitleList[i].GameID, CachedList[i].GameID); strcpy(TitleList[i].GameID, CachedList[i].GameID);
TitleList[i].Title = CachedList[i].Title; TitleList[i].Title = CachedList[i].Title;
TitleList[i].Region = CachedList[i].Region;
TitleList[i].ParentalRating = CachedList[i].ParentalRating; TitleList[i].ParentalRating = CachedList[i].ParentalRating;
TitleList[i].PlayersCount = CachedList[i].PlayersCount; TitleList[i].PlayersCount = CachedList[i].PlayersCount;
TitleList[i].FromWiiTDB = CachedList[i].FromWiiTDB; TitleList[i].FromWiiTDB = CachedList[i].FromWiiTDB;
@ -193,6 +211,7 @@ void CGameTitles::WriteCachedTitles(const char * path)
memset(&Cache, 0, sizeof(CacheTitle)); memset(&Cache, 0, sizeof(CacheTitle));
snprintf(Cache.GameID, sizeof(Cache.GameID), "%s", TitleList[i].GameID); snprintf(Cache.GameID, sizeof(Cache.GameID), "%s", TitleList[i].GameID);
snprintf(Cache.Title, sizeof(Cache.Title), "%s", TitleList[i].Title.c_str()); snprintf(Cache.Title, sizeof(Cache.Title), "%s", TitleList[i].Title.c_str());
snprintf(Cache.Region, sizeof(Cache.Region), "%s", TitleList[i].Region.c_str());
Cache.ParentalRating = TitleList[i].ParentalRating; Cache.ParentalRating = TitleList[i].ParentalRating;
Cache.PlayersCount = TitleList[i].PlayersCount; Cache.PlayersCount = TitleList[i].PlayersCount;
Cache.FromWiiTDB = TitleList[i].FromWiiTDB; Cache.FromWiiTDB = TitleList[i].FromWiiTDB;
@ -271,13 +290,17 @@ void CGameTitles::LoadTitlesFromGameTDB(const char * path, bool removeUnused)
XML_DB.SetLanguageCode(Settings.db_language); XML_DB.SetLanguageCode(Settings.db_language);
int Rating; int Rating;
std::string RatValTxt; std::string RatValTxt;
std::string Region;
for(u32 i = 0; i < MissingTitles.size(); ++i) for(u32 i = 0; i < MissingTitles.size(); ++i)
{ {
if(!XML_DB.GetTitle(MissingTitles[i].c_str(), Title)) if(!XML_DB.GetTitle(MissingTitles[i].c_str(), Title))
continue; continue;
this->SetGameTitle(MissingTitles[i].c_str(), Title.c_str()); if(XML_DB.GetRegion(MissingTitles[i].c_str(), Region))
this->SetGameTitle(MissingTitles[i].c_str(), Title.c_str(), Region);
else
this->SetGameTitle(MissingTitles[i].c_str(), Title.c_str());
//! Title is loaded from WiiTDB, remember that it's good //! Title is loaded from WiiTDB, remember that it's good
TitleList[TitleList.size()-1].FromWiiTDB = 1; TitleList[TitleList.size()-1].FromWiiTDB = 1;
@ -293,4 +316,5 @@ void CGameTitles::LoadTitlesFromGameTDB(const char * path, bool removeUnused)
if(ret > 0) if(ret > 0)
TitleList[TitleList.size()-1].PlayersCount = ret; TitleList[TitleList.size()-1].PlayersCount = ret;
} }
XML_DB.CloseFile();
} }

View File

@ -10,6 +10,7 @@ typedef struct _GameTitle
{ {
char GameID[7]; char GameID[7];
std::string Title; std::string Title;
std::string Region;
int ParentalRating; int ParentalRating;
int PlayersCount; int PlayersCount;
char FromWiiTDB; char FromWiiTDB;
@ -20,9 +21,9 @@ class CGameTitles
{ {
public: public:
//! Set a game title from GameTDB //! Set a game title from GameTDB
void SetGameTitle(const char * id, const char * title); void SetGameTitle(const char * id, const char * title, const std::string region = "NULL");
//! Overload //! Overload
void SetGameTitle(const u8 * id, const char * title) { SetGameTitle((const char *) id, title); }; void SetGameTitle(const u8 * id, const char * title) { SetGameTitle((const char *) id, title, "NULL"); };
//! Get a game title //! Get a game title
const char * GetTitle(const char * id) const; const char * GetTitle(const char * id) const;
@ -31,6 +32,8 @@ class CGameTitles
//! Overload //! Overload
const char * GetTitle(const struct discHdr *header) const; const char * GetTitle(const struct discHdr *header) const;
//! Get game region
const char * GetRegion(const char * id) const;
//! Get game parental rating //! Get game parental rating
int GetParentalRating(const char * id) const; int GetParentalRating(const char * id) const;
//! Get possible number of players for this game //! Get possible number of players for this game