From adce6c0919d75c8ed5942bcc37a76878315240ec Mon Sep 17 00:00:00 2001 From: Adrian <78108584+AdrianCassar@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:11:03 +0100 Subject: [PATCH] [XAM] Error check count in XUserStatsEnumerator Fix Homefront from crashing --- src/xenia/kernel/xenumerator.cc | 7 +++++++ src/xenia/kernel/xenumerator.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/xenia/kernel/xenumerator.cc b/src/xenia/kernel/xenumerator.cc index 4df073aef..1780f72f3 100644 --- a/src/xenia/kernel/xenumerator.cc +++ b/src/xenia/kernel/xenumerator.cc @@ -120,6 +120,13 @@ uint32_t XAchievementEnumerator::WriteItems(uint32_t buffer_ptr, uint32_t XUserStatsEnumerator::WriteItems(uint32_t buffer_ptr, uint8_t* buffer_data, uint32_t* written_count) { + size_t count = std::min(items_.size() - current_item_, items_per_enumerate()); + if (!count) { + return X_ERROR_NO_MORE_FILES; + } + + size_t size = count * item_size(); + return X_ERROR_SUCCESS; } diff --git a/src/xenia/kernel/xenumerator.h b/src/xenia/kernel/xenumerator.h index ce55b24c4..08a3ff86b 100644 --- a/src/xenia/kernel/xenumerator.h +++ b/src/xenia/kernel/xenumerator.h @@ -176,6 +176,12 @@ class XAchievementEnumerator : public XEnumerator { class XUserStatsEnumerator : public XEnumerator { public: + struct XUSER_STATS_SPEC { + xe::be ViewId; + xe::be NumColumnIds; + xe::be rgwColumnIds[0x40]; + }; + XUserStatsEnumerator(KernelState* kernel_state, size_t items_per_enumerate) : XEnumerator(kernel_state, items_per_enumerate, 0) {} @@ -183,6 +189,7 @@ class XUserStatsEnumerator : public XEnumerator { uint32_t* written_count) override; private: + std::vector items_; size_t current_item_ = 0; };