From d47945da9be570ab05db1f9684af737d0105a385 Mon Sep 17 00:00:00 2001 From: Elinsrc Date: Sun, 13 Oct 2024 20:20:12 +0500 Subject: [PATCH] Updated: hud_watermark --- cl_dll/ui/hud/hud.cpp | 103 ++++++++++++++++++++++++++++++++ cl_dll/ui/hud/hud_watermark.cpp | 16 ++--- public/build_info.h | 4 +- 3 files changed, 113 insertions(+), 10 deletions(-) diff --git a/cl_dll/ui/hud/hud.cpp b/cl_dll/ui/hud/hud.cpp index d741bcc..f9aa471 100644 --- a/cl_dll/ui/hud/hud.cpp +++ b/cl_dll/ui/hud/hud.cpp @@ -22,6 +22,7 @@ #include "cl_util.h" #include #include +#include #include "parsemsg.h" #if USE_VGUI #include "vgui_int.h" @@ -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 - 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 ) { @@ -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 ); diff --git a/cl_dll/ui/hud/hud_watermark.cpp b/cl_dll/ui/hud/hud_watermark.cpp index 789fb5b..075b1fb 100644 --- a/cl_dll/ui/hud/hud_watermark.cpp +++ b/cl_dll/ui/hud/hud_watermark.cpp @@ -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; } diff --git a/public/build_info.h b/public/build_info.h index 0680419..7d13a00 100644 --- a/public/build_info.h +++ b/public/build_info.h @@ -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__; }