Skip to content

Commit

Permalink
Merge pull request #142 from xiaodo1337/main
Browse files Browse the repository at this point in the history
Fix Custom Crosshair Alpha & Merge multiple crosshair color cvars to one cvar
  • Loading branch information
Velaron authored Feb 21, 2025
2 parents 8bd1b70 + f3284b0 commit 596db47
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
37 changes: 17 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ You have to own the [game on Steam](https://store.steampowered.com/app/10/Counte
After that, just install the APK and run.

## Configuration (CVars)
| CVar | Default | Min | Max | Description |
|--------------------------|-------------|-----|-----|---------------------------------------------------------------------------------------------|
| hud_color | "255 160 0" | - | - | HUD color in RGB. |
| cl_quakeguns | 0 | 0 | 1 | Draw centered weapons. |
| cl_weaponlag | 0 | 0.0 | - | Enable weapon lag/sway. |
| xhair_additive | 0 | 0 | 1 | Makes the crosshair additive. |
| xhair_alpha | 255 | 0 | 255 | Crosshair's transparency. |
| xhair_color_b | 0 | 0 | 255 | Crosshair color's blue value. |
| xhair_color_g | 255 | 0 | 255 | Crosshair color's green value. |
| xhair_color_r | 0 | 0 | 255 | Crosshair color's red value. |
| xhair_dot | 0 | 0 | 1 | Enables crosshair dot. |
| xhair_dynamic_move | 1 | 0 | 1 | Jumping, crouching and moving will affect the dynamic crosshair (like cl_dynamiccrosshair). |
| xhair_dynamic_scale | 0 | 0 | - | Scale of the dynamic crosshair movement. |
| xhair_gap_useweaponvalue | 0 | 0 | 1 | Makes the crosshair gap scale depend on the active weapon. |
| xhair_enable | 0 | 0 | 1 | Enables enhanced crosshair. |
| xhair_gap | 0 | 0 | - | Space between crosshair's lines. |
| xhair_pad | 0 | 0 | - | Border around crosshair. |
| xhair_size | 4 | 0 | - | Crosshair size. |
| xhair_t | 0 | 0 | 1 | Enables T-shaped crosshair. |
| xhair_thick | 0 | 0 | - | Crosshair thickness. |
| CVar | Default | Min | Max | Description |
|--------------------------|---------------|-----|-----|---------------------------------------------------------------------------------------------|
| hud_color | "255 160 0" | - | - | HUD color in RGB. |
| cl_quakeguns | 0 | 0 | 1 | Draw centered weapons. |
| cl_weaponlag | 0 | 0.0 | - | Enable weapon lag/sway. |
| xhair_additive | 0 | 0 | 1 | Makes the crosshair additive. |
| xhair_color | "0 255 0 255" | - | - | Crosshair's color (RGBA). |
| xhair_dot | 0 | 0 | 1 | Enables crosshair dot. |
| xhair_dynamic_move | 1 | 0 | 1 | Jumping, crouching and moving will affect the dynamic crosshair (like cl_dynamiccrosshair). |
| xhair_dynamic_scale | 0 | 0 | - | Scale of the dynamic crosshair movement. |
| xhair_gap_useweaponvalue | 0 | 0 | 1 | Makes the crosshair gap scale depend on the active weapon. |
| xhair_enable | 0 | 0 | 1 | Enables enhanced crosshair. |
| xhair_gap | 0 | 0 | - | Space between crosshair's lines. |
| xhair_pad | 0 | 0 | - | Border around crosshair. |
| xhair_size | 4 | 0 | - | Crosshair size. |
| xhair_t | 0 | 0 | 1 | Enables T-shaped crosshair. |
| xhair_thick | 0 | 0 | - | Crosshair thickness. |

## Building
Clone the source code:
Expand Down
28 changes: 19 additions & 9 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ int CHudAmmo::Init(void)
xhair_gap_useweaponvalue = CVAR_CREATE( "xhair_gap_useweaponvalue", "0", FCVAR_ARCHIVE );
xhair_dynamic_move = CVAR_CREATE( "xhair_dynamic_move", "1", FCVAR_ARCHIVE );

xhair_color_r = CVAR_CREATE( "xhair_color_r", "0", FCVAR_ARCHIVE );
xhair_color_g = CVAR_CREATE( "xhair_color_g", "255", FCVAR_ARCHIVE );
xhair_color_b = CVAR_CREATE( "xhair_color_b", "0", FCVAR_ARCHIVE );
xhair_alpha = CVAR_CREATE( "xhair_alpha", "255", FCVAR_ARCHIVE );
xhair_color = CVAR_CREATE( "xhair_color", "0 255 0 255", FCVAR_ARCHIVE );
xhair_additive = CVAR_CREATE( "xhair_additive", "0", FCVAR_ARCHIVE );

return 1;
Expand Down Expand Up @@ -1445,16 +1442,23 @@ void CHudAmmo::DrawCrosshairSection( int _x0, int _y0, int _x1, int _y1 )
float y0 = (float)_y0;
float x1 = (float)_x1;
float y1 = (float)_y1;
int color[3] = { 0, 255, 0 };
float alpha = 255.0f;

// float top_left[2] = { x0, y0 };
// float top_right[2] = { x1, y0 };
// float bottom_right[2] = { x1, y1 };
// float bottom_left[2] = { x0, y1 };

gEngfuncs.pTriAPI->Color4ub( xhair_color_r->value,
xhair_color_g->value,
xhair_color_b->value,
xhair_alpha->value );
if ( sscanf( xhair_color->string, "%d %d %d %f", &color[0], &color[1], &color[2], &alpha ) == 4 )
{
color[0] = bound( 0, color[0], 255 );
color[1] = bound( 0, color[1], 255 );
color[2] = bound( 0, color[2], 255 );
alpha = bound( 0.0f, alpha, 255.0f );
}
gEngfuncs.pTriAPI->Color4ub( color[0], color[1], color[2], alpha );
gEngfuncs.pTriAPI->Brightness( alpha / 255.0f );

DrawUtils::Draw2DQuad( x0, y0, x1, y1 );
}
Expand All @@ -1466,6 +1470,7 @@ void CHudAmmo::DrawCrosshairPadding( int _pad, int _x0, int _y0, int _x1, int _y
float y0 = (float)_y0;
float x1 = (float)_x1;
float y1 = (float)_y1;
float alpha = 255.0f;

// float out_top_left[2] = { x0 - pad, y0 - pad };
// float out_top_right[2] = { x1 + pad, y0 - pad };
Expand All @@ -1476,7 +1481,12 @@ void CHudAmmo::DrawCrosshairPadding( int _pad, int _x0, int _y0, int _x1, int _y
// float in_bottom_right[2] = { x1, y1 };
// float in_bottom_left[2] = { x0, y1 };

gEngfuncs.pTriAPI->Color4ub( 0, 0, 0, xhair_alpha->value );
if ( sscanf( xhair_color->string, "%*d %*d %*d %f", &alpha ) == 1 )
{
alpha = bound( 0.0f, alpha, 255.0f );
}
gEngfuncs.pTriAPI->Color4ub( 0, 0, 0, alpha );
gEngfuncs.pTriAPI->Brightness( alpha / 255.0f );

DrawUtils::Draw2DQuad( x0, y0, x1, y1 );
DrawUtils::Draw2DQuad( x0 + pad, y0 + pad, x1 + pad, y1 + pad );
Expand Down
5 changes: 1 addition & 4 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ class CHudAmmo: public CHudBase
cvar_t *xhair_gap_useweaponvalue;
cvar_t *xhair_dynamic_move;

cvar_t *xhair_color_r;
cvar_t *xhair_color_g;
cvar_t *xhair_color_b;
cvar_t *xhair_alpha;
cvar_t *xhair_color;
cvar_t *xhair_additive;

cvar_t *cl_crosshair_color;
Expand Down

0 comments on commit 596db47

Please sign in to comment.