Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Steam rich presence #149

Merged
merged 7 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 317360_loc_all.vdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"lang" {
"english" {
"tokens" {
"#Status" "{#Verb} on %mapname%"
"#Verb" "{#Verb_SuperFall_%superfalling%}"
"#Verb_SuperFall_true" "Falling"
"#Verb_SuperFall_false" "{#Verb_Objective_%miniobjective%}"
"#Verb_Objective_Briefcase_Carrying" "Carrying"
"#Verb_Objective_Briefcase_Hunting" "Acquiring"
"#Verb_Objective_Bounty_Hunted" "Wanted"
"#Verb_Objective_Bounty_Hunting" "Hunting"
"#Verb_Objective_RatRace_Leading" "Leading"
"#Verb_Objective_RatRace_Racing" "Racing"
"#Verb_Objective_None" "{#Verb_SuperSkill_%superskill%}"
"#Verb_SuperSkill_true" "Styling"
"#Verb_SuperSkill_false" "{#Verb_Skill_%skill%}"
"#Verb_Skill_bouncer" "Brawling"
"#Verb_Skill_athletic" "Stunting"
"#Verb_Skill_reflexes" "Slowing time"
"#Verb_Skill_marksman" "Camping"
"#Verb_Skill_troll" "Exploding"
"#Verb_Skill_none" "Playing"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentations added to highlight the decision tree.

}
}
}
5 changes: 3 additions & 2 deletions mp/src/game/client/recvproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ RecvProp RecvPropEHandle(
RecvProp RecvPropBool(
const char *pVarName,
int offset,
int sizeofVar )
int sizeofVar,
RecvVarProxyFn proxyFn )
{
Assert( sizeofVar == sizeof( bool ) );
return RecvPropInt( pVarName, offset, sizeofVar );
return RecvPropInt( pVarName, offset, sizeofVar, 0, proxyFn );
}


Expand Down
3 changes: 2 additions & 1 deletion mp/src/game/client/recvproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ RecvProp RecvPropEHandle(
RecvProp RecvPropBool(
const char *pVarName,
int offset,
int sizeofVar );
int sizeofVar,
RecvVarProxyFn proxyFn=0 );

RecvProp RecvPropIntWithMinusOneFlag(
const char *pVarName,
Expand Down
66 changes: 61 additions & 5 deletions mp/src/game/client/sdk/c_sdk_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "functionproxy.h"
#include "clientsteamcontext.h"

#include "da_buymenu.h"
#include "sdk_teammenu.h"
Expand All @@ -56,6 +57,19 @@ ConVar cl_ragdoll_physics_enable( "cl_ragdoll_physics_enable", "1", 0, "Enable/d
#undef CSDKPlayer
#endif

static void RecvCallback_UpdateRichPresence(const CRecvProxyData *pData) {
if (!pData)
return;

C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
if (!pPlayer)
return;

if (pData->m_ObjectID != pPlayer->entindex())
return;

pPlayer->UpdateRichPresence();
}



Expand Down Expand Up @@ -154,18 +168,17 @@ BEGIN_RECV_TABLE_NOBASE( CSDKPlayerShared, DT_SDKPlayerShared )
RecvPropBool( RECVINFO( m_bAimedIn ) ),
RecvPropFloat( RECVINFO( m_flAimIn ) ),
RecvPropFloat( RECVINFO( m_flSlowAimIn ) ),
RecvPropInt( RECVINFO( m_iStyleSkill ) ),
RecvPropInt( RECVINFO( m_iStyleSkill ), 0, RECVCALLBACKPROXY(RecvProxy_Int32ToInt8, RecvCallback_UpdateRichPresence) ),
RecvPropInt( RECVINFO( m_iStyleSkillAfterRespawn ), 0, RecvProxy_Skill ),
RecvPropBool( RECVINFO( m_bSuperSkill ) ),
RecvPropBool( RECVINFO( m_bSuperSkill ), RECVCALLBACKPROXY(RecvProxy_Int32ToInt32, RecvCallback_UpdateRichPresence) ),
RecvPropDataTable( "sdksharedlocaldata", 0, 0, &REFERENCE_RECV_TABLE(DT_SDKSharedLocalPlayerExclusive) ),

RecvPropInt (RECVINFO (m_iWallFlipCount)),
RecvPropBool (RECVINFO (m_bIsWallFlipping)),
RecvPropFloat (RECVINFO (m_flWallFlipEndTime)),
RecvPropBool (RECVINFO (m_bIsManteling)),
RecvPropVector (RECVINFO (m_vecMantelWallNormal)),

RecvPropBool( RECVINFO( m_bSuperFalling ) ),
RecvPropBool( RECVINFO( m_bSuperFalling ), RECVCALLBACKPROXY(RecvProxy_Int32ToInt8, RecvCallback_UpdateRichPresence) ),
RecvPropBool( RECVINFO( m_bSuperFallOthersVisible ) ),
RecvPropTime( RECVINFO( m_flSuperFallOthersNextCheck ) ),
END_RECV_TABLE()
Expand Down Expand Up @@ -240,7 +253,7 @@ IMPLEMENT_CLIENTCLASS_DT( C_SDKPlayer, DT_SDKPlayer, CSDKPlayer )

RecvPropString( RECVINFO( m_iszCharacter ), 0, RecvProxy_Character ),

RecvPropEHandle( RECVINFO( m_hBriefcase ) ),
RecvPropEHandle( RECVINFO( m_hBriefcase ), RECVCALLBACKPROXY(RecvProxy_IntToEHandle, RecvCallback_UpdateRichPresence) ),
RecvPropInt( RECVINFO( m_iRaceWaypoint ) ),

RecvPropBool( RECVINFO( m_bCoderHacks ) ),
Expand Down Expand Up @@ -946,6 +959,8 @@ void C_SDKPlayer::LocalPlayerRespawn( void )
#else
#error !
#endif

UpdateRichPresence();
}

void C_SDKPlayer::OnDataChanged( DataUpdateType_t type )
Expand Down Expand Up @@ -2296,6 +2311,47 @@ bool C_SDKPlayer::UseVRHUD() const
return UseVR() || da_vr_hud.GetBool();
}

