Skip to content

Commit

Permalink
Added: support ag game
Browse files Browse the repository at this point in the history
  • Loading branch information
Elinsrc committed Oct 13, 2024
1 parent ef0bdfa commit 201829e
Show file tree
Hide file tree
Showing 47 changed files with 1,835 additions and 63 deletions.
22 changes: 17 additions & 5 deletions cl_dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,33 @@ set (CLDLL_SOURCES
ui/hud/hud_msg.cpp
ui/hud/hud_redraw.cpp
ui/hud/hud_spectator.cpp
ui/hud/hud_speedometer.cpp
ui/hud/hud_jumpspeed.cpp
ui/hud/hud_update.cpp
ui/hud/hud_crosshairs.cpp
ui/hud/hud_watermark.cpp
ui/hud/hud_debug.cpp
ui/hud/hud_strafeguide.cpp
ui/hud/menu.cpp
ui/hud/message.cpp
ui/hud/rainbow.cpp
ui/hud/saytext.cpp
ui/hud/status_icons.cpp
ui/hud/statusbar.cpp
ui/hud/text_message.cpp
ui/hud/train.cpp
ui/hud/OpenAG/color_tags.cpp
ui/hud/OpenAG/rainbow.cpp
ui/hud/OpenAG/hud_strafeguide.cpp
ui/hud/OpenAG/hud_speedometer.cpp
ui/hud/OpenAG/hud_jumpspeed.cpp
ui/hud/OpenAG/hud_countdown.cpp
ui/hud/OpenAG/hud_settings.cpp
ui/hud/OpenAG/hud_timer.cpp
ui/hud/OpenAG/hud_ctf.cpp
ui/hud/OpenAG/hud_customtimer.cpp
ui/hud/OpenAG/hud_location.cpp
ui/hud/OpenAG/hud_nextmap.cpp
ui/hud/OpenAG/hud_playerid.cpp
ui/hud/OpenAG/hud_suddendeath.cpp
ui/hud/OpenAG/hud_timeout.cpp
ui/hud/OpenAG/hud_vote.cpp
cdll_int.cpp
com_weapons.cpp
demo.cpp
Expand Down Expand Up @@ -180,7 +192,7 @@ if (BUILD_IMGUI)
"${CMAKE_SOURCE_DIR}/3rdparty/imgui/imgui_widgets.cpp")
endif()

include_directories (. hl/ events/ input/ rendering/ ui ui/hud ${CMAKE_SOURCE_DIR}/dlls ${CMAKE_SOURCE_DIR}/dlls/wpn_shared ${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/engine ${CMAKE_SOURCE_DIR}/pm_shared ${CMAKE_SOURCE_DIR}/game_shared ${CMAKE_SOURCE_DIR}/public)
include_directories (. hl/ events/ input/ rendering/ ui ui/hud ui/hud/OpenAG/ ${CMAKE_SOURCE_DIR}/dlls ${CMAKE_SOURCE_DIR}/dlls/wpn_shared ${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/engine ${CMAKE_SOURCE_DIR}/pm_shared ${CMAKE_SOURCE_DIR}/game_shared ${CMAKE_SOURCE_DIR}/public)

if (BUILD_DISCORD_RPC)
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/discord-rpc/include discord-rpc)
Expand Down
131 changes: 100 additions & 31 deletions cl_dll/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#define CL_UTIL_H
#include "exportdef.h"
#include "cvardef.h"

#include "net_api.h"
#include "color_tags.h"

#include <stdio.h> // for safe_sprintf()
#include <stdarg.h> // "
Expand Down Expand Up @@ -120,33 +120,33 @@ inline int DrawConsoleString( int x, int y, const char *string )
return gEngfuncs.pfnDrawConsoleString( x, y, (char*) string );
}

inline void GetConsoleStringSize( const char *string, int *width, int *height )
int DrawUtfString( int xpos, int ypos, int iMaxX, const char *szIt, int r, int g, int b );

inline int DrawConsoleString( int x, int y, char *string )
{
if( hud_textmode->value == 1 )
*height = 13, *width = gHUD.DrawHudStringLen( (char*)string );
else
gEngfuncs.pfnDrawConsoleStringLen( (char*)string, width, height );
return gHUD.DrawConsoleStringWithColorTags(x, y, string);
}

