From 67b92d727344ab66bb5e070a9d45e8e647942c87 Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Mon, 25 Jan 2016 11:47:33 +0000
Subject: [PATCH] Went and fixed the dashmode variable hack nonsense once and
 for all myself

would have gone for "dashtime", but then I was reminded that was already a name for something to do with spindash. Oh well
---
 src/d_clisrv.c      |  2 ++
 src/d_clisrv.h      |  1 +
 src/d_player.h      |  1 +
 src/lua_playerlib.c |  4 ++++
 src/p_saveg.c       |  2 ++
 src/p_user.c        | 11 ++++++-----
 6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index 31738e9b21..ee2d189615 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -531,6 +531,7 @@ static inline void resynch_write_player(resynch_pak *rsp, const size_t i)
 	rsp->deadtimer = players[i].deadtimer;
 	rsp->exiting = (tic_t)LONG(players[i].exiting);
 	rsp->homing = players[i].homing;
+	rsp->dashmode = (tic_t)LONG(players[i].dashmode);
 	rsp->cmomx = (fixed_t)LONG(players[i].cmomx);
 	rsp->cmomy = (fixed_t)LONG(players[i].cmomy);
 	rsp->rmomx = (fixed_t)LONG(players[i].rmomx);
@@ -656,6 +657,7 @@ static void resynch_read_player(resynch_pak *rsp)
 	players[i].deadtimer = rsp->deadtimer;
 	players[i].exiting = (tic_t)LONG(rsp->exiting);
 	players[i].homing = rsp->homing;
+	players[i].dashmode = (tic_t)LONG(rsp->dashmode);
 	players[i].cmomx = (fixed_t)LONG(rsp->cmomx);
 	players[i].cmomy = (fixed_t)LONG(rsp->cmomy);
 	players[i].rmomx = (fixed_t)LONG(rsp->rmomx);
diff --git a/src/d_clisrv.h b/src/d_clisrv.h
index 6bc06f13a5..2bcfad1767 100644
--- a/src/d_clisrv.h
+++ b/src/d_clisrv.h
@@ -191,6 +191,7 @@ typedef struct
 	INT32 deadtimer;
 	tic_t exiting;
 	UINT8 homing;
+	tic_t dashmode;
 	fixed_t cmomx;
 	fixed_t cmomy;
 	fixed_t rmomx;
diff --git a/src/d_player.h b/src/d_player.h
index 08c98b7a3a..a3acb87281 100644
--- a/src/d_player.h
+++ b/src/d_player.h
@@ -352,6 +352,7 @@ typedef struct player_s
 	tic_t exiting; // Exitlevel timer
 
 	UINT8 homing; // Are you homing?
+	tic_t dashmode; // counter for dashmode ability
 
 	tic_t skidtime; // Skid timer
 
diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c
index 64513ab972..b038333543 100644
--- a/src/lua_playerlib.c
+++ b/src/lua_playerlib.c
@@ -202,6 +202,8 @@ static int player_get(lua_State *L)
 		lua_pushinteger(L, plr->exiting);
 	else if (fastcmp(field,"homing"))
 		lua_pushinteger(L, plr->homing);
+	else if (fastcmp(field,"dashmode"))
+		lua_pushinteger(L, plr->dashmode);
 	else if (fastcmp(field,"skidtime"))
 		lua_pushinteger(L, plr->skidtime);
 	else if (fastcmp(field,"cmomx"))
@@ -452,6 +454,8 @@ static int player_set(lua_State *L)
 		plr->exiting = (tic_t)luaL_checkinteger(L, 3);
 	else if (fastcmp(field,"homing"))
 		plr->homing = (UINT8)luaL_checkinteger(L, 3);
+	else if (fastcmp(field,"dashmode"))
+		plr->dashmode = (tic_t)luaL_checkinteger(L, 3);
 	else if (fastcmp(field,"skidtime"))
 		plr->skidtime = (tic_t)luaL_checkinteger(L, 3);
 	else if (fastcmp(field,"cmomx"))
diff --git a/src/p_saveg.c b/src/p_saveg.c
index 07e7b3564c..a574afb55b 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -162,6 +162,7 @@ static inline void P_NetArchivePlayers(void)
 		WRITEINT32(save_p, players[i].deadtimer);
 		WRITEUINT32(save_p, players[i].exiting);
 		WRITEUINT8(save_p, players[i].homing);
+		WRITEUINT32(save_p, players[i].dashmode);
 		WRITEUINT32(save_p, players[i].skidtime);
 
 		////////////////////////////
@@ -337,6 +338,7 @@ static inline void P_NetUnArchivePlayers(void)
 		players[i].deadtimer = READINT32(save_p); // End game if game over lasts too long
 		players[i].exiting = READUINT32(save_p); // Exitlevel timer
 		players[i].homing = READUINT8(save_p); // Are you homing?
+		players[i].dashmode = READUINT32(save_p); // counter for dashmode ability
 		players[i].skidtime = READUINT32(save_p); // Skid timer
 
 		////////////////////////////
diff --git a/src/p_user.c b/src/p_user.c
index 91bbfc6f2c..8a6d8b8714 100644
--- a/src/p_user.c
+++ b/src/p_user.c
@@ -9155,10 +9155,10 @@ void P_PlayerThink(player_t *player)
 
 	player->pflags &= ~PF_SLIDING;
 
+#define dashmode player->dashmode
 	// Dash mode ability for Metal Sonic
 	if ((player->charability == CA_DASHMODE) && !(maptol & TOL_NIGHTS))		// woo, dashmode! no nights tho.
 	{
-#define dashmode player->laps
 		if (player->speed >= FixedMul(skins[player->skin].normalspeed - 5*FRACUNIT, player->mo->scale) || (player->pflags & PF_STARTDASH))
 		{
 			dashmode++; 	// Counter. Adds 1 to dash mode per tic in top speed.
@@ -9172,10 +9172,10 @@ void P_PlayerThink(player_t *player)
 			else
 				dashmode = 0;
 		}
-		
+
 		if (dashmode > 254)
 			dashmode = 3*TICRATE+1;
-	
+
 		if (dashmode < 3*TICRATE)	// Exits Dash Mode if you drop below speed/dash counter tics. Not in the above block so it doesn't keep disabling in midair.
 		{
 			player->normalspeed = skins[player->skin].normalspeed; 	// Reset to default if not capable of entering dash mode.
@@ -9195,9 +9195,10 @@ void P_PlayerThink(player_t *player)
 			mobj_t *ghost = P_SpawnGhostMobj(player->mo); 	// Spawns afterimages
 			ghost->fuse = 2;	// Makes the images fade quickly
 		}
-#undef dashmode
 	}
-	
+	else
+		dashmode = 0;
+#undef dashmode
 /*
 //	Colormap verification
 	{
-- 
GitLab