[Friends] Better presence handling + Spacewar app as fallback
This commit is contained in:
parent
0198948d26
commit
d121b9119d
@ -159,21 +159,56 @@ namespace Components
|
||||
Friends::UpdateState();
|
||||
}
|
||||
|
||||
void Friends::ClearPresence(std::string key)
|
||||
std::vector<int> Friends::GetAppIdList()
|
||||
{
|
||||
std::vector<int> 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<void>("SetRichPresence", 0, key.data(), nullptr);
|
||||
Steam::Proxy::ClientFriends.invoke<void>("SetRichPresence", Steam::Proxy::AppId, key.data(), nullptr);
|
||||
auto appIds = Friends::GetAppIdList();
|
||||
|
||||
for (auto id : appIds)
|
||||
{
|
||||
Steam::Proxy::ClientFriends.invoke<void>("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<bool>() && Steam::Enabled())
|
||||
if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils && !Dvar::Var("cl_anonymous").get<bool>() && Steam::Enabled())
|
||||
{
|
||||
Steam::Proxy::ClientFriends.invoke<void>("SetRichPresence", 0, key.data(), value.data());
|
||||
Steam::Proxy::ClientFriends.invoke<void>("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<void>("RequestFriendRichPresence", 0, user);
|
||||
Steam::Proxy::ClientFriends.invoke<void>("RequestFriendRichPresence", Steam::Proxy::AppId, user);
|
||||
Steam::Proxy::ClientFriends.invoke<void>("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<const char*>("GetFriendRichPresence", Steam::Proxy::AppId, user, key.data());
|
||||
if (result.empty()) result = Steam::Proxy::ClientFriends.invoke<const char*>("GetFriendRichPresence", 0, user, key.data());
|
||||
std::string result = Steam::Proxy::ClientFriends.invoke<const char*>("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()));
|
||||
|
@ -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<int> GetAppIdList();
|
||||
};
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Steam
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Friends::GetFriendGamePlayed(SteamID steamIDFriend, void *pFriendGameInfo)
|
||||
bool Friends::GetFriendGamePlayed(SteamID steamIDFriend, FriendGameInfo *pFriendGameInfo)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<Apps7*>(Proxy::SteamClient->GetISteamApps(Proxy::SteamUser, Proxy::SteamPipe, "STEAMAPPS_INTERFACE_VERSION007"));
|
||||
if (!Proxy::SteamApps) return false;
|
||||
|
||||
Proxy::SteamFriends = reinterpret_cast<Friends15*>(Proxy::SteamClient->GetISteamFriends(Proxy::SteamUser, Proxy::SteamPipe, "SteamFriends015"));
|
||||
if (!Proxy::SteamFriends) return false;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user