Allow XamUserReadProfileSettings to use xuid to define profile

This commit is contained in:
Gliniak
2022-04-15 09:28:42 +02:00
parent 84e5b159c3
commit dde8adc140
4 changed files with 42 additions and 10 deletions

View File

@@ -960,7 +960,7 @@ uint8_t KernelState::GetConnectedUsers() const {
void KernelState::UpdateUsedUserProfiles() { void KernelState::UpdateUsedUserProfiles() {
const uint8_t used_slots_bitmask = GetConnectedUsers(); const uint8_t used_slots_bitmask = GetConnectedUsers();
for (uint8_t i = 1; i < 4; i++) { for (uint32_t i = 1; i < 4; i++) {
bool is_used = used_slots_bitmask & (1 << i); bool is_used = used_slots_bitmask & (1 << i);
if (IsUserSignedIn(i) && !is_used) { if (IsUserSignedIn(i) && !is_used) {

View File

@@ -108,14 +108,31 @@ class KernelState {
uint8_t GetConnectedUsers() const; uint8_t GetConnectedUsers() const;
void UpdateUsedUserProfiles(); void UpdateUsedUserProfiles();
bool IsUserSignedIn(uint8_t index) const { bool IsUserSignedIn(uint32_t index) const {
return user_profiles_.find(index) != user_profiles_.cend(); return user_profiles_.find(index) != user_profiles_.cend();
} }
xam::UserProfile* user_profile(uint8_t index) const { bool IsUserSignedIn(uint64_t xuid) const {
return user_profile(xuid) != nullptr;
}
xam::UserProfile* user_profile(uint32_t index) const {
if (!IsUserSignedIn(index)) {
return nullptr;
}
return user_profiles_.at(index).get(); return user_profiles_.at(index).get();
} }
xam::UserProfile* user_profile(uint64_t xuid) const {
for (const auto& [key, value] : user_profiles_) {
if (value->xuid() == xuid) {
return user_profiles_.at(key).get();
}
}
return nullptr;
}
// Access must be guarded by the global critical region. // Access must be guarded by the global critical region.
util::ObjectTable* object_table() { return &object_table_; } util::ObjectTable* object_table() { return &object_table_; }

View File

@@ -321,7 +321,8 @@ X_RESULT ContentManager::DeleteContent(const XCONTENT_AGGREGATE_DATA& data) {
std::filesystem::path ContentManager::ResolveGameUserContentPath() { std::filesystem::path ContentManager::ResolveGameUserContentPath() {
auto title_id = fmt::format("{:08X}", kernel_state_->title_id()); auto title_id = fmt::format("{:08X}", kernel_state_->title_id());
auto user_name = xe::to_path(kernel_state_->user_profile(0)->name()); auto user_name =
xe::to_path(kernel_state_->user_profile(uint32_t(0))->name());
// Per-game per-profile data location: // Per-game per-profile data location:
// content_root/title_id/profile/user_name // content_root/title_id/profile/user_name

View File

@@ -224,17 +224,31 @@ uint32_t XamUserReadProfileSettingsEx(uint32_t title_id, uint32_t user_index,
// Title ID = 0 means us. // Title ID = 0 means us.
// 0xfffe07d1 = profile? // 0xfffe07d1 = profile?
if (!kernel_state()->IsUserSignedIn(user_index)) { if (!kernel_state()->IsUserSignedIn(user_index) && !xuids) {
if (overlapped) { if (overlapped) {
kernel_state()->CompleteOverlappedImmediate( kernel_state()->CompleteOverlappedImmediate(
kernel_state()->memory()->HostToGuestVirtual(overlapped), kernel_state()->memory()->HostToGuestVirtual(overlapped),
X_ERROR_NO_SUCH_USER); 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;
} }
const auto& user_profile = kernel_state()->user_profile(user_index); auto user_profile = kernel_state()->user_profile(user_index);
if (xuids) {
uint64_t user_xuid = static_cast<uint64_t>(xuids[0]);
if (!kernel_state()->IsUserSignedIn(user_xuid)) {
if (overlapped) {
kernel_state()->CompleteOverlappedImmediate(
kernel_state()->memory()->HostToGuestVirtual(overlapped),
X_ERROR_NO_SUCH_USER);
return X_ERROR_IO_PENDING;
}
return X_ERROR_NO_SUCH_USER;
}
user_profile = kernel_state()->user_profile(user_xuid);
}
// First call asks for size (fill buffer_size_ptr). // First call asks for size (fill buffer_size_ptr).
// Second call asks for buffer contents with that size. // Second call asks for buffer contents with that size.
@@ -529,7 +543,7 @@ dword_result_t XamShowSigninUI_entry(dword_t unk, dword_t unk_mask) {
// Mask values vary. Probably matching user types? Local/remote? // Mask values vary. Probably matching user types? Local/remote?
// Games seem to sit and loop until we trigger this notification: // Games seem to sit and loop until we trigger this notification:
for (uint8_t i = 0; i < 4; i++) { for (uint32_t i = 0; i < 4; i++) {
if (kernel_state()->IsUserSignedIn(i)) { if (kernel_state()->IsUserSignedIn(i)) {
// XN_SYS_SIGNINCHANGED // XN_SYS_SIGNINCHANGED
kernel_state()->BroadcastNotification(0xA, i); kernel_state()->BroadcastNotification(0xA, i);