From d9bc478822f4ea9df901ea6485f6f62f3d4426ec Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 15:39:16 +0100 Subject: [PATCH 01/30] Cleanup blank chatbox checking code --- src/hu_stuff.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 3107057a1..086d9f799 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -946,25 +946,15 @@ void HU_Ticker(void) static boolean teamtalk = false; -// Clear spaces so we don't end up with messages only made out of emptiness -static boolean HU_clearChatSpaces(void) +static boolean HU_chatboxContainsOnlySpaces(void) { - size_t i = 0; // Used to just check our message - char c; // current character we're iterating. - boolean nothingbutspaces = true; + size_t i; - for (; i < strlen(w_chat); i++) // iterate through message and eradicate all spaces that don't belong. - { - c = w_chat[i]; - if (!c) - break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. + for (i = 0; w_chat[i]; i++) + if (w_chat[i] != ' ') + return false; - if (c != ' ') // Isn't a space - { - nothingbutspaces = false; - } - } - return nothingbutspaces; + return true; } // @@ -980,8 +970,9 @@ static void HU_queueChatChar(char c) size_t ci = 2; INT32 target = 0; - if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. - return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + // if our message was nothing but spaces, don't send it. + if (HU_chatboxContainsOnlySpaces()) + return; do { c = w_chat[-2+ci++]; From 34ad64ba591aa969d080a56edfaf5f4bc53b3ddd Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 15:41:54 +0100 Subject: [PATCH 02/30] Cleanup chatbox reset code --- src/hu_stuff.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 086d9f799..50be5e233 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -966,7 +966,6 @@ static void HU_queueChatChar(char c) { char buf[2+256]; char *msg = &buf[2]; - size_t i = 0; size_t ci = 2; INT32 target = 0; @@ -980,9 +979,7 @@ static void HU_queueChatChar(char c) buf[ci-1]=c; } while (c); - for (;(i Date: Sun, 2 Jan 2022 15:48:31 +0100 Subject: [PATCH 03/30] Cleanup chatbox sanitizing code --- src/hu_stuff.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 50be5e233..fdbef2980 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -966,18 +966,21 @@ static void HU_queueChatChar(char c) { char buf[2+256]; char *msg = &buf[2]; - size_t ci = 2; + size_t ci; INT32 target = 0; // if our message was nothing but spaces, don't send it. if (HU_chatboxContainsOnlySpaces()) return; - do { - c = w_chat[-2+ci++]; - if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. - buf[ci-1]=c; - } while (c); + // copy printable characters and terminating '\0' only. + for (ci = 2; w_chat[ci-2]; ci++) + { + c = w_chat[ci-2]; + if (c >= ' ' && !(c & 0x80)) + buf[ci] = c; + }; + buf[ci] = '\0'; memset(w_chat, '\0', HU_MAXMSGLEN); c_input = 0; From 3638d5d55692090da133b66ad93d9ddbf5570555 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:08:10 +0100 Subject: [PATCH 04/30] Cleanup chat code a little --- src/hu_stuff.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fdbef2980..29686cd26 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -957,11 +957,8 @@ static boolean HU_chatboxContainsOnlySpaces(void) return true; } -// -// static void HU_queueChatChar(char c) { - // send automaticly the message (no more chat char) if (c == KEY_ENTER) { char buf[2+256]; @@ -1010,7 +1007,7 @@ static void HU_queueChatChar(char c) strncpy(playernum, msg+3, 3); // check for undesirable characters in our "number" - if (((playernum[0] < '0') || (playernum[0] > '9')) || ((playernum[1] < '0') || (playernum[1] > '9'))) + if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) { // check if playernum[1] is a space if (playernum[1] == ' ') @@ -1023,17 +1020,13 @@ static void HU_queueChatChar(char c) } } // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0) + if (spc != 0 && msg[5] != ' ') { - if (msg[5] != ' ') - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + return; } target = atoi(playernum); // turn that into a number - //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! if (target < MAXPLAYERS && playeringame[target]) // player exists @@ -1050,11 +1043,7 @@ static void HU_queueChatChar(char c) } if (ci > 3) // don't send target+flags+empty message. { - if (teamtalk) - buf[0] = -1; // target - else - buf[0] = target; - + buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } From b8975b6a71c9814aa9f0f0630de1d77754a0b56c Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:38:49 +0100 Subject: [PATCH 05/30] Group related chat stuff together --- src/hu_stuff.c | 144 ++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 73 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 29686cd26..60f3d9969 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -858,72 +858,6 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) #endif } -// Handles key input and string input -// -static inline boolean HU_keyInChatString(char *s, char ch) -{ - size_t l; - - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - 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. - } - c_input++; - return true; - } - return false; - } - else if (ch == KEY_BACKSPACE) - { - size_t i = c_input; - - if (c_input <= 0) - return false; - - if (!s[i-1]) - return false; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return false; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } - c_input--; - } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key -} - #endif // @@ -945,6 +879,10 @@ void HU_Ticker(void) #ifndef NONET static boolean teamtalk = false; +static boolean justscrolleddown; +static boolean justscrolledup; +static INT16 typelines = 1; // number of drawfill lines we need when drawing the chat. it's some weird hack and might be one frame off but I'm lazy to make another loop. +// It's up here since it has to be reset when we open the chat. static boolean HU_chatboxContainsOnlySpaces(void) { @@ -1050,6 +988,73 @@ static void HU_queueChatChar(char c) return; } } + +// Handles key input and string input +// +static inline boolean HU_keyInChatString(char *s, char ch) +{ + size_t l; + + if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) + || ch == ' ') // Allow spaces, of course + { + l = strlen(s); + if (l < HU_MAXMSGLEN - 1) + { + if (c_input >= strlen(s)) // don't do anything complicated + { + s[l++] = ch; + s[l]=0; + } + else + { + + // move everything past c_input for new characters: + size_t m = HU_MAXMSGLEN-1; + 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. + } + c_input++; + return true; + } + return false; + } + else if (ch == KEY_BACKSPACE) + { + size_t i = c_input; + + if (c_input <= 0) + return false; + + if (!s[i-1]) + return false; + + if (i >= strlen(s)-1) + { + s[strlen(s)-1] = 0; + c_input--; + return false; + } + + for (; (i < HU_MAXMSGLEN); i++) + { + s[i-1] = s[i]; + } + c_input--; + } + else if (ch != KEY_ENTER) + return false; // did not eat key + + return true; // ate the key +} + #endif void HU_clearChatChars(void) @@ -1061,13 +1066,6 @@ void HU_clearChatChars(void) I_UpdateMouseGrab(); } -#ifndef NONET -static boolean justscrolleddown; -static boolean justscrolledup; -static INT16 typelines = 1; // number of drawfill lines we need when drawing the chat. it's some weird hack and might be one frame off but I'm lazy to make another loop. -// It's up here since it has to be reset when we open the chat. -#endif - // // Returns true if key eaten // From 2bbbd57c6e3ce058b9bb4510260a1fb0496585ef Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 17:55:14 +0100 Subject: [PATCH 06/30] Turn HU_queueChatChar into HU_sendChatMessage --- src/hu_stuff.c | 179 +++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 95 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 60f3d9969..1def5c153 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -895,103 +895,99 @@ static boolean HU_chatboxContainsOnlySpaces(void) return true; } -static void HU_queueChatChar(char c) +static void HU_sendChatMessage(void) { - if (c == KEY_ENTER) + char buf[2+256]; + char *msg = &buf[2]; + size_t ci; + INT32 target = 0; + + // if our message was nothing but spaces, don't send it. + if (HU_chatboxContainsOnlySpaces()) + return; + + // copy printable characters and terminating '\0' only. + for (ci = 2; w_chat[ci-2]; ci++) { - char buf[2+256]; - char *msg = &buf[2]; - size_t ci; - INT32 target = 0; + char c = w_chat[ci-2]; + if (c >= ' ' && !(c & 0x80)) + buf[ci] = c; + }; + buf[ci] = '\0'; - // if our message was nothing but spaces, don't send it. - if (HU_chatboxContainsOnlySpaces()) - return; + memset(w_chat, '\0', HU_MAXMSGLEN); + c_input = 0; - // copy printable characters and terminating '\0' only. - for (ci = 2; w_chat[ci-2]; ci++) + // last minute mute check + if (CHAT_MUTE) + { + HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + return; + } + + if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + { + INT32 spc = 1; // used if playernum[1] is a space. + char playernum[3]; + const char *newmsg; + + // what we're gonna do now is check if the player exists + // with that logic, characters 4 and 5 are our numbers: + + // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. + if (teamtalk) { - c = w_chat[ci-2]; - if (c >= ' ' && !(c & 0x80)) - buf[ci] = c; - }; - buf[ci] = '\0'; - - memset(w_chat, '\0', HU_MAXMSGLEN); - c_input = 0; - - // last minute mute check - if (CHAT_MUTE) - { - HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); return; } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + strncpy(playernum, msg+3, 3); + // check for undesirable characters in our "number" + if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) { - INT32 spc = 1; // used if playernum[1] is a space. - char playernum[3]; - const char *newmsg; - - // what we're gonna do now is check if the player exists - // with that logic, characters 4 and 5 are our numbers: - - // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. - if (teamtalk) - { - HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); - return; - } - - strncpy(playernum, msg+3, 3); - // check for undesirable characters in our "number" - if (!(isdigit(playernum[0]) && isdigit(playernum[1]))) - { - // check if playernum[1] is a space - if (playernum[1] == ' ') - spc = 0; - // let it slide - else - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - return; - } - } - // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0 && msg[5] != ' ') + // check if playernum[1] is a space + if (playernum[1] == ' ') + spc = 0; + // let it slide + else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); return; } - - target = atoi(playernum); // turn that into a number - - // check for target player, if it doesn't exist then we can't send the message! - if (target < MAXPLAYERS && playeringame[target]) // player exists - target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! - else - { - HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same - return; - } - - // we need to get rid of the /pm - newmsg = msg+5+spc; - strlcpy(msg, newmsg, 255); } - if (ci > 3) // don't send target+flags+empty message. + // I'm very bad at C, I swear I am, additional checks eww! + if (spc != 0 && msg[5] != ' ') { - buf[0] = teamtalk ? -1 : target; // target - buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + return; } - return; + + target = atoi(playernum); // turn that into a number + + // check for target player, if it doesn't exist then we can't send the message! + if (target < MAXPLAYERS && playeringame[target]) // player exists + target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + else + { + HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + return; + } + + // we need to get rid of the /pm + newmsg = msg+5+spc; + strlcpy(msg, newmsg, 255); + } + if (ci > 3) // don't send target+flags+empty message. + { + buf[0] = teamtalk ? -1 : target; // target + buf[1] = 0; // flags + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } // Handles key input and string input // -static inline boolean HU_keyInChatString(char *s, char ch) +static inline void HU_keyInChatString(char *s, char ch) { size_t l; @@ -1022,25 +1018,25 @@ static inline boolean HU_keyInChatString(char *s, char ch) s[c_input] = ch; // and replace this. } c_input++; - return true; + return; } - return false; + return; } else if (ch == KEY_BACKSPACE) { size_t i = c_input; if (c_input <= 0) - return false; + return; if (!s[i-1]) - return false; + return; if (i >= strlen(s)-1) { s[strlen(s)-1] = 0; c_input--; - return false; + return; } for (; (i < HU_MAXMSGLEN); i++) @@ -1049,10 +1045,6 @@ static inline boolean HU_keyInChatString(char *s, char ch) } c_input--; } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key } #endif @@ -1174,14 +1166,9 @@ boolean HU_Responder(event_t *ev) { memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. c_input += pastelen; - /*size_t i = 0; - for (;i= c_input) @@ -1198,12 +1185,11 @@ boolean HU_Responder(event_t *ev) } } - if (!CHAT_MUTE && HU_keyInChatString(w_chat,c)) - { - HU_queueChatChar(c); - } if (c == KEY_ENTER) { + if (!CHAT_MUTE) + HU_sendChatMessage(); + chat_on = false; c_input = 0; // reset input cursor chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) @@ -1244,6 +1230,9 @@ boolean HU_Responder(event_t *ev) else c_input++; } + else if (!CHAT_MUTE) + HU_keyInChatString(w_chat, c); + return true; } #endif From e761e36c55e3ecf412ee552b6a2dadd25e77d635 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 23:06:34 +0100 Subject: [PATCH 07/30] Cleanup and fix chat deleting and pasting --- src/hu_stuff.c | 87 ++++++++++---------------------------------------- src/hu_stuff.h | 2 +- 2 files changed, 17 insertions(+), 72 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 1def5c153..c43d6b62a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -76,7 +76,7 @@ patch_t *nto_font[NT_FONTSIZE]; static player_t *plr; boolean chat_on; // entering a chat message? -static char w_chat[HU_MAXMSGLEN]; +static char w_chat[HU_MAXMSGLEN + 1]; 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 @@ -915,7 +915,7 @@ static void HU_sendChatMessage(void) }; buf[ci] = '\0'; - memset(w_chat, '\0', HU_MAXMSGLEN); + memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; // last minute mute check @@ -985,64 +985,27 @@ static void HU_sendChatMessage(void) } } +// // Handles key input and string input // static inline void HU_keyInChatString(char *s, char ch) { - size_t l; - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) || ch == ' ') // Allow spaces, of course { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - 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. - } - c_input++; + if (strlen(s) >= HU_MAXMSGLEN) return; - } - return; + + memmove(&s[c_input + 1], &s[c_input], strlen(s) - c_input + 1); + s[c_input] = ch; + c_input++; } else if (ch == KEY_BACKSPACE) { - size_t i = c_input; - if (c_input <= 0) return; - if (!s[i-1]) - return; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } + memmove(&s[c_input - 1], &s[c_input], strlen(s) - c_input + 1); c_input--; } } @@ -1051,7 +1014,7 @@ static inline void HU_keyInChatString(char *s, char ch) void HU_clearChatChars(void) { - memset(w_chat, '\0', HU_MAXMSGLEN); + memset(w_chat, '\0', sizeof(w_chat)); chat_on = false; c_input = 0; @@ -1148,12 +1111,11 @@ boolean HU_Responder(event_t *ev) // pasting. pasting is cool. chat is a bit limited, though :( if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) { - const char *paste = I_ClipboardPaste(); + const char *paste; size_t chatlen; size_t pastelen; - // create a dummy string real quickly - + paste = I_ClipboardPaste(); if (paste == NULL) return true; @@ -1162,27 +1124,10 @@ boolean HU_Responder(event_t *ev) if (chatlen+pastelen > HU_MAXMSGLEN) return true; // we can't paste this!! - if (c_input >= strlen(w_chat)) // add it at the end of the string. - { - memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. - c_input += pastelen; - return true; - } - else // otherwise, we need to shift everything and make space, etc etc - { - size_t i = HU_MAXMSGLEN-1; - 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; - return true; - } + memmove(&w_chat[c_input + pastelen], &w_chat[c_input], pastelen); + memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. + c_input += pastelen; + return true; } if (c == KEY_ENTER) diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 9b7cee2d3..bb1a59e69 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -62,7 +62,7 @@ typedef struct //------------------------------------ // chat stuff //------------------------------------ -#define HU_MAXMSGLEN 224 +#define HU_MAXMSGLEN 223 #define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. #ifdef NETSPLITSCREEN #define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640) From b933316f23e809a8ebb5d4d4a41e7051a88cdab1 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 2 Jan 2022 23:19:34 +0100 Subject: [PATCH 08/30] Cleanup chat event handling --- src/hu_stuff.c | 55 ++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index c43d6b62a..755e7a237 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -985,31 +985,6 @@ static void HU_sendChatMessage(void) } } -// -// Handles key input and string input -// -static inline void HU_keyInChatString(char *s, char ch) -{ - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - if (strlen(s) >= HU_MAXMSGLEN) - return; - - memmove(&s[c_input + 1], &s[c_input], strlen(s) - c_input + 1); - s[c_input] = ch; - c_input++; - } - else if (ch == KEY_BACKSPACE) - { - if (c_input <= 0) - return; - - memmove(&s[c_input - 1], &s[c_input], strlen(s) - c_input + 1); - c_input--; - } -} - #endif void HU_clearChatChars(void) @@ -1102,19 +1077,22 @@ boolean HU_Responder(event_t *ev) if (shiftdown ^ capslock) c = shiftxform[c]; } - else // if we're holding shift we should still shift non letter symbols + else // if we're holding shift we should still shift non letter symbols { if (shiftdown) c = shiftxform[c]; } // pasting. pasting is cool. chat is a bit limited, though :( - if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) + if ((c == 'v' || c == 'V') && ctrldown) { const char *paste; size_t chatlen; size_t pastelen; + if (CHAT_MUTE) + return true; + paste = I_ClipboardPaste(); if (paste == NULL) return true; @@ -1129,8 +1107,7 @@ boolean HU_Responder(event_t *ev) c_input += pastelen; return true; } - - if (c == KEY_ENTER) + else if (c == KEY_ENTER) { if (!CHAT_MUTE) HU_sendChatMessage(); @@ -1175,8 +1152,24 @@ boolean HU_Responder(event_t *ev) else c_input++; } - else if (!CHAT_MUTE) - HU_keyInChatString(w_chat, c); + else if ((c >= HU_FONTSTART && c <= HU_FONTEND && hu_font[c-HU_FONTSTART]) + || c == ' ') // Allow spaces, of course + { + if (CHAT_MUTE || strlen(w_chat) >= HU_MAXMSGLEN) + return true; + + memmove(&w_chat[c_input + 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); + w_chat[c_input] = c; + c_input++; + } + else if (c == KEY_BACKSPACE) + { + if (CHAT_MUTE || c_input <= 0) + return true; + + memmove(&w_chat[c_input - 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); + c_input--; + } return true; } From 055d57c56c9233e7dbf6f588b110373bf54cffb2 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:06:20 +0100 Subject: [PATCH 09/30] Fix single-letter messages not being sent --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 755e7a237..484f3ee43 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -977,7 +977,7 @@ static void HU_sendChatMessage(void) newmsg = msg+5+spc; strlcpy(msg, newmsg, 255); } - if (ci > 3) // don't send target+flags+empty message. + if (ci > 2) // don't send target+flags+empty message. { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags From 3c8a29f1ff5b62a0ca4ff636b9668df0ff894068 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:06:43 +0100 Subject: [PATCH 10/30] Add SKIPSTRINGN macro --- src/byteptr.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/byteptr.h b/src/byteptr.h index 4c8414fae..4de415505 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -154,7 +154,8 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) #define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) -#define SKIPSTRING(p) while (READCHAR(p) != '\0') +#define SKIPSTRING(p) while (READCHAR(p) != '\0') +#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); }) #define READSTRINGN(p,s,n) ({ size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) #define READSTRING(p,s) ({ size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) From af629fefe996f58a0a77bb0d759a40e31b7e23a6 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:08:23 +0100 Subject: [PATCH 11/30] Fix long chat messages crashing the game --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 484f3ee43..8a8a6498d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -644,7 +644,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); msg = (char *)*p; - SKIPSTRING(*p); + SKIPSTRINGN(*p, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { From 159be00109ebe379dd737f811b9f03fc85454681 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 00:30:16 +0100 Subject: [PATCH 12/30] Support delete key in chatbox --- src/hu_stuff.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 8a8a6498d..fbd485b0a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1170,6 +1170,13 @@ boolean HU_Responder(event_t *ev) memmove(&w_chat[c_input - 1], &w_chat[c_input], strlen(w_chat) - c_input + 1); c_input--; } + else if (c == KEY_DEL) + { + if (CHAT_MUTE || c_input >= strlen(w_chat)) + return true; + + memmove(&w_chat[c_input], &w_chat[c_input + 1], strlen(w_chat) - c_input); + } return true; } From 0241016f6a258f1ef14d5dd2520f76f45bac95fd Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 12:13:55 +0100 Subject: [PATCH 13/30] Do not attempt to disconnect when a packet checksum is invalid --- src/d_net.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 3a4746002..fc029f967 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1144,8 +1144,9 @@ boolean HGetPacket(void) if (netbuffer->checksum != NetbufferChecksum()) { DEBFILE("Bad packet checksum\n"); - //Net_CloseConnection(nodejustjoined ? (doomcom->remotenode | FORCECLOSE) : doomcom->remotenode); - Net_CloseConnection(doomcom->remotenode); + // Do not disconnect or anything, just ignore the packet. + // Bad checksums with UDP tend to happen very scarcely + // so they are not normally an issue. continue; } From 13778247990d60c2ad8aa5729bc0397ab764eaaa Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 3 Jan 2022 22:37:19 +0100 Subject: [PATCH 14/30] Fix long chat messages causing net command failures --- src/hu_stuff.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fbd485b0a..5f838b894 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -634,7 +634,8 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) SINT8 target; UINT8 flags; const char *dispname; - char *msg; + char msgbuf[HU_MAXMSGLEN + 1]; + char *msg = msgbuf; boolean action = false; char *ptr; INT32 spam_eatmsg = 0; @@ -643,8 +644,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); - msg = (char *)*p; - SKIPSTRINGN(*p, HU_MAXMSGLEN); + READSTRINGN(*p, msgbuf, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { @@ -913,7 +913,11 @@ static void HU_sendChatMessage(void) if (c >= ' ' && !(c & 0x80)) buf[ci] = c; }; - buf[ci] = '\0'; + if (ci-2 < HU_MAXMSGLEN) + { + buf[ci] = '\0'; + ci++; + } memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; @@ -981,7 +985,7 @@ static void HU_sendChatMessage(void) { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + SendNetXCmd(XD_SAY, buf, ci); } } From a8fe12ae9836e6e4dff788bd9d8d2a0da77c6937 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Tue, 4 Jan 2022 22:30:50 +0200 Subject: [PATCH 15/30] Hack that fixes software drop shadow crashes by bypassing incorrectly set variables --- src/r_draw.h | 1 + src/r_draw8.c | 33 +++++++++++++++++++++++++++++++++ src/r_things.c | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/src/r_draw.h b/src/r_draw.h index 2173c7a5a..2576e1577 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -170,6 +170,7 @@ void R_DrawViewBorder(void); void R_DrawColumn_8(void); void R_DrawShadeColumn_8(void); void R_DrawTranslucentColumn_8(void); +void R_DrawDropShadowColumn_8(void); void R_DrawTranslatedColumn_8(void); void R_DrawTranslatedTranslucentColumn_8(void); void R_Draw2sMultiPatchColumn_8(void); diff --git a/src/r_draw8.c b/src/r_draw8.c index b8a63d5c0..182182574 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -416,6 +416,39 @@ void R_DrawTranslucentColumn_8(void) } } +// Hack: A cut-down copy of R_DrawTranslucentColumn_8 that does not read texture +// data since something about calculating the texture reading address for drop shadows is broken. +// dc_texturemid and dc_iscale get wrong values for drop shadows, however those are not strictly +// needed for the current design of the shadows, so this function bypasses the issue +// by not using those variables at all. +void R_DrawDropShadowColumn_8(void) +{ + register INT32 count; + register UINT8 *dest; + + count = dc_yh - dc_yl + 1; + + if (count <= 0) // Zero length, column does not exceed a pixel. + return; + + dest = &topleft[dc_yl*vid.width + dc_x]; + + { +#define DSCOLOR 31 // palette index for the color of the shadow + register const UINT8 *transmap_offset = dc_transmap + (dc_colormap[DSCOLOR] << 8); +#undef DSCOLOR + while ((count -= 2) >= 0) + { + *dest = *(transmap_offset + (*dest)); + dest += vid.width; + *dest = *(transmap_offset + (*dest)); + dest += vid.width; + } + if (count & 1) + *dest = *(transmap_offset + (*dest)); + } +} + /** \brief The R_DrawTranslatedTranslucentColumn_8 function Spiffy function. Not only does it colormap a sprite, but does translucency as well. Uber-kudos to Cyan Helkaraxe diff --git a/src/r_things.c b/src/r_things.c index bed71a6d7..85c085043 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -837,6 +837,12 @@ static void R_DrawVisSprite(vissprite_t *vis) else if (vis->mobj->sprite == SPR_PLAY) // Looks like a player, but doesn't have a color? Get rid of green sonic syndrome. colfunc = colfuncs[COLDRAWFUNC_TRANS]; + // Hack: Use a special column function for drop shadows that bypasses + // invalid memory access crashes caused by R_ProjectDropShadow putting wrong values + // in dc_texturemid and dc_iscale when the shadow is sloped. + if (vis->cut & SC_SHADOW) + colfunc = R_DrawDropShadowColumn_8; + if (vis->extra_colormap && !(vis->renderflags & RF_NOCOLORMAPS)) { if (!dc_colormap) From 549569e75b4c072a54d9ab39926521c6cc198895 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 5 Jan 2022 10:08:49 +0100 Subject: [PATCH 16/30] Fix offset calculation for segs that represent linedef backsides --- src/p_setup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 7f9674e4e..de91f4674 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2494,7 +2494,10 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype P_InitializeSeg(seg); seg->angle = R_PointToAngle2(v1->x, v1->y, v2->x, v2->y); if (seg->linedef) - segs[i].offset = FixedHypot(v1->x - seg->linedef->v1->x, v1->y - seg->linedef->v1->y); + { + vertex_t *v = (seg->side == 1) ? seg->linedef->v2 : seg->linedef->v1; + segs[i].offset = FixedHypot(v1->x - v->x, v1->y - v->y); + } seg->length = P_SegLength(seg); #ifdef HWRENDER seg->flength = (rendermode == render_opengl) ? P_SegLengthFloat(seg) : 0; From e0afc2d2b67d49ddd7d031c60bc610b8325df158 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 9 Jan 2022 17:09:57 -0600 Subject: [PATCH 17/30] Add a player->mo check before attempting to account for ztargetting. --- src/g_game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index 3955834b2..c2eda8fa0 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1411,7 +1411,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) newtarget = P_SpawnMobj(ticcmd_ztargetfocus[forplayer]->x, ticcmd_ztargetfocus[forplayer]->y, ticcmd_ztargetfocus[forplayer]->z, MT_LOCKON); // positioning, flip handled in P_SceneryThinker P_SetTarget(&newtarget->target, ticcmd_ztargetfocus[forplayer]); - if (P_AproxDistance( + if (player->mo && P_AproxDistance( player->mo->x - ticcmd_ztargetfocus[forplayer]->x, player->mo->y - ticcmd_ztargetfocus[forplayer]->y ) > 50*player->mo->scale) From a66854608855b2ee9336169cf7393b8a21c1b86e Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 18:56:42 +0100 Subject: [PATCH 18/30] Make byte stream manipulation code easier to read --- src/byteptr.h | 71 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index 4de415505..f66d9fcaf 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #undef DEALIGNED -#define WRITESTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); if (tmp_i < n) WRITECHAR(p, '\0');} while (0) -#define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) -#define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) +#define WRITESTRINGN(p, s, n) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + if (tmp_i < n) \ + WRITECHAR(p, '\0'); \ +}) -#define SKIPSTRING(p) while (READCHAR(p) != '\0') -#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); }) +#define WRITESTRING(p, s) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + WRITECHAR(p, '\0'); \ +}) -#define READSTRINGN(p,s,n) ({ size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) -#define READSTRING(p,s) ({ size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) -#define READMEM(p,s,n) ({ memcpy(s, p, n); p += n; }) +#define WRITEMEM(p, s, n) ({ \ + memcpy(p, s, n); \ + p += n; \ +}) -#if 0 // old names -#define WRITEBYTE(p,b) WRITEUINT8(p,b) -#define WRITESHORT(p,b) WRITEINT16(p,b) -#define WRITEUSHORT(p,b) WRITEUINT16(p,b) -#define WRITELONG(p,b) WRITEINT32(p,b) -#define WRITEULONG(p,b) WRITEUINT32(p,b) +#define SKIPSTRING(p) while (READCHAR(p) != '\0') -#define READBYTE(p) READUINT8(p) -#define READSHORT(p) READINT16(p) -#define READUSHORT(p) READUINT16(p) -#define READLONG(p) READINT32(p) -#define READULONG(p) READUINT32(p) -#endif +#define SKIPSTRINGN(p, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n && READCHAR(p) != '\0') \ + tmp_i++; \ +}) + +#define READSTRINGN(p, s, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + +#define READSTRING(p, s) ({ \ + size_t tmp_i = 0; \ + \ + while ((s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + +#define READMEM(p, s, n) ({ \ + memcpy(s, p, n); \ + p += n; \ +}) From 3083290af868a18bdf3f2bd7a251f8567d266ef0 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 18:57:18 +0100 Subject: [PATCH 19/30] Add READSTRINGL and WRITESTRINGL macros --- src/byteptr.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/byteptr.h b/src/byteptr.h index f66d9fcaf..3a1366577 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -160,6 +160,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) WRITECHAR(p, '\0'); \ }) +#define WRITESTRINGL(p, s, n) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; tmp_i < n - 1 && s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + WRITECHAR(p, '\0'); \ +}) + #define WRITESTRING(p, s) ({ \ size_t tmp_i; \ \ @@ -192,6 +201,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) s[tmp_i] = '\0'; \ }) +#define READSTRINGL(p, s, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n - 1 && (s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + #define READSTRING(p, s) ({ \ size_t tmp_i = 0; \ \ From 7ea81eacc5986e0fec4b68e945db3443897e8561 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 19:31:41 +0100 Subject: [PATCH 20/30] Fix say command and its variants using hardcoded buffer size --- src/hu_stuff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 5f838b894..4c07e07d9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -461,7 +461,7 @@ void HU_AddChatText(const char *text, boolean playsound) static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) { - char buf[254]; + char buf[2 + HU_MAXMSGLEN + 1]; size_t numwords, ix; char *msg = &buf[2]; const size_t msgspace = sizeof buf - 2; @@ -537,7 +537,7 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) } buf[0] = target; newmsg = msg+5+spc; - strlcpy(msg, newmsg, 252); + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); From 05f1a9edc19ebcc0e383aca72bb52a9f6b83b349 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 19:57:15 +0100 Subject: [PATCH 21/30] Revert "Fix long chat messages causing net command failures" This reverts commit 13778247990d60c2ad8aa5729bc0397ab764eaaa. --- src/hu_stuff.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 4c07e07d9..edbb2d8ec 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -634,8 +634,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) SINT8 target; UINT8 flags; const char *dispname; - char msgbuf[HU_MAXMSGLEN + 1]; - char *msg = msgbuf; + char *msg; boolean action = false; char *ptr; INT32 spam_eatmsg = 0; @@ -644,7 +643,8 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); - READSTRINGN(*p, msgbuf, HU_MAXMSGLEN); + msg = (char *)*p; + SKIPSTRINGN(*p, HU_MAXMSGLEN); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { @@ -913,11 +913,7 @@ static void HU_sendChatMessage(void) if (c >= ' ' && !(c & 0x80)) buf[ci] = c; }; - if (ci-2 < HU_MAXMSGLEN) - { - buf[ci] = '\0'; - ci++; - } + buf[ci] = '\0'; memset(w_chat, '\0', sizeof(w_chat)); c_input = 0; @@ -985,7 +981,7 @@ static void HU_sendChatMessage(void) { buf[0] = teamtalk ? -1 : target; // target buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, ci); + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } From aee7803621d5b4c77c69a626dac1077f93b19264 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:03:29 +0100 Subject: [PATCH 22/30] Add SKIPSTRINGL macro --- src/byteptr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/byteptr.h b/src/byteptr.h index 3a1366577..ee16bc13f 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -192,6 +192,8 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) tmp_i++; \ }) +#define SKIPSTRINGL(p, n) SKIPSTRINGN(p, n) + #define READSTRINGN(p, s, n) ({ \ size_t tmp_i = 0; \ \ From de9d6ecbe682d14153a7af0bba02f62de4a42ccc Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:05:58 +0100 Subject: [PATCH 23/30] Fix long chat messages causing net command failures --- src/hu_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index edbb2d8ec..a6341ff29 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -644,7 +644,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) target = READSINT8(*p); flags = READUINT8(*p); msg = (char *)*p; - SKIPSTRINGN(*p, HU_MAXMSGLEN); + SKIPSTRINGL(*p, HU_MAXMSGLEN + 1); if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) { From a6808de96c18d744550bf9ce0b48ef4f3dc12d00 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Mon, 10 Jan 2022 20:12:27 +0100 Subject: [PATCH 24/30] Fix message sending code using hardcoded buffer size --- src/hu_stuff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a6341ff29..32ca59e6a 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -897,7 +897,7 @@ static boolean HU_chatboxContainsOnlySpaces(void) static void HU_sendChatMessage(void) { - char buf[2+256]; + char buf[2 + HU_MAXMSGLEN + 1]; char *msg = &buf[2]; size_t ci; INT32 target = 0; @@ -975,7 +975,7 @@ static void HU_sendChatMessage(void) // we need to get rid of the /pm newmsg = msg+5+spc; - strlcpy(msg, newmsg, 255); + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } if (ci > 2) // don't send target+flags+empty message. { From b7dbb7782e5e1ca96ea3e79521f9ce0d7f5ab7f7 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Wed, 12 Jan 2022 23:06:26 +0100 Subject: [PATCH 25/30] Only load map lumps that are WADs or have no extension --- src/p_setup.c | 2 +- src/w_wad.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4f21922a0..f6abc70e6 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4373,7 +4373,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) // internal game map maplumpname = G_BuildMapName(gamemap); - lastloadedmaplumpnum = W_CheckNumForName(maplumpname); + lastloadedmaplumpnum = W_CheckNumForMap(maplumpname); if (lastloadedmaplumpnum == LUMPERROR) I_Error("Map %s not found.\n", maplumpname); diff --git a/src/w_wad.c b/src/w_wad.c index e49e0ce82..b594912f1 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1463,8 +1463,14 @@ lumpnum_t W_CheckNumForMap(const char *name) continue; // Now look for the specified map. for (; lumpNum < end; lumpNum++) - if (!strnicmp(name, (wadfiles[i]->lumpinfo + lumpNum)->name, 8)) - return (i<<16) + lumpNum; + { + if (!strnicmp(name, wadfiles[i]->lumpinfo[lumpNum].name, 8)) + { + const char *extension = strrchr(wadfiles[i]->lumpinfo[lumpNum].fullname, '.'); + if (!(extension && stricmp(extension, ".wad"))) + return (i<<16) + lumpNum; + } + } } } return LUMPERROR; From f72f45d93ab530af40fb05b10be4a52a5c3db256 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Fri, 14 Jan 2022 19:53:03 +0200 Subject: [PATCH 26/30] Fix software splats breaking and crashing in skyboxes --- src/r_things.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index accd1e2b3..423276a59 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3001,13 +3001,25 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, drawseg_t* dsstart, p if (portal) { - for (x = x1; x <= x2; x++) + INT32 start_index = max(portal->start, x1); + INT32 end_index = min(portal->start + portal->end - portal->start, x2); + for (x = x1; x < start_index; x++) + { + spr->clipbot[x] = -1; + spr->cliptop[x] = -1; + } + for (x = start_index; x <= end_index; x++) { if (spr->clipbot[x] > portal->floorclip[x - portal->start]) spr->clipbot[x] = portal->floorclip[x - portal->start]; if (spr->cliptop[x] < portal->ceilingclip[x - portal->start]) spr->cliptop[x] = portal->ceilingclip[x - portal->start]; } + for (x = end_index + 1; x <= x2; x++) + { + spr->clipbot[x] = -1; + spr->cliptop[x] = -1; + } } } From d0966f123fc825befe3a90286c70f92b85d0f9c8 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Fri, 14 Jan 2022 20:11:49 +0200 Subject: [PATCH 27/30] Fix software splats not being clipped by ceiling walls --- src/r_splats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_splats.c b/src/r_splats.c index c554e9b1f..21048c46d 100644 --- a/src/r_splats.c +++ b/src/r_splats.c @@ -482,7 +482,7 @@ static void R_RasterizeFloorSplat(floorsplat_t *pSplat, vector2_t *verts, visspr continue; for (i = x1; i <= x2; i++) - cliptab[i] = (y >= mfloorclip[i]); + cliptab[i] = (y >= mfloorclip[i] || y <= mceilingclip[i]); // clip left while (cliptab[x1]) From 49d03913d72769e3343555c5784ea60a755faf96 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Fri, 14 Jan 2022 20:45:28 +0200 Subject: [PATCH 28/30] Add missing optimization to npo2 sloped floor sprites --- src/r_draw8_npo2.c | 72 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/r_draw8_npo2.c b/src/r_draw8_npo2.c index 2433cb402..90201c771 100644 --- a/src/r_draw8_npo2.c +++ b/src/r_draw8_npo2.c @@ -992,6 +992,9 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) double endz, endu, endv; UINT32 stepu, stepv; + struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); + struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); + iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); @@ -1033,12 +1036,13 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) @@ -1065,12 +1069,13 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) @@ -1101,12 +1106,13 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) @@ -1142,6 +1148,9 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) double endz, endu, endv; UINT32 stepu, stepv; + struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); + struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); + iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); @@ -1183,12 +1192,13 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) @@ -1215,12 +1225,13 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) @@ -1251,12 +1262,13 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) // Carefully align all of my Friends. if (x < 0) - x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); + x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; + else + x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; if (y < 0) - y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); - - x %= ds_flatwidth; - y %= ds_flatheight; + y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; + else + y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; val = source[((y * ds_flatwidth) + x)]; if (val & 0xFF00) From bf2809b213fadfffdb5d199f660bcb4a0b3d37d3 Mon Sep 17 00:00:00 2001 From: spherallic Date: Sat, 15 Jan 2022 17:12:33 +0100 Subject: [PATCH 29/30] Fix crosshairs not displaying and refactor their code. --- src/hu_stuff.c | 77 +++++++++----------------------------------------- 1 file changed, 14 insertions(+), 63 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index cf7118fbe..281280c9b 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1863,64 +1863,25 @@ static void HU_DrawChat_Old(void) } #endif -// draw the Crosshair, at the exact center of the view. -// +// Draw crosshairs at the exact center of the view. +// In splitscreen, crosshairs are stretched vertically to compensate for V_PERPLAYER squishing them. // Crosshairs are pre-cached at HU_Init -static inline void HU_DrawCrosshair(void) +static inline void HU_DrawCrosshairs(void) { - INT32 i, y, dupz; + INT32 cross1 = cv_crosshair.value & 3; + INT32 cross2 = cv_crosshair2.value & 3; - i = cv_crosshair.value & 3; - if (!i) + if (automapactive || demoplayback) return; - if ((netgame || multiplayer) && players[displayplayer].spectator) - return; + stplyr = ((stplyr == &players[displayplayer]) ? &players[secondarydisplayplayer] : &players[displayplayer]); + if (!players[displayplayer].spectator && (!camera.chase || ticcmd_ztargetfocus[0]) && cross1) + V_DrawStretchyFixedPatch((BASEVIDWIDTH/2)<>1); - - dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - - V_DrawFixedPatch(vid.width<<(FRACBITS-1), y<>1); - - if (!splitscreen) - return; - - #ifdef HWRENDER - if (rendermode != render_soft) - y += (INT32)gl_viewheight; - else - #endif - y += viewheight; - - dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - - V_DrawFixedPatch(vid.width<<(FRACBITS-1), y< Date: Sat, 5 Feb 2022 18:19:00 -0600 Subject: [PATCH 30/30] Make dedicated servers not pop up that annoying SDL error window So they don't mess with shell scripts that expect SRB2 to exit when it crashes (like most other programs) --- src/sdl/i_system.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index ccec37093..ab63be946 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -358,9 +358,10 @@ static void I_ReportSignal(int num, int coredumped) I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Process killed by signal", - sigmsg, NULL); + if (!M_CheckParm("-dedicated")) + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "Process killed by signal", + sigmsg, NULL); } #ifndef NEWSIGNALHANDLER @@ -2202,9 +2203,10 @@ static void newsignalhandler_Warn(const char *pr) I_OutputMsg("%s\n", text); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Startup error", - text, NULL); + if (!M_CheckParm("-dedicated")) + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "Startup error", + text, NULL); I_ShutdownConsole(); exit(-1); @@ -2405,9 +2407,10 @@ void I_Error(const char *error, ...) // Implement message box with SDL_ShowSimpleMessageBox, // which should fail gracefully if it can't put a message box up // on the target system - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2 "VERSIONSTRING" Recursive Error", - buffer, NULL); + if (!M_CheckParm("-dedicated")) + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "SRB2 "VERSIONSTRING" Recursive Error", + buffer, NULL); W_Shutdown(); exit(-1); // recursive errors detected @@ -2449,9 +2452,10 @@ void I_Error(const char *error, ...) // Implement message box with SDL_ShowSimpleMessageBox, // which should fail gracefully if it can't put a message box up // on the target system - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2 "VERSIONSTRING" Error", - buffer, NULL); + if (!M_CheckParm("-dedicated")) + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + "SRB2 "VERSIONSTRING" Error", + buffer, NULL); // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be // initialized at the time, so calling it after SDL_Quit() is // perfectly okay! In addition, we do this on purpose so the