void C_SDKPlayer::UpdateRichPresence()
{
Msg("Updating Rich Presence...\n");

steamapicontext->SteamFriends()->SetRichPresence("steam_display", "#Status");
steamapicontext->SteamFriends()->SetRichPresence("superfalling", m_Shared.IsSuperFalling() ? "true" : "false");
steamapicontext->SteamFriends()->SetRichPresence("mapname", SDKGameRules()->MapName());
steamapicontext->SteamFriends()->SetRichPresence("superskill", m_Shared.m_bSuperSkill ? "true" : "false");
steamapicontext->SteamFriends()->SetRichPresence("skill", SkillIDToAlias((SkillID)m_Shared.m_iStyleSkill.Get()));

const char * miniobjective;
switch (SDKGameRules()->GetCurrentMiniObjective())
{
case MINIOBJECTIVE_BRIEFCASE:
miniobjective = HasBriefcase() ? "Briefcase_Carrying" : "Briefcase_Hunting";
break;

case MINIOBJECTIVE_BOUNTY:
miniobjective = SDKGameRules()->GetBountyPlayer() == this ? "Bounty_Hunted" : "Bounty_Hunting";
break;

case MINIOBJECTIVE_RATRACE:
if (SDKGameRules()->GetLeader() == this)
{
miniobjective = "RatRace_Leading";
}
else
{
miniobjective = "RatRace_Racing";
}

break;

default:
miniobjective = "None";
break;
}

steamapicontext->SteamFriends()->SetRichPresence("miniobjective", miniobjective);
}

class CSlowIntensityProxy : public CResultProxy
{
public:
Expand Down
2 changes: 2 additions & 0 deletions mp/src/game/client/sdk/c_sdk_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ class C_SDKPlayer : public C_BasePlayer

bool UseVRHUD() const;

void UpdateRichPresence();

public: // Public Variables
CSDKPlayerAnimState *m_PlayerAnimState;
#if defined ( SDK_USE_PRONE )
Expand Down
8 changes: 8 additions & 0 deletions mp/src/game/client/sdk/clientmode_sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "da_credits.h"
#include "hud_macros.h"
#include "sourcevr/isourcevirtualreality.h"
#include "clientsteamcontext.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -162,6 +163,13 @@ void ClientModeSDKNormal::InitViewport()
m_pViewport->Start( gameuifuncs, gameeventmanager );
}

void ClientModeSDKNormal::LevelShutdown()
{
BaseClass::LevelShutdown();

steamapicontext->SteamFriends()->ClearRichPresence();
}

ClientModeSDKNormal g_ClientModeNormal;

IClientMode *GetClientModeNormal()
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/client/sdk/clientmode_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DECLARE_CLASS( ClientModeSDKNormal, ClientModeShared );
virtual ~ClientModeSDKNormal();

virtual void InitViewport();
virtual void LevelShutdown();

virtual float GetViewModelFOV( void );

