From 12bf52b36327004464a24d7d5a06863471ab31a3 Mon Sep 17 00:00:00 2001 From: Adrian <78108584+AdrianCassar@users.noreply.github.com> Date: Sat, 21 Sep 2024 17:01:14 +0100 Subject: [PATCH] [XLast] Add presence getters --- src/xenia/kernel/util/xlast.cc | 83 +++++++++++++++++++++++++++++++++- src/xenia/kernel/util/xlast.h | 7 +++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/util/xlast.cc b/src/xenia/kernel/util/xlast.cc index 3bb784356..9bef86bdd 100644 --- a/src/xenia/kernel/util/xlast.cc +++ b/src/xenia/kernel/util/xlast.cc @@ -89,6 +89,10 @@ XLast::~XLast() {} std::u16string XLast::GetTitleName() const { std::string xpath = "/XboxLiveSubmissionProject/GameConfigProject"; + if (!HasXLast()) { + return std::u16string(); + } + const pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); if (!node) { return std::u16string(); @@ -104,6 +108,10 @@ XLast::GetProductInformationAttributes() const { std::string xpath = "/XboxLiveSubmissionProject/GameConfigProject/ProductInformation"; + if (!HasXLast()) { + return attributes; + } + const pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); if (!node) { return attributes; @@ -140,6 +148,10 @@ std::vector XLast::GetSupportedLanguages() const { std::string xpath = fmt::format( "/XboxLiveSubmissionProject/GameConfigProject/LocalizedStrings"); + if (!HasXLast()) { + return launguages; + } + const pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); if (!node) { return launguages; @@ -166,6 +178,10 @@ std::u16string XLast::GetLocalizedString(uint32_t string_id, "LocalizedString[@id = \"{}\"]", string_id); + if (!HasXLast()) { + return std::u16string(); + } + const pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); if (!node) { return std::u16string(); @@ -182,6 +198,66 @@ std::u16string XLast::GetLocalizedString(uint32_t string_id, return xe::to_utf16(locale_node.child_value()); } +const std::optional XLast::GetPresenceStringId( + const uint32_t context_id) { + std::string xpath = fmt::format( + "/XboxLiveSubmissionProject/GameConfigProject/Presence/" + "PresenceMode[@contextValue = \"{}\"]", + context_id); + + std::optional id = std::nullopt; + + if (!HasXLast()) { + return id; + } + + pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); + + if (node) { + const auto string_id = node.node().attribute("stringId").value(); + id = xe::string_util::from_string(string_id); + } + + return id; +} + +const std::optional XLast::GetPropertyStringId( + const uint32_t property_id) { + std::string xpath = fmt::format( + "/XboxLiveSubmissionProject/GameConfigProject/Properties/Property[@id = " + "\"0x{:08X}\"]", + property_id); + + std::optional value = std::nullopt; + + if (!HasXLast()) { + return value; + } + + pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); + + if (node) { + const auto string_id_value = node.node().attribute("stringId").value(); + value = xe::string_util::from_string(string_id_value); + } + + return value; +} + +const std::u16string XLast::GetPresenceRawString(const uint32_t presence_value, + const XLanguage language) { + const std::optional presence_string_id = + GetPresenceStringId(presence_value); + + std::u16string raw_presence = u""; + + if (presence_string_id.has_value()) { + raw_presence = GetLocalizedString(presence_string_id.value(), language); + } + + return raw_presence; +} + XLastMatchmakingQuery* XLast::GetMatchmakingQuery( const uint32_t query_id) const { std::string xpath = fmt::format( @@ -190,6 +266,11 @@ XLastMatchmakingQuery* XLast::GetMatchmakingQuery( query_id); XLastMatchmakingQuery* query = nullptr; + + if (!HasXLast()) { + return query; + } + pugi::xpath_node node = parsed_xlast_->select_node(xpath.c_str()); if (!node) { return query; @@ -215,7 +296,7 @@ std::vector XLast::GetAllValuesFromNode( } void XLast::Dump(std::string file_name) const { - if (xlast_decompressed_xml_.empty()) { + if (!HasXLast()) { return; } diff --git a/src/xenia/kernel/util/xlast.h b/src/xenia/kernel/util/xlast.h index 45aaf8564..06111f21f 100644 --- a/src/xenia/kernel/util/xlast.h +++ b/src/xenia/kernel/util/xlast.h @@ -11,6 +11,7 @@ #define XENIA_KERNEL_UTIL_XLAST_H_ #include +#include #include #include @@ -78,6 +79,10 @@ class XLast { std::vector GetSupportedLanguages() const; std::u16string GetLocalizedString(uint32_t string_id, XLanguage language) const; + const std::optional GetPresenceStringId(const uint32_t context_id); + const std::optional GetPropertyStringId(const uint32_t property_id); + const std::u16string GetPresenceRawString(const uint32_t presence_value, + const XLanguage language); XLastMatchmakingQuery* GetMatchmakingQuery(uint32_t query_id) const; static std::vector GetAllValuesFromNode( const pugi::xpath_node node, const std::string child_name, @@ -85,6 +90,8 @@ class XLast { void Dump(std::string file_name) const; + const bool HasXLast() const { return !xlast_decompressed_xml_.empty(); }; + private: std::string GetLocaleStringFromLanguage(XLanguage language) const;