InitInput
, it runs the DiscordMan_Startup
function and sets up everythingHUD_Shutdown
function.HUD_Frame
function, the DiscordMan_Update
function is called, which will use a set of map-controlled CVars that the game changesInitInput
, and they are rpc_chapter
, rpc_area
and rpc_image
.rpc_chapter
will display nothing when blank (default), or a custom string if defined;rpc_area
will display the map file name when blank (default), or a string of up to 64 characters long if defined;rpc_image
will display your default logo (defined in the "discord_manager.cpp" file, default), or any other asset you put in your mod's Discordconst char* defaultLogo
line to an image you uploaded to your app's dev page. Your mod's logo should work pretty well.Discord_Initialize
line. You'll see that the first argument is your game's ID; you can also pull this from your app's dev page (listed as// jay - discord rpc
#include "discord_manager.h"
Scroll down to the HUD_Frame
function, and put DiscordMan_Update();
at the bottom. This will make the update function get called every frame.// jay - discord rpc
#include "discord_manager.h"
cvar_t* rpc_chapter;
cvar_t* rpc_area;
cvar_t* rpc_image;
Then, go to InitInput
. Below the m_side
line, paste this:
// jay - discord rpc
gEngfuncs.Con_Printf("Initializing Discord RPC CVars\n");
rpc_chapter = gEngfuncs.pfnRegisterVariable("rpc_chapter", "", FCVAR_CLIENTDLL);
rpc_area = gEngfuncs.pfnRegisterVariable("rpc_area", "", FCVAR_CLIENTDLL);
rpc_image = gEngfuncs.pfnRegisterVariable("rpc_image", "", FCVAR_CLIENTDLL);
This will add our CVars.V_Init();
line, add this:
// jay - discord rpc
gEngfuncs.Con_Printf("Starting up Discord RPC\n");
DiscordMan_Startup();
For the last change on the client side, scroll a bit further down to the HUD_Shutdown
function, and add this at the top:
// jay - discord rpc
gEngfuncs.Con_Printf("Shutting down Discord RPC");
DiscordMan_Kill();
Now, if you compile the code and open the game, you should see rich presence working it's magic. Mess around with the CVars and see what it looks like in Discord.CWorld
class definition there. If you're using the vanilla code or Xash, add these lines to the// jay - discord rpc
virtual int Save(CSave& save);
virtual int Restore(CRestore& restore);
static TYPEDESCRIPTION m_SaveData[];
string_t m_iszChapter;
string_t m_iszArea;
string_t m_iszImage;
If you're using HL Updated, add this instead:
// jay - discord rpc
bool Save(CSave& save) override;
bool Restore(CRestore& restore) override;
static TYPEDESCRIPTION m_SaveData[];
string_t m_iszChapter;
string_t m_iszArea;
string_t m_iszImage;
This will allow the worldspawn
entity, or the map, to read and store the new keyvalues for the system. We also implement save & restore functionality here, so itCWorld
function definitions. You can find them by looking for a big comment right above them:
//=======================
// CWorld
//
// This spawns first when each level begins.
//=======================
In here, right below the LINK_ENTITY_TO_CLASS
line, add this chunk of code:
// jay - discord rpc
// If we don't do save & restore, everything gets reset when loading a save
TYPEDESCRIPTION CWorld::m_SaveData[] =
{
DEFINE_FIELD(CWorld, m_iszChapter, FIELD_STRING),
DEFINE_FIELD(CWorld, m_iszArea, FIELD_STRING),
DEFINE_FIELD(CWorld, m_iszImage, FIELD_STRING),
};
IMPLEMENT_SAVERESTORE(CWorld, CBaseEntity);
After that, put this at the bottom of CWorld::Precache
:
// jay - discord rpc
CVAR_SET_STRING("rpc_chapter", m_iszChapter ? STRING(m_iszChapter) : "");
CVAR_SET_STRING("rpc_area", m_iszArea ? STRING(m_iszArea) : "");
CVAR_SET_STRING("rpc_image", m_iszImage ? STRING(m_iszImage) : "");
This will set our CVars to whatever the mapper put into their map properties page when we load the map.CWorld::KeyValue
function. If you're using vanilla code or Xash, look for this final else statement:
else
CBaseEntity::KeyValue( pkvd );
and put this right above it, so that it's also below the defaultteam
keyvalue definition:
// jay - discord rpc
else if (FStrEq(pkvd->szKeyName, "rpc_chapter"))
{
m_iszChapter = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "rpc_area"))
{
m_iszArea = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "rpc_image"))
{
m_iszImage = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
If you're using HL Updated, then like I mentioned earlier, put that snippet below the defaultteam
keyvalue definition, so the next line is return
;pkvd->fHandled = TRUE;
to return true;
.worldspawn
definition, and add these three keyvalues:
rpc_chapter(string) : "RPC Chapter" : : "Chapter name to display in Discord."
rpc_area(string) : "RPC Area" : : "Area name to display in Discord. Shows map file name if empty."
rpc_image(string) : "RPC Image" : : "Image to display in Discord."
Now you're actually done. Go ahead and try it out!
You must log in to post a comment. You can login or register a new account.