mirror of https://github.com/PCSX2/pcsx2.git
- Get pcsx2 to display "game name (region) [serial] [crc]" in the console title-bar based on info found in game database.
- Some work on the database_loader class... now loads all game data into memory, and you can switch the game who's data is being read by calling setGame(). - Made the database_loader class a global "GameDB" so that it can be referred to throughout pcsx2 code... git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2983 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
parent
8687a03c78
commit
36973bfb92
|
@ -29,6 +29,7 @@
|
||||||
#include "ps2/BiosTools.h"
|
#include "ps2/BiosTools.h"
|
||||||
#include "DataBase_Loader.h"
|
#include "DataBase_Loader.h"
|
||||||
|
|
||||||
|
DataBase_Loader GameDB("DataBase.dbf", "Serial");
|
||||||
wxString DiscID;
|
wxString DiscID;
|
||||||
|
|
||||||
static cdvdStruct cdvd;
|
static cdvdStruct cdvd;
|
||||||
|
@ -346,8 +347,9 @@ static __forceinline void _reloadElfInfo(wxString elfpath)
|
||||||
|
|
||||||
elfptr.Delete();
|
elfptr.Delete();
|
||||||
|
|
||||||
DataBase_Loader dbLoader("DataBase.dbf", "Serial", DiscID.ToUTF8().data());
|
// Set the Game DataBase to the correct game based on Game Serial Code...
|
||||||
Console.WriteLn("Game = %s (%s)", dbLoader.getString("Name").c_str(), dbLoader.getString("Region").c_str());
|
GameDB.setGame(DiscID.ToUTF8().data());
|
||||||
|
Console.WriteLn("Game = %s (%s)", GameDB.getString("Name").c_str(), GameDB.getString("Region").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void cdvdReloadElfInfo()
|
void cdvdReloadElfInfo()
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
#include "File_Reader.h"
|
#include "File_Reader.h"
|
||||||
|
|
||||||
struct key_pair {
|
struct key_pair {
|
||||||
|
@ -22,6 +23,14 @@ struct key_pair {
|
||||||
: key(_key) , value(_value) {}
|
: key(_key) , value(_value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Game_Data {
|
||||||
|
public:
|
||||||
|
string id; // Serial Identification Code
|
||||||
|
deque<key_pair> kList; // List of all (key, value) pairs for game data
|
||||||
|
Game_Data(string _id)
|
||||||
|
: id(_id) {}
|
||||||
|
};
|
||||||
|
|
||||||
// DataBase_Loader:
|
// DataBase_Loader:
|
||||||
// Give the starting Key and Value you're looking for,
|
// Give the starting Key and Value you're looking for,
|
||||||
// and it will extract the necessary data from the database.
|
// and it will extract the necessary data from the database.
|
||||||
|
@ -50,6 +59,8 @@ private:
|
||||||
void extract(string& line, key_pair& keyPair) {
|
void extract(string& line, key_pair& keyPair) {
|
||||||
stringstream ss(line);
|
stringstream ss(line);
|
||||||
string t;
|
string t;
|
||||||
|
keyPair.key = "";
|
||||||
|
keyPair.value = "";
|
||||||
ss >> keyPair.key;
|
ss >> keyPair.key;
|
||||||
if (!line.length() || isComment(keyPair.key)) {
|
if (!line.length() || isComment(keyPair.key)) {
|
||||||
doError(line, keyPair);
|
doError(line, keyPair);
|
||||||
|
@ -78,60 +89,113 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
deque<key_pair> kList;
|
deque<Game_Data*> gList;
|
||||||
DataBase_Loader(string file, string key, string value) {
|
Game_Data* curGame;
|
||||||
|
|
||||||
|
DataBase_Loader(string file, string key, string value = "") {
|
||||||
|
curGame = NULL;
|
||||||
if (!fileExists(file)) {
|
if (!fileExists(file)) {
|
||||||
Console.Error("DataBase_Loader: DataBase Not Found! [%s]", file.c_str());
|
Console.Error("DataBase_Loader: DataBase Not Found! [%s]", file.c_str());
|
||||||
}
|
}
|
||||||
File_Reader reader(file);
|
File_Reader reader(file);
|
||||||
key_pair keyPair("", "");
|
key_pair keyPair("", "");
|
||||||
string s0, s1;
|
string s0;
|
||||||
try {
|
try {
|
||||||
for(;;) {
|
for(;;) {
|
||||||
keyPair.key = "";
|
for(;;) { // Find first game
|
||||||
keyPair.value = "";
|
s0 = reader.getLine();
|
||||||
s0 = reader.getLine();
|
extract(s0, keyPair);
|
||||||
extract(s0, keyPair);
|
if (keyPair.key.compare(key) == 0) break;
|
||||||
if ((keyPair.key.compare(key) == 0)
|
}
|
||||||
&& (keyPair.value.compare(value) == 0)) break;
|
Game_Data* game = new Game_Data(keyPair.value);
|
||||||
}
|
game->kList.push_back(keyPair);
|
||||||
Console.WriteLn("DataBase_Loader: Found Game! [%s]", value.c_str());
|
for (;;) { // Fill game data, find new game, repeat...
|
||||||
kList.push_back(keyPair);
|
s0 = reader.getLine();
|
||||||
for (;;) {
|
extract(s0, keyPair);
|
||||||
s0 = reader.getLine();
|
if (keyPair.key.compare("") == 0) continue;
|
||||||
extract(s0, keyPair);
|
if (keyPair.key.compare(key) == 0) {
|
||||||
if (keyPair.key.compare("") == 0) continue;
|
gList.push_back(game);
|
||||||
if (keyPair.key.compare(key) == 0) break;
|
game = new Game_Data(keyPair.value);
|
||||||
kList.push_back(keyPair);
|
}
|
||||||
|
game->kList.push_back(keyPair);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(...) {}
|
catch(int& i) { i = 0; }
|
||||||
if (!kList.size()) Console.Warning("DataBase_Loader: Game Not Found! [%s]", value.c_str());
|
if (!value.compare("")) return;
|
||||||
|
if (setGame(value)) Console.WriteLn("DataBase_Loader: Found Game! [%s]", value.c_str());
|
||||||
|
else Console.Warning("DataBase_Loader: Game Not Found! [%s]", value.c_str());
|
||||||
}
|
}
|
||||||
~DataBase_Loader() {}
|
|
||||||
|
~DataBase_Loader() {
|
||||||
|
deque<Game_Data*>::iterator it = gList.begin();
|
||||||
|
for ( ; it != gList.end(); ++it) {
|
||||||
|
delete it[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets the current game to the one matching the serial id given
|
||||||
|
// Returns true if game found, false if not found...
|
||||||
|
bool setGame(string id) {
|
||||||
|
deque<Game_Data*>::iterator it = gList.begin();
|
||||||
|
for ( ; it != gList.end(); ++it) {
|
||||||
|
if (!it[0]->id.compare(id)) {
|
||||||
|
curGame = it[0];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets a string representation of the 'value' for the given key
|
||||||
string getString(string key) {
|
string getString(string key) {
|
||||||
deque<key_pair>::iterator it = kList.begin();
|
if (curGame) {
|
||||||
for ( ; it != kList.end(); ++it) {
|
deque<key_pair>::iterator it = curGame->kList.begin();
|
||||||
if (!it[0].key.compare(key)) {
|
for ( ; it != curGame->kList.end(); ++it) {
|
||||||
return it[0].value;
|
if (!it[0].key.compare(key)) {
|
||||||
|
return it[0].value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string("???");
|
else Console.Error("DataBase_Loader: Game not set!");
|
||||||
|
return string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a wxString representation of the 'value' for the given key
|
||||||
|
wxString getStringWX(string key) {
|
||||||
|
string s = getString(key);
|
||||||
|
return wxString(fromAscii(s.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets a double representation of the 'value' for the given key
|
||||||
double getDouble(string key) {
|
double getDouble(string key) {
|
||||||
string v = getString(key);
|
string v = getString(key);
|
||||||
return atof(v.c_str());
|
return atof(v.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a float representation of the 'value' for the given key
|
||||||
float getFloat(string key) {
|
float getFloat(string key) {
|
||||||
string v = getString(key);
|
string v = getString(key);
|
||||||
return (float)atof(v.c_str());
|
return (float)atof(v.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets an integer representation of the 'value' for the given key
|
||||||
int getInt(string key) {
|
int getInt(string key) {
|
||||||
string v = getString(key);
|
string v = getString(key);
|
||||||
return strtoul(v.c_str(), NULL, 0);
|
return strtoul(v.c_str(), NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a u8 representation of the 'value' for the given key
|
||||||
u8 getU8(string key) {
|
u8 getU8(string key) {
|
||||||
string v = getString(key);
|
string v = getString(key);
|
||||||
return (u8)atoi(v.c_str());
|
return (u8)atoi(v.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a bool representation of the 'value' for the given key
|
||||||
|
u8 getBool(string key) {
|
||||||
|
string v = getString(key);
|
||||||
|
return !!atoi(v.c_str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern DataBase_Loader GameDB;
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "Elfheader.h"
|
#include "Elfheader.h"
|
||||||
#include "CDVD/CDVD.h"
|
#include "CDVD/CDVD.h"
|
||||||
#include "Patch.h"
|
#include "Patch.h"
|
||||||
|
#include "DataBase_Loader.h"
|
||||||
|
|
||||||
using namespace R5900; // for R5900 disasm tools
|
using namespace R5900; // for R5900 disasm tools
|
||||||
|
|
||||||
|
@ -576,12 +577,16 @@ __forceinline void CPU_INT( u32 n, s32 ecycle)
|
||||||
void __fastcall eeGameStarting()
|
void __fastcall eeGameStarting()
|
||||||
{
|
{
|
||||||
if (!g_GameStarted && ElfCRC) {
|
if (!g_GameStarted && ElfCRC) {
|
||||||
wxString filename( wxsFormat( L"%8.8x", ElfCRC ) );
|
wxString gameCRC( wxsFormat( L"%8.8x", ElfCRC ) );
|
||||||
|
wxString gameName = GameDB.getStringWX("Name");
|
||||||
|
gameName += L" (" + GameDB.getStringWX("Region") + L")";
|
||||||
|
gameName += L" [" + DiscID + L"]";
|
||||||
|
gameName += L" [" + gameCRC + L"]";
|
||||||
|
|
||||||
// if patches found the following status msg will be overwritten
|
// if patches found the following title will be overwritten
|
||||||
Console.SetTitle(L"Game running [CRC=" + filename +L"]");
|
Console.SetTitle(gameName);
|
||||||
|
|
||||||
if (EmuConfig.EnablePatches) InitPatch(filename);
|
if (EmuConfig.EnablePatches) InitPatch(gameCRC);
|
||||||
GetMTGS().SendGameCRC(ElfCRC);
|
GetMTGS().SendGameCRC(ElfCRC);
|
||||||
|
|
||||||
g_GameStarted = true;
|
g_GameStarted = true;
|
||||||
|
|
Loading…
Reference in New Issue