From 0de3a64b59e6647a97efef630450f3565d06e4bd Mon Sep 17 00:00:00 2001
From: LJ Sonic <lamr@free.fr>
Date: Tue, 29 Dec 2020 21:36:15 +0100
Subject: [PATCH] Let Lua toggle the crosshair

---
 src/hu_stuff.c   | 21 ++++++++++++---------
 src/lua_hud.h    |  1 +
 src/lua_hudlib.c |  1 +
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 7e9144f98f..0b24d06906 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -2109,15 +2109,18 @@ void HU_Drawer(void)
 		return;
 
 	// draw the crosshair, not when viewing demos nor with chasecam
-	if (!automapactive && cv_crosshair.value && !demoplayback &&
-		(!camera.chase || ticcmd_ztargetfocus[0])
-	&& !players[displayplayer].spectator)
-		HU_DrawCrosshair();
-
-	if (!automapactive && cv_crosshair2.value && !demoplayback &&
-		(!camera2.chase || ticcmd_ztargetfocus[1])
-	&& !players[secondarydisplayplayer].spectator)
-		HU_DrawCrosshair2();
+	if (LUA_HudEnabled(hud_crosshair))
+	{
+		if (!automapactive && cv_crosshair.value && !demoplayback &&
+			(!camera.chase || ticcmd_ztargetfocus[0])
+		&& !players[displayplayer].spectator)
+			HU_DrawCrosshair();
+
+		if (!automapactive && cv_crosshair2.value && !demoplayback &&
+			(!camera2.chase || ticcmd_ztargetfocus[1])
+		&& !players[secondarydisplayplayer].spectator)
+			HU_DrawCrosshair2();
+	}
 
 	// draw desynch text
 	if (hu_redownloadinggamestate)
diff --git a/src/lua_hud.h b/src/lua_hud.h
index 4a7c596c8a..1e9dca00b9 100644
--- a/src/lua_hud.h
+++ b/src/lua_hud.h
@@ -13,6 +13,7 @@
 enum hud {
 	hud_stagetitle = 0,
 	hud_textspectator,
+	hud_crosshair,
 	// Singleplayer / Co-op
 	hud_score,
 	hud_time,
diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index e58cd4a584..8d451e99c5 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -39,6 +39,7 @@ static UINT8 hudAvailable; // hud hooks field
 static const char *const hud_disable_options[] = {
 	"stagetitle",
 	"textspectator",
+	"crosshair",
 
 	"score",
 	"time",
-- 
GitLab