Skip to content

Commit

Permalink
Updated: hud_watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
Elinsrc committed Oct 13, 2024
1 parent 201829e commit d47945d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 10 deletions.
103 changes: 103 additions & 0 deletions cl_dll/ui/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "cl_util.h"
#include <string.h>
#include <stdio.h>
#include <ctime>
#include "parsemsg.h"
#if USE_VGUI
#include "vgui_int.h"
Expand Down Expand Up @@ -183,6 +184,103 @@ void __CmdFunc_ForceCloseCommandMenu( void )
#endif
}

void __CmdFunc_Agrecord()
{
/*
* Yay overcomplicating stuff.
* All this code makes sure we can fit as much as possible into cmd.
*/

char cmd[256];
cmd[ARRAYSIZE(cmd) - 1] = '\0';

std::time_t curtime = std::time(nullptr);

auto written = std::strftime(cmd, sizeof(cmd), "record %Y%m%d_%H%M%S_", std::localtime(&curtime));
if (written > 0) {
char mapname[256];
auto mapname_len = get_map_name(mapname, ARRAYSIZE(mapname));

/*
* We want to leave at least one more byte for '\0'.
* written does not include the '\0'.
* written is strictly less than sizeof(cmd).
* The maximal value for written is sizeof(cmd) - 1.
* So if we wrote ARRAYSIZE(cmd) - 1 bytes, we have no extra bytes left.
*/
mapname_len = Q_min(mapname_len, ARRAYSIZE(cmd) - written - 1);
strncpy(cmd + written, mapname, mapname_len);

cmd[written + mapname_len] = '\0';

if (gEngfuncs.Cmd_Argc() >= 2) {
size_t bytes_left = ARRAYSIZE(cmd) - written - 1 - mapname_len;
if (bytes_left >= 2) {
cmd[written + mapname_len] = '_';

auto arg_len = strlen(gEngfuncs.Cmd_Argv(1));
auto bytes_to_write = Q_min(arg_len, bytes_left - 1);

strncpy(cmd + written + mapname_len + 1, gEngfuncs.Cmd_Argv(1), bytes_to_write);

cmd[written + mapname_len + 1 + bytes_to_write] = '\0';
}
}

gEngfuncs.pfnClientCmd(cmd);
}
}

void __CmdFunc_Append()
{
if (gEngfuncs.Cmd_Argc() != 2) {
if (!gEngfuncs.pDemoAPI->IsPlayingback())
gEngfuncs.Con_Printf("append <command> - put the command into the end of the command buffer.\n");

return;
}

ClientCmd(gEngfuncs.Cmd_Argv(1));
}

void __CmdFunc_Writemap()
{
FILE* saved_maps;
char map_name[64];
char map_name_to_check[64];

get_map_name(map_name, ARRAYSIZE(map_name));

if (map_name[0])
{
saved_maps = fopen("saved_maps.txt", "r+");

if (saved_maps)
{
while (fgets(map_name_to_check, ARRAYSIZE(map_name_to_check), saved_maps))
{
map_name_to_check[strlen(map_name_to_check) - 1] = '\0';

if (!strcmp(map_name, map_name_to_check))
{
gEngfuncs.Con_Printf("Current map is already in saved_maps.txt\n");
fclose(saved_maps);
return;
}
}
}
else
{
saved_maps = fopen("saved_maps.txt", "a");
if(!saved_maps)
return;
}

fprintf(saved_maps, "%s\n", map_name);
fclose(saved_maps);
}
}

// TFFree Command Menu Message Handlers
int __MsgFunc_ValClass( const char *pszName, int iSize, void *pbuf )
{
Expand Down Expand Up @@ -350,6 +448,11 @@ void CHud::Init( void )
HOOK_COMMAND( "ForceCloseCommandMenu", ForceCloseCommandMenu );
HOOK_COMMAND( "special", InputPlayerSpecial );

HOOK_COMMAND( "agrecord", Agrecord );
HOOK_COMMAND( "append", Append );
HOOK_COMMAND( "writemap", Writemap );
ClientCmd("alias zpecial \"append _zpecial\"");

HOOK_MESSAGE( ValClass );
HOOK_MESSAGE( TeamNames );
HOOK_MESSAGE( Feign );
Expand Down
16 changes: 8 additions & 8 deletions cl_dll/ui/hud/hud_watermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ int CHudWatermark::Draw(float time)
int r, g, b;
UnpackRGB(r, g, b, gHUD.m_iDefaultHUDColor);

char build[256];
sprintf(build, "Client-Mod: built %s, commit %s, architecture %s, platform %s",
char str[256];
sprintf(str, "^2Client-Mod^7: built ^1%s^7, commit ^2%s^7, architecture ^3%s^7, platform ^5%s\n",
BuildInfo::GetDate(),
BuildInfo::GetCommitHash(),
BuildInfo::GetArchitecture(),
BuildInfo::GetPlatform()
);

DrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight, build, r, g, b);
DrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 2, "t.me/Elinsrc", r, g, b);
DrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 3, "t.me/HalfLifeCollectiveChat", r, g, b);
DrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 4, BuildInfo::GetGitHubLink(), r, g, b);
DrawString(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 6, "To disable this message, type in the console 'hud_watermark 0'", r, g, b);
gHUD.DrawHudStringWithColorTags(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight, str, r, g, b);
gHUD.DrawHudStringWithColorTags(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 2, "t.me/Elinsrc", r, g, b);
gHUD.DrawHudStringWithColorTags(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 3, "t.me/HalfLifeCollectiveChat", r, g, b);
gHUD.DrawHudStringWithColorTags(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 4, BuildInfo::GetGitHubLink(), r, g, b);
sprintf(str, "To disable this message, type in the console ^2hud_watermark 0");
gHUD.DrawHudStringWithColorTags(ScreenWidth / 20, gHUD.m_scrinfo.iCharHeight * 6, str, r, g, b);

return 0;
}
4 changes: 2 additions & 2 deletions public/build_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ namespace BuildInfo
}

// Returns project GitHub repository URL.
constexpr const char *GetGitHubLink()
constexpr char *GetGitHubLink()
{
return "https://github.com/Elinsrc/Client-Mod";
}

// Returns build host machine date when program was built.
constexpr const char *GetDate()
constexpr char *GetDate()
{
return __DATE__;
}
Expand Down

0 comments on commit d47945d

Please sign in to comment.