int DrawUtfString( int xpos, int ypos, int iMaxX, const char *szIt, int r, int g, int b );
inline void GetConsoleStringSize( char *string, int *width, int *height )
{
gHUD.GetConsoleStringSizeWithColorTags(string, *width, *height);
}

inline int ConsoleStringLen( const char *string )
inline int ConsoleStringLen( char *string )
{
int _width = 0, _height = 0;
if( hud_textmode->value == 1 )
return gHUD.DrawHudStringLen( (char*)string );
int _width, _height;
GetConsoleStringSize( string, &_width, &_height );
return _width;
}

inline void ConsolePrint( const char *string )
{
gEngfuncs.pfnConsolePrint( string );
gEngfuncs.pfnConsolePrint( color_tags::strip_color_tags_thread_unsafe(string) );
}

inline void CenterPrint( const char *string )
{
gEngfuncs.pfnCenterPrint( string );
gEngfuncs.pfnCenterPrint( color_tags::strip_color_tags_thread_unsafe(string) );
}

inline int DrawString( int x, int y, const char *string, int r, int g, int b )
Expand All @@ -165,11 +165,41 @@ inline void PlaySound( int iSound, float vol ) { gEngfuncs.pfnPlaySoundByIndex(
#define Q_min(a, b) (((a) < (b)) ? (a) : (b))
#define fabs(x) ((x) > 0 ? (x) : 0 - (x))


//// OpenAG
// OpenAG
template<typename T, size_t N>
char (&ArraySizeHelper(T (&)[N]))[N];
#define ARRAYSIZED(x) sizeof(ArraySizeHelper(x))
#define ARRAYSIZE(x) sizeof(ArraySizeHelper(x))

static size_t count_digits(int n)
{
size_t result = 0;

do {
++result;
} while ((n /= 10) != 0);

return result;
}

static char* get_server_address()
{
net_status_t netstatus{};
gEngfuncs.pNetAPI->Status(&netstatus);
return gEngfuncs.pNetAPI->AdrToString(&netstatus.remote_address);
}

static void sanitize_address(std::string& address)
{
for (size_t i = 0; i < address.size(); ++i) {
char c = address[i];
if ((c >= '0' && c <= '9') || c == '.' || c == ':')
continue;

// Invalid character.
address = address.substr(0, i);
break;
}
}

static size_t get_map_name(char* dest, size_t count)
{
Expand Down Expand Up @@ -208,24 +238,63 @@ static size_t get_player_count()

return player_count;
}
////

//// ChatGPT
inline void convert_to_lower_case(const char *str)
{
unsigned char *str_lw = (unsigned char *)str;
while (*str_lw) {
*str_lw = tolower(*str_lw);
str_lw++;
}
}

inline char *safe_strcpy( char *dst, const char *src, int len_dst)
{
if( len_dst <= 0 )
{
return NULL; // this is bad
}

strncpy(dst,src,len_dst);
dst[ len_dst - 1 ] = '\0';

return dst;
}

inline int safe_sprintf( char *dst, int len_dst, const char *format, ...)
{
if( len_dst <= 0 )
{
return -1; // this is bad
}

va_list v;

va_start(v, format);

_vsnprintf(dst,len_dst,format,v);

va_end(v);

dst[ len_dst - 1 ] = '\0';

return 0;
}
//

inline void remove_color_characters(char *input_string) {
char *read = input_string;
char *write = input_string;

while (*read) {
if (*read == '^' && isdigit(*(read + 1))) {
read += 2;
} else {
*write++ = *read++;
}
}

*write = '\0';
char *read = input_string;
char *write = input_string;

while (*read) {
if (*read == '^' && isdigit(*(read + 1))) {
read += 2;
} else {
*write++ = *read++;
}
}
*write = '\0';
}
////

void ScaleColors( int &r, int &g, int &b, int a );

Expand Down
2 changes: 1 addition & 1 deletion cl_dll/discord-rpc/discord_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace discord_integration
char map[256] = "Map: ";
size_t map_len = strlen(map);
const size_t length =
get_map_name(map+map_len, ARRAYSIZED(map)-map_len);
get_map_name(map+map_len, ARRAYSIZE(map)-map_len);

char ServerName[256] = "Server: ";
#if USE_VGUI
Expand Down
1 change: 1 addition & 0 deletions cl_dll/input/input_goldsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif

#if USE_SDL2
#undef ARRAYSIZE
#define ARRAYSIZE(p) ( sizeof(p) /sizeof(p[0]) )
#include <dlfcn.h>
#include <SDL2/SDL_mouse.h>
Expand Down
14 changes: 14 additions & 0 deletions cl_dll/ui/VGUI/vgui_ScorePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ ScorePanel::ScorePanel( int x, int y, int wide, int tall ) : Panel( x, y, wide,

//m_pTrackerIcon = vgui_LoadTGANoInvertAlpha("gfx/vgui/640_scoreboardtracker.tga");

if ((m_pFlagIcon = vgui_LoadTGANoInvertAlpha("gfx/vgui/640_ag_ctf_score.tga")))
m_pFlagIcon->setColor(vgui::Color(255, 255, 255, 1));

// Initialize the top title.
m_TitleLabel.setFont( tfont );
m_TitleLabel.setText( "" );
Expand Down Expand Up @@ -227,6 +230,12 @@ ScorePanel::ScorePanel( int x, int y, int wide, int tall ) : Panel( x, y, wide,
Initialize();
}

ScorePanel::~ScorePanel()
{
if (m_pFlagIcon)
delete m_pFlagIcon;
}

//-----------------------------------------------------------------------------
// Purpose: Called each time a new level is started.
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -810,6 +819,11 @@ void ScorePanel::FillGrid()
}
}
*/
if (m_pFlagIcon
&& (gHUD.m_CTF.GetBlueFlagPlayerIndex() == m_iSortedRows[row]
|| gHUD.m_CTF.GetRedFlagPlayerIndex() == m_iSortedRows[row])) {
pLabel->setImage(m_pFlagIcon);
}
break;
case COLUMN_KILLS:
sprintf(sz, "%d", g_PlayerExtraInfo[ m_iSortedRows[row] ].frags );
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/ui/VGUI/vgui_ScorePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class ScorePanel : public Panel, public vgui::CDefaultInputSignal
ScorePanel::HitTestPanel m_HitTestPanel;
CommandButton *m_pCloseButton;
CLabelHeader* GetPlayerEntry(int x, int y) {return &m_PlayerEntries[x][y];}
vgui::BitmapTGA* m_pFlagIcon;

public:

Expand All @@ -282,6 +283,7 @@ class ScorePanel : public Panel, public vgui::CDefaultInputSignal
public:

ScorePanel(int x,int y,int wide,int tall);
~ScorePanel();

void Update( void );

Expand Down
91 changes: 91 additions & 0 deletions cl_dll/ui/hud/OpenAG/color_tags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "color_tags.h"

#include "hud.h"
#include "cl_util.h"

namespace color_tags {
namespace {
// R, G, B.
constexpr int colors[][3] = {
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 255, 255, 0 },
{ 0, 0, 255 },
{ 0, 255, 255 },
{ 255, 0, 255 },
{ 136, 136, 136 },
{ 255, 255, 255 }
};
}

void strip_color_tags(char* dest, const char* src, size_t count) {
if (count == 0)
return;

for (; *src != '\0' && count > 1; ++src) {
if (src[0] == '^' && src[1] >= '0' && src[1] <= '9') {
++src;
continue;
} else {
*dest++ = *src;
--count;
}
}

*dest = '\0';
}

char* strip_color_tags_thread_unsafe(const char* string) {
static char buf[2048];

strip_color_tags(buf, string, ARRAYSIZE(buf));

return buf;
}

bool contains_color_tags(const char* string) {
for (; *string != '\0'; ++string) {
if (string[0] == '^' && string[1] >= '0' && string[1] <= '9')
return true;
}

return false;
}

void for_each_colored_substr(char* string, std::function<void(const char* string, bool custom_color, int r, int g, int b)> function) {
bool custom_color = false;
int r = 0, g = 0, b = 0;
char *temp = string;

while ((temp = strchr(temp, '^'))) {
char color_index = temp[1];

if (color_index >= '0' && color_index <= '9') {
if (temp != string) {
*temp = '\0';

function(string, custom_color, r, g, b);

*temp = '^';
}

string = temp + 2;
temp = temp + 2;

if (color_index == '0' || color_index == '9') {
custom_color = false;
} else {
custom_color = true;
r = colors[color_index - '1'][0];
g = colors[color_index - '1'][1];
b = colors[color_index - '1'][2];
}
} else {
++temp;
}
}

if (string[0] != '\0')
function(string, custom_color, r, g, b);
}
}
Loading

0 comments on commit 201829e

Please sign in to comment.