PSF loader: implemented 0x0004 entry format

This commit is contained in:
DHrpcs3 2016-01-07 21:22:36 +02:00
parent 657a6c9511
commit f97d791fe8
2 changed files with 56 additions and 29 deletions

View File

@ -75,7 +75,7 @@ bool PSFLoader::Load(vfsStream& stream)
// load data
stream.Seek(header.off_data_table + indices[i].data_off);
if (indices[i].param_fmt == PSF_PARAM_INT && indices[i].param_len == 4 && indices[i].param_max == 4)
if (indices[i].param_fmt == psf_entry_format::integer && indices[i].param_len == 4 && indices[i].param_max >= indices[i].param_len)
{
// load int data
@ -84,7 +84,8 @@ bool PSFLoader::Load(vfsStream& stream)
return false;
}
}
else if (indices[i].param_fmt == PSF_PARAM_STR && indices[i].param_max >= indices[i].param_len)
else if ((indices[i].param_fmt == psf_entry_format::string || indices[i].param_fmt == psf_entry_format::string_not_null_term)
&& indices[i].param_max >= indices[i].param_len)
{
// load str data
@ -143,12 +144,17 @@ bool PSFLoader::Save(vfsStream& stream) const
switch (m_entries[i].fmt) // calculate data size
{
case PSF_PARAM_STR:
case psf_entry_format::string_not_null_term:
{
data_offset += (indices[i].param_len = indices[i].param_max = static_cast<u32>(m_entries[i].vstr.size()));
break;
}
case psf_entry_format::string:
{
data_offset += (indices[i].param_len = indices[i].param_max = static_cast<u32>(m_entries[i].vstr.size()) + 1);
break;
}
case PSF_PARAM_INT:
case psf_entry_format::integer:
{
data_offset += (indices[i].param_len = indices[i].param_max = 4);
break;
@ -190,7 +196,7 @@ bool PSFLoader::Save(vfsStream& stream) const
{
switch (entry.fmt)
{
case PSF_PARAM_STR:
case psf_entry_format::string:
{
if (!stream.SWrite(entry.vstr[0], entry.vstr.size() + 1))
{
@ -198,7 +204,15 @@ bool PSFLoader::Save(vfsStream& stream) const
}
break;
}
case PSF_PARAM_INT:
case psf_entry_format::string_not_null_term:
{
if (!stream.SWrite(entry.vstr[0], entry.vstr.size()))
{
return false;
}
break;
}
case psf_entry_format::integer:
{
if (!stream.SWrite(entry.vint))
{
@ -230,7 +244,7 @@ const PSFEntry* PSFLoader::SearchEntry(const std::string& key) const
return nullptr;
}
PSFEntry& PSFLoader::AddEntry(const std::string& key, u16 fmt)
PSFEntry& PSFLoader::AddEntry(const std::string& key, psf_entry_format fmt)
{
for (auto& entry : m_entries)
{
@ -253,7 +267,7 @@ std::string PSFLoader::GetString(const std::string& key, std::string def) const
{
if (const auto entry = SearchEntry(key))
{
if (entry->fmt == PSF_PARAM_STR)
if (entry->fmt == psf_entry_format::string || entry->fmt == psf_entry_format::string_not_null_term)
{
return entry->vstr;
}
@ -266,7 +280,7 @@ s32 PSFLoader::GetInteger(const std::string& key, s32 def) const
{
if (const auto entry = SearchEntry(key))
{
if (entry->fmt == PSF_PARAM_INT)
if (entry->fmt == psf_entry_format::integer)
{
return entry->vint;
}
@ -277,10 +291,10 @@ s32 PSFLoader::GetInteger(const std::string& key, s32 def) const
void PSFLoader::SetString(const std::string& key, std::string value)
{
AddEntry(key, PSF_PARAM_STR).vstr = value;
AddEntry(key, psf_entry_format::string).vstr = value;
}
void PSFLoader::SetInteger(const std::string& key, s32 value)
{
AddEntry(key, PSF_PARAM_INT).vint = value;
AddEntry(key, psf_entry_format::integer).vint = value;
}

View File

@ -2,6 +2,13 @@
struct vfsStream;
enum class psf_entry_format : u16
{
string_not_null_term = 0x0004,
string = 0x0204,
integer = 0x0404,
};
struct PSFHeader
{
u32 magic;
@ -14,22 +21,15 @@ struct PSFHeader
struct PSFDefTable
{
u16 key_off;
u16 param_fmt;
psf_entry_format param_fmt;
u32 param_len;
u32 param_max;
u32 data_off;
};
enum : u16
{
PSF_PARAM_UNK = 0x0004,
PSF_PARAM_STR = 0x0204,
PSF_PARAM_INT = 0x0404,
};
struct PSFEntry
{
u16 fmt;
psf_entry_format fmt;
std::string name;
s32 vint;
@ -51,25 +51,38 @@ public:
virtual ~PSFLoader() = default;
bool Load(vfsStream& stream);
bool Save(vfsStream& stream) const;
void Clear();
operator bool() const
explicit operator bool() const
{
return !m_entries.empty();
}
const PSFEntry* SearchEntry(const std::string& key) const;
PSFEntry& AddEntry(const std::string& key, u16 type);
PSFEntry& AddEntry(const std::string& key, psf_entry_format format);
std::string GetString(const std::string& key, std::string def = "") const;
s32 GetInteger(const std::string& key, s32 def = 0) const;
void SetString(const std::string& key, std::string value);
void SetInteger(const std::string& key, s32 value);
std::vector<PSFEntry>& entries()
{
return m_entries;
}
const std::vector<PSFEntry>& entries() const
{
return m_entries;
}
std::vector<PSFEntry>::iterator begin()
{
return m_entries.begin();
}
std::vector<PSFEntry>::iterator end()
{
return m_entries.end();
}
};