Skip to content

Commit

Permalink
Get engine build version from sv_version cvar
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG committed Jan 2, 2024
1 parent 7f75082 commit fe79be6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ void CL_DLLEXPORT HUD_PlayerMove( struct playermove_s *ppmove, int server )
PM_Move( ppmove, server );
}

void SaveEngineVersion()
{
cvar_t *sv_version = gEngfuncs.pfnGetCvarPointer("sv_version");
if (sv_version)
{
strncpy(gHUD.m_szEngineVersion, sv_version->string, sizeof(gHUD.m_szEngineVersion) - 1);

// Parse build number
std::string version = gHUD.m_szEngineVersion;
size_t lastComma = version.rfind(',');

if (lastComma != std::string::npos)
{
const char *buildStr = gHUD.m_szEngineVersion + lastComma + 1;
gHUD.m_iEngineBuildNumber = atoi(buildStr);
}
}
}

int CL_DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion )
{
gEngfuncs = *pEnginefuncs;
Expand All @@ -162,6 +181,8 @@ int CL_DLLEXPORT Initialize( cl_enginefunc_t *pEnginefuncs, int iVersion )

memcpy(&gEngfuncs, pEnginefuncs, sizeof(cl_enginefunc_t));

SaveEngineVersion();

update_checker::check_for_updates();
discord_integration::initialize();

Expand Down
10 changes: 10 additions & 0 deletions cl_dll/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
#include <stdarg.h> // "
#include <string.h> // for strncpy()

#ifdef _WIN32
#define BUILD_OFFSET_LINUX 0
#else
#define BUILD_OFFSET_LINUX 1
#endif

constexpr int ENGINE_BUILD_ANNIVERSARY_FIRST = 9884 + BUILD_OFFSET_LINUX;

#undef BUILD_OFFSET_LINUX

// Macros to hook function calls into the HUD object
#define HOOK_MESSAGE(x) gEngfuncs.pfnHookUserMsg(#x, __MsgFunc_##x );

Expand Down
3 changes: 3 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,9 @@ class CHud
bool IsTriggerForSinglePlayer(color24 rendercolor);

HSPRITE white_sprite = 0;

char m_szEngineVersion[256];
int m_iEngineBuildNumber = -1;
};

extern CHud gHUD;
Expand Down

0 comments on commit fe79be6

Please sign in to comment.