From 5badc11159e6d754803aefaeff29cdf50e01ebc4 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 22 Dec 2018 20:17:50 -0500 Subject: [PATCH 01/11] Fix integer overflow on for loop decrements --- src/hu_stuff.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fc5ae657..984d1016 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -847,10 +847,13 @@ static inline boolean HU_keyInChatString(char *s, char ch) // move everything past c_input for new characters: size_t m = HU_MAXMSGLEN-1; - for (;(m>=c_input);m--) + while (m>=c_input) { if (s[m]) s[m+1] = (s[m]); + if (m == 0) // prevent overflow + break; + m--; } s[c_input] = ch; // and replace this. } @@ -1177,11 +1180,13 @@ boolean HU_Responder(event_t *ev) else // otherwise, we need to shift everything and make space, etc etc { size_t i = HU_MAXMSGLEN-1; - for (; i>=c_input;i--) + while (i >= c_input) { if (w_chat[i]) w_chat[i+pastelen] = w_chat[i]; - + if (i == 0) // prevent overflow + break; + i--; } memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. c_input += pastelen; From 0f0e30924f3d32571efc30595f42a83003581ffd Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 22 Dec 2018 20:35:12 -0500 Subject: [PATCH 02/11] One more free(nodenum) --- src/hu_stuff.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 984d1016..094db29e 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1730,6 +1730,7 @@ static void HU_DrawChat(void) nodenum = (char*) malloc(3); strncpy(nodenum, w_chat+3, 3); n = atoi((const char*) nodenum); // turn that into a number + free(nodenum); // special cases: if ((n == 0) && !(w_chat[4] == '0')) From fb3722a6f37e1e0182762e3fbee001b3a4c37ea5 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 22 Dec 2018 20:52:32 -0500 Subject: [PATCH 03/11] Accommodate Kart splitscreen code for CHAT via #define NETSPLITSCREEN --- src/d_net.h | 1 + src/hu_stuff.c | 32 ++++++++++++++++---------------- src/hu_stuff.h | 4 ++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/d_net.h b/src/d_net.h index 55ea308b..61c669db 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -22,6 +22,7 @@ #define MAXNETNODES 32 #define BROADCASTADDR MAXNETNODES #define MAXSPLITSCREENPLAYERS 2 // Max number of players on a single computer +//#define NETSPLITSCREEN // Kart's splitscreen netgame feature #define STATLENGTH (TICRATE*2) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 094db29e..1f474d22 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1488,27 +1488,27 @@ static void HU_drawChatLog(INT32 offset) if (chat_scroll > chat_maxscroll) chat_scroll = chat_maxscroll; - /*if (splitscreen) +#ifdef NETSPLITSCREEN + if (splitscreen) { boxh = max(6, boxh/2); if (splitscreen > 1) boxw = max(64, boxw/2); - }*/ - - // Unused SRB2KART splitscreen stuff. I'll leave it here in case it ever happens in Vanilla? + } +#endif y = chaty - offset*charheight - (chat_scroll*charheight) - boxh*charheight - 12; - /*if (splitscreen) +#ifdef NETSPLITSCREEN + if (splitscreen) { y -= BASEVIDHEIGHT/2; if (splitscreen > 1) y += 16; - }*/ + } +#endif y -= (G_RingSlingerGametype() ? 16 : 0); - // Unused SRB2KART splitscreen stuff. I'll leave it here in case it ever happens in Vanilla? (x2) - chat_topy = y + chat_scroll*charheight; chat_bottomy = chat_topy + boxh*charheight; @@ -1607,7 +1607,8 @@ static void HU_DrawChat(void) const char *talk = ntalk; const char *mute = "Chat has been muted."; - /*if (splitscreen) +#ifdef NETSPLITSCREEN + if (splitscreen) { y -= BASEVIDHEIGHT/2; if (splitscreen > 1) @@ -1615,11 +1616,10 @@ static void HU_DrawChat(void) y += 16; boxw = max(64, boxw/2); } - }*/ + } +#endif y -= (G_RingSlingerGametype() ? 16 : 0); - // More unused SRB2KART stuff. - if (teamtalk) { talk = ttalk; @@ -1703,16 +1703,16 @@ static void HU_DrawChat(void) { INT32 count = 0; INT32 p_dispy = chaty - charheight -1; - /*if (splitscreen) +#ifdef NETSPLITSCREEN + if (splitscreen) { p_dispy -= BASEVIDHEIGHT/2; if (splitscreen > 1) p_dispy += 16; - }*/ + } +#endif p_dispy -= (G_RingSlingerGametype() ? 16 : 0); - // more kart leftovers. - i = 0; for(i=0; (i Date: Sat, 22 Dec 2018 20:57:53 -0500 Subject: [PATCH 04/11] Draw up and down arrows by string --- src/hu_stuff.c | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 1f474d22..40c06538 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1440,39 +1440,6 @@ static void HU_drawMiniChat(void) } - -// HU_DrawUpArrow -// You see, we don't have arrow graphics in 2.1 and I'm too lazy to include a 2 bytes file for it. - -static void HU_DrawUpArrow(INT32 x, INT32 y, INT32 options) -{ - // Ok I'm super lazy so let's make this as the worst draw function: - V_DrawFill(x+2, y, 1, 1, 103|options); - V_DrawFill(x+1, y+1, 3, 1, 103|options); - V_DrawFill(x, y+2, 5, 1, 103|options); // that's the yellow part, I swear - - V_DrawFill(x+3, y, 1, 1, 26|options); - V_DrawFill(x+4, y+1, 1, 1, 26|options); - V_DrawFill(x+5, y+2, 1, 1, 26|options); - V_DrawFill(x, y+3, 6, 1, 26|options); // that's the black part. no racism intended. i swear. -} - -// HU_DrawDownArrow -// Should we talk about anime waifus to pass the time? This feels retarded. - -static void HU_DrawDownArrow(INT32 x, INT32 y, INT32 options) -{ - // Ok I'm super lazy so let's make this as the worst draw function: - V_DrawFill(x, y, 6, 1, 26|options); - V_DrawFill(x, y+1, 5, 1, 26|options); - V_DrawFill(x+1, y+2, 3, 1, 26|options); - V_DrawFill(x+2, y+3, 1, 1, 26|options); // that's the black part. no racism intended. i swear. - - V_DrawFill(x, y, 5, 1, 103|options); - V_DrawFill(x+1, y+1, 3, 1, 103|options); - V_DrawFill(x+2, y+2, 1, 1, 103|options); // that's the yellow part, I swear -} - // HU_DrawChatLog static void HU_drawChatLog(INT32 offset) @@ -1580,11 +1547,10 @@ static void HU_drawChatLog(INT32 offset) chat_scroll = chat_maxscroll; // draw arrows to indicate that we can (or not) scroll. - if (chat_scroll > 0) - HU_DrawUpArrow(chatx-8, ((justscrolledup) ? (chat_topy-1) : (chat_topy)), V_SNAPTOBOTTOM | V_SNAPTOLEFT); + V_DrawString(chatx-8, ((justscrolledup) ? (chat_topy-1) : (chat_topy)), V_SNAPTOBOTTOM | V_SNAPTOLEFT | V_YELLOWMAP, "\x1A"); // up arrow if (chat_scroll < chat_maxscroll) - HU_DrawDownArrow(chatx-8, chat_bottomy-((justscrolleddown) ? 3 : 4), V_SNAPTOBOTTOM | V_SNAPTOLEFT); + V_DrawString(chatx-8, chat_bottomy-((justscrolleddown) ? 3 : 4), V_SNAPTOBOTTOM | V_SNAPTOLEFT | V_YELLOWMAP, "\x1B"); // down arrow justscrolleddown = false; justscrolledup = false; From 7e9411f320b75f7f90cc9f16a501d7aed7e88ae4 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 22 Dec 2018 21:17:01 -0500 Subject: [PATCH 05/11] Minor code cleanup, CHAT --- src/hu_stuff.c | 238 ++++++++++++++++++++++++------------------------- 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 40c06538..1fea28f0 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -73,7 +73,7 @@ patch_t *cred_font[CRED_FONTSIZE]; static player_t *plr; boolean chat_on; // entering a chat message? static char w_chat[HU_MAXMSGLEN]; -static size_t c_input = 0; // let's try to make the chat input less shitty. +static size_t c_input = 0; // let's try to make the chat input less shitty. static boolean headsupactive = false; boolean hu_showscores; // draw rankings static char hu_tick; @@ -328,20 +328,20 @@ static UINT32 chat_nummsg_min = 0; static UINT32 chat_scroll = 0; static tic_t chat_scrolltime = 0; -static UINT32 chat_maxscroll = 0; // how far can we scroll? +static UINT32 chat_maxscroll = 0; // how far can we scroll? -//static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent. -//static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool. +//static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent. +//static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool. -static char chat_log[CHAT_BUFSIZE][255]; // hold the last 48 or so messages in that log. -static char chat_mini[8][255]; // display up to 8 messages that will fade away / get overwritten +static char chat_log[CHAT_BUFSIZE][255]; // hold the last 48 or so messages in that log. +static char chat_mini[8][255]; // display up to 8 messages that will fade away / get overwritten static tic_t chat_timers[8]; -static boolean chat_scrollmedown = false; // force instant scroll down on the chat log. Happens when you open it / send a message. +static boolean chat_scrollmedown = false; // force instant scroll down on the chat log. Happens when you open it / send a message. // remove text from minichat table -static INT16 addy = 0; // use this to make the messages scroll smoothly when one fades away +static INT16 addy = 0; // use this to make the messages scroll smoothly when one fades away static void HU_removeChatText_Mini(void) { @@ -351,7 +351,7 @@ static void HU_removeChatText_Mini(void) strcpy(chat_mini[i], chat_mini[i+1]); chat_timers[i] = chat_timers[i+1]; } - chat_nummsg_min--; // lost 1 msg. + chat_nummsg_min--; // lost 1 msg. // use addy and make shit slide smoothly af. addy += (vid.width < 640) ? 8 : 6; @@ -366,16 +366,16 @@ static void HU_removeChatText_Log(void) for(i=0;i