From 82601e881b8296a0cb4ed6ae44c99976a5c30fda Mon Sep 17 00:00:00 2001 From: MPC Date: Mon, 17 Dec 2018 17:57:53 -0300 Subject: [PATCH 1/7] fix my fucking code --- src/v_video.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 796e6465..2a5eca9d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -881,6 +881,7 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) { UINT8 *dest; INT32 u, v; + UINT8 *fadetable; UINT32 alphalevel = 0; if (rendermode == render_none) @@ -965,23 +966,20 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) c &= 255; - if (!alphalevel) { - for (v = 0; v < h; v++, dest += vid.width) { - for (u = 0; u < w; u++) { - dest[u] = consolebgmap[dest[u]]; - } - } - } else { // mpc 12-04-2018 - const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<y) ? y : x - w = clip(w,vid.width); - h = clip(h,vid.height); - for (v = 0; v < h; v++, dest += vid.width) { - for (u = 0; u < w; u++) { - dest[u] = fadetable[consolebgmap[dest[u]]]; - } - } - } + // Jimita (12-04-2018) + w = min(w, vid.width); + h = min(h, vid.height); + if (alphalevel) // Use fadetable + fadetable = ((UINT8 *)transtables + ((alphalevel-1)< Date: Mon, 17 Dec 2018 18:09:29 -0300 Subject: [PATCH 2/7] fix the fucking warning --- src/v_video.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 2a5eca9d..cfe7d036 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -969,9 +969,7 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) // Jimita (12-04-2018) w = min(w, vid.width); h = min(h, vid.height); - if (alphalevel) // Use fadetable - fadetable = ((UINT8 *)transtables + ((alphalevel-1)< Date: Mon, 17 Dec 2018 18:55:21 -0500 Subject: [PATCH 3/7] Fix compile errors --- src/hu_stuff.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 27144e50..d99fe07a 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 INT32 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,7 +328,7 @@ static UINT32 chat_nummsg_min = 0; static UINT32 chat_scroll = 0; static tic_t chat_scrolltime = 0; -static INT32 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. @@ -346,7 +346,7 @@ static INT16 addy = 0; // use this to make the messages scroll smoothly when one static void HU_removeChatText_Mini(void) { // MPC: Don't create new arrays, just iterate through an existing one - int i; + size_t i; for(i=0;i=c_input);m--) { if (s[m]) @@ -1199,7 +1199,7 @@ boolean HU_Responder(event_t *ev) // This is a muuuch better method than V_WORDWRAP. // again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day. // this one is simplified for the chat drawer. -char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) +static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) { int c; size_t chw, i, lastusablespace = 0; @@ -2611,7 +2611,7 @@ void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scoreline // // HU_Draw32TabRankings // -void HU_Draw32TabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer) +static void HU_Draw32TabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer) { INT32 i; const UINT8 *colormap; From 7a92c9d3d04b4dee842dda8b9b149ddda75b7812 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 19:02:22 -0500 Subject: [PATCH 4/7] Mixed D&C fixes; replace a couple int's with INT32 --- src/hu_stuff.c | 27 +++++++++++++++++---------- src/lua_baselib.c | 12 ++++++++---- src/m_menu.c | 15 ++++++++------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index d99fe07a..22e3aa3d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -727,9 +727,10 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) } else { + const UINT8 color = players[playernum].skincolor; cstart = "\x83"; - const UINT8 color = players[playernum].skincolor; + if (color <= SKINCOLOR_SILVER) cstart = "\x80"; // White else if (color <= SKINCOLOR_BLACK) @@ -856,9 +857,11 @@ static inline boolean HU_keyInChatString(char *s, char ch) } else if (ch == KEY_BACKSPACE) { + size_t i = c_input; + if (c_input <= 0) return false; - size_t i = c_input; + if (!s[i-1]) return false; @@ -910,14 +913,17 @@ static void HU_queueChatChar(char c) if (c == KEY_ENTER) { char buf[2+256]; - size_t ci = 2; char *msg = &buf[2]; + size_t i = 0; + size_t ci = 2; + INT32 target = 0; + do { c = w_chat[-2+ci++]; if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. buf[ci-1]=c; } while (c); - size_t i = 0; + for (;(i 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { + INT32 spc = 1; // used if nodenum[1] is a space. + char *nodenum = (char*) malloc(3); + const char *newmsg = msg+5+spc; + // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: @@ -944,8 +952,6 @@ static void HU_queueChatChar(char c) return; } - int spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); strncpy(nodenum, msg+3, 5); // check for undesirable characters in our "number" if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) @@ -981,8 +987,8 @@ static void HU_queueChatChar(char c) HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same return; } + // we need to get rid of the /pm - const char *newmsg = msg+5+spc; memcpy(msg, newmsg, 255); } if (ci > 3) // don't send target+flags+empty message. @@ -2158,6 +2164,8 @@ void HU_drawPing(INT32 x, INT32 y, INT32 ping, boolean notext) UINT8 barcolor = 128; // color we use for the bars (green, yellow or red) SINT8 i = 0; SINT8 yoffset = 6; + INT32 dx = x+1 - (V_SmallStringWidth(va("%dms", ping), V_ALLOWLOWERCASE)/2); + if (ping < 128) { numbars = 3; @@ -2169,7 +2177,6 @@ void HU_drawPing(INT32 x, INT32 y, INT32 ping, boolean notext) barcolor = 103; } - INT32 dx = x+1 - (V_SmallStringWidth(va("%dms", ping), V_ALLOWLOWERCASE)/2); if (!notext || vid.width >= 640) // how sad, we're using a shit resolution. V_DrawSmallString(dx, y+4, V_ALLOWLOWERCASE, va("%dms", ping)); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index d8b8d24e..6b1456e9 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -96,9 +96,11 @@ static int lib_chatprint(lua_State *L) { const char *str = luaL_checkstring(L, 1); // retrieve string boolean sound = luaL_checkboolean(L, 2); // retrieve sound boolean + int len = strlen(str); + if (str == NULL) // error if we don't have a string! return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprint")); - int len = strlen(str); + if (len > 255) // string is too long!!! return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer."); @@ -110,7 +112,11 @@ static int lib_chatprint(lua_State *L) static int lib_chatprintf(lua_State *L) { int n = lua_gettop(L); /* number of arguments */ + const char *str = luaL_checkstring(L, 2); // retrieve string + boolean sound = luaL_checkboolean(L, 3); // sound? + int len = strlen(str); player_t *plr; + if (n < 2) return luaL_error(L, "chatprintf requires at least two arguments: player and text."); @@ -120,11 +126,9 @@ static int lib_chatprintf(lua_State *L) if (plr != &players[consoleplayer]) return 0; - const char *str = luaL_checkstring(L, 2); // retrieve string - boolean sound = luaL_checkboolean(L, 3); // sound? if (str == NULL) // error if we don't have a string! return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("chatprintf")); - int len = strlen(str); + if (len > 255) // string is too long!!! return luaL_error(L, "String exceeds the 255 characters limit of the chat buffer."); diff --git a/src/m_menu.c b/src/m_menu.c index 7647d72f..380ba266 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1315,13 +1315,14 @@ static menuitem_t OP_GameOptionsMenu[] = static menuitem_t OP_ChatOptionsMenu[] = { - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Width", &cv_chatwidth, 10}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Height", &cv_chatheight, 20}, - {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 30}, - {IT_STRING | IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 40}, - {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 50}, - {IT_STRING | IT_CVAR, NULL, "Chat background tint", &cv_chatbacktint, 60}, - {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 70}, + {IT_STRING | IT_CVAR, NULL, "Chat Mode", &cv_consolechat, 10}, + + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Width", &cv_chatwidth, 30}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Chat Box Height", &cv_chatheight, 40}, + {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 50}, + {IT_STRING | IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 60}, + {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70}, + {IT_STRING | IT_CVAR, NULL, "Chat background tint", &cv_chatbacktint, 80}, }; static menuitem_t OP_ServerOptionsMenu[] = From bf21b7c483a207412577e0786c98698cfcefd4b0 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 19:03:09 -0500 Subject: [PATCH 5/7] Mixed D&C fixes for HU_DrawTeamTabRankings --- src/hu_stuff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 22e3aa3d..b924cf78 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2407,6 +2407,8 @@ void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer) INT32 i,x,y; INT32 redplayers = 0, blueplayers = 0; boolean smol = false; + const UINT8 *colormap; + char name[MAXPLAYERNAME+1]; // before we draw, we must count how many players are in each team. It makes an additional loop, but we need to know if we have to draw a big or a small ranking. for (i = 0; i < MAXPLAYERS; i++) @@ -2446,9 +2448,6 @@ void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer) V_DrawFill(1, 26, 318, 1, 0); //And a horizontal line to make a T. V_DrawFill(1, 180, 318, 1, 0); //And a horizontal line near the bottom. - const UINT8 *colormap; - char name[MAXPLAYERNAME+1]; - i=0, redplayers=0, blueplayers=0; for (i = 0; i < MAXPLAYERS; i++) From 876ddd48f11a4e92c8d32b551819cf815ebecdb4 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 19:09:05 -0500 Subject: [PATCH 6/7] Change int to INT32 --- src/hu_stuff.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index b924cf78..6d5fbfca 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -456,8 +456,9 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: const char *newmsg; - int spc = 1; // used if nodenum[1] is a space. char *nodenum = (char*) malloc(3); + INT32 spc = 1; // used if nodenum[1] is a space. + strncpy(nodenum, msg+3, 5); // check for undesirable characters in our "number" if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) @@ -595,7 +596,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) char *msg; boolean action = false; char *ptr; - int spam_eatmsg = 0; + INT32 spam_eatmsg = 0; CONS_Debug(DBG_NETPLAY,"Received SAY cmd from Player %d (%s)\n", playernum+1, player_names[playernum]); @@ -1207,7 +1208,7 @@ boolean HU_Responder(event_t *ev) // this one is simplified for the chat drawer. static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) { - int c; + INT32 c; size_t chw, i, lastusablespace = 0; size_t slen; char *newstring = Z_StrDup(string); @@ -1634,8 +1635,8 @@ static void HU_DrawChat(void) boolean skippedline = false; if (c_input == (i+1)) { - int cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. - int cursory = (cursorx != chatx+1) ? (y) : (y+charheight); + INT32 cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. + INT32 cursory = (cursorx != chatx+1) ? (y) : (y+charheight); if (hu_tick < 4) V_DrawChatCharacter(cursorx, cursory+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); @@ -1644,7 +1645,6 @@ static void HU_DrawChat(void) typelines += 1; skippedline = true; } - } //Hurdler: isn't it better like that? @@ -1789,8 +1789,8 @@ static void HU_DrawChat_Old(void) if (c_input == (i+1) && hu_tick < 4) { - int cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. - int cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); + INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. + INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); } From 1fcf607b41ef3578efc4fb32e30f0cde7fb7dd55 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Mon, 17 Dec 2018 21:31:00 -0500 Subject: [PATCH 7/7] Fix strncpy nodenum length overflow --- src/hu_stuff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6d5fbfca..5941c68d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -459,7 +459,7 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) char *nodenum = (char*) malloc(3); INT32 spc = 1; // used if nodenum[1] is a space. - strncpy(nodenum, msg+3, 5); + strncpy(nodenum, msg+3, 3); // check for undesirable characters in our "number" if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { @@ -953,7 +953,7 @@ static void HU_queueChatChar(char c) return; } - strncpy(nodenum, msg+3, 5); + strncpy(nodenum, msg+3, 3); // check for undesirable characters in our "number" if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { @@ -1692,7 +1692,7 @@ static void HU_DrawChat(void) nodenum = (char*) malloc(3); - strncpy(nodenum, w_chat+3, 4); + strncpy(nodenum, w_chat+3, 3); n = atoi((const char*) nodenum); // turn that into a number // special cases: