1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-23 03:02:53 +01:00

PSF Loader improved & issue #126 fixed

* Improved PSF Loader: Now you can get the value of the PARAM.SFO
entries directly with the GetString(key), GetInteger(key) methods.
GameInfo related lines were removed since they have nothing to do with
PSF files.
* cellGame, cellSysutil, and GameViewer are modified because of the PSF
Loader changes.
* Removed unnecessary null pointer checks:
https://github.com/DHrpcs3/rpcs3/issues/126
This commit is contained in:
Alexandro Sánchez Bach 2014-03-28 05:20:13 +01:00
parent 64145d7d62
commit 2c7269e3de
9 changed files with 128 additions and 134 deletions

View File

@ -23,11 +23,8 @@ void AudioManager::Init()
void AudioManager::Close()
{
if(m_audio_out)
{
delete m_audio_out;
m_audio_out = nullptr;
}
delete m_audio_out;
m_audio_out = nullptr;
}
u8 AudioManager::GetState()

View File

@ -165,11 +165,8 @@ void PPUThread::DoPause()
void PPUThread::DoStop()
{
if(m_dec)
{
delete m_dec;
m_dec = nullptr;
}
delete m_dec;
m_dec = nullptr;
}
bool dump_enable = false;

View File

@ -133,9 +133,9 @@ int cellGameBootCheck(mem32_t type, mem32_t attributes, mem_ptr_t<CellGameConten
PSFLoader psf(f);
if(!psf.Load(false))
return CELL_GAME_ERROR_FAILURE;
wxString dir = psf.m_info.serial(0,4) + psf.m_info.serial(5,5);
Memory.WriteString(dirName.GetAddr(), dir);
std::string titleId = psf.GetString("TITLE_ID");
Memory.WriteString(dirName.GetAddr(), titleId);
return CELL_OK;
}
@ -164,11 +164,11 @@ int cellGameContentPermit(mem_list_ptr_t<u8> contentInfoPath, mem_list_ptr_t<u8
PSFLoader psf(f);
if(!psf.Load(false))
return CELL_GAME_ERROR_FAILURE;
wxString title_id = psf.m_info.serial(0,4) + psf.m_info.serial(5,5);
std::string titleId = psf.GetString("TITLE_ID");
// TODO: Only works for HDD games
Memory.WriteString(contentInfoPath.GetAddr(), "/dev_hdd0/game/"+title_id);
Memory.WriteString(usrdirPath.GetAddr(), "/dev_hdd0/game/"+title_id+"/USRDIR");
Memory.WriteString(contentInfoPath.GetAddr(), "/dev_hdd0/game/"+titleId);
Memory.WriteString(usrdirPath.GetAddr(), "/dev_hdd0/game/"+titleId+"/USRDIR");
return CELL_OK;
}
@ -199,9 +199,9 @@ int cellGameGetParamInt(u32 id, mem32_t value)
switch(id)
{
case CELL_GAME_PARAMID_PARENTAL_LEVEL: value = psf.m_info.parental_lvl; break;
case CELL_GAME_PARAMID_RESOLUTION: value = psf.m_info.resolution; break;
case CELL_GAME_PARAMID_SOUND_FORMAT: value = psf.m_info.sound_format; break;
case CELL_GAME_PARAMID_PARENTAL_LEVEL: value = psf.GetInteger("PARENTAL_LEVEL"); break;
case CELL_GAME_PARAMID_RESOLUTION: value = psf.GetInteger("RESOLUTION"); break;
case CELL_GAME_PARAMID_SOUND_FORMAT: value = psf.GetInteger("SOUND_FORMAT"); break;
default:
return CELL_GAME_ERROR_INVALID_ID;
@ -210,11 +210,11 @@ int cellGameGetParamInt(u32 id, mem32_t value)
return CELL_OK;
}
int cellGameGetParamString(u32 id, mem_list_ptr_t<u8> buf, u32 bufsize)
int cellGameGetParamString(u32 id, u32 buf_addr, u32 bufsize)
{
cellGame.Warning("cellGameGetParamString(id=%d, buf_addr=0x%x, bufsize=%d)", id, buf.GetAddr(), bufsize);
cellGame.Warning("cellGameGetParamString(id=%d, buf_addr=0x%x, bufsize=%d)", id, buf_addr, bufsize);
if(!buf.IsGood())
if(!Memory.IsGoodAddr(buf_addr))
return CELL_GAME_ERROR_PARAM;
// TODO: Locate the PARAM.SFO. The following path may be wrong.
@ -223,46 +223,41 @@ int cellGameGetParamString(u32 id, mem_list_ptr_t<u8> buf, u32 bufsize)
if(!psf.Load(false))
return CELL_GAME_ERROR_FAILURE;
std::string data;
switch(id)
{
// WARNING: Is there any difference between all these "CELL_GAME_PARAMID_TITLE*" IDs?
case CELL_GAME_PARAMID_TITLE:
case CELL_GAME_PARAMID_TITLE_DEFAULT:
case CELL_GAME_PARAMID_TITLE_JAPANESE:
case CELL_GAME_PARAMID_TITLE_ENGLISH:
case CELL_GAME_PARAMID_TITLE_FRENCH:
case CELL_GAME_PARAMID_TITLE_SPANISH:
case CELL_GAME_PARAMID_TITLE_GERMAN:
case CELL_GAME_PARAMID_TITLE_ITALIAN:
case CELL_GAME_PARAMID_TITLE_DUTCH:
case CELL_GAME_PARAMID_TITLE_PORTUGUESE:
case CELL_GAME_PARAMID_TITLE_RUSSIAN:
case CELL_GAME_PARAMID_TITLE_KOREAN:
case CELL_GAME_PARAMID_TITLE_CHINESE_T:
case CELL_GAME_PARAMID_TITLE_CHINESE_S:
case CELL_GAME_PARAMID_TITLE_FINNISH:
case CELL_GAME_PARAMID_TITLE_SWEDISH:
case CELL_GAME_PARAMID_TITLE_DANISH:
case CELL_GAME_PARAMID_TITLE_NORWEGIAN:
case CELL_GAME_PARAMID_TITLE_POLISH:
case CELL_GAME_PARAMID_TITLE_PORTUGUESE_BRAZIL:
case CELL_GAME_PARAMID_TITLE_ENGLISH_UK:
Memory.WriteString(buf.GetAddr(), psf.m_info.name.Left(bufsize));
break;
case CELL_GAME_PARAMID_TITLE_ID:
Memory.WriteString(buf.GetAddr(), psf.m_info.serial.Left(bufsize));
break;
case CELL_GAME_PARAMID_VERSION:
Memory.WriteString(buf.GetAddr(), psf.m_info.fw.Left(bufsize));
break;
case CELL_GAME_PARAMID_APP_VER:
Memory.WriteString(buf.GetAddr(), psf.m_info.app_ver.Left(bufsize));
break;
case CELL_GAME_PARAMID_TITLE: data = psf.GetString("TITLE"); break; // TODO: Is this value correct?
case CELL_GAME_PARAMID_TITLE_DEFAULT: data = psf.GetString("TITLE"); break;
case CELL_GAME_PARAMID_TITLE_JAPANESE: data = psf.GetString("TITLE_00"); break;
case CELL_GAME_PARAMID_TITLE_ENGLISH: data = psf.GetString("TITLE_01"); break;
case CELL_GAME_PARAMID_TITLE_FRENCH: data = psf.GetString("TITLE_02"); break;
case CELL_GAME_PARAMID_TITLE_SPANISH: data = psf.GetString("TITLE_03"); break;
case CELL_GAME_PARAMID_TITLE_GERMAN: data = psf.GetString("TITLE_04"); break;
case CELL_GAME_PARAMID_TITLE_ITALIAN: data = psf.GetString("TITLE_05"); break;
case CELL_GAME_PARAMID_TITLE_DUTCH: data = psf.GetString("TITLE_06"); break;
case CELL_GAME_PARAMID_TITLE_PORTUGUESE: data = psf.GetString("TITLE_07"); break;
case CELL_GAME_PARAMID_TITLE_RUSSIAN: data = psf.GetString("TITLE_08"); break;
case CELL_GAME_PARAMID_TITLE_KOREAN: data = psf.GetString("TITLE_09"); break;
case CELL_GAME_PARAMID_TITLE_CHINESE_T: data = psf.GetString("TITLE_10"); break;
case CELL_GAME_PARAMID_TITLE_CHINESE_S: data = psf.GetString("TITLE_11"); break;
case CELL_GAME_PARAMID_TITLE_FINNISH: data = psf.GetString("TITLE_12"); break;
case CELL_GAME_PARAMID_TITLE_SWEDISH: data = psf.GetString("TITLE_13"); break;
case CELL_GAME_PARAMID_TITLE_DANISH: data = psf.GetString("TITLE_14"); break;
case CELL_GAME_PARAMID_TITLE_NORWEGIAN: data = psf.GetString("TITLE_15"); break;
case CELL_GAME_PARAMID_TITLE_POLISH: data = psf.GetString("TITLE_16"); break;
case CELL_GAME_PARAMID_TITLE_PORTUGUESE_BRAZIL: data = psf.GetString("TITLE_17"); break;
case CELL_GAME_PARAMID_TITLE_ENGLISH_UK: data = psf.GetString("TITLE_18"); break;
case CELL_GAME_PARAMID_TITLE_ID: data = psf.GetString("TITLE_ID"); break;
case CELL_GAME_PARAMID_VERSION: data = psf.GetString("PS3_SYSTEM_VER"); break;
case CELL_GAME_PARAMID_APP_VER: data = psf.GetString("APP_VER"); break;
default:
return CELL_GAME_ERROR_INVALID_ID;
}
data.resize(bufsize-1);
Memory.WriteString(buf_addr, data.c_str());
return CELL_OK;
}

