From 3cd866f834d068f34b547e10600e226feb9055cd Mon Sep 17 00:00:00 2001 From: Mikko Kokko Date: Fri, 7 Apr 2023 13:14:07 +0300 Subject: [PATCH] check HIDEHUD_CROSSHAIR before drawing crosshair --- csldr/cdll_int.c | 5 +++++ csldr/export.c | 4 ++-- csldr/hud_crosshair.c | 38 +++++++++++++++++++++++++++++++++----- csldr/hud_crosshair.h | 4 ++++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/csldr/cdll_int.c b/csldr/cdll_int.c index 99db767..db6cdd7 100644 --- a/csldr/cdll_int.c +++ b/csldr/cdll_int.c @@ -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); } diff --git a/csldr/export.c b/csldr/export.c index 9ea9012..fdacb46 100644 --- a/csldr/export.c +++ b/csldr/export.c @@ -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) diff --git a/csldr/hud_crosshair.c b/csldr/hud_crosshair.c index 92a9239..8837750 100644 --- a/csldr/hud_crosshair.c +++ b/csldr/hud_crosshair.c @@ -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; @@ -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) @@ -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; @@ -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(); +} diff --git a/csldr/hud_crosshair.h b/csldr/hud_crosshair.h index f369922..f020ac9 100644 --- a/csldr/hud_crosshair.h +++ b/csldr/hud_crosshair.h @@ -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);