From 69e3722e816fd027af17f9800a136b4eff57de86 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 9 May 2025 15:07:49 +0200 Subject: [PATCH] Fix controls getting stuck when opening the pause menu https://git.srb2.org/Hanicef/SRB2Classic/-/commit/ed53d96430dedac42b288bd6a5ca8152e6e6acc4 --- src/g_game.c | 3 ++- src/g_input.c | 22 ++++++++++++++++++++++ src/g_input.h | 1 + src/lua_script.c | 5 ++++- src/m_menu.c | 4 +--- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d1a5a440c..bf1ce0206 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1471,7 +1471,8 @@ boolean G_Responder(event_t *ev) } // update keys current state - G_MapEventsToControls(ev); + if (!menuactive) + G_MapEventsToControls(ev); switch (ev->type) { diff --git a/src/g_input.c b/src/g_input.c index f7ea83a75..41c11c204 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -20,6 +20,8 @@ #include "d_net.h" #include "console.h" +#include "m_menu.h" + #include "i_system.h" #include "i_video.h" #include "r_draw.h" @@ -261,6 +263,26 @@ void G_MapEventsToControls(event_t *ev) } } +void G_ResetControls(void) +{ + memset(gamekeydown, 0, NUMINPUTS); + + memset(joyxmove, 0, sizeof(joyxmove)); + memset(joyymove, 0, sizeof(joyymove)); + + memset(joy2xmove, 0, sizeof(joy2xmove)); + memset(joy2ymove, 0, sizeof(joy2ymove)); + + memset(joy3xmove, 0, sizeof(joy3xmove)); + memset(joy3ymove, 0, sizeof(joy3ymove)); + + memset(joy4xmove, 0, sizeof(joy4xmove)); + memset(joy4ymove, 0, sizeof(joy4ymove)); + + // reset those just in case the game missed the keyup event + memset(dpadscrollstate, false, sizeof(dpadscrollstate)); +} + // // General double-click detection routine for any kind of input. // diff --git a/src/g_input.h b/src/g_input.h index b8e4cd8d8..478dae8f1 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -138,6 +138,7 @@ void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_stre // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); +void G_ResetControls(void); // returns the name of a key const char *G_KeynumToString(INT32 keynum); diff --git a/src/lua_script.c b/src/lua_script.c index 8d481b95b..799cb101a 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -861,7 +861,8 @@ static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype) int TABLESINDEX; UINT16 i; - if (!gL) { + if (!gL) + { if (fastcmp(ptype,"player")) // players must always be included, even if no vars WRITEUINT16(*p, 0); return; @@ -898,8 +899,10 @@ static void ArchiveExtVars(UINT8 **p, void *pointer, const char *ptype) if (fastcmp(ptype,"mobj")) // mobjs must write their mobjnum as a header WRITEUINT32(*p, ((mobj_t *)pointer)->mobjnum); + WRITEUINT16(*p, i); lua_pushnil(gL); + while (lua_next(gL, -2)) { I_Assert(lua_type(gL, -2) == LUA_TSTRING); diff --git a/src/m_menu.c b/src/m_menu.c index a87033997..efb56cd9a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4556,9 +4556,7 @@ void M_StartControlPanel(void) } menuactive = true; - - // reset those just in case the game missed the keyup event - memset(dpadscrollstate, false, sizeof(dpadscrollstate)); + G_ResetControls(); if (demo.playback) {