View File

@ -885,16 +885,18 @@ int cellHddGameCheck(u32 version, u32 dirName_addr, u32 errDialog, mem_func_ptr_
return CELL_HDDGAME_ERROR_BROKEN;
}
get->getParam.parentalLevel = psf.m_info.parental_lvl;
get->getParam.attribute = psf.m_info.attr;
get->getParam.resolution = psf.m_info.resolution;
get->getParam.soundFormat = psf.m_info.sound_format;
memcpy(get->getParam.title, psf.m_info.name.mb_str(), CELL_HDDGAME_SYSP_TITLE_SIZE);
memcpy(get->getParam.dataVersion, psf.m_info.app_ver.mb_str(), CELL_HDDGAME_SYSP_VERSION_SIZE);
get->getParam.parentalLevel = psf.GetInteger("PARENTAL_LEVEL");
get->getParam.attribute = psf.GetInteger("ATTRIBUTE");
get->getParam.resolution = psf.GetInteger("RESOLUTION");
get->getParam.soundFormat = psf.GetInteger("SOUND_FORMAT");
memcpy(get->getParam.title, psf.GetString("TITLE"), CELL_HDDGAME_SYSP_TITLE_SIZE);
memcpy(get->getParam.dataVersion, psf.GetString("APP_VER"), CELL_HDDGAME_SYSP_VERSION_SIZE);
memcpy(get->getParam.titleId, dirName.c_str(), CELL_HDDGAME_SYSP_TITLEID_SIZE);
for (u32 i=0; i<CELL_HDDGAME_SYSP_LANGUAGE_NUM; i++) {
memcpy(get->getParam.titleLang[i], psf.m_info.name.mb_str(), CELL_HDDGAME_SYSP_TITLE_SIZE); // TODO: Get real titleLang name
char key [16];
sprintf(key, "TITLE_%02d", i);
memcpy(get->getParam.titleLang[i], psf.GetString(key), CELL_HDDGAME_SYSP_TITLE_SIZE);
}
}

