From 0f11116e7b406eeebebffae6c532727d9214fb8b Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 1 Dec 2018 20:13:14 -0500 Subject: [PATCH 1/5] Fix up controller menu support --- src/m_menu.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index dfe8bbec..4b65303b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -160,7 +160,7 @@ typedef enum levellist_mode_t levellistmode = LLM_CREATESERVER; UINT8 maplistoption = 0; -static char joystickInfo[8][25]; +static char joystickInfo[8][29]; #ifndef NONET static UINT32 serverlistpage; #endif @@ -6711,37 +6711,38 @@ static void M_DrawJoystick(void) M_DrawGenericMenu(); - for (i = 0;i < 8; i++) + for (i = 0;i < 7; i++) { - M_DrawSaveLoadBorder(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i); + M_DrawTextBox(OP_JoystickSetDef.x-8, OP_JoystickSetDef.y+LINEHEIGHT*i-12, 28, 1); + //M_DrawSaveLoadBorder(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i); if ((setupcontrols_secondaryplayer && (i == cv_usejoystick2.value)) || (!setupcontrols_secondaryplayer && (i == cv_usejoystick.value))) - V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i,V_GREENMAP,joystickInfo[i]); + V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i-4,V_GREENMAP,joystickInfo[i]); else - V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i,0,joystickInfo[i]); + V_DrawString(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i-4,0,joystickInfo[i]); } } static void M_SetupJoystickMenu(INT32 choice) { INT32 i = 0; - const char *joyname = "None"; const char *joyNA = "Unavailable"; INT32 n = I_NumJoys(); (void)choice; - strcpy(joystickInfo[i], joyname); + strncpy(joystickInfo[i], "None", 5); for (i = 1; i < 8; i++) { - if (i <= n && (joyname = I_GetJoyName(i)) != NULL) + if (i <= n && (I_GetJoyName(i)) != NULL) { - strncpy(joystickInfo[i], joyname, 24); - joystickInfo[i][24] = '\0'; + strncpy(joystickInfo[i], I_GetJoyName(i), 28); + CONS_Printf("%s\n", joystickInfo[i]); } else strcpy(joystickInfo[i], joyNA); + CONS_Printf("%s\n", joystickInfo[i]); } M_SetupNextMenu(&OP_JoystickSetDef); From 19d19543b7184310c2eec368a255d1e8d78cc79e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 3 Dec 2018 05:37:07 -0500 Subject: [PATCH 2/5] Copy string from SDL_JoystickNameForIndex before the subsystem is shut down --- src/sdl/i_system.c | 24 +++++++++++++++++++++--- src/sdl12/i_system.c | 24 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2b35ce8b..905bec09 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1455,16 +1455,34 @@ INT32 I_NumJoys(void) const char *I_GetJoyName(INT32 joyindex) { - const char *joyname = "NA"; + const char *tempname = NULL; + size_t templen; + char *joyname = NULL; joyindex--; //SDL's Joystick System starts at 0, not 1 if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1) - joyname = SDL_JoystickNameForIndex(joyindex); + { + tempname = SDL_JoystickNameForIndex(joyindex); + if (tempname) + { + templen = strlen(tempname); + joyname = malloc(templen*sizeof(char)); + strcpy(joyname, tempname); + } + } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } else - joyname = SDL_JoystickNameForIndex(joyindex); + { + tempname = SDL_JoystickNameForIndex(joyindex); + if (tempname) + { + templen = strlen(tempname); + joyname = malloc(templen*sizeof(char)); + strcpy(joyname, tempname); + } + } return joyname; } diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index 8729e592..c4dd96f8 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -1577,16 +1577,34 @@ INT32 I_NumJoys(void) const char *I_GetJoyName(INT32 joyindex) { - const char *joyname = "NA"; + const char *tempname = NULL; + size_t templen; + char *joyname = NULL; joyindex--; //SDL's Joystick System starts at 0, not 1 if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1) - joyname = SDL_JoystickName(joyindex); + { + tempname = SDL_JoystickNameForIndex(joyindex); + if (tempname) + { + templen = strlen(tempname); + joyname = malloc(templen*sizeof(char)); + strcpy(joyname, tempname); + } + } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } else - joyname = SDL_JoystickName(joyindex); + { + tempname = SDL_JoystickNameForIndex(joyindex); + if (tempname) + { + templen = strlen(tempname); + joyname = malloc(templen*sizeof(char)); + strcpy(joyname, tempname); + } + } return joyname; } From d8e70c32e068f055cfe98d2acaf78152c4bb249b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 3 Dec 2018 05:39:10 -0500 Subject: [PATCH 3/5] Remove console messages for joynames --- src/m_menu.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 4b65303b..f6eb705f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6736,13 +6736,9 @@ static void M_SetupJoystickMenu(INT32 choice) for (i = 1; i < 8; i++) { if (i <= n && (I_GetJoyName(i)) != NULL) - { strncpy(joystickInfo[i], I_GetJoyName(i), 28); - CONS_Printf("%s\n", joystickInfo[i]); - } else strcpy(joystickInfo[i], joyNA); - CONS_Printf("%s\n", joystickInfo[i]); } M_SetupNextMenu(&OP_JoystickSetDef); From 8851f39b84a147bade43917b9cdb9d469bc9983a Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 3 Dec 2018 12:35:12 -0500 Subject: [PATCH 4/5] Use static joyname instead of malloc --- src/sdl/i_system.c | 16 ++++------------ src/sdl12/i_system.c | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 905bec09..68ebc5e9 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1453,11 +1453,11 @@ INT32 I_NumJoys(void) return numjoy; } +static char joyname[255]; // MAX_PATH; joystick name is straight from the driver + const char *I_GetJoyName(INT32 joyindex) { const char *tempname = NULL; - size_t templen; - char *joyname = NULL; joyindex--; //SDL's Joystick System starts at 0, not 1 if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { @@ -1465,11 +1465,7 @@ const char *I_GetJoyName(INT32 joyindex) { tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) - { - templen = strlen(tempname); - joyname = malloc(templen*sizeof(char)); - strcpy(joyname, tempname); - } + strncpy(joyname, tempname, 255); } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } @@ -1477,11 +1473,7 @@ const char *I_GetJoyName(INT32 joyindex) { tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) - { - templen = strlen(tempname); - joyname = malloc(templen*sizeof(char)); - strcpy(joyname, tempname); - } + strncpy(joyname, tempname, 255); } return joyname; } diff --git a/src/sdl12/i_system.c b/src/sdl12/i_system.c index c4dd96f8..10fbc50e 100644 --- a/src/sdl12/i_system.c +++ b/src/sdl12/i_system.c @@ -1575,11 +1575,11 @@ INT32 I_NumJoys(void) return numjoy; } +static char joyname[255]; // MAX_PATH; joystick name is straight from the driver + const char *I_GetJoyName(INT32 joyindex) { const char *tempname = NULL; - size_t templen; - char *joyname = NULL; joyindex--; //SDL's Joystick System starts at 0, not 1 if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { @@ -1587,11 +1587,7 @@ const char *I_GetJoyName(INT32 joyindex) { tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) - { - templen = strlen(tempname); - joyname = malloc(templen*sizeof(char)); - strcpy(joyname, tempname); - } + strncpy(joyname, tempname, 255); } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); } @@ -1599,11 +1595,7 @@ const char *I_GetJoyName(INT32 joyindex) { tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) - { - templen = strlen(tempname); - joyname = malloc(templen*sizeof(char)); - strcpy(joyname, tempname); - } + strncpy(joyname, tempname, 255); } return joyname; } From 168647275ca6d4e6cda29593e6c52097a41ec940 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 3 Dec 2018 13:32:24 -0500 Subject: [PATCH 5/5] One small change --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index f6eb705f..82c818c7 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6731,7 +6731,7 @@ static void M_SetupJoystickMenu(INT32 choice) INT32 n = I_NumJoys(); (void)choice; - strncpy(joystickInfo[i], "None", 5); + strcpy(joystickInfo[i], "None"); for (i = 1; i < 8; i++) {