Skip to content

Commit

Permalink
check HIDEHUD_CROSSHAIR before drawing crosshair
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokko committed Apr 7, 2023
1 parent 56da929 commit 3cd866f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
5 changes: 5 additions & 0 deletions csldr/cdll_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ static int Hk_HookUserMsg(const char *szMsgName, pfnUserMsgHook pfn)
Og_MsgFunc_CurWeapon = pfn;
hook = Hk_MsgFunc_CurWeapon;
}
else if (!strcmp(szMsgName, "HideWeapon"))
{
Og_MsgFunc_HideWeapon = pfn;
hook = Hk_MsgFunc_HideWeapon;
}

return gEngfuncs.pfnHookUserMsg(szMsgName, hook);
}
Expand Down
4 changes: 2 additions & 2 deletions csldr/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ EXPORT int HUD_UpdateClientData(client_data_t *pcldata, float flTime)

EXPORT int HUD_VidInit(void)
{
/* pass through */
return cl_funcs.pHudVidInitFunc();
/* hooked */
return Hk_HudVidInit();
}

EXPORT void HUD_VoiceStatus(int entindex, qboolean bTalking)
Expand Down
38 changes: 33 additions & 5 deletions csldr/hud_crosshair.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "pch.h"

/* mikkotodo: other flags can hide the crosshair as well, however
the way those work is more complicated than just checking the flag
before drawing the crosshair */
#define HIDEHUD_CROSSHAIR (1 << 6)

bool can_xhair;

cvar_t *xhair_enable;
Expand All @@ -21,20 +26,29 @@ cvar_t *cl_crosshair_translucent;
cvar_t *hud_draw;

int currentWeaponId;
static int hideHudFlags;

int (*Og_MsgFunc_CurWeapon)(const char *pszName, int iSize, void *pbuf);

int Hk_MsgFunc_CurWeapon(const char *name, int size, void *data)
int Hk_MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf)
{
int state = ((byte *)data)[0];
int weaponId = ((char *)data)[1];
int state = ((byte *)pbuf)[0];
int weaponId = ((char *)pbuf)[1];

if (weaponId < 1)
currentWeaponId = 0;
else if (state)
currentWeaponId = weaponId;

return Og_MsgFunc_CurWeapon(name,size,data);
return Og_MsgFunc_CurWeapon(pszName, iSize, pbuf);
}

int (*Og_MsgFunc_HideWeapon)(const char *pszName, int iSize, void *pbuf);

int Hk_MsgFunc_HideWeapon(const char *pszName, int iSize, void *pbuf)
{
hideHudFlags = ((byte *)pbuf)[0];
return Og_MsgFunc_HideWeapon(pszName, iSize, pbuf);
}

void HudInit(void)
Expand Down Expand Up @@ -207,8 +221,14 @@ int Hk_HudRedraw(float time, int intermission)
float old_trans;
char old_color[2];

if (!isOpenGL || !can_xhair || !xhair_enable->value || (hud_draw && !hud_draw->value))
if (!isOpenGL
|| !can_xhair
|| !xhair_enable->value
|| (hud_draw && !hud_draw->value)
|| (hideHudFlags & HIDEHUD_CROSSHAIR))
{
return cl_funcs.pHudRedrawFunc(time, intermission);
}

/* stupid hack, the memory is always writable though */
color_str = (char *)cl_crosshair_color->string;
Expand All @@ -235,3 +255,11 @@ int Hk_HudRedraw(float time, int intermission)

return 1;
}

int Hk_HudVidInit(void)
{
currentWeaponId = 0;
hideHudFlags = 0;

return cl_funcs.pHudVidInitFunc();
}
4 changes: 4 additions & 0 deletions csldr/hud_crosshair.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ extern int currentWeaponId;
extern int (*Og_MsgFunc_CurWeapon)(const char *pszName, int iSize, void *pbuf);
int Hk_MsgFunc_CurWeapon(const char *pszName, int iSize, void *pbuf);

extern int (*Og_MsgFunc_HideWeapon)(const char *pszName, int iSize, void *pbuf);
int Hk_MsgFunc_HideWeapon(const char *pszName, int iSize, void *pbuf);

void HudInit(void);
int Hk_HudRedraw(float time, int intermission);
int Hk_HudVidInit(void);

0 comments on commit 3cd866f

Please sign in to comment.