From a3a7a637811d3e18506d82a72e634cdc978dd2ee Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 27 May 2024 19:58:46 +0100 Subject: Hide custom crosshair in menus/load screens This isn't perfect logic - the standard crosshair has a lot more cases where it's not displayed - but it's better than nothing and avoids looking stupid as often. In the process, also fix the IConVar virtual table being one entry too small, which somehow wasn't a problem until it led to vtidx_IsInGame here getting clobbered and causing hard-to-debug crashes. Woopsy! --- src/xhair.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/xhair.c') diff --git a/src/xhair.c b/src/xhair.c index e2f7bfb..dddcdab 100644 --- a/src/xhair.c +++ b/src/xhair.c @@ -19,13 +19,17 @@ #include "con_.h" #include "engineapi.h" #include "feature.h" +#include "gamedata.h" #include "hexcolour.h" #include "hud.h" #include "intdefs.h" +#include "vcall.h" FEATURE("crosshair drawing") REQUIRE(hud) +DECL_VFUNC_DYN(bool, IsInGame) + DEF_CVAR(sst_xhair, "Enable custom crosshair", 0, CON_ARCHIVE | CON_HIDDEN) DEF_CVAR(sst_xhair_colour, "Colour for alternative crosshair (RGBA hex)", "FFFFFF", CON_ARCHIVE | CON_HIDDEN) @@ -51,8 +55,10 @@ static inline void drawrect(int x0, int y0, int x1, int y1, struct rgba colour, hud_drawrect(x0, y0, x1, y1, colour, true); if (outline) hud_drawrect(x0, y0, x1, y1, (struct rgba){.a = 255}, false); } + HANDLE_EVENT(HudPaint, void) { if (!con_getvari(sst_xhair)) return; + if (has_vtidx_IsInGame && engclient && !IsInGame(engclient)) return; int w, h; hud_screensize(&w, &h); int thick = con_getvari(sst_xhair_thickness); -- cgit v1.2.3