mirror of
https://github.com/xenia-project/xenia.git
synced 2025-12-06 07:12:03 +01:00
[XAM] Improvements to profile r/w setting exports
[XAM] Improvements to XamUserReadProfileSettingsEx/ XamUserWriteProfileSettings. - Unify X_USER_READ_PROFILE_SETTING and X_USER_WRITE_PROFILE_SETTING into X_USER_PROFILE_SETTING. - Clean up Setting serialization to use X_USER_PROFILE_SETTING_DATA instead of manual buffer copying. - Fix XamUserReadProfileSettingsEx case where user_index is non-zero and xuids are being used. - Skip unset settings in XamUserWriteProfileSettings_entry.
This commit is contained in:
parent
b3bb6687db
commit
e49916ea0a
|
|
@ -2,7 +2,7 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* Xenia : Xbox 360 Emulator Research Project *
|
* Xenia : Xbox 360 Emulator Research Project *
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* Copyright 2020 Ben Vanik. All rights reserved. *
|
* Copyright 2022 Ben Vanik. All rights reserved. *
|
||||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
@ -15,14 +15,69 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "xenia/base/byte_stream.h"
|
||||||
#include "xenia/xbox.h"
|
#include "xenia/xbox.h"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
namespace xam {
|
namespace xam {
|
||||||
|
|
||||||
|
struct X_USER_PROFILE_SETTING_DATA {
|
||||||
|
// UserProfile::Setting::Type. Appears to be 8-in-32 field, and the upper 24
|
||||||
|
// are not always zeroed by the game.
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t unk_1[3];
|
||||||
|
xe::be<uint32_t> unk_4;
|
||||||
|
// TODO(sabretooth): not sure if this is a union, but it seems likely.
|
||||||
|
// Haven't run into cases other than "binary data" yet.
|
||||||
|
union {
|
||||||
|
xe::be<int32_t> s32;
|
||||||
|
xe::be<int64_t> s64;
|
||||||
|
xe::be<uint32_t> u32;
|
||||||
|
xe::be<double> f64;
|
||||||
|
struct {
|
||||||
|
xe::be<uint32_t> size;
|
||||||
|
xe::be<uint32_t> ptr;
|
||||||
|
} unicode;
|
||||||
|
xe::be<float> f32;
|
||||||
|
struct {
|
||||||
|
xe::be<uint32_t> size;
|
||||||
|
xe::be<uint32_t> ptr;
|
||||||
|
} binary;
|
||||||
|
xe::be<uint64_t> filetime;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
static_assert_size(X_USER_PROFILE_SETTING_DATA, 16);
|
||||||
|
|
||||||
|
struct X_USER_PROFILE_SETTING {
|
||||||
|
xe::be<uint32_t> from;
|
||||||
|
xe::be<uint32_t> unk04;
|
||||||
|
union {
|
||||||
|
xe::be<uint32_t> user_index;
|
||||||
|
xe::be<uint64_t> xuid;
|
||||||
|
};
|
||||||
|
xe::be<uint32_t> setting_id;
|
||||||
|
xe::be<uint32_t> unk14;
|
||||||
|
union {
|
||||||
|
uint8_t data_bytes[sizeof(X_USER_PROFILE_SETTING_DATA)];
|
||||||
|
X_USER_PROFILE_SETTING_DATA data;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
static_assert_size(X_USER_PROFILE_SETTING, 40);
|
||||||
|
|
||||||
class UserProfile {
|
class UserProfile {
|
||||||
public:
|
public:
|
||||||
|
class SettingByteStream : public ByteStream {
|
||||||
|
public:
|
||||||
|
SettingByteStream(uint32_t ptr, uint8_t* data, size_t data_length,
|
||||||
|
size_t offset = 0)
|
||||||
|
: ByteStream(data, data_length, offset), ptr_(ptr) {}
|
||||||
|
|
||||||
|
uint32_t ptr() const { return static_cast<uint32_t>(ptr_ + offset()); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t ptr_;
|
||||||
|
};
|
||||||
struct Setting {
|
struct Setting {
|
||||||
enum class Type {
|
enum class Type {
|
||||||
CONTENT = 0,
|
CONTENT = 0,
|
||||||
|
|
@ -33,7 +88,7 @@ class UserProfile {
|
||||||
FLOAT = 5,
|
FLOAT = 5,
|
||||||
BINARY = 6,
|
BINARY = 6,
|
||||||
DATETIME = 7,
|
DATETIME = 7,
|
||||||
INVALID = 0xFF,
|
UNSET = 0xFF,
|
||||||
};
|
};
|
||||||
union Key {
|
union Key {
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
|
|
@ -55,97 +110,77 @@ class UserProfile {
|
||||||
size(size),
|
size(size),
|
||||||
is_set(is_set),
|
is_set(is_set),
|
||||||
loaded_title_id(0) {}
|
loaded_title_id(0) {}
|
||||||
virtual size_t extra_size() const { return 0; }
|
virtual void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
virtual size_t Append(uint8_t* user_data, uint8_t* buffer,
|
SettingByteStream* stream) {
|
||||||
uint32_t buffer_ptr, size_t buffer_offset) {
|
data->type = static_cast<uint8_t>(type);
|
||||||
xe::store_and_swap<uint8_t>(user_data + kTypeOffset,
|
|
||||||
static_cast<uint8_t>(type));
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
virtual std::vector<uint8_t> Serialize() const {
|
virtual std::vector<uint8_t> Serialize() const {
|
||||||
return std::vector<uint8_t>();
|
return std::vector<uint8_t>();
|
||||||
}
|
}
|
||||||
virtual void Deserialize(std::vector<uint8_t>) {}
|
virtual void Deserialize(std::vector<uint8_t>) {}
|
||||||
bool is_title_specific() const { return (setting_id & 0x3F00) == 0x3F00; }
|
bool is_title_specific() const { return (setting_id & 0x3F00) == 0x3F00; }
|
||||||
|
|
||||||
protected:
|
|
||||||
const size_t kTypeOffset = 0;
|
|
||||||
const size_t kValueOffset = 8;
|
|
||||||
const size_t kPointerOffset = 12;
|
|
||||||
};
|
};
|
||||||
struct Int32Setting : public Setting {
|
struct Int32Setting : public Setting {
|
||||||
Int32Setting(uint32_t setting_id, int32_t value)
|
Int32Setting(uint32_t setting_id, int32_t value)
|
||||||
: Setting(setting_id, Type::INT32, 4, true), value(value) {}
|
: Setting(setting_id, Type::INT32, 4, true), value(value) {}
|
||||||
int32_t value;
|
int32_t value;
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
size_t buffer_offset) override {
|
SettingByteStream* stream) override {
|
||||||
buffer_offset =
|
Setting::Append(data, stream);
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
data->s32 = value;
|
||||||
xe::store_and_swap<int32_t>(user_data + kValueOffset, value);
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct Int64Setting : public Setting {
|
struct Int64Setting : public Setting {
|
||||||
Int64Setting(uint32_t setting_id, int64_t value)
|
Int64Setting(uint32_t setting_id, int64_t value)
|
||||||
: Setting(setting_id, Type::INT64, 8, true), value(value) {}
|
: Setting(setting_id, Type::INT64, 8, true), value(value) {}
|
||||||
int64_t value;
|
int64_t value;
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
size_t buffer_offset) override {
|
SettingByteStream* stream) override {
|
||||||
buffer_offset =
|
Setting::Append(data, stream);
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
data->s64 = value;
|
||||||
xe::store_and_swap<int64_t>(user_data + kValueOffset, value);
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct DoubleSetting : public Setting {
|
struct DoubleSetting : public Setting {
|
||||||
DoubleSetting(uint32_t setting_id, double value)
|
DoubleSetting(uint32_t setting_id, double value)
|
||||||
: Setting(setting_id, Type::DOUBLE, 8, true), value(value) {}
|
: Setting(setting_id, Type::DOUBLE, 8, true), value(value) {}
|
||||||
double value;
|
double value;
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
size_t buffer_offset) override {
|
SettingByteStream* stream) override {
|
||||||
buffer_offset =
|
Setting::Append(data, stream);
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
data->f64 = value;
|
||||||
xe::store_and_swap<double>(user_data + kValueOffset, value);
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct UnicodeSetting : public Setting {
|
struct UnicodeSetting : public Setting {
|
||||||
UnicodeSetting(uint32_t setting_id, const std::u16string& value)
|
UnicodeSetting(uint32_t setting_id, const std::u16string& value)
|
||||||
: Setting(setting_id, Type::WSTRING, 8, true), value(value) {}
|
: Setting(setting_id, Type::WSTRING, 8, true), value(value) {}
|
||||||
std::u16string value;
|
std::u16string value;
|
||||||
size_t extra_size() const override {
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
return value.empty() ? 0 : 2 * (static_cast<int32_t>(value.size()) + 1);
|
SettingByteStream* stream) override {
|
||||||
}
|
Setting::Append(data, stream);
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
|
||||||
size_t buffer_offset) override {
|
|
||||||
buffer_offset =
|
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
|
||||||
int32_t length;
|
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
length = 0;
|
data->unicode.size = 0;
|
||||||
xe::store_and_swap<int32_t>(user_data + kValueOffset, 0);
|
data->unicode.ptr = 0;
|
||||||
xe::store_and_swap<uint32_t>(user_data + kPointerOffset, 0);
|
|
||||||
} else {
|
} else {
|
||||||
length = 2 * (static_cast<int32_t>(value.size()) + 1);
|
size_t count = value.size() + 1;
|
||||||
xe::store_and_swap<int32_t>(user_data + kValueOffset, length);
|
size_t size = 2 * count;
|
||||||
xe::store_and_swap<uint32_t>(
|
assert_true(size <= std::numeric_limits<uint32_t>::max());
|
||||||
user_data + kPointerOffset,
|
data->unicode.size = static_cast<uint32_t>(size);
|
||||||
buffer_ptr + static_cast<uint32_t>(buffer_offset));
|
data->unicode.ptr = stream->ptr();
|
||||||
memcpy(buffer + buffer_offset, value.data(), length);
|
auto buffer =
|
||||||
|
reinterpret_cast<uint16_t*>(&stream->data()[stream->offset()]);
|
||||||
|
stream->Advance(size);
|
||||||
|
xe::copy_and_swap(buffer, (uint16_t*)value.data(), count);
|
||||||
}
|
}
|
||||||
return buffer_offset + length;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct FloatSetting : public Setting {
|
struct FloatSetting : public Setting {
|
||||||
FloatSetting(uint32_t setting_id, float value)
|
FloatSetting(uint32_t setting_id, float value)
|
||||||
: Setting(setting_id, Type::FLOAT, 4, true), value(value) {}
|
: Setting(setting_id, Type::FLOAT, 4, true), value(value) {}
|
||||||
float value;
|
float value;
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
size_t buffer_offset) override {
|
SettingByteStream* stream) override {
|
||||||
buffer_offset =
|
Setting::Append(data, stream);
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
data->f32 = value;
|
||||||
xe::store_and_swap<float>(user_data + kValueOffset, value);
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct BinarySetting : public Setting {
|
struct BinarySetting : public Setting {
|
||||||
|
|
@ -154,27 +189,19 @@ class UserProfile {
|
||||||
BinarySetting(uint32_t setting_id, const std::vector<uint8_t>& value)
|
BinarySetting(uint32_t setting_id, const std::vector<uint8_t>& value)
|
||||||
: Setting(setting_id, Type::BINARY, 8, true), value(value) {}
|
: Setting(setting_id, Type::BINARY, 8, true), value(value) {}
|
||||||
std::vector<uint8_t> value;
|
std::vector<uint8_t> value;
|
||||||
size_t extra_size() const override {
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
return static_cast<int32_t>(value.size());
|
SettingByteStream* stream) override {
|
||||||
}
|
Setting::Append(data, stream);
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
|
||||||
size_t buffer_offset) override {
|
|
||||||
buffer_offset =
|
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
|
||||||
int32_t length;
|
|
||||||
if (value.empty()) {
|
if (value.empty()) {
|
||||||
length = 0;
|
data->binary.size = 0;
|
||||||
xe::store_and_swap<int32_t>(user_data + kValueOffset, 0);
|
data->binary.ptr = 0;
|
||||||
xe::store_and_swap<int32_t>(user_data + kPointerOffset, 0);
|
|
||||||
} else {
|
} else {
|
||||||
length = static_cast<int32_t>(value.size());
|
size_t size = value.size();
|
||||||
xe::store_and_swap<int32_t>(user_data + kValueOffset, length);
|
assert_true(size <= std::numeric_limits<uint32_t>::max());
|
||||||
xe::store_and_swap<uint32_t>(
|
data->binary.size = static_cast<uint32_t>(size);
|
||||||
user_data + kPointerOffset,
|
data->binary.ptr = stream->ptr();
|
||||||
buffer_ptr + static_cast<uint32_t>(buffer_offset));
|
stream->Write(value.data(), size);
|
||||||
memcpy(buffer + buffer_offset, value.data(), length);
|
|
||||||
}
|
}
|
||||||
return buffer_offset + length;
|
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> Serialize() const override {
|
std::vector<uint8_t> Serialize() const override {
|
||||||
return std::vector<uint8_t>(value.data(), value.data() + value.size());
|
return std::vector<uint8_t>(value.data(), value.data() + value.size());
|
||||||
|
|
@ -188,12 +215,10 @@ class UserProfile {
|
||||||
DateTimeSetting(uint32_t setting_id, int64_t value)
|
DateTimeSetting(uint32_t setting_id, int64_t value)
|
||||||
: Setting(setting_id, Type::DATETIME, 8, true), value(value) {}
|
: Setting(setting_id, Type::DATETIME, 8, true), value(value) {}
|
||||||
int64_t value;
|
int64_t value;
|
||||||
size_t Append(uint8_t* user_data, uint8_t* buffer, uint32_t buffer_ptr,
|
void Append(X_USER_PROFILE_SETTING_DATA* data,
|
||||||
size_t buffer_offset) override {
|
SettingByteStream* stream) override {
|
||||||
buffer_offset =
|
Setting::Append(data, stream);
|
||||||
Setting::Append(user_data, buffer, buffer_ptr, buffer_offset);
|
data->filetime = value;
|
||||||
xe::store_and_swap<int64_t>(user_data + kValueOffset, value);
|
|
||||||
return buffer_offset;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "xenia/base/string_util.h"
|
#include "xenia/base/string_util.h"
|
||||||
#include "xenia/kernel/kernel_state.h"
|
#include "xenia/kernel/kernel_state.h"
|
||||||
#include "xenia/kernel/util/shim_utils.h"
|
#include "xenia/kernel/util/shim_utils.h"
|
||||||
|
#include "xenia/kernel/xam/user_profile.h"
|
||||||
#include "xenia/kernel/xam/xam_private.h"
|
#include "xenia/kernel/xam/xam_private.h"
|
||||||
#include "xenia/kernel/xenumerator.h"
|
#include "xenia/kernel/xenumerator.h"
|
||||||
#include "xenia/kernel/xthread.h"
|
#include "xenia/kernel/xthread.h"
|
||||||
|
|
@ -146,25 +147,14 @@ typedef struct {
|
||||||
} X_USER_READ_PROFILE_SETTINGS;
|
} X_USER_READ_PROFILE_SETTINGS;
|
||||||
static_assert_size(X_USER_READ_PROFILE_SETTINGS, 8);
|
static_assert_size(X_USER_READ_PROFILE_SETTINGS, 8);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
xe::be<uint32_t> from;
|
|
||||||
xe::be<uint32_t> unk04;
|
|
||||||
xe::be<uint32_t> user_index;
|
|
||||||
xe::be<uint32_t> unk0C;
|
|
||||||
xe::be<uint32_t> setting_id;
|
|
||||||
xe::be<uint32_t> unk14;
|
|
||||||
uint8_t setting_data[16];
|
|
||||||
} X_USER_READ_PROFILE_SETTING;
|
|
||||||
static_assert_size(X_USER_READ_PROFILE_SETTING, 40);
|
|
||||||
|
|
||||||
// https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/Generic/xboxtools.cpp
|
// https://github.com/oukiar/freestyledash/blob/master/Freestyle/Tools/Generic/xboxtools.cpp
|
||||||
uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
uint32_t XamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
uint32_t xuid_count, lpqword_t xuids,
|
uint32_t xuid_count, be<uint64_t>* xuids,
|
||||||
uint32_t setting_count,
|
uint32_t setting_count,
|
||||||
lpdword_t setting_ids, uint32_t unk,
|
be<uint32_t>* setting_ids, uint32_t unk,
|
||||||
lpdword_t buffer_size_ptr,
|
be<uint32_t>* buffer_size_ptr,
|
||||||
lpvoid_t buffer_ptr,
|
uint8_t* buffer,
|
||||||
uint32_t overlapped_ptr) {
|
XAM_OVERLAPPED* overlapped) {
|
||||||
if (!xuid_count) {
|
if (!xuid_count) {
|
||||||
assert_null(xuids);
|
assert_null(xuids);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -173,8 +163,11 @@ uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
// TODO(gibbed): allow proper lookup of arbitrary XUIDs
|
// TODO(gibbed): allow proper lookup of arbitrary XUIDs
|
||||||
const auto& user_profile = kernel_state()->user_profile();
|
const auto& user_profile = kernel_state()->user_profile();
|
||||||
assert_true(static_cast<uint64_t>(xuids[0]) == user_profile->xuid());
|
assert_true(static_cast<uint64_t>(xuids[0]) == user_profile->xuid());
|
||||||
|
// TODO(gibbed): we assert here, but in case a title passes xuid_count > 1
|
||||||
|
// until it's implemented for release builds...
|
||||||
|
xuid_count = 1;
|
||||||
}
|
}
|
||||||
assert_zero(unk);
|
assert_zero(unk); // probably flags
|
||||||
|
|
||||||
// must have at least 1 to 32 settings
|
// must have at least 1 to 32 settings
|
||||||
if (setting_count < 1 || setting_count > 32) {
|
if (setting_count < 1 || setting_count > 32) {
|
||||||
|
|
@ -188,35 +181,33 @@ uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
|
|
||||||
// if buffer size is non-zero, buffer pointer must be valid
|
// if buffer size is non-zero, buffer pointer must be valid
|
||||||
auto buffer_size = static_cast<uint32_t>(*buffer_size_ptr);
|
auto buffer_size = static_cast<uint32_t>(*buffer_size_ptr);
|
||||||
if (buffer_size && !buffer_ptr) {
|
if (buffer_size && !buffer) {
|
||||||
return X_ERROR_INVALID_PARAMETER;
|
return X_ERROR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t needed_header_size = 0;
|
uint32_t needed_header_size = 0;
|
||||||
uint32_t needed_extra_size = 0;
|
uint32_t needed_data_size = 0;
|
||||||
for (uint32_t i = 0; i < setting_count; ++i) {
|
for (uint32_t i = 0; i < setting_count; ++i) {
|
||||||
needed_header_size += sizeof(X_USER_READ_PROFILE_SETTING);
|
needed_header_size += sizeof(X_USER_PROFILE_SETTING);
|
||||||
UserProfile::Setting::Key setting_key;
|
UserProfile::Setting::Key setting_key;
|
||||||
setting_key.value = static_cast<uint32_t>(setting_ids[i]);
|
setting_key.value = static_cast<uint32_t>(setting_ids[i]);
|
||||||
switch (static_cast<UserProfile::Setting::Type>(setting_key.type)) {
|
switch (static_cast<UserProfile::Setting::Type>(setting_key.type)) {
|
||||||
case UserProfile::Setting::Type::WSTRING:
|
case UserProfile::Setting::Type::WSTRING:
|
||||||
case UserProfile::Setting::Type::BINARY: {
|
case UserProfile::Setting::Type::BINARY:
|
||||||
needed_extra_size += setting_key.size;
|
needed_data_size += setting_key.size;
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
default: {
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xuids) {
|
if (xuids) {
|
||||||
// needed_header_size *= xuid_count;
|
needed_header_size *= xuid_count;
|
||||||
// needed_extra_size *= !xuid_count;
|
needed_data_size *= xuid_count;
|
||||||
}
|
}
|
||||||
needed_header_size += sizeof(X_USER_READ_PROFILE_SETTINGS);
|
needed_header_size += sizeof(X_USER_READ_PROFILE_SETTINGS);
|
||||||
|
|
||||||
uint32_t needed_size = needed_header_size + needed_extra_size;
|
uint32_t needed_size = needed_header_size + needed_data_size;
|
||||||
if (!buffer_ptr || buffer_size < needed_size) {
|
if (!buffer || buffer_size < needed_size) {
|
||||||
if (!buffer_size) {
|
if (!buffer_size) {
|
||||||
*buffer_size_ptr = needed_size;
|
*buffer_size_ptr = needed_size;
|
||||||
}
|
}
|
||||||
|
|
@ -226,11 +217,12 @@ uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
// Title ID = 0 means us.
|
// Title ID = 0 means us.
|
||||||
// 0xfffe07d1 = profile?
|
// 0xfffe07d1 = profile?
|
||||||
|
|
||||||
if (user_index) {
|
if (!xuids && user_index) {
|
||||||
// Only support user 0.
|
// Only support user 0.
|
||||||
if (overlapped_ptr) {
|
if (overlapped) {
|
||||||
kernel_state()->CompleteOverlappedImmediate(overlapped_ptr,
|
kernel_state()->CompleteOverlappedImmediate(
|
||||||
X_ERROR_NO_SUCH_USER);
|
kernel_state()->memory()->HostToGuestVirtual(overlapped),
|
||||||
|
X_ERROR_NO_SUCH_USER);
|
||||||
return X_ERROR_IO_PENDING;
|
return X_ERROR_IO_PENDING;
|
||||||
}
|
}
|
||||||
return X_ERROR_NO_SUCH_USER;
|
return X_ERROR_NO_SUCH_USER;
|
||||||
|
|
@ -257,49 +249,49 @@ uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
}
|
}
|
||||||
if (any_missing) {
|
if (any_missing) {
|
||||||
// TODO(benvanik): don't fail? most games don't even check!
|
// TODO(benvanik): don't fail? most games don't even check!
|
||||||
if (overlapped_ptr) {
|
if (overlapped) {
|
||||||
kernel_state()->CompleteOverlappedImmediate(overlapped_ptr,
|
kernel_state()->CompleteOverlappedImmediate(
|
||||||
X_ERROR_INVALID_PARAMETER);
|
kernel_state()->memory()->HostToGuestVirtual(overlapped),
|
||||||
|
X_ERROR_INVALID_PARAMETER);
|
||||||
return X_ERROR_IO_PENDING;
|
return X_ERROR_IO_PENDING;
|
||||||
}
|
}
|
||||||
return X_ERROR_INVALID_PARAMETER;
|
return X_ERROR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out_header = buffer_ptr.as<X_USER_READ_PROFILE_SETTINGS*>();
|
auto out_header = reinterpret_cast<X_USER_READ_PROFILE_SETTINGS*>(buffer);
|
||||||
|
auto out_setting = reinterpret_cast<X_USER_PROFILE_SETTING*>(&out_header[1]);
|
||||||
out_header->setting_count = static_cast<uint32_t>(setting_count);
|
out_header->setting_count = static_cast<uint32_t>(setting_count);
|
||||||
out_header->settings_ptr = buffer_ptr.guest_address() + 8;
|
out_header->settings_ptr =
|
||||||
|
kernel_state()->memory()->HostToGuestVirtual(out_setting);
|
||||||
|
|
||||||
auto out_setting =
|
UserProfile::SettingByteStream out_stream(
|
||||||
reinterpret_cast<X_USER_READ_PROFILE_SETTING*>(&out_header[1]);
|
kernel_state()->memory()->HostToGuestVirtual(buffer), buffer, buffer_size,
|
||||||
|
needed_header_size);
|
||||||
size_t buffer_offset = needed_header_size;
|
|
||||||
for (uint32_t n = 0; n < setting_count; ++n) {
|
for (uint32_t n = 0; n < setting_count; ++n) {
|
||||||
uint32_t setting_id = setting_ids[n];
|
uint32_t setting_id = setting_ids[n];
|
||||||
auto setting = user_profile->GetSetting(setting_id);
|
auto setting = user_profile->GetSetting(setting_id);
|
||||||
|
|
||||||
std::memset(out_setting, 0, sizeof(X_USER_READ_PROFILE_SETTING));
|
std::memset(out_setting, 0, sizeof(X_USER_PROFILE_SETTING));
|
||||||
out_setting->from = !setting || !setting->is_set ? 0
|
out_setting->from = !setting || !setting->is_set ? 0
|
||||||
: setting->is_title_specific() ? 2
|
: setting->is_title_specific() ? 2
|
||||||
: 1;
|
: 1;
|
||||||
out_setting->user_index = static_cast<uint32_t>(user_index);
|
if (xuids) {
|
||||||
|
out_setting->xuid = user_profile->xuid();
|
||||||
|
} else {
|
||||||
|
out_setting->user_index = static_cast<uint32_t>(user_index);
|
||||||
|
}
|
||||||
out_setting->setting_id = setting_id;
|
out_setting->setting_id = setting_id;
|
||||||
|
|
||||||
if (setting && setting->is_set) {
|
if (setting && setting->is_set) {
|
||||||
buffer_offset =
|
setting->Append(&out_setting->data, &out_stream);
|
||||||
setting->Append(&out_setting->setting_data[0], buffer_ptr,
|
|
||||||
buffer_ptr.guest_address(), buffer_offset);
|
|
||||||
}
|
}
|
||||||
// TODO(benvanik): why did I do this?
|
|
||||||
/*else {
|
|
||||||
std::memset(&out_setting->setting_data[0], 0,
|
|
||||||
sizeof(out_setting->setting_data));
|
|
||||||
}*/
|
|
||||||
++out_setting;
|
++out_setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlapped_ptr) {
|
if (overlapped) {
|
||||||
kernel_state()->CompleteOverlappedImmediate(overlapped_ptr,
|
kernel_state()->CompleteOverlappedImmediate(
|
||||||
X_ERROR_SUCCESS);
|
kernel_state()->memory()->HostToGuestVirtual(overlapped),
|
||||||
|
X_ERROR_SUCCESS);
|
||||||
return X_ERROR_IO_PENDING;
|
return X_ERROR_IO_PENDING;
|
||||||
}
|
}
|
||||||
return X_ERROR_SUCCESS;
|
return X_ERROR_SUCCESS;
|
||||||
|
|
@ -308,57 +300,35 @@ uint32_t xeXamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
|
||||||
dword_result_t XamUserReadProfileSettings_entry(
|
dword_result_t XamUserReadProfileSettings_entry(
|
||||||
dword_t title_id, dword_t user_index, dword_t xuid_count, lpqword_t xuids,
|
dword_t title_id, dword_t user_index, dword_t xuid_count, lpqword_t xuids,
|
||||||
dword_t setting_count, lpdword_t setting_ids, lpdword_t buffer_size_ptr,
|
dword_t setting_count, lpdword_t setting_ids, lpdword_t buffer_size_ptr,
|
||||||
lpvoid_t buffer_ptr, dword_t overlapped_ptr) {
|
lpvoid_t buffer_ptr, pointer_t<XAM_OVERLAPPED> overlapped) {
|
||||||
return xeXamUserReadProfileSettingsEx(
|
return XamUserReadProfileSettingsEx(title_id, user_index, xuid_count, xuids,
|
||||||
title_id, user_index, xuid_count, xuids, setting_count, setting_ids, 0,
|
setting_count, setting_ids, 0,
|
||||||
buffer_size_ptr, buffer_ptr, overlapped_ptr);
|
buffer_size_ptr, buffer_ptr, overlapped);
|
||||||
}
|
}
|
||||||
DECLARE_XAM_EXPORT1(XamUserReadProfileSettings, kUserProfiles, kImplemented);
|
DECLARE_XAM_EXPORT1(XamUserReadProfileSettings, kUserProfiles, kImplemented);
|
||||||
|
|
||||||
dword_result_t XamUserReadProfileSettingsEx_entry(
|
dword_result_t XamUserReadProfileSettingsEx_entry(
|
||||||
dword_t title_id, dword_t user_index, dword_t xuid_count, lpqword_t xuids,
|
dword_t title_id, dword_t user_index, dword_t xuid_count, lpqword_t xuids,
|
||||||
dword_t setting_count, lpdword_t setting_ids, lpdword_t buffer_size_ptr,
|
dword_t setting_count, lpdword_t setting_ids, lpdword_t buffer_size_ptr,
|
||||||
dword_t unk_2, lpvoid_t buffer_ptr, dword_t overlapped_ptr) {
|
dword_t unk_2, lpvoid_t buffer_ptr, pointer_t<XAM_OVERLAPPED> overlapped) {
|
||||||
return xeXamUserReadProfileSettingsEx(
|
return XamUserReadProfileSettingsEx(title_id, user_index, xuid_count, xuids,
|
||||||
title_id, user_index, xuid_count, xuids, setting_count, setting_ids,
|
setting_count, setting_ids, unk_2,
|
||||||
unk_2, buffer_size_ptr, buffer_ptr, overlapped_ptr);
|
buffer_size_ptr, buffer_ptr, overlapped);
|
||||||
}
|
}
|
||||||
DECLARE_XAM_EXPORT1(XamUserReadProfileSettingsEx, kUserProfiles, kImplemented);
|
DECLARE_XAM_EXPORT1(XamUserReadProfileSettingsEx, kUserProfiles, kImplemented);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
xe::be<uint32_t> from;
|
|
||||||
xe::be<uint32_t> unk_04;
|
|
||||||
xe::be<uint32_t> unk_08;
|
|
||||||
xe::be<uint32_t> unk_0c;
|
|
||||||
xe::be<uint32_t> setting_id;
|
|
||||||
xe::be<uint32_t> unk_14;
|
|
||||||
|
|
||||||
// UserProfile::Setting::Type. Appears to be 8-in-32 field, and the upper 24
|
|
||||||
// are not always zeroed by the game.
|
|
||||||
uint8_t type;
|
|
||||||
|
|
||||||
xe::be<uint32_t> unk_1c;
|
|
||||||
// TODO(sabretooth): not sure if this is a union, but it seems likely.
|
|
||||||
// Haven't run into cases other than "binary data" yet.
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
xe::be<uint32_t> length;
|
|
||||||
xe::be<uint32_t> ptr;
|
|
||||||
} binary;
|
|
||||||
};
|
|
||||||
} X_USER_WRITE_PROFILE_SETTING;
|
|
||||||
|
|
||||||
dword_result_t XamUserWriteProfileSettings_entry(
|
dword_result_t XamUserWriteProfileSettings_entry(
|
||||||
dword_t title_id, dword_t user_index, dword_t setting_count,
|
dword_t title_id, dword_t user_index, dword_t setting_count,
|
||||||
pointer_t<X_USER_WRITE_PROFILE_SETTING> settings, dword_t overlapped_ptr) {
|
pointer_t<X_USER_PROFILE_SETTING> settings,
|
||||||
|
pointer_t<XAM_OVERLAPPED> overlapped) {
|
||||||
if (!setting_count || !settings) {
|
if (!setting_count || !settings) {
|
||||||
return X_ERROR_INVALID_PARAMETER;
|
return X_ERROR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user_index) {
|
if (user_index) {
|
||||||
// Only support user 0.
|
// Only support user 0.
|
||||||
if (overlapped_ptr) {
|
if (overlapped) {
|
||||||
kernel_state()->CompleteOverlappedImmediate(overlapped_ptr,
|
kernel_state()->CompleteOverlappedImmediate(overlapped,
|
||||||
X_ERROR_NO_SUCH_USER);
|
X_ERROR_NO_SUCH_USER);
|
||||||
return X_ERROR_IO_PENDING;
|
return X_ERROR_IO_PENDING;
|
||||||
}
|
}
|
||||||
|
|
@ -369,39 +339,39 @@ dword_result_t XamUserWriteProfileSettings_entry(
|
||||||
const auto& user_profile = kernel_state()->user_profile();
|
const auto& user_profile = kernel_state()->user_profile();
|
||||||
|
|
||||||
for (uint32_t n = 0; n < setting_count; ++n) {
|
for (uint32_t n = 0; n < setting_count; ++n) {
|
||||||
const X_USER_WRITE_PROFILE_SETTING& settings_data = settings[n];
|
const X_USER_PROFILE_SETTING& setting = settings[n];
|
||||||
|
|
||||||
|
auto setting_type =
|
||||||
|
static_cast<UserProfile::Setting::Type>(setting.data.type);
|
||||||
|
if (setting_type == UserProfile::Setting::Type::UNSET) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
XELOGD(
|
XELOGD(
|
||||||
"XamUserWriteProfileSettings: setting index [{}]:"
|
"XamUserWriteProfileSettings: setting index [{}]:"
|
||||||
" from={} setting_id={:08X} data.type={}",
|
" from={} setting_id={:08X} data.type={}",
|
||||||
n, (uint32_t)settings_data.from, (uint32_t)settings_data.setting_id,
|
n, (uint32_t)setting.from, (uint32_t)setting.setting_id,
|
||||||
settings_data.type);
|
setting.data.type);
|
||||||
|
|
||||||
xam::UserProfile::Setting::Type settingType =
|
switch (setting_type) {
|
||||||
static_cast<xam::UserProfile::Setting::Type>(settings_data.type);
|
|
||||||
|
|
||||||
switch (settingType) {
|
|
||||||
case UserProfile::Setting::Type::CONTENT:
|
case UserProfile::Setting::Type::CONTENT:
|
||||||
case UserProfile::Setting::Type::BINARY: {
|
case UserProfile::Setting::Type::BINARY: {
|
||||||
uint8_t* settings_data_ptr = kernel_state()->memory()->TranslateVirtual(
|
uint8_t* binary_ptr =
|
||||||
settings_data.binary.ptr);
|
kernel_state()->memory()->TranslateVirtual(setting.data.binary.ptr);
|
||||||
size_t settings_data_len = settings_data.binary.length;
|
size_t binary_size = setting.data.binary.size;
|
||||||
std::vector<uint8_t> data_vec;
|
std::vector<uint8_t> bytes;
|
||||||
|
if (setting.data.binary.ptr) {
|
||||||
if (settings_data.binary.ptr) {
|
|
||||||
// Copy provided data
|
// Copy provided data
|
||||||
data_vec.resize(settings_data_len);
|
bytes.resize(binary_size);
|
||||||
std::memcpy(data_vec.data(), settings_data_ptr, settings_data_len);
|
std::memcpy(bytes.data(), binary_ptr, binary_size);
|
||||||
} else {
|
} else {
|
||||||
// Data pointer was NULL, so just fill with zeroes
|
// Data pointer was NULL, so just fill with zeroes
|
||||||
data_vec.resize(settings_data_len, 0);
|
bytes.resize(binary_size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_profile->AddSetting(
|
user_profile->AddSetting(
|
||||||
std::make_unique<xam::UserProfile::BinarySetting>(
|
std::make_unique<xam::UserProfile::BinarySetting>(
|
||||||
settings_data.setting_id, data_vec));
|
setting.setting_id, bytes));
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UserProfile::Setting::Type::WSTRING:
|
case UserProfile::Setting::Type::WSTRING:
|
||||||
case UserProfile::Setting::Type::DOUBLE:
|
case UserProfile::Setting::Type::DOUBLE:
|
||||||
case UserProfile::Setting::Type::FLOAT:
|
case UserProfile::Setting::Type::FLOAT:
|
||||||
|
|
@ -410,14 +380,13 @@ dword_result_t XamUserWriteProfileSettings_entry(
|
||||||
case UserProfile::Setting::Type::DATETIME:
|
case UserProfile::Setting::Type::DATETIME:
|
||||||
default: {
|
default: {
|
||||||
XELOGE("XamUserWriteProfileSettings: Unimplemented data type {}",
|
XELOGE("XamUserWriteProfileSettings: Unimplemented data type {}",
|
||||||
settingType);
|
setting_type);
|
||||||
} break;
|
} break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overlapped_ptr) {
|
if (overlapped) {
|
||||||
kernel_state()->CompleteOverlappedImmediate(overlapped_ptr,
|
kernel_state()->CompleteOverlappedImmediate(overlapped, X_ERROR_SUCCESS);
|
||||||
X_ERROR_SUCCESS);
|
|
||||||
return X_ERROR_IO_PENDING;
|
return X_ERROR_IO_PENDING;
|
||||||
}
|
}
|
||||||
return X_ERROR_SUCCESS;
|
return X_ERROR_SUCCESS;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue