XamContent change HDD size to 1TB, rewrite XamContentCreateEnumerator

This commit is contained in:
Dr. Chat 2015-07-27 18:22:10 -05:00
parent df500e162e
commit 9b722eb602
1 changed files with 29 additions and 66 deletions

View File

@ -25,7 +25,11 @@ struct DeviceInfo {
std::wstring name;
};
static const DeviceInfo dummy_device_info_ = {
0xF00D0000, 1, 1024 * 1024 * 1024, 1024 * 1024 * 1024, L"Dummy HDD",
0xF00D0000,
1,
1024ull * 1024ull * 1024ull * 1024ull, // 1TB
1024ull * 1024ull * 1024ull * 1024ull, // 1TB
L"Dummy HDD",
};
SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_context,
@ -38,7 +42,7 @@ SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_context,
// Each bit in the mask represents a granted license. Available licenses
// seems to vary from game to game, but most appear to use bit 0 to indicate
// if the game is purchased or not.
SHIM_SET_MEM_32(mask_ptr, 0);
SHIM_SET_MEM_32(mask_ptr, -1);
if (overlapped_ptr) {
kernel_state->CompleteOverlappedImmediate(overlapped_ptr, X_ERROR_SUCCESS);
@ -48,40 +52,6 @@ SHIM_CALL XamContentGetLicenseMask_shim(PPCContext* ppc_context,
}
}
SHIM_CALL XamShowDeviceSelectorUI_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t user_index = SHIM_GET_ARG_32(0);
uint32_t content_type = SHIM_GET_ARG_32(1);
uint32_t content_flags = SHIM_GET_ARG_32(2);
uint64_t total_requested = SHIM_GET_ARG_64(3);
uint32_t device_id_ptr = SHIM_GET_ARG_32(4);
uint32_t overlapped_ptr = SHIM_GET_ARG_32(5);
XELOGD("XamShowDeviceSelectorUI(%d, %.8X, %.8X, %.8X, %.8X, %.8X)",
user_index, content_type, content_flags, total_requested,
device_id_ptr, overlapped_ptr);
switch (content_type) {
case 1: // save game
SHIM_SET_MEM_32(device_id_ptr, dummy_device_info_.device_id | 0x0001);
break;
case 2: // marketplace
SHIM_SET_MEM_32(device_id_ptr, dummy_device_info_.device_id | 0x0002);
break;
case 3: // title/publisher update?
SHIM_SET_MEM_32(device_id_ptr, dummy_device_info_.device_id | 0x0003);
break;
}
X_RESULT result = X_ERROR_SUCCESS;
if (overlapped_ptr) {
kernel_state->CompleteOverlappedImmediate(overlapped_ptr, result);
SHIM_SET_RETURN_32(X_ERROR_IO_PENDING);
} else {
SHIM_SET_RETURN_32(result);
}
}
SHIM_CALL XamContentGetDeviceName_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t device_id = SHIM_GET_ARG_32(0);
@ -149,7 +119,7 @@ SHIM_CALL XamContentGetDeviceData_shim(PPCContext* ppc_context,
const auto& device_info = dummy_device_info_;
SHIM_SET_MEM_32(device_data_ptr + 0, device_info.device_id);
SHIM_SET_MEM_32(device_data_ptr + 4, device_info.device_type);
SHIM_SET_MEM_32(device_data_ptr + 4, device_id & 0xFFFF); // Fake it.
SHIM_SET_MEM_64(device_data_ptr + 8, device_info.total_bytes);
SHIM_SET_MEM_64(device_data_ptr + 16, device_info.free_bytes);
xe::store_and_swap<std::wstring>(SHIM_MEM_ADDR(device_data_ptr + 24),
@ -183,54 +153,49 @@ SHIM_CALL XamContentResolve_shim(PPCContext* ppc_context,
}
// http://gameservice.googlecode.com/svn-history/r14/trunk/ContentManager.cpp
SHIM_CALL XamContentCreateEnumerator_shim(PPCContext* ppc_context,
KernelState* kernel_state) {
uint32_t user_index = SHIM_GET_ARG_32(0);
uint32_t device_id = SHIM_GET_ARG_32(1);
uint32_t content_type = SHIM_GET_ARG_32(2);
uint32_t content_flags = SHIM_GET_ARG_32(3);
uint32_t item_count = SHIM_GET_ARG_32(4);
uint32_t buffer_size_ptr = SHIM_GET_ARG_32(5);
uint32_t handle_ptr = SHIM_GET_ARG_32(6);
XELOGD("XamContentCreateEnumerator(%d, %.8X, %.8X, %.8X, %.8X, %.8X, %.8X)",
user_index, device_id, content_type, content_flags, item_count,
buffer_size_ptr, handle_ptr);
if (device_id && (device_id & 0xFFFF0000) != dummy_device_info_.device_id) {
// TODO(benvanik): memset 0 the data?
SHIM_SET_RETURN_32(X_E_INVALIDARG);
return;
// https://github.com/LestaD/SourceEngine2007/blob/master/se2007/engine/xboxsystem.cpp#L499
dword_result_t XamContentCreateEnumerator(dword_t user_index, dword_t device_id,
dword_t content_type,
dword_t content_flags,
dword_t max_count,
lpdword_t buffer_size_ptr,
lpdword_t handle_out) {
assert_not_null(handle_out);
if ((device_id && (device_id & 0xFFFF0000) != dummy_device_info_.device_id) ||
!handle_out) {
if (buffer_size_ptr) {
*buffer_size_ptr = 0;
}
if (!device_id) {
// 0 == whatever
device_id = dummy_device_info_.device_id;
// TODO(benvanik): memset 0 the data?
return X_E_INVALIDARG;
}
if (buffer_size_ptr) {
SHIM_SET_MEM_32(buffer_size_ptr, item_count * XCONTENT_DATA::kSize);
*buffer_size_ptr = (uint32_t)XCONTENT_DATA::kSize;
}
auto e =
new XStaticEnumerator(kernel_state, item_count, XCONTENT_DATA::kSize);
new XStaticEnumerator(kernel_state(), max_count, XCONTENT_DATA::kSize);
e->Initialize();
// Get all content data.
auto content_datas =
kernel_state->content_manager()->ListContent(device_id, content_type);
auto content_datas = kernel_state()->content_manager()->ListContent(
device_id ? device_id : dummy_device_info_.device_id, content_type);
for (auto& content_data : content_datas) {
auto ptr = e->AppendItem();
if (!ptr) {
// Too many items.
break;
}
content_data.Write(ptr);
}
SHIM_SET_MEM_32(handle_ptr, e->handle());
SHIM_SET_RETURN_32(X_ERROR_SUCCESS);
*handle_out = e->handle();
return X_ERROR_SUCCESS;
}
DECLARE_XAM_EXPORT(XamContentCreateEnumerator, ExportTag::kImplemented);
void XamContentCreateCore(PPCContext* ppc_context, KernelState* kernel_state,
uint32_t user_index, std::string root_name,
@ -542,12 +507,10 @@ SHIM_CALL XamContentDelete_shim(PPCContext* ppc_context,
void xe::kernel::xam::RegisterContentExports(
xe::cpu::ExportResolver* export_resolver, KernelState* kernel_state) {
SHIM_SET_MAPPING("xam.xex", XamContentGetLicenseMask, state);
SHIM_SET_MAPPING("xam.xex", XamShowDeviceSelectorUI, state);
SHIM_SET_MAPPING("xam.xex", XamContentGetDeviceName, state);
SHIM_SET_MAPPING("xam.xex", XamContentGetDeviceState, state);
SHIM_SET_MAPPING("xam.xex", XamContentGetDeviceData, state);
SHIM_SET_MAPPING("xam.xex", XamContentResolve, state);
SHIM_SET_MAPPING("xam.xex", XamContentCreateEnumerator, state);
SHIM_SET_MAPPING("xam.xex", XamContentCreate, state);
SHIM_SET_MAPPING("xam.xex", XamContentCreateEx, state);
SHIM_SET_MAPPING("xam.xex", XamContentFlush, state);