diff options
Diffstat (limited to 'runtime/test/xgameruntime_test.cpp')
| -rw-r--r-- | runtime/test/xgameruntime_test.cpp | 189 |
1 files changed, 185 insertions, 4 deletions
diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index 6464b4907..5102c54ab 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp | |||
| @@ -231,7 +231,8 @@ void check_run_time_load() { | |||
| 231 | auto query = reinterpret_cast<Query>(get_proc(rt_mod, "QueryApiImpl")); | 231 | auto query = reinterpret_cast<Query>(get_proc(rt_mod, "QueryApiImpl")); |
| 232 | auto uninit_api = reinterpret_cast<Uninit>(get_proc(rt_mod, "UninitializeApiImpl")); | 232 | auto uninit_api = reinterpret_cast<Uninit>(get_proc(rt_mod, "UninitializeApiImpl")); |
| 233 | check(init_ex2(0x2410, 0x0, 0x02, &options) == S_OK, "InitializeApiImplEx2 succeeds offline"); | 233 | check(init_ex2(0x2410, 0x0, 0x02, &options) == S_OK, "InitializeApiImplEx2 succeeds offline"); |
| 234 | const GUID some_class = {0x973a344e, 0x24bf, 0x4d0f, {0x84, 0x57, 0x56, 0xc5, 0x34, 0x89, 0x2b, 0x29}}; | 234 | // XGameSaveImpl (xgameruntime include/xgamesave.idl), not served yet. |
| 235 | const GUID some_class = {0x704c3f58, 0xe629, 0x4cc2, {0xb1, 0x97, 0x30, 0x51, 0x1b, 0x99, 0x6f, 0xe2}}; | ||
| 235 | void* out = reinterpret_cast<void*>(1); | 236 | void* out = reinterpret_cast<void*>(1); |
| 236 | check(query(&some_class, some_class, &out) == static_cast<HRESULT>(0x80070032) && out == nullptr, | 237 | check(query(&some_class, some_class, &out) == static_cast<HRESULT>(0x80070032) && out == nullptr, |
| 237 | "QueryApiImpl refuses a class it doesn't provide yet (HRESULT 0x80070032) and clears the out pointer"); | 238 | "QueryApiImpl refuses a class it doesn't provide yet (HRESULT 0x80070032) and clears the out pointer"); |
| @@ -489,13 +490,13 @@ void check_run_time_load() { | |||
| 489 | {0x67ce4bfc, 0xb1d1, 0x4ac7, {0xbc, 0x3a, 0xcb, 0x92, 0x19, 0xa9, 0x7a, 0x85}}, | 490 | {0x67ce4bfc, 0xb1d1, 0x4ac7, {0xbc, 0x3a, 0xcb, 0x92, 0x19, 0xa9, 0x7a, 0x85}}, |
| 490 | {0xdadc2895, 0x34b0, 0x4ef5, {0xa8, 0x3e, 0x45, 0x11, 0x4d, 0x62, 0x9b, 0x80}}, | 491 | {0xdadc2895, 0x34b0, 0x4ef5, {0xa8, 0x3e, 0x45, 0x11, 0x4d, 0x62, 0x9b, 0x80}}, |
| 491 | system5}; | 492 | system5}; |
| 492 | bool all = true; | 493 | bool all_inherited = true; |
| 493 | for (const GUID& iid : chain) { | 494 | for (const GUID& iid : chain) { |
| 494 | void* same = nullptr; | 495 | void* same = nullptr; |
| 495 | all = all && query(&system_cls, iid, &same) == S_OK && same == sy; | 496 | all_inherited = all_inherited && query(&system_cls, iid, &same) == S_OK && same == sy; |
| 496 | if (same) release(same); | 497 | if (same) release(same); |
| 497 | } | 498 | } |
| 498 | check(all, "IXSystemImpl5 answers for every interface it inherits (IXSystemImpl .. IXSystemImpl4)"); | 499 | check(all_inherited, "IXSystemImpl5 answers for every interface it inherits (IXSystemImpl .. IXSystemImpl4)"); |
| 499 | check(reinterpret_cast<IdQuery>(slot(sy, 5))(sy, sizeof(buf), buf, &used) == S_OK && used == 45 && | 500 | check(reinterpret_cast<IdQuery>(slot(sy, 5))(sy, sizeof(buf), buf, &used) == S_OK && used == 45 && |
| 500 | reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 44, buf, &used) == | 501 | reinterpret_cast<IdQuery>(slot(sy, 5))(sy, 44, buf, &used) == |
| 501 | HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && | 502 | HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && |
| @@ -512,6 +513,186 @@ void check_run_time_load() { | |||
| 512 | "slots 6-8 (handle tracking, handle check, download bandwidth) answer offline"); | 513 | "slots 6-8 (handle tracking, handle check, download bandwidth) answer offline"); |
| 513 | release(sy); | 514 | release(sy); |
| 514 | } | 515 | } |
| 516 | |||
| 517 | // XPackageImpl, asked for as libHttpClient.GDK.dll does: the class id with IXPackageImpl3's interface id. The | ||
| 518 | // slots with an offline answer agree with the named exports; the others are E_NOTIMPL. | ||
| 519 | const GUID package_cls = {0xaf406016, 0xe850, 0x4aa8, {0xa8, 0x8d, 0x2f, 0x3d, 0xcb, 0x9d, 0xac, 0x7e}}; | ||
| 520 | const GUID package3 = {0xe2a4734b, 0x2f4a, 0x456d, {0xaa, 0x8f, 0xd0, 0x65, 0xe0, 0x4f, 0xb2, 0x09}}; | ||
| 521 | void* pk = nullptr; | ||
| 522 | check(query(&package_cls, package3, &pk) == S_OK && pk, "QueryApiImpl hands out XPackageImpl for IXPackageImpl3"); | ||
| 523 | if (pk) { | ||
| 524 | using Ident = HRESULT(STDMETHODCALLTYPE*)(void*, size_t, char*); | ||
| 525 | using IdentExport = HRESULT(__stdcall*)(size_t, char*); | ||
| 526 | char a[64] = {}, b[64] = {}; | ||
| 527 | const auto ident_export = reinterpret_cast<IdentExport>( | ||
| 528 | rt::shims::find("xgameruntime.dll", "XPackageGetCurrentProcessPackageIdentifier")); | ||
| 529 | check(reinterpret_cast<Ident>(slot(pk, 3))(pk, sizeof(a), a) == S_OK && ident_export && | ||
| 530 | ident_export(sizeof(b), b) == S_OK && std::strcmp(a, b) == 0, | ||
| 531 | "slot 3 is XPackageGetCurrentProcessPackageIdentifier, the same answer as the export"); | ||
| 532 | using IsPackaged = bool(STDMETHODCALLTYPE*)(void*); | ||
| 533 | using IsPackagedExport = bool(__stdcall*)(); | ||
| 534 | const auto packaged_export = | ||
| 535 | reinterpret_cast<IsPackagedExport>(rt::shims::find("xgameruntime.dll", "XPackageIsPackagedProcess")); | ||
| 536 | check(packaged_export && reinterpret_cast<IsPackaged>(slot(pk, 4))(pk) == packaged_export(), | ||
| 537 | "slot 4 is XPackageIsPackagedProcess"); | ||
| 538 | // Slot 11, XPackageGetUserLocale: one of the package's declared locales, never the host's; nothing written | ||
| 539 | // (but S_OK) when the package declares none. | ||
| 540 | using Locale = HRESULT(STDMETHODCALLTYPE*)(void*, size_t, char*); | ||
| 541 | char tmp[MAX_PATH] = {}; | ||
| 542 | GetTempPathA(sizeof(tmp), tmp); | ||
| 543 | const std::string game = std::string(tmp) + "leonida_xpackage_locale_test"; | ||
| 544 | CreateDirectoryA(game.c_str(), nullptr); | ||
| 545 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", game.c_str()); | ||
| 546 | char locale[128]; | ||
| 547 | std::memset(locale, 'z', sizeof(locale)); | ||
| 548 | check(reinterpret_cast<Locale>(slot(pk, 11))(pk, sizeof(locale), locale) == S_OK && locale[0] == 'z', | ||
| 549 | "slot 11 without declared locales: S_OK and nothing written"); | ||
| 550 | if (FILE* f = std::fopen((game + "\\MicrosoftGame.Config").c_str(), "wb")) { | ||
| 551 | std::fputs("<Game><Resources><Resource Language=\"zz-ZZ\"/><Resource Language='xx-YY'/></Resources></Game>", | ||
| 552 | f); | ||
| 553 | std::fclose(f); | ||
| 554 | } | ||
| 555 | check(reinterpret_cast<Locale>(slot(pk, 11))(pk, sizeof(locale), locale) == S_OK && | ||
| 556 | (std::strcmp(locale, "zz-ZZ") == 0 || std::strcmp(locale, "xx-YY") == 0) && | ||
| 557 | reinterpret_cast<Locale>(slot(pk, 11))(pk, 3, locale) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), | ||
| 558 | "slot 11 gives one of the package's declared locales, not the host's; a short buffer is refused"); | ||
| 559 | DeleteFileA((game + "\\MicrosoftGame.Config").c_str()); | ||
| 560 | RemoveDirectoryA(game.c_str()); | ||
| 561 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); | ||
| 562 | { | ||
| 563 | // A game folder outside every ANSI code page (U+16A0, a runic letter) reaches MicrosoftGame.Config intact. | ||
| 564 | wchar_t wtmp[MAX_PATH] = {}; | ||
| 565 | GetTempPathW(MAX_PATH, wtmp); | ||
| 566 | const std::wstring wide = std::wstring(wtmp) + L"leonida_xpackage_\u16a0ocale"; | ||
| 567 | CreateDirectoryW(wide.c_str(), nullptr); | ||
| 568 | SetEnvironmentVariableW(L"LEONIDA_GAME_DIR", wide.c_str()); | ||
| 569 | const std::wstring wconfig = wide + L"\\MicrosoftGame.Config"; | ||
| 570 | if (FILE* f = _wfopen(wconfig.c_str(), L"wb")) { | ||
| 571 | std::fputs("<Game><Resources><Resource Language=\"qq-QQ\"/></Resources></Game>", f); | ||
| 572 | std::fclose(f); | ||
| 573 | } | ||
| 574 | char wlocale[32] = {}; | ||
| 575 | check(reinterpret_cast<Locale>(slot(pk, 11))(pk, sizeof(wlocale), wlocale) == S_OK && | ||
| 576 | std::strcmp(wlocale, "qq-QQ") == 0, | ||
| 577 | "slot 11 reads MicrosoftGame.Config from a game folder named outside the ANSI code page"); | ||
| 578 | DeleteFileW(wconfig.c_str()); | ||
| 579 | RemoveDirectoryW(wide.c_str()); | ||
| 580 | SetEnvironmentVariableW(L"LEONIDA_GAME_DIR", nullptr); | ||
| 581 | } | ||
| 582 | // Slots 23-26 are the named exports' content-package mounts: XPackageMount, the path size and path of the | ||
| 583 | // handle, and closing it. XPackageMountHandle is one u64, passed by value. | ||
| 584 | using Mount = HRESULT(STDMETHODCALLTYPE*)(void*, const char*, uint64_t*); | ||
| 585 | using PathSize = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t, size_t*); | ||
| 586 | using Path = HRESULT(STDMETHODCALLTYPE*)(void*, uint64_t, size_t, char*); | ||
| 587 | using CloseMount = void(STDMETHODCALLTYPE*)(void*, uint64_t); | ||
| 588 | SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", "SLOTDLC_12345678901234567890123=C:\\LeonidaSlotDLC"); | ||
| 589 | uint64_t handle = 0; | ||
| 590 | size_t need = 0; | ||
| 591 | char path[MAX_PATH] = {}; | ||
| 592 | check(reinterpret_cast<Mount>(slot(pk, 23))(pk, "SLOTDLC_12345678901234567890123", &handle) == S_OK && | ||
| 593 | handle != 0, | ||
| 594 | "slot 23 (XPackageMount) mounts a content package and hands out a handle"); | ||
| 595 | check(reinterpret_cast<PathSize>(slot(pk, 24))(pk, handle, &need) == S_OK && | ||
| 596 | need == std::strlen("C:\\LeonidaSlotDLC") + 1 && | ||
| 597 | reinterpret_cast<Path>(slot(pk, 25))(pk, handle, need, path) == S_OK && | ||
| 598 | std::strcmp(path, "C:\\LeonidaSlotDLC") == 0 && | ||
| 599 | reinterpret_cast<Path>(slot(pk, 25))(pk, handle, need - 1, path) == | ||
| 600 | HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), | ||
| 601 | "slots 24/25: the mount's path, and exactly the size XPackageGetMountPath needs"); | ||
| 602 | reinterpret_cast<CloseMount>(slot(pk, 26))(pk, handle); | ||
| 603 | check(reinterpret_cast<PathSize>(slot(pk, 24))(pk, handle, &need) == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), | ||
| 604 | "slot 26 (XPackageCloseMountHandle) closes the handle"); | ||
| 605 | SetEnvironmentVariableA("LEONIDA_CONTENT_PACKAGES", nullptr); | ||
| 606 | using Stub = HRESULT(STDMETHODCALLTYPE*)(void*); | ||
| 607 | check(reinterpret_cast<Stub>(slot(pk, 5))(pk) == E_NOTIMPL && reinterpret_cast<Stub>(slot(pk, 40))(pk) == E_NOTIMPL, | ||
| 608 | "the slots without an offline answer (5, 40) are E_NOTIMPL"); | ||
| 609 | struct Progress { | ||
| 610 | uint64_t total, installed, launch; | ||
| 611 | bool launchable, completed; | ||
| 612 | } progress{~0ull, 7, 7, false, false}; | ||
| 613 | using GetProgress = void(STDMETHODCALLTYPE*)(void*, void*, Progress*); | ||
| 614 | reinterpret_cast<GetProgress>(slot(pk, 7))(pk, nullptr, &progress); | ||
| 615 | check(progress.launchable && progress.completed && progress.installed == progress.total, | ||
| 616 | "slot 7 (void XPackageGetInstallationProgress) writes an installed, launchable, completed package"); | ||
| 617 | using Update = bool(STDMETHODCALLTYPE*)(void*, void*); | ||
| 618 | using UnregProgress = bool(STDMETHODCALLTYPE*)(void*, void*, XTaskQueueRegistrationToken, bool); | ||
| 619 | using UnregInstalled = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueRegistrationToken, bool); | ||
| 620 | using Uninstall = bool(STDMETHODCALLTYPE*)(void*, const char*); | ||
| 621 | check(!reinterpret_cast<Update>(slot(pk, 8))(pk, nullptr) && | ||
| 622 | reinterpret_cast<UnregProgress>(slot(pk, 10))(pk, nullptr, XTaskQueueRegistrationToken{1}, true) && | ||
| 623 | reinterpret_cast<UnregInstalled>(slot(pk, 22))(pk, XTaskQueueRegistrationToken{1}, false) && | ||
| 624 | !reinterpret_cast<Uninstall>(slot(pk, 34))(pk, "pkg"), | ||
| 625 | "the bool slots 8, 10, 22 and 34 return their documented offline answers"); | ||
| 626 | const GUID chain[] = { | ||
| 627 | package_cls, | ||
| 628 | {0x3720de07, 0xe8e4, 0x44a3, {0xad, 0x32, 0xb3, 0x59, 0xe8, 0xad, 0xbe, 0x55}}, | ||
| 629 | {0xf92d8712, 0x2b27, 0x4d8a, {0xbf, 0x01, 0x11, 0xa6, 0xf8, 0xe3, 0xeb, 0x42}}, | ||
| 630 | package3}; | ||
| 631 | bool all = true; | ||
| 632 | for (const GUID& iid : chain) { | ||
| 633 | void* same = nullptr; | ||
| 634 | all = all && query(&package_cls, iid, &same) == S_OK && same == pk; | ||
| 635 | if (same) release(same); | ||
| 636 | } | ||
| 637 | check(all, "IXPackageImpl3 answers for IXPackageImpl and IXPackageImpl2 too"); | ||
| 638 | release(pk); | ||
| 639 | } | ||
| 640 | { | ||
| 641 | // XGameImpl (IXGameImpl3 : IXGameImpl2 : IXGameImpl, xgameruntime include/xgame.idl); IXGameImpl's id is the | ||
| 642 | // class id. Slots: 3 XGameGetXboxTitleId, 4 XLaunchNewGame (void), 5 XLaunchRestartOnCrash. | ||
| 643 | const GUID game_cls = {0x973a344e, 0x24bf, 0x4d0f, {0x84, 0x57, 0x56, 0xc5, 0x34, 0x89, 0x2b, 0x29}}; | ||
| 644 | const GUID game2 = {0x50849859, 0x0ad8, 0x4f81, {0x80, 0xe4, 0x5b, 0xc7, 0x86, 0x26, 0xf8, 0x52}}; | ||
| 645 | const GUID game3 = {0x2549f142, 0x6419, 0x4a06, {0x97, 0xb5, 0x93, 0x1a, 0xab, 0x7c, 0x2f, 0x34}}; | ||
| 646 | void* g = get(game_cls); | ||
| 647 | check(g != nullptr, "QueryApiImpl hands out XGameImpl for its class id"); | ||
| 648 | bool every = g != nullptr; | ||
| 649 | for (const GUID& iid : {game2, game3}) { | ||
| 650 | void* same = nullptr; | ||
| 651 | every = every && query(&game_cls, iid, &same) == S_OK && same == g; | ||
| 652 | if (same) release(same); | ||
| 653 | } | ||
| 654 | check(every, "XGameImpl answers for IXGameImpl2's and IXGameImpl3's ids, the same object"); | ||
| 655 | if (g) { | ||
| 656 | using TitleId = HRESULT(STDMETHODCALLTYPE*)(void*, uint32_t*); | ||
| 657 | using LaunchNew = void(STDMETHODCALLTYPE*)(void*, const char*, const char*, void*); | ||
| 658 | using Restart = HRESULT(STDMETHODCALLTYPE*)(void*, const char*, uint32_t); | ||
| 659 | char tmp[MAX_PATH] = {}; | ||
| 660 | GetTempPathA(sizeof(tmp), tmp); | ||
| 661 | const std::string game = std::string(tmp) + "leonida_xgame_title_test"; | ||
| 662 | CreateDirectoryA(game.c_str(), nullptr); | ||
| 663 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", game.c_str()); | ||
| 664 | const std::string config = game + "\\MicrosoftGame.Config"; | ||
| 665 | auto write_config = [&](const char* text) { | ||
| 666 | if (FILE* f = std::fopen(config.c_str(), "wb")) { | ||
| 667 | std::fputs(text, f); | ||
| 668 | std::fclose(f); | ||
| 669 | } | ||
| 670 | }; | ||
| 671 | uint32_t id = 0x5a5a5a5a; | ||
| 672 | DeleteFileA(config.c_str()); | ||
| 673 | check(reinterpret_cast<TitleId>(slot(g, 3))(g, &id) == E_FAIL && id == 0x5a5a5a5a, | ||
| 674 | "slot 3 (XGameGetXboxTitleId) without a config: E_FAIL, nothing written"); | ||
| 675 | write_config("<Game configVersion=\"1\">\n <TitleId> 1a2B3c4D </TitleId>\n</Game>\n"); | ||
| 676 | check(reinterpret_cast<TitleId>(slot(g, 3))(g, &id) == S_OK && id == 0x1A2B3C4Du, | ||
| 677 | "slot 3 gives the config's <TitleId> (hex, either case, whitespace allowed)"); | ||
| 678 | check(reinterpret_cast<TitleId>(slot(g, 3))(g, nullptr) == E_INVALIDARG, | ||
| 679 | "slot 3 with a null pointer is E_INVALIDARG"); | ||
| 680 | write_config("<Game><TitleId>not-hex</TitleId></Game>"); | ||
| 681 | id = 0x5a5a5a5a; | ||
| 682 | check(reinterpret_cast<TitleId>(slot(g, 3))(g, &id) == E_FAIL && id == 0x5a5a5a5a, | ||
| 683 | "slot 3 refuses a <TitleId> that is not hex"); | ||
| 684 | write_config("<Game><TitleId>123456789</TitleId></Game>"); | ||
| 685 | check(reinterpret_cast<TitleId>(slot(g, 3))(g, &id) == E_FAIL, "slot 3 refuses more than 8 hex digits"); | ||
| 686 | DeleteFileA(config.c_str()); | ||
| 687 | RemoveDirectoryA(game.c_str()); | ||
| 688 | SetEnvironmentVariableA("LEONIDA_GAME_DIR", nullptr); | ||
| 689 | reinterpret_cast<LaunchNew>(slot(g, 4))(g, "other.exe", "", nullptr); | ||
| 690 | check(true, "slot 4 (void XLaunchNewGame) returns offline"); | ||
| 691 | check(reinterpret_cast<Restart>(slot(g, 5))(g, "--restarted", 0) == S_OK, | ||
| 692 | "slot 5 (XLaunchRestartOnCrash) succeeds offline"); | ||
| 693 | release(g); | ||
| 694 | } | ||
| 695 | } | ||
| 515 | check(uninit_api() == S_OK, "UninitializeApiImpl succeeds"); | 696 | check(uninit_api() == S_OK, "UninitializeApiImpl succeeds"); |
| 516 | 697 | ||
| 517 | HMODULE k32 = load_w(L"kernel32.dll"); | 698 | HMODULE k32 = load_w(L"kernel32.dll"); |