diff --git a/README.md b/README.md index ccd29df..33c76ab 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,9 @@ both leave the runtime unloaded. A dedicated server passes `initializeClient = 0 only uses the game server functions. * Client: game connection tickets (`InitiateGameConnection_DEPRECATED`), SteamID, - persona name, app subscription and voice (User023, Friends018, Apps009). Missing - interfaces make the corresponding calls return `SB_UNAVAILABLE`. + persona name, app subscription, current game language, low violence and voice + (User023, Friends018, Apps009). Missing interfaces make the corresponding calls return + `SB_UNAVAILABLE`. * Game server (`SteamBridge_ServerInit`): GameServer015 logon, server rules and heartbeats, ticket authentication (`SendUserConnectAndAuthenticate_DEPRECATED`), bots and shared-socket master server packets. The interface version list matches @@ -130,7 +131,8 @@ runtime for the target architecture beside the bridge, as host mode expects; ## Verification CTest covers, on every supported platform, absent runtimes and host mode against a -fixture runtime: client initialization failure and retry, connection tickets, voice +fixture runtime: client initialization failure and retry, connection tickets, app +subscription, game language (including truncation and a missing language), low violence, voice capture/decoding and non-OK voice results, client and game server event translation and dispatcher separation, deferred shutdown from callbacks, game server setters and authentication, packets, dedicated (server-only) sessions, and FakeIP ports: datagram diff --git a/include/SteamAPIBridge.h b/include/SteamAPIBridge.h index 5c52776..77467b0 100644 --- a/include/SteamAPIBridge.h +++ b/include/SteamAPIBridge.h @@ -181,6 +181,10 @@ extern "C" // Copies the persona name, truncated and NUL-terminated. STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserGetPersonaName(char* name, uint32_t capacity); STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserIsSubscribedApp(uint32_t appID, uint32_t* subscribed); + // Copies the running application's language ("english", "schinese", ...), truncated and + // NUL-terminated. + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserGetCurrentGameLanguage(char* language, uint32_t capacity); + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UserIsLowViolence(uint32_t* lowViolence); // Voice. Get and Decompress succeed only for Steam's k_EVoiceResultOK; any other // voice result returns SB_FAILED with zero lengths. diff --git a/src/Host.cpp b/src/Host.cpp index 10db8d6..c631f07 100644 --- a/src/Host.cpp +++ b/src/Host.cpp @@ -404,6 +404,24 @@ SteamBridgeStatus SteamBridge_UserIsSubscribedApp(uint32_t appID, uint32_t* subs *subscribed = host.apps->BIsSubscribedApp(appID); return SB_OK; } +SteamBridgeStatus SteamBridge_UserGetCurrentGameLanguage(char* language, uint32_t capacity) +{ + if (!language || !capacity) return SB_INVALID_ARGUMENT; + language[0] = 0; + if (!host.apps) return SB_UNAVAILABLE; + const char* current = host.apps->GetCurrentGameLanguage(); + if (!current) return SB_FAILED; + CopyText(language, capacity, current); + return SB_OK; +} +SteamBridgeStatus SteamBridge_UserIsLowViolence(uint32_t* lowViolence) +{ + if (!lowViolence) return SB_INVALID_ARGUMENT; + *lowViolence = 0; + if (!host.apps) return SB_UNAVAILABLE; + *lowViolence = host.apps->BIsLowViolence(); + return SB_OK; +} SteamBridgeStatus SteamBridge_VoiceStartRecording() { diff --git a/tests/Host.cpp b/tests/Host.cpp index d6775c0..cc11196 100644 --- a/tests/Host.cpp +++ b/tests/Host.cpp @@ -14,6 +14,7 @@ using QueueFn = void(S_CALLTYPE*)(int, int, const void*, int); using QueueFakeFn = void(S_CALLTYPE*)(int, uint32_t, uint16_t, int); using SetFakeIPFn = void(S_CALLTYPE*)(int, uint32_t, uint16_t); using EmitDebugFn = int(S_CALLTYPE*)(int, const char*); +using SetAppsFn = void(S_CALLTYPE*)(int, const char*, int); namespace mock { SetIntFn failInit, voiceResult; @@ -23,6 +24,7 @@ QueueFn queue; QueueFakeFn queueFake; SetFakeIPFn setFakeIP; EmitDebugFn emitDebug; +SetAppsFn setApps; } // namespace mock using namespace mock; @@ -79,6 +81,12 @@ void Unavailable(const char* missing) assert(0 == size); assert(SB_UNAVAILABLE == SteamBridge_ServerInit(0, 27015, 27015, SB_SERVER_MODE_SECURE, "1.0")); assert(0 == SteamBridge_VoiceGetOptimalSampleRate()); + char language[8] = "x"; + assert(SB_UNAVAILABLE == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language))); + assert(0 == language[0]); + uint32_t lowViolence = 1; + assert(SB_UNAVAILABLE == SteamBridge_UserIsLowViolence(&lowViolence)); + assert(0 == lowViolence); SteamBridge_HostRunCallbacks(); SteamBridge_HostShutdown(); } @@ -107,13 +115,20 @@ void Client(const char* mock) uint64_t id{}; assert(SB_OK == SteamBridge_UserGetSteamID(&id)); assert(76561198000000001 == id); - // The fixture exposes no SteamFriends/SteamApps; those calls report unavailability. + // The fixture exposes no SteamFriends, nor SteamApps until Apps enables it; those calls + // report unavailability. char name[4] = "x"; assert(SB_UNAVAILABLE == SteamBridge_UserGetPersonaName(name, sizeof(name))); assert(0 == name[0]); uint32_t subscribed = 1; assert(SB_UNAVAILABLE == SteamBridge_UserIsSubscribedApp(70, &subscribed)); assert(0 == subscribed); + char language[8] = "x"; + assert(SB_UNAVAILABLE == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language))); + assert(0 == language[0]); + uint32_t lowViolence = 1; + assert(SB_UNAVAILABLE == SteamBridge_UserIsLowViolence(&lowViolence)); + assert(0 == lowViolence); assert(SB_OK == SteamBridge_VoiceStartRecording()); uint32_t available{}; @@ -205,6 +220,42 @@ void Client(const char* mock) assert(SB_UNAVAILABLE == SteamBridge_UserGetSteamID(&id)); SteamBridge_HostSetClientCallback(nullptr, nullptr); } +void Apps(const char* mock) +{ + setApps(1, "schinese", 1); + assert(SB_OK == SteamBridge_HostInit(mock, 1)); + uint32_t subscribed{}; + assert(SB_OK == SteamBridge_UserIsSubscribedApp(70, &subscribed)); + assert(1 == subscribed); + assert(SB_OK == SteamBridge_UserIsSubscribedApp(10, &subscribed)); + assert(0 == subscribed); + char language[16]{}; + assert(SB_OK == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language))); + assert(!std::strcmp("schinese", language)); + char truncated[4]{}; + assert(SB_OK == SteamBridge_UserGetCurrentGameLanguage(truncated, sizeof(truncated))); + assert(!std::strcmp("sch", truncated)); + assert(SB_INVALID_ARGUMENT == SteamBridge_UserGetCurrentGameLanguage(nullptr, sizeof(language))); + assert(SB_INVALID_ARGUMENT == SteamBridge_UserGetCurrentGameLanguage(language, 0)); + uint32_t lowViolence{}; + assert(SB_OK == SteamBridge_UserIsLowViolence(&lowViolence)); + assert(1 == lowViolence); + assert(SB_INVALID_ARGUMENT == SteamBridge_UserIsLowViolence(nullptr)); + SteamBridge_HostShutdown(); + + // SteamApps without a language fails the query and still answers the others. + setApps(1, nullptr, 0); + assert(SB_OK == SteamBridge_HostInit(mock, 1)); + std::strcpy(language, "x"); + assert(SB_FAILED == SteamBridge_UserGetCurrentGameLanguage(language, sizeof(language))); + assert(0 == language[0]); + lowViolence = 1; + assert(SB_OK == SteamBridge_UserIsLowViolence(&lowViolence)); + assert(0 == lowViolence); + SteamBridge_HostShutdown(); + setApps(0, nullptr, 0); + assert(!SteamBridge_HostIsActive()); +} void DedicatedServer(const char* mock) { int shutdowns = mock::stat(MOCK_HOST_SHUTDOWNS); @@ -314,10 +365,12 @@ int main(int argc, char** argv) mock::queueFake = platform::Resolve(module, "MockHostQueueFakeMessage"); mock::setFakeIP = platform::Resolve(module, "MockHostSetFakeIP"); mock::emitDebug = platform::Resolve(module, "MockHostEmitDebug"); + mock::setApps = platform::Resolve(module, "MockHostSetApps"); assert(mock::failInit && mock::voiceResult && mock::stat && mock::forwarded && mock::queue); - assert(mock::queueFake && mock::setFakeIP && mock::emitDebug); + assert(mock::queueFake && mock::setFakeIP && mock::emitDebug && mock::setApps); Unavailable(argv[2]); Client(argv[1]); + Apps(argv[1]); DedicatedServer(argv[1]); platform::UnloadRuntime(module); } diff --git a/tests/HostStubs.h b/tests/HostStubs.h index 1427b5d..07133f7 100644 --- a/tests/HostStubs.h +++ b/tests/HostStubs.h @@ -1,6 +1,6 @@ #pragma once -// Empty implementations of every SteamUser023, SteamGameServer015, SteamNetworkingSockets013 and -// SteamNetworkingUtils004 method, generated from the Steamworks SDK v1.65 declarations. Mocks +// Empty implementations of every SteamUser023, SteamApps009, SteamGameServer015, SteamNetworkingSockets013 +// and SteamNetworkingUtils004 method, generated from the Steamworks SDK v1.65 declarations. Mocks // override the methods they exercise. #include #include @@ -42,6 +42,45 @@ class StubUser : public ISteamUser SteamAPICall_t GetDurationControl() override { return {}; } bool BSetDurationControlOnlineState(EDurationControlOnlineState eNewState) override { return {}; } }; +class StubApps : public ISteamApps +{ +public: + bool BIsSubscribed() override { return {}; } + bool BIsLowViolence() override { return {}; } + bool BIsCybercafe() override { return {}; } + bool BIsVACBanned() override { return {}; } + const char* GetCurrentGameLanguage() override { return {}; } + const char* GetAvailableGameLanguages() override { return {}; } + bool BIsSubscribedApp(AppId_t appID) override { return {}; } + bool BIsDlcInstalled(AppId_t appID) override { return {}; } + uint32 GetEarliestPurchaseUnixTime(AppId_t nAppID) override { return {}; } + bool BIsSubscribedFromFreeWeekend() override { return {}; } + int GetDLCCount() override { return {}; } + bool BGetDLCDataByIndex(int iDLC, AppId_t* pAppID, bool* pbAvailable, char* pchName, int cchNameBufferSize) override { return {}; } + void InstallDLC(AppId_t nAppID) override {} + void UninstallDLC(AppId_t nAppID) override {} + void RequestAppProofOfPurchaseKey(AppId_t nAppID) override {} + bool GetCurrentBetaName(char* pchName, int cchNameBufferSize) override { return {}; } + bool MarkContentCorrupt(bool bMissingFilesOnly) override { return {}; } + uint32 GetInstalledDepots(AppId_t appID, DepotId_t* pvecDepots, uint32 cMaxDepots) override { return {}; } + uint32 GetAppInstallDir(AppId_t appID, char* pchFolder, uint32 cchFolderBufferSize) override { return {}; } + bool BIsAppInstalled(AppId_t appID) override { return {}; } + CSteamID GetAppOwner() override { return {}; } + const char* GetLaunchQueryParam(const char* pchKey) override { return {}; } + bool GetDlcDownloadProgress(AppId_t nAppID, uint64* punBytesDownloaded, uint64* punBytesTotal) override { return {}; } + int GetAppBuildId() override { return {}; } + void RequestAllProofOfPurchaseKeys() override {} + SteamAPICall_t GetFileDetails(const char* pszFileName) override { return {}; } + int GetLaunchCommandLine(char* pszCommandLine, int cubCommandLine) override { return {}; } + bool BIsSubscribedFromFamilySharing() override { return {}; } + bool BIsTimedTrial(uint32* punSecondsAllowed, uint32* punSecondsPlayed) override { return {}; } + bool SetDlcContext(AppId_t nAppID) override { return {}; } + int GetNumBetas(int* pnAvailable, int* pnPrivate) override { return {}; } + bool GetBetaInfo(int iBetaIndex, uint32* punFlags, uint32* punBuildID, char* pchBetaName, int cchBetaName, char* pchDescription, int cchDescription, uint32* punLastUpdated) override { return {}; } + bool SetActiveBeta(const char* pchBetaName) override { return {}; } + void SetGamePerformanceSetting(EGamePerformanceSetting setting) override {} + void SetGameRenderResolution(uint32 unWidth, uint32 unHeight) override {} +}; class StubGameServer : public ISteamGameServer { public: diff --git a/tests/MockHost.cpp b/tests/MockHost.cpp index 302fca8..66d38ac 100644 --- a/tests/MockHost.cpp +++ b/tests/MockHost.cpp @@ -91,6 +91,17 @@ class User final : public StubUser uint32 GetVoiceOptimalSampleRate() override { return 24000; } } user; +// MockHostSetApps controls whether SteamApps exists and what it reports. +bool appsAvailable, appsHasLanguage, appsLowViolence; +char appsLanguage[32]; +class Apps final : public StubApps +{ +public: + bool BIsLowViolence() override { return appsLowViolence; } + const char* GetCurrentGameLanguage() override { return appsHasLanguage ? appsLanguage : nullptr; } + bool BIsSubscribedApp(AppId_t appID) override { return appID == 70; } +} apps; + class GameServer final : public StubGameServer { public: @@ -227,6 +238,7 @@ extern "C" S_API void* S_CALLTYPE SteamInternal_FindOrCreateUserInterface(HSteamUser steamUser, const char* version) { if (!std::strcmp(version, STEAMUSER_INTERFACE_VERSION)) return &user; + if (!std::strcmp(version, STEAMAPPS_INTERFACE_VERSION)) return appsAvailable ? &apps : nullptr; if (!std::strcmp(version, STEAMNETWORKINGSOCKETS_INTERFACE_VERSION)) return steamUser == 1 ? &clientSockets : nullptr; // The global utilities (user 0) exist once the client is initialized. if (!std::strcmp(version, STEAMNETWORKINGUTILS_INTERFACE_VERSION)) return clientInitialized && !steamUser ? &utils : nullptr; @@ -261,7 +273,15 @@ extern "C" // Fixture control. S_API void S_CALLTYPE MockHostSetFailInit(int value) { failInit = value; } S_API void S_CALLTYPE MockHostSetVoiceResult(int value) { voiceResult = value; } - S_API int S_CALLTYPE MockHostStat(int which) + // Applies to the next client initialization. A NULL language makes SteamApps return NULL. + S_API void S_CALLTYPE MockHostSetApps(int available, const char* language, int lowViolence) + { + appsAvailable = available != 0; + appsHasLanguage = language != nullptr; + appsLowViolence = lowViolence != 0; + std::snprintf(appsLanguage, sizeof(appsLanguage), "%s", language ? language : ""); + } + S_API int S_CALLTYPE MockHostStat(int which) { switch (which) {