Skip to content

Commit

Permalink
Allow setting start time & party size via Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 12, 2023
1 parent 8240c85 commit 8371339
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Client/core/CDiscordRichPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void CDiscordRichPresence::UpdatePresence()
discordPresence.buttons = buttons;
}

discordPresence.partySize = (m_bDisallowCustomDetails) ? 0 : m_iPartySize;
discordPresence.partyMax = (m_bDisallowCustomDetails) ? 0 : m_iPartyMax;

Discord_UpdatePresence(&discordPresence);
m_bUpdateRichPresence = false;
}
Expand Down Expand Up @@ -225,3 +228,9 @@ bool CDiscordRichPresence::IsDiscordCustomDetailsDisallowed() const
{
return m_bDisallowCustomDetails;
}

void CDiscordRichPresence::SetPresencePartySize(int iSize, int iMax)
{
m_iPartySize = iSize;
m_iPartyMax = iMax;
}
4 changes: 4 additions & 0 deletions Client/core/CDiscordRichPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CDiscordRichPresence : public CDiscordInterface
bool SetPresenceState(const char* szState, bool bCustom = false);
bool SetPresenceDetails(const char* szDetails, bool bCustom = false);
bool SetPresenceButtons(unsigned short int iIndex, const char* szName, const char* szUrl);
void SetPresencePartySize(int iSize, int iMax);
bool SetDiscordRPCEnabled(bool bEnabled);
bool IsDiscordCustomDetailsDisallowed() const;
bool IsDiscordRPCEnabled() const;
Expand Down Expand Up @@ -63,4 +64,7 @@ class CDiscordRichPresence : public CDiscordInterface
bool m_bDisallowCustomDetails;
bool m_bDiscordRPCEnabled;
bool m_bUpdateRichPresence;

int m_iPartySize;
int m_iPartyMax;
};
37 changes: 37 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void CLuaDiscordDefs::LoadFunctions()
{"setDiscordRichPresenceAsset", ArgumentParser<SetLargeAsset>},
{"setDiscordRichPresenceSmallAsset", ArgumentParser<SetSmallAsset>},
{"setDiscordRichPresenceButton", ArgumentParser<SetButtons>},
{"setDiscordRichPresenceStartTime", ArgumentParser<SetStartTime>},
{"setDiscordRichPresencePartySize", ArgumentParser<SetPartySize>},
{"resetDiscordRichPresenceData", ArgumentParser<ResetData>},
{"isDiscordRichPresenceConnected", ArgumentParser < IsDiscordRPCConnected>},

Expand All @@ -40,6 +42,8 @@ void CLuaDiscordDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setAsset", "setDiscordRichPresenceAsset");
lua_classfunction(luaVM, "setSmallAsset", "setDiscordRichPresenceSmallAsset");
lua_classfunction(luaVM, "setButton", "setDiscordRichPresenceButton");
lua_classfunction(luaVM, "setStartTime", "setDiscordRichPresenceStartTime");
lua_classfunction(luaVM, "setPartySize", "setDiscordRichPresencePartySize");

lua_classfunction(luaVM, "isConnected", "isDiscordRichPresenceConnected");
//lua_classfunction(luaVM, "setAppID", "setDiscordRichPresenceAppID");
Expand Down Expand Up @@ -115,6 +119,39 @@ bool CLuaDiscordDefs::SetDetails(std::string strDetails)
return true;
}

bool CLuaDiscordDefs::SetStartTime(unsigned long iSecondsSinceEpoch)
{
auto discord = g_pCore->GetDiscord();

if (!discord || !discord->IsDiscordRPCEnabled())
return false;

if (discord->IsDiscordCustomDetailsDisallowed())
return false;

discord->SetPresenceStartTimestamp(iSecondsSinceEpoch);
return true;
}
bool CLuaDiscordDefs::SetPartySize(int iSize, int iMax)
{
if (iMax < 0)
throw std::invalid_argument("Max size must be greater than or equal to 0");

if (iSize > iMax)
throw std::invalid_argument("Party size must be less than or equal to max party size");

auto discord = g_pCore->GetDiscord();

if (!discord || !discord->IsDiscordRPCEnabled())
return false;

if (discord->IsDiscordCustomDetailsDisallowed())
return false;

discord->SetPresencePartySize(iSize, iMax);
return true;
}

bool CLuaDiscordDefs::SetAsset(std::string szAsset, std::string szAssetText, bool bIsLarge)
{
int assetLength = szAsset.length();
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CLuaDiscordDefs : public CLuaDefs
static bool SetButtons(unsigned short int iIndex, std::string szName, std::string szUrl);
static bool SetLargeAsset(std::string szAsset, std::string szAssetText);
static bool SetSmallAsset(std::string szAsset, std::string szAssetText);
static bool SetStartTime(unsigned long iSecondsSinceEpoch);
static bool SetPartySize(int iMin, int iMax);
static bool IsDiscordRPCConnected();

};
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/core/CDiscordInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CDiscordInterface
virtual void SetAssetSmallData(const char* szAsset, const char* szAssetText) = 0;
virtual void SetPresenceStartTimestamp(const unsigned long ulStart) = 0;
virtual bool SetPresenceButtons(unsigned short int iIndex, const char* szName, const char* szUrl) = 0;
virtual void SetPresencePartySize(int iSize, int iMax) = 0;
//virtual void SetPresenceEndTimestamp(const unsigned long ulEnd) = 0;

virtual bool SetDiscordRPCEnabled(bool bEnabled = false) = 0;
Expand Down

0 comments on commit 8371339

Please sign in to comment.