diff --git a/README.md b/README.md index 9990005..a143d9e 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ only uses the game server functions. `gameserveritem_t`. A request released, or a query cancelled, from a callback answers no more at once, and Steam releases or cancels it after the dispatcher returns. Client shutdown releases and cancels the rest. Favorites and history (MatchMaking009): count, - add and remove. Friends018: a friend's persona name and game; Apps009: VAC ban status. + add and remove. Friends018: a user's persona name, game, relationship and avatar image handles; + Utils011: the size and RGBA pixels of those images; Apps009: VAC ban status. * Events: ClientGameServerDeny, GameServerChangeRequested and GameOverlayActivated reach the client callback during `SteamBridge_HostRunCallbacks`, and FavoritesListChanged and PersonaStateChange the separate matchmaking callback; SteamServersConnected, @@ -149,7 +150,7 @@ send results, delivery and dropping, cleanup, session-owned port destruction, th server's FakeIP request and result event, diagnostics forwarding, and server browsing: list kinds and filters, details, refresh and cancellation calls, list, ping and player answers, deferred release and cancellation from callbacks, release and cancellation at -shutdown, favorites, friends, VAC status and the matchmaking events. On Windows it also +shutdown, favorites, friends, avatars and their images, VAC status and the matchmaking events. On Windows it also covers plugin mode: absent/uninitialized Steam, legacy (x86) and intermediate-modern exports, exact-version availability and retry, SteamID/screenshots, cookie/certificate forwarding, stream events, context isolation, cancellation and reentrant destruction. diff --git a/include/SteamAPIBridge.h b/include/SteamAPIBridge.h index b17cdfb..6a7fce5 100644 --- a/include/SteamAPIBridge.h +++ b/include/SteamAPIBridge.h @@ -430,6 +430,33 @@ extern "C" STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_FriendsGetPersonaName(uint64_t steamID, char* name, uint32_t capacity); // SB_FAILED: the friend is not in a game. STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_FriendsGetGamePlayed(uint64_t steamID, SteamBridgeFriendGame* game); + // Relationship values are Steam's EFriendRelationship. + enum + { + SB_FRIEND_RELATIONSHIP_NONE = 0, + SB_FRIEND_RELATIONSHIP_BLOCKED = 1, + SB_FRIEND_RELATIONSHIP_REQUEST_RECIPIENT = 2, + SB_FRIEND_RELATIONSHIP_FRIEND = 3, + SB_FRIEND_RELATIONSHIP_REQUEST_INITIATOR = 4, + SB_FRIEND_RELATIONSHIP_IGNORED = 5, + SB_FRIEND_RELATIONSHIP_IGNORED_FRIEND = 6 + }; + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_FriendsGetRelationship(uint64_t steamID, int32_t* relationship); + // Avatar sizes: 32x32, 64x64 and 184x184 pixels. + enum + { + SB_AVATAR_SMALL = 1, + SB_AVATAR_MEDIUM = 2, + SB_AVATAR_LARGE = 3 + }; + // The image handle of the user's avatar, as Steam returns it: 0 when the user has none, -1 while Steam + // is still loading it (ask again later). Read the image with SteamBridge_UtilsGetImageSize and + // SteamBridge_UtilsGetImageRGBA. + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_FriendsGetAvatar(uint64_t steamID, uint32_t size, int32_t* image); + + // Images (ISteamUtils). SB_FAILED: no such image, or rgba holds less than 4 * width * height bytes. + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UtilsGetImageSize(int32_t image, uint32_t* width, uint32_t* height); + STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_UtilsGetImageRGBA(int32_t image, uint8_t* rgba, uint32_t capacity); STEAMBRIDGE_API SteamBridgeStatus STEAMBRIDGE_CALL SteamBridge_AppsIsVACBanned(uint32_t* banned); #ifdef __cplusplus diff --git a/src/Host.cpp b/src/Host.cpp index 0a26f9e..91a159f 100644 --- a/src/Host.cpp +++ b/src/Host.cpp @@ -73,6 +73,7 @@ struct Host UnregisterFn unregisterCallback{}; ISteamUser* user{}; ISteamFriends* friends{}; + ISteamUtils* steamUtils{}; ISteamApps* apps{}; ISteamMatchmaking* matchmaking{}; ISteamMatchmakingServers* servers{}; @@ -405,6 +406,8 @@ SteamBridgeStatus SteamBridge_HostInit(const char* runtimePath, uint32_t initial h.sockets = static_cast(h.findUser(steamUser, STEAMNETWORKINGSOCKETS_INTERFACE_VERSION)); // The networking utilities are global, not per user (SteamNetworkingUtils_SteamAPI). h.utils = static_cast(h.findUser(0, STEAMNETWORKINGUTILS_INTERFACE_VERSION)); + // So are the Steam utilities (SteamUtils). + h.steamUtils = static_cast(h.findUser(0, STEAMUTILS_INTERFACE_VERSION)); } h.clientFn = host.clientFn; h.clientUser = host.clientUser; @@ -1134,6 +1137,48 @@ SteamBridgeStatus SteamBridge_FriendsGetGamePlayed(uint64_t steamID, SteamBridge game->lobbySteamID = info.m_steamIDLobby.ConvertToUint64(); return SB_OK; } +SteamBridgeStatus SteamBridge_FriendsGetRelationship(uint64_t steamID, int32_t* relationship) +{ + if (!relationship) return SB_INVALID_ARGUMENT; + *relationship = SB_FRIEND_RELATIONSHIP_NONE; + if (!host.friends) return SB_UNAVAILABLE; + *relationship = host.friends->GetFriendRelationship(CSteamID(uint64(steamID))); + return SB_OK; +} +SteamBridgeStatus SteamBridge_FriendsGetAvatar(uint64_t steamID, uint32_t size, int32_t* image) +{ + if (!image) return SB_INVALID_ARGUMENT; + *image = 0; + if (size != SB_AVATAR_SMALL && size != SB_AVATAR_MEDIUM && size != SB_AVATAR_LARGE) return SB_INVALID_ARGUMENT; + if (!host.friends) return SB_UNAVAILABLE; + const CSteamID id{uint64(steamID)}; + switch (size) + { + case SB_AVATAR_SMALL: *image = host.friends->GetSmallFriendAvatar(id); break; + case SB_AVATAR_MEDIUM: *image = host.friends->GetMediumFriendAvatar(id); break; + default: *image = host.friends->GetLargeFriendAvatar(id); break; + } + return SB_OK; +} + +SteamBridgeStatus SteamBridge_UtilsGetImageSize(int32_t image, uint32_t* width, uint32_t* height) +{ + if (!width || !height) return SB_INVALID_ARGUMENT; + *width = 0; + *height = 0; + if (!host.steamUtils) return SB_UNAVAILABLE; + uint32 nativeWidth{}, nativeHeight{}; + if (!host.steamUtils->GetImageSize(image, &nativeWidth, &nativeHeight)) return SB_FAILED; + *width = nativeWidth; + *height = nativeHeight; + return SB_OK; +} +SteamBridgeStatus SteamBridge_UtilsGetImageRGBA(int32_t image, uint8_t* rgba, uint32_t capacity) +{ + if (!rgba || !capacity || capacity > uint32_t(INT32_MAX)) return SB_INVALID_ARGUMENT; + if (!host.steamUtils) return SB_UNAVAILABLE; + return Result(host.steamUtils->GetImageRGBA(image, rgba, int(capacity))); +} SteamBridgeStatus SteamBridge_AppsIsVACBanned(uint32_t* banned) { if (!banned) return SB_INVALID_ARGUMENT; diff --git a/tests/Host.cpp b/tests/Host.cpp index c6fc4d3..1441fd0 100644 --- a/tests/Host.cpp +++ b/tests/Host.cpp @@ -162,6 +162,9 @@ void Client(const char* mock) char name[4] = "x"; assert(SB_UNAVAILABLE == SteamBridge_UserGetPersonaName(name, sizeof(name))); assert(0 == name[0]); + int32_t image = 1, relationship = 1; + assert(SB_UNAVAILABLE == SteamBridge_FriendsGetAvatar(76561198000000005, SB_AVATAR_SMALL, &image) && 0 == image); + assert(SB_UNAVAILABLE == SteamBridge_FriendsGetRelationship(76561198000000005, &relationship) && SB_FRIEND_RELATIONSHIP_NONE == relationship); uint32_t subscribed = 1; assert(SB_UNAVAILABLE == SteamBridge_UserIsSubscribedApp(70, &subscribed)); assert(0 == subscribed); @@ -444,6 +447,24 @@ void Servers(const char* mock) assert(SB_OK == SteamBridge_FriendsGetGamePlayed(76561198000000005, &game)); assert(70 == game.gameID && 0x0a000002 == game.ip && 27015 == game.gamePort && 27016 == game.queryPort && 76561198000000006 == game.lobbySteamID); assert(SB_FAILED == SteamBridge_FriendsGetGamePlayed(1, &game) && 0 == game.gameID && 0 == game.ip); + int32_t relationship = -1; + assert(SB_OK == SteamBridge_FriendsGetRelationship(76561198000000005, &relationship) && SB_FRIEND_RELATIONSHIP_IGNORED_FRIEND == relationship); + assert(SB_OK == SteamBridge_FriendsGetRelationship(1, &relationship) && SB_FRIEND_RELATIONSHIP_NONE == relationship); + assert(SB_INVALID_ARGUMENT == SteamBridge_FriendsGetRelationship(1, nullptr)); + int32_t image = 1; + assert(SB_OK == SteamBridge_FriendsGetAvatar(76561198000000005, SB_AVATAR_SMALL, &image) && 7 == image); + assert(SB_OK == SteamBridge_FriendsGetAvatar(76561198000000005, SB_AVATAR_MEDIUM, &image) && -1 == image); + assert(SB_OK == SteamBridge_FriendsGetAvatar(76561198000000005, SB_AVATAR_LARGE, &image) && 0 == image); + image = 1; + assert(SB_INVALID_ARGUMENT == SteamBridge_FriendsGetAvatar(76561198000000005, 0, &image) && 0 == image); + uint32_t width = 9, height = 9; + assert(SB_OK == SteamBridge_UtilsGetImageSize(7, &width, &height) && 2 == width && 1 == height); + assert(SB_FAILED == SteamBridge_UtilsGetImageSize(8, &width, &height) && 0 == width && 0 == height); + assert(SB_INVALID_ARGUMENT == SteamBridge_UtilsGetImageSize(7, nullptr, &height)); + uint8_t rgba[8]{}; + assert(SB_OK == SteamBridge_UtilsGetImageRGBA(7, rgba, sizeof(rgba)) && 0x11 == rgba[0] && 0x88 == rgba[7]); + assert(SB_FAILED == SteamBridge_UtilsGetImageRGBA(7, rgba, sizeof(rgba) - 1)); + assert(SB_INVALID_ARGUMENT == SteamBridge_UtilsGetImageRGBA(7, rgba, 0)); uint32_t banned{}; assert(SB_OK == SteamBridge_AppsIsVACBanned(&banned) && banned); assert(SB_INVALID_ARGUMENT == SteamBridge_AppsIsVACBanned(nullptr)); @@ -456,6 +477,9 @@ void Servers(const char* mock) assert(released + 1 == forwarded()->listsReleased && cancelled + 1 == forwarded()->queriesCancelled); assert(SB_INVALID_ARGUMENT == SteamBridge_ServersRefreshQuery(request)); assert(SB_UNAVAILABLE == SteamBridge_AppsIsVACBanned(&banned) && 0 == banned); + assert(SB_UNAVAILABLE == SteamBridge_FriendsGetAvatar(76561198000000005, SB_AVATAR_SMALL, &image) && 0 == image); + assert(SB_UNAVAILABLE == SteamBridge_UtilsGetImageSize(7, &width, &height) && 0 == width && 0 == height); + assert(SB_UNAVAILABLE == SteamBridge_UtilsGetImageRGBA(7, rgba, sizeof(rgba))); SteamBridge_HostSetMatchmakingCallback(nullptr, nullptr); SteamBridge_HostSetClientCallback(nullptr, nullptr); setFriends(0); diff --git a/tests/HostStubs.h b/tests/HostStubs.h index 364e038..ab3b3ff 100644 --- a/tests/HostStubs.h +++ b/tests/HostStubs.h @@ -1,6 +1,6 @@ #pragma once // Empty implementations of every SteamUser023, SteamApps009, SteamGameServer015, SteamNetworkingSockets013, -// SteamNetworkingUtils004, SteamMatchMaking009, SteamMatchMakingServers003 and SteamFriends018 method, +// SteamNetworkingUtils004, SteamMatchMaking009, SteamMatchMakingServers003, SteamFriends018 and SteamUtils011 method, // generated from the Steamworks SDK v1.65 declarations. Mocks override the methods they exercise. #include #include @@ -355,3 +355,47 @@ class StubFriends : public ISteamFriends const char* GetProfileItemPropertyString(CSteamID steamID, ECommunityProfileItemType itemType, ECommunityProfileItemProperty prop) override { return {}; } uint32 GetProfileItemPropertyUint(CSteamID steamID, ECommunityProfileItemType itemType, ECommunityProfileItemProperty prop) override { return {}; } }; +class StubUtils : public ISteamUtils +{ +public: + uint32 GetSecondsSinceAppActive() override { return {}; } + uint32 GetSecondsSinceComputerActive() override { return {}; } + EUniverse GetConnectedUniverse() override { return {}; } + uint32 GetServerRealTime() override { return {}; } + const char* GetIPCountry() override { return {}; } + bool GetImageSize(int iImage, uint32* pnWidth, uint32* pnHeight) override { return {}; } + bool GetImageRGBA(int iImage, uint8* pubDest, int nDestBufferSize) override { return {}; } + uint8 GetCurrentBatteryPower() override { return {}; } + uint32 GetAppID() override { return {}; } + void SetOverlayNotificationPosition(ENotificationPosition eNotificationPosition) override {} + bool IsAPICallCompleted(SteamAPICall_t hSteamAPICall, bool* pbFailed) override { return {}; } + ESteamAPICallFailure GetAPICallFailureReason(SteamAPICall_t hSteamAPICall) override { return {}; } + bool GetAPICallResult(SteamAPICall_t hSteamAPICall, void* pCallback, int cubCallback, int iCallbackExpected, bool* pbFailed) override { return {}; } + void RunFrame() override {} + uint32 GetIPCCallCount() override { return {}; } + void SetWarningMessageHook(SteamAPIWarningMessageHook_t pFunction) override {} + bool IsOverlayEnabled() override { return {}; } + bool BOverlayNeedsPresent() override { return {}; } + SteamAPICall_t CheckFileSignature(const char* szFileName) override { return {}; } + bool ShowGamepadTextInput(EGamepadTextInputMode eInputMode, EGamepadTextInputLineMode eLineInputMode, const char* pchDescription, uint32 unCharMax, const char* pchExistingText) override { return {}; } + uint32 GetEnteredGamepadTextLength() override { return {}; } + bool GetEnteredGamepadTextInput(char* pchText, uint32 cchText) override { return {}; } + const char* GetSteamUILanguage() override { return {}; } + bool IsSteamRunningInVR() override { return {}; } + void SetOverlayNotificationInset(int nHorizontalInset, int nVerticalInset) override {} + bool IsSteamInBigPictureMode() override { return {}; } + void StartVRDashboard() override {} + bool IsVRHeadsetStreamingEnabled() override { return {}; } + void SetVRHeadsetStreamingEnabled(bool bEnabled) override {} + bool IsSteamChinaLauncher() override { return {}; } + bool InitFilterText(uint32 unFilterOptions) override { return {}; } + int FilterText(ETextFilteringContext eContext, CSteamID sourceSteamID, const char* pchInputMessage, char* pchOutFilteredText, uint32 nByteSizeOutFilteredText) override { return {}; } + ESteamIPv6ConnectivityState GetIPv6ConnectivityState(ESteamIPv6ConnectivityProtocol eProtocol) override { return {}; } + bool ShowFloatingGamepadTextInput(EFloatingGamepadTextInputMode eKeyboardMode, int nTextFieldXPosition, int nTextFieldYPosition, int nTextFieldWidth, int nTextFieldHeight) override { return {}; } + void SetGameLauncherMode(bool bLauncherMode) override {} + bool DismissFloatingGamepadTextInput() override { return {}; } + bool DismissGamepadTextInput() override { return {}; } + ESteamHardwareType IsRunningOnSteamHardware() override { return {}; } + ESteamHardwareDefaultConfig GetSteamHardwareDefaultConfig() override { return {}; } + bool IsRunningUnderProton() override { return {}; } +}; diff --git a/tests/MockHost.cpp b/tests/MockHost.cpp index c30e2ed..89ae954 100644 --- a/tests/MockHost.cpp +++ b/tests/MockHost.cpp @@ -220,8 +220,32 @@ class Friends final : public StubFriends info->m_steamIDLobby = CSteamID(uint64(76561198000000006)); return true; } + EFriendRelationship GetFriendRelationship(CSteamID id) override { return id.ConvertToUint64() == 76561198000000005 ? k_EFriendRelationshipIgnoredFriend : k_EFriendRelationshipNone; } + // The friend's small avatar is image 7, the medium one is still loading and there is no large one. + int GetSmallFriendAvatar(CSteamID id) override { return id.ConvertToUint64() == 76561198000000005 ? 7 : 0; } + int GetMediumFriendAvatar(CSteamID id) override { return id.ConvertToUint64() == 76561198000000005 ? -1 : 0; } } friends; +// Image 7 is 2x1 pixels. +const uint8 avatarPixels[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; +class Utils final : public StubUtils +{ +public: + bool GetImageSize(int image, uint32* width, uint32* height) override + { + if (image != 7) return false; + *width = 2; + *height = 1; + return true; + } + bool GetImageRGBA(int image, uint8* rgba, int capacity) override + { + if (image != 7 || capacity < int(sizeof(avatarPixels))) return false; + std::memcpy(rgba, avatarPixels, sizeof(avatarPixels)); + return true; + } +} steamUtils; + class GameServer final : public StubGameServer { public: @@ -372,6 +396,7 @@ extern "C" 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; + if (!std::strcmp(version, STEAMUTILS_INTERFACE_VERSION)) return clientInitialized && !steamUser ? &steamUtils : nullptr; return nullptr; } S_API ESteamAPIInitResult S_CALLTYPE SteamInternal_GameServer_Init_V2(uint32, uint16, uint16, EServerMode mode, const char*, const char* versions, SteamErrMsg*)