[Kernel] Remove redundant 'Xdbf' from names

This commit is contained in:
emoose 2018-11-18 06:30:22 +00:00
parent c1eaf6879a
commit fa61106984
No known key found for this signature in database
GPG Key ID: 3735C67912F5FF97
5 changed files with 98 additions and 101 deletions

View File

@ -70,7 +70,7 @@ X_RESULT XgiApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr,
bool modified = false; bool modified = false;
auto* achievement = auto* achievement =
(X_XUSER_ACHIEVEMENT*)memory_->TranslateVirtual(achievements_ptr); (X_XUSER_ACHIEVEMENT*)memory_->TranslateVirtual(achievements_ptr);
xdbf::XdbfAchievement ach; xdbf::Achievement ach;
for (uint32_t i = 0; i < achievement_count; i++, achievement++) { for (uint32_t i = 0; i < achievement_count; i++, achievement++) {
if (game_gpd->GetAchievement(achievement->achievement_id, &ach)) { if (game_gpd->GetAchievement(achievement->achievement_id, &ach)) {
if (!ach.IsUnlocked()) { if (!ach.IsUnlocked()) {

View File

@ -117,7 +117,7 @@ void UserProfile::LoadGpdFiles() {
dash_gpd_.Read(mmap_->data(), mmap_->size()); dash_gpd_.Read(mmap_->data(), mmap_->size());
mmap_->Close(); mmap_->Close();
std::vector<xdbf::XdbfTitlePlayed> titles; std::vector<xdbf::TitlePlayed> titles;
dash_gpd_.GetTitles(&titles); dash_gpd_.GetTitles(&titles);
for (auto title : titles) { for (auto title : titles) {
@ -150,11 +150,11 @@ void UserProfile::LoadGpdFiles() {
xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) { xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) {
uint32_t spa_title = spa_data.GetTitleId(); uint32_t spa_title = spa_data.GetTitleId();
std::vector<xdbf::XdbfAchievement> spa_achievements; std::vector<xdbf::Achievement> spa_achievements;
// TODO: let user choose locale? // TODO: let user choose locale?
spa_data.GetAchievements(spa_data.GetDefaultLocale(), &spa_achievements); spa_data.GetAchievements(spa_data.GetDefaultLocale(), &spa_achievements);
xdbf::XdbfTitlePlayed title_info; xdbf::TitlePlayed title_info;
auto gpd = title_gpds_.find(spa_title); auto gpd = title_gpds_.find(spa_title);
if (gpd != title_gpds_.end()) { if (gpd != title_gpds_.end()) {
@ -232,7 +232,7 @@ xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) {
// Try copying achievement images if we can... // Try copying achievement images if we can...
for (auto ach : spa_achievements) { for (auto ach : spa_achievements) {
auto* image_entry = spa_data.GetEntry( auto* image_entry = spa_data.GetEntry(
static_cast<uint16_t>(xdbf::XdbfSpaSection::kImage), ach.image_id); static_cast<uint16_t>(xdbf::SpaSection::kImage), ach.image_id);
if (image_entry) { if (image_entry) {
title_gpd.UpdateEntry(*image_entry); title_gpd.UpdateEntry(*image_entry);
} }
@ -240,18 +240,18 @@ xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) {
// Try adding title image & name // Try adding title image & name
auto* title_image = auto* title_image =
spa_data.GetEntry(static_cast<uint16_t>(xdbf::XdbfSpaSection::kImage), spa_data.GetEntry(static_cast<uint16_t>(xdbf::SpaSection::kImage),
static_cast<uint64_t>(xdbf::XdbfSpaID::Title)); static_cast<uint64_t>(xdbf::SpaID::Title));
if (title_image) { if (title_image) {
title_gpd.UpdateEntry(*title_image); title_gpd.UpdateEntry(*title_image);
} }
auto title_name = xe::to_wstring(spa_data.GetTitleName()); auto title_name = xe::to_wstring(spa_data.GetTitleName());
if (title_name.length()) { if (title_name.length()) {
xdbf::XdbfEntry title_name_ent; xdbf::Entry title_name_ent;
title_name_ent.info.section = title_name_ent.info.section =
static_cast<uint16_t>(xdbf::XdbfGpdSection::kString); static_cast<uint16_t>(xdbf::GpdSection::kString);
title_name_ent.info.id = static_cast<uint64_t>(xdbf::XdbfSpaID::Title); title_name_ent.info.id = static_cast<uint64_t>(xdbf::SpaID::Title);
title_name_ent.data.resize((title_name.length() + 1) * 2); title_name_ent.data.resize((title_name.length() + 1) * 2);
xe::copy_and_swap((wchar_t*)title_name_ent.data.data(), xe::copy_and_swap((wchar_t*)title_name_ent.data.data(),
title_name.c_str(), title_name.length()); title_name.c_str(), title_name.length());
@ -272,7 +272,7 @@ xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) {
// Print achievement list to log, ATM there's no other way for users to see // Print achievement list to log, ATM there's no other way for users to see
// achievement status... // achievement status...
std::vector<xdbf::XdbfAchievement> achievements; std::vector<xdbf::Achievement> achievements;
if (curr_gpd_->GetAchievements(&achievements)) { if (curr_gpd_->GetAchievements(&achievements)) {
XELOGI("Achievement list:"); XELOGI("Achievement list:");
@ -375,9 +375,9 @@ bool UserProfile::UpdateGpd(uint32_t title_id, xdbf::GpdFile& gpd_data) {
} else { } else {
// Check if we need to update dashboard data... // Check if we need to update dashboard data...
if (title_id != kDashboardID) { if (title_id != kDashboardID) {
xdbf::XdbfTitlePlayed title_info; xdbf::TitlePlayed title_info;
if (dash_gpd_.GetTitle(title_id, &title_info)) { if (dash_gpd_.GetTitle(title_id, &title_info)) {
std::vector<xdbf::XdbfAchievement> gpd_achievements; std::vector<xdbf::Achievement> gpd_achievements;
gpd_data.GetAchievements(&gpd_achievements); gpd_data.GetAchievements(&gpd_achievements);
uint32_t num_ach_total = 0; uint32_t num_ach_total = 0;

View File

@ -599,7 +599,7 @@ dword_result_t XamUserCreateAchievementEnumerator(dword_t title_id,
xe::copy_and_swap(place_addr, placeholder_val, wcslen(placeholder_val)); xe::copy_and_swap(place_addr, placeholder_val, wcslen(placeholder_val));
} }
std::vector<xdbf::XdbfAchievement> achievements; std::vector<xdbf::Achievement> achievements;
game_gpd->GetAchievements(&achievements); game_gpd->GetAchievements(&achievements);
for (auto ach : achievements) { for (auto ach : achievements) {

View File

@ -36,7 +36,7 @@ bool XdbfFile::Read(const uint8_t* data, size_t data_size) {
(uint8_t*)free_ptr + (sizeof(X_XDBF_FILELOC) * header_.free_count); (uint8_t*)free_ptr + (sizeof(X_XDBF_FILELOC) * header_.free_count);
for (uint32_t i = 0; i < header_.entry_used; i++) { for (uint32_t i = 0; i < header_.entry_used; i++) {
XdbfEntry entry; Entry entry;
memcpy(&entry.info, ptr, sizeof(X_XDBF_ENTRY)); memcpy(&entry.info, ptr, sizeof(X_XDBF_ENTRY));
entry.data.resize(entry.info.size); entry.data.resize(entry.info.size);
memcpy(entry.data.data(), data_ptr + entry.info.offset, entry.info.size); memcpy(entry.data.data(), data_ptr + entry.info.offset, entry.info.size);
@ -111,9 +111,9 @@ bool XdbfFile::Write(uint8_t* data, size_t* data_size) {
return true; return true;
} }
XdbfEntry* XdbfFile::GetEntry(uint16_t section, uint64_t id) const { Entry* XdbfFile::GetEntry(uint16_t section, uint64_t id) const {
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* entry = (XdbfEntry*)&entries_[i]; auto* entry = (Entry*)&entries_[i];
if (entry->info.section != section || entry->info.id != id) { if (entry->info.section != section || entry->info.id != id) {
continue; continue;
} }
@ -124,9 +124,9 @@ XdbfEntry* XdbfFile::GetEntry(uint16_t section, uint64_t id) const {
return nullptr; return nullptr;
} }
bool XdbfFile::UpdateEntry(XdbfEntry entry) { bool XdbfFile::UpdateEntry(Entry entry) {
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* ent = (XdbfEntry*)&entries_[i]; auto* ent = (Entry*)&entries_[i];
if (ent->info.section != entry.info.section || if (ent->info.section != entry.info.section ||
ent->info.id != entry.info.id) { ent->info.id != entry.info.id) {
continue; continue;
@ -137,7 +137,7 @@ bool XdbfFile::UpdateEntry(XdbfEntry entry) {
return true; return true;
} }
XdbfEntry new_entry; Entry new_entry;
new_entry.info.section = entry.info.section; new_entry.info.section = entry.info.section;
new_entry.info.id = entry.info.id; new_entry.info.id = entry.info.id;
new_entry.info.size = (uint32_t)entry.data.size(); new_entry.info.size = (uint32_t)entry.data.size();
@ -162,18 +162,17 @@ std::string GetStringTableEntry_(const uint8_t* table_start, uint16_t string_id,
return ""; return "";
} }
std::string SpaFile::GetStringTableEntry(XdbfLocale locale, std::string SpaFile::GetStringTableEntry(Locale locale,
uint16_t string_id) const { uint16_t string_id) const {
auto xstr_table = auto xstr_table = GetEntry(static_cast<uint16_t>(SpaSection::kStringTable),
GetEntry(static_cast<uint16_t>(XdbfSpaSection::kStringTable), static_cast<uint64_t>(locale));
static_cast<uint64_t>(locale));
if (!xstr_table) { if (!xstr_table) {
return ""; return "";
} }
auto xstr_head = auto xstr_head =
reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xstr_table->data.data()); reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xstr_table->data.data());
assert_true(xstr_head->magic == static_cast<uint32_t>(XdbfSpaID::Xstr)); assert_true(xstr_head->magic == static_cast<uint32_t>(SpaID::Xstr));
assert_true(xstr_head->version == 1); assert_true(xstr_head->version == 1);
const uint8_t* ptr = xstr_table->data.data() + sizeof(X_XDBF_TABLE_HEADER); const uint8_t* ptr = xstr_table->data.data() + sizeof(X_XDBF_TABLE_HEADER);
@ -182,28 +181,27 @@ std::string SpaFile::GetStringTableEntry(XdbfLocale locale,
} }
uint32_t SpaFile::GetAchievements( uint32_t SpaFile::GetAchievements(
XdbfLocale locale, std::vector<XdbfAchievement>* achievements) const { Locale locale, std::vector<Achievement>* achievements) const {
auto xach_table = GetEntry(static_cast<uint16_t>(XdbfSpaSection::kMetadata), auto xach_table = GetEntry(static_cast<uint16_t>(SpaSection::kMetadata),
static_cast<uint64_t>(XdbfSpaID::Xach)); static_cast<uint64_t>(SpaID::Xach));
if (!xach_table) { if (!xach_table) {
return 0; return 0;
} }
auto xach_head = auto xach_head =
reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xach_table->data.data()); reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xach_table->data.data());
assert_true(xach_head->magic == static_cast<uint32_t>(XdbfSpaID::Xach)); assert_true(xach_head->magic == static_cast<uint32_t>(SpaID::Xach));
assert_true(xach_head->version == 1); assert_true(xach_head->version == 1);
auto xstr_table = auto xstr_table = GetEntry(static_cast<uint16_t>(SpaSection::kStringTable),
GetEntry(static_cast<uint16_t>(XdbfSpaSection::kStringTable), static_cast<uint64_t>(locale));
static_cast<uint64_t>(locale));
if (!xstr_table) { if (!xstr_table) {
return 0; return 0;
} }
auto xstr_head = auto xstr_head =
reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xstr_table->data.data()); reinterpret_cast<const X_XDBF_TABLE_HEADER*>(xstr_table->data.data());
assert_true(xstr_head->magic == static_cast<uint32_t>(XdbfSpaID::Xstr)); assert_true(xstr_head->magic == static_cast<uint32_t>(SpaID::Xstr));
assert_true(xstr_head->version == 1); assert_true(xstr_head->version == 1);
const uint8_t* xstr_ptr = const uint8_t* xstr_ptr =
@ -213,7 +211,7 @@ uint32_t SpaFile::GetAchievements(
auto* ach_data = auto* ach_data =
reinterpret_cast<const X_XDBF_SPA_ACHIEVEMENT*>(xach_head + 1); reinterpret_cast<const X_XDBF_SPA_ACHIEVEMENT*>(xach_head + 1);
for (uint32_t i = 0; i < xach_head->count; i++) { for (uint32_t i = 0; i < xach_head->count; i++) {
XdbfAchievement ach; Achievement ach;
ach.id = ach_data->id; ach.id = ach_data->id;
ach.image_id = ach_data->image_id; ach.image_id = ach_data->image_id;
ach.gamerscore = ach_data->gamerscore; ach.gamerscore = ach_data->gamerscore;
@ -236,47 +234,47 @@ uint32_t SpaFile::GetAchievements(
return xach_head->count; return xach_head->count;
} }
XdbfEntry* SpaFile::GetIcon() const { Entry* SpaFile::GetIcon() const {
return GetEntry(static_cast<uint16_t>(XdbfSpaSection::kImage), return GetEntry(static_cast<uint16_t>(SpaSection::kImage),
static_cast<uint64_t>(XdbfSpaID::Title)); static_cast<uint64_t>(SpaID::Title));
} }
XdbfLocale SpaFile::GetDefaultLocale() const { Locale SpaFile::GetDefaultLocale() const {
auto block = GetEntry(static_cast<uint16_t>(XdbfSpaSection::kMetadata), auto block = GetEntry(static_cast<uint16_t>(SpaSection::kMetadata),
static_cast<uint64_t>(XdbfSpaID::Xstc)); static_cast<uint64_t>(SpaID::Xstc));
if (!block) { if (!block) {
return XdbfLocale::kEnglish; return Locale::kEnglish;
} }
auto xstc = reinterpret_cast<const X_XDBF_XSTC_DATA*>(block->data.data()); auto xstc = reinterpret_cast<const X_XDBF_XSTC_DATA*>(block->data.data());
assert_true(xstc->magic == static_cast<uint32_t>(XdbfSpaID::Xstc)); assert_true(xstc->magic == static_cast<uint32_t>(SpaID::Xstc));
return static_cast<XdbfLocale>(static_cast<uint32_t>(xstc->default_language)); return static_cast<Locale>(static_cast<uint32_t>(xstc->default_language));
} }
std::string SpaFile::GetTitleName() const { std::string SpaFile::GetTitleName() const {
return GetStringTableEntry(GetDefaultLocale(), return GetStringTableEntry(GetDefaultLocale(),
static_cast<uint16_t>(XdbfSpaID::Title)); static_cast<uint16_t>(SpaID::Title));
} }
uint32_t SpaFile::GetTitleId() const { uint32_t SpaFile::GetTitleId() const {
auto block = GetEntry(static_cast<uint16_t>(XdbfSpaSection::kMetadata), auto block = GetEntry(static_cast<uint16_t>(SpaSection::kMetadata),
static_cast<uint64_t>(XdbfSpaID::Xthd)); static_cast<uint64_t>(SpaID::Xthd));
if (!block) { if (!block) {
return -1; return -1;
} }
auto xthd = reinterpret_cast<const X_XDBF_XTHD_DATA*>(block->data.data()); auto xthd = reinterpret_cast<const X_XDBF_XTHD_DATA*>(block->data.data());
assert_true(xthd->magic == static_cast<uint32_t>(XdbfSpaID::Xthd)); assert_true(xthd->magic == static_cast<uint32_t>(SpaID::Xthd));
return xthd->title_id; return xthd->title_id;
} }
bool GpdFile::GetAchievement(uint16_t id, XdbfAchievement* dest) { bool GpdFile::GetAchievement(uint16_t id, Achievement* dest) {
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* entry = (XdbfEntry*)&entries_[i]; auto* entry = (Entry*)&entries_[i];
if (entry->info.section != if (entry->info.section !=
static_cast<uint16_t>(XdbfGpdSection::kAchievement) || static_cast<uint16_t>(GpdSection::kAchievement) ||
entry->info.id != id) { entry->info.id != id) {
continue; continue;
} }
@ -294,13 +292,13 @@ bool GpdFile::GetAchievement(uint16_t id, XdbfAchievement* dest) {
} }
uint32_t GpdFile::GetAchievements( uint32_t GpdFile::GetAchievements(
std::vector<XdbfAchievement>* achievements) const { std::vector<Achievement>* achievements) const {
uint32_t ach_count = 0; uint32_t ach_count = 0;
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* entry = (XdbfEntry*)&entries_[i]; auto* entry = (Entry*)&entries_[i];
if (entry->info.section != if (entry->info.section !=
static_cast<uint16_t>(XdbfGpdSection::kAchievement)) { static_cast<uint16_t>(GpdSection::kAchievement)) {
continue; continue;
} }
if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) { if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) {
@ -313,7 +311,7 @@ uint32_t GpdFile::GetAchievements(
auto* ach_data = auto* ach_data =
reinterpret_cast<const X_XDBF_GPD_ACHIEVEMENT*>(entry->data.data()); reinterpret_cast<const X_XDBF_GPD_ACHIEVEMENT*>(entry->data.data());
XdbfAchievement ach; Achievement ach;
ach.ReadGPD(ach_data); ach.ReadGPD(ach_data);
achievements->push_back(ach); achievements->push_back(ach);
@ -323,10 +321,10 @@ uint32_t GpdFile::GetAchievements(
return ach_count; return ach_count;
} }
bool GpdFile::GetTitle(uint32_t title_id, XdbfTitlePlayed* dest) { bool GpdFile::GetTitle(uint32_t title_id, TitlePlayed* dest) {
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* entry = (XdbfEntry*)&entries_[i]; auto* entry = (Entry*)&entries_[i];
if (entry->info.section != static_cast<uint16_t>(XdbfGpdSection::kTitle) || if (entry->info.section != static_cast<uint16_t>(GpdSection::kTitle) ||
entry->info.id != title_id) { entry->info.id != title_id) {
continue; continue;
} }
@ -342,12 +340,12 @@ bool GpdFile::GetTitle(uint32_t title_id, XdbfTitlePlayed* dest) {
return false; return false;
} }
uint32_t GpdFile::GetTitles(std::vector<XdbfTitlePlayed>* titles) const { uint32_t GpdFile::GetTitles(std::vector<TitlePlayed>* titles) const {
uint32_t title_count = 0; uint32_t title_count = 0;
for (size_t i = 0; i < entries_.size(); i++) { for (size_t i = 0; i < entries_.size(); i++) {
auto* entry = (XdbfEntry*)&entries_[i]; auto* entry = (Entry*)&entries_[i];
if (entry->info.section != static_cast<uint16_t>(XdbfGpdSection::kTitle)) { if (entry->info.section != static_cast<uint16_t>(GpdSection::kTitle)) {
continue; continue;
} }
if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) { if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) {
@ -360,7 +358,7 @@ uint32_t GpdFile::GetTitles(std::vector<XdbfTitlePlayed>* titles) const {
auto* title_data = auto* title_data =
reinterpret_cast<const X_XDBF_GPD_TITLEPLAYED*>(entry->data.data()); reinterpret_cast<const X_XDBF_GPD_TITLEPLAYED*>(entry->data.data());
XdbfTitlePlayed title; TitlePlayed title;
title.ReadGPD(title_data); title.ReadGPD(title_data);
titles->push_back(title); titles->push_back(title);
} }
@ -369,9 +367,9 @@ uint32_t GpdFile::GetTitles(std::vector<XdbfTitlePlayed>* titles) const {
return title_count; return title_count;
} }
bool GpdFile::UpdateAchievement(XdbfAchievement ach) { bool GpdFile::UpdateAchievement(Achievement ach) {
XdbfEntry ent; Entry ent;
ent.info.section = static_cast<uint16_t>(XdbfGpdSection::kAchievement); ent.info.section = static_cast<uint16_t>(GpdSection::kAchievement);
ent.info.id = ach.id; ent.info.id = ach.id;
// calculate entry size... // calculate entry size...
@ -387,7 +385,7 @@ bool GpdFile::UpdateAchievement(XdbfAchievement ach) {
ent.data.resize(est_size); ent.data.resize(est_size);
memset(ent.data.data(), 0, est_size); memset(ent.data.data(), 0, est_size);
// convert XdbfAchievement to GPD achievement // convert Achievement to GPD achievement
auto* ach_data = reinterpret_cast<X_XDBF_GPD_ACHIEVEMENT*>(ent.data.data()); auto* ach_data = reinterpret_cast<X_XDBF_GPD_ACHIEVEMENT*>(ent.data.data());
ach_data->id = ach.id; ach_data->id = ach.id;
ach_data->image_id = ach.image_id; ach_data->image_id = ach.image_id;
@ -410,9 +408,9 @@ bool GpdFile::UpdateAchievement(XdbfAchievement ach) {
return UpdateEntry(ent); return UpdateEntry(ent);
} }
bool GpdFile::UpdateTitle(XdbfTitlePlayed title) { bool GpdFile::UpdateTitle(TitlePlayed title) {
XdbfEntry ent; Entry ent;
ent.info.section = static_cast<uint16_t>(XdbfGpdSection::kTitle); ent.info.section = static_cast<uint16_t>(GpdSection::kTitle);
ent.info.id = title.title_id; ent.info.id = title.title_id;
// calculate entry size... // calculate entry size...

View File

@ -26,7 +26,7 @@ namespace xdbf {
// https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/XEX/SPA.h // https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/XEX/SPA.h
// https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/XEX/SPA.cpp // https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/XEX/SPA.cpp
enum class XdbfSpaID : uint64_t { enum class SpaID : uint64_t {
Xach = 'XACH', Xach = 'XACH',
Xstr = 'XSTR', Xstr = 'XSTR',
Xstc = 'XSTC', Xstc = 'XSTC',
@ -34,13 +34,13 @@ enum class XdbfSpaID : uint64_t {
Title = 0x8000, Title = 0x8000,
}; };
enum class XdbfSpaSection : uint16_t { enum class SpaSection : uint16_t {
kMetadata = 0x1, kMetadata = 0x1,
kImage = 0x2, kImage = 0x2,
kStringTable = 0x3, kStringTable = 0x3,
}; };
enum class XdbfGpdSection : uint16_t { enum class GpdSection : uint16_t {
kAchievement = 0x1, kAchievement = 0x1,
kImage = 0x2, kImage = 0x2,
kSetting = 0x3, kSetting = 0x3,
@ -50,7 +50,7 @@ enum class XdbfGpdSection : uint16_t {
}; };
// Found by dumping the kSectionStringTable sections of various games: // Found by dumping the kSectionStringTable sections of various games:
enum class XdbfLocale : uint32_t { enum class Locale : uint32_t {
kUnknown = 0, kUnknown = 0,
kEnglish = 1, kEnglish = 1,
kJapanese = 2, kJapanese = 2,
@ -73,7 +73,7 @@ inline std::wstring ReadNullTermString(const wchar_t* ptr) {
return retval; return retval;
} }
struct XdbfTitlePlayed { struct TitlePlayed {
uint32_t title_id = 0; uint32_t title_id = 0;
std::wstring title_name; std::wstring title_name;
uint32_t achievements_possible = 0; uint32_t achievements_possible = 0;
@ -123,7 +123,7 @@ struct XdbfTitlePlayed {
} }
}; };
enum class XdbfAchievementType : uint32_t { enum class AchievementType : uint32_t {
kCompletion = 1, kCompletion = 1,
kLeveling = 2, kLeveling = 2,
kUnlock = 3, kUnlock = 3,
@ -133,14 +133,14 @@ enum class XdbfAchievementType : uint32_t {
kOther = 7, kOther = 7,
}; };
enum class XdbfAchievementFlags : uint32_t { enum class AchievementFlags : uint32_t {
kTypeMask = 0x7, kTypeMask = 0x7,
kShowUnachieved = 0x8, kShowUnachieved = 0x8,
kAchievedOnline = 0x10000, kAchievedOnline = 0x10000,
kAchieved = 0x20000 kAchieved = 0x20000
}; };
struct XdbfAchievement { struct Achievement {
uint16_t id = 0; uint16_t id = 0;
std::wstring label; std::wstring label;
std::wstring description; std::wstring description;
@ -150,32 +150,31 @@ struct XdbfAchievement {
uint32_t flags = 0; uint32_t flags = 0;
uint64_t unlock_time = 0; uint64_t unlock_time = 0;
XdbfAchievementType GetType() { AchievementType GetType() {
return static_cast<XdbfAchievementType>( return static_cast<AchievementType>(
flags & static_cast<uint32_t>(XdbfAchievementFlags::kTypeMask)); flags & static_cast<uint32_t>(AchievementFlags::kTypeMask));
} }
bool IsUnlocked() { bool IsUnlocked() {
return flags & static_cast<uint32_t>(XdbfAchievementFlags::kAchieved); return flags & static_cast<uint32_t>(AchievementFlags::kAchieved);
} }
bool IsUnlockedOnline() { bool IsUnlockedOnline() {
return flags & static_cast<uint32_t>(XdbfAchievementFlags::kAchievedOnline); return flags & static_cast<uint32_t>(AchievementFlags::kAchievedOnline);
} }
void Unlock(bool online = false) { void Unlock(bool online = false) {
flags |= static_cast<uint32_t>(XdbfAchievementFlags::kAchieved); flags |= static_cast<uint32_t>(AchievementFlags::kAchieved);
if (online) { if (online) {
flags |= static_cast<uint32_t>(XdbfAchievementFlags::kAchievedOnline); flags |= static_cast<uint32_t>(AchievementFlags::kAchievedOnline);
} }
unlock_time = Clock::QueryHostSystemTime(); unlock_time = Clock::QueryHostSystemTime();
} }
void Lock() { void Lock() {
flags = flags & ~(static_cast<uint32_t>(XdbfAchievementFlags::kAchieved)); flags = flags & ~(static_cast<uint32_t>(AchievementFlags::kAchieved));
flags = flags = flags & ~(static_cast<uint32_t>(AchievementFlags::kAchievedOnline));
flags & ~(static_cast<uint32_t>(XdbfAchievementFlags::kAchievedOnline));
unlock_time = 0; unlock_time = 0;
} }
@ -198,7 +197,7 @@ struct XdbfAchievement {
} }
}; };
struct XdbfEntry { struct Entry {
X_XDBF_ENTRY info; X_XDBF_ENTRY info;
std::vector<uint8_t> data; std::vector<uint8_t> data;
}; };
@ -215,26 +214,26 @@ class XdbfFile {
bool Read(const uint8_t* data, size_t data_size); bool Read(const uint8_t* data, size_t data_size);
bool Write(uint8_t* data, size_t* data_size); bool Write(uint8_t* data, size_t* data_size);
XdbfEntry* GetEntry(uint16_t section, uint64_t id) const; Entry* GetEntry(uint16_t section, uint64_t id) const;
// Updates (or adds) an entry // Updates (or adds) an entry
bool UpdateEntry(XdbfEntry entry); bool UpdateEntry(Entry entry);
protected: protected:
X_XDBF_HEADER header_; X_XDBF_HEADER header_;
std::vector<XdbfEntry> entries_; std::vector<Entry> entries_;
std::vector<X_XDBF_FILELOC> free_entries_; std::vector<X_XDBF_FILELOC> free_entries_;
}; };
class SpaFile : public XdbfFile { class SpaFile : public XdbfFile {
public: public:
std::string GetStringTableEntry(XdbfLocale locale, uint16_t string_id) const; std::string GetStringTableEntry(Locale locale, uint16_t string_id) const;
uint32_t GetAchievements(XdbfLocale locale, uint32_t GetAchievements(Locale locale,
std::vector<XdbfAchievement>* achievements) const; std::vector<Achievement>* achievements) const;
XdbfEntry* GetIcon() const; Entry* GetIcon() const;
XdbfLocale GetDefaultLocale() const; Locale GetDefaultLocale() const;
std::string GetTitleName() const; std::string GetTitleName() const;
uint32_t GetTitleId() const; uint32_t GetTitleId() const;
}; };
@ -244,17 +243,17 @@ class GpdFile : public XdbfFile {
GpdFile() : title_id_(-1) {} GpdFile() : title_id_(-1) {}
GpdFile(uint32_t title_id) : title_id_(title_id) {} GpdFile(uint32_t title_id) : title_id_(title_id) {}
bool GetAchievement(uint16_t id, XdbfAchievement* dest); bool GetAchievement(uint16_t id, Achievement* dest);
uint32_t GetAchievements(std::vector<XdbfAchievement>* achievements) const; uint32_t GetAchievements(std::vector<Achievement>* achievements) const;
bool GetTitle(uint32_t title_id, XdbfTitlePlayed* title); bool GetTitle(uint32_t title_id, TitlePlayed* title);
uint32_t GetTitles(std::vector<XdbfTitlePlayed>* titles) const; uint32_t GetTitles(std::vector<TitlePlayed>* titles) const;
// Updates (or adds) an achievement // Updates (or adds) an achievement
bool UpdateAchievement(XdbfAchievement ach); bool UpdateAchievement(Achievement ach);
// Updates (or adds) a title // Updates (or adds) a title
bool UpdateTitle(XdbfTitlePlayed title); bool UpdateTitle(TitlePlayed title);
uint32_t GetTitleId() { return title_id_; } uint32_t GetTitleId() { return title_id_; }