mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 13:18:37 +00:00
xgameruntime: serve XUserImpl (offline local user) through QueryApiImpl
A GDK title links the XUser* functions statically (xgameruntime.lib); each thunk asks QueryApiImpl for XUserImpl and calls one slot with the function's arguments after `this` (docs/runtime_imports.md). QueryApiImpl refused the class, so XUserAddAsync, the call a title makes at boot before nearly anything else, could not succeed. runtime/shims/xgameruntime_user.cpp serves it, in its own file so the other class PRs touching xgameruntime.cpp only meet it at one line: - ids and slot order from xgameruntime-docs (facts only), signatures, enum values and E_GAMEUSER_* codes from the public GDK reference; - IXUserImpl..IXUserImpl6 answer with one 50-slot vtable, IXUserGamertagImpl (XUserGetGamertag) with a second; - one offline user, always signed in: XUserAddAsync (silent or not; AllowGuests with AddDefaultUserSilently is E_INVALIDARG), fixed ids, FindUserById/ByLocalId, Duplicate/Close/Compare, not a guest, adult, every privilege, ResolvePrivilegeWithUi, AddByIdWithUi, IsStoreUser, change-event tokens; gamertag from LEONIDA_GAMERTAG, "Player" otherwise; - tokens, gamer picture, MSA tokens and resolve-issue fail synchronously before starting; no sign-out deferral; private and PC-only slots log once. xgameruntime_user_test (40 checks) drives every served slot; a second ctest run checks LEONIDA_GAMERTAG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -154,7 +154,8 @@ pseudo-handle, and `GetProcAddress` on it resolves through the registry. A name
|
||||
with `ERROR_PROC_NOT_FOUND` and is logged once. Every other module goes to the host unchanged.
|
||||
|
||||
`runtime/shims/xgameruntime.cpp` serves the five entry points. The initializers succeed offline and log the GDK
|
||||
version and mode once. `QueryApiImpl` serves `XThreadingImpl` and `XErrorImpl` (below); for any other class it logs
|
||||
version and mode once. `QueryApiImpl` serves `XThreadingImpl` and `XErrorImpl` (below), and `XUserImpl` from xgameruntime-docs' layout
|
||||
(below); for any other class it logs
|
||||
the class and interface id and returns `0x80070032`, the documented error for a class the runtime doesn't provide, so
|
||||
the first boot with the executable lists the classes to implement next. `xgameruntime_test` drives this path through
|
||||
the api-set binding `XCurl.dll` uses, and calls the two classes slot by slot.
|
||||
@ -196,6 +197,26 @@ connectivity (level None), the port and URL security-information queries fail wi
|
||||
certificate check fails the same way, change registrations return tokens that never fire, and the three
|
||||
`IXNetworkingImpl2` additions are `E_NOTIMPL`.
|
||||
|
||||
`XUserImpl` (`runtime/shims/xgameruntime_user.cpp`) is served from xgameruntime-docs' layout alone. No package DLL
|
||||
calls an `XUser*` slot (`libHttpClient.GDK.dll` only holds the GUID table), so its slots are **not measured** yet.
|
||||
The executable's first boot confirms them, or names the slots that differ.
|
||||
- **Interfaces:** the class id doubles as `IXUserImpl`'s; `IXUserImpl2`-`6` answer with the same 50-slot vtable;
|
||||
`IXUserGamertagImpl` (`XUserGetGamertag`) is a second interface.
|
||||
- **The user:** one offline local user, always signed in. `XUserAddAsync` adds it with or without
|
||||
`AddDefaultUserSilently` (with `AllowGuests` as well, it's `E_INVALIDARG`, as documented). It has fixed non-zero user
|
||||
and local ids, is not a guest, is an adult, and has every privilege. Its gamertag comes from `LEONIDA_GAMERTAG` (15
|
||||
printable ASCII characters at most), `Player` otherwise.
|
||||
- **Handles:** each one is its own allocation, closed once by `XUserCloseHandle`. `XUserCompare` is 0 for any two
|
||||
handles, since they all name the one user.
|
||||
- **Not available offline:** token, gamer-picture, MSA-token and resolve-issue requests fail synchronously before
|
||||
starting (`E_GAMEUSER_FAILED_TO_GET_TOKEN`, `E_FAIL`, `E_GAMEUSER_FAILED_TO_RESOLVE`), so no `XAsyncBlock` waits.
|
||||
`XUserGetSignOutDeferral` is `E_GAMEUSER_DEFERRAL_NOT_AVAILABLE`, and change callbacks are only tracked as tokens,
|
||||
because the user never changes.
|
||||
- **Logged on first use:** the docs' unknown slot 15, the PC-only `IXUserImpl5` slots and `IXUserImpl6`'s
|
||||
undocumented sign-out trio.
|
||||
|
||||
`xgameruntime_user_test` calls every served slot with the documented arguments.
|
||||
|
||||
Which classes the package's GDK modules reference, from a byte search for the class and interface GUIDs that
|
||||
xgameruntime-docs lists (16-byte in-memory form, every `.dll` of the package; counts only, nothing else read):
|
||||
|
||||
|
||||
@ -97,6 +97,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)
|
||||
shims/d3d12_xs.cpp
|
||||
shims/d3d12_xs_device.cpp
|
||||
shims/xgameruntime.cpp
|
||||
shims/xgameruntime_user.cpp
|
||||
shims/library_loader.cpp
|
||||
shims/process.cpp
|
||||
)
|
||||
@ -226,6 +227,7 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)
|
||||
add_executable(xgameruntime_test
|
||||
test/xgameruntime_test.cpp
|
||||
shims/xgameruntime.cpp
|
||||
shims/xgameruntime_user.cpp
|
||||
shims/library_loader.cpp
|
||||
shims/registry.cpp
|
||||
)
|
||||
@ -235,6 +237,20 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME)
|
||||
target_link_options(xgameruntime_test PRIVATE /OPT:NOREF)
|
||||
target_link_libraries(xgameruntime_test PRIVATE gta6rt_xtaskqueue)
|
||||
|
||||
# XUserImpl (offline local user) through QueryApiImpl, slot by slot as xgameruntime.lib's thunks call it.
|
||||
add_executable(xgameruntime_user_test
|
||||
test/xgameruntime_user_test.cpp
|
||||
shims/xgameruntime.cpp
|
||||
shims/xgameruntime_user.cpp
|
||||
shims/library_loader.cpp
|
||||
shims/registry.cpp
|
||||
)
|
||||
target_include_directories(xgameruntime_user_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shims)
|
||||
target_compile_definitions(xgameruntime_user_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
|
||||
target_compile_options(xgameruntime_user_test PRIVATE /W4 /permissive- /utf-8)
|
||||
target_link_options(xgameruntime_user_test PRIVATE /OPT:NOREF)
|
||||
target_link_libraries(xgameruntime_user_test PRIVATE gta6rt_xtaskqueue)
|
||||
|
||||
# GameInput shim on SDL3 (zlib licence): any controller SDL supports, DualSense trigger effects and lightbar.
|
||||
# Nothing is downloaded unless asked. The shim is built when SDL3 is available:
|
||||
# - an installed SDL3 3.2+ that find_package finds (SDL3_DIR / CMAKE_PREFIX_PATH), or
|
||||
@ -714,6 +730,9 @@ if(BUILD_TESTING)
|
||||
endif()
|
||||
if(WIN32 AND TARGET xgameruntime_test)
|
||||
add_test(NAME xgameruntime COMMAND xgameruntime_test)
|
||||
add_test(NAME xgameruntime_user COMMAND xgameruntime_user_test)
|
||||
add_test(NAME xgameruntime_user_gamertag COMMAND xgameruntime_user_test --expect-gamertag Tester42)
|
||||
set_tests_properties(xgameruntime_user_gamertag PROPERTIES ENVIRONMENT "LEONIDA_GAMERTAG=Tester42")
|
||||
endif()
|
||||
if(WIN32 AND TARGET gameinput_test)
|
||||
add_test(NAME gameinput COMMAND gameinput_test)
|
||||
|
||||
@ -27,6 +27,10 @@
|
||||
|
||||
#include "shims.h"
|
||||
|
||||
namespace rt::shims {
|
||||
bool xgameruntime_user_query(const GUID& class_id, REFIID interface_id, void** out, HRESULT* hr);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// ---- XGameRuntime ----
|
||||
@ -346,6 +350,8 @@ HRESULT WINAPI QueryApiImpl(const GUID* class_id, REFIID interface_id, void** ou
|
||||
if (class_id && out) {
|
||||
for (RuntimeObject* o : {&g_threading, &g_error, &g_networking, &system_object()})
|
||||
if (*class_id == *o->class_id) return object_query_interface(o, interface_id, out);
|
||||
HRESULT hr = S_OK;
|
||||
if (rt::shims::xgameruntime_user_query(*class_id, interface_id, out, &hr)) return hr; // xgameruntime_user.cpp
|
||||
}
|
||||
char cls[40], iid[40];
|
||||
print_guid(cls, class_id);
|
||||
|
||||
515
runtime/shims/xgameruntime_user.cpp
Normal file
515
runtime/shims/xgameruntime_user.cpp
Normal file
@ -0,0 +1,515 @@
|
||||
// xgameruntime: XUserImpl, the class xgameruntime.lib's XUser* functions reach through QueryApiImpl, offline.
|
||||
//
|
||||
// A GDK title links XUserAddAsync, XUserGetId, XUserGetGamertag and the rest statically (xgameruntime.lib); each of
|
||||
// those thunks asks QueryApiImpl for XUserImpl and calls one slot with the function's own arguments after `this`
|
||||
// (docs/runtime_imports.md, "Run-time loaded modules"; xgameruntime.cpp serves the other classes the same way).
|
||||
// The class and interface ids and the slot order are xodus-gaming/xgameruntime-docs' "Layout" lists (GPL-3.0; facts
|
||||
// only, nothing copied). Signatures, enum values and error codes follow Microsoft's public GDK reference
|
||||
// (learn.microsoft.com/gaming/gdk, XUser and Error Codes pages). No GDK header or library code is used.
|
||||
//
|
||||
// Offline there is one local user, always signed in: the default user XUserAddAsync returns (with or without
|
||||
// AddDefaultUserSilently), with a fixed Xbox user id and local id, and a gamertag from LEONIDA_GAMERTAG (15 ASCII
|
||||
// characters at most, "Player" otherwise). Nothing goes online: token and gamer-picture requests fail as they would
|
||||
// without a network, and the user never changes, so registered change callbacks are never called.
|
||||
//
|
||||
// ASSUMPTION: the console executable is not available, so which of these slots it calls is unknown until its first
|
||||
// boot. Private and PC-only slots log once when called, so that boot lists them.
|
||||
#include <windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
#include <XAsync.h>
|
||||
#include <XAsyncProvider.h>
|
||||
#include <XTaskQueue.h>
|
||||
|
||||
namespace {
|
||||
|
||||
// ---- Public GDK types (XUser.h, as the GDK reference documents them) ----
|
||||
|
||||
using XUserHandle = struct XUserLocal*; // opaque to the title
|
||||
using XUserSignOutDeferralHandle = struct XUserSignOutDeferral*;
|
||||
struct XUserLocalId {
|
||||
uint64_t value;
|
||||
};
|
||||
enum class XUserAddOptions : uint32_t { None = 0x00, AddDefaultUserSilently = 0x01, AllowGuests = 0x02, AddDefaultUserAllowingUI = 0x04 };
|
||||
enum class XUserState : uint32_t { SignedIn = 0, SigningOut = 1, SignedOut = 2 };
|
||||
enum class XUserAgeGroup : uint32_t { Unknown = 0, Child = 1, Teen = 2, Adult = 3 };
|
||||
enum class XUserGamertagComponent : uint32_t { Classic = 0, Modern = 1, ModernSuffix = 2, UniqueModern = 3 };
|
||||
enum class XUserPrivilegeDenyReason : uint32_t { None = 0 };
|
||||
enum class XUserChangeEvent : uint32_t { SignedInAgain = 0 };
|
||||
using XUserChangeEventCallback = void(CALLBACK*)(void* context, XUserLocalId user, XUserChangeEvent event);
|
||||
|
||||
// XGameErr.h values, from the GDK "Error codes" page.
|
||||
constexpr HRESULT E_GAMEUSER_USER_NOT_FOUND = static_cast<HRESULT>(0x89245104);
|
||||
constexpr HRESULT E_GAMEUSER_DEFERRAL_NOT_AVAILABLE = static_cast<HRESULT>(0x89245103);
|
||||
constexpr HRESULT E_GAMEUSER_FAILED_TO_RESOLVE = static_cast<HRESULT>(0x89245107);
|
||||
constexpr HRESULT E_GAMEUSER_FAILED_TO_GET_TOKEN = static_cast<HRESULT>(0x89245111);
|
||||
constexpr HRESULT kInsufficientBuffer = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
|
||||
|
||||
// ---- The offline user ----
|
||||
|
||||
// Fixed, non-zero ids. The Xbox user id has the shape of a real XUID (a 64-bit number); nothing checks it offline.
|
||||
constexpr uint64_t kOfflineXuid = 0x0009000000000001ull;
|
||||
constexpr uint64_t kOfflineLocalId = 1;
|
||||
|
||||
const char* gamertag() {
|
||||
static char tag[16] = "Player";
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] {
|
||||
char value[64] = {};
|
||||
size_t length = 0;
|
||||
if (getenv_s(&length, value, "LEONIDA_GAMERTAG") != 0 || length <= 1) return;
|
||||
if (length - 1 > 15) {
|
||||
std::fprintf(stderr, "[rt] xgameruntime: LEONIDA_GAMERTAG is longer than 15 characters; using \"Player\"\n");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i + 1 < length; ++i)
|
||||
if (static_cast<unsigned char>(value[i]) < 0x20 || static_cast<unsigned char>(value[i]) > 0x7e) {
|
||||
std::fprintf(stderr, "[rt] xgameruntime: LEONIDA_GAMERTAG is not printable ASCII; using \"Player\"\n");
|
||||
return;
|
||||
}
|
||||
std::memcpy(tag, value, length);
|
||||
});
|
||||
return tag;
|
||||
}
|
||||
|
||||
// A title must close every XUserHandle it gets exactly once, so each one is its own allocation; they all name the
|
||||
// one local user. The magic tells a live handle from a closed or foreign pointer.
|
||||
struct XUserLocal {
|
||||
uint32_t magic;
|
||||
};
|
||||
constexpr uint32_t kHandleMagic = 0x52535558; // "XUSR"
|
||||
constexpr uint32_t kClosedMagic = 0x44534c43; // "CLSD"
|
||||
std::atomic<long> g_open_handles{0};
|
||||
|
||||
XUserHandle new_handle() {
|
||||
auto* h = new XUserLocal{kHandleMagic};
|
||||
g_open_handles.fetch_add(1);
|
||||
return h;
|
||||
}
|
||||
bool valid(XUserHandle h) { return h && h->magic == kHandleMagic; }
|
||||
|
||||
// ---- IXUserImpl (slots 3-36) ----
|
||||
|
||||
// 3: HRESULT XUserDuplicateHandle(XUserHandle handle, XUserHandle* duplicatedHandle)
|
||||
HRESULT STDMETHODCALLTYPE user_duplicate(void*, XUserHandle handle, XUserHandle* dup) {
|
||||
if (!dup) return E_POINTER;
|
||||
*dup = nullptr;
|
||||
if (!valid(handle)) return E_INVALIDARG;
|
||||
*dup = new_handle();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 4: void XUserCloseHandle(XUserHandle user)
|
||||
void STDMETHODCALLTYPE user_close(void*, XUserHandle user) {
|
||||
if (!valid(user)) return;
|
||||
user->magic = kClosedMagic;
|
||||
g_open_handles.fetch_sub(1);
|
||||
delete user;
|
||||
}
|
||||
|
||||
// 5: int32_t XUserCompare(XUserHandle user1, XUserHandle user2): 0 when both name the same user. Every valid handle
|
||||
// names the one local user.
|
||||
int32_t STDMETHODCALLTYPE user_compare(void*, XUserHandle a, XUserHandle b) {
|
||||
const bool va = valid(a), vb = valid(b);
|
||||
if (va && vb) return 0;
|
||||
if (va != vb) return va ? 1 : -1;
|
||||
return a == b ? 0 : (a < b ? -1 : 1);
|
||||
}
|
||||
|
||||
// 6: HRESULT XUserGetMaxUsers(uint32_t* maxUsers). One local user offline.
|
||||
HRESULT STDMETHODCALLTYPE user_get_max_users(void*, uint32_t* max_users) {
|
||||
if (!max_users) return E_POINTER;
|
||||
*max_users = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// XAsync providers. The result of an add is a new handle, created when the title collects it, so a result the
|
||||
// title never collects leaks nothing.
|
||||
const char kAddIdentity = 0;
|
||||
const char kAddByIdIdentity = 0;
|
||||
const char kResolveIdentity = 0;
|
||||
|
||||
HRESULT CALLBACK add_provider(XAsyncOp op, const XAsyncProviderData* data) {
|
||||
switch (op) {
|
||||
case XAsyncOp::Begin:
|
||||
return XAsyncSchedule(data->async, 0);
|
||||
case XAsyncOp::DoWork:
|
||||
XAsyncComplete(data->async, S_OK, sizeof(XUserHandle));
|
||||
return S_OK;
|
||||
case XAsyncOp::GetResult:
|
||||
if (data->bufferSize < sizeof(XUserHandle) || !data->buffer) return E_INVALIDARG;
|
||||
*static_cast<XUserHandle*>(data->buffer) = new_handle();
|
||||
return S_OK;
|
||||
default:
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// The add-by-id flavour: the context is the requested id; an id other than the local user's completes with
|
||||
// E_GAMEUSER_USER_NOT_FOUND (no other user can sign in offline).
|
||||
HRESULT CALLBACK add_by_id_provider(XAsyncOp op, const XAsyncProviderData* data) {
|
||||
switch (op) {
|
||||
case XAsyncOp::Begin:
|
||||
return XAsyncSchedule(data->async, 0);
|
||||
case XAsyncOp::DoWork: {
|
||||
const bool known = reinterpret_cast<uintptr_t>(data->context) == static_cast<uintptr_t>(kOfflineXuid);
|
||||
XAsyncComplete(data->async, known ? S_OK : E_GAMEUSER_USER_NOT_FOUND, known ? sizeof(XUserHandle) : 0);
|
||||
return S_OK;
|
||||
}
|
||||
case XAsyncOp::GetResult:
|
||||
if (data->bufferSize < sizeof(XUserHandle) || !data->buffer) return E_INVALIDARG;
|
||||
*static_cast<XUserHandle*>(data->buffer) = new_handle();
|
||||
return S_OK;
|
||||
default:
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Resolving a privilege: every privilege is granted offline, so there is nothing to show; completes with S_OK.
|
||||
HRESULT CALLBACK resolve_provider(XAsyncOp op, const XAsyncProviderData* data) {
|
||||
if (op == XAsyncOp::Begin) return XAsyncSchedule(data->async, 0);
|
||||
if (op == XAsyncOp::DoWork) XAsyncComplete(data->async, S_OK, 0);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 7: HRESULT XUserAddAsync(XUserAddOptions options, XAsyncBlock* async). AllowGuests with AddDefaultUserSilently is
|
||||
// refused, as documented ("A guest cannot be the default user"). Without a silent option the console would show the
|
||||
// account picker; offline the one user is the answer either way.
|
||||
HRESULT STDMETHODCALLTYPE user_add_async(void*, XUserAddOptions options, XAsyncBlock* async) {
|
||||
if (!async) return E_POINTER;
|
||||
const auto bits = static_cast<uint32_t>(options);
|
||||
if ((bits & static_cast<uint32_t>(XUserAddOptions::AddDefaultUserSilently)) &&
|
||||
(bits & static_cast<uint32_t>(XUserAddOptions::AllowGuests)))
|
||||
return E_INVALIDARG;
|
||||
return XAsyncBegin(async, nullptr, &kAddIdentity, "XUserAddAsync", add_provider);
|
||||
}
|
||||
|
||||
// 8: HRESULT XUserAddResult(XAsyncBlock* async, XUserHandle* newUser)
|
||||
HRESULT STDMETHODCALLTYPE user_add_result(void*, XAsyncBlock* async, XUserHandle* user) {
|
||||
if (!user) return E_POINTER;
|
||||
*user = nullptr;
|
||||
return XAsyncGetResult(async, &kAddIdentity, sizeof(*user), user, nullptr);
|
||||
}
|
||||
|
||||
// 9: HRESULT XUserGetLocalId(XUserHandle user, XUserLocalId* userLocalId)
|
||||
HRESULT STDMETHODCALLTYPE user_get_local_id(void*, XUserHandle user, XUserLocalId* id) {
|
||||
if (!id) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
id->value = kOfflineLocalId;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 10: HRESULT XUserFindUserByLocalId(XUserLocalId userLocalId, XUserHandle* handle)
|
||||
HRESULT STDMETHODCALLTYPE user_find_by_local_id(void*, XUserLocalId id, XUserHandle* handle) {
|
||||
if (!handle) return E_POINTER;
|
||||
*handle = nullptr;
|
||||
if (id.value != kOfflineLocalId) return E_GAMEUSER_USER_NOT_FOUND;
|
||||
*handle = new_handle();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 11: HRESULT XUserGetId(XUserHandle user, uint64_t* userId)
|
||||
HRESULT STDMETHODCALLTYPE user_get_id(void*, XUserHandle user, uint64_t* id) {
|
||||
if (!id) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
*id = kOfflineXuid;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 12: HRESULT XUserFindUserById(uint64_t userId, XUserHandle* handle)
|
||||
HRESULT STDMETHODCALLTYPE user_find_by_id(void*, uint64_t id, XUserHandle* handle) {
|
||||
if (!handle) return E_POINTER;
|
||||
*handle = nullptr;
|
||||
if (id != kOfflineXuid) return E_GAMEUSER_USER_NOT_FOUND;
|
||||
*handle = new_handle();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 13: HRESULT XUserGetIsGuest(XUserHandle user, bool* isGuest)
|
||||
HRESULT STDMETHODCALLTYPE user_get_is_guest(void*, XUserHandle user, bool* guest) {
|
||||
if (!guest) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
*guest = false;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 14: HRESULT XUserGetState(XUserHandle user, XUserState* state)
|
||||
HRESULT STDMETHODCALLTYPE user_get_state(void*, XUserHandle user, XUserState* state) {
|
||||
if (!state) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
*state = XUserState::SignedIn;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// A slot with no public signature (15 is the docs' "unknown"; 47-49 are IXUserImpl6's undocumented sign-out trio):
|
||||
// logged once, answers 0 (S_OK / false).
|
||||
template <int Slot> uint64_t STDMETHODCALLTYPE private_slot(void*) {
|
||||
static std::atomic<bool> s_logged{false};
|
||||
if (!s_logged.exchange(true))
|
||||
std::fprintf(stderr, "[rt] xgameruntime: XUserImpl private slot %d called; answering 0\n", Slot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// An operation that needs the network or a system UI the offline runtime doesn't have. The *Async function fails
|
||||
// before starting, so the XAsyncBlock is never used and no callback runs; its Result/ResultSize partners return the
|
||||
// same error. Their arguments don't matter, so the functions take none (x64: the caller owns the argument area).
|
||||
template <int Slot, HRESULT Error> HRESULT STDMETHODCALLTYPE offline_failure(void*) {
|
||||
static std::atomic<bool> s_logged{false};
|
||||
if (!s_logged.exchange(true))
|
||||
std::fprintf(stderr, "[rt] xgameruntime: XUserImpl slot %d is not available offline (HRESULT 0x%08lx)\n", Slot,
|
||||
static_cast<unsigned long>(Error));
|
||||
return Error;
|
||||
}
|
||||
|
||||
// 19: HRESULT XUserGetAgeGroup(XUserHandle user, XUserAgeGroup* ageGroup)
|
||||
HRESULT STDMETHODCALLTYPE user_get_age_group(void*, XUserHandle user, XUserAgeGroup* group) {
|
||||
if (!group) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
*group = XUserAgeGroup::Adult;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 20: HRESULT XUserCheckPrivilege(XUserHandle user, XUserPrivilegeOptions options, XUserPrivilege privilege,
|
||||
// bool* hasPrivilege, XUserPrivilegeDenyReason* reason). Everything is allowed offline
|
||||
// (multiplayer and the like then fail at the network, as on a console without one).
|
||||
HRESULT STDMETHODCALLTYPE user_check_privilege(void*, XUserHandle user, uint32_t, uint32_t, bool* has,
|
||||
XUserPrivilegeDenyReason* reason) {
|
||||
if (!has) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
*has = true;
|
||||
if (reason) *reason = XUserPrivilegeDenyReason::None;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// 21: HRESULT XUserResolvePrivilegeWithUiAsync(XUserHandle user, XUserPrivilegeOptions options, XUserPrivilege privilege,
|
||||
// XAsyncBlock* async)
|
||||
HRESULT STDMETHODCALLTYPE user_resolve_privilege_async(void*, XUserHandle user, uint32_t, uint32_t, XAsyncBlock* async) {
|
||||
if (!async) return E_POINTER;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
return XAsyncBegin(async, nullptr, &kResolveIdentity, "XUserResolvePrivilegeWithUiAsync", resolve_provider);
|
||||
}
|
||||
|
||||
// 22: HRESULT XUserResolvePrivilegeWithUiResult(XAsyncBlock* async)
|
||||
HRESULT STDMETHODCALLTYPE user_resolve_privilege_result(void*, XAsyncBlock* async) {
|
||||
return XAsyncGetResult(async, &kResolveIdentity, 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
// 33: HRESULT XUserRegisterForChangeEvent(XTaskQueueHandle queue, void* context, XUserChangeEventCallback* callback,
|
||||
// XTaskQueueRegistrationToken* token)
|
||||
// 34: bool XUserUnregisterForChangeEvent(XTaskQueueRegistrationToken token, bool wait)
|
||||
// The user never changes offline, so the callbacks are kept only as tokens.
|
||||
std::mutex g_tokens_mutex;
|
||||
std::set<uint64_t> g_tokens;
|
||||
uint64_t g_next_token = 1;
|
||||
|
||||
HRESULT STDMETHODCALLTYPE user_register_change(void*, XTaskQueueHandle, void*, XUserChangeEventCallback callback,
|
||||
XTaskQueueRegistrationToken* token) {
|
||||
if (!callback || !token) return E_POINTER;
|
||||
std::lock_guard<std::mutex> lock(g_tokens_mutex);
|
||||
token->token = g_next_token++;
|
||||
g_tokens.insert(token->token);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
bool STDMETHODCALLTYPE user_unregister_change(void*, XTaskQueueRegistrationToken token, bool) {
|
||||
std::lock_guard<std::mutex> lock(g_tokens_mutex);
|
||||
return g_tokens.erase(token.token) != 0;
|
||||
}
|
||||
|
||||
// 35: HRESULT XUserGetSignOutDeferral(XUserSignOutDeferralHandle* deferral): nothing signs out offline, so there is
|
||||
// no sign-out to defer (the documented E_GAMEUSER_DEFERRAL_NOT_AVAILABLE).
|
||||
HRESULT STDMETHODCALLTYPE user_get_signout_deferral(void*, XUserSignOutDeferralHandle* deferral) {
|
||||
if (deferral) *deferral = nullptr;
|
||||
return E_GAMEUSER_DEFERRAL_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
// 36: void XUserCloseSignOutDeferralHandle(XUserSignOutDeferralHandle deferral)
|
||||
void STDMETHODCALLTYPE user_close_signout_deferral(void*, XUserSignOutDeferralHandle) {}
|
||||
|
||||
// ---- IXUserImpl2 (37-38) ----
|
||||
|
||||
// 37: HRESULT XUserAddByIdWithUiAsync(uint64_t userId, XAsyncBlock* async)
|
||||
HRESULT STDMETHODCALLTYPE user_add_by_id_async(void*, uint64_t id, XAsyncBlock* async) {
|
||||
if (!async) return E_POINTER;
|
||||
return XAsyncBegin(async, reinterpret_cast<void*>(static_cast<uintptr_t>(id)), &kAddByIdIdentity,
|
||||
"XUserAddByIdWithUiAsync", add_by_id_provider);
|
||||
}
|
||||
|
||||
// 38: HRESULT XUserAddByIdWithUiResult(XAsyncBlock* async, XUserHandle* newUser)
|
||||
HRESULT STDMETHODCALLTYPE user_add_by_id_result(void*, XAsyncBlock* async, XUserHandle* user) {
|
||||
if (!user) return E_POINTER;
|
||||
*user = nullptr;
|
||||
return XAsyncGetResult(async, &kAddByIdIdentity, sizeof(*user), user, nullptr);
|
||||
}
|
||||
|
||||
// ---- IXUserImpl4 (42) ----
|
||||
|
||||
// 42: bool XUserIsStoreUser(XUserHandle user): the local user is the one the game was "bought" by.
|
||||
bool STDMETHODCALLTYPE user_is_store_user(void*, XUserHandle user) { return valid(user); }
|
||||
|
||||
// ---- IXUserGamertagImpl (its slot 3) ----
|
||||
|
||||
// HRESULT XUserGetGamertag(XUserHandle user, XUserGamertagComponent component, size_t gamertagSize, char* gamertag,
|
||||
// size_t* gamertagUsed). The offline user has a classic gamertag: Modern and UniqueModern are
|
||||
// the same text (a classic tag has no '#' and no suffix) and ModernSuffix is empty. gamertagUsed counts the
|
||||
// terminator.
|
||||
HRESULT STDMETHODCALLTYPE user_get_gamertag(void*, XUserHandle user, XUserGamertagComponent component, size_t size,
|
||||
char* out, size_t* used) {
|
||||
if (used) *used = 0;
|
||||
if (!valid(user)) return E_INVALIDARG;
|
||||
const char* text = nullptr;
|
||||
switch (component) {
|
||||
case XUserGamertagComponent::Classic:
|
||||
case XUserGamertagComponent::Modern:
|
||||
case XUserGamertagComponent::UniqueModern:
|
||||
text = gamertag();
|
||||
break;
|
||||
case XUserGamertagComponent::ModernSuffix:
|
||||
text = "";
|
||||
break;
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
const size_t need = std::strlen(text) + 1;
|
||||
if (!out || size < need) return kInsufficientBuffer;
|
||||
std::memcpy(out, text, need);
|
||||
if (used) *used = need;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// ---- The object: one vtable for the IXUserImpl..IXUserImpl6 chain, one for IXUserGamertagImpl ----
|
||||
|
||||
constexpr GUID kUserClass = {0x01acd177, 0x91f9, 0x4763, {0xa3, 0x8e, 0xcc, 0xbb, 0x55, 0xce, 0x32, 0xe0}};
|
||||
// IXUserImpl's id is the class id; IXUserImpl2..6 extend it, so each of them answers with the same vtable.
|
||||
constexpr GUID kUserInterfaces[] = {
|
||||
kUserClass,
|
||||
{0xeb9bf948, 0x18dc, 0x4d82, {0xbb, 0xcc, 0x40, 0xe0, 0xa8, 0x09, 0xc4, 0xc0}}, // IXUserImpl2
|
||||
{0x1bf2f8c5, 0xd507, 0x4e52, {0xbb, 0x05, 0xf7, 0x26, 0xd0, 0xe7, 0x11, 0x61}}, // IXUserImpl3
|
||||
{0x079415e3, 0x6727, 0x437f, {0x8e, 0x9d, 0x8f, 0x8f, 0x9b, 0x24, 0x39, 0xf7}}, // IXUserImpl4
|
||||
{0x26f3c674, 0xa2fe, 0x44fa, {0xb6, 0xc4, 0xa3, 0x23, 0xbc, 0x94, 0xff, 0x53}}, // IXUserImpl5
|
||||
{0x5131d685, 0x4394, 0x4ee6, {0x8c, 0x18, 0xbf, 0xb5, 0xd4, 0xae, 0xf1, 0xff}}, // IXUserImpl6
|
||||
};
|
||||
constexpr GUID kGamertagInterface = {0xcef4fac0, 0x7676, 0x4a94, {0xa1, 0x19, 0x4c, 0x43, 0xf9, 0xeb, 0x5b, 0x74}};
|
||||
constexpr GUID kIUnknown = {0x00000000, 0x0000, 0x0000, {0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
|
||||
|
||||
struct UserObject {
|
||||
const void* const* vtable; // IXUserImpl6
|
||||
const void* const* gamertag_vtable; // IXUserGamertagImpl
|
||||
};
|
||||
UserObject* user_object();
|
||||
|
||||
HRESULT query(REFIID iid, void** out) {
|
||||
if (!out) return E_POINTER;
|
||||
*out = nullptr;
|
||||
UserObject* o = user_object();
|
||||
if (iid == kIUnknown) {
|
||||
*out = &o->vtable;
|
||||
return S_OK;
|
||||
}
|
||||
for (const GUID& id : kUserInterfaces)
|
||||
if (iid == id) {
|
||||
*out = &o->vtable;
|
||||
return S_OK;
|
||||
}
|
||||
if (iid == kGamertagInterface) {
|
||||
*out = &o->gamertag_vtable;
|
||||
return S_OK;
|
||||
}
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
// A process-wide singleton, as the other runtime classes: AddRef and Release don't free.
|
||||
HRESULT STDMETHODCALLTYPE object_query_interface(void*, REFIID iid, void** out) { return query(iid, out); }
|
||||
ULONG STDMETHODCALLTYPE object_add_ref(void*) { return 2; }
|
||||
ULONG STDMETHODCALLTYPE object_release(void*) { return 1; }
|
||||
|
||||
#define FN(f) reinterpret_cast<const void*>(&f)
|
||||
|
||||
const void* const kUserVtable[] = {
|
||||
FN(object_query_interface), FN(object_add_ref), FN(object_release), // 0-2 IUnknown
|
||||
FN(user_duplicate), // 3 XUserDuplicateHandle
|
||||
FN(user_close), // 4 XUserCloseHandle
|
||||
FN(user_compare), // 5 XUserCompare
|
||||
FN(user_get_max_users), // 6 XUserGetMaxUsers
|
||||
FN(user_add_async), // 7 XUserAddAsync
|
||||
FN(user_add_result), // 8 XUserAddResult
|
||||
FN(user_get_local_id), // 9 XUserGetLocalId
|
||||
FN(user_find_by_local_id), // 10 XUserFindUserByLocalId
|
||||
FN(user_get_id), // 11 XUserGetId
|
||||
FN(user_find_by_id), // 12 XUserFindUserById
|
||||
FN(user_get_is_guest), // 13 XUserGetIsGuest
|
||||
FN(user_get_state), // 14 XUserGetState
|
||||
FN(private_slot<15>), // 15 (unknown in the docs)
|
||||
FN((offline_failure<16, E_FAIL>)), // 16 XUserGetGamerPictureAsync
|
||||
FN((offline_failure<17, E_FAIL>)), // 17 XUserGetGamerPictureResultSize
|
||||
FN((offline_failure<18, E_FAIL>)), // 18 XUserGetGamerPictureResult
|
||||
FN(user_get_age_group), // 19 XUserGetAgeGroup
|
||||
FN(user_check_privilege), // 20 XUserCheckPrivilege
|
||||
FN(user_resolve_privilege_async), // 21 XUserResolvePrivilegeWithUiAsync
|
||||
FN(user_resolve_privilege_result), // 22 XUserResolvePrivilegeWithUiResult
|
||||
FN((offline_failure<23, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 23 XUserGetTokenAndSignatureAsync
|
||||
FN((offline_failure<24, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 24 ...ResultSize
|
||||
FN((offline_failure<25, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 25 ...Result
|
||||
FN((offline_failure<26, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 26 XUserGetTokenAndSignatureUtf16Async
|
||||
FN((offline_failure<27, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 27 ...Utf16ResultSize
|
||||
FN((offline_failure<28, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 28 ...Utf16Result
|
||||
FN((offline_failure<29, E_GAMEUSER_FAILED_TO_RESOLVE>)), // 29 XUserResolveIssueWithUiAsync
|
||||
FN((offline_failure<30, E_GAMEUSER_FAILED_TO_RESOLVE>)), // 30 XUserResolveIssueWithUiResult
|
||||
FN((offline_failure<31, E_GAMEUSER_FAILED_TO_RESOLVE>)), // 31 XUserResolveIssueWithUiUtf16Async
|
||||
FN((offline_failure<32, E_GAMEUSER_FAILED_TO_RESOLVE>)), // 32 XUserResolveIssueWithUiUtf16Result
|
||||
FN(user_register_change), // 33 XUserRegisterForChangeEvent
|
||||
FN(user_unregister_change), // 34 XUserUnregisterForChangeEvent
|
||||
FN(user_get_signout_deferral), // 35 XUserGetSignOutDeferral
|
||||
FN(user_close_signout_deferral), // 36 XUserCloseSignOutDeferralHandle
|
||||
FN(user_add_by_id_async), // 37 XUserAddByIdWithUiAsync (2)
|
||||
FN(user_add_by_id_result), // 38 XUserAddByIdWithUiResult (2)
|
||||
FN((offline_failure<39, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 39 XUserGetMsaTokenSilentlyAsync (3)
|
||||
FN((offline_failure<40, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 40 ...Result (3)
|
||||
FN((offline_failure<41, E_GAMEUSER_FAILED_TO_GET_TOKEN>)), // 41 ...ResultSize (3)
|
||||
FN(user_is_store_user), // 42 XUserIsStoreUser (4)
|
||||
FN((offline_failure<43, E_NOTIMPL>)), // 43 XUserPlatformRemoteConnectSetEventHandlers (5, PC)
|
||||
FN((offline_failure<44, E_NOTIMPL>)), // 44 XUserPlatformRemoteConnectCancelPrompt (5, PC)
|
||||
FN((offline_failure<45, E_NOTIMPL>)), // 45 XUserPlatformSpopPromptSetEventHandlers (5, PC)
|
||||
FN((offline_failure<46, E_NOTIMPL>)), // 46 XUserPlatformSpopPromptComplete (5, PC)
|
||||
FN(private_slot<47>), // 47 XUserIsSignOutPresent (6): false
|
||||
FN((offline_failure<48, E_NOTIMPL>)), // 48 XUserSignOutAsync (6)
|
||||
FN((offline_failure<49, E_NOTIMPL>)), // 49 XUserSignOutResult (6)
|
||||
};
|
||||
static_assert(std::size(kUserVtable) == 50, "IUnknown + IXUserImpl's 34 methods + 2 + 3 + 1 + 4 + 3");
|
||||
|
||||
// The gamertag face's IUnknown slots get `this` = &gamertag_vtable; the object is a singleton, so they ignore it.
|
||||
const void* const kGamertagVtable[] = {
|
||||
FN(object_query_interface), FN(object_add_ref), FN(object_release),
|
||||
FN(user_get_gamertag), // 3 XUserGetGamertag
|
||||
};
|
||||
|
||||
#undef FN
|
||||
|
||||
UserObject* user_object() {
|
||||
static UserObject o{kUserVtable, kGamertagVtable};
|
||||
return &o;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace rt::shims {
|
||||
|
||||
// Called by xgameruntime.cpp's QueryApiImpl for every class: true when the class is XUserImpl, with *hr set.
|
||||
bool xgameruntime_user_query(const GUID& class_id, REFIID interface_id, void** out, HRESULT* hr) {
|
||||
if (class_id != kUserClass) return false;
|
||||
*hr = query(interface_id, out);
|
||||
return true;
|
||||
}
|
||||
|
||||
// For tests: the XUserHandles a title holds open.
|
||||
long xgameruntime_user_open_handles() { return g_open_handles.load(); }
|
||||
|
||||
} // namespace rt::shims
|
||||
216
runtime/test/xgameruntime_user_test.cpp
Normal file
216
runtime/test/xgameruntime_user_test.cpp
Normal file
@ -0,0 +1,216 @@
|
||||
// XUserImpl through QueryApiImpl, called the way xgameruntime.lib's XUser* thunks call it: QueryApiImpl with the
|
||||
// class id (or a later interface id), one vtable slot with `this` first. Slots follow xgameruntime-docs' layout;
|
||||
// arguments and expected values follow the public GDK reference. No game data; nothing online.
|
||||
//
|
||||
// xgameruntime_user_test the offline user, its handles, gamertag "Player"
|
||||
// xgameruntime_user_test --expect-gamertag TAG the same, run with LEONIDA_GAMERTAG=TAG
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <XAsync.h>
|
||||
#include <XAsyncProvider.h>
|
||||
#include <XTaskQueue.h>
|
||||
|
||||
#include "shims.h"
|
||||
|
||||
namespace rt::shims {
|
||||
long xgameruntime_user_open_handles();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
int g_checks = 0;
|
||||
int g_failures = 0;
|
||||
|
||||
void check(bool condition, const char* what) {
|
||||
++g_checks;
|
||||
std::printf("%s %s\n", condition ? "PASS" : "FAIL", what);
|
||||
if (!condition) ++g_failures;
|
||||
}
|
||||
|
||||
using XUserHandle = void*;
|
||||
struct XUserLocalId {
|
||||
uint64_t value;
|
||||
};
|
||||
|
||||
constexpr HRESULT E_GAMEUSER_USER_NOT_FOUND = static_cast<HRESULT>(0x89245104);
|
||||
constexpr HRESULT E_GAMEUSER_DEFERRAL_NOT_AVAILABLE = static_cast<HRESULT>(0x89245103);
|
||||
constexpr HRESULT E_GAMEUSER_FAILED_TO_GET_TOKEN = static_cast<HRESULT>(0x89245111);
|
||||
|
||||
constexpr GUID kUserClass = {0x01acd177, 0x91f9, 0x4763, {0xa3, 0x8e, 0xcc, 0xbb, 0x55, 0xce, 0x32, 0xe0}};
|
||||
constexpr GUID kUserImpl3 = {0x1bf2f8c5, 0xd507, 0x4e52, {0xbb, 0x05, 0xf7, 0x26, 0xd0, 0xe7, 0x11, 0x61}};
|
||||
constexpr GUID kUserImpl6 = {0x5131d685, 0x4394, 0x4ee6, {0x8c, 0x18, 0xbf, 0xb5, 0xd4, 0xae, 0xf1, 0xff}};
|
||||
constexpr GUID kGamertag = {0xcef4fac0, 0x7676, 0x4a94, {0xa1, 0x19, 0x4c, 0x43, 0xf9, 0xeb, 0x5b, 0x74}};
|
||||
constexpr GUID kOther = {0x973a344e, 0x24bf, 0x4d0f, {0x84, 0x57, 0x56, 0xc5, 0x34, 0x89, 0x2b, 0x29}}; // XGameImpl
|
||||
|
||||
using Query = HRESULT(WINAPI*)(const GUID*, REFIID, void**);
|
||||
using Fn = void*;
|
||||
Fn slot(void* obj, int index) { return (*static_cast<Fn* const*>(obj))[index]; }
|
||||
template <class F> F at(void* obj, int index) { return reinterpret_cast<F>(slot(obj, index)); }
|
||||
|
||||
// Waits for an XAsyncBlock on the process queue, as a title polling XAsyncGetStatus(wait = true) does.
|
||||
bool finished(XAsyncBlock* async) { return XAsyncGetStatus(async, true) != E_PENDING; }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* expect_tag = "Player";
|
||||
if (argc == 3 && std::strcmp(argv[1], "--expect-gamertag") == 0) expect_tag = argv[2];
|
||||
std::printf("xgameruntime_user_test: XUserImpl through QueryApiImpl (gamertag \"%s\")\n", expect_tag);
|
||||
|
||||
auto query = reinterpret_cast<Query>(rt::shims::find("xgameruntime.dll", "QueryApiImpl"));
|
||||
check(query != nullptr, "QueryApiImpl is registered");
|
||||
if (!query) return 1;
|
||||
|
||||
// ---- the object and its interfaces ----
|
||||
void* user = nullptr;
|
||||
check(query(&kUserClass, kUserClass, &user) == S_OK && user, "QueryApiImpl hands out XUserImpl for its class id");
|
||||
if (!user) return 1;
|
||||
void* user6 = nullptr;
|
||||
void* user3 = nullptr;
|
||||
check(query(&kUserClass, kUserImpl6, &user6) == S_OK && user6 == user &&
|
||||
query(&kUserClass, kUserImpl3, &user3) == S_OK && user3 == user,
|
||||
"IXUserImpl3 and IXUserImpl6 (later versions of the same vtable) answer with the same object");
|
||||
void* tag_face = nullptr;
|
||||
check(query(&kUserClass, kGamertag, &tag_face) == S_OK && tag_face && tag_face != user,
|
||||
"IXUserGamertagImpl is a second interface of the object");
|
||||
void* none = reinterpret_cast<void*>(1);
|
||||
check(query(&kUserClass, kOther, &none) == E_NOINTERFACE && none == nullptr,
|
||||
"an interface the class doesn't have is E_NOINTERFACE with a cleared out pointer");
|
||||
|
||||
// ---- XUserAddAsync / XUserAddResult (slots 7, 8) ----
|
||||
using AddAsync = HRESULT(STDMETHODCALLTYPE*)(void*, uint32_t, XAsyncBlock*);
|
||||
using AddResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, XUserHandle*);
|
||||
XAsyncBlock add{};
|
||||
check(at<AddAsync>(user, 7)(user, 0x01, &add) == S_OK, "XUserAddAsync(AddDefaultUserSilently) starts");
|
||||
check(finished(&add) && XAsyncGetStatus(&add, false) == S_OK, "it completes with S_OK");
|
||||
XUserHandle h = nullptr;
|
||||
check(at<AddResult>(user, 8)(user, &add, &h) == S_OK && h != nullptr, "XUserAddResult hands out a user handle");
|
||||
XAsyncBlock bad{};
|
||||
check(at<AddAsync>(user, 7)(user, 0x01 | 0x02, &bad) == E_INVALIDARG,
|
||||
"AllowGuests with AddDefaultUserSilently is refused (a guest can't be the default user)");
|
||||
XAsyncBlock picker{};
|
||||
XUserHandle h_picker = nullptr;
|
||||
check(at<AddAsync>(user, 7)(user, 0x00, &picker) == S_OK && finished(&picker) &&
|
||||
at<AddResult>(user, 8)(user, &picker, &h_picker) == S_OK && h_picker,
|
||||
"XUserAddAsync without a silent option also adds the offline user (no account picker offline)");
|
||||
|
||||
// ---- identity (slots 5, 6, 9-14, 19, 20) ----
|
||||
using Compare = int32_t(STDMETHODCALLTYPE*)(void*, XUserHandle, XUserHandle);
|
||||
using MaxUsers = HRESULT(STDMETHODCALLTYPE*)(void*, uint32_t*);
|
||||
using GetLocalId = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, XUserLocalId*);
|
||||
using FindLocal = HRESULT(STDMETHODCALLTYPE*)(void*, XUserLocalId, XUserHandle*);
|
||||
using GetId = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint64_t*);
|
||||
using FindId = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t, XUserHandle*);
|
||||
using GetBool = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, bool*);
|
||||
using GetU32 = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint32_t*);
|
||||
using CheckPrivilege = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint32_t, uint32_t, bool*, uint32_t*);
|
||||
uint32_t max_users = 0;
|
||||
check(at<MaxUsers>(user, 6)(user, &max_users) == S_OK && max_users == 1, "XUserGetMaxUsers: one local user");
|
||||
check(at<Compare>(user, 5)(user, h, h_picker) == 0, "XUserCompare: both handles name the same user");
|
||||
XUserLocalId local{};
|
||||
check(at<GetLocalId>(user, 9)(user, h, &local) == S_OK && local.value != 0, "XUserGetLocalId: a non-zero local id");
|
||||
uint64_t xuid = 0;
|
||||
check(at<GetId>(user, 11)(user, h, &xuid) == S_OK && xuid != 0, "XUserGetId: a non-zero user id");
|
||||
XUserHandle by_local = nullptr, by_id = nullptr, missing = reinterpret_cast<XUserHandle>(1);
|
||||
check(at<FindLocal>(user, 10)(user, local, &by_local) == S_OK && by_local &&
|
||||
at<Compare>(user, 5)(user, by_local, h) == 0,
|
||||
"XUserFindUserByLocalId finds it");
|
||||
check(at<FindLocal>(user, 10)(user, XUserLocalId{local.value + 1}, &missing) == E_GAMEUSER_USER_NOT_FOUND &&
|
||||
missing == nullptr,
|
||||
"another local id is E_GAMEUSER_USER_NOT_FOUND");
|
||||
check(at<FindId>(user, 12)(user, xuid, &by_id) == S_OK && by_id, "XUserFindUserById finds it");
|
||||
missing = reinterpret_cast<XUserHandle>(1);
|
||||
check(at<FindId>(user, 12)(user, xuid + 1, &missing) == E_GAMEUSER_USER_NOT_FOUND && missing == nullptr,
|
||||
"another user id is E_GAMEUSER_USER_NOT_FOUND");
|
||||
bool guest = true;
|
||||
check(at<GetBool>(user, 13)(user, h, &guest) == S_OK && !guest, "XUserGetIsGuest: not a guest");
|
||||
uint32_t state = 99, age = 99;
|
||||
check(at<GetU32>(user, 14)(user, h, &state) == S_OK && state == 0, "XUserGetState: SignedIn (0)");
|
||||
check(at<GetU32>(user, 19)(user, h, &age) == S_OK && age == 3, "XUserGetAgeGroup: Adult (3)");
|
||||
bool has = false;
|
||||
uint32_t reason = 99;
|
||||
check(at<CheckPrivilege>(user, 20)(user, h, 0, 254, &has, &reason) == S_OK && has && reason == 0,
|
||||
"XUserCheckPrivilege: granted, deny reason None (0)");
|
||||
check(at<GetBool>(user, 13)(user, nullptr, &guest) == E_INVALIDARG, "a null handle is E_INVALIDARG");
|
||||
|
||||
// ---- XUserResolvePrivilegeWithUiAsync / Result (21, 22) ----
|
||||
using ResolveAsync = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint32_t, uint32_t, XAsyncBlock*);
|
||||
using ResolveResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*);
|
||||
XAsyncBlock resolve{};
|
||||
check(at<ResolveAsync>(user, 21)(user, h, 0, 254, &resolve) == S_OK && finished(&resolve) &&
|
||||
at<ResolveResult>(user, 22)(user, &resolve) == S_OK,
|
||||
"XUserResolvePrivilegeWithUiAsync completes with S_OK (nothing to resolve)");
|
||||
|
||||
// ---- tokens: not available offline (23) ----
|
||||
using TokenAsync = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint32_t, const char*, const char*, size_t,
|
||||
const void*, size_t, const void*, XAsyncBlock*);
|
||||
XAsyncBlock token{};
|
||||
check(at<TokenAsync>(user, 23)(user, h, 0, "GET", "https://example.invalid/", 0, nullptr, 0, nullptr, &token) ==
|
||||
E_GAMEUSER_FAILED_TO_GET_TOKEN,
|
||||
"XUserGetTokenAndSignatureAsync fails before starting: E_GAMEUSER_FAILED_TO_GET_TOKEN");
|
||||
|
||||
// ---- change events, sign-out deferral (33-36) ----
|
||||
using Register = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, void*, void(CALLBACK*)(void*, XUserLocalId, uint32_t),
|
||||
XTaskQueueRegistrationToken*);
|
||||
using Unregister = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool);
|
||||
using Deferral = HRESULT(STDMETHODCALLTYPE*)(void*, void**);
|
||||
auto on_change = [](void*, XUserLocalId, uint32_t) {};
|
||||
XTaskQueueRegistrationToken reg{};
|
||||
check(at<Register>(user, 33)(user, nullptr, nullptr, on_change, ®) == S_OK && reg.token != 0,
|
||||
"XUserRegisterForChangeEvent hands out a token");
|
||||
check(at<Unregister>(user, 34)(user, reg, true) && !at<Unregister>(user, 34)(user, reg, true),
|
||||
"XUserUnregisterForChangeEvent: true once, then false for the same token");
|
||||
void* deferral = reinterpret_cast<void*>(1);
|
||||
check(at<Deferral>(user, 35)(user, &deferral) == E_GAMEUSER_DEFERRAL_NOT_AVAILABLE && deferral == nullptr,
|
||||
"XUserGetSignOutDeferral: E_GAMEUSER_DEFERRAL_NOT_AVAILABLE (nothing signs out offline)");
|
||||
|
||||
// ---- IXUserImpl2: XUserAddByIdWithUiAsync / Result (37, 38) ----
|
||||
using AddByIdAsync = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t, XAsyncBlock*);
|
||||
XAsyncBlock by_id_add{}, by_other{};
|
||||
XUserHandle h_by_id = nullptr, h_other = reinterpret_cast<XUserHandle>(1);
|
||||
check(at<AddByIdAsync>(user, 37)(user, xuid, &by_id_add) == S_OK && finished(&by_id_add) &&
|
||||
at<AddResult>(user, 38)(user, &by_id_add, &h_by_id) == S_OK && h_by_id,
|
||||
"XUserAddByIdWithUiAsync with the local user's id adds it");
|
||||
check(at<AddByIdAsync>(user, 37)(user, xuid + 1, &by_other) == S_OK && finished(&by_other) &&
|
||||
at<AddResult>(user, 38)(user, &by_other, &h_other) == E_GAMEUSER_USER_NOT_FOUND && h_other == nullptr,
|
||||
"with another id it completes with E_GAMEUSER_USER_NOT_FOUND");
|
||||
|
||||
// ---- IXUserImpl4: XUserIsStoreUser (42) ----
|
||||
using IsStore = bool(STDMETHODCALLTYPE*)(void*, XUserHandle);
|
||||
check(at<IsStore>(user, 42)(user, h), "XUserIsStoreUser: true");
|
||||
|
||||
// ---- IXUserGamertagImpl: XUserGetGamertag (3) ----
|
||||
using GetTag = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, uint32_t, size_t, char*, size_t*);
|
||||
auto tag = at<GetTag>(tag_face, 3);
|
||||
char buf[101] = {};
|
||||
size_t used = 0;
|
||||
const size_t want = std::strlen(expect_tag) + 1;
|
||||
check(tag(tag_face, h, 0, sizeof(buf), buf, &used) == S_OK && std::strcmp(buf, expect_tag) == 0 && used == want,
|
||||
"XUserGetGamertag(Classic): the gamertag, gamertagUsed counting the terminator");
|
||||
check(tag(tag_face, h, 3, sizeof(buf), buf, &used) == S_OK && std::strcmp(buf, expect_tag) == 0,
|
||||
"UniqueModern of a classic gamertag: the same text, no '#' and no suffix");
|
||||
check(tag(tag_face, h, 1, sizeof(buf), buf, &used) == S_OK && std::strcmp(buf, expect_tag) == 0,
|
||||
"Modern: the classic gamertag when none is set");
|
||||
check(tag(tag_face, h, 2, sizeof(buf), buf, &used) == S_OK && buf[0] == 0 && used == 1,
|
||||
"ModernSuffix: empty (just the terminator)");
|
||||
check(tag(tag_face, h, 0, want - 1, buf, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
|
||||
"a buffer one byte short is E_INSUFFICIENT_BUFFER");
|
||||
check(tag(tag_face, h, 7, sizeof(buf), buf, &used) == E_INVALIDARG, "an unknown component is E_INVALIDARG");
|
||||
|
||||
// ---- handles: duplicate, close, all accounted for (3, 4) ----
|
||||
using Dup = HRESULT(STDMETHODCALLTYPE*)(void*, XUserHandle, XUserHandle*);
|
||||
using Close = void(STDMETHODCALLTYPE*)(void*, XUserHandle);
|
||||
XUserHandle dup = nullptr;
|
||||
check(at<Dup>(user, 3)(user, h, &dup) == S_OK && dup && dup != h && at<Compare>(user, 5)(user, dup, h) == 0,
|
||||
"XUserDuplicateHandle: a new handle for the same user");
|
||||
check(rt::shims::xgameruntime_user_open_handles() == 6, "six handles are open: two adds, two finds, an add by id and a duplicate");
|
||||
for (XUserHandle x : {h, h_picker, by_local, by_id, h_by_id, dup}) at<Close>(user, 4)(user, x);
|
||||
check(rt::shims::xgameruntime_user_open_handles() == 0, "XUserCloseHandle closes each of them");
|
||||
|
||||
std::printf("xgameruntime_user_test: %d of %d checks failed\n", g_failures, g_checks);
|
||||
return g_failures ? 1 : 0;
|
||||
}
|
||||
@ -35,7 +35,7 @@ if ((Test-Path $cmake) -and (Test-Path $ninja)) {
|
||||
Write-Warning "VS C++ CMake tools not found: building with cl.exe directly, without the GameInput shim (SDL3). Install the CMake tools component to get it."
|
||||
$xtaskqueueDir = Join-Path $root "third_party\xtaskqueue"
|
||||
$xtaskqueueFiles = "Source\Task\TaskQueue.cpp", "Source\Task\AsyncLib.cpp", "Source\Task\ThreadPool_win32.cpp", "Source\Task\WaitTimer_win32.cpp" | ForEach-Object { "`"$xtaskqueueDir\$_`"" }
|
||||
$files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\winhttp_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp" | ForEach-Object { "`"$src\$_`"" }
|
||||
$files = "src\main.cpp", "src\pe_loader.cpp", "shims\registry.cpp", "shims\file_system.cpp", "shims\xmem.cpp", "shims\d3d12_xs.cpp", "shims\d3d12_xs_device.cpp", "shims\d3d12_xs_rootsig.cpp", "shims\xgameruntime.cpp", "shims\xgameruntime_user.cpp", "shims\winhttp_offline.cpp", "shims\library_loader.cpp", "shims\process.cpp" | ForEach-Object { "`"$src\$_`"" }
|
||||
$includes = "/I `"$src\src`" /I `"$src\shims`" /I `"$src\shims\xtaskqueue`" /I `"$xtaskqueueDir\Include`" /I `"$xtaskqueueDir\Source\Task`" /I `"$xtaskqueueDir\Source\Common`""
|
||||
$opt = if ($Debug) { "/Od /MDd" } else { "/O2 /MD" }
|
||||
$body = @"
|
||||
|
||||
Reference in New Issue
Block a user