Expand Down
23 changes: 19 additions & 4 deletions mp/src/game/shared/sdk/sdk_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,34 @@ END_DATADESC();
#endif


#if defined ( CLIENT_DLL )
static void RecvCallback_UpdateRichPresence(const CRecvProxyData *pData) {
if (!pData)
return;

C_SDKPlayer *pPlayer = C_SDKPlayer::GetLocalSDKPlayer();
if (!pPlayer)
return;

pPlayer->UpdateRichPresence();
}
#endif

REGISTER_GAMERULES_CLASS( CSDKGameRules );


BEGIN_NETWORK_TABLE_NOBASE( CSDKGameRules, DT_SDKGameRules )
#if defined ( CLIENT_DLL )
RecvPropInt( RECVINFO( m_eCurrentMiniObjective ) ),
RecvPropInt( RECVINFO( m_eCurrentMiniObjective ), 0, RECVCALLBACKPROXY(RecvProxy_Int32ToInt32, RecvCallback_UpdateRichPresence) ),
RecvPropFloat( RECVINFO( m_flGameStartTime ) ),
RecvPropBool( RECVINFO( m_bIsTeamplay ) ),
RecvPropBool( RECVINFO( m_bCoderHacks ) ),
RecvPropEHandle( RECVINFO( m_hBriefcase ) ),
RecvPropEHandle( RECVINFO( m_hCaptureZone ) ),
RecvPropEHandle( RECVINFO( m_hBountyPlayer ) ),
RecvPropEHandle( RECVINFO( m_hBountyPlayer ), RECVCALLBACKPROXY(RecvProxy_IntToEHandle, RecvCallback_UpdateRichPresence) ),
RecvPropVector( RECVINFO( m_vecLowestSpawnPoint ) ),
RecvPropArray3( RECVINFO_ARRAY(m_ahWaypoint1RaceLeaders), RecvPropEHandle( RECVINFO(m_ahWaypoint1RaceLeaders[0]))),
RecvPropArray3( RECVINFO_ARRAY(m_ahWaypoint2RaceLeaders), RecvPropEHandle( RECVINFO(m_ahWaypoint2RaceLeaders[0]))),
RecvPropArray3( RECVINFO_ARRAY(m_ahWaypoint1RaceLeaders), RecvPropEHandle( RECVINFO(m_ahWaypoint1RaceLeaders[0]), RECVCALLBACKPROXY(RecvProxy_IntToEHandle, RecvCallback_UpdateRichPresence))),
RecvPropArray3( RECVINFO_ARRAY(m_ahWaypoint2RaceLeaders), RecvPropEHandle( RECVINFO(m_ahWaypoint2RaceLeaders[0]), RECVCALLBACKPROXY(RecvProxy_IntToEHandle, RecvCallback_UpdateRichPresence))),
RecvPropEHandle( RECVINFO( m_hRaceWaypoint1 ) ),
RecvPropEHandle( RECVINFO( m_hRaceWaypoint2 ) ),
RecvPropEHandle( RECVINFO( m_hRaceWaypoint3 ) ),
Expand Down Expand Up @@ -2512,8 +2525,10 @@ bool CSDKGameRules::SetupMiniObjective_Bounty()
if (!pPlayer->IsAlive())
continue;

#ifndef _DEBUG
if (pPlayer->m_iDeaths + pPlayer->m_iKills < 5)
continue;
#endif

if (pPlayer->m_Shared.m_bSuperFalling)
continue;
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/shared/sdk/sdk_gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class CSDKGameRules : public CTeamplayRules

public:
void StartMiniObjective(const char* pszObjective = NULL);
miniobjective_t GetCurrentMiniObjective() { return m_eCurrentMiniObjective; }
notice_t GetNoticeForMiniObjective(miniobjective_t eObjective);
void MaintainMiniObjective();
void CleanupMiniObjective();
Expand Down
2 changes: 2 additions & 0 deletions mp/src/public/dt_recv.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ inline bool RecvTable::IsInMainList() const
#define RECVINFO_DT(varName) RECVINFO_NOSIZE(varName)
#define RECVINFO_DTNAME(varName,remoteVarName) #remoteVarName, offsetof(currentRecvDTClass, varName)

#define RECVCALLBACKPROXY(proxyFn, callbackFn) [](const CRecvProxyData *pData, void *pStruct, void *pOut) { (proxyFn)(pData, pStruct, pOut); (callbackFn)(pData); }


void RecvProxy_FloatToFloat ( const CRecvProxyData *pData, void *pStruct, void *pOut );
void RecvProxy_VectorToVector( const CRecvProxyData *pData, void *pStruct, void *pOut );
Expand Down