From fedf7edc2b223b92724a7e46eb7ea5c4b6cb22c4 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Tue, 10 Dec 2013 17:23:03 +0100 Subject: [PATCH] Guess game region from game ID, display on game screen --- UI/GameInfoCache.cpp | 62 +++++++++++++++++++++++++++++--------------- UI/GameInfoCache.h | 16 ++++++++++-- UI/GameScreen.cpp | 12 +++++++++ UI/GameScreen.h | 1 + 4 files changed, 68 insertions(+), 23 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index bf08267060..da9e6349d2 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -162,6 +162,44 @@ bool GameInfo::DeleteAllSaveData() { return true; } +void GameInfo::ParseParamSFO() { + title = paramSFO.GetValueString("TITLE"); + id = paramSFO.GetValueString("DISC_ID"); + id_version = paramSFO.GetValueString("DISC_ID") + "_" + paramSFO.GetValueString("DISC_VERSION"); + disc_total = paramSFO.GetValueInt("DISC_TOTAL"); + disc_number = paramSFO.GetValueInt("DISC_NUMBER"); + // region = paramSFO.GetValueInt("REGION"); // Always seems to be 32768? + + region = GAMEREGION_OTHER; + if (id_version.size() >= 4) { + std::string regStr = id_version.substr(0, 4); + + // Guesswork + switch (regStr[2]) { + case 'E': region = GAMEREGION_EUROPE; break; + case 'U': region = GAMEREGION_USA; break; + case 'J': region = GAMEREGION_JAPAN; break; + case 'H': region = GAMEREGION_HONGKONG; break; + case 'A': region = GAMEREGION_ASIA; break; + } + /* + if (regStr == "NPEZ" || regStr == "NPEG" || regStr == "ULES" || regStr == "UCES" || + regStr == "NPEX") { + region = GAMEREGION_EUROPE; + } else if (regStr == "NPUG" || regStr == "NPUZ" || regStr == "ULUS" || regStr == "UCUS") { + region = GAMEREGION_USA; + } else if (regStr == "NPJH" || regStr == "NPJG" || regStr == "ULJM"|| regStr == "ULJS") { + region = GAMEREGION_JAPAN; + } else if (regStr == "NPHG") { + region = GAMEREGION_HONGKONG; + } else if (regStr == "UCAS") { + region = GAMEREGION_CHINA; + }*/ + } + + paramSFOLoaded = true; +} + static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string *contents, recursive_mutex *mtx) { PSPFileInfo info = fs->GetFileInfo(filename); if (!info.exists) { @@ -218,13 +256,7 @@ public: { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO(sfoData, sfoSize); - info_->title = info_->paramSFO.GetValueString("TITLE"); - info_->id = info_->paramSFO.GetValueString("DISC_ID"); - info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); - info_->disc_total = info_->paramSFO.GetValueInt("DISC_TOTAL"); - info_->disc_number = info_->paramSFO.GetValueInt("DISC_NUMBER"); - - info_->paramSFOLoaded = true; + info_->ParseParamSFO(); } delete [] sfoData; @@ -287,13 +319,7 @@ public: if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); - info_->title = info_->paramSFO.GetValueString("TITLE"); - info_->id = info_->paramSFO.GetValueString("DISC_ID"); - info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); - info_->disc_total = info_->paramSFO.GetValueInt("DISC_TOTAL"); - info_->disc_number = info_->paramSFO.GetValueInt("DISC_NUMBER"); - - info_->paramSFOLoaded = true; + info_->ParseParamSFO(); } ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock); @@ -321,13 +347,7 @@ public: if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", ¶mSFOcontents, 0)) { lock_guard lock(info_->lock); info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size()); - info_->title = info_->paramSFO.GetValueString("TITLE"); - info_->id = info_->paramSFO.GetValueString("DISC_ID"); - info_->id_version = info_->paramSFO.GetValueString("DISC_ID") + "_" + info_->paramSFO.GetValueString("DISC_VERSION"); - info_->disc_total = info_->paramSFO.GetValueInt("DISC_TOTAL"); - info_->disc_number = info_->paramSFO.GetValueInt("DISC_NUMBER"); - - info_->paramSFOLoaded = true; + info_->ParseParamSFO(); } else { // Fall back to the filename for title if ISO is broken info_->title = gamePath_; diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 84fa511e88..77f1616d66 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -31,11 +31,22 @@ // does on the PSP, namely checking for and deleting savedata, and similar things. // Only cares about games that are installed on the current device. +// Guessed from GameID, not necessarily accurate +enum GameRegion { + GAMEREGION_JAPAN, + GAMEREGION_USA, + GAMEREGION_EUROPE, + GAMEREGION_HONGKONG, + GAMEREGION_ASIA, + GAMEREGION_OTHER, + GAMEREGION_MAX, +}; + class GameInfo { public: GameInfo() : fileType(FILETYPE_UNKNOWN), paramSFOLoaded(false), iconTexture(NULL), pic0Texture(NULL), pic1Texture(NULL), - wantBG(false), gameSize(0), saveDataSize(0), installDataSize(0), disc_total(0), disc_number(0) {} + wantBG(false), gameSize(0), saveDataSize(0), installDataSize(0), disc_total(0), disc_number(0), region(-1) {} bool DeleteGame(); // Better be sure what you're doing when calling this. bool DeleteAllSaveData(); @@ -44,7 +55,7 @@ public: u64 GetSaveDataSizeInBytes(); u64 GetInstallDataSizeInBytes(); - void LoadParamSFO(); + void ParseParamSFO(); std::vector GetSaveDataDirectories(); @@ -61,6 +72,7 @@ public: std::string id_version; int disc_total; int disc_number; + int region; IdentifiedFileType fileType; ParamSFOData paramSFO; bool paramSFOLoaded; diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index abe9bb0684..a2e2cdd55b 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -57,6 +57,7 @@ void GameScreen::CreateViews() { tvGameSize_ = leftColumn->Add(new TextView("...", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 250, NONE, NONE))); tvSaveDataSize_ = leftColumn->Add(new TextView("...", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 290, NONE, NONE))); tvInstallDataSize_ = leftColumn->Add(new TextView("", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 330, NONE, NONE))); + tvRegion_ = leftColumn->Add(new TextView("", ALIGN_LEFT, 1.0f, new AnchorLayoutParams(10, 370, NONE, NONE))); } ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(300, FILL_PARENT, actionMenuMargins)); @@ -135,6 +136,17 @@ void GameScreen::update(InputState &input) { tvInstallDataSize_->SetText(temp); } } + + if (info->region >= 0 && info->region < GAMEREGION_MAX && info->region != GAMEREGION_OTHER) { + static const char *regionNames[GAMEREGION_MAX] = { + "Japan", + "USA", + "Europe", + "Hong Kong", + "Asia" + }; + tvRegion_->SetText(ga->T(regionNames[info->region])); + } } UI::EventReturn GameScreen::OnSwitchBack(UI::EventParams &e) { diff --git a/UI/GameScreen.h b/UI/GameScreen.h index dbecc2712c..a18513c2a5 100644 --- a/UI/GameScreen.h +++ b/UI/GameScreen.h @@ -57,4 +57,5 @@ private: UI::TextView *tvGameSize_; UI::TextView *tvSaveDataSize_; UI::TextView *tvInstallDataSize_; + UI::TextView *tvRegion_; };