diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index 42c219fe..0c17fae2 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -159,21 +159,56 @@ namespace Components Friends::UpdateState(); } - void Friends::ClearPresence(std::string key) + std::vector Friends::GetAppIdList() + { + std::vector ids; + + auto addId = [&](int id) + { + if(std::find(ids.begin(), ids.end(), id) == ids.end()) + { + ids.push_back(id); + } + }; + + addId(0); + addId(10190); + addId(480); + + if (Steam::Proxy::SteamUtils) + { + addId(Steam::Proxy::SteamUtils->GetAppID()); + } + + return ids; + } + + void Friends::SetRawPresence(const char* key, const char* value) { if (Steam::Proxy::ClientFriends) { - Steam::Proxy::ClientFriends.invoke("SetRichPresence", 0, key.data(), nullptr); - Steam::Proxy::ClientFriends.invoke("SetRichPresence", Steam::Proxy::AppId, key.data(), nullptr); + auto appIds = Friends::GetAppIdList(); + + for (auto id : appIds) + { + Steam::Proxy::ClientFriends.invoke("SetRichPresence", id, key, value); + } + } + } + + void Friends::ClearPresence(std::string key) + { + if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils) + { + Friends::SetRawPresence(key.data(), nullptr); } } void Friends::SetPresence(std::string key, std::string value) { - if (Steam::Proxy::ClientFriends && !Dvar::Var("cl_anonymous").get() && Steam::Enabled()) + if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils && !Dvar::Var("cl_anonymous").get() && Steam::Enabled()) { - Steam::Proxy::ClientFriends.invoke("SetRichPresence", 0, key.data(), value.data()); - Steam::Proxy::ClientFriends.invoke("SetRichPresence", Steam::Proxy::AppId, key.data(), value.data()); + Friends::SetRawPresence(key.data(), value.data()); } } @@ -181,17 +216,15 @@ namespace Components { if(Steam::Proxy::ClientFriends) { - Steam::Proxy::ClientFriends.invoke("RequestFriendRichPresence", 0, user); - Steam::Proxy::ClientFriends.invoke("RequestFriendRichPresence", Steam::Proxy::AppId, user); + Steam::Proxy::ClientFriends.invoke("RequestFriendRichPresence", Friends::GetGame(user), user); } } std::string Friends::GetPresence(SteamID user, std::string key) { - if (!Steam::Proxy::ClientFriends) return ""; + if (!Steam::Proxy::ClientFriends || !Steam::Proxy::SteamUtils) return ""; - std::string result = Steam::Proxy::ClientFriends.invoke("GetFriendRichPresence", Steam::Proxy::AppId, user, key.data()); - if (result.empty()) result = Steam::Proxy::ClientFriends.invoke("GetFriendRichPresence", 0, user, key.data()); + std::string result = Steam::Proxy::ClientFriends.invoke("GetFriendRichPresence", Friends::GetGame(user), user, key.data()); return result; } @@ -426,6 +459,19 @@ namespace Components } } + int Friends::GetGame(SteamID user) + { + int appId = 0; + + Steam::FriendGameInfo info; + if (Steam::Proxy::SteamFriends && Steam::Proxy::SteamFriends->GetFriendGamePlayed(user, &info)) + { + appId = info.m_gameID.appID; + } + + return appId; + } + void Friends::UpdateTimeStamp() { Friends::SetPresence("iw4x_playing", Utils::String::VA("%d", Steam::SteamUtils()->GetServerRealTime())); diff --git a/src/Components/Modules/Friends.hpp b/src/Components/Modules/Friends.hpp index 6ce24df9..21ab888f 100644 --- a/src/Components/Modules/Friends.hpp +++ b/src/Components/Modules/Friends.hpp @@ -25,6 +25,8 @@ namespace Components static void AddFriend(SteamID user); + static int GetGame(SteamID user); + private: #pragma pack(push, 4) struct FriendRichPresenceUpdate @@ -86,5 +88,8 @@ namespace Components static bool IsOnline(unsigned __int64 timeStamp); static void StoreFriendsList(); + + static void SetRawPresence(const char* key, const char* value); + static std::vector GetAppIdList(); }; } diff --git a/src/Steam/Interfaces/SteamFriends.cpp b/src/Steam/Interfaces/SteamFriends.cpp index d97d913b..6f1d1c06 100644 --- a/src/Steam/Interfaces/SteamFriends.cpp +++ b/src/Steam/Interfaces/SteamFriends.cpp @@ -51,7 +51,7 @@ namespace Steam return 0; } - bool Friends::GetFriendGamePlayed(SteamID steamIDFriend, void *pFriendGameInfo) + bool Friends::GetFriendGamePlayed(SteamID steamIDFriend, FriendGameInfo *pFriendGameInfo) { return false; } diff --git a/src/Steam/Interfaces/SteamFriends.hpp b/src/Steam/Interfaces/SteamFriends.hpp index a0881021..2b4ab668 100644 --- a/src/Steam/Interfaces/SteamFriends.hpp +++ b/src/Steam/Interfaces/SteamFriends.hpp @@ -2,12 +2,21 @@ namespace Steam { - struct FriendSessionStateInfo_t + struct FriendSessionStateInfo { uint32_t m_uiOnlineSessionInstances; uint8_t m_uiPublishedToFriendsSessionInstance; }; + struct FriendGameInfo + { + GameID_t m_gameID; + uint32_t m_unGameIP; + uint16_t m_usGamePort; + uint16_t m_usQueryPort; + SteamID m_steamIDLobby; + }; + class Friends { public: @@ -20,7 +29,7 @@ namespace Steam virtual int GetFriendPersonaState(SteamID steamIDFriend); virtual const char *GetFriendPersonaName(SteamID steamIDFriend); virtual int GetFriendAvatar(SteamID steamIDFriend, int eAvatarSize); - virtual bool GetFriendGamePlayed(SteamID steamIDFriend, void *pFriendGameInfo); + virtual bool GetFriendGamePlayed(SteamID steamIDFriend, FriendGameInfo *pFriendGameInfo); virtual const char *GetFriendPersonaNameHistory(SteamID steamIDFriend, int iPersonaName); virtual bool HasFriend(SteamID steamIDFriend, int eFriendFlags); virtual int GetClanCount(); @@ -49,7 +58,7 @@ namespace Steam virtual int GetFriendPersonaState(SteamID steamIDFriend) = 0; virtual const char *GetFriendPersonaName(SteamID steamIDFriend) = 0; virtual bool GetFriendGamePlayed(SteamID steamID, void *pGamePlayInfo) = 0; - virtual const char *GetFriendPersonaNameHistory(SteamID steamIDFriend, int iPersonaName) = 0; + virtual const char *GetFriendPersonaNameHistory(SteamID steamIDFriend, FriendGameInfo iPersonaName) = 0; virtual int GetFriendSteamLevel(SteamID steamIDFriend) = 0; virtual const char *GetPlayerNickname(SteamID steamIDPlayer) = 0; virtual int16_t GetFriendsGroupCount() = 0; diff --git a/src/Steam/Proxy.cpp b/src/Steam/Proxy.cpp index 79f70b1e..98987775 100644 --- a/src/Steam/Proxy.cpp +++ b/src/Steam/Proxy.cpp @@ -14,6 +14,7 @@ namespace Steam void* Proxy::SteamUser = nullptr; Friends15* Proxy::SteamFriends = nullptr; + Apps7* Proxy::SteamApps = nullptr; Utils* Proxy::SteamUtils = nullptr; User* Proxy::SteamUser_ = nullptr; @@ -108,13 +109,19 @@ namespace Steam void Proxy::SetMod(std::string mod) { - if (!Proxy::ClientUser || !Steam::Enabled() || Components::Dedicated::IsEnabled() || Components::ZoneBuilder::IsEnabled()) return; + if (!Proxy::ClientUser || !Proxy::SteamApps || !Steam::Enabled() || Components::Dedicated::IsEnabled() || Components::ZoneBuilder::IsEnabled()) return; + + if (!Proxy::SteamApps->BIsSubscribedApp(Proxy::AppId)) + { + Proxy::AppId = 480; // Spacewar - Steam's demo app + } GameID_t gameID; gameID.type = 1; // k_EGameIDTypeGameMod gameID.appID = Proxy::AppId & 0xFFFFFF; gameID.modID = 0xBAADF00D; + // Interface clientApps(Proxy::ClientEngine->GetIClientApps(Proxy::SteamUser, Proxy::SteamPipe, "CLIENTAPPS_INTERFACE_VERSION001")); // Interface clientShortcuts(Proxy::ClientEngine->GetIClientShortcuts(Proxy::SteamUser, Proxy::SteamPipe, "CLIENTSHORTCUTS_INTERFACE_VERSION001")); // if (!clientApps || !clientShortcuts) return; @@ -412,6 +419,9 @@ namespace Steam Proxy::ClientFriends = Proxy::ClientEngine->GetIClientFriends(Proxy::SteamUser, Proxy::SteamPipe, "CLIENTFRIENDS_INTERFACE_VERSION001"); if (!Proxy::ClientFriends) return false; + Proxy::SteamApps = reinterpret_cast(Proxy::SteamClient->GetISteamApps(Proxy::SteamUser, Proxy::SteamPipe, "STEAMAPPS_INTERFACE_VERSION007")); + if (!Proxy::SteamApps) return false; + Proxy::SteamFriends = reinterpret_cast(Proxy::SteamClient->GetISteamFriends(Proxy::SteamUser, Proxy::SteamPipe, "SteamFriends015")); if (!Proxy::SteamFriends) return false; diff --git a/src/Steam/Proxy.hpp b/src/Steam/Proxy.hpp index 3d42dad4..ecbf8605 100644 --- a/src/Steam/Proxy.hpp +++ b/src/Steam/Proxy.hpp @@ -102,6 +102,35 @@ namespace Steam virtual void *GetIClientVR(char const * pchVersion) = 0; }; + class Apps7 + { + public: + virtual bool BIsSubscribed() = 0; + virtual bool BIsLowViolence() = 0; + virtual bool BIsCybercafe() = 0; + virtual bool BIsVACBanned() = 0; + virtual const char *GetCurrentGameLanguage() = 0; + virtual const char *GetAvailableGameLanguages() = 0; + virtual bool BIsSubscribedApp(int nAppID) = 0; + virtual bool BIsDlcInstalled(int nAppID) = 0; + virtual uint32_t GetEarliestPurchaseUnixTime(int nAppID) = 0; + virtual bool BIsSubscribedFromFreeWeekend() = 0; + virtual int GetDLCCount() = 0; + virtual bool BGetDLCDataByIndex(int iDLC, int *pAppID, bool *pbAvailable, char *pchName, int cchNameBufferSize) = 0; + virtual void InstallDLC(int nAppID) = 0; + virtual void UninstallDLC(int nAppID) = 0; + virtual void RequestAppProofOfPurchaseKey(int nAppID) = 0; + virtual bool GetCurrentBetaName(char *pchName, int cchNameBufferSize) = 0; + virtual bool MarkContentCorrupt(bool bMissingFilesOnly) = 0; + virtual uint32_t GetInstalledDepots(int appID, void *pvecDepots, uint32_t cMaxDepots) = 0; + virtual uint32_t GetAppInstallDir(int appID, char *pchFolder, uint32_t cchFolderBufferSize) = 0; + virtual bool BIsAppInstalled(int appID) = 0; + virtual SteamID GetAppOwner() = 0; + virtual const char *GetLaunchQueryParam(const char *pchKey) = 0; + virtual bool GetDlcDownloadProgress(uint32_t, uint64_t *, uint64_t *) = 0; + virtual int GetAppBuildId() = 0; + }; + class Interface { public: @@ -238,6 +267,7 @@ namespace Steam static void UnregisterCallback(int32_t callId); static Friends15* SteamFriends; + static Apps7* SteamApps; static Utils* SteamUtils; static User* SteamUser_; static Interface ClientFriends;