summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2024-05-27 19:58:46 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2024-05-27 19:58:46 +0100
commita3a7a637811d3e18506d82a72e634cdc978dd2ee (patch)
tree55278b90d094058ae03e7007cc5a0d887be8de8d
parent33a9c3eca5bfc972622935cd455972d64eb513a3 (diff)
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!
-rw-r--r--gamedata/engine.kv13
-rw-r--r--src/con_.h4
-rw-r--r--src/xhair.c6
3 files changed, 21 insertions, 2 deletions
diff --git a/gamedata/engine.kv b/gamedata/engine.kv
index b23bab5..304b218 100644
--- a/gamedata/engine.kv
+++ b/gamedata/engine.kv
@@ -20,6 +20,19 @@ vtidx_StopRecording 7
vtidx_RecordPacket 11
// VEngineClient
+vtidx_IsInGame {
+ Client015 26
+ Client014 {
+ L4D2 28
+ 2013 26
+ }
+ Client013 {
+ L4D1 27
+ default 26
+ }
+ // TODO(compat): unconfirmed, and OE support isn't really a thing yet anyway
+ //Client012 28
+}
vtidx_GetGameDirectory {
Client015 35 // current portal 2
Client014 {
diff --git a/src/con_.h b/src/con_.h
index db322bc..0e6efef 100644
--- a/src/con_.h
+++ b/src/con_.h
@@ -1,6 +1,6 @@
/* THIS FILE SHOULD BE CALLED `con.h` BUT WINDOWS IS STUPID */
/*
- * Copyright © 2023 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -219,7 +219,7 @@ extern struct _con_vtab_iconvar_wrap {
ssize topoffset;
const struct itanium_vmi_type_info *rtti;
#endif
- void *vtable[7];
+ void *vtable[8];
} _con_vtab_iconvar_wrap;
#define _con_vtab_iconvar _con_vtab_iconvar_wrap.vtable
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);