[Kernel] Remove item limit from enumerators, fixes #1255

Like said in that issue, it seems the limit passed to XamContentCreateEnumerator is actually a limit on how many results XamEnumerate should return per call, not a limit on the number of enumeration items in total.
These changes fix Sonic Unleashed not loading more than 1 DLC (it passes 1 as the limit, but then loops over XamEnumerate to load in each DLC one at a time), and likely many other games.
This commit is contained in:
emoose 2018-11-07 22:47:59 +00:00
parent 3103ad8e16
commit 7f479ffb79
3 changed files with 19 additions and 22 deletions

View File

@ -158,7 +158,7 @@ SHIM_CALL XamContentResolve_shim(PPCContext* ppc_context,
dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
dword_t content_type,
dword_t content_flags,
dword_t max_count,
dword_t items_per_enumerate,
lpdword_t buffer_size_ptr,
lpdword_t handle_out) {
assert_not_null(handle_out);
@ -173,11 +173,11 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
}
if (buffer_size_ptr) {
*buffer_size_ptr = (uint32_t)XCONTENT_DATA::kSize * max_count;
*buffer_size_ptr = (uint32_t)XCONTENT_DATA::kSize * items_per_enumerate;
}
auto e =
new XStaticEnumerator(kernel_state(), max_count, XCONTENT_DATA::kSize);
auto e = new XStaticEnumerator(kernel_state(), items_per_enumerate,
XCONTENT_DATA::kSize);
e->Initialize();
// Get all content data.
@ -187,14 +187,13 @@ dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
content_type);
for (auto& content_data : content_datas) {
auto ptr = e->AppendItem();
if (!ptr) {
// Too many items.
break;
}
assert_not_null(ptr);
content_data.Write(ptr);
}
XELOGD("XamContentCreateEnumerator: added %d items to enumerator",
e->item_count());
*handle_out = e->handle();
return X_ERROR_SUCCESS;
}

View File

@ -12,10 +12,10 @@
namespace xe {
namespace kernel {
XEnumerator::XEnumerator(KernelState* kernel_state, size_t item_capacity,
XEnumerator::XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size)
: XObject(kernel_state, kTypeEnumerator),
item_capacity_(item_capacity),
items_per_enumerate_(items_per_enumerate),
item_size_(item_size) {}
XEnumerator::~XEnumerator() = default;

View File

@ -23,7 +23,7 @@ class XEnumerator : public XObject {
public:
static const Type kType = kTypeEnumerator;
XEnumerator(KernelState* kernel_state, size_t item_capacity,
XEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size);
virtual ~XEnumerator();
@ -34,30 +34,28 @@ class XEnumerator : public XObject {
virtual bool WriteItem(uint8_t* buffer) = 0;
size_t item_size() const { return item_size_; }
size_t items_per_enumerate() const { return items_per_enumerate_; }
size_t current_item() const { return current_item_; }
protected:
size_t item_capacity_ = 0;
size_t items_per_enumerate_ = 0;
size_t item_size_ = 0;
size_t current_item_ = 0;
};
class XStaticEnumerator : public XEnumerator {
public:
XStaticEnumerator(KernelState* kernel_state, size_t item_capacity,
XStaticEnumerator(KernelState* kernel_state, size_t items_per_enumerate,
size_t item_size)
: XEnumerator(kernel_state, item_capacity, item_size), item_count_(0) {
buffer_.resize(item_capacity_ * item_size_);
}
: XEnumerator(kernel_state, items_per_enumerate, item_size),
item_count_(0) {}
uint32_t item_count() const override { return item_count_; }
uint8_t* AppendItem() {
if (item_count_ + 1 > item_capacity_) {
return nullptr;
}
auto ptr = const_cast<uint8_t*>(buffer_.data() + item_count_ * item_size_);
++item_count_;
buffer_.resize(++item_count_ * item_size_);
auto ptr =
const_cast<uint8_t*>(buffer_.data() + (item_count_ - 1) * item_size_);
return ptr;
}