From 032db82f8221347a5bf40bf217bc5f8bcb1f4b17 Mon Sep 17 00:00:00 2001
From: Mitchell Richters <mjr4077au@gmail.com>
Date: Sat, 7 Nov 2020 13:27:58 +1100
Subject: [PATCH] - Exhumed: Add crouch toggle mechanism.

---
 source/exhumed/src/input.cpp | 18 ++++++++++++++++--
 source/exhumed/src/player.h  |  2 ++
 wadsrc/static/menudef.txt    |  6 +-----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp
index e803281a3..73b12f5bf 100644
--- a/source/exhumed/src/input.cpp
+++ b/source/exhumed/src/input.cpp
@@ -106,6 +106,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
         if (PlayerList[nLocalPlayer].nHealth == 0) localInput.actions &= SB_OPEN;
     }
 
+    Player* pPlayer = &PlayerList[nLocalPlayer];
     double const scaleAdjust = InputScale();
     InputPacket input {};
 
@@ -119,10 +120,23 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
         processMovement(&input, &localInput, hidInput, scaleAdjust);
     }
 
+    // Handle crouch toggling.
+    if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle)
+    {
+        localInput.actions |= SB_CROUCH;
+    }
+    if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
+    {
+        pPlayer->crouch_toggle = !pPlayer->crouch_toggle;
+        buttonMap.ClearButton(gamefunc_Toggle_Crouch);
+    }
+    if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump))
+    {
+        pPlayer->crouch_toggle = false;
+    }
+
     if (!cl_syncinput)
     {
-        Player* pPlayer = &PlayerList[nLocalPlayer];
-
         if (!nFreeze)
         {
             applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080);
diff --git a/source/exhumed/src/player.h b/source/exhumed/src/player.h
index 254796ae0..2e30465c7 100644
--- a/source/exhumed/src/player.h
+++ b/source/exhumed/src/player.h
@@ -75,6 +75,8 @@ struct Player
     PlayerHorizon horizon;
     PlayerAngle angle;
     vec3_t opos;
+
+    bool crouch_toggle;
 };
 
 extern short PlayerCount;
diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt
index e019e8a08..37ec0b02d 100644
--- a/wadsrc/static/menudef.txt
+++ b/wadsrc/static/menudef.txt
@@ -514,11 +514,7 @@ OptionMenu "ActionControlsMenu" protected
 	StaticText ""
 	Control    "$CNTRLMNU_JUMP"             , "+jump"
 	Control    "$CNTRLMNU_CROUCH"           , "+crouch"
-	ifgame(Duke, Nam, WW2GI, Redneck, RedneckRides, Blood)
-	{
-		// Fixme: Make this work in all games
-		Control    "$CNTRLMNU_TOGGLECROUCH"     , "+toggle_crouch"
-	}
+	Control    "$CNTRLMNU_TOGGLECROUCH"     , "+toggle_crouch"
 
 	StaticText ""
 	Control    "$CNTRLMNU_MOUSELOOK"        , "+mouse_aiming"