upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/xgameruntime_test.cpp
diff options
context:
space:
mode:
authorlumenpearson <139921639+lumenpearson@users.noreply.github.com>2026-11-22 23:25:25 +0300
committerlumenpearson <139921639+lumenpearson@users.noreply.github.com>2026-11-22 23:25:25 +0300
commitf324bfbc71f0eabf9515bcd7c8b7c9e4b89448bf (patch)
tree2db4ae6fd5412abbbc3e1894f8bc7ed88c8ae514 /runtime/test/xgameruntime_test.cpp
parent18380c6d2baf1422109b369860a6e8be5e185b05 (diff)
parentf847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff)
Merge upstream main into SHADER-537
Diffstat (limited to 'runtime/test/xgameruntime_test.cpp')
-rw-r--r--runtime/test/xgameruntime_test.cpp276
1 files changed, 193 insertions, 83 deletions
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp
index 504f0f74d..c5a0e988e 100644
--- a/runtime/test/xgameruntime_test.cpp
+++ b/runtime/test/xgameruntime_test.cpp
@@ -51,16 +51,11 @@ using AsyncCompleteFn = void(__stdcall*)(XAsyncBlock*, HRESULT, size_t);
51using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*); 51using AsyncResultSizeFn = HRESULT(__stdcall*)(XAsyncBlock*, size_t*);
52using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*); 52using AsyncResultFn = HRESULT(__stdcall*)(XAsyncBlock*, const void*, size_t, void*, size_t*);
53 53
54struct XVersion { 54struct alignas(8) XVersion {
55 union { 55 uint16_t major;
56 struct { 56 uint16_t minor;
57 uint16_t major; 57 uint16_t build;
58 uint16_t minor; 58 uint16_t revision;
59 uint16_t build;
60 uint16_t revision;
61 };
62 uint64_t Value;
63 };
64}; 59};
65static_assert(sizeof(XVersion) == 8, "XVersion must be 8 bytes per GDK spec"); 60static_assert(sizeof(XVersion) == 8, "XVersion must be 8 bytes per GDK spec");
66 61
@@ -72,14 +67,22 @@ struct XSystemAnalyticsInfo {
72}; 67};
73static_assert(sizeof(XSystemAnalyticsInfo) == 144, "XSystemAnalyticsInfo must be 144 bytes per GDK spec"); 68static_assert(sizeof(XSystemAnalyticsInfo) == 144, "XSystemAnalyticsInfo must be 144 bytes per GDK spec");
74 69
70struct XPackageMountHandle {
71 uint64_t handle;
72};
73
75using AnalyticsInfoFn = XSystemAnalyticsInfo(__stdcall*)(); 74using AnalyticsInfoFn = XSystemAnalyticsInfo(__stdcall*)();
76using PackageIdentifierFn = HRESULT(__stdcall*)(size_t, char*); 75using PackageIdentifierFn = HRESULT(__stdcall*)(size_t, char*);
77using PackageMountPathFn = HRESULT(__stdcall*)(void*, size_t, char*); 76using PackageMountFn = HRESULT(__stdcall*)(const char*, XPackageMountHandle*);
77using PackageCloseMountHandleFn = void(__stdcall*)(XPackageMountHandle);
78using PackageMountPathSizeFn = HRESULT(__stdcall*)(XPackageMountHandle, size_t*);
79using PackageMountPathFn = HRESULT(__stdcall*)(XPackageMountHandle, size_t, char*);
78using PackagedProcessFn = bool(__stdcall*)(); 80using PackagedProcessFn = bool(__stdcall*)();
79 81
80const char* const kNames[] = { 82const char* const kNames[] = {
81 "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId", 83 "XGameRuntimeInitialize", "XGameRuntimeUninitialize", "XSystemGetDeviceType", "XSystemGetConsoleId",
82 "XSystemGetAnalyticsInfo", "XPackageGetCurrentProcessPackageIdentifier", "XPackageGetMountPath", 84 "XSystemGetAnalyticsInfo", "XPackageGetCurrentProcessPackageIdentifier", "XPackageMount",
85 "XPackageCloseMountHandle", "XPackageGetMountPathSize", "XPackageGetMountPath",
83 "XPackageIsPackagedProcess", 86 "XPackageIsPackagedProcess",
84 "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle", 87 "XTaskQueueCreate", "XTaskQueueCreateComposite", "XTaskQueueGetPort", "XTaskQueueDuplicateHandle",
85 "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback", 88 "XTaskQueueCloseHandle", "XTaskQueueTerminate", "XTaskQueueDispatch", "XTaskQueueSubmitCallback",
@@ -194,6 +197,23 @@ void check_run_time_load() {
194 check(get_proc(rt_mod, nullptr) == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND, 197 check(get_proc(rt_mod, nullptr) == nullptr && GetLastError() == ERROR_PROC_NOT_FOUND,
195 "a null proc name is NULL with ERROR_PROC_NOT_FOUND"); 198 "a null proc name is NULL with ERROR_PROC_NOT_FOUND");
196 199
200 // XCurl.dll's other way in: LoadLibraryExW(L"gameplatformservices.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32),
201 // then GetApiVersionImpl(uint64_t*, uint64_t*) and QueryApiImpl. Served by the shims, never the PC's own.
202 using LoadExW = HMODULE(WINAPI*)(LPCWSTR, HANDLE, DWORD);
203 auto load_ex_w = reinterpret_cast<LoadExW>(rt::shims::find(set, "LoadLibraryExW"));
204 HMODULE gps = load_ex_w ? load_ex_w(L"gameplatformservices.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32) : nullptr;
205 check(rt::shims::owns_dll("gameplatformservices.dll") && gps != nullptr && gps != rt_mod,
206 "LoadLibraryExW(gameplatformservices.dll, SEARCH_SYSTEM32) is served by the shims");
207 using ApiVersion = HRESULT(WINAPI*)(uint64_t*, uint64_t*);
208 auto api_version = gps ? reinterpret_cast<ApiVersion>(get_proc(gps, "GetApiVersionImpl")) : nullptr;
209 uint64_t v1 = 0, v2 = 0, w1 = 0, w2 = 0;
210 check(api_version && api_version(&v1, &v2) == S_OK && api_version(&w1, &w2) == S_OK && v1 && v2 && v1 == w1 &&
211 v2 == w2,
212 "GetApiVersionImpl writes the same two non-zero versions on every call");
213 check(gps && reinterpret_cast<void*>(get_proc(gps, "QueryApiImpl")) ==
214 rt::shims::find("xgameruntime.dll", "QueryApiImpl"),
215 "its QueryApiImpl is the offline runtime's");
216
197 struct Options { 217 struct Options {
198 uint32_t unknown; 218 uint32_t unknown;
199 BOOL is_inline; 219 BOOL is_inline;
@@ -283,76 +303,123 @@ void check_run_time_load() {
283 return true; 303 return true;
284 }; 304 };
285 using SetCallback = void(STDMETHODCALLTYPE*)(void*, Callback, void*); 305 using SetCallback = void(STDMETHODCALLTYPE*)(void*, Callback, void*);
286 using Report = void(STDMETHODCALLTYPE*)(void*, HRESULT, const char*); 306 using Report = HRESULT(STDMETHODCALLTYPE*)(void*, HRESULT, const char*);
287 reinterpret_cast<SetCallback>(slot(e, 4))(e, on_error, &seen); 307 reinterpret_cast<SetCallback>(slot(e, 4))(e, on_error, &seen);
288 reinterpret_cast<Report>(slot(e, 3))(e, E_FAIL, "offline test"); 308 const HRESULT reported = reinterpret_cast<Report>(slot(e, 3))(e, E_FAIL, "offline test");
289 check(seen.hr == E_FAIL && std::strcmp(seen.msg, "offline test") == 0, 309 check(reported == S_OK && seen.hr == E_FAIL && std::strcmp(seen.msg, "offline test") == 0,
290 "slot 3 is XErrorReport and reaches the callback slot 4 (XErrorSetCallback) set"); 310 "slot 3 is XErrorReport and reaches the callback slot 4 (XErrorSetCallback) set");
291 reinterpret_cast<SetCallback>(slot(e, 4))(e, nullptr, nullptr); 311 reinterpret_cast<SetCallback>(slot(e, 4))(e, nullptr, nullptr);
292 using SetOptions = HRESULT(STDMETHODCALLTYPE*)(void*, uint32_t, uint32_t); 312 using SetOptions = void(STDMETHODCALLTYPE*)(void*, uint32_t, uint32_t); // void, per Microsoft's page
293 check(reinterpret_cast<SetOptions>(slot(e, 5))(e, 0, 0) == S_OK, "slot 5 is XErrorSetOptions"); 313 reinterpret_cast<SetOptions>(slot(e, 5))(e, 0x01, 0x00); // OutputDebugStringOnError / None
294 release(e); 314 release(e);
295 } 315 }
296 316
297 const GUID networking_cls = {0x37e56907, 0x2f10, 0x41e8, {0xb7, 0x2f, 0x36, 0xed, 0xb1, 0x85, 0x33, 0x1a}}; 317 // XNetworkingImpl, asked for as XCurl.dll does: the class id with IXNetworkingImpl2's interface id.
298 void* n = get(networking_cls); 318 const GUID networking = {0x37e56907, 0x2f10, 0x41e8, {0xb7, 0x2f, 0x36, 0xed, 0xb1, 0x85, 0x33, 0x1a}};
299 check(n != nullptr, "QueryApiImpl hands out XNetworkingImpl for its class id"); 319 const GUID networking2 = {0xbf2346b2, 0x39af, 0x4658, {0xb5, 0xea, 0x44, 0x71, 0x3c, 0x7e, 0x83, 0xb3}};
320 const HRESULT no_network = HRESULT_FROM_WIN32(ERROR_NETWORK_UNREACHABLE);
321 void* n = nullptr;
322 check(query(&networking, networking2, &n) == S_OK && n, "QueryApiImpl hands out XNetworkingImpl for IXNetworkingImpl2");
323 void* n1 = nullptr;
324 check(query(&networking, networking, &n1) == S_OK && n1 == n, "and the same object for IXNetworkingImpl");
325 if (n1) release(n1);
300 if (n) { 326 if (n) {
301 void* again = get(networking_cls); 327 struct Hint {
302 check(again == n, "XNetworkingImpl is one process-wide object"); 328 uint32_t level, cost, iana;
303 release(again); 329 bool initialized, approaching, over, roaming;
304 330 } hint{9, 9, 9, false, true, true, true};
305 // Slot 15: XNetworkingGetConnectivityHint 331 using GetHint = HRESULT(STDMETHODCALLTYPE*)(void*, Hint*);
306 struct ConnectivityHint { 332 check(reinterpret_cast<GetHint>(slot(n, 15))(n, &hint) == S_OK && hint.level == 1 && hint.cost == 0 &&
307 uint32_t level; 333 hint.initialized && !hint.approaching && !hint.over && !hint.roaming,
308 uint32_t cost; 334 "slot 15 (XNetworkingGetConnectivityHint): initialized, no connectivity");
309 uint32_t iana_type; 335 XAsyncBlock block{};
310 bool network_initialized; 336 using SecurityAsync = HRESULT(STDMETHODCALLTYPE*)(void*, const wchar_t*, XAsyncBlock*);
311 bool approaching_limit; 337 using ResultSize = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t*);
312 bool over_limit; 338 size_t size = 99;
313 bool roaming; 339 check(reinterpret_cast<SecurityAsync>(slot(n, 11))(n, L"https://example.invalid/", &block) == S_OK &&
314 } hint{}; 340 XAsyncGetStatus(&block, true) == no_network &&
315 using GetHint = HRESULT(STDMETHODCALLTYPE*)(void*, ConnectivityHint*); 341 reinterpret_cast<ResultSize>(slot(n, 12))(n, &block, &size) == no_network && size == 0,
316 check(reinterpret_cast<GetHint>(slot(n, 15))(n, nullptr) == E_POINTER, 342 "slots 11/12 (UTF-16 URL security info): the async call completes with no network");
317 "slot 15 rejects null pointer with E_POINTER"); 343 // Slots 10/13 in Microsoft's order: (async, bufferByteCount, bufferByteCountUsed*, buffer*, information**).
318 check(reinterpret_cast<GetHint>(slot(n, 15))(n, &hint) == S_OK && hint.network_initialized && 344 // A sentinel buffer must stay untouched; the two outputs are written where they are, not into the buffer.
319 hint.level == 3 && hint.cost == 1, 345 using SecurityResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t, size_t*, uint8_t*, void**);
320 "slot 15 is XNetworkingGetConnectivityHint reporting initialized network and internet access"); 346 for (int s : {10, 13}) {
321 347 uint8_t buffer[32];
322 // Slot 14: XNetworkingVerifyServerCertificate 348 std::memset(buffer, 0xA5, sizeof(buffer));
323 using VerifyCert = HRESULT(STDMETHODCALLTYPE*)(void*, void*, const void*); 349 size_t used = 77;
324 check(reinterpret_cast<VerifyCert>(slot(n, 14))(n, nullptr, nullptr) == S_OK, 350 void* info = &used;
325 "slot 14 is XNetworkingVerifyServerCertificate returning S_OK offline"); 351 const HRESULT hr = reinterpret_cast<SecurityResult>(slot(n, s))(n, &block, sizeof(buffer), &used, buffer, &info);
326 352 bool untouched = true;
327 // Slot 16 & 17: XNetworkingRegisterConnectivityHintChanged and Unregister 353 for (uint8_t byte : buffer) untouched = untouched && byte == 0xA5;
328 using RegisterHint = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, void*, void*, XTaskQueueRegistrationToken*); 354 check(hr == no_network && used == 0 && info == nullptr && untouched,
329 using UnregisterHint = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool); 355 s == 10 ? "slot 10 (ANSI result): outputs zeroed in place, the caller's buffer untouched"
330 XTaskQueueRegistrationToken tok1{0}, tok2{0}; 356 : "slot 13 (UTF-16 result): outputs zeroed in place, the caller's buffer untouched");
331 check(reinterpret_cast<RegisterHint>(slot(n, 16))(n, nullptr, nullptr, nullptr, &tok1) == S_OK && 357 }
332 reinterpret_cast<RegisterHint>(slot(n, 16))(n, nullptr, nullptr, nullptr, &tok2) == S_OK && 358 using Verify = HRESULT(STDMETHODCALLTYPE*)(void*, void*, const void*);
333 tok1.token != tok2.token && tok1.token > 0, 359 check(reinterpret_cast<Verify>(slot(n, 14))(n, nullptr, nullptr) == no_network,
334 "slot 16 registers connectivity hint callbacks and hands out tokens"); 360 "slot 14 (XNetworkingVerifyServerCertificate) fails offline");
335 check(reinterpret_cast<UnregisterHint>(slot(n, 17))(n, tok1, false) == true && 361 XTaskQueueRegistrationToken token{};
336 reinterpret_cast<UnregisterHint>(slot(n, 17))(n, tok2, true) == true, 362 using Register = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, void*, void*, XTaskQueueRegistrationToken*);
337 "slot 17 unregisters connectivity hint callbacks"); 363 using Unregister = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool);
338 364 check(reinterpret_cast<Register>(slot(n, 16))(n, nullptr, nullptr, nullptr, &token) == S_OK && token.token &&
339 // Slots 11-13: Async security info query 365 reinterpret_cast<Unregister>(slot(n, 17))(n, token, true),
340 using QuerySecAsync = HRESULT(STDMETHODCALLTYPE*)(void*, const wchar_t*, XAsyncBlock*); 366 "slots 16/17 register and unregister a connectivity-hint callback");
341 using QuerySecSize = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t*); 367 uint16_t port = 7;
342 using QuerySecResult = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, size_t, size_t*, uint8_t*, void**); 368 using QueryPort = HRESULT(STDMETHODCALLTYPE*)(void*, uint16_t*);
343 check(reinterpret_cast<QuerySecAsync>(slot(n, 11))(n, L"https://example.com", nullptr) == S_OK, 369 using NotImpl = HRESULT(STDMETHODCALLTYPE*)(void*);
344 "slot 11 is XNetworkingQuerySecurityInformationForUrlUtf16Async"); 370 check(reinterpret_cast<QueryPort>(slot(n, 3))(n, &port) == no_network && port == 0 &&
345 size_t sec_size = 42; 371 reinterpret_cast<NotImpl>(slot(n, 20))(n) == E_NOTIMPL,
346 check(reinterpret_cast<QuerySecSize>(slot(n, 12))(n, nullptr, &sec_size) == S_OK && sec_size == 0, 372 "slot 3 (preferred UDP port) has no answer offline; slot 20 (IXNetworkingImpl2) is E_NOTIMPL");
347 "slot 12 is XNetworkingQuerySecurityInformationForUrlUtf16AsyncResultSize returning 0 bytes");
348 size_t used = 42;
349 void* sec_info = reinterpret_cast<void*>(1);
350 check(reinterpret_cast<QuerySecResult>(slot(n, 13))(n, nullptr, 0, &used, nullptr, &sec_info) == S_OK &&
351 used == 0 && sec_info == nullptr,
352 "slot 13 is XNetworkingQuerySecurityInformationForUrlUtf16AsyncResult returning S_OK with null result");
353
354 release(n); 373 release(n);
355 } 374 }
375
376 // XSystemImpl, asked for as libHttpClient.GDK.dll does: the class id with IXSystemImpl5's interface id.
377 const GUID system_cls = {0xe349bd1a, 0xfc20, 0x4e40, {0xb9, 0x9c, 0x41, 0x78, 0xcc, 0x6b, 0x40, 0x9f}};
378 const GUID system5 = {0x1861cf2e, 0xe18b, 0x4834, {0xa9, 0xf5, 0xb4, 0xa4, 0xe6, 0xef, 0xb4, 0xcf}};
379 void* sy = nullptr;
380 check(query(&system_cls, system5, &sy) == S_OK && sy, "QueryApiImpl hands out XSystemImpl for IXSystemImpl5");
381 if (sy) {
382 using IdQuery = HRESULT(STDMETHODCALLTYPE*)(void*, size_t, char*, size_t*);
383 char buf[64] = {};
384 size_t used = 0;
385 check(reinterpret_cast<IdQuery>(slot(sy, 3))(sy, sizeof(buf), buf, &used) == S_OK && used == 39 &&
386 std::strlen(buf) == 38,
387 "slot 3 (XSystemGetConsoleId): the 39-byte placeholder");
388 check(reinterpret_cast<IdQuery>(slot(sy, 4))(sy, sizeof(buf), buf, &used) == S_OK &&
389 std::strcmp(buf, "RETAIL") == 0 && used == 7,
390 "slot 4 (XSystemGetXboxLiveSandboxId): RETAIL");
391 check(reinterpret_cast<IdQuery>(slot(sy, 4))(sy, 15, buf, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) &&
392 reinterpret_cast<IdQuery>(slot(sy, 4))(sy, 16, buf, &used) == S_OK,
393 "slot 4 needs XSystemXboxLiveSandboxIdMaxBytes (16), not just the id's 7 bytes");
394 const GUID chain[] = {
395 system_cls,
396 {0x6fd71f09, 0x7513, 0x49f0, {0x89, 0xbc, 0xbf, 0xaf, 0x5d, 0xf6, 0xf8, 0x52}},
397 {0x67ce4bfc, 0xb1d1, 0x4ac7, {0xbc, 0x3a, 0xcb, 0x92, 0x19, 0xa9, 0x7a, 0x85}},
398 {0xdadc2895, 0x34b0, 0x4ef5, {0xa8, 0x3e, 0x45, 0x11, 0x4d, 0x62, 0x9b, 0x80}},
399 system5};
400 bool all = true;
401 for (const GUID& iid : chain) {
402 void* same = nullptr;
403 all = all && query(&system_cls, iid, &same) == S_OK && same == sy;
404 if (same) release(same);
405 }
406 check(all, "IXSystemImpl5 answers for every interface it inherits (IXSystemImpl .. IXSystemImpl4)");
407 check(reinterpret_cast<IdQuery>(slot(sy, 5))(sy, sizeof(buf), buf, &used) == S_OK && used == 45 &&
408 reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 44, buf, &used) ==
409 HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) &&
410 reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 45, nullptr, &used) == E_INVALIDARG,
411 "slot 5 (XSystemGetAppSpecificDeviceId): 45 bytes; a short or null buffer is refused");
412 using Track = HRESULT(STDMETHODCALLTYPE*)(void*, void*, void*);
413 using IsValid = bool(STDMETHODCALLTYPE*)(void*, void*); // bool, per Microsoft's reference page
414 using Bandwidth = void(STDMETHODCALLTYPE*)(void*, bool);
415 int ctx = 0;
416 reinterpret_cast<Bandwidth>(slot(sy, 8))(sy, true);
417 check(reinterpret_cast<Track>(slot(sy, 6))(sy, &ctx, &ctx) == S_OK &&
418 reinterpret_cast<IsValid>(slot(sy, 7))(sy, &ctx) &&
419 !reinterpret_cast<IsValid>(slot(sy, 7))(sy, nullptr),
420 "slots 6-8 (handle tracking, handle check, download bandwidth) answer offline");
421 release(sy);
422 }
356 check(uninit_api() == S_OK, "UninitializeApiImpl succeeds"); 423 check(uninit_api() == S_OK, "UninitializeApiImpl succeeds");
357 424
358 HMODULE k32 = load_w(L"kernel32.dll"); 425 HMODULE k32 = load_w(L"kernel32.dll");
@@ -426,20 +493,63 @@ int main() {
426 std::strcmp(pkg_id, "CustomTestPackageId_123456789012") == 0, 493 std::strcmp(pkg_id, "CustomTestPackageId_123456789012") == 0,
427 "XPackageGetCurrentProcessPackageIdentifier respects LEONIDA_PACKAGE_ID override"); 494 "XPackageGetCurrentProcessPackageIdentifier respects LEONIDA_PACKAGE_ID override");
428 SetEnvironmentVariableA("LEONIDA_PACKAGE_ID", nullptr); 495 SetEnvironmentVariableA("LEONIDA_PACKAGE_ID", nullptr);
496 // pkg_id still holds the override; the mount checks below need the game's own identifier again.
497 check(package_id(sizeof(pkg_id), pkg_id) == S_OK && std::strlen(pkg_id) == 32,
498 "XPackageGetCurrentProcessPackageIdentifier returns the default again once the override is cleared");
429 499
500 auto mount_pkg = get<PackageMountFn>("XPackageMount");
501 auto close_mount = get<PackageCloseMountHandleFn>("XPackageCloseMountHandle");
502 auto mount_path_size = get<PackageMountPathSizeFn>("XPackageGetMountPathSize");
430 auto mount_path = get<PackageMountPathFn>("XPackageGetMountPath"); 503 auto mount_path = get<PackageMountPathFn>("XPackageGetMountPath");
431 check(mount_path(nullptr, 0, nullptr) == E_INVALIDARG, "XPackageGetMountPath rejects null buffer and size 0");
432 char mnt_path[MAX_PATH] = {};
433 check(mount_path(nullptr, 0, mnt_path) == E_INVALIDARG, "XPackageGetMountPath rejects size 0 with buffer");
434 check(mount_path(nullptr, 10, nullptr) == E_INVALIDARG, "XPackageGetMountPath rejects null pointer with size");
435 504
436 SetEnvironmentVariableA("LEONIDA_GAME_DIR", "C:\\LeonidaGameDir"); 505 const XPackageMountHandle kInvalidMount{0};
437 check(mount_path(nullptr, 5, mnt_path) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), 506 const XPackageMountHandle kStaleMount{999};
507
508 XPackageMountHandle test_out{0};
509 check(mount_pkg(nullptr, nullptr) == E_INVALIDARG, "XPackageMount rejects null identifier and null out pointer");
510 check(mount_pkg(pkg_id, nullptr) == E_INVALIDARG, "XPackageMount rejects null out pointer with identifier");
511 check(mount_pkg(nullptr, &test_out) == E_INVALIDARG, "XPackageMount rejects null identifier with out pointer");
512 check(mount_pkg(pkg_id, &test_out) == E_ACCESSDENIED,
513 "XPackageMount rejects game package identifier with E_ACCESSDENIED");
514 check(mount_pkg("UninstalledPackage_0000000000000", &test_out) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND),
515 "XPackageMount rejects uninstalled package identifier with ERROR_NOT_FOUND");
516
517 size_t req_size = 0;
518 check(mount_path_size(kInvalidMount, &req_size) == E_INVALIDARG,
519 "XPackageGetMountPathSize rejects invalid mount handle 0");
520 check(mount_path_size(kStaleMount, &req_size) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND),
521 "XPackageGetMountPathSize rejects unknown mount handle");
522
523 char mnt_path[MAX_PATH] = {};
524 check(mount_path(kInvalidMount, 0, nullptr) == E_INVALIDARG,
525 "XPackageGetMountPath rejects invalid mount handle 0");
526 check(mount_path(kStaleMount, sizeof(mnt_path), mnt_path) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND),
527 "XPackageGetMountPath rejects unknown mount handle");
528
529 SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", "DLC1_123456789012345678901234567=C:\\LeonidaDLC1");
530 XPackageMountHandle dlc_mount{0};
531 check(mount_pkg("DLC1_123456789012345678901234567", &dlc_mount) == S_OK && dlc_mount.handle != 0,
532 "XPackageMount mounts content package from LEONIDA_CONTENT_PACKAGES");
533 check(mount_path_size(dlc_mount, nullptr) == E_INVALIDARG,
534 "XPackageGetMountPathSize rejects null size pointer");
535 check(mount_path_size(dlc_mount, &req_size) == S_OK && req_size == std::strlen("C:\\LeonidaDLC1") + 1,
536 "XPackageGetMountPathSize returns required buffer size including null terminator for mounted handle");
537 check(mount_path(dlc_mount, 0, mnt_path) == E_INVALIDARG,
538 "XPackageGetMountPath rejects size 0 with buffer");
539 check(mount_path(dlc_mount, 10, nullptr) == E_INVALIDARG,
540 "XPackageGetMountPath rejects null pointer with size");
541 check(mount_path(dlc_mount, 5, mnt_path) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),
438 "XPackageGetMountPath rejects insufficient buffer"); 542 "XPackageGetMountPath rejects insufficient buffer");
439 check(mount_path(nullptr, sizeof(mnt_path), mnt_path) == S_OK && 543 check(mount_path(dlc_mount, sizeof(mnt_path), mnt_path) == S_OK &&
440 std::strcmp(mnt_path, "C:\\LeonidaGameDir") == 0, 544 std::strcmp(mnt_path, "C:\\LeonidaDLC1") == 0,
441 "XPackageGetMountPath returns configured game directory"); 545 "XPackageGetMountPath returns configured content directory for mounted handle");
442 SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); 546
547 close_mount(dlc_mount);
548 check(mount_path_size(dlc_mount, &req_size) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND),
549 "XPackageGetMountPathSize rejects closed/stale mount handle");
550 check(mount_path(dlc_mount, sizeof(mnt_path), mnt_path) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND),
551 "XPackageGetMountPath rejects closed/stale mount handle");
552 SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", nullptr);
443 553
444 auto is_packaged = get<PackagedProcessFn>("XPackageIsPackagedProcess"); 554 auto is_packaged = get<PackagedProcessFn>("XPackageIsPackagedProcess");
445 check(is_packaged() == true, "XPackageIsPackagedProcess returns true by default"); 555 check(is_packaged() == true, "XPackageIsPackagedProcess returns true by default");