From fa611069841b63830d84a1a8361c7e1b86adc754 Mon Sep 17 00:00:00 2001 From: emoose Date: Sun, 18 Nov 2018 06:30:22 +0000 Subject: [PATCH] [Kernel] Remove redundant 'Xdbf' from names --- src/xenia/kernel/xam/apps/xgi_app.cc | 2 +- src/xenia/kernel/xam/user_profile.cc | 24 +++--- src/xenia/kernel/xam/xam_user.cc | 2 +- src/xenia/kernel/xam/xdbf/xdbf.cc | 106 +++++++++++++-------------- src/xenia/kernel/xam/xdbf/xdbf.h | 65 ++++++++-------- 5 files changed, 98 insertions(+), 101 deletions(-) diff --git a/src/xenia/kernel/xam/apps/xgi_app.cc b/src/xenia/kernel/xam/apps/xgi_app.cc index 420e72786..346e15c26 100644 --- a/src/xenia/kernel/xam/apps/xgi_app.cc +++ b/src/xenia/kernel/xam/apps/xgi_app.cc @@ -70,7 +70,7 @@ X_RESULT XgiApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr, bool modified = false; auto* achievement = (X_XUSER_ACHIEVEMENT*)memory_->TranslateVirtual(achievements_ptr); - xdbf::XdbfAchievement ach; + xdbf::Achievement ach; for (uint32_t i = 0; i < achievement_count; i++, achievement++) { if (game_gpd->GetAchievement(achievement->achievement_id, &ach)) { if (!ach.IsUnlocked()) { diff --git a/src/xenia/kernel/xam/user_profile.cc b/src/xenia/kernel/xam/user_profile.cc index 25e5375c9..591762861 100644 --- a/src/xenia/kernel/xam/user_profile.cc +++ b/src/xenia/kernel/xam/user_profile.cc @@ -117,7 +117,7 @@ void UserProfile::LoadGpdFiles() { dash_gpd_.Read(mmap_->data(), mmap_->size()); mmap_->Close(); - std::vector titles; + std::vector titles; dash_gpd_.GetTitles(&titles); for (auto title : titles) { @@ -150,11 +150,11 @@ void UserProfile::LoadGpdFiles() { xdbf::GpdFile* UserProfile::SetTitleSpaData(const xdbf::SpaFile& spa_data) { uint32_t spa_title = spa_data.GetTitleId(); - std::vector spa_achievements; + std::vector spa_achievements; // TODO: let user choose locale? spa_data.GetAchievements(spa_data.GetDefaultLocale(), &spa_achievements); - xdbf::XdbfTitlePlayed title_info; + xdbf::TitlePlayed title_info; auto gpd = title_gpds_.find(spa_title); 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... for (auto ach : spa_achievements) { auto* image_entry = spa_data.GetEntry( - static_cast(xdbf::XdbfSpaSection::kImage), ach.image_id); + static_cast(xdbf::SpaSection::kImage), ach.image_id); if (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 auto* title_image = - spa_data.GetEntry(static_cast(xdbf::XdbfSpaSection::kImage), - static_cast(xdbf::XdbfSpaID::Title)); + spa_data.GetEntry(static_cast(xdbf::SpaSection::kImage), + static_cast(xdbf::SpaID::Title)); if (title_image) { title_gpd.UpdateEntry(*title_image); } auto title_name = xe::to_wstring(spa_data.GetTitleName()); if (title_name.length()) { - xdbf::XdbfEntry title_name_ent; + xdbf::Entry title_name_ent; title_name_ent.info.section = - static_cast(xdbf::XdbfGpdSection::kString); - title_name_ent.info.id = static_cast(xdbf::XdbfSpaID::Title); + static_cast(xdbf::GpdSection::kString); + title_name_ent.info.id = static_cast(xdbf::SpaID::Title); title_name_ent.data.resize((title_name.length() + 1) * 2); xe::copy_and_swap((wchar_t*)title_name_ent.data.data(), 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 // achievement status... - std::vector achievements; + std::vector achievements; if (curr_gpd_->GetAchievements(&achievements)) { XELOGI("Achievement list:"); @@ -375,9 +375,9 @@ bool UserProfile::UpdateGpd(uint32_t title_id, xdbf::GpdFile& gpd_data) { } else { // Check if we need to update dashboard data... if (title_id != kDashboardID) { - xdbf::XdbfTitlePlayed title_info; + xdbf::TitlePlayed title_info; if (dash_gpd_.GetTitle(title_id, &title_info)) { - std::vector gpd_achievements; + std::vector gpd_achievements; gpd_data.GetAchievements(&gpd_achievements); uint32_t num_ach_total = 0; diff --git a/src/xenia/kernel/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc index d994f4089..83d0171a3 100644 --- a/src/xenia/kernel/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -599,7 +599,7 @@ dword_result_t XamUserCreateAchievementEnumerator(dword_t title_id, xe::copy_and_swap(place_addr, placeholder_val, wcslen(placeholder_val)); } - std::vector achievements; + std::vector achievements; game_gpd->GetAchievements(&achievements); for (auto ach : achievements) { diff --git a/src/xenia/kernel/xam/xdbf/xdbf.cc b/src/xenia/kernel/xam/xdbf/xdbf.cc index ecef34136..f04a18656 100644 --- a/src/xenia/kernel/xam/xdbf/xdbf.cc +++ b/src/xenia/kernel/xam/xdbf/xdbf.cc @@ -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); for (uint32_t i = 0; i < header_.entry_used; i++) { - XdbfEntry entry; + Entry entry; memcpy(&entry.info, ptr, sizeof(X_XDBF_ENTRY)); entry.data.resize(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; } -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++) { - auto* entry = (XdbfEntry*)&entries_[i]; + auto* entry = (Entry*)&entries_[i]; if (entry->info.section != section || entry->info.id != id) { continue; } @@ -124,9 +124,9 @@ XdbfEntry* XdbfFile::GetEntry(uint16_t section, uint64_t id) const { return nullptr; } -bool XdbfFile::UpdateEntry(XdbfEntry entry) { +bool XdbfFile::UpdateEntry(Entry entry) { 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 || ent->info.id != entry.info.id) { continue; @@ -137,7 +137,7 @@ bool XdbfFile::UpdateEntry(XdbfEntry entry) { return true; } - XdbfEntry new_entry; + Entry new_entry; new_entry.info.section = entry.info.section; new_entry.info.id = entry.info.id; 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 ""; } -std::string SpaFile::GetStringTableEntry(XdbfLocale locale, +std::string SpaFile::GetStringTableEntry(Locale locale, uint16_t string_id) const { - auto xstr_table = - GetEntry(static_cast(XdbfSpaSection::kStringTable), - static_cast(locale)); + auto xstr_table = GetEntry(static_cast(SpaSection::kStringTable), + static_cast(locale)); if (!xstr_table) { return ""; } auto xstr_head = reinterpret_cast(xstr_table->data.data()); - assert_true(xstr_head->magic == static_cast(XdbfSpaID::Xstr)); + assert_true(xstr_head->magic == static_cast(SpaID::Xstr)); assert_true(xstr_head->version == 1); 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( - XdbfLocale locale, std::vector* achievements) const { - auto xach_table = GetEntry(static_cast(XdbfSpaSection::kMetadata), - static_cast(XdbfSpaID::Xach)); + Locale locale, std::vector* achievements) const { + auto xach_table = GetEntry(static_cast(SpaSection::kMetadata), + static_cast(SpaID::Xach)); if (!xach_table) { return 0; } auto xach_head = reinterpret_cast(xach_table->data.data()); - assert_true(xach_head->magic == static_cast(XdbfSpaID::Xach)); + assert_true(xach_head->magic == static_cast(SpaID::Xach)); assert_true(xach_head->version == 1); - auto xstr_table = - GetEntry(static_cast(XdbfSpaSection::kStringTable), - static_cast(locale)); + auto xstr_table = GetEntry(static_cast(SpaSection::kStringTable), + static_cast(locale)); if (!xstr_table) { return 0; } auto xstr_head = reinterpret_cast(xstr_table->data.data()); - assert_true(xstr_head->magic == static_cast(XdbfSpaID::Xstr)); + assert_true(xstr_head->magic == static_cast(SpaID::Xstr)); assert_true(xstr_head->version == 1); const uint8_t* xstr_ptr = @@ -213,7 +211,7 @@ uint32_t SpaFile::GetAchievements( auto* ach_data = reinterpret_cast(xach_head + 1); for (uint32_t i = 0; i < xach_head->count; i++) { - XdbfAchievement ach; + Achievement ach; ach.id = ach_data->id; ach.image_id = ach_data->image_id; ach.gamerscore = ach_data->gamerscore; @@ -236,47 +234,47 @@ uint32_t SpaFile::GetAchievements( return xach_head->count; } -XdbfEntry* SpaFile::GetIcon() const { - return GetEntry(static_cast(XdbfSpaSection::kImage), - static_cast(XdbfSpaID::Title)); +Entry* SpaFile::GetIcon() const { + return GetEntry(static_cast(SpaSection::kImage), + static_cast(SpaID::Title)); } -XdbfLocale SpaFile::GetDefaultLocale() const { - auto block = GetEntry(static_cast(XdbfSpaSection::kMetadata), - static_cast(XdbfSpaID::Xstc)); +Locale SpaFile::GetDefaultLocale() const { + auto block = GetEntry(static_cast(SpaSection::kMetadata), + static_cast(SpaID::Xstc)); if (!block) { - return XdbfLocale::kEnglish; + return Locale::kEnglish; } auto xstc = reinterpret_cast(block->data.data()); - assert_true(xstc->magic == static_cast(XdbfSpaID::Xstc)); + assert_true(xstc->magic == static_cast(SpaID::Xstc)); - return static_cast(static_cast(xstc->default_language)); + return static_cast(static_cast(xstc->default_language)); } std::string SpaFile::GetTitleName() const { return GetStringTableEntry(GetDefaultLocale(), - static_cast(XdbfSpaID::Title)); + static_cast(SpaID::Title)); } uint32_t SpaFile::GetTitleId() const { - auto block = GetEntry(static_cast(XdbfSpaSection::kMetadata), - static_cast(XdbfSpaID::Xthd)); + auto block = GetEntry(static_cast(SpaSection::kMetadata), + static_cast(SpaID::Xthd)); if (!block) { return -1; } auto xthd = reinterpret_cast(block->data.data()); - assert_true(xthd->magic == static_cast(XdbfSpaID::Xthd)); + assert_true(xthd->magic == static_cast(SpaID::Xthd)); 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++) { - auto* entry = (XdbfEntry*)&entries_[i]; + auto* entry = (Entry*)&entries_[i]; if (entry->info.section != - static_cast(XdbfGpdSection::kAchievement) || + static_cast(GpdSection::kAchievement) || entry->info.id != id) { continue; } @@ -294,13 +292,13 @@ bool GpdFile::GetAchievement(uint16_t id, XdbfAchievement* dest) { } uint32_t GpdFile::GetAchievements( - std::vector* achievements) const { + std::vector* achievements) const { uint32_t ach_count = 0; 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(XdbfGpdSection::kAchievement)) { + static_cast(GpdSection::kAchievement)) { continue; } if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) { @@ -313,7 +311,7 @@ uint32_t GpdFile::GetAchievements( auto* ach_data = reinterpret_cast(entry->data.data()); - XdbfAchievement ach; + Achievement ach; ach.ReadGPD(ach_data); achievements->push_back(ach); @@ -323,10 +321,10 @@ uint32_t GpdFile::GetAchievements( 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++) { - auto* entry = (XdbfEntry*)&entries_[i]; - if (entry->info.section != static_cast(XdbfGpdSection::kTitle) || + auto* entry = (Entry*)&entries_[i]; + if (entry->info.section != static_cast(GpdSection::kTitle) || entry->info.id != title_id) { continue; } @@ -342,12 +340,12 @@ bool GpdFile::GetTitle(uint32_t title_id, XdbfTitlePlayed* dest) { return false; } -uint32_t GpdFile::GetTitles(std::vector* titles) const { +uint32_t GpdFile::GetTitles(std::vector* titles) const { uint32_t title_count = 0; for (size_t i = 0; i < entries_.size(); i++) { - auto* entry = (XdbfEntry*)&entries_[i]; - if (entry->info.section != static_cast(XdbfGpdSection::kTitle)) { + auto* entry = (Entry*)&entries_[i]; + if (entry->info.section != static_cast(GpdSection::kTitle)) { continue; } if (entry->info.id == 0x100000000 || entry->info.id == 0x200000000) { @@ -360,7 +358,7 @@ uint32_t GpdFile::GetTitles(std::vector* titles) const { auto* title_data = reinterpret_cast(entry->data.data()); - XdbfTitlePlayed title; + TitlePlayed title; title.ReadGPD(title_data); titles->push_back(title); } @@ -369,9 +367,9 @@ uint32_t GpdFile::GetTitles(std::vector* titles) const { return title_count; } -bool GpdFile::UpdateAchievement(XdbfAchievement ach) { - XdbfEntry ent; - ent.info.section = static_cast(XdbfGpdSection::kAchievement); +bool GpdFile::UpdateAchievement(Achievement ach) { + Entry ent; + ent.info.section = static_cast(GpdSection::kAchievement); ent.info.id = ach.id; // calculate entry size... @@ -387,7 +385,7 @@ bool GpdFile::UpdateAchievement(XdbfAchievement ach) { ent.data.resize(est_size); memset(ent.data.data(), 0, est_size); - // convert XdbfAchievement to GPD achievement + // convert Achievement to GPD achievement auto* ach_data = reinterpret_cast(ent.data.data()); ach_data->id = ach.id; ach_data->image_id = ach.image_id; @@ -410,9 +408,9 @@ bool GpdFile::UpdateAchievement(XdbfAchievement ach) { return UpdateEntry(ent); } -bool GpdFile::UpdateTitle(XdbfTitlePlayed title) { - XdbfEntry ent; - ent.info.section = static_cast(XdbfGpdSection::kTitle); +bool GpdFile::UpdateTitle(TitlePlayed title) { + Entry ent; + ent.info.section = static_cast(GpdSection::kTitle); ent.info.id = title.title_id; // calculate entry size... diff --git a/src/xenia/kernel/xam/xdbf/xdbf.h b/src/xenia/kernel/xam/xdbf/xdbf.h index 17e1988be..de12617af 100644 --- a/src/xenia/kernel/xam/xdbf/xdbf.h +++ b/src/xenia/kernel/xam/xdbf/xdbf.h @@ -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.cpp -enum class XdbfSpaID : uint64_t { +enum class SpaID : uint64_t { Xach = 'XACH', Xstr = 'XSTR', Xstc = 'XSTC', @@ -34,13 +34,13 @@ enum class XdbfSpaID : uint64_t { Title = 0x8000, }; -enum class XdbfSpaSection : uint16_t { +enum class SpaSection : uint16_t { kMetadata = 0x1, kImage = 0x2, kStringTable = 0x3, }; -enum class XdbfGpdSection : uint16_t { +enum class GpdSection : uint16_t { kAchievement = 0x1, kImage = 0x2, kSetting = 0x3, @@ -50,7 +50,7 @@ enum class XdbfGpdSection : uint16_t { }; // Found by dumping the kSectionStringTable sections of various games: -enum class XdbfLocale : uint32_t { +enum class Locale : uint32_t { kUnknown = 0, kEnglish = 1, kJapanese = 2, @@ -73,7 +73,7 @@ inline std::wstring ReadNullTermString(const wchar_t* ptr) { return retval; } -struct XdbfTitlePlayed { +struct TitlePlayed { uint32_t title_id = 0; std::wstring title_name; uint32_t achievements_possible = 0; @@ -123,7 +123,7 @@ struct XdbfTitlePlayed { } }; -enum class XdbfAchievementType : uint32_t { +enum class AchievementType : uint32_t { kCompletion = 1, kLeveling = 2, kUnlock = 3, @@ -133,14 +133,14 @@ enum class XdbfAchievementType : uint32_t { kOther = 7, }; -enum class XdbfAchievementFlags : uint32_t { +enum class AchievementFlags : uint32_t { kTypeMask = 0x7, kShowUnachieved = 0x8, kAchievedOnline = 0x10000, kAchieved = 0x20000 }; -struct XdbfAchievement { +struct Achievement { uint16_t id = 0; std::wstring label; std::wstring description; @@ -150,32 +150,31 @@ struct XdbfAchievement { uint32_t flags = 0; uint64_t unlock_time = 0; - XdbfAchievementType GetType() { - return static_cast( - flags & static_cast(XdbfAchievementFlags::kTypeMask)); + AchievementType GetType() { + return static_cast( + flags & static_cast(AchievementFlags::kTypeMask)); } bool IsUnlocked() { - return flags & static_cast(XdbfAchievementFlags::kAchieved); + return flags & static_cast(AchievementFlags::kAchieved); } bool IsUnlockedOnline() { - return flags & static_cast(XdbfAchievementFlags::kAchievedOnline); + return flags & static_cast(AchievementFlags::kAchievedOnline); } void Unlock(bool online = false) { - flags |= static_cast(XdbfAchievementFlags::kAchieved); + flags |= static_cast(AchievementFlags::kAchieved); if (online) { - flags |= static_cast(XdbfAchievementFlags::kAchievedOnline); + flags |= static_cast(AchievementFlags::kAchievedOnline); } unlock_time = Clock::QueryHostSystemTime(); } void Lock() { - flags = flags & ~(static_cast(XdbfAchievementFlags::kAchieved)); - flags = - flags & ~(static_cast(XdbfAchievementFlags::kAchievedOnline)); + flags = flags & ~(static_cast(AchievementFlags::kAchieved)); + flags = flags & ~(static_cast(AchievementFlags::kAchievedOnline)); unlock_time = 0; } @@ -198,7 +197,7 @@ struct XdbfAchievement { } }; -struct XdbfEntry { +struct Entry { X_XDBF_ENTRY info; std::vector data; }; @@ -215,26 +214,26 @@ class XdbfFile { bool Read(const 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 - bool UpdateEntry(XdbfEntry entry); + bool UpdateEntry(Entry entry); protected: X_XDBF_HEADER header_; - std::vector entries_; + std::vector entries_; std::vector free_entries_; }; class SpaFile : public XdbfFile { 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, - std::vector* achievements) const; + uint32_t GetAchievements(Locale locale, + std::vector* achievements) const; - XdbfEntry* GetIcon() const; - XdbfLocale GetDefaultLocale() const; + Entry* GetIcon() const; + Locale GetDefaultLocale() const; std::string GetTitleName() const; uint32_t GetTitleId() const; }; @@ -244,17 +243,17 @@ class GpdFile : public XdbfFile { GpdFile() : title_id_(-1) {} GpdFile(uint32_t title_id) : title_id_(title_id) {} - bool GetAchievement(uint16_t id, XdbfAchievement* dest); - uint32_t GetAchievements(std::vector* achievements) const; + bool GetAchievement(uint16_t id, Achievement* dest); + uint32_t GetAchievements(std::vector* achievements) const; - bool GetTitle(uint32_t title_id, XdbfTitlePlayed* title); - uint32_t GetTitles(std::vector* titles) const; + bool GetTitle(uint32_t title_id, TitlePlayed* title); + uint32_t GetTitles(std::vector* titles) const; // Updates (or adds) an achievement - bool UpdateAchievement(XdbfAchievement ach); + bool UpdateAchievement(Achievement ach); // Updates (or adds) a title - bool UpdateTitle(XdbfTitlePlayed title); + bool UpdateTitle(TitlePlayed title); uint32_t GetTitleId() { return title_id_; }