View File

@ -47,7 +47,7 @@ void GameViewer::LoadGames()
void GameViewer::LoadPSF()
{
m_game_data.Clear();
m_game_data.clear();
for(uint i=0; i<m_games.GetCount(); ++i)
{
const wxString& path = m_path + m_games[i] + "/PARAM.SFO";
@ -56,9 +56,23 @@ void GameViewer::LoadPSF()
continue;
PSFLoader psf(f);
if(!psf.Load(false)) continue;
psf.m_info.root = m_games[i];
m_game_data.Add(new GameInfo(psf.m_info));
if(!psf.Load(false))
continue;
GameInfo game;
game.root = m_games[i];
game.serial = psf.GetString("TITLE_ID");
game.name = psf.GetString("TITLE");
game.app_ver = psf.GetString("APP_VER");
game.category = psf.GetString("CATEGORY");
game.fw = psf.GetString("PS3_SYSTEM_VER");
game.parental_lvl = psf.GetInteger("PARENTAL_LEVEL");
game.resolution = psf.GetInteger("RESOLUTION");
game.sound_format = psf.GetInteger("SOUND_FORMAT");
if(game.serial.Length() == 9)
game.serial = game.serial(0, 4) + "-" + game.serial(4, 5);
m_game_data.push_back(game);
}
m_columns.Update(m_game_data);

View File

@ -89,7 +89,7 @@ public:
#undef ADD_COLUMN
}
void Update(ArrayF<GameInfo>& game_data)
void Update(std::vector<GameInfo>& game_data)
{
m_col_name->data.Clear();
m_col_serial->data.Clear();
@ -100,9 +100,8 @@ public:
if(m_columns.GetCount() == 0) return;
for(uint i=0; i<game_data.GetCount(); ++i)
for(const auto& game : game_data)
{
GameInfo& game = game_data[i];
m_col_name->data.Add(game.name);
m_col_serial->data.Add(game.serial);
m_col_fw->data.Add(game.fw);
@ -218,7 +217,7 @@ class GameViewer : public wxListView
{
wxString m_path;
wxArrayString m_games;
ArrayF<GameInfo> m_game_data;
std::vector<GameInfo> m_game_data;
ColumnsArr m_columns;
public:

View File

@ -5,12 +5,12 @@ PSFLoader::PSFLoader(vfsStream& f) : psf_f(f)
{
}
PsfEntry* PSFLoader::SearchEntry(const std::string& key)
PSFEntry* PSFLoader::SearchEntry(const std::string& key)
{
for(uint i=0; i<m_entries.GetCount(); ++i)
for(auto& entry : m_entries)
{
if(m_entries[i].name == key)
return &m_entries[i];
if(entry.name == key)
return &entry;
}
return nullptr;
@ -22,7 +22,7 @@ bool PSFLoader::Load(bool show)
m_show_log = show;
if(!LoadHdr()) return false;
if(!LoadHeader()) return false;
if(!LoadKeyTable()) return false;
if(!LoadDataTable()) return false;
@ -34,23 +34,24 @@ bool PSFLoader::Close()
return psf_f.Close();
}
bool PSFLoader::LoadHdr()
bool PSFLoader::LoadHeader()
{
if(psf_f.Read(&psfhdr, sizeof(PsfHeader)) != sizeof(PsfHeader))
if(psf_f.Read(&m_header, sizeof(PSFHeader)) != sizeof(PSFHeader))
return false;
if(!psfhdr.CheckMagic()) return false;
if(!m_header.CheckMagic())
return false;
if(m_show_log) ConLog.Write("PSF version: %x", psfhdr.psf_version);
if(m_show_log) ConLog.Write("PSF version: %x", m_header.psf_version);
m_psfindxs.Clear();
m_entries.Clear();
m_psfindxs.SetCount(psfhdr.psf_entries_num);
m_entries.SetCount(psfhdr.psf_entries_num);
m_psfindxs.clear();
m_entries.clear();
m_psfindxs.resize(m_header.psf_entries_num);
m_entries.resize(m_header.psf_entries_num);
for(u32 i=0; i<psfhdr.psf_entries_num; ++i)
for(u32 i=0; i<m_header.psf_entries_num; ++i)
{
if(psf_f.Read(&m_psfindxs[i], sizeof(PsfDefTbl)) != sizeof(PsfDefTbl))
if(psf_f.Read(&m_psfindxs[i], sizeof(PSFDefTbl)) != sizeof(PSFDefTbl))
return false;
m_entries[i].fmt = m_psfindxs[i].psf_param_fmt;
@ -61,9 +62,9 @@ bool PSFLoader::LoadHdr()
bool PSFLoader::LoadKeyTable()
{
for(u32 i=0; i<psfhdr.psf_entries_num; ++i)
for(u32 i=0; i<m_header.psf_entries_num; ++i)
{
psf_f.Seek(psfhdr.psf_offset_key_table + m_psfindxs[i].psf_key_table_offset);
psf_f.Seek(m_header.psf_offset_key_table + m_psfindxs[i].psf_key_table_offset);
int c_pos = 0;
@ -83,29 +84,28 @@ bool PSFLoader::LoadKeyTable()
bool PSFLoader::LoadDataTable()
{
for(u32 i=0; i<psfhdr.psf_entries_num; ++i)
for(u32 i=0; i<m_header.psf_entries_num; ++i)
{
psf_f.Seek(psfhdr.psf_offset_data_table + m_psfindxs[i].psf_data_tbl_offset);
psf_f.Seek(m_header.psf_offset_data_table + m_psfindxs[i].psf_data_tbl_offset);
psf_f.Read(m_entries[i].param, m_psfindxs[i].psf_param_len);
memset(m_entries[i].param + m_psfindxs[i].psf_param_len, 0, m_psfindxs[i].psf_param_max_len - m_psfindxs[i].psf_param_len);
}
m_info.Reset();
if(PsfEntry* entry = SearchEntry("TITLE_ID")) m_info.serial = entry->Format();
if(PsfEntry* entry = SearchEntry("TITLE")) m_info.name = entry->Format();
if(PsfEntry* entry = SearchEntry("APP_VER")) m_info.app_ver = entry->Format();
if(PsfEntry* entry = SearchEntry("CATEGORY")) m_info.category = entry->Format();
if(PsfEntry* entry = SearchEntry("PS3_SYSTEM_VER")) m_info.fw = entry->Format();
if(PsfEntry* entry = SearchEntry("SOUND_FORMAT")) m_info.sound_format = entry->FormatInteger();
if(PsfEntry* entry = SearchEntry("RESOLUTION")) m_info.resolution = entry->FormatInteger();
if(PsfEntry* entry = SearchEntry("PARENTAL_LEVEL")) m_info.parental_lvl = entry->FormatInteger();
if(m_info.serial.Length() == 9)
{
m_info.serial = m_info.serial(0, 4) + "-" + m_info.serial(4, 5);
}
return true;
}
const char* PSFLoader::GetString(const std::string& key)
{
if(PSFEntry* entry = SearchEntry(key))
return entry->FormatString();
else
return "";
}
u32 PSFLoader::GetInteger(const std::string& key)
{
if(PSFEntry* entry = SearchEntry(key))
return entry->FormatInteger();
else
return 0;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Loader.h"
struct PsfHeader
struct PSFHeader
{
u32 psf_magic;
u32 psf_version;
@ -12,7 +12,7 @@ struct PsfHeader
bool CheckMagic() const { return psf_magic == *(u32*)"\0PSF"; }
};
struct PsfDefTbl
struct PSFDefTbl
{
u16 psf_key_table_offset;
u16 psf_param_fmt;
@ -21,23 +21,22 @@ struct PsfDefTbl
u32 psf_data_tbl_offset;
};
struct PsfEntry
struct PSFEntry
{
char name[128];
u16 fmt;
char param[4096];
std::string Format() const
const char* FormatString() const
{
switch(fmt)
{
default:
case 0x0400:
case 0x0402:
return FormatString();
return (const char*)param;
case 0x0404:
return wxString::Format("0x%x", FormatInteger()).ToStdString();
return (const char*)wxString::Format("0x%x", FormatInteger()).mb_str();
}
}
@ -45,34 +44,27 @@ struct PsfEntry
{
return *(u32*)param;
}
char* FormatString() const
{
return (char*)param;
}
};
class PSFLoader
{
vfsStream& psf_f;
PSFHeader m_header;
std::vector<PSFDefTbl> m_psfindxs;
std::vector<PSFEntry> m_entries;
bool m_show_log;
bool LoadHeader();
bool LoadKeyTable();
bool LoadDataTable();
public:
PSFLoader(vfsStream& f);
Array<PsfEntry> m_entries;
PsfEntry* SearchEntry(const std::string& key);
//wxArrayString m_table;
GameInfo m_info;
PsfHeader psfhdr;
Array<PsfDefTbl> m_psfindxs;
virtual bool Load(bool show = true);
virtual bool Close();
private:
bool LoadHdr();
bool LoadKeyTable();
bool LoadDataTable();
PSFEntry* SearchEntry(const std::string& key);
const char* GetString(const std::string& key);
u32 GetInteger(const std::string& key);
};

View File

@ -83,8 +83,6 @@ QSGNode* GLViewer::updatePaintNode(QSGNode* node, UpdatePaintNodeData* data)
void GLViewer::cleanup() {
this->killTimer(m_timerID);
m_timerID = 0;
if (m_fbo) {
delete m_fbo;
m_fbo = 0;
}
delete m_fbo;
m_fbo = nullptr;
}