From efb29e6be5d58e44a6c99c72833b1cfe33747906 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 12:42:22 +0100 Subject: [PATCH 01/47] d_cliserv: do some cleanups - expose SAVEGAMESIZE - pass node number to SV_AddWaitingPlayers (saves iterating through all 128 net nodes everytime a player joins) lifted from RR - move all packet handling to the packet handlers - Reorder packethandling switches a little, so common/important packets get checked first - fix wrong clamp for realfirsttic that was too early - add nowtime division by NEWTICRATERATIO (no change unless ticrate changes) --- src/d_clisrv.c | 427 ++++++++++++++++++++++++------------------------- src/d_clisrv.h | 4 +- src/g_game.c | 5 +- 3 files changed, 215 insertions(+), 221 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index fa1536e72..33b69045e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1933,8 +1933,6 @@ static boolean SV_SendServerConfig(INT32 node) return waspacketsent; } -#define SAVEGAMESIZE (768*1024) - #ifdef SATURNPAK static boolean SV_ResendingSavegameToAnyone(void) { @@ -4565,71 +4563,69 @@ static void Got_RemovePlayer(const UINT8 **p, INT32 playernum) #endif } -static boolean SV_AddWaitingPlayers(void) +static boolean SV_AddWaitingPlayers(SINT8 node) { - INT32 node, n, newplayer = false; + INT32 n; UINT8 buf[2]; UINT8 newplayernum = 0; + boolean newplayer = false; // What is the reason for this? Why can't newplayernum always be 0? // Sal: Because the dedicated player is stupidly forced into players[0]..... if (dedicated) newplayernum = 1; - for (node = 0; node < MAXNETNODES; node++) + // splitscreen can allow 2+ players in one node + for (; nodewaiting[node] > 0; nodewaiting[node]--) { - // splitscreen can allow 2+ players in one node - for (; nodewaiting[node] > 0; nodewaiting[node]--) + newplayer = true; + + // search for a free playernum + // we can't use playeringame since it is not updated here + for (; newplayernum < MAXPLAYERS; newplayernum++) { - newplayer = true; - - // search for a free playernum - // we can't use playeringame since it is not updated here - for (; newplayernum < MAXPLAYERS; newplayernum++) - { - for (n = 0; n < MAXNETNODES; n++) - if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum - || nodetoplayer3[n] == newplayernum || nodetoplayer4[n] == newplayernum) - break; - if (n == MAXNETNODES) + for (n = 0; n < MAXNETNODES; n++) + if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum + || nodetoplayer3[n] == newplayernum || nodetoplayer4[n] == newplayernum) break; - } - - // should never happen since we check the playernum - // before accepting the join - I_Assert(newplayernum < MAXPLAYERS); - - playernode[newplayernum] = (UINT8)node; - - buf[0] = (UINT8)node; - buf[1] = newplayernum; - if (playerpernode[node] < 1) - { - nodetoplayer[node] = newplayernum; - } - else if (playerpernode[node] < 2) - { - nodetoplayer2[node] = newplayernum; - buf[1] += MAXPLAYERS; - } - else if (playerpernode[node] < 3) - { - nodetoplayer3[node] = newplayernum; - buf[1] += MAXPLAYERS*2; - } - else - { - nodetoplayer4[node] = newplayernum; - buf[1] += MAXPLAYERS*3; - } - playerpernode[node]++; - - SendNetXCmd(XD_ADDPLAYER, &buf, 2); - - DEBFILE(va("Server added player %d node %d\n", newplayernum, node)); - // use the next free slot (we can't put playeringame[newplayernum] = true here) - newplayernum++; + if (n == MAXNETNODES) + break; } + + // should never happen since we check the playernum + // before accepting the join + I_Assert(newplayernum < MAXPLAYERS); + + playernode[newplayernum] = (UINT8)node; + + buf[0] = (UINT8)node; + buf[1] = newplayernum; + if (playerpernode[node] < 1) + { + nodetoplayer[node] = newplayernum; + } + else if (playerpernode[node] < 2) + { + nodetoplayer2[node] = newplayernum; + buf[1] += MAXPLAYERS; + } + else if (playerpernode[node] < 3) + { + nodetoplayer3[node] = newplayernum; + buf[1] += MAXPLAYERS*2; + } + else + { + nodetoplayer4[node] = newplayernum; + buf[1] += MAXPLAYERS*3; + } + playerpernode[node]++; + + SendNetXCmd(XD_ADDPLAYER, &buf, 2); + + DEBFILE(va("Server added player %d node %d\n", newplayernum, node)); + // use the next free slot (we can't put playeringame[newplayernum] = true here) + newplayernum++; } return newplayer; @@ -4666,6 +4662,8 @@ boolean Playing(void) boolean SV_SpawnServer(void) { + boolean result = false; + if (demo.playback) G_StopDemo(); // reset engine parameter @@ -4686,7 +4684,15 @@ boolean SV_SpawnServer(void) else doomcom->numslots = 1; } - return SV_AddWaitingPlayers(); + // strictly speaking, i'm not convinced the following is necessary + // but I'm not confident enough to remove it entirely in case it breaks something + { + SINT8 node = 0; + for (; node < MAXNETNODES; node++) + result |= SV_AddWaitingPlayers(node); + } + + return result; } void SV_StopServer(void) @@ -4772,8 +4778,12 @@ static size_t TotalTextCmdPerTic(tic_t tic) * \param node The packet sender * */ -static void HandleConnect(SINT8 node) +static void PT_ClientJoin(SINT8 node) { + // Ignore duplicate packets + if (client || nodeingame[node]|| levelloading) + return; + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); // Sal: Dedicated mode is INCREDIBLY hacked together. @@ -4783,8 +4793,17 @@ static void HandleConnect(SINT8 node) UINT8 connectedplayers = 0; for (UINT8 i = dedicated ? 1 : 0; i < MAXPLAYERS; i++) - if (playernode[i] != UINT8_MAX) // We use this to count players because it is affected by SV_AddWaitingPlayers when more than one client joins on the same tic, unlike playeringame and D_NumPlayers. UINT8_MAX denotes no node for that player + { + // We use this to count players because it is affected by SV_AddWaitingPlayers when + // more than one client joins on the same tic, unlike playeringame and D_NumPlayers. + // UINT8_MAX denotes no node for that player. + + if (playernode[i] != UINT8_MAX) + { connectedplayers++; + } + } + #ifdef SATURNJOIN const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && netbuffer->u.clientcfg.issaturn == ISSATURN); // Check the packet lenght to skip potential garbo data! @@ -4840,7 +4859,7 @@ static void HandleConnect(SINT8 node) else if (netbuffer->u.clientcfg.version != VERSION || netbuffer->u.clientcfg.subversion != SUBVERSION) { - SV_SendRefuse(node, va(M_GetText("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)"), VERSION, SUBVERSION)); + SV_SendRefuse(node, va("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)", VERSION, SUBVERSION)); } #ifdef SATURNJOIN else if (((!cv_allownewplayer.value && !issaturn) || (!cv_allownewsaturnplayer.value && issaturn)) && node) @@ -4848,71 +4867,61 @@ static void HandleConnect(SINT8 node) else if (!cv_allownewplayer.value && node) #endif { - SV_SendRefuse(node, M_GetText(cv_joinrefusemessage.string)); + SV_SendRefuse(node, cv_joinrefusemessage.string); } else if (connectedplayers >= maxplayers) { - SV_SendRefuse(node, va(M_GetText("Maximum players reached: %d"), maxplayers)); + SV_SendRefuse(node, va("Maximum players reached: %d", maxplayers)); } else if (netgame && netbuffer->u.clientcfg.localplayers > 4) // Hacked client? { - SV_SendRefuse(node, M_GetText("Too many players from\nthis node.")); + SV_SendRefuse(node, "Too many players from\nthis node."); } else if (netgame && connectedplayers + netbuffer->u.clientcfg.localplayers > maxplayers) { - SV_SendRefuse(node, va(M_GetText("Number of local players\nwould exceed maximum: %d"), maxplayers)); + SV_SendRefuse(node, va("Number of local players\nwould exceed maximum: %d", maxplayers)); } else if (netgame && !netbuffer->u.clientcfg.localplayers) // Stealth join? { - SV_SendRefuse(node, M_GetText("No players from\nthis node.")); + SV_SendRefuse(node, "No players from\nthis node."); } else { - boolean newnode = false; - // client authorised to join nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); - if (!nodeingame[node]) + gamestate_t backupstate = gamestate; + + SV_AddNode(node); + + /// \note Wait what??? + /// What if the gamestate takes more than one second to get downloaded? + /// Or if a lagspike happens? + // you get a free second before desynch checks. use it wisely. + SV_InitResynchVars(node); + + if (!SV_SendServerConfig(node)) { - gamestate_t backupstate = gamestate; - - newnode = true; - - SV_AddNode(node); - - /// \note Wait what??? - /// What if the gamestate takes more than one second to get downloaded? - /// Or if a lagspike happens? - // you get a free second before desynch checks. use it wisely. - SV_InitResynchVars(node); - - if (!SV_SendServerConfig(node)) - { - G_SetGamestate(backupstate); - /// \note Shouldn't SV_SendRefuse be called before ResetNode? - SV_SendRefuse(node, M_GetText("Server couldn't send info, please try again")); - ResetNode(node); // Yeah, lets try it! - /// \todo fix this !!! - return; // restart the while - } - - SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea - //if (gamestate != GS_LEVEL) // GS_INTERMISSION, etc? - // SV_SendPlayerConfigs(node); // send bare minimum player info G_SetGamestate(backupstate); - DEBFILE("new node joined\n"); + /// \note Shouldn't SV_SendRefuse be called before ResetNode? + SV_SendRefuse(node, "Server couldn't send info, please try again"); + ResetNode(node); // Yeah, lets try it! + /// \todo fix this !!! + return; // restart the while } + SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea + //if (gamestate != GS_LEVEL) // GS_INTERMISSION, etc? + // SV_SendPlayerConfigs(node); // send bare minimum player info + G_SetGamestate(backupstate); + DEBFILE("new node joined\n"); + if (nodewaiting[node]) { - if (node && newnode) - { - SV_SendSaveGame(node, false); // send a complete game state - DEBFILE("send savegame\n"); - } + SV_SendSaveGame(node, false); // send a complete game state + DEBFILE("send savegame\n"); - SV_AddWaitingPlayers(); + SV_AddWaitingPlayers(node); } } } @@ -4922,8 +4931,11 @@ static void HandleConnect(SINT8 node) * \param node The packet sender (should be the server) * */ -static void HandleShutdown(SINT8 node) +static void PT_ServerShutdown(SINT8 node) { + if (node != servernode || server || cl_mode == CL_SEARCHING) + return; + (void)node; D_QuitNetGame(); CL_Reset(); @@ -4951,7 +4963,7 @@ static void HandleTimeout(SINT8 node) * \note What happens if the packet comes from a client or something like that? * */ -static void HandleServerInfo(SINT8 node) +static void PT_ServerInfo(SINT8 node) { char servername[MAXSERVERNAME]; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -4974,7 +4986,7 @@ static void HandleServerInfo(SINT8 node) memcpy(connectedservername, netbuffer->u.serverinfo.servername, MAXSERVERNAME); } -static void HandlePlayerInfo(void) +static void PT_PlayerInfo(void) { INT32 i; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -5372,6 +5384,9 @@ static void HandlePacketFromAwayNode(SINT8 node) case PT_ASKINFOVIAMS: Net_CloseConnection(node); break; + case PT_SERVERINFO: + PT_ServerInfo(node); + break; case PT_TELLFILESNEEDED: PT_TellFilesNeeded(node); break; @@ -5402,7 +5417,7 @@ static void HandlePacketFromAwayNode(SINT8 node) case PT_CLIENTCMD: break; // This is not an "unknown packet" case PT_PLAYERINFO: - HandlePlayerInfo(); + PT_PlayerInfo(); break; case PT_MAPICON: PT_MapIcon(); @@ -5410,6 +5425,13 @@ static void HandlePacketFromAwayNode(SINT8 node) case PT_NEEDMAPICON: PT_NeedMapIcon(node); break; + case PT_CLIENTJOIN: + PT_ClientJoin(node); + break; + case PT_SERVERSHUTDOWN: + PT_ServerShutdown(node); + break; + case PT_SERVERTICS: // Do not remove my own server (we have just get a out of order packet) if (node == servernode) @@ -5659,6 +5681,10 @@ static void PT_BasicKeepAlive(INT32 netconsole, SINT8 node) static void PT_TextCmd(INT32 netconsole, SINT8 node) { + size_t j; + tic_t tic; + UINT8 *textcmd; + if (client) return; @@ -5680,79 +5706,84 @@ static void PT_TextCmd(INT32 netconsole, SINT8 node) } if (netconsole < 0 || netconsole >= MAXPLAYERS) - Net_UnAcknowledgePacket(node); - else { - size_t j; - tic_t tic = maketic; - UINT8 *textcmd; - - // ignore if the textcmd has a reported size of zero - // this shouldn't be sent at all - if (!netbuffer->u.textcmd[0]) - { - DEBFILE(va("GetPacket: Textcmd with size 0 detected! (node %u, player %d)\n", - node, netconsole)); - Net_UnAcknowledgePacket(node); - return; - } - - // ignore if the textcmd size var is actually larger than it should be - // BASEPACKETSIZE + 1 (for size) + textcmd[0] should == datalength - if (netbuffer->u.textcmd[0] > (size_t)doomcom->datalength-1) - { - DEBFILE(va("GetPacket: Bad Textcmd packet size! (expected %d, actual %s, node %u, player %d)\n", - netbuffer->u.textcmd[0], sizeu1((size_t)doomcom->datalength-1), - node, netconsole)); - Net_UnAcknowledgePacket(node); - return; - } - - // check if tic that we are making isn't too large else we cannot send it :( - // doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time - j = (software_MAXPACKETLENGTH - (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE + (doomcom->numslots+1)*sizeof(ticcmd_t))); - - // search a tic that have enougth space in the ticcmd - while ((textcmd = D_GetExistingTextcmd(tic, netconsole)), - (TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD) - && tic < firstticstosend + BACKUPTICS) - { - tic++; - } - - if (tic >= firstticstosend + BACKUPTICS) - { - DEBFILE(va("GetPacket: Textcmd too long (max %s, used %s, mak %d, " - "tosend %u, node %u, player %d)\n", sizeu1(j), sizeu2(TotalTextCmdPerTic(maketic)), - maketic, firstticstosend, node, netconsole)); - Net_UnAcknowledgePacket(node); - return; - } - - // Make sure we have a buffer - if (!textcmd) - textcmd = D_GetTextcmd(tic, netconsole); - - DEBFILE(va("textcmd put in tic %u at position %d (player %d) ftts %u mk %u\n", - tic, textcmd[0]+1, netconsole, firstticstosend, maketic)); - - memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); - textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; + Net_UnAcknowledgePacket(node); + return; } + + // ignore if the textcmd has a reported size of zero + // this shouldn't be sent at all + if (!netbuffer->u.textcmd[0]) + { + DEBFILE(va("GetPacket: Textcmd with size 0 detected! (node %u, player %d)\n", + node, netconsole)); + Net_UnAcknowledgePacket(node); + return; + } + + // ignore if the textcmd size var is actually larger than it should be + // BASEPACKETSIZE + 1 (for size) + textcmd[0] should == datalength + if (netbuffer->u.textcmd[0] > (size_t)doomcom->datalength-1) + { + DEBFILE(va("GetPacket: Bad Textcmd packet size! (expected %d, actual %s, node %u, player %d)\n", + netbuffer->u.textcmd[0], sizeu1((size_t)doomcom->datalength-1), + node, netconsole)); + Net_UnAcknowledgePacket(node); + return; + } + + // check if tic that we are making isn't too large else we cannot send it :( + // doomcom->numslots+1 "+1" since doomcom->numslots can change within this time and sent time + j = (software_MAXPACKETLENGTH - (netbuffer->u.textcmd[0]+2+BASESERVERTICSSIZE + (doomcom->numslots+1)*sizeof(ticcmd_t))); + + tic = maketic; + + // search a tic that have enougth space in the ticcmd + while ((textcmd = D_GetExistingTextcmd(tic, netconsole)), + (TotalTextCmdPerTic(tic) > j || netbuffer->u.textcmd[0] + (textcmd ? textcmd[0] : 0) > MAXTEXTCMD) + && tic < firstticstosend + BACKUPTICS) + { + tic++; + } + + if (tic >= firstticstosend + BACKUPTICS) + { + DEBFILE(va("GetPacket: Textcmd too long (max %s, used %s, mak %d, " + "tosend %u, node %u, player %d)\n", sizeu1(j), sizeu2(TotalTextCmdPerTic(maketic)), + maketic, firstticstosend, node, netconsole)); + Net_UnAcknowledgePacket(node); + return; + } + + // Make sure we have a buffer + if (!textcmd) + textcmd = D_GetTextcmd(tic, netconsole); + + DEBFILE(va("textcmd put in tic %u at position %d (player %d) ftts %u mk %u\n", + tic, textcmd[0]+1, netconsole, firstticstosend, maketic)); + + memcpy(&textcmd[textcmd[0]+1], netbuffer->u.textcmd+1, netbuffer->u.textcmd[0]); + textcmd[0] += (UINT8)netbuffer->u.textcmd[0]; } static void PT_ClientQuit(INT32 netconsole, SINT8 node) { + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); + if (client) + { + if (node == servernode && cl_mode != CL_SEARCHING && netbuffer->packettype == PT_NODETIMEOUT) + HandleTimeout(node); return; + } // nodeingame will be put false in the execution of kick command // this allow to send some packets to the quitting client to have their ack back nodewaiting[node] = 0; if (netconsole != -1 && playeringame[netconsole]) { - doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); - SendKick(netconsole, (netbuffer->packettype == PT_NODETIMEOUT) ? KICK_MSG_TIMEOUT : KICK_MSG_PLAYER_QUIT); + const int quitreason = ((netbuffer->packettype == PT_NODETIMEOUT) ? KICK_MSG_TIMEOUT : KICK_MSG_PLAYER_QUIT); + SendKick(netconsole, quitreason); } Net_CloseConnection(node); nodeingame[node] = false; @@ -5938,9 +5969,6 @@ static void HandlePacketFromPlayer(SINT8 node) switch (netbuffer->packettype) { // -------------------------------------------- SERVER RECEIVE ---------- - case PT_RESYNCHGET: - SV_AcknowledgeResynchAck(node, netbuffer->u.resynchgot); - break; case PT_CLIENTCMD: case PT_CLIENT2CMD: case PT_CLIENT3CMD: @@ -5966,16 +5994,13 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENTQUIT: PT_ClientQuit(netconsole, node); break; -// -------------------------------------------- CLIENT RECEIVE ---------- - case PT_RESYNCHEND: - PT_Resynched(node); + case PT_RESYNCHGET: + SV_AcknowledgeResynchAck(node, netbuffer->u.resynchgot); break; +// -------------------------------------------- CLIENT RECEIVE ---------- case PT_SERVERTICS: PT_ServerTics(node); break; - case PT_RESYNCHING: - PT_Resynching(node); - break; case PT_PING: PT_Ping(node); break; @@ -5999,6 +6024,12 @@ static void HandlePacketFromPlayer(SINT8 node) is_client_saturn[node] = true; break; #endif + case PT_RESYNCHING: + PT_Resynching(node); + break; + case PT_RESYNCHEND: + PT_Resynched(node); + break; default: DEBFILE(va("UNKNOWN PACKET TYPE RECEIVED %d from host %d\n", netbuffer->packettype, node)); } @@ -6019,36 +6050,6 @@ static void GetPackets(void) { node = (SINT8)doomcom->remotenode; - if (server && netbuffer->packettype == PT_CLIENTJOIN) - { - if (!levelloading) // Otherwise just ignore - { - HandleConnect(node); - } - - continue; - } - - if (client && node == servernode && cl_mode != CL_SEARCHING) - { - if (netbuffer->packettype == PT_SERVERSHUTDOWN) - { - HandleShutdown(node); - continue; - } - if (netbuffer->packettype == PT_NODETIMEOUT) - { - HandleTimeout(node); - continue; - } - } - - if (netbuffer->packettype == PT_SERVERINFO) - { - HandleServerInfo(node); - continue; - } - /*if (netbuffer->packettype == PT_PLAYERINFO) continue; // We do nothing with PLAYERINFO, that's for the MS browser. Not quite true anymore :p*/ @@ -6367,21 +6368,7 @@ static void CL_SendClientCmd(void) { if (localtextcmd[i][0]) { - switch (i) - { - case 3: - netbuffer->packettype = PT_TEXTCMD4; - break; - case 2: - netbuffer->packettype = PT_TEXTCMD3; - break; - case 1: - netbuffer->packettype = PT_TEXTCMD2; - break; - default: - netbuffer->packettype = PT_TEXTCMD; - break; - } + netbuffer->packettype = PT_TEXTCMD + i; memcpy(netbuffer->u.textcmd, localtextcmd[i], localtextcmd[i][0]+1); @@ -6425,7 +6412,7 @@ static void SV_SendTics(void) continue; // assert supposedtics[n]>=nettics[n] - realfirsttic = max(supposedtics[n], firstticstosend); + realfirsttic = supposedtics[n]; lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS); if (realfirsttic >= lasttictosend) @@ -7164,6 +7151,8 @@ void NetUpdate(void) Net_AckTicker(); HandleNodeTimeouts(); + nowtime /= NEWTICRATERATIO; + if (nowtime > resptime) { resptime = nowtime; @@ -7189,9 +7178,15 @@ void NetUpdate(void) INT32 D_NumPlayers(void) { INT32 num = 0, ix; + for (ix = 0; ix < MAXPLAYERS; ix++) + { if (playeringame[ix]) + { num++; + } + } + return num; } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 430729bc2..08bccf845 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -660,9 +660,11 @@ extern UINT8 hu_redownloadinggamestate; #endif extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player +#define SAVEGAMESIZE (768*1024) + typedef struct rewind_s { - UINT8 savebuffer[(768*1024)]; + UINT8 savebuffer[SAVEGAMESIZE]; tic_t leveltime; size_t demopos; diff --git a/src/g_game.c b/src/g_game.c index 55c2c6c1a..14acd7f62 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -69,9 +69,6 @@ UINT8 botcolor = 0; JoyType_t Joystick[MAXSPLITSCREENPLAYERS] = {}; -// 1024 bytes is plenty for a savegame -#define SAVEGAMESIZE (1024) - // SRB2kart char gamedatafilename[64] = "kartdata.dat"; char timeattackfolder[64] = "kart"; @@ -3837,7 +3834,7 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - save.p = save.buffer = (UINT8 *)Z_Malloc(SAVEGAMESIZE, PU_STATIC, NULL); + save.p = save.buffer = (UINT8 *)Z_Malloc(1024, PU_STATIC, NULL); // 1024 bytes is plenty for a savegame if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); -- 2.54.0 From 96aaaf52615cd010f68a49b12a33b3b04ffa6c41 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 12:45:47 +0100 Subject: [PATCH 02/47] merge SendNameAndColor & SendWeaponPref TODO: make a bunch of player specific cvars arrays for splitscreen handling - also cleanup some strlen usage --- src/d_clisrv.c | 2 +- src/d_netcmd.c | 626 ++++++++++++------------------------------------- src/d_netcmd.h | 7 +- src/r_main.cpp | 8 +- 4 files changed, 151 insertions(+), 492 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 33b69045e..ccb8d092b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4495,7 +4495,7 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum) P_ForceLocalAngle(&players[newplayernum], (angle_t)(players[newplayernum].cmd.angleturn << TICCMD_REDUCE)); - D_SendPlayerConfig(); + D_SendPlayerConfig(splitscreenplayer); addedtogame = true; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 00760e4a4..246702a4d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1197,11 +1197,11 @@ static boolean AllowedPlayerNameChar(char ch) static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum) { - INT32 ix; + size_t ix, len = strlen(name); - if (strlen(name) == 0 || strlen(name) > MAXPLAYERNAME) + if (len == 0 || len > MAXPLAYERNAME) return false; // Empty or too long. - if (name[0] == ' ' || name[strlen(name)-1] == ' ') + if (name[0] == ' ' || name[len-1] == ' ') return false; // Starts or ends with a space. if (isdigit(name[0])) return false; // Starts with a digit. @@ -1215,20 +1215,19 @@ static boolean EnsurePlayerNameIsGood(char *name, INT32 playernum) // Also, anything over 0x80 is disallowed too, since compilers love to // differ on whether they're printable characters or not. - for (ix = 0; name[ix] != '\0'; ix++) + for (ix = 0; ix < len; ix++) if (!AllowedPlayerNameChar(name[ix])) return false; // Check if a player is currently using the name, case-insensitively. for (ix = 0; ix < MAXPLAYERS; ix++) { - if (ix != playernum && playeringame[ix] + if (ix != (size_t)playernum && playeringame[ix] && fasticmp(name, player_names[ix])) { // We shouldn't kick people out just because // they joined the game with the same name // as someone else -- modify the name instead. - size_t len = strlen(name); // Recursion! // Slowly strip characters off the end of the @@ -1447,7 +1446,9 @@ UINT8 CanChangeSkin(INT32 playernum) return true; } - if (players[playernum].spectator || players[playernum].playerstate == PST_DEAD || players[playernum].playerstate == PST_REBORN) + if (players[playernum].spectator || + players[playernum].playerstate == PST_DEAD || + players[playernum].playerstate == PST_REBORN) return true; return false; @@ -1481,445 +1482,144 @@ static void ForceAllSkins(INT32 forcedskin) } } -static INT32 snacpending = 0, snac2pending = 0, snac3pending = 0, snac4pending = 0, chmappending = 0; +static INT32 chmappending; +static INT32 snacpending[MAXSPLITSCREENPLAYERS]; + +// wonky compat, idk if anything uses this.... +#define playerisbot (splitplayer == 1 && botingame) // name, color, or skin has changed // -static void SendNameAndColor(void) +static void SendNameAndColor(UINT8 splitplayer) { char buf[MAXPLAYERNAME+2]; char *p; p = buf; + // splitscreen + if (splitscreen < splitplayer && !playerisbot) + return; + + const INT32 pnum = P_GetLocalPlayerNumForNum(splitplayer); + + player_t *player = &players[pnum]; + + // TODO: make those cvars arrays + consvar_t *playercolor, *playername, *playerskin; + consvar_t *colorvars[] = {&cv_playercolor, &cv_playercolor2, &cv_playercolor3, &cv_playercolor4}; + consvar_t *namevars[] = {&cv_playername, &cv_playername2, &cv_playername3, &cv_playername4}; + consvar_t *skinvars[] = {&cv_skin, &cv_skin2, &cv_skin3, &cv_skin4}; + + playercolor = colorvars[splitplayer]; + playername = namevars[splitplayer]; + playerskin = skinvars[splitplayer]; + // normal player colors if (G_GametypeHasTeams()) { - if (players[consoleplayer].ctfteam == 1 && cv_playercolor.value != skincolor_redteam) - CV_StealthSetValue(&cv_playercolor, skincolor_redteam); - else if (players[consoleplayer].ctfteam == 2 && cv_playercolor.value != skincolor_blueteam) - CV_StealthSetValue(&cv_playercolor, skincolor_blueteam); + if (player->ctfteam == 1 && playercolor->value != skincolor_redteam) + CV_StealthSetValue(playercolor, skincolor_redteam); + else if (player->ctfteam == 2 && playercolor->value != skincolor_blueteam) + CV_StealthSetValue(playercolor, skincolor_blueteam); } // never allow the color "none" - if (!cv_playercolor.value) + if (!playercolor->value) { - if (players[consoleplayer].skincolor) - CV_StealthSetValue(&cv_playercolor, players[consoleplayer].skincolor); - else if (skins[players[consoleplayer].skin].prefcolor) - CV_StealthSetValue(&cv_playercolor, skins[players[consoleplayer].skin].prefcolor); + if (player->skincolor) + CV_StealthSetValue(playercolor, player->skincolor); + else if (skins[player->skin].prefcolor) + CV_StealthSetValue(playercolor, skins[player->skin].prefcolor); else - CV_StealthSet(&cv_playercolor, cv_playercolor.defaultvalue); + CV_StealthSet(playercolor, playercolor->defaultvalue); } - if (fastcmp(cv_playername.string, player_names[consoleplayer]) - && cv_playercolor.value == players[consoleplayer].skincolor - && fastcmp(cv_skin.string, skins[players[consoleplayer].skin].name)) - return; - // We'll handle it later if we're not playing. if (!Playing()) return; + if (fastcmp(playername->string, player_names[pnum]) + && playercolor->value == player->skincolor + && fastcmp(playerskin->string, skins[player->skin].name)) + return; + + if (playerisbot) + { + players[pnum].skincolor = botcolor; + if (players[pnum].mo) + players[pnum].mo->color = players[pnum].skincolor; + SetPlayerSkinByNum(pnum, botskin-1); + return; + } + // If you're not in a netgame, merely update the skin, color, and name. if (!netgame) { INT32 foundskin; - CleanupPlayerName(consoleplayer, cv_playername.zstring); - strcpy(player_names[consoleplayer], cv_playername.zstring); + CleanupPlayerName(pnum, playername->zstring); + strcpy(player_names[pnum], playername->zstring); - players[consoleplayer].skincolor = cv_playercolor.value; + player->skincolor = playercolor->value; - if (players[consoleplayer].mo) - players[consoleplayer].mo->color = players[consoleplayer].skincolor; + if (player->mo) + player->mo->color = player->skincolor; - if ((foundskin = R_SkinAvailable(cv_skin.string)) != -1) + if ((foundskin = R_SkinAvailable(playerskin->string)) != -1) { - cv_skin.value = foundskin; - SetPlayerSkin(consoleplayer, cv_skin.string); - CV_StealthSet(&cv_skin, skins[cv_skin.value].name); + playerskin->value = foundskin; + SetPlayerSkin(pnum, playerskin->string); + CV_StealthSet(playerskin, skins[playerskin->value].name); } else { - cv_skin.value = players[consoleplayer].skin; - CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); + playerskin->value = player->skin; + CV_StealthSet(playerskin, skins[player->skin].name); // will always be same as current - SetPlayerSkin(consoleplayer, cv_skin.string); + SetPlayerSkin(pnum, playerskin->string); } return; } - snacpending++; + snacpending[splitplayer]++; // Don't change name if muted - if (player_name_changes[consoleplayer] >= MAXNAMECHANGES) + if (player_name_changes[pnum] >= MAXNAMECHANGES) { - CV_StealthSet(&cv_playername, player_names[consoleplayer]); + CV_StealthSet(playername, player_names[pnum]); HU_AddChatText("\x85*You must wait to change your name again", false); } - else if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) - CV_StealthSet(&cv_playername, player_names[consoleplayer]); + else if (cv_mute.value && !(server || IsPlayerAdmin(pnum))) + CV_StealthSet(playername, player_names[pnum]); else // Cleanup name if changing it - CleanupPlayerName(consoleplayer, cv_playername.zstring); + CleanupPlayerName(pnum, playername->zstring); // Don't change skin if the server doesn't want you to. - if (!CanChangeSkin(consoleplayer)) - CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); + if (!CanChangeSkin(pnum)) + CV_StealthSet(playerskin, skins[player->skin].name); // check if player has the skin loaded (cv_skin may have // the name of a skin that was available in the previous game) - cv_skin.value = R_SkinAvailable(cv_skin.string); - if (cv_skin.value < 0) + playerskin->value = R_SkinAvailable(playerskin->string); + if (playerskin->value < 0) { - INT32 skinnum = players[consoleplayer].skin; - CV_StealthSet(&cv_skin, skins[skinnum].name); - cv_skin.value = skinnum; + INT32 skinnum = player->skin; + CV_StealthSet(playerskin, skins[skinnum].name); + playerskin->value = skinnum; } // Finally write out the complete packet and send it off. - WRITESTRINGN(p, cv_playername.zstring, MAXPLAYERNAME); - WRITEUINT8(p, (UINT8)cv_playercolor.value); - WRITEUINT8(p, (UINT8)cv_skin.value); - SendNetXCmdForPlayer(0, XD_NAMEANDCOLOR, buf, p - buf); -} - -// splitscreen -static void SendNameAndColor2(void) -{ - INT32 secondplaya = -1; - char buf[MAXPLAYERNAME+2]; - char *p; - - if (splitscreen < 1 && !botingame) - return; // can happen if skin2/color2/name2 changed - - if (displayplayers[1] != consoleplayer) - secondplaya = displayplayers[1]; - else if (!netgame) // HACK - secondplaya = 1; - - if (secondplaya == -1) - return; - - p = buf; - - // normal player colors - if (G_GametypeHasTeams()) - { - if (players[secondplaya].ctfteam == 1 && cv_playercolor2.value != skincolor_redteam) - CV_StealthSetValue(&cv_playercolor2, skincolor_redteam); - else if (players[secondplaya].ctfteam == 2 && cv_playercolor2.value != skincolor_blueteam) - CV_StealthSetValue(&cv_playercolor2, skincolor_blueteam); - } - - // never allow the color "none" - if (!cv_playercolor2.value) - { - if (players[secondplaya].skincolor) - CV_StealthSetValue(&cv_playercolor2, players[secondplaya].skincolor); - else if (skins[players[secondplaya].skin].prefcolor) - CV_StealthSetValue(&cv_playercolor2, skins[players[secondplaya].skin].prefcolor); - else - CV_StealthSet(&cv_playercolor2, cv_playercolor2.defaultvalue); - } - - // We'll handle it later if we're not playing. - if (!Playing()) - return; - - // If you're not in a netgame, merely update the skin, color, and name. - if (botingame) - { - players[secondplaya].skincolor = botcolor; - if (players[secondplaya].mo) - players[secondplaya].mo->color = players[secondplaya].skincolor; - SetPlayerSkinByNum(secondplaya, botskin-1); - return; - } - else if (!netgame) - { - INT32 foundskin; - - CleanupPlayerName(secondplaya, cv_playername2.zstring); - strcpy(player_names[secondplaya], cv_playername2.zstring); - - // don't use displayplayers[1]: the second player must be 1 - players[secondplaya].skincolor = cv_playercolor2.value; - if (players[secondplaya].mo) - players[secondplaya].mo->color = players[secondplaya].skincolor; - - if ((foundskin = R_SkinAvailable(cv_skin2.string)) != -1) - { - cv_skin2.value = foundskin; - SetPlayerSkin(secondplaya, cv_skin2.string); - } - else - { - cv_skin2.value = players[secondplaya].skin; - CV_StealthSet(&cv_skin2, skins[players[secondplaya].skin].name); - // will always be same as current - SetPlayerSkin(secondplaya, cv_skin2.string); - } - return; - } - - snac2pending++; - - // Don't change name if muted - if (player_name_changes[displayplayers[1]] >= MAXNAMECHANGES) - { - CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]); - HU_AddChatText("\x85*You must wait to change your name again", false); - } - else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[1]))) - CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]); - else // Cleanup name if changing it - CleanupPlayerName(displayplayers[1], cv_playername2.zstring); - - // Don't change skin if the server doesn't want you to. - if (!CanChangeSkin(displayplayers[1])) - CV_StealthSet(&cv_skin2, skins[players[displayplayers[1]].skin].name); - - // check if player has the skin loaded (cv_skin2 may have - // the name of a skin that was available in the previous game) - cv_skin2.value = R_SkinAvailable(cv_skin2.string); - if (cv_skin2.value < 0) - { - INT32 skinnum = players[displayplayers[1]].skin; - CV_StealthSet(&cv_skin2, skins[skinnum].name); - cv_skin2.value = skinnum; - } - - // Finally write out the complete packet and send it off. - WRITESTRINGN(p, cv_playername2.zstring, MAXPLAYERNAME); - WRITEUINT8(p, (UINT8)cv_playercolor2.value); - WRITEUINT8(p, (UINT8)cv_skin2.value); - SendNetXCmdForPlayer(1, XD_NAMEANDCOLOR, buf, p - buf); -} - -static void SendNameAndColor3(void) -{ - INT32 thirdplaya = -1; - char buf[MAXPLAYERNAME+2]; - char *p; - - if (splitscreen < 2) - return; // can happen if skin3/color3/name3 changed - - if (displayplayers[2] != consoleplayer) - thirdplaya = displayplayers[2]; - else if (!netgame) // HACK - thirdplaya = 2; - - if (thirdplaya == -1) - return; - - p = buf; - - // normal player colors - if (G_GametypeHasTeams()) - { - if (players[thirdplaya].ctfteam == 1 && cv_playercolor3.value != skincolor_redteam) - CV_StealthSetValue(&cv_playercolor3, skincolor_redteam); - else if (players[thirdplaya].ctfteam == 2 && cv_playercolor3.value != skincolor_blueteam) - CV_StealthSetValue(&cv_playercolor3, skincolor_blueteam); - } - - // never allow the color "none" - if (!cv_playercolor3.value) - { - if (players[thirdplaya].skincolor) - CV_StealthSetValue(&cv_playercolor3, players[thirdplaya].skincolor); - else if (skins[players[thirdplaya].skin].prefcolor) - CV_StealthSetValue(&cv_playercolor3, skins[players[thirdplaya].skin].prefcolor); - else - CV_StealthSet(&cv_playercolor3, cv_playercolor3.defaultvalue); - } - - // We'll handle it later if we're not playing. - if (!Playing()) - return; - - // If you're not in a netgame, merely update the skin, color, and name. - if (!netgame) - { - INT32 foundskin; - - CleanupPlayerName(thirdplaya, cv_playername3.zstring); - strcpy(player_names[thirdplaya], cv_playername3.zstring); - - // don't use displayplayers[2]: the third player must be 2 - players[thirdplaya].skincolor = cv_playercolor3.value; - if (players[thirdplaya].mo) - players[thirdplaya].mo->color = players[thirdplaya].skincolor; - - if ((foundskin = R_SkinAvailable(cv_skin3.string)) != -1) - { - cv_skin3.value = foundskin; - SetPlayerSkin(thirdplaya, cv_skin3.string); - } - else - { - cv_skin3.value = players[thirdplaya].skin; - CV_StealthSet(&cv_skin3, skins[players[thirdplaya].skin].name); - // will always be same as current - SetPlayerSkin(thirdplaya, cv_skin3.string); - } - return; - } - - snac3pending++; - - // Don't change name if muted - if (player_name_changes[displayplayers[2]] >= MAXNAMECHANGES) - { - CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]); - HU_AddChatText("\x85*You must wait to change your name again", false); - } - else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[2]))) - CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]); - else // Cleanup name if changing it - CleanupPlayerName(displayplayers[2], cv_playername3.zstring); - - // Don't change skin if the server doesn't want you to. - if (!CanChangeSkin(displayplayers[2])) - CV_StealthSet(&cv_skin3, skins[players[displayplayers[2]].skin].name); - - // check if player has the skin loaded (cv_skin3 may have - // the name of a skin that was available in the previous game) - cv_skin3.value = R_SkinAvailable(cv_skin3.string); - if (cv_skin3.value < 0) - { - INT32 skinnum = players[displayplayers[2]].skin; - CV_StealthSet(&cv_skin3, skins[skinnum].name); - cv_skin3.value = skinnum; - } - - // Finally write out the complete packet and send it off. - WRITESTRINGN(p, cv_playername3.zstring, MAXPLAYERNAME); - WRITEUINT8(p, (UINT8)cv_playercolor3.value); - WRITEUINT8(p, (UINT8)cv_skin3.value); - SendNetXCmdForPlayer(2, XD_NAMEANDCOLOR, buf, p - buf); -} - -static void SendNameAndColor4(void) -{ - INT32 fourthplaya = -1; - char buf[MAXPLAYERNAME+2]; - char *p; - - if (splitscreen < 3) - return; // can happen if skin4/color4/name4 changed - - if (displayplayers[3] != consoleplayer) - fourthplaya = displayplayers[3]; - else if (!netgame) // HACK - fourthplaya = 3; - - if (fourthplaya == -1) - return; - - p = buf; - - // normal player colors - if (G_GametypeHasTeams()) - { - if (players[fourthplaya].ctfteam == 1 && cv_playercolor4.value != skincolor_redteam) - CV_StealthSetValue(&cv_playercolor4, skincolor_redteam); - else if (players[fourthplaya].ctfteam == 2 && cv_playercolor4.value != skincolor_blueteam) - CV_StealthSetValue(&cv_playercolor4, skincolor_blueteam); - } - - // never allow the color "none" - if (!cv_playercolor4.value) - { - if (players[fourthplaya].skincolor) - CV_StealthSetValue(&cv_playercolor4, players[fourthplaya].skincolor); - else if (skins[players[fourthplaya].skin].prefcolor) - CV_StealthSetValue(&cv_playercolor4, skins[players[fourthplaya].skin].prefcolor); - else - CV_StealthSet(&cv_playercolor4, cv_playercolor4.defaultvalue); - } - - // We'll handle it later if we're not playing. - if (!Playing()) - return; - - // If you're not in a netgame, merely update the skin, color, and name. - if (botingame) - { - players[fourthplaya].skincolor = botcolor; - if (players[fourthplaya].mo) - players[fourthplaya].mo->color = players[fourthplaya].skincolor; - SetPlayerSkinByNum(fourthplaya, botskin-1); - return; - } - else if (!netgame) - { - INT32 foundskin; - - CleanupPlayerName(fourthplaya, cv_playername4.zstring); - strcpy(player_names[fourthplaya], cv_playername4.zstring); - - // don't use displayplayers[3]: the second player must be 4 - players[fourthplaya].skincolor = cv_playercolor4.value; - if (players[fourthplaya].mo) - players[fourthplaya].mo->color = players[fourthplaya].skincolor; - - if ((foundskin = R_SkinAvailable(cv_skin4.string)) != -1) - { - cv_skin4.value = foundskin; - SetPlayerSkin(fourthplaya, cv_skin4.string); - } - else - { - cv_skin4.value = players[fourthplaya].skin; - CV_StealthSet(&cv_skin4, skins[players[fourthplaya].skin].name); - // will always be same as current - SetPlayerSkin(fourthplaya, cv_skin4.string); - } - return; - } - - snac4pending++; - - // Don't change name if muted - if (player_name_changes[displayplayers[3]] >= MAXNAMECHANGES) - { - CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]); - HU_AddChatText("\x85*You must wait to change your name again", false); - } - else if (cv_mute.value && !(server || IsPlayerAdmin(displayplayers[3]))) - CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]); - else // Cleanup name if changing it - CleanupPlayerName(displayplayers[3], cv_playername4.zstring); - - // Don't change skin if the server doesn't want you to. - if (!CanChangeSkin(displayplayers[3])) - CV_StealthSet(&cv_skin4, skins[players[displayplayers[3]].skin].name); - - // check if player has the skin loaded (cv_skin4 may have - // the name of a skin that was available in the previous game) - cv_skin4.value = R_SkinAvailable(cv_skin4.string); - if (cv_skin4.value < 0) - { - INT32 skinnum = players[displayplayers[3]].skin; - CV_StealthSet(&cv_skin4, skins[skinnum].name); - cv_skin4.value = skinnum; - } - - // Finally write out the complete packet and send it off. - WRITESTRINGN(p, cv_playername4.zstring, MAXPLAYERNAME); - WRITEUINT8(p, (UINT8)cv_playercolor4.value); - WRITEUINT8(p, (UINT8)cv_skin4.value); - SendNetXCmdForPlayer(3, XD_NAMEANDCOLOR, buf, p - buf); + WRITESTRINGN(p, playername->zstring, MAXPLAYERNAME); + WRITEUINT8(p, (UINT8)playercolor->value); + WRITEUINT8(p, (UINT8)playerskin->value); + SendNetXCmdForPlayer(splitplayer, XD_NAMEANDCOLOR, buf, p - buf); } static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) { - player_t *p = &players[playernum]; + player_t *player = &players[playernum]; char name[MAXPLAYERNAME+1]; UINT8 color, skin; @@ -1928,19 +1628,14 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) I_Error("There is no player %d!", playernum); #endif - if (playernum == consoleplayer) - snacpending--; // TODO: make snacpending an array instead of 4 separate vars? - else if (playernum == displayplayers[1]) - snac2pending--; - else if (playernum == displayplayers[2]) - snac3pending--; - else if (playernum == displayplayers[3]) - snac4pending--; - + if (P_IsLocalPlayer(player)) + { + snacpending[playernum]--; #ifdef PARANOIA - if (snacpending < 0 || snac2pending < 0 || snac3pending < 0 || snac4pending < 0) - I_Error("snacpending negative!"); + if (snacpending[playernum] < 0) + I_Error("snacpending negative!"); #endif + } READSTRINGN(*cp, name, MAXPLAYERNAME); color = READUINT8(*cp); @@ -1954,33 +1649,32 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) } // set color - p->skincolor = color % MAXSKINCOLORS; - if (p->mo) - p->mo->color = (UINT8)p->skincolor; + player->skincolor = color % MAXSKINCOLORS; + if (player->mo) + player->mo->color = (UINT8)player->skincolor; demo_extradata[playernum] |= DXD_COLOR; // normal player colors - if (server && (p != &players[consoleplayer] && p != &players[displayplayers[1]] - && p != &players[displayplayers[2]] && p != &players[displayplayers[3]])) + if (server && !P_IsLocalPlayer(player)) { boolean kick = false; // team colors if (G_GametypeHasTeams()) { - if (p->ctfteam == 1 && p->skincolor != skincolor_redteam) + if (player->ctfteam == 1 && player->skincolor != skincolor_redteam) kick = true; - else if (p->ctfteam == 2 && p->skincolor != skincolor_blueteam) + else if (player->ctfteam == 2 && player->skincolor != skincolor_blueteam) kick = true; } // don't allow color "none" - if (!p->skincolor) + if (!player->skincolor) kick = true; if (kick) { - CONS_Alert(CONS_WARNING, M_GetText("Illegal color change received from %s (team: %d), color: %d)\n"), player_names[playernum], p->ctfteam, p->skincolor); + CONS_Alert(CONS_WARNING, M_GetText("Illegal color change received from %s (team: %d), color: %d)\n"), player_names[playernum], player->ctfteam, player->skincolor); SendKick(playernum, KICK_MSG_CON_FAIL); return; } @@ -1992,6 +1686,7 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) const INT32 forcedskin = cv_forceskin.value; SetPlayerSkinByNum(playernum, forcedskin); + // TODO: make cv_skin an array if (playernum == consoleplayer) CV_StealthSet(&cv_skin, skins[forcedskin].name); else if (playernum == displayplayers[1]) @@ -2005,44 +1700,16 @@ static void Got_NameAndColor(const UINT8 **cp, INT32 playernum) SetPlayerSkinByNum(playernum, skin); } -void SendWeaponPref(void) +void SendWeaponPref(UINT8 splitplayer) { UINT8 buf[1]; buf[0] = 0; - if (cv_flipcam[0].value) + + if (cv_flipcam[splitplayer].value) buf[0] |= 1; - SendNetXCmdForPlayer(0, XD_WEAPONPREF, buf, 1); -} -void SendWeaponPref2(void) -{ - UINT8 buf[1]; - - buf[0] = 0; - if (cv_flipcam[1].value) - buf[0] |= 1; - SendNetXCmdForPlayer(1, XD_WEAPONPREF, buf, 1); -} - -void SendWeaponPref3(void) -{ - UINT8 buf[1]; - - buf[0] = 0; - if (cv_flipcam[2].value) - buf[0] |= 1; - SendNetXCmdForPlayer(2, XD_WEAPONPREF, buf, 1); -} - -void SendWeaponPref4(void) -{ - UINT8 buf[1]; - - buf[0] = 0; - if (cv_flipcam[3].value) - buf[0] |= 1; - SendNetXCmdForPlayer(3, XD_WEAPONPREF, buf, 1); + SendNetXCmdForPlayer(splitplayer, XD_WEAPONPREF, buf, 1); } static void Got_WeaponPref(const UINT8 **cp, INT32 playernum) @@ -2058,23 +1725,10 @@ static void Got_WeaponPref(const UINT8 **cp, INT32 playernum) player->pflags |= PF_ANALOGMODE; } -void D_SendPlayerConfig(void) +void D_SendPlayerConfig(UINT8 splitplayer) { - SendNameAndColor(); - if (splitscreen || botingame) - SendNameAndColor2(); - if (splitscreen > 1) - SendNameAndColor3(); - if (splitscreen > 2) - SendNameAndColor4(); - - SendWeaponPref(); - if (splitscreen) - SendWeaponPref2(); - if (splitscreen > 1) - SendWeaponPref3(); - if (splitscreen > 2) - SendWeaponPref4(); + SendNameAndColor(splitplayer); + SendWeaponPref(splitplayer); } // Only works for displayplayer, sorry! @@ -2097,10 +1751,12 @@ INT32 D_LookupPlayer(const char *s) return playernum; } + const size_t len = strlen(s); + for (playernum = 0; playernum < MAXPLAYERS; ++playernum) { /* Match name case-insensitively: fully, or partially the start. */ - if (playeringame[playernum] && (strnicmp(player_names[playernum], s, strlen(s)) == 0)) + if (playeringame[playernum] && (strnicmp(player_names[playernum], s, len) == 0)) { return playernum; } @@ -2140,13 +1796,15 @@ static void GetViewablePlayerPlaceRange(INT32 *first, INT32 *last) (*last) = 0; for (i = 0; i < MAXPLAYERS; ++i) - if (G_CouldView(i)) { - place = players[i].kartstuff[k_position]; - if (place < (*first)) - (*first) = place; - if (place > (*last)) - (*last) = place; + if (G_CouldView(i)) + { + place = players[i].kartstuff[k_position]; + if (place < (*first)) + (*first) = place; + if (place > (*last)) + (*last) = place; + } } } @@ -2480,7 +2138,7 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pencoremode, boolean r displayplayers[1] = 1; playeringame[1] = true; players[1].bot = 1; - SendNameAndColor2(); + SendNameAndColor(1); } } @@ -5735,50 +5393,54 @@ static void ForceSkin_OnChange(void) } } -//Allows the player's name to be changed if cv_mute is off. +// Allows the player's name to be changed if cv_mute is off. static void Name_OnChange(void) { if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CV_StealthSet(&cv_playername, player_names[consoleplayer]); + return; } - else - SendNameAndColor(); + + SendNameAndColor(0); } static void Name2_OnChange(void) { - if (cv_mute.value) //Secondary player can't be admin. + if (cv_mute.value) // Secondary player can't be admin. { CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CV_StealthSet(&cv_playername2, player_names[displayplayers[1]]); + return; } - else - SendNameAndColor2(); + + SendNameAndColor(1); } static void Name3_OnChange(void) { - if (cv_mute.value) //Third player can't be admin. + if (cv_mute.value) // Third player can't be admin. { CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CV_StealthSet(&cv_playername3, player_names[displayplayers[2]]); + return; } - else - SendNameAndColor3(); + + SendNameAndColor(2); } static void Name4_OnChange(void) { - if (cv_mute.value) //Secondary player can't be admin. + if (cv_mute.value) // Secondary player can't be admin. { CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CV_StealthSet(&cv_playername4, player_names[displayplayers[3]]); + return; } - else - SendNameAndColor4(); + + SendNameAndColor(3); } /** Sends a skin change for the console player, unless that player is moving. @@ -5800,7 +5462,7 @@ static void Skin_OnChange(void) } if (CanChangeSkin(consoleplayer) && !P_PlayerMoving(consoleplayer)) - SendNameAndColor(); + SendNameAndColor(0); else { CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); @@ -5821,7 +5483,7 @@ static void Skin2_OnChange(void) return; // do whatever you want if (CanChangeSkin(displayplayers[1]) && !P_PlayerMoving(displayplayers[1])) - SendNameAndColor2(); + SendNameAndColor(1); else { CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); @@ -5837,7 +5499,7 @@ static void Skin3_OnChange(void) return; // do whatever you want if (CanChangeSkin(displayplayers[2]) && !P_PlayerMoving(displayplayers[2])) - SendNameAndColor3(); + SendNameAndColor(2); else { CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); @@ -5853,7 +5515,7 @@ static void Skin4_OnChange(void) return; // do whatever you want if (CanChangeSkin(displayplayers[3]) && !P_PlayerMoving(displayplayers[3])) - SendNameAndColor4(); + SendNameAndColor(3); else { CONS_Alert(CONS_NOTICE, M_GetText("You can't change your skin at the moment.\n")); @@ -5966,7 +5628,7 @@ static void Color_OnChange(void) if (!P_PlayerMoving(consoleplayer)) { // Color change menu scrolling fix is no longer necessary - SendNameAndColor(); + SendNameAndColor(0); } else { @@ -5988,7 +5650,7 @@ static void Color2_OnChange(void) if (!P_PlayerMoving(displayplayers[1])) { // Color change menu scrolling fix is no longer necessary - SendNameAndColor2(); + SendNameAndColor(1); } else { @@ -6005,7 +5667,7 @@ static void Color3_OnChange(void) if (!P_PlayerMoving(displayplayers[2])) { // Color change menu scrolling fix is no longer necessary - SendNameAndColor3(); + SendNameAndColor(2); } else { @@ -6022,7 +5684,7 @@ static void Color4_OnChange(void) if (!P_PlayerMoving(displayplayers[3])) { // Color change menu scrolling fix is no longer necessary - SendNameAndColor4(); + SendNameAndColor(3); } else { diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 6b7382403..f22fe33a8 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -21,10 +21,7 @@ extern "C" { #include "command.h" -void SendWeaponPref(void); -void SendWeaponPref2(void); -void SendWeaponPref3(void); -void SendWeaponPref4(void); +void SendWeaponPref(UINT8 splitplayer); // console vars extern consvar_t cv_playername; @@ -295,7 +292,7 @@ typedef union { // add game commands, needs cleanup void D_RegisterServerCommands(void); void D_RegisterClientCommands(void); -void D_SendPlayerConfig(void); +void D_SendPlayerConfig(UINT8 splitplayer); void Command_ExitGame_f(void); void Command_Retry_f(void); void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore diff --git a/src/r_main.cpp b/src/r_main.cpp index 1ad8e8be9..fe9edc9eb 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -277,22 +277,22 @@ static void Fov_OnChange(void) static void FlipCam_OnChange(void) { - SendWeaponPref(); + SendWeaponPref(0); } static void FlipCam2_OnChange(void) { - SendWeaponPref2(); + SendWeaponPref(1); } static void FlipCam3_OnChange(void) { - SendWeaponPref3(); + SendWeaponPref(2); } static void FlipCam4_OnChange(void) { - SendWeaponPref4(); + SendWeaponPref(3); } static void Precipstuff_OnChange(void) -- 2.54.0 From c680dd3222667b4f948d0c01a05925e65b63f63a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 20:24:39 +0100 Subject: [PATCH 03/47] fix some packet types not being correctly handled --- src/d_clisrv.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ccb8d092b..f622b4802 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5994,6 +5994,9 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENTQUIT: PT_ClientQuit(netconsole, node); break; + case PT_SERVERINFO: + PT_ServerInfo(node); + break; case PT_RESYNCHGET: SV_AcknowledgeResynchAck(node, netbuffer->u.resynchgot); break; @@ -6024,6 +6027,12 @@ static void HandlePacketFromPlayer(SINT8 node) is_client_saturn[node] = true; break; #endif + case PT_CLIENTJOIN: + PT_ClientJoin(node); + break; + case PT_SERVERSHUTDOWN: + PT_ServerShutdown(node); + break; case PT_RESYNCHING: PT_Resynching(node); break; -- 2.54.0 From e83e2659a7567cf219c4d9ff0b86b3e31a470402 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 21:50:44 +0100 Subject: [PATCH 04/47] reorder packets again --- src/d_clisrv.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f622b4802..5d1566f47 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4804,7 +4804,6 @@ static void PT_ClientJoin(SINT8 node) } } - #ifdef SATURNJOIN const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && netbuffer->u.clientcfg.issaturn == ISSATURN); // Check the packet lenght to skip potential garbo data! #endif @@ -5425,19 +5424,17 @@ static void HandlePacketFromAwayNode(SINT8 node) case PT_NEEDMAPICON: PT_NeedMapIcon(node); break; - case PT_CLIENTJOIN: - PT_ClientJoin(node); - break; case PT_SERVERSHUTDOWN: PT_ServerShutdown(node); break; - + case PT_CLIENTJOIN: + PT_ClientJoin(node); + break; case PT_SERVERTICS: // Do not remove my own server (we have just get a out of order packet) if (node == servernode) break; /* FALLTHRU */ - default: DEBFILE(va("unknown packet received (%d) from unknown host\n", netbuffer->packettype)); Net_CloseConnection(node); @@ -5994,6 +5991,14 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENTQUIT: PT_ClientQuit(netconsole, node); break; +#ifdef SATURNPAK + case PT_CANRECEIVEGAMESTATE: + PT_CanReceiveGamestate(node); + break; + case PT_RECEIVEDGAMESTATE: + PT_ReceivedGamestate(node); + break; +#endif case PT_SERVERINFO: PT_ServerInfo(node); break; @@ -6007,18 +6012,11 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_PING: PT_Ping(node); break; - case PT_SERVERCFG: - break; + case PT_FILEFRAGMENT: PT_FileFragmentFromPlayer(node); break; #ifdef SATURNPAK - case PT_CANRECEIVEGAMESTATE: - PT_CanReceiveGamestate(node); - break; - case PT_RECEIVEDGAMESTATE: - PT_ReceivedGamestate(node); - break; case PT_WILLRESENDGAMESTATE: PT_WillResendGamestate(); break; @@ -6027,12 +6025,14 @@ static void HandlePacketFromPlayer(SINT8 node) is_client_saturn[node] = true; break; #endif - case PT_CLIENTJOIN: - PT_ClientJoin(node); - break; case PT_SERVERSHUTDOWN: PT_ServerShutdown(node); break; + case PT_SERVERCFG: + break; + case PT_CLIENTJOIN: + PT_ClientJoin(node); + break; case PT_RESYNCHING: PT_Resynching(node); break; -- 2.54.0 From 265f4a50ef6eb414572d16096cf50c1f837b6a7f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 22:04:18 +0100 Subject: [PATCH 05/47] readd check for node before SV_SendSaveGame Apparently in some cases the server will connect to itself, in this case the server tries to send itself the savegame, leading to a crash in some cases. oops --- src/d_clisrv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5d1566f47..a7745242d 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4781,7 +4781,7 @@ static size_t TotalTextCmdPerTic(tic_t tic) static void PT_ClientJoin(SINT8 node) { // Ignore duplicate packets - if (client || nodeingame[node]|| levelloading) + if (client || nodeingame[node] || levelloading) return; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -4917,8 +4917,11 @@ static void PT_ClientJoin(SINT8 node) if (nodewaiting[node]) { - SV_SendSaveGame(node, false); // send a complete game state - DEBFILE("send savegame\n"); + if (node) + { + SV_SendSaveGame(node, false); // send a complete game state + DEBFILE("send savegame\n"); + } SV_AddWaitingPlayers(node); } -- 2.54.0 From f49e57a38c29e845e62032528a1e01a08ea1988f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 23:16:35 +0100 Subject: [PATCH 06/47] d_cliserv: Cleanup PT_ClientJoin move refuse message handling into its own function --- src/d_clisrv.c | 168 +++++++++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 76 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a7745242d..653dae05e 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4746,17 +4746,6 @@ void SV_StartSinglePlayerServer(void) multiplayer = true; } -static void SV_SendRefuse(INT32 node, const char *reason) -{ - doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); - - strcpy(netbuffer->u.serverrefuse.reason, reason); - - netbuffer->packettype = PT_SERVERREFUSE; - HSendPacket(node, false, 0, strlen(netbuffer->u.serverrefuse.reason) + 1); - Net_CloseConnection(node); -} - // used at txtcmds received to check packetsize bound static size_t TotalTextCmdPerTic(tic_t tic) { @@ -4773,19 +4762,25 @@ static size_t TotalTextCmdPerTic(tic_t tic) return total; } -/** Called when a PT_CLIENTJOIN packet is received - * - * \param node The packet sender - * - */ -static void PT_ClientJoin(SINT8 node) +static void SV_SendRefuse(INT32 node, const char *reason) { - // Ignore duplicate packets - if (client || nodeingame[node] || levelloading) - return; - doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); + strcpy(netbuffer->u.serverrefuse.reason, reason); + + netbuffer->packettype = PT_SERVERREFUSE; + HSendPacket(node, false, 0, strlen(netbuffer->u.serverrefuse.reason) + 1); + Net_CloseConnection(node); +} + +static const char *GetRefuseMessage(SINT8 node) +{ + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); + clientconfig_pak *cc = &netbuffer->u.clientcfg; + + if (!node) /* server connecting to itself */ + return NULL; + // Sal: Dedicated mode is INCREDIBLY hacked together. // If a server filled out, then it'd overwrite the host and turn everyone into weird husks..... // It's too much effort to legimately fix right now. Just prevent it from reaching that state. @@ -4805,7 +4800,7 @@ static void PT_ClientJoin(SINT8 node) } #ifdef SATURNJOIN - const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && netbuffer->u.clientcfg.issaturn == ISSATURN); // Check the packet lenght to skip potential garbo data! + const boolean issaturn = (((doomcom->datalength) == sizeof(clientconfig_pak)) && (cc->issaturn == ISSATURN)); // Check the packet length to skip garbo data! #endif if (bannednode && bannednode[node].banid != SIZE_MAX) @@ -4818,47 +4813,44 @@ static void PT_ClientJoin(SINT8 node) if (bannednode[node].timeleft != NO_BAN_TIME) { - // these are fudged a little to allow it to sink in for impatient rejoiners + // these are fudged a little to allow it to sink in for impatient rejoiners int minutes = (bannednode[node].timeleft + 30) / 60; int hours = (minutes + 1) / 60; int days = (hours + 1) / 24; if (days) { - SV_SendRefuse(node, va("K|%s\n(Time remaining: %d day%s)", reason, days, days > 1 ? "s" : "")); + return va("K|%s\n(Time remaining: %d day%s)", reason, days, days > 1 ? "s" : ""); } else if (hours) { - SV_SendRefuse(node, va("K|%s\n(Time remaining: %d hour%s)", reason, hours, hours > 1 ? "s" : "")); + return va("K|%s\n(Time remaining: %d hour%s)", reason, hours, hours > 1 ? "s" : ""); } else if (minutes) { - SV_SendRefuse(node, va("K|%s\n(Time remaining: %d minute%s)", reason, minutes, minutes > 1 ? "s" : "")); + return va("K|%s\n(Time remaining: %d minute%s)", reason, minutes, minutes > 1 ? "s" : ""); } else { - SV_SendRefuse(node, va("K|%s\n(Time remaining: <1 minute)", reason)); + return va("K|%s\n(Time remaining: <1 minute)", reason); } } else { - SV_SendRefuse(node, va("B|%s", reason)); + return va("B|%s", reason); } } - else if (netbuffer->u.clientcfg._255 != 255 || - netbuffer->u.clientcfg.packetversion != PACKETVERSION) + else if (cc->_255 != 255 || cc->packetversion != PACKETVERSION) { - SV_SendRefuse(node, "Incompatible packet formats."); + return "Incompatible packet formats."; } - else if (strncmp(netbuffer->u.clientcfg.application, SRB2APPLICATION, - sizeof netbuffer->u.clientcfg.application)) + else if (strncmp(cc->application, SRB2APPLICATION, sizeof(cc->application))) { - SV_SendRefuse(node, "Different SRB2Kart modifications\nare not compatible."); + return "Different SRB2Kart modifications\nare not compatible."; } - else if (netbuffer->u.clientcfg.version != VERSION - || netbuffer->u.clientcfg.subversion != SUBVERSION) + else if (cc->version != VERSION || cc->subversion != SUBVERSION) { - SV_SendRefuse(node, va("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)", VERSION, SUBVERSION)); + return va("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)", VERSION, SUBVERSION); } #ifdef SATURNJOIN else if (((!cv_allownewplayer.value && !issaturn) || (!cv_allownewsaturnplayer.value && issaturn)) && node) @@ -4866,65 +4858,89 @@ static void PT_ClientJoin(SINT8 node) else if (!cv_allownewplayer.value && node) #endif { - SV_SendRefuse(node, cv_joinrefusemessage.string); + return cv_joinrefusemessage.string; } else if (connectedplayers >= maxplayers) { - SV_SendRefuse(node, va("Maximum players reached: %d", maxplayers)); + return va("Maximum players reached: %d", maxplayers); } - else if (netgame && netbuffer->u.clientcfg.localplayers > 4) // Hacked client? + else if (cc->localplayers != 1) { - SV_SendRefuse(node, "Too many players from\nthis node."); + return "Wrong player count."; } - else if (netgame && connectedplayers + netbuffer->u.clientcfg.localplayers > maxplayers) + else if (netgame && !cc->localplayers) // Stealth join? { - SV_SendRefuse(node, va("Number of local players\nwould exceed maximum: %d", maxplayers)); + return "No players from\nthis node."; } - else if (netgame && !netbuffer->u.clientcfg.localplayers) // Stealth join? + else if (netgame && cc->localplayers > 4) // Hacked client? { - SV_SendRefuse(node, "No players from\nthis node."); + return "Too many players from\nthis node."; } - else + else if (netgame && connectedplayers + cc->localplayers > maxplayers) { - // client authorised to join - nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); + return va("Number of local players\nwould exceed maximum: %d", maxplayers); + } - gamestate_t backupstate = gamestate; + return NULL; +} - SV_AddNode(node); +/** Called when a PT_CLIENTJOIN packet is received + * + * \param node The packet sender + * + */ +static void PT_ClientJoin(SINT8 node) +{ + // Ignore duplicate packets + if (client || nodeingame[node] || levelloading) + return; - /// \note Wait what??? - /// What if the gamestate takes more than one second to get downloaded? - /// Or if a lagspike happens? - // you get a free second before desynch checks. use it wisely. - SV_InitResynchVars(node); + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); - if (!SV_SendServerConfig(node)) - { - G_SetGamestate(backupstate); - /// \note Shouldn't SV_SendRefuse be called before ResetNode? - SV_SendRefuse(node, "Server couldn't send info, please try again"); - ResetNode(node); // Yeah, lets try it! - /// \todo fix this !!! - return; // restart the while - } + const char *refuse = GetRefuseMessage(node); - SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea - //if (gamestate != GS_LEVEL) // GS_INTERMISSION, etc? - // SV_SendPlayerConfigs(node); // send bare minimum player info + if (refuse) + { + SV_SendRefuse(node, refuse); + return; + } + + // client authorised to join + nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); + + gamestate_t backupstate = gamestate; + + SV_AddNode(node); + + /// \note Wait what??? + /// What if the gamestate takes more than one second to get downloaded? + /// Or if a lagspike happens? + // you get a free second before desynch checks. use it wisely. + SV_InitResynchVars(node); + + if (!SV_SendServerConfig(node)) + { G_SetGamestate(backupstate); - DEBFILE("new node joined\n"); + /// \note Shouldn't SV_SendRefuse be called before ResetNode? + SV_SendRefuse(node, "Server couldn't send info, please try again"); + ResetNode(node); // Yeah, lets try it! + /// \todo fix this !!! + return; // restart the while + } - if (nodewaiting[node]) + SV_SendServerInfo(node, 0); // Dunno if 0 time is good idea + G_SetGamestate(backupstate); + DEBFILE("new node joined\n"); + + if (nodewaiting[node]) + { + if (node) { - if (node) - { - SV_SendSaveGame(node, false); // send a complete game state - DEBFILE("send savegame\n"); - } - - SV_AddWaitingPlayers(node); + SV_SendSaveGame(node, false); // send a complete game state + DEBFILE("send savegame\n"); } + + SV_AddWaitingPlayers(node); } } -- 2.54.0 From 7eb2ad1e35669293a4a35afd493bcfd967f97032 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Dec 2025 23:20:17 +0100 Subject: [PATCH 07/47] slightly cleanup SV_AddWaitingPlayers --- src/d_clisrv.c | 52 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 653dae05e..1117112cb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4445,18 +4445,21 @@ static inline void SV_AddNode(INT32 node) // Xcmd XD_ADDPLAYER static void Got_AddPlayer(const UINT8 **p, INT32 playernum) { + UINT8 i; INT16 node, newplayernum; UINT8 splitscreenplayer = 0; - UINT8 i; + player_t *newplayer; if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { // protect against hacked/buggy client CONS_Alert(CONS_WARNING, M_GetText("Illegal add player command received from %s\n"), player_names[playernum]); + if (server) { SendKick(playernum, KICK_MSG_CON_FAIL); } + return; } @@ -4465,14 +4468,19 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum) splitscreenplayer = newplayernum/MAXPLAYERS; newplayernum %= MAXPLAYERS; + CONS_Debug(DBG_NETPLAY, "addplayer: %d %d\n", node, newplayernum); + // Clear player before joining, lest some things get set incorrectly CL_ClearPlayer(newplayernum); playeringame[newplayernum] = true; G_AddPlayer(newplayernum); + if (newplayernum+1 > doomcom->numslots) doomcom->numslots = (INT16)(newplayernum+1); + newplayer = &players[newplayernum]; + // the server is creating my player if (node == mynode) { @@ -4483,7 +4491,7 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum) displayplayers[splitscreenplayer] = newplayernum; DEBFILE(va("spawning one of my sister number %d\n", splitscreenplayer)); if (splitscreenplayer == 1 && botingame) - players[newplayernum].bot = 1; + newplayer->bot = 1; // do we really want this löl } else { @@ -4493,13 +4501,13 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum) DEBFILE("spawning me\n"); } - P_ForceLocalAngle(&players[newplayernum], (angle_t)(players[newplayernum].cmd.angleturn << TICCMD_REDUCE)); + P_ForceLocalAngle(newplayer, (angle_t)(newplayer->cmd.angleturn << TICCMD_REDUCE)); D_SendPlayerConfig(splitscreenplayer); addedtogame = true; } - players[newplayernum].splitscreenindex = splitscreenplayer; + newplayer->splitscreenindex = splitscreenplayer; if (netgame) { @@ -4570,24 +4578,27 @@ static boolean SV_AddWaitingPlayers(SINT8 node) UINT8 newplayernum = 0; boolean newplayer = false; - // What is the reason for this? Why can't newplayernum always be 0? - // Sal: Because the dedicated player is stupidly forced into players[0]..... - if (dedicated) - newplayernum = 1; - // splitscreen can allow 2+ players in one node for (; nodewaiting[node] > 0; nodewaiting[node]--) { newplayer = true; // search for a free playernum - // we can't use playeringame since it is not updated here - for (; newplayernum < MAXPLAYERS; newplayernum++) + // we can't solely use playeringame since it is not updated here + for (newplayernum = dedicated ? 1 : 0; newplayernum < MAXPLAYERS; newplayernum++) { + if (playeringame[newplayernum]) + continue; + for (n = 0; n < MAXNETNODES; n++) - if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum - || nodetoplayer3[n] == newplayernum || nodetoplayer4[n] == newplayernum) + { + if (nodetoplayer[n] == newplayernum || + nodetoplayer2[n] == newplayernum || + nodetoplayer3[n] == newplayernum || + nodetoplayer4[n] == newplayernum) break; + } + if (n == MAXNETNODES) break; } @@ -4596,10 +4607,9 @@ static boolean SV_AddWaitingPlayers(SINT8 node) // before accepting the join I_Assert(newplayernum < MAXPLAYERS); - playernode[newplayernum] = (UINT8)node; - buf[0] = (UINT8)node; buf[1] = newplayernum; + if (playerpernode[node] < 1) { nodetoplayer[node] = newplayernum; @@ -4614,11 +4624,21 @@ static boolean SV_AddWaitingPlayers(SINT8 node) nodetoplayer3[node] = newplayernum; buf[1] += MAXPLAYERS*2; } - else + else if (playerpernode[node] < 4) { nodetoplayer4[node] = newplayernum; buf[1] += MAXPLAYERS*3; } + else + { + // I don't know if it's safe to assert here, + // but I do know this should not be allowed + // to be reached. + return newplayer; + } + + playernode[newplayernum] = (UINT8)node; + playerpernode[node]++; SendNetXCmd(XD_ADDPLAYER, &buf, 2); -- 2.54.0 From 37eba186f5621895112320878026e26bddb93cb9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Dec 2025 18:06:48 +0100 Subject: [PATCH 08/47] netcode: replace some stuff with memsets + add a little bounds safety in some places --- src/d_clisrv.c | 16 ++++++++++++++++ src/d_net.c | 6 +----- src/d_netfil.c | 32 ++++++++++++++++---------------- src/i_tcp.c | 16 +++++++++------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1117112cb..b380b2ed0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1939,8 +1939,11 @@ static boolean SV_ResendingSavegameToAnyone(void) INT32 i; for (i = 0; i < MAXNETNODES; i++) + { if (nodeingame[i] && resendingsavegame[i]) return true; + } + return false; } #endif @@ -2923,8 +2926,10 @@ static void CL_ConnectToServer(void) { pnumnodes = 0; for (i = 0; i < MAXNETNODES; i++) + { if (nodeingame[i]) pnumnodes++; + } } } while (!(cl_mode == CL_CONNECTED && (client || (server && nodewaited <= pnumnodes)))); @@ -4400,8 +4405,10 @@ void D_QuitNetGame(void) netbuffer->packettype = PT_SERVERSHUTDOWN; for (i = 0; i < MAXNETNODES; i++) + { if (nodeingame[i]) HSendPacket(i, true, 0, 0); + } #ifdef MASTERSERVER if (serverrunning && netgame && cv_advertise.value) // see mserv.c Online() UnregisterServer(); @@ -6851,8 +6858,10 @@ static inline void PingUpdate(void) //send out our ping packets for (i = 0; i < MAXNETNODES; i++) + { if (nodeingame[i]) HSendPacket(i, true, 0, sizeof(INT32) * (MAXPLAYERS+1)); + } pingmeasurecount = 0; //Reset count } @@ -6955,10 +6964,15 @@ static void RenewHolePunch(void) static void HandleNodeTimeouts(void) { INT32 i; + if (server) + { for (i = 1; i < MAXNETNODES; i++) + { if (nodeingame[i] && freezetimeout[i] < I_GetTime()) Net_ConnectionTimeout(i); + } + } } // Keep the network alive while not advancing tics! @@ -7168,11 +7182,13 @@ void NetUpdate(void) } for (i = 0; i < MAXNETNODES; ++i) + { if (resynch_inprogress[i]) { SV_SendResynch(i); counts = -666; } + } // Do not make tics while resynching if (counts != -666) diff --git a/src/d_net.c b/src/d_net.c index ba70cb7c1..33654ee67 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -611,12 +611,8 @@ void Net_WaitAllAckReceived(UINT32 timeout) static void InitNode(node_t *node) { - node->acktosend_head = node->acktosend_tail = 0; - memset(node->acktosend, 0, sizeof(node->acktosend)); - node->firstacktosend = 0; + memset(node, 0, sizeof(node_t)); node->nextacknum = 1; - node->remotefirstack = 0; - node->flags = 0; } static void InitAck(void) diff --git a/src/d_netfil.c b/src/d_netfil.c index d35bb09b3..ecbca1eed 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -958,7 +958,7 @@ void Got_Filetxpak(void) || fastcmp(filename, "music.kart") || fastcmp(filename, "patch.kart") )) - I_Error("Tried to download \"%s\"", filename); + I_Error("Tried to download base-game file: \"%s\"", filename); if (filenum >= fileneedednum) { @@ -1017,21 +1017,21 @@ void Got_Filetxpak(void) switch(file->status) { - case FS_NOTFOUND: - s = "FS_NOTFOUND"; - break; - case FS_FOUND: - s = "FS_FOUND"; - break; - case FS_OPEN: - s = "FS_OPEN"; - break; - case FS_MD5SUMBAD: - s = "FS_MD5SUMBAD"; - break; - default: - s = "unknown"; - break; + case FS_NOTFOUND: + s = "FS_NOTFOUND"; + break; + case FS_FOUND: + s = "FS_FOUND"; + break; + case FS_OPEN: + s = "FS_OPEN"; + break; + case FS_MD5SUMBAD: + s = "FS_MD5SUMBAD"; + break; + default: + s = "unknown"; + break; } I_Error("Received a file not requested (file id: %d, file status: %s)\n", filenum, s); diff --git a/src/i_tcp.c b/src/i_tcp.c index 98a03f841..e4d9e0a7a 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -496,8 +496,10 @@ static void cleanupnodes(void) // Why can't I start at zero? for (j = 1; j < MAXNETNODES; j++) + { if (!(nodeingame[j] || SV_SendingFile(j))) nodeconnected[j] = false; + } } static SINT8 getfreenode(void) @@ -507,11 +509,13 @@ static SINT8 getfreenode(void) cleanupnodes(); for (j = 0; j < MAXNETNODES; j++) + { if (!nodeconnected[j]) { nodeconnected[j] = true; return j; } + } /** \warning No free node? Just in case a node might not have been freed properly, * look if there are connected nodes that aren't in game, and forget them. @@ -810,7 +814,7 @@ static void SOCK_Send(void) static void SOCK_FreeNodenum(INT32 numnode) { // can't disconnect from self :) - if (!numnode || numnode > MAXNETNODES) + if (numnode <= 0 || numnode > MAXNETNODES) return; DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode))); @@ -1431,14 +1435,12 @@ static void SOCK_RegisterHolePunch(void) static boolean SOCK_OpenSocket(void) { - size_t i; - - memset(clientaddress, 0, sizeof (clientaddress)); + memset(clientaddress, 0, sizeof(clientaddress)); + memset(nodeconnected, false, sizeof(nodeconnected)); nodeconnected[0] = true; // always connected to self - for (i = 1; i < MAXNETNODES; i++) - nodeconnected[i] = false; nodeconnected[BROADCASTADDR] = true; + I_NetSend = SOCK_Send; I_NetGet = SOCK_Get; I_NetCloseSocket = SOCK_CloseSocket; @@ -1478,7 +1480,7 @@ static boolean SOCK_Ban(INT32 node) { INT32 ban; - if (node > MAXNETNODES) + if (node < 0 || node > MAXNETNODES) return false; ban = numbans; -- 2.54.0 From 4a3c9ccfbb81f8c11d92213be6c0ffdfd08abbdd Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 21:36:29 +0100 Subject: [PATCH 09/47] Remove tic provision (vanilla compat edition) based on https://codeberg.org/srb2classic/srb2classic/commit/7cf14fbe740998c3246dd190904f49a236b2ccec seems to get rid of some jitter in localhost --- src/d_clisrv.c | 54 +++++++++++++------------------------------------- src/d_net.c | 3 ++- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1a2717a12..ef78fe91a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -159,7 +159,6 @@ boolean nodeingame[MAXNETNODES] = {}; // set false as nodes leave game tic_t servermaxping = 20; // server's max delay, in frames. Defaults to 20 static tic_t nettics[MAXNETNODES]; // what tic the client have received -static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet static UINT8 nodewaiting[MAXNETNODES]; static tic_t firstticstosend; // min of the nettics static tic_t tictoclear = 0; // optimize d_clearticcmd @@ -186,7 +185,6 @@ boolean hu_stopped = false; // Client specific static ticcmd_t localcmds[MAXSPLITSCREENPLAYERS][MAXGENTLEMENDELAY]; -static boolean cl_packetmissed; // here it is for the secondary local player (splitscreen) static UINT8 mynode; // my address pointofview server @@ -4296,7 +4294,6 @@ static void ResetNode(INT32 node) playerpernode[node] = 0; nettics[node] = gametic; - supposedtics[node] = gametic; sendingsavegame[node] = false; @@ -4351,7 +4348,7 @@ void SV_ResetServer(void) ClearAdminPlayers(); mynode = 0; - cl_packetmissed = false; + #ifdef SATURNPAK cl_redownloadinggamestate = false; #endif @@ -4453,7 +4450,7 @@ void D_QuitNetGame(void) static inline void SV_AddNode(INT32 node) { nettics[node] = gametic; - supposedtics[node] = gametic; + // little hack because the server connects to itself and puts // nodeingame when connected not here if (node) @@ -5535,14 +5532,6 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) realstart = ExpandTics(netbuffer->u.clientpak.client_tic, nettics[node]); realend = ExpandTics(netbuffer->u.clientpak.resendfrom, nettics[node]); - if (netbuffer->packettype == PT_CLIENTMIS || netbuffer->packettype == PT_CLIENT2MIS - || netbuffer->packettype == PT_CLIENT3MIS || netbuffer->packettype == PT_CLIENT4MIS - || netbuffer->packettype == PT_NODEKEEPALIVEMIS - || supposedtics[node] < realend) - { - supposedtics[node] = realend; - } - // Discard out of order packet if (nettics[node] > realend) { @@ -5894,7 +5883,6 @@ static void PT_ServerTics(SINT8 node) if (realend > gametic + CLIENTBACKUPTICS) realend = gametic + CLIENTBACKUPTICS; - cl_packetmissed = realstart > neededtic; UINT8 *pak = (UINT8 *)&packet->cmds; UINT8 *txtpak = (UINT8 *)&packet->cmds[packet->numslots * packet->numtics]; @@ -6027,11 +6015,12 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: + case PT_NODEKEEPALIVE: + // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: - case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: PT_ClientCmd(netconsole, node); break; @@ -6323,25 +6312,18 @@ static void SV_SendServerKeepAlive(void) static void CL_SendClientCmd(void) { size_t packetsize = 0; - boolean mis = false; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); netbuffer->packettype = PT_CLIENTCMD; - if (cl_packetmissed) - { - netbuffer->packettype = PT_CLIENTMIS; - mis = true; - } - netbuffer->u.clientpak.resendfrom = (UINT8)(neededtic & UINT8_MAX); netbuffer->u.clientpak.client_tic = (UINT8)(gametic & UINT8_MAX); if (gamestate == GS_WAITINGPLAYERS) { // Send PT_NODEKEEPALIVE packet - netbuffer->packettype = (mis ? PT_NODEKEEPALIVEMIS : PT_NODEKEEPALIVE); + netbuffer->packettype = PT_NODEKEEPALIVE; packetsize = sizeof (clientcmd_pak) - sizeof (ticcmd_t) - sizeof (INT16); HSendPacket(servernode, false, 0, packetsize); } @@ -6404,19 +6386,19 @@ static void CL_SendClientCmd(void) if (splitscreen || botingame) // Send a special packet with 2 cmd for splitscreen { - netbuffer->packettype = (mis ? PT_CLIENT2MIS : PT_CLIENT2CMD); + netbuffer->packettype = PT_CLIENT2CMD; packetsize = sizeof (client2cmd_pak); G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds[1][lagDelay], 1); if (splitscreen > 1) { - netbuffer->packettype = (mis ? PT_CLIENT3MIS : PT_CLIENT3CMD); + netbuffer->packettype = PT_CLIENT3CMD; packetsize = sizeof (client3cmd_pak); G_MoveTiccmd(&netbuffer->u.client3pak.cmd3, &localcmds[2][lagDelay], 1); if (splitscreen > 2) { - netbuffer->packettype = (mis ? PT_CLIENT4MIS : PT_CLIENT4CMD); + netbuffer->packettype = PT_CLIENT4CMD; packetsize = sizeof (client4cmd_pak); G_MoveTiccmd(&netbuffer->u.client4pak.cmd4, &localcmds[3][lagDelay], 1); } @@ -6471,14 +6453,13 @@ static void SV_SendTics(void) // send to all client but not to me // for each node create a packet with x tics and send it - // x is computed using supposedtics[n], max packet size and maketic + // x is computed using nettics[n], max packet size and maketic for (n = 1; n < MAXNETNODES; n++) { if (!nodeingame[n]) continue; - // assert supposedtics[n]>=nettics[n] - realfirsttic = supposedtics[n]; + realfirsttic = nettics[n]; lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS); if (realfirsttic >= lasttictosend) @@ -6487,8 +6468,8 @@ static void SV_SendTics(void) // to resent packet that are supposed lost (this is necessary since lost // packet detection work when we have received packet with firsttic > neededtic // (getpacket servertics case) - DEBFILE(va("Nothing to send node %u mak=%u sup=%u net=%u \n", - n, lasttictosend, supposedtics[n], nettics[n])); + DEBFILE(va("Nothing to send node %u mak=%u net=%u \n", + n, lasttictosend, nettics[n])); realfirsttic = nettics[n]; if (realfirsttic >= lasttictosend || (I_GetTime() + n)&3) // all tic are ok @@ -6568,17 +6549,10 @@ static void SV_SendTics(void) packsize = bufpos - (UINT8 *)&(netbuffer->u); HSendPacket(n, false, 0, packsize); - - // when tic are too large, only one tic is sent so don't go backward! - if (lasttictosend-doomcom->extratics > realfirsttic) - supposedtics[n] = lasttictosend-doomcom->extratics; - else - supposedtics[n] = lasttictosend; - - supposedtics[n] = max(supposedtics[n], nettics[n]); } + // node 0 is me! - supposedtics[0] = maketic; + nettics[0] = maketic; } // diff --git a/src/d_net.c b/src/d_net.c index fd8fb0e31..3e0d4410c 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -863,11 +863,12 @@ static void DebugPrintpacket(const char *header) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: + case PT_NODEKEEPALIVE: + // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: - case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: fprintf(debugfile, " tic %4u resendfrom %u\n", (UINT32)netbuffer->u.clientpak.client_tic, -- 2.54.0 From 08864e27b2de8382ca7530feedc37e7f5783d3e5 Mon Sep 17 00:00:00 2001 From: PAS Date: Tue, 23 Dec 2025 17:17:32 -0500 Subject: [PATCH 10/47] Fix double byte-swap in SV_MakeTic --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ef78fe91a..729a8f698 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -6626,7 +6626,7 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) // create missed tic static void SV_Maketic(void) { - G_MoveTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS); + G_CopyTiccmd(netcmds[maketic % BACKUPTICS], playercmds, MAXPLAYERS); maketic++; } -- 2.54.0 From 39a46e8f79ed4032b78b058817bf010e4923c6f3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Dec 2025 01:09:14 +0100 Subject: [PATCH 11/47] Revert "Remove tic provision (vanilla compat edition)" This reverts commit 4a3c9ccfbb81f8c11d92213be6c0ffdfd08abbdd. --- src/d_clisrv.c | 54 +++++++++++++++++++++++++++++++++++++------------- src/d_net.c | 3 +-- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 729a8f698..5125a6c7b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -159,6 +159,7 @@ boolean nodeingame[MAXNETNODES] = {}; // set false as nodes leave game tic_t servermaxping = 20; // server's max delay, in frames. Defaults to 20 static tic_t nettics[MAXNETNODES]; // what tic the client have received +static tic_t supposedtics[MAXNETNODES]; // nettics prevision for smaller packet static UINT8 nodewaiting[MAXNETNODES]; static tic_t firstticstosend; // min of the nettics static tic_t tictoclear = 0; // optimize d_clearticcmd @@ -185,6 +186,7 @@ boolean hu_stopped = false; // Client specific static ticcmd_t localcmds[MAXSPLITSCREENPLAYERS][MAXGENTLEMENDELAY]; +static boolean cl_packetmissed; // here it is for the secondary local player (splitscreen) static UINT8 mynode; // my address pointofview server @@ -4294,6 +4296,7 @@ static void ResetNode(INT32 node) playerpernode[node] = 0; nettics[node] = gametic; + supposedtics[node] = gametic; sendingsavegame[node] = false; @@ -4348,7 +4351,7 @@ void SV_ResetServer(void) ClearAdminPlayers(); mynode = 0; - + cl_packetmissed = false; #ifdef SATURNPAK cl_redownloadinggamestate = false; #endif @@ -4450,7 +4453,7 @@ void D_QuitNetGame(void) static inline void SV_AddNode(INT32 node) { nettics[node] = gametic; - + supposedtics[node] = gametic; // little hack because the server connects to itself and puts // nodeingame when connected not here if (node) @@ -5532,6 +5535,14 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) realstart = ExpandTics(netbuffer->u.clientpak.client_tic, nettics[node]); realend = ExpandTics(netbuffer->u.clientpak.resendfrom, nettics[node]); + if (netbuffer->packettype == PT_CLIENTMIS || netbuffer->packettype == PT_CLIENT2MIS + || netbuffer->packettype == PT_CLIENT3MIS || netbuffer->packettype == PT_CLIENT4MIS + || netbuffer->packettype == PT_NODEKEEPALIVEMIS + || supposedtics[node] < realend) + { + supposedtics[node] = realend; + } + // Discard out of order packet if (nettics[node] > realend) { @@ -5883,6 +5894,7 @@ static void PT_ServerTics(SINT8 node) if (realend > gametic + CLIENTBACKUPTICS) realend = gametic + CLIENTBACKUPTICS; + cl_packetmissed = realstart > neededtic; UINT8 *pak = (UINT8 *)&packet->cmds; UINT8 *txtpak = (UINT8 *)&packet->cmds[packet->numslots * packet->numtics]; @@ -6015,12 +6027,11 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: - case PT_NODEKEEPALIVE: - // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: + case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: PT_ClientCmd(netconsole, node); break; @@ -6312,18 +6323,25 @@ static void SV_SendServerKeepAlive(void) static void CL_SendClientCmd(void) { size_t packetsize = 0; + boolean mis = false; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); netbuffer->packettype = PT_CLIENTCMD; + if (cl_packetmissed) + { + netbuffer->packettype = PT_CLIENTMIS; + mis = true; + } + netbuffer->u.clientpak.resendfrom = (UINT8)(neededtic & UINT8_MAX); netbuffer->u.clientpak.client_tic = (UINT8)(gametic & UINT8_MAX); if (gamestate == GS_WAITINGPLAYERS) { // Send PT_NODEKEEPALIVE packet - netbuffer->packettype = PT_NODEKEEPALIVE; + netbuffer->packettype = (mis ? PT_NODEKEEPALIVEMIS : PT_NODEKEEPALIVE); packetsize = sizeof (clientcmd_pak) - sizeof (ticcmd_t) - sizeof (INT16); HSendPacket(servernode, false, 0, packetsize); } @@ -6386,19 +6404,19 @@ static void CL_SendClientCmd(void) if (splitscreen || botingame) // Send a special packet with 2 cmd for splitscreen { - netbuffer->packettype = PT_CLIENT2CMD; + netbuffer->packettype = (mis ? PT_CLIENT2MIS : PT_CLIENT2CMD); packetsize = sizeof (client2cmd_pak); G_MoveTiccmd(&netbuffer->u.client2pak.cmd2, &localcmds[1][lagDelay], 1); if (splitscreen > 1) { - netbuffer->packettype = PT_CLIENT3CMD; + netbuffer->packettype = (mis ? PT_CLIENT3MIS : PT_CLIENT3CMD); packetsize = sizeof (client3cmd_pak); G_MoveTiccmd(&netbuffer->u.client3pak.cmd3, &localcmds[2][lagDelay], 1); if (splitscreen > 2) { - netbuffer->packettype = PT_CLIENT4CMD; + netbuffer->packettype = (mis ? PT_CLIENT4MIS : PT_CLIENT4CMD); packetsize = sizeof (client4cmd_pak); G_MoveTiccmd(&netbuffer->u.client4pak.cmd4, &localcmds[3][lagDelay], 1); } @@ -6453,13 +6471,14 @@ static void SV_SendTics(void) // send to all client but not to me // for each node create a packet with x tics and send it - // x is computed using nettics[n], max packet size and maketic + // x is computed using supposedtics[n], max packet size and maketic for (n = 1; n < MAXNETNODES; n++) { if (!nodeingame[n]) continue; - realfirsttic = nettics[n]; + // assert supposedtics[n]>=nettics[n] + realfirsttic = supposedtics[n]; lasttictosend = min(maketic, nettics[n] + CLIENTBACKUPTICS); if (realfirsttic >= lasttictosend) @@ -6468,8 +6487,8 @@ static void SV_SendTics(void) // to resent packet that are supposed lost (this is necessary since lost // packet detection work when we have received packet with firsttic > neededtic // (getpacket servertics case) - DEBFILE(va("Nothing to send node %u mak=%u net=%u \n", - n, lasttictosend, nettics[n])); + DEBFILE(va("Nothing to send node %u mak=%u sup=%u net=%u \n", + n, lasttictosend, supposedtics[n], nettics[n])); realfirsttic = nettics[n]; if (realfirsttic >= lasttictosend || (I_GetTime() + n)&3) // all tic are ok @@ -6549,10 +6568,17 @@ static void SV_SendTics(void) packsize = bufpos - (UINT8 *)&(netbuffer->u); HSendPacket(n, false, 0, packsize); - } + // when tic are too large, only one tic is sent so don't go backward! + if (lasttictosend-doomcom->extratics > realfirsttic) + supposedtics[n] = lasttictosend-doomcom->extratics; + else + supposedtics[n] = lasttictosend; + + supposedtics[n] = max(supposedtics[n], nettics[n]); + } // node 0 is me! - nettics[0] = maketic; + supposedtics[0] = maketic; } // diff --git a/src/d_net.c b/src/d_net.c index 3e0d4410c..fd8fb0e31 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -863,12 +863,11 @@ static void DebugPrintpacket(const char *header) case PT_CLIENT2CMD: case PT_CLIENT3CMD: case PT_CLIENT4CMD: - case PT_NODEKEEPALIVE: - // "mis" tics kept for vanilla compat case PT_CLIENTMIS: case PT_CLIENT2MIS: case PT_CLIENT3MIS: case PT_CLIENT4MIS: + case PT_NODEKEEPALIVE: case PT_NODEKEEPALIVEMIS: fprintf(debugfile, " tic %4u resendfrom %u\n", (UINT32)netbuffer->u.clientpak.client_tic, -- 2.54.0 From 5184115216790614e9953e0268a5563034051446 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:33:43 +0100 Subject: [PATCH 12/47] enable "Wzero-as-null-pointer-constant", fix cases of it prevent ambiguity and bad practices, i like expressive and "correct" code shoutout blankart for making me aware this exists --- src/Makefile.d/versions.mk | 2 +- src/blua/lstrlib.c | 2 +- src/blua/luaconf.h | 6 +++--- src/d_clisrv.c | 14 +++++++------- src/d_main.c | 3 ++- src/d_netcmd.c | 14 +++++++------- src/f_finale.c | 2 +- src/g_demo.c | 2 +- src/g_game.c | 14 +++++++------- src/hardware/hw_batching.c | 2 +- src/hardware/hw_md2load.c | 28 ++++++++++++++-------------- src/hardware/hw_md3load.c | 24 ++++++++++++------------ src/hardware/hw_model.c | 18 +++++++++--------- src/hardware/r_opengl/r_opengl.c | 12 ++++++------ src/http-mserv.c | 8 ++++---- src/lua_mobjlib.c | 2 +- src/m_cheat.c | 8 ++++---- src/m_cond.c | 2 +- src/m_menu.c | 8 ++++---- src/m_perfstats.c | 18 +++++++++--------- src/p_enemy.c | 8 ++++---- src/p_mobj.c | 24 ++++++++++++------------ src/p_setup.c | 4 ++-- src/p_spec.c | 6 +++--- src/r_main.cpp | 2 +- src/r_skins.c | 2 +- src/r_things.cpp | 4 ++-- src/s_sound.c | 6 +++--- src/s_sound.h | 4 ++-- src/strcasestr.c | 8 ++++---- src/w_wad.c | 18 +++++++++--------- src/y_inter.c | 8 ++++---- 32 files changed, 142 insertions(+), 141 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 2a80cfa39..e57119fb9 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference -Wzero-as-null-pointer-constant ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/blua/lstrlib.c b/src/blua/lstrlib.c index e2fd23604..6fe279bcb 100644 --- a/src/blua/lstrlib.c +++ b/src/blua/lstrlib.c @@ -527,7 +527,7 @@ static int str_find_aux (lua_State *L, int find) { if (find) { lua_pushinteger(L, s1-s+1); /* start */ lua_pushinteger(L, res-s); /* end */ - return push_captures(&ms, NULL, 0) + 2; + return push_captures(&ms, NULL, NULL) + 2; } else return push_captures(&ms, s1, res); diff --git a/src/blua/luaconf.h b/src/blua/luaconf.h index 76a798751..22fa8bf53 100644 --- a/src/blua/luaconf.h +++ b/src/blua/luaconf.h @@ -772,10 +772,10 @@ union luai_Cast { double l_d; long l_l; }; #include #if defined(__GNUC__) -#define l_likely(x) (__builtin_expect(((x) != 0), 1)) -#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#define l_likely(x) (__builtin_expect(!!(x), 1)) +#define l_unlikely(x) (__builtin_expect(!!(x), 0)) #else -#define l_likely(x) (x) +#define l_likely(x) (x) #define l_unlikely(x) (x) #endif diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d4983daa2..68ab08c5a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -332,7 +332,7 @@ void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(const UINT8 **p, INT32 playernu #ifdef PARANOIA if (id >= MAXNETXCMD) I_Error("Command id %d too big", id); - if (listnetxcmd[id] != 0) + if (listnetxcmd[id] != NULL) I_Error("Command id %d already used", id); #endif listnetxcmd[id] = cmd_f; @@ -1236,7 +1236,7 @@ static void CL_DrawConnectionStatus(void) va(" %4uK/%4uK", currentsize>>10, totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - va("%3.1fK/s ", ((double)getbps)/1024)); + va("%3.1fK/s ", ((double)getbps)/1024.0)); } else cltext = M_GetText("Waiting to download game state..."); @@ -1963,7 +1963,7 @@ static boolean SV_ResendingSavegameToAnyone(void) static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; - savebuffer_t save = {0}; + savebuffer_t save = {}; UINT8 *compressedsave; UINT8 *buffertosend; @@ -2033,7 +2033,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O static void SV_SavedGame(void) { size_t length; - savebuffer_t save = {0}; + savebuffer_t save = {}; char tmpsave[264]; if (!cv_dumpconsistency.value) @@ -2073,7 +2073,7 @@ static void SV_SavedGame(void) static void CL_LoadReceivedSavegame(boolean reloading) { - savebuffer_t save = {0}; + savebuffer_t save = {}; size_t length, decompressedlen; char tmpsave[264]; @@ -7237,7 +7237,7 @@ void CL_ClearRewinds(void) rewind_t *CL_SaveRewindPoint(size_t demopos) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) @@ -7260,7 +7260,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) rewind_t *CL_RewindToTime(tic_t time) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; while (rewindhead && rewindhead->leveltime > time) diff --git a/src/d_main.c b/src/d_main.c index ab5fe7a10..3e474cec3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1865,7 +1865,8 @@ void D_SRB2Main(void) if (M_CheckParm("-warp") && M_IsNextParm()) { const char *word = M_GetNextParm(); - pstartmap = G_FindMapByNameOrCode(word, 0); + pstartmap = G_FindMapByNameOrCode(word, NULL); + if (! pstartmap) I_Error("Cannot find a map remotely named '%s'\n", word); else diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c669da59b..781120be2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -249,7 +249,7 @@ consvar_t cv_competitionboxes = {"competitionboxes", "Random", CV_NETVAR|CV_CHEA #ifdef SEENAMES static CV_PossibleValue_t seenames_cons_t[] = {{0, "Off"}, {1, "Colorless"}, {2, "Team"}, {3, "Ally/Foe"}, {0, NULL}}; -consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowseenames = {"allowseenames", "No", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif @@ -458,16 +458,16 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; -consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; @@ -2789,7 +2789,7 @@ static void Command_Map_f(void) // G_TOLFlag handles both multiplayer gametype and ignores it for !multiplayer else { - if (!mapheaderinfo[newmapnum-1]) + if (mapheaderinfo[newmapnum-1] == NULL) { CONS_Alert(CONS_WARNING, M_GetText("Invalid mapheaderinfo for Course %s (%s)\n"), realmapname, G_BuildMapName(newmapnum)); return; diff --git a/src/f_finale.c b/src/f_finale.c index 801af8ab5..32ed8c3ec 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1318,7 +1318,7 @@ boolean F_ContinueResponder(event_t *event) keypressed = true; imcontinuing = true; continuetime = TICRATE; - S_StartSound(0, sfx_itemup); + S_StartSound(NULL, sfx_itemup); return true; } diff --git a/src/g_demo.c b/src/g_demo.c index 312e57530..ede5adf18 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -76,7 +76,7 @@ static tic_t demostarttime; // for comparative timing purposes //@TODO put these all in a struct for namespacing purposes? static char demoname[128]; -savebuffer_t demobuf = {0}; +savebuffer_t demobuf = {}; static UINT8 *demotime_p, *demoinfo_p; static UINT8 *demoend; static UINT8 demoflags; diff --git a/src/g_game.c b/src/g_game.c index 892579163..27a2922a8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3501,7 +3501,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; //For records tic_t rectime; @@ -3634,7 +3634,7 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; (void)force; char backupfile[MAX_WADPATH+4]; @@ -3805,7 +3805,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; - savebuffer_t save = {0}; + savebuffer_t save = {}; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -3891,7 +3891,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; - savebuffer_t save = {0}; + savebuffer_t save = {}; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -4161,7 +4161,7 @@ static void measurekeywords(mapsearchfreq_t *fr, PU_STATIC, NULL); for (qp = strtok(va("%s", q), " "); qp && fr->total < 255; - qp = strtok(0, " ")) + qp = strtok(NULL, " ")) { if (( sp = strcasestr(s, qp) )) { @@ -4242,7 +4242,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { newmapnum = mapnum; newmapname = realmapname; - realmapname = 0; + realmapname = NULL; Z_Free(apromapname); if (!wanttable) break; @@ -4263,7 +4263,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { apromapnum = mapnum; apromapname = realmapname; - realmapname = 0; + realmapname = NULL; } } else/* ...match individual keywords */ diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 4d6b1ea6e..8bf7f7375 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -391,7 +391,7 @@ void HWR_RenderBatches(void) nextSurfaceInfo = nextEntry->surf; if (nextPolyFlags & PF_NoTexture) - nextTexture = 0; + nextTexture = NULL; if (useshader && currentShader != nextShader) { diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 3805deffb..d28ebf058 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -274,7 +274,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); //size_t fileLen; @@ -288,13 +288,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { texPos++; namelen = strlen(texPos) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, texPos); } else { namelen = strlen(fileName) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, fileName); } @@ -316,7 +316,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) header = (md2header_t*)buffer; retModel->numMeshes = 1; // MD2 only has one mesh - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, NULL); retModel->meshes[0].numFrames = header->numFrames; // const float WUNITS = 1.0f; // float dataScale = WUNITS; @@ -332,7 +332,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); // int t; for (t = 0; t < retModel->numMaterials; t++) @@ -409,9 +409,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) float *uvptr; dataScale = 0.015624f; // 1 / 64.0f - retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); + retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, NULL); retModel->meshes[0].numVertices = header->numXYZ; - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); ptr = (char*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) @@ -423,12 +423,12 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0); - retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0); + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, NULL); + retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); - retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); + retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, NULL); vertptr = retModel->meshes[0].tinyframes[i].vertices; normptr = retModel->meshes[0].tinyframes[i].normals; @@ -484,8 +484,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) char *ptr; retModel->meshes[0].numVertices = header->numTris * 3; - retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, NULL); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); trisPtr = tris; uvptr = retModel->meshes[0].uvs; @@ -507,8 +507,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); - retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); + retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); + retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); //float *vertptr, *normptr; diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 53f6034c0..b536c7e73 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -168,7 +168,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); // find length of file fseek(f, 0, SEEK_END); @@ -201,7 +201,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); for (t = 0; t < retModel->numMaterials; t++) { @@ -225,7 +225,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials[t].spheremap = false; } - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, NULL); matCount = 0; for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) @@ -298,9 +298,9 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) unsigned short *indexptr; md3Triangle *mdT; - retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0); + retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, NULL); retModel->meshes[i].numVertices = mdS->numVerts; - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { short *vertptr; @@ -308,12 +308,12 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // char *tanptr; int k; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0); - retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0); + retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, NULL); + retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag); - retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0); + retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, NULL); vertptr = retModel->meshes[i].tinyframes[j].vertices; normptr = retModel->meshes[i].tinyframes[j].normals; @@ -374,16 +374,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) int k; retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; - retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0); - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, NULL); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { float *vertptr; float *normptr; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); - retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); + retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); // if (retModel->materials[i].lightmap) // retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag); vertptr = retModel->meshes[i].frames[j].vertices; diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 8698365e4..274c23394 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -189,7 +189,7 @@ model_t *LoadModel(const char *filename, int ztag) return NULL; } - model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, 0); + model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, NULL); strcpy(model->mdlFilename, filename); Optimize(model); @@ -237,7 +237,7 @@ void GenerateVertexNormals(model_t *model) { mdlframe_t *frame = &mesh->frames[j]; int memTag = PU_STATIC; - float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0); + float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, NULL); int k; float *vertPtr = frame->vertices; float *oldNormals; @@ -309,7 +309,7 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material) } // Didn't find it, so add to the list - newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); + newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, NULL); newMatNode->material = material; ListAdd(newMatNode, (listitem_t**)head); return true; @@ -351,7 +351,7 @@ void Optimize(model_t *model) } memTag = PU_STATIC; - newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); + newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, NULL); i = 0; for (node = matListHead; node; node = node->next) @@ -377,14 +377,14 @@ void Optimize(model_t *model) newMesh->numFrames = 1; newMesh->numTriangles = numTriangles; newMesh->numVertices = numTriangles * 3; - newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); - newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0); + newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, NULL); + newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, NULL); curFrame = &newMesh->frames[0]; curFrame->material = curMat; - curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, 0); + curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, NULL); // Now traverse the meshes of the model, adding in // vertices/normals/uvs that match the current material diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index edd2f51a7..fab0a8a6d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -98,10 +98,10 @@ static size_t textureBufferSize = 0; static LTListItem *LightTablesTail = NULL; static LTListItem *LightTablesHead = NULL; -static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering +static RGBA_t screenPalette[256] = {}; // the palette for the postprocessing step in palette rendering static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256] = {0}; // the palette for converting textures to RGBA +RGBA_t myPaletteData[256] = {}; // the palette for converting textures to RGBA static GLint gltexformat = GL_RGB5_A1; GLint screen_width = 0; // used by Draw2DLine() @@ -127,9 +127,9 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -GLfloat modelMatrix[16] = {0}; -GLfloat projMatrix[16] = {0}; -static GLint viewport[4]; +GLfloat modelMatrix[16] = {}; +GLfloat projMatrix[16] = {}; +static GLint viewport[4]; #ifdef USE_FBO_OGL enum @@ -171,7 +171,7 @@ boolean supportstencil = false; // flush all of the stored textures, leaving them unavailable at times such as between levels // These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs // can know when the textures aren't there, as textures are always considered resident in their virtual memory -static GLuint screenTextures[NUMSCREENTEXTURES] = {0}; +static GLuint screenTextures[NUMSCREENTEXTURES] = {}; #define byte2float(byte) (GLfloat)(byte / 255.0f) diff --git a/src/http-mserv.c b/src/http-mserv.c index 8e35f905d..fd63c5f69 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -189,7 +189,7 @@ HMS_connect (const char *format, ...) seek = strlen(hms_api) + 1;/* + '/' */ va_start (ap, format); - url = malloc(seek + vsnprintf(0, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); + url = malloc(seek + vsnprintf(NULL, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); va_end (ap); sprintf(url, "%s/", hms_api); @@ -471,8 +471,8 @@ HMS_fetch_servers (msg_server_t *list, int query_id) *end = '\0'; address = strtok(p, " "); - port = strtok(0, " "); - contact = strtok(0, ""); + port = strtok(NULL, " "); + contact = strtok(NULL, ""); if (address && port) { @@ -539,7 +539,7 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size) if (HMS_do(hms)) { version = strtok(hms->buffer, " "); - version_name = strtok(0, "\n"); + version_name = strtok(NULL, "\n"); if (version && version_name) { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 45c3a9f19..9bd5f5203 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -475,7 +475,7 @@ int mobj_localskin_setter(lua_State *L) } else { - mo->localskin = 0; + mo->localskin = NULL; mo->skinlocal = false; } } diff --git a/src/m_cheat.c b/src/m_cheat.c index 2890c7196..58bc1401d 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -80,7 +80,7 @@ static UINT8 cheatf_warp(void) if (success) { G_SaveGameData(true); //G_SetGameModified(false); - S_StartSound(0, sfx_kc42); + S_StartSound(NULL, sfx_kc42); } // Refresh secrets menu existing. @@ -117,13 +117,13 @@ static UINT8 cheatf_devmode(void) #endif static cheatseq_t cheat_warp = { - 0, cheatf_warp, + NULL, cheatf_warp, //{ SCRAMBLE('r'), SCRAMBLE('e'), SCRAMBLE('d'), SCRAMBLE('x'), SCRAMBLE('v'), SCRAMBLE('i'), 0xff } { SCRAMBLE('b'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), 0xff } }; static cheatseq_t cheat_warp_joy = { - 0, cheatf_warp, + NULL, cheatf_warp, /*{ SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), @@ -136,7 +136,7 @@ static cheatseq_t cheat_warp_joy = { #ifdef DEVELOP static cheatseq_t cheat_devmode = { - 0, cheatf_devmode, + NULL, cheatf_devmode, { SCRAMBLE('d'), SCRAMBLE('e'), SCRAMBLE('v'), SCRAMBLE('m'), SCRAMBLE('o'), SCRAMBLE('d'), SCRAMBLE('e'), 0xff } }; #endif diff --git a/src/m_cond.c b/src/m_cond.c index acf78e6ef..126d5a49a 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -235,7 +235,7 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 wnum = conditionSets[set - 1].numconditions; num = ++conditionSets[set - 1].numconditions; - conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, 0); + conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, NULL); cond = conditionSets[set - 1].condition; diff --git a/src/m_menu.c b/src/m_menu.c index c2978fe82..55112356b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5385,7 +5385,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na { CONS_Printf("custom settings menu initiation\n"); for (CVARSETUP = 0; CVARSETUP < MAXMENUCCVARS; ++CVARSETUP) - OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", 0, INT16_MAX}; + OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", NULL, INT16_MAX}; } if (category && ((ccvarposition == 0 && category[0] != '\0') || !fasticmp(category, OP_CustomCvarMenu[ccvarlaststheader].text))) @@ -7494,7 +7494,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if ((lumpnum = W_CheckNumForName(va("%sE", mapname))) != LUMPERROR) mappingforencore = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH);*/ - V_DrawFixedPatch((x+w)<>1), (staty+67)<>1, 0, statlr, flashcol); V_DrawFixedPatch((statx+40+GRIDSTATOFFSET)<>1, 0, statud, flashcol); // bg - V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, 0); + V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, NULL); for (i = 0; i < numskins; i++) // draw the stat dots { @@ -8218,7 +8218,7 @@ static void M_DrawSetupMultiPlayerMenu(void) V_DrawFixedPatch((statx+64)<flags2 & MF2_FRET) { P_SetMobjState(actor, S_BLACKEGG_DESTROYPLAT1); - S_StartSound(0, sfx_s3k53); + S_StartSound(NULL, sfx_s3k53); actor->flags2 &= ~MF2_FRET; return; } @@ -6011,7 +6011,7 @@ void A_Boss7Chase(void *thing) { // Punch him! P_SetMobjState(actor, actor->info->meleestate); - S_StartSound(0, sfx_begrnd); // warning sound + S_StartSound(NULL, sfx_begrnd); // warning sound return; } } @@ -6057,7 +6057,7 @@ void A_Boss7Chase(void *thing) case 2: // Homing Missile A_FaceTarget(actor); P_SetMobjState(actor, actor->info->missilestate); - S_StartSound(0, sfx_beflap); + S_StartSound(NULL, sfx_beflap); break; } @@ -10739,7 +10739,7 @@ void A_BrakChase(void *thing) { actor->reactiontime--; if (actor->reactiontime == 0 && actor->type == MT_CYBRAKDEMON) - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } // modify target threshold diff --git a/src/p_mobj.c b/src/p_mobj.c index ad7982d87..581edf2f0 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3606,10 +3606,10 @@ static void P_CalculatePrecipFloor(precipmobj_t *mobj) // Just the identification of a precip thinker. The thinker // should never actually be called! // -void P_NullPrecipThinker(precipmobj_t *mobj) +FUNCNORETURN void P_NullPrecipThinker(precipmobj_t *mobj) { (void)mobj; - I_Assert("P_NullPrecipThinker should not be called" == 0); + I_Error("P_NullPrecipThinker should not be called"); } boolean P_PrecipThinker(precipmobj_t *mobj) @@ -4012,7 +4012,7 @@ static void P_Boss3Thinker(mobj_t *mobj) if ((UINT32)mobj->extravalue1 + TICRATE*2 < leveltime) { mobj->extravalue1 = (INT32)leveltime; - S_StartSound(0, sfx_buzz1); + S_StartSound(NULL, sfx_buzz1); } // If in the center, check to make sure @@ -4631,7 +4631,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (mobj->health > 0) mobj->health--; - S_StartSound(0, (mobj->health) ? sfx_behurt : sfx_bedie2); + S_StartSound(NULL, (mobj->health) ? sfx_behurt : sfx_bedie2); mobj->reactiontime /= 3; @@ -4670,7 +4670,7 @@ static void P_Boss7Thinker(mobj_t *mobj) INT32 i; mobj->state->nextstate = mobj->info->painstate; // Reset - S_StartSound(0, sfx_bedeen); + S_StartSound(NULL, sfx_bedeen); for (i = 0; i < MAXPLAYERS; i++) { @@ -4694,7 +4694,7 @@ static void P_Boss7Thinker(mobj_t *mobj) mobj->state->nextstate = mobj->info->spawnstate; // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } } } @@ -4714,7 +4714,7 @@ static void P_Boss7Thinker(mobj_t *mobj) var2 = 2*TICRATE + (80<<16); A_LobShot(mobj); - S_StartSound(0, sfx_begoop); + S_StartSound(NULL, sfx_begoop); } } else if (mobj->state == &states[S_BLACKEGG_SHOOT2]) @@ -4738,7 +4738,7 @@ static void P_Boss7Thinker(mobj_t *mobj) S_StopSound(missile); if (leveltime & 1) - S_StartSound(0, sfx_beshot); + S_StartSound(NULL, sfx_beshot); } else if (mobj->state == &states[S_BLACKEGG_JUMP1] && mobj->tics == 1) { @@ -4871,7 +4871,7 @@ static void P_Boss7Thinker(mobj_t *mobj) fixed_t x,y,z; mobj_t *mo2; - S_StartSound(0, sfx_befall); + S_StartSound(NULL, sfx_befall); z = mobj->floorz; for (j = 0; j < 2; j++) @@ -4910,13 +4910,13 @@ static void P_Boss7Thinker(mobj_t *mobj) P_DamageMobj(players[i].mo, mobj, mobj, 1); // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } P_SetMobjState(mobj, mobj->info->spawnstate); } else if (mobj->state == &states[mobj->info->deathstate] && mobj->tics == mobj->state->tics) - S_StartSound(0, sfx_bedie1 + (P_RandomFixed() & 1)); + S_StartSound(NULL, sfx_bedie1 + (P_RandomFixed() & 1)); } // Metal Sonic battle boss @@ -10711,7 +10711,7 @@ void P_SpawnPlayer(INT32 playernum) // the dead body mobj retains the skin through the 'spritedef' override). mobj->skin = &skins[p->skin]; - mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : 0); + mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : NULL); mobj->skinlocal = p->skinlocal; mobj->health = p->health; diff --git a/src/p_setup.c b/src/p_setup.c index bf40afe9d..612530882 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1022,7 +1022,7 @@ void P_WriteThings(lumpnum_t lumpnum) size_t i, length; mapthing_t *mt; UINT8 *data; - savebuffer_t save = {0}; + savebuffer_t save = {}; INT16 temp; data = W_CacheLumpNum(lumpnum, PU_LEVEL); @@ -1166,7 +1166,7 @@ static void P_LoadLineDefs2(void) for (; i--; ld++) { ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here - ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; + ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : NULL; // Repeat count for midtexture if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != 0xffff)) diff --git a/src/p_spec.c b/src/p_spec.c index 66901d234..5045a8287 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4579,8 +4579,8 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) if (!sec->ffloors) { sec->ffloors = ffloor; - ffloor->next = 0; - ffloor->prev = 0; + ffloor->next = NULL; + ffloor->prev = NULL; return; } @@ -4588,7 +4588,7 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) rover->next = ffloor; ffloor->prev = rover; - ffloor->next = 0; + ffloor->next = NULL; } /** Adds a 3Dfloor. diff --git a/src/r_main.cpp b/src/r_main.cpp index fecfba580..e3bfb83fa 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1087,7 +1087,7 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) ret = &subsectors[nodenum & ~NF_SUBSECTOR]; for (i = 0; i < ret->numlines; i++) if (P_PointOnLineSide(x, y, segs[ret->firstline + i].linedef) != segs[ret->firstline + i].side) - return 0; + return NULL; return ret; } diff --git a/src/r_skins.c b/src/r_skins.c index 538b8c38a..41971788c 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -302,7 +302,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (player->mo) { - player->mo->localskin = 0; + player->mo->localskin = NULL; player->mo->skinlocal = false; } } diff --git a/src/r_things.cpp b/src/r_things.cpp index cab9512e3..77b02b78c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -532,8 +532,8 @@ void R_ClearSprites(void) visspritecount = numvisiblesprites = clippedvissprites = 0; } -static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; -static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; +static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; +static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; static void R_AllocVisSpriteChunkMemory(UINT32 chunk) { diff --git a/src/s_sound.c b/src/s_sound.c index e8075469c..7f931671d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -884,7 +884,7 @@ static void S_StopChannel(INT32 cnum) if (cnum != i && c->sfxinfo == channels[i].sfxinfo) break; - c->sfxinfo = 0; + c->sfxinfo = NULL; } c->origin = NULL; @@ -1271,7 +1271,7 @@ static musicdef_t *S_AddMusicCredit(void) return &musicdefs[chunk][i]; } -struct cursongcredit cursongcredit = {0}; // Currently displayed song credit info +struct cursongcredit cursongcredit = {}; // Currently displayed song credit info static boolean ReadMusicDefFields(UINT16 wadnum, int line, char *stoken, musicdef_t **defp) { @@ -1704,7 +1704,7 @@ static void S_UnloadMusic(void) music.flags = 0; music.looping = false; - music_refade_cv = 0; + music_refade_cv = NULL; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) diff --git a/src/s_sound.h b/src/s_sound.h index 9e0296d2b..c7f487e92 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -253,9 +253,9 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 void S_ChangeMusicSpecial (const char *mmusic); -void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); +void S_SetRestoreMusicFadeInCvar(consvar_t *cvar); #define S_ClearRestoreMusicFadeInCvar() \ - S_SetRestoreMusicFadeInCvar(0) + S_SetRestoreMusicFadeInCvar(NULL) int S_GetRestoreMusicFadeIn (void); // Stops the music. diff --git a/src/strcasestr.c b/src/strcasestr.c index d24a36e54..f50141dcf 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -73,8 +73,8 @@ nongnu_strcasestr (const char *s, const char *q) up = strchr(s, uc); lp = strchr(s, lc); - if (!( (intptr_t)up|(intptr_t)lp )) - return 0; + if (up == NULL || lp == NULL) + return NULL; if (!lp || ( up && up < lp )) { @@ -100,12 +100,12 @@ nongnu_strcasestr (const char *s, const char *q) if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); - if (!( (intptr_t)up|(intptr_t)lp )) + if (up == NULL || lp == NULL) break; if (!(*ppa) || ( (*ppb) && (*ppb) < (*ppa) )) swapp(&ppa, &ppb, &cpa, &cpb); } - return 0; + return NULL; } diff --git a/src/w_wad.c b/src/w_wad.c index 7e1ec30df..432f1421f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -697,12 +697,12 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -1667,9 +1667,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si if (fread(rawData, 1, rawSize, handle) < rawSize) I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; + strm.zalloc = NULL; + strm.zfree = NULL; + strm.opaque = NULL; strm.total_in = strm.avail_in = rawSize; strm.total_out = strm.avail_out = decSize; @@ -2238,14 +2238,14 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -2483,14 +2483,14 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? diff --git a/src/y_inter.c b/src/y_inter.c index d35fa7825..27e794ffc 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -104,7 +104,7 @@ typedef struct } y_voteclient; // votescreen stuff -votescreen_t VoteScreen = {0}; +votescreen_t VoteScreen = {}; static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; @@ -1093,7 +1093,7 @@ void Y_VoteDrawer(void) V_DrawSmallScaledPatch(BASEVIDWIDTH-100, y, V_SNAPTORIGHT, pic); else { - V_DrawFixedPatch((BASEVIDWIDTH-20)< Date: Thu, 8 Jan 2026 00:27:06 +0100 Subject: [PATCH 13/47] K_SpawnSparkleTrail: check for blend effect apply outside the loop tiny optimization --- src/k_kart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index bb4da62a5..342414738 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3595,6 +3595,8 @@ void K_SpawnSparkleTrail(mobj_t *mo) I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); + const boolean shouldblend = (mo->player && K_PlayerEffectsShouldBlend(mo->player)); + for (i = 0; i < 3; i++) { fixed_t newx = mo->x + mo->momx + (P_RandomRange(-rad, rad)<color = mo->color; - if (mo->player && K_PlayerEffectsShouldBlend(mo->player)) + if (shouldblend) sparkle->blendmode = AST_ADD; } -- 2.54.0 From e923777eb67df6d889c8196e496f722b7c44ed20 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:26:02 +0100 Subject: [PATCH 14/47] Acessability: add basic "reducevfx" toggle to disable/reduce certain effects toggles certain effects, which may be troublesome to some players -disabled hyudoro flashing, instead makes player translucent - Makes rainbow colour effects, such as invul, change colours very slowly - Disables underwater and heatwave screen effects - Disables palette flashing - Disables vhs effect not the most pretty implementation, but im lazy and this works feel free to suggest more things --- src/g_game.h | 1 + src/hardware/hw_main.cpp | 24 ++++- src/hardware/hw_md2.c | 11 ++- src/k_kart.c | 11 ++- src/p_mobj.c | 3 +- src/r_things.cpp | 11 ++- src/v_video.c | 197 ++++++++++++++++++++------------------- 7 files changed, 150 insertions(+), 108 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index 509749c5f..6ecc69dfa 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -130,6 +130,7 @@ extern consvar_t cv_spinoutroll; extern consvar_t cv_squishdance, cv_squishdancespeed; extern consvar_t cv_playerblendeffects; +extern consvar_t cv_reducevfx; extern consvar_t cv_cechotoggle; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 70a5a3a8d..1622a4528 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3786,8 +3786,15 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && sprmo->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + if (sprmo->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && sprmo->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + } if (HWR_UseShader()) { @@ -4076,8 +4083,15 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && sprmo->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + if (sprmo->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && sprmo->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + } if (HWR_UseShader()) { @@ -6100,7 +6114,7 @@ static void HWR_DoPostProcessor(void) const camera_t *thiscam = &camera[0]; // Not supported in splitscreen - someone want to add support? - const boolean screenwave = (!splitscreen && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); + const boolean screenwave = (!splitscreen && !cv_reducevfx.value && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); // Capture the screen for intermission and screen waving if ((lastdraw || screenwave) && gamestate != GS_INTERMISSION) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 763fb873c..e45a56cda 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1198,8 +1198,15 @@ void HWR_DrawMD2(gl_vissprite_t *spr) Surf.PolyFlags = HWR_GetBlendModeFlag(blendmode); } - if (cv_playerfade.value && spr->mobj->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + if (spr->mobj->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && spr->mobj->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + } // dont forget to enabled the depth test because we can't do this like // before: polygons models are not sorted diff --git a/src/k_kart.c b/src/k_kart.c index 342414738..59271a1e4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -47,6 +47,8 @@ consvar_t cv_airsparks = {"airdriftsparks", "Off", CV_SAVE, CV_OnOff, NULL, 0, N consvar_t cv_playerblendeffects = {"playerblendeffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_reducevfx = {"reducevfx", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // funn-E streeetch static CV_PossibleValue_t stretchfactor_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}}; consvar_t cv_gravstretch = {"gravstretch", "MIN", CV_SAVE|CV_FLOAT, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -482,7 +484,8 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { // UINT8 K_RainbowColor(void) { - return (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))); + const INT32 time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; + return (UINT8)(1 + (time % (MAXSKINCOLORS-1))); } // Define for getting accurate color brightness readings according to how the human eye sees them. @@ -764,6 +767,8 @@ void K_RegisterClientKartStuff(void) CV_RegisterVar(&cv_playerblendeffects); + CV_RegisterVar(&cv_reducevfx); + CV_RegisterVar(&cv_saltyhop); CV_RegisterVar(&cv_saltyhopsfx); CV_RegisterVar(&cv_saltysquish); @@ -6768,7 +6773,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) { if (splitscreen) { - if (leveltime & 1) + if (!cv_reducevfx.value && leveltime & 1) player->mo->flags2 |= MF2_DONTDRAW; else player->mo->flags2 &= ~MF2_DONTDRAW; @@ -6794,7 +6799,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if (P_IsDisplayPlayer(player) || (!P_IsDisplayPlayer(player) && (player->kartstuff[k_hyudorotimer] < (1*TICRATE/2) || player->kartstuff[k_hyudorotimer] > hyudorotime-(1*TICRATE/2)))) { - if (leveltime & 1) + if (!cv_reducevfx.value && leveltime & 1) player->mo->flags2 |= MF2_DONTDRAW; else player->mo->flags2 &= ~MF2_DONTDRAW; diff --git a/src/p_mobj.c b/src/p_mobj.c index 581edf2f0..d1b8b850a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12354,8 +12354,9 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai // void P_FlashPal(player_t *pl, UINT16 type, UINT16 duration) { - if (!pl) + if (!pl || cv_reducevfx.value) // no palette flashing with reducevfx return; + pl->flashcount = duration; pl->flashpal = type; } diff --git a/src/r_things.cpp b/src/r_things.cpp index 77b02b78c..d1c856238 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1588,8 +1588,15 @@ static void R_ProjectSprite(mobj_t *thing) else trans = 0; - if (cv_playerfade.value && thing->player) - trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(thing), static_cast(trans))); + if (thing->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && thing->player->kartstuff[k_hyudorotimer] > 0) + trans = static_cast(R_GetThingTransTable(FRACUNIT/2, static_cast(trans))); + + if (cv_playerfade.value) + trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(thing), static_cast(trans))); + } //SoM: 3/17/2000: Disregard sprites that are out of view.. if (vflip) diff --git a/src/v_video.c b/src/v_video.c index ac85715ef..bb118d269 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -15,6 +15,7 @@ #include "doomdef.h" #include "d_main.h" +#include "g_game.h" #include "r_local.h" #include "p_local.h" #include "v_video.h" @@ -1755,6 +1756,9 @@ void V_DrawVhsEffect(boolean rewind) #endif SINT8 offs; + if (cv_reducevfx.value) + return; + barsize = vid.dup << 5; updistort = vid.dup << (rewind ? 5 : 3); downdistort = updistort >> 1; @@ -3639,127 +3643,130 @@ void V_DoPostProcessor(INT32 view, INT32 param) UINT8 *tmpscr = vid.screens[4]; UINT8 *srcscr = vid.screens[0]; - if (thiscam->postimg & POSTIMG_WATER) + if (!cv_reducevfx.value) { - INT32 y; - // Set disStart to a range from 0 to FINEANGLE, incrementing by 128 per tic - angle_t disStart = (((leveltime-1)*128) + (R_GetTimeFrac(RTF_LEVEL) / (FRACUNIT/128))) & FINEMASK; - INT32 newpix; - INT32 sine; - //UINT8 *transme = transtables + ((tr_trans50-1)<postimg & POSTIMG_WATER) { - sine = (FINESINE(disStart)*5)>>FRACBITS; - newpix = abs(sine); + INT32 y; + // Set disStart to a range from 0 to FINEANGLE, incrementing by 128 per tic + angle_t disStart = (((leveltime-1)*128) + (R_GetTimeFrac(RTF_LEVEL) / (FRACUNIT/128))) & FINEMASK; + INT32 newpix; + INT32 sine; + //UINT8 *transme = transtables + ((tr_trans50-1)<>FRACBITS; + newpix = abs(sine); - // Cleanup edge - while (newpix) + if (sine < 0) { - tmpscr[(y*vid.width)+xoffset+newpix] = srcscr[(y*vid.width)+xoffset]; - newpix--; - } - } - else - { - memcpy(&tmpscr[(y*vid.width)+xoffset+0], &srcscr[(y*vid.width)+xoffset+sine], viewwidth-newpix); + memcpy(&tmpscr[(y*vid.width)+xoffset+newpix], &srcscr[(y*vid.width)+xoffset], viewwidth-newpix); - // Cleanup edge - while (newpix) + // Cleanup edge + while (newpix) + { + tmpscr[(y*vid.width)+xoffset+newpix] = srcscr[(y*vid.width)+xoffset]; + newpix--; + } + } + else { - tmpscr[(y*vid.width)+xoffset+viewwidth-newpix] = srcscr[(y*vid.width)+xoffset+(viewwidth-1)]; - newpix--; + memcpy(&tmpscr[(y*vid.width)+xoffset+0], &srcscr[(y*vid.width)+xoffset+sine], viewwidth-newpix); + + // Cleanup edge + while (newpix) + { + tmpscr[(y*vid.width)+xoffset+viewwidth-newpix] = srcscr[(y*vid.width)+xoffset+(viewwidth-1)]; + newpix--; + } } + + /* + Unoptimized version + for (x = 0; x < vid.width; x++) + { + newpix = (x + sine); + + if (newpix < 0) + newpix = 0; + else if (newpix >= vid.width) + newpix = vid.width-1; + + tmpscr[y*vid.width + x] = srcscr[y*vid.width+newpix]; // *(transme + (srcscr[y*vid.width+x]<<8) + srcscr[y*vid.width+newpix]); + }*/ + + disStart += 22;//the offset into the displacement map, increment each game loop + disStart &= FINEMASK; //clip it to FINEMASK } - /* - Unoptimized version - for (x = 0; x < vid.width; x++) - { - newpix = (x + sine); - - if (newpix < 0) - newpix = 0; - else if (newpix >= vid.width) - newpix = vid.width-1; - - tmpscr[y*vid.width + x] = srcscr[y*vid.width+newpix]; // *(transme + (srcscr[y*vid.width+x]<<8) + srcscr[y*vid.width+newpix]); - }*/ - - disStart += 22;//the offset into the displacement map, increment each game loop - disStart &= FINEMASK; //clip it to FINEMASK + UINT8 *tmp = tmpscr; + tmpscr = srcscr; + srcscr = tmp; } - - UINT8 *tmp = tmpscr; - tmpscr = srcscr; - srcscr = tmp; - } - else if (thiscam->postimg & POSTIMG_HEAT) // Heat wave - { - INT32 y; - - // Make sure table is built - if (heatshifter == NULL || lastheight != viewheight) + else if (thiscam->postimg & POSTIMG_HEAT) // Heat wave { - if (heatshifter) - Z_Free(heatshifter); + INT32 y; - heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); - - for (y = 0; y < viewheight; y++) + // Make sure table is built + if (heatshifter == NULL || lastheight != viewheight) { - if (M_RandomChance(FRACUNIT/8)) // 12.5% - heatshifter[y] = true; + if (heatshifter) + Z_Free(heatshifter); + + heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); + + for (y = 0; y < viewheight; y++) + { + if (M_RandomChance(FRACUNIT/8)) // 12.5% + heatshifter[y] = true; + } + + heatindex[0] = heatindex[1] = heatindex[2] = heatindex[3] = 0; + lastheight = viewheight; } - heatindex[0] = heatindex[1] = heatindex[2] = heatindex[3] = 0; - lastheight = viewheight; - } - - for (y = yoffset; y < yoffset+viewheight; y++) - { - if (heatshifter[heatindex[view]++]) + for (y = yoffset; y < yoffset+viewheight; y++) { - // Shift this row of pixels to the right by 2 - tmpscr[(y*vid.width)+xoffset] = srcscr[(y*vid.width)+xoffset]; - memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dup], viewwidth-vid.dup); + if (heatshifter[heatindex[view]++]) + { + // Shift this row of pixels to the right by 2 + tmpscr[(y*vid.width)+xoffset] = srcscr[(y*vid.width)+xoffset]; + memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dup], viewwidth-vid.dup); + } + else + memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset], viewwidth); + + heatindex[view] %= viewheight; } - else - memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset], viewwidth); - heatindex[view] %= viewheight; + if (renderisnewtic) // This isn't interpolated... but how do you interpolate a one-pixel shift? + { + heatindex[view]++; + heatindex[view] %= vid.height; + } + + UINT8 *tmp = tmpscr; + tmpscr = srcscr; + srcscr = tmp; } - if (renderisnewtic) // This isn't interpolated... but how do you interpolate a one-pixel shift? - { - heatindex[view]++; - heatindex[view] %= vid.height; - } - - UINT8 *tmp = tmpscr; - tmpscr = srcscr; - srcscr = tmp; - } - #ifdef MOTIONBLUR - if (thiscam->postimg & POSTIMG_MOTION) // Motion Blur! - { - INT32 x, y; - - // TODO: Add a postimg_param so that we can pick the translucency level... - UINT8 *transme = transtables + ((param-1)<postimg & POSTIMG_MOTION) // Motion Blur! { - for (x = xoffset; x < xoffset+viewwidth; x++) - tmpscr[y*vid.width + x] = colormaps[*(transme + (srcscr [(y*vid.width)+x ] <<8) + (tmpscr[(y*vid.width)+x]))]; + INT32 x, y; + + // TODO: Add a postimg_param so that we can pick the translucency level... + UINT8 *transme = transtables + ((param-1)<postimg & POSTIMG_FLIP) && !(thiscam->postimg & POSTIMG_MIRROR)) // Flip the screen upside-down { -- 2.54.0 From 3bf3bdf641add15d06adc37eeae47fca47c1e29b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:33:06 +0100 Subject: [PATCH 15/47] enable "Wzero-as-null-pointer-constant", fix cases of it prevent ambiguity and bad practices, i like expressive and "correct" code shoutout blankart for making me aware this exists --- src/Makefile.d/versions.mk | 2 +- src/blua/lstrlib.c | 2 +- src/blua/luaconf.h | 6 +++--- src/d_clisrv.c | 18 +++++++++--------- src/d_main.c | 3 ++- src/d_netcmd.c | 14 +++++++------- src/f_finale.c | 2 +- src/g_demo.c | 2 +- src/g_game.c | 14 +++++++------- src/hardware/hw_batching.c | 2 +- src/hardware/hw_md2load.c | 28 ++++++++++++++-------------- src/hardware/hw_md3load.c | 24 ++++++++++++------------ src/hardware/hw_model.c | 18 +++++++++--------- src/hardware/r_opengl/r_opengl.c | 12 ++++++------ src/http-mserv.c | 8 ++++---- src/lua_mobjlib.c | 2 +- src/m_cheat.c | 8 ++++---- src/m_cond.c | 2 +- src/m_menu.c | 8 ++++---- src/m_perfstats.c | 18 +++++++++--------- src/p_enemy.c | 8 ++++---- src/p_mobj.c | 24 ++++++++++++------------ src/p_setup.c | 4 ++-- src/p_spec.c | 6 +++--- src/r_main.cpp | 2 +- src/r_skins.c | 2 +- src/r_things.cpp | 4 ++-- src/s_sound.c | 6 +++--- src/s_sound.h | 4 ++-- src/strcasestr.c | 8 ++++---- src/w_wad.c | 18 +++++++++--------- src/y_inter.c | 8 ++++---- 32 files changed, 144 insertions(+), 143 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 2a80cfa39..e57119fb9 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference -Wzero-as-null-pointer-constant ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/blua/lstrlib.c b/src/blua/lstrlib.c index e2fd23604..6fe279bcb 100644 --- a/src/blua/lstrlib.c +++ b/src/blua/lstrlib.c @@ -527,7 +527,7 @@ static int str_find_aux (lua_State *L, int find) { if (find) { lua_pushinteger(L, s1-s+1); /* start */ lua_pushinteger(L, res-s); /* end */ - return push_captures(&ms, NULL, 0) + 2; + return push_captures(&ms, NULL, NULL) + 2; } else return push_captures(&ms, s1, res); diff --git a/src/blua/luaconf.h b/src/blua/luaconf.h index 76a798751..22fa8bf53 100644 --- a/src/blua/luaconf.h +++ b/src/blua/luaconf.h @@ -772,10 +772,10 @@ union luai_Cast { double l_d; long l_l; }; #include #if defined(__GNUC__) -#define l_likely(x) (__builtin_expect(((x) != 0), 1)) -#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#define l_likely(x) (__builtin_expect(!!(x), 1)) +#define l_unlikely(x) (__builtin_expect(!!(x), 0)) #else -#define l_likely(x) (x) +#define l_likely(x) (x) #define l_unlikely(x) (x) #endif diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5125a6c7b..50d9a322f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -332,7 +332,7 @@ void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(const UINT8 **p, INT32 playernu #ifdef PARANOIA if (id >= MAXNETXCMD) I_Error("Command id %d too big", id); - if (listnetxcmd[id] != 0) + if (listnetxcmd[id] != NULL) I_Error("Command id %d already used", id); #endif listnetxcmd[id] = cmd_f; @@ -1234,7 +1234,7 @@ static inline void CL_DrawConnectionStatus(void) va(" %4uK/%4uK",currentsize>>10,totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - va("%3.1fK/s ", ((double)getbps)/1024)); + va("%3.1fK/s ", ((double)getbps)/1024.0)); } else cltext = M_GetText("Waiting to download game state..."); @@ -1956,7 +1956,7 @@ static boolean SV_ResendingSavegameToAnyone(void) static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; - savebuffer_t save = {0}; + savebuffer_t save = {}; UINT8 *compressedsave; UINT8 *buffertosend; @@ -2026,7 +2026,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O static void SV_SavedGame(void) { size_t length; - savebuffer_t save = {0}; + savebuffer_t save = {}; char tmpsave[264]; if (!cv_dumpconsistency.value) @@ -2066,7 +2066,7 @@ static void SV_SavedGame(void) static void CL_LoadReceivedSavegame(boolean reloading) { - savebuffer_t save = {0}; + savebuffer_t save = {}; size_t length, decompressedlen; char tmpsave[264]; @@ -4933,8 +4933,6 @@ static void PT_ClientJoin(SINT8 node) if (client || nodeingame[node] || levelloading) return; - doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); - const char *refuse = GetRefuseMessage(node); if (refuse) @@ -4943,6 +4941,8 @@ static void PT_ClientJoin(SINT8 node) return; } + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); + // client authorised to join nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); @@ -7288,7 +7288,7 @@ void CL_ClearRewinds(void) rewind_t *CL_SaveRewindPoint(size_t demopos) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) @@ -7311,7 +7311,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) rewind_t *CL_RewindToTime(tic_t time) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; while (rewindhead && rewindhead->leveltime > time) diff --git a/src/d_main.c b/src/d_main.c index c46ef0c44..486ca5b07 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1869,7 +1869,8 @@ void D_SRB2Main(void) if (M_CheckParm("-warp") && M_IsNextParm()) { const char *word = M_GetNextParm(); - pstartmap = G_FindMapByNameOrCode(word, 0); + pstartmap = G_FindMapByNameOrCode(word, NULL); + if (! pstartmap) I_Error("Cannot find a map remotely named '%s'\n", word); else diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b579e6848..e9f814857 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -249,7 +249,7 @@ consvar_t cv_competitionboxes = {"competitionboxes", "Random", CV_NETVAR|CV_CHEA #ifdef SEENAMES static CV_PossibleValue_t seenames_cons_t[] = {{0, "Off"}, {1, "Colorless"}, {2, "Team"}, {3, "Ally/Foe"}, {0, NULL}}; -consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowseenames = {"allowseenames", "No", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif @@ -458,16 +458,16 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; -consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; @@ -2447,7 +2447,7 @@ static void Command_Map_f(void) // G_TOLFlag handles both multiplayer gametype and ignores it for !multiplayer else { - if (!mapheaderinfo[newmapnum-1]) + if (mapheaderinfo[newmapnum-1] == NULL) { CONS_Alert(CONS_WARNING, M_GetText("Invalid mapheaderinfo for Course %s (%s)\n"), realmapname, G_BuildMapName(newmapnum)); return; diff --git a/src/f_finale.c b/src/f_finale.c index 801af8ab5..32ed8c3ec 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1318,7 +1318,7 @@ boolean F_ContinueResponder(event_t *event) keypressed = true; imcontinuing = true; continuetime = TICRATE; - S_StartSound(0, sfx_itemup); + S_StartSound(NULL, sfx_itemup); return true; } diff --git a/src/g_demo.c b/src/g_demo.c index 312e57530..ede5adf18 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -76,7 +76,7 @@ static tic_t demostarttime; // for comparative timing purposes //@TODO put these all in a struct for namespacing purposes? static char demoname[128]; -savebuffer_t demobuf = {0}; +savebuffer_t demobuf = {}; static UINT8 *demotime_p, *demoinfo_p; static UINT8 *demoend; static UINT8 demoflags; diff --git a/src/g_game.c b/src/g_game.c index c304c2e6f..64328da06 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3498,7 +3498,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; //For records tic_t rectime; @@ -3631,7 +3631,7 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; (void)force; char backupfile[MAX_WADPATH+4]; @@ -3802,7 +3802,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; - savebuffer_t save = {0}; + savebuffer_t save = {}; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -3888,7 +3888,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; - savebuffer_t save = {0}; + savebuffer_t save = {}; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -4158,7 +4158,7 @@ static void measurekeywords(mapsearchfreq_t *fr, PU_STATIC, NULL); for (qp = strtok(va("%s", q), " "); qp && fr->total < 255; - qp = strtok(0, " ")) + qp = strtok(NULL, " ")) { if (( sp = strcasestr(s, qp) )) { @@ -4239,7 +4239,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { newmapnum = mapnum; newmapname = realmapname; - realmapname = 0; + realmapname = NULL; Z_Free(apromapname); if (!wanttable) break; @@ -4260,7 +4260,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { apromapnum = mapnum; apromapname = realmapname; - realmapname = 0; + realmapname = NULL; } } else/* ...match individual keywords */ diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 4d6b1ea6e..8bf7f7375 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -391,7 +391,7 @@ void HWR_RenderBatches(void) nextSurfaceInfo = nextEntry->surf; if (nextPolyFlags & PF_NoTexture) - nextTexture = 0; + nextTexture = NULL; if (useshader && currentShader != nextShader) { diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 3805deffb..d28ebf058 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -274,7 +274,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); //size_t fileLen; @@ -288,13 +288,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { texPos++; namelen = strlen(texPos) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, texPos); } else { namelen = strlen(fileName) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, fileName); } @@ -316,7 +316,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) header = (md2header_t*)buffer; retModel->numMeshes = 1; // MD2 only has one mesh - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, NULL); retModel->meshes[0].numFrames = header->numFrames; // const float WUNITS = 1.0f; // float dataScale = WUNITS; @@ -332,7 +332,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); // int t; for (t = 0; t < retModel->numMaterials; t++) @@ -409,9 +409,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) float *uvptr; dataScale = 0.015624f; // 1 / 64.0f - retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); + retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, NULL); retModel->meshes[0].numVertices = header->numXYZ; - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); ptr = (char*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) @@ -423,12 +423,12 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0); - retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0); + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, NULL); + retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); - retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); + retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, NULL); vertptr = retModel->meshes[0].tinyframes[i].vertices; normptr = retModel->meshes[0].tinyframes[i].normals; @@ -484,8 +484,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) char *ptr; retModel->meshes[0].numVertices = header->numTris * 3; - retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, NULL); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); trisPtr = tris; uvptr = retModel->meshes[0].uvs; @@ -507,8 +507,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); - retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); + retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); + retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); //float *vertptr, *normptr; diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 53f6034c0..b536c7e73 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -168,7 +168,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); // find length of file fseek(f, 0, SEEK_END); @@ -201,7 +201,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); for (t = 0; t < retModel->numMaterials; t++) { @@ -225,7 +225,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials[t].spheremap = false; } - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, NULL); matCount = 0; for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) @@ -298,9 +298,9 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) unsigned short *indexptr; md3Triangle *mdT; - retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0); + retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, NULL); retModel->meshes[i].numVertices = mdS->numVerts; - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { short *vertptr; @@ -308,12 +308,12 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // char *tanptr; int k; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0); - retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0); + retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, NULL); + retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag); - retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0); + retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, NULL); vertptr = retModel->meshes[i].tinyframes[j].vertices; normptr = retModel->meshes[i].tinyframes[j].normals; @@ -374,16 +374,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) int k; retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; - retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0); - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, NULL); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { float *vertptr; float *normptr; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); - retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); + retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); // if (retModel->materials[i].lightmap) // retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag); vertptr = retModel->meshes[i].frames[j].vertices; diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 8698365e4..274c23394 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -189,7 +189,7 @@ model_t *LoadModel(const char *filename, int ztag) return NULL; } - model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, 0); + model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, NULL); strcpy(model->mdlFilename, filename); Optimize(model); @@ -237,7 +237,7 @@ void GenerateVertexNormals(model_t *model) { mdlframe_t *frame = &mesh->frames[j]; int memTag = PU_STATIC; - float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0); + float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, NULL); int k; float *vertPtr = frame->vertices; float *oldNormals; @@ -309,7 +309,7 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material) } // Didn't find it, so add to the list - newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); + newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, NULL); newMatNode->material = material; ListAdd(newMatNode, (listitem_t**)head); return true; @@ -351,7 +351,7 @@ void Optimize(model_t *model) } memTag = PU_STATIC; - newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); + newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, NULL); i = 0; for (node = matListHead; node; node = node->next) @@ -377,14 +377,14 @@ void Optimize(model_t *model) newMesh->numFrames = 1; newMesh->numTriangles = numTriangles; newMesh->numVertices = numTriangles * 3; - newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); - newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0); + newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, NULL); + newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, NULL); curFrame = &newMesh->frames[0]; curFrame->material = curMat; - curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, 0); + curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, NULL); // Now traverse the meshes of the model, adding in // vertices/normals/uvs that match the current material diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 94656e843..86d1f5faa 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -98,10 +98,10 @@ static size_t textureBufferSize = 0; static LTListItem *LightTablesTail = NULL; static LTListItem *LightTablesHead = NULL; -static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering +static RGBA_t screenPalette[256] = {}; // the palette for the postprocessing step in palette rendering static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256] = {0}; // the palette for converting textures to RGBA +RGBA_t myPaletteData[256] = {}; // the palette for converting textures to RGBA static GLint gltexformat = GL_RGB5_A1; GLint screen_width = 0; // used by Draw2DLine() @@ -127,9 +127,9 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -GLfloat modelMatrix[16] = {0}; -GLfloat projMatrix[16] = {0}; -static GLint viewport[4]; +GLfloat modelMatrix[16] = {}; +GLfloat projMatrix[16] = {}; +static GLint viewport[4]; #ifdef USE_FBO_OGL enum @@ -171,7 +171,7 @@ boolean supportstencil = false; // flush all of the stored textures, leaving them unavailable at times such as between levels // These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs // can know when the textures aren't there, as textures are always considered resident in their virtual memory -static GLuint screenTextures[NUMSCREENTEXTURES] = {0}; +static GLuint screenTextures[NUMSCREENTEXTURES] = {}; #define byte2float(byte) (GLfloat)(byte / 255.0f) diff --git a/src/http-mserv.c b/src/http-mserv.c index 8e35f905d..fd63c5f69 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -189,7 +189,7 @@ HMS_connect (const char *format, ...) seek = strlen(hms_api) + 1;/* + '/' */ va_start (ap, format); - url = malloc(seek + vsnprintf(0, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); + url = malloc(seek + vsnprintf(NULL, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); va_end (ap); sprintf(url, "%s/", hms_api); @@ -471,8 +471,8 @@ HMS_fetch_servers (msg_server_t *list, int query_id) *end = '\0'; address = strtok(p, " "); - port = strtok(0, " "); - contact = strtok(0, ""); + port = strtok(NULL, " "); + contact = strtok(NULL, ""); if (address && port) { @@ -539,7 +539,7 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size) if (HMS_do(hms)) { version = strtok(hms->buffer, " "); - version_name = strtok(0, "\n"); + version_name = strtok(NULL, "\n"); if (version && version_name) { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 45c3a9f19..9bd5f5203 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -475,7 +475,7 @@ int mobj_localskin_setter(lua_State *L) } else { - mo->localskin = 0; + mo->localskin = NULL; mo->skinlocal = false; } } diff --git a/src/m_cheat.c b/src/m_cheat.c index 2890c7196..58bc1401d 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -80,7 +80,7 @@ static UINT8 cheatf_warp(void) if (success) { G_SaveGameData(true); //G_SetGameModified(false); - S_StartSound(0, sfx_kc42); + S_StartSound(NULL, sfx_kc42); } // Refresh secrets menu existing. @@ -117,13 +117,13 @@ static UINT8 cheatf_devmode(void) #endif static cheatseq_t cheat_warp = { - 0, cheatf_warp, + NULL, cheatf_warp, //{ SCRAMBLE('r'), SCRAMBLE('e'), SCRAMBLE('d'), SCRAMBLE('x'), SCRAMBLE('v'), SCRAMBLE('i'), 0xff } { SCRAMBLE('b'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), 0xff } }; static cheatseq_t cheat_warp_joy = { - 0, cheatf_warp, + NULL, cheatf_warp, /*{ SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), @@ -136,7 +136,7 @@ static cheatseq_t cheat_warp_joy = { #ifdef DEVELOP static cheatseq_t cheat_devmode = { - 0, cheatf_devmode, + NULL, cheatf_devmode, { SCRAMBLE('d'), SCRAMBLE('e'), SCRAMBLE('v'), SCRAMBLE('m'), SCRAMBLE('o'), SCRAMBLE('d'), SCRAMBLE('e'), 0xff } }; #endif diff --git a/src/m_cond.c b/src/m_cond.c index acf78e6ef..126d5a49a 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -235,7 +235,7 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 wnum = conditionSets[set - 1].numconditions; num = ++conditionSets[set - 1].numconditions; - conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, 0); + conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, NULL); cond = conditionSets[set - 1].condition; diff --git a/src/m_menu.c b/src/m_menu.c index c2978fe82..55112356b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5385,7 +5385,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na { CONS_Printf("custom settings menu initiation\n"); for (CVARSETUP = 0; CVARSETUP < MAXMENUCCVARS; ++CVARSETUP) - OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", 0, INT16_MAX}; + OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", NULL, INT16_MAX}; } if (category && ((ccvarposition == 0 && category[0] != '\0') || !fasticmp(category, OP_CustomCvarMenu[ccvarlaststheader].text))) @@ -7494,7 +7494,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if ((lumpnum = W_CheckNumForName(va("%sE", mapname))) != LUMPERROR) mappingforencore = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH);*/ - V_DrawFixedPatch((x+w)<>1), (staty+67)<>1, 0, statlr, flashcol); V_DrawFixedPatch((statx+40+GRIDSTATOFFSET)<>1, 0, statud, flashcol); // bg - V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, 0); + V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, NULL); for (i = 0; i < numskins; i++) // draw the stat dots { @@ -8218,7 +8218,7 @@ static void M_DrawSetupMultiPlayerMenu(void) V_DrawFixedPatch((statx+64)<flags2 & MF2_FRET) { P_SetMobjState(actor, S_BLACKEGG_DESTROYPLAT1); - S_StartSound(0, sfx_s3k53); + S_StartSound(NULL, sfx_s3k53); actor->flags2 &= ~MF2_FRET; return; } @@ -6011,7 +6011,7 @@ void A_Boss7Chase(void *thing) { // Punch him! P_SetMobjState(actor, actor->info->meleestate); - S_StartSound(0, sfx_begrnd); // warning sound + S_StartSound(NULL, sfx_begrnd); // warning sound return; } } @@ -6057,7 +6057,7 @@ void A_Boss7Chase(void *thing) case 2: // Homing Missile A_FaceTarget(actor); P_SetMobjState(actor, actor->info->missilestate); - S_StartSound(0, sfx_beflap); + S_StartSound(NULL, sfx_beflap); break; } @@ -10739,7 +10739,7 @@ void A_BrakChase(void *thing) { actor->reactiontime--; if (actor->reactiontime == 0 && actor->type == MT_CYBRAKDEMON) - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } // modify target threshold diff --git a/src/p_mobj.c b/src/p_mobj.c index ad7982d87..581edf2f0 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3606,10 +3606,10 @@ static void P_CalculatePrecipFloor(precipmobj_t *mobj) // Just the identification of a precip thinker. The thinker // should never actually be called! // -void P_NullPrecipThinker(precipmobj_t *mobj) +FUNCNORETURN void P_NullPrecipThinker(precipmobj_t *mobj) { (void)mobj; - I_Assert("P_NullPrecipThinker should not be called" == 0); + I_Error("P_NullPrecipThinker should not be called"); } boolean P_PrecipThinker(precipmobj_t *mobj) @@ -4012,7 +4012,7 @@ static void P_Boss3Thinker(mobj_t *mobj) if ((UINT32)mobj->extravalue1 + TICRATE*2 < leveltime) { mobj->extravalue1 = (INT32)leveltime; - S_StartSound(0, sfx_buzz1); + S_StartSound(NULL, sfx_buzz1); } // If in the center, check to make sure @@ -4631,7 +4631,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (mobj->health > 0) mobj->health--; - S_StartSound(0, (mobj->health) ? sfx_behurt : sfx_bedie2); + S_StartSound(NULL, (mobj->health) ? sfx_behurt : sfx_bedie2); mobj->reactiontime /= 3; @@ -4670,7 +4670,7 @@ static void P_Boss7Thinker(mobj_t *mobj) INT32 i; mobj->state->nextstate = mobj->info->painstate; // Reset - S_StartSound(0, sfx_bedeen); + S_StartSound(NULL, sfx_bedeen); for (i = 0; i < MAXPLAYERS; i++) { @@ -4694,7 +4694,7 @@ static void P_Boss7Thinker(mobj_t *mobj) mobj->state->nextstate = mobj->info->spawnstate; // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } } } @@ -4714,7 +4714,7 @@ static void P_Boss7Thinker(mobj_t *mobj) var2 = 2*TICRATE + (80<<16); A_LobShot(mobj); - S_StartSound(0, sfx_begoop); + S_StartSound(NULL, sfx_begoop); } } else if (mobj->state == &states[S_BLACKEGG_SHOOT2]) @@ -4738,7 +4738,7 @@ static void P_Boss7Thinker(mobj_t *mobj) S_StopSound(missile); if (leveltime & 1) - S_StartSound(0, sfx_beshot); + S_StartSound(NULL, sfx_beshot); } else if (mobj->state == &states[S_BLACKEGG_JUMP1] && mobj->tics == 1) { @@ -4871,7 +4871,7 @@ static void P_Boss7Thinker(mobj_t *mobj) fixed_t x,y,z; mobj_t *mo2; - S_StartSound(0, sfx_befall); + S_StartSound(NULL, sfx_befall); z = mobj->floorz; for (j = 0; j < 2; j++) @@ -4910,13 +4910,13 @@ static void P_Boss7Thinker(mobj_t *mobj) P_DamageMobj(players[i].mo, mobj, mobj, 1); // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } P_SetMobjState(mobj, mobj->info->spawnstate); } else if (mobj->state == &states[mobj->info->deathstate] && mobj->tics == mobj->state->tics) - S_StartSound(0, sfx_bedie1 + (P_RandomFixed() & 1)); + S_StartSound(NULL, sfx_bedie1 + (P_RandomFixed() & 1)); } // Metal Sonic battle boss @@ -10711,7 +10711,7 @@ void P_SpawnPlayer(INT32 playernum) // the dead body mobj retains the skin through the 'spritedef' override). mobj->skin = &skins[p->skin]; - mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : 0); + mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : NULL); mobj->skinlocal = p->skinlocal; mobj->health = p->health; diff --git a/src/p_setup.c b/src/p_setup.c index bf40afe9d..612530882 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1022,7 +1022,7 @@ void P_WriteThings(lumpnum_t lumpnum) size_t i, length; mapthing_t *mt; UINT8 *data; - savebuffer_t save = {0}; + savebuffer_t save = {}; INT16 temp; data = W_CacheLumpNum(lumpnum, PU_LEVEL); @@ -1166,7 +1166,7 @@ static void P_LoadLineDefs2(void) for (; i--; ld++) { ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here - ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; + ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : NULL; // Repeat count for midtexture if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != 0xffff)) diff --git a/src/p_spec.c b/src/p_spec.c index 66901d234..5045a8287 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4579,8 +4579,8 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) if (!sec->ffloors) { sec->ffloors = ffloor; - ffloor->next = 0; - ffloor->prev = 0; + ffloor->next = NULL; + ffloor->prev = NULL; return; } @@ -4588,7 +4588,7 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) rover->next = ffloor; ffloor->prev = rover; - ffloor->next = 0; + ffloor->next = NULL; } /** Adds a 3Dfloor. diff --git a/src/r_main.cpp b/src/r_main.cpp index 493105929..e470e5b5d 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1087,7 +1087,7 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) ret = &subsectors[nodenum & ~NF_SUBSECTOR]; for (i = 0; i < ret->numlines; i++) if (P_PointOnLineSide(x, y, segs[ret->firstline + i].linedef) != segs[ret->firstline + i].side) - return 0; + return NULL; return ret; } diff --git a/src/r_skins.c b/src/r_skins.c index 538b8c38a..41971788c 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -302,7 +302,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (player->mo) { - player->mo->localskin = 0; + player->mo->localskin = NULL; player->mo->skinlocal = false; } } diff --git a/src/r_things.cpp b/src/r_things.cpp index b62d9e5d7..f9e159843 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -532,8 +532,8 @@ void R_ClearSprites(void) visspritecount = numvisiblesprites = clippedvissprites = 0; } -static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; -static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; +static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; +static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; static void R_AllocVisSpriteChunkMemory(UINT32 chunk) { diff --git a/src/s_sound.c b/src/s_sound.c index e8075469c..7f931671d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -884,7 +884,7 @@ static void S_StopChannel(INT32 cnum) if (cnum != i && c->sfxinfo == channels[i].sfxinfo) break; - c->sfxinfo = 0; + c->sfxinfo = NULL; } c->origin = NULL; @@ -1271,7 +1271,7 @@ static musicdef_t *S_AddMusicCredit(void) return &musicdefs[chunk][i]; } -struct cursongcredit cursongcredit = {0}; // Currently displayed song credit info +struct cursongcredit cursongcredit = {}; // Currently displayed song credit info static boolean ReadMusicDefFields(UINT16 wadnum, int line, char *stoken, musicdef_t **defp) { @@ -1704,7 +1704,7 @@ static void S_UnloadMusic(void) music.flags = 0; music.looping = false; - music_refade_cv = 0; + music_refade_cv = NULL; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) diff --git a/src/s_sound.h b/src/s_sound.h index 9e0296d2b..c7f487e92 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -253,9 +253,9 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 void S_ChangeMusicSpecial (const char *mmusic); -void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); +void S_SetRestoreMusicFadeInCvar(consvar_t *cvar); #define S_ClearRestoreMusicFadeInCvar() \ - S_SetRestoreMusicFadeInCvar(0) + S_SetRestoreMusicFadeInCvar(NULL) int S_GetRestoreMusicFadeIn (void); // Stops the music. diff --git a/src/strcasestr.c b/src/strcasestr.c index d24a36e54..f50141dcf 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -73,8 +73,8 @@ nongnu_strcasestr (const char *s, const char *q) up = strchr(s, uc); lp = strchr(s, lc); - if (!( (intptr_t)up|(intptr_t)lp )) - return 0; + if (up == NULL || lp == NULL) + return NULL; if (!lp || ( up && up < lp )) { @@ -100,12 +100,12 @@ nongnu_strcasestr (const char *s, const char *q) if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); - if (!( (intptr_t)up|(intptr_t)lp )) + if (up == NULL || lp == NULL) break; if (!(*ppa) || ( (*ppb) && (*ppb) < (*ppa) )) swapp(&ppa, &ppb, &cpa, &cpb); } - return 0; + return NULL; } diff --git a/src/w_wad.c b/src/w_wad.c index 7e1ec30df..432f1421f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -697,12 +697,12 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -1667,9 +1667,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si if (fread(rawData, 1, rawSize, handle) < rawSize) I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; + strm.zalloc = NULL; + strm.zfree = NULL; + strm.opaque = NULL; strm.total_in = strm.avail_in = rawSize; strm.total_out = strm.avail_out = decSize; @@ -2238,14 +2238,14 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -2483,14 +2483,14 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? diff --git a/src/y_inter.c b/src/y_inter.c index d35fa7825..27e794ffc 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -104,7 +104,7 @@ typedef struct } y_voteclient; // votescreen stuff -votescreen_t VoteScreen = {0}; +votescreen_t VoteScreen = {}; static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; @@ -1093,7 +1093,7 @@ void Y_VoteDrawer(void) V_DrawSmallScaledPatch(BASEVIDWIDTH-100, y, V_SNAPTORIGHT, pic); else { - V_DrawFixedPatch((BASEVIDWIDTH-20)< Date: Tue, 6 Jan 2026 12:54:25 +0100 Subject: [PATCH 16/47] Simplify textcmd handling --- src/d_clisrv.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 4da62742f..1ec57eaaf 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -212,14 +212,9 @@ tic_t firstconnectattempttime = 0; // engine -// Must be a power of two -#define TEXTCMD_HASH_SIZE 4 - typedef struct textcmdtic_s { - tic_t tic; UINT8 *playercmds[MAXPLAYERS]; - struct textcmdtic_s *next; } textcmdtic_t; typedef struct textcmdbuf_s textcmdbuf_t; @@ -234,7 +229,7 @@ static textcmdbuf_t *textcmdbuf[MAXSPLITSCREENPLAYERS] = {NULL}; static ticcmd_t playercmds[MAXPLAYERS]; ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS] = {}; -static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; +static textcmdtic_t *textcmds[BACKUPTICS] = {NULL}; consvar_t cv_showjoinaddress = {"showjoinaddress", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -396,20 +391,10 @@ void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_ // Frees all textcmd memory for the specified tic static void D_FreeTextcmd(tic_t tic) { - textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - textcmdtic_t *textcmdtic = *tctprev; - - while (textcmdtic && textcmdtic->tic != tic) - { - tctprev = &textcmdtic->next; - textcmdtic = textcmdtic->next; - } + textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS]; if (textcmdtic) { - // Remove this tic from the list. - *tctprev = textcmdtic->next; - // Free all players. for (INT32 i = 0; i < MAXPLAYERS; i++) { @@ -418,14 +403,14 @@ static void D_FreeTextcmd(tic_t tic) // Free this tic's own memory. Z_Free(textcmdtic); + textcmds[tic%BACKUPTICS] = NULL; } } // Gets the buffer for the specified ticcmd, or NULL if there isn't one static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) { - textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - while (textcmdtic && textcmdtic->tic != tic) textcmdtic = textcmdtic->next; + textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS]; // Do we have an entry for the tic? If so, look for player. if (textcmdtic) @@ -441,22 +426,11 @@ static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) // Gets the buffer for the specified ticcmd, creating one if necessary static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) { - textcmdtic_t *textcmdtic = textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - textcmdtic_t **tctprev = &textcmds[tic & (TEXTCMD_HASH_SIZE - 1)]; - - // Look for the tic. - while (textcmdtic && textcmdtic->tic != tic) - { - tctprev = &textcmdtic->next; - textcmdtic = textcmdtic->next; - } + textcmdtic_t *textcmdtic = textcmds[tic%BACKUPTICS]; // If we don't have an entry for the tic, make it. if (!textcmdtic) - { - textcmdtic = *tctprev = (textcmdtic_t*)Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL); - textcmdtic->tic = tic; - } + textcmds[tic%BACKUPTICS] = textcmdtic = (textcmdtic_t*)Z_Calloc(sizeof(textcmdtic_t), PU_STATIC, NULL); // If we don't have an entry for the player, make it. if (!textcmdtic->playercmds[playernum]) @@ -540,9 +514,8 @@ void D_ResetTiccmds(void) } // Reset the net command list - for (i = 0; i < TEXTCMD_HASH_SIZE; i++) - while (textcmds[i]) - D_Clearticcmd(textcmds[i]->tic); + for (i = 0; i < BACKUPTICS; i++) + D_Clearticcmd(i); } void SendKick(UINT8 playernum, UINT8 msg) -- 2.54.0 From cd02242a014cbb21366ab65352d01d3dedf3a012 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:01:14 +0100 Subject: [PATCH 17/47] fix splitscreen clients being unable to join saturn servers lmao oops idk dumb copy paste sry --- src/d_clisrv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1ec57eaaf..27206b337 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4121,7 +4121,7 @@ static void Command_ResendGamestate(void) } playernum = nametonum(COM_Argv(1)); - if (playernum == -1 || playernum == 0) + if (playernum <= 0) return; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -4591,7 +4591,7 @@ static boolean SV_AddWaitingPlayers(SINT8 node) for (n = 0; n < MAXNETNODES; n++) { - if (nodetoplayer[n] == newplayernum || + if (nodetoplayer[n] == newplayernum || nodetoplayer2[n] == newplayernum || nodetoplayer3[n] == newplayernum || nodetoplayer4[n] == newplayernum) @@ -4883,10 +4883,6 @@ static const char *GetRefuseMessage(SINT8 node) { return va("Maximum players reached: %d", maxplayers); } - else if (cc->localplayers != 1) - { - return "Wrong player count."; - } else if (netgame && !cc->localplayers) // Stealth join? { return "No players from\nthis node."; -- 2.54.0 From fdccf868cc388614df67b4d6c9be483f768a808f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:09:21 +0100 Subject: [PATCH 18/47] disable player fade if viewplayer is spectator fixes some wonky stuff like players disappearing when they were close to the invisible spectator player and you werent watching someone else --- src/r_things.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 60b0bbd52..9da1f4c3e 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2960,7 +2960,7 @@ fixed_t R_DoPlayerFade(mobj_t *thing) fixed_t fadealpha = FRACUNIT; static constexpr tic_t countdownstarttime = (15 * TICRATE) / 4; // starttime - (3*TICRATE) - if (thing->player == viewplayer || viewplayer->exiting || camera[R_GetViewNumber()].freecam || leveltime < countdownstarttime) + if (thing->player == viewplayer || viewplayer->exiting || viewplayer->spectator || camera[R_GetViewNumber()].freecam || leveltime < countdownstarttime) return fadealpha; const INT32 playerdist = (FixedMul((thing->x - viewx), viewcos) + FixedMul((thing->y - viewy), viewsin)) >> FRACBITS; -- 2.54.0 From 1265bbba2efd8352512d527838c6f6803edf40c5 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 23 Feb 2026 19:12:42 +0300 Subject: [PATCH 19/47] Rename I_LockMutex back into I_lock_mutex for now --- src/console.c | 4 ++-- src/m_menu.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/console.c b/src/console.c index 09ac2e36d..7276b59c8 100644 --- a/src/console.c +++ b/src/console.c @@ -50,8 +50,8 @@ I_mutex con_mutex; // to avoid infinite SIGABRT recursion in the signal handler // due to poisoned locks or mach-o kernel not supporting locks in signals // or something like that. idk -# define Lock_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&con_mutex); } -# define Unlock_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(con_mutex); } +# define Lock_state() if (!I_In_Exiting_Signal_Handler()) { I_lock_mutex(&con_mutex); } +# define Unlock_state() if (!I_In_Exiting_Signal_Handler()) { I_unlock_mutex(con_mutex); } #else /*HAVE_THREADS*/ # define Lock_state() # define Unlock_state() diff --git a/src/m_menu.c b/src/m_menu.c index f2b3ac1bb..79879032e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4020,8 +4020,8 @@ I_mutex replayquerymutex; // to avoid infinite SIGABRT recursion in the signal handler // due to poisoned locks or mach-o kernel not supporting locks in signals // or something like that. idk -# define Lock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&replayquerymutex); } -# define Unlock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(replayquerymutex); } +# define Lock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_lock_mutex(&replayquerymutex); } +# define Unlock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_unlock_mutex(replayquerymutex); } #else /*HAVE_THREADS*/ # define Lock_search_state() # define Unlock_search_state() -- 2.54.0 From 4623f8aff2ff16edf4a112230dfed2af95c6e9d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:56:41 +0100 Subject: [PATCH 20/47] explicitly set "std=gnu17" we *rely* on a bunch of gnu extensions so its better to explicitly set this yes in theory we fully comply with c23/gnu23 and saturn compiles fine under that, but since its still fairly new theres alot of maschines that still dont support it :chaosleep: --- src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile b/src/Makefile index 0456990f3..be4f995db 100644 --- a/src/Makefile +++ b/src/Makefile @@ -295,6 +295,7 @@ opts+=$(debug_opts) opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v))) +CWFLAGS+=-std=gnu17 CXXFLAGS+=-std=c++17 # force c17 for c++ since most vpss run older ubuntu versions with old compilers opts+=$(WFLAGS) $(CFLAGS) -- 2.54.0 From 355c78e07529c074620a72a1b9d1a6ab529a2418 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:51:06 +0100 Subject: [PATCH 21/47] check for _GNU_SOURCE for nongnu_strcasestr idk we dont need it and it throws warnings on new glibc so i dont want it tbh --- src/doomtype.h | 2 +- src/strcasestr.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index ed6248129..0e6b6ef5d 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,8 +68,8 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif -char *nongnu_strcasestr(const char *in, const char *what); #ifndef _GNU_SOURCE +char *nongnu_strcasestr(const char *in, const char *what); #define strcasestr nongnu_strcasestr #endif diff --git a/src/strcasestr.c b/src/strcasestr.c index f05449778..84bc0671e 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -23,24 +23,26 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef _GNU_SOURCE + #include #include #include -static inline int -trycmp (char **pp, char *cp, - const char *q, size_t qn) +static inline int trycmp(char **pp, char *cp, const char *q, size_t qn) { char *p; p = (*pp); + if (strncasecmp(p, q, qn) == 0) return 0; + (*pp) = strchr(&p[1], (*cp)); + return 1; } -static inline void -swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) +static inline void swapp(char ***ppap, char ***ppbp, char **cpap, char **cpbp) { char **pp; char *p; @@ -54,8 +56,7 @@ swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) *cpbp = p; } -char * -nongnu_strcasestr (const char *s, const char *q) +char *nongnu_strcasestr(const char *s, const char *q) { size_t qn; @@ -113,3 +114,5 @@ nongnu_strcasestr (const char *s, const char *q) return NULL; } + +#endif -- 2.54.0 From a9a0d4bed8bf92319ef34ca8e49b55157555ddd1 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 17:54:51 +0100 Subject: [PATCH 22/47] fix compiler warnings for glibc 2.43 and newer this version changed so that many standard functions now propagate the constness of its input pointers to not cause warnings for everyone on older versions this is now a really dumb macro lol --- src/d_main.c | 2 +- src/doomtype.h | 9 +++++++++ src/g_game.c | 3 +++ src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/m_misc.c | 6 +++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 8bae5ea91..2832d6c6a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2023,7 +2023,7 @@ void D_SRB2Main(void) if (M_CheckProtoParam("replay")) { const char *replayurl = M_GetProtoParam(); - char *replayname = strrchr(replayurl, '/'); + gconst char *replayname = strrchr(replayurl, '/'); if (!replayname || !replayurl) I_Error("REPLAY: Invalid URL."); diff --git a/src/doomtype.h b/src/doomtype.h index 0e6b6ef5d..b7f8a73e5 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,6 +68,15 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif +// glibc 2.43 made alot of standard lib functions propagate the constness of its input pointers +// to not cause warnings or compile issues on older glibc versions we do this silly thing +// to not have a gazillion glibc version checks +#if __GLIBC_PREREQ(2, 43) + #define gconst const +#else + #define gconst +#endif + #ifndef _GNU_SOURCE char *nongnu_strcasestr(const char *in, const char *what); #define strcasestr nongnu_strcasestr diff --git a/src/g_game.c b/src/g_game.c index a79a957ef..e4e0601f0 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4153,6 +4153,7 @@ static void measurekeywords(mapsearchfreq_t *fr, { char *qp; char *sp; + if (wanttable) (*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim), PU_STATIC, NULL); @@ -4167,10 +4168,12 @@ static void measurekeywords(mapsearchfreq_t *fr, (*dimp)[(*cuntp)].pos = sp - s; (*dimp)[(*cuntp)].siz = strlen(qp); } + (*cuntp)++; fr->total++; } } + if (wanttable) (*dimp) = Z_Realloc((*dimp), (*cuntp) * sizeof (struct searchdim), PU_STATIC, NULL); diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 28f8e46d7..90d019b2b 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -109,7 +109,7 @@ boolean HWR_InitShaders(void) // returns INT32_MAX if not found static INT32 strstr_int(const char *str1, const char *str2) { - char *location = strstr(str1, str2); + gconst char *location = strstr(str1, str2); if (location) return location - str1; else diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index eeb40a8dc..a759b8b2b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1383,19 +1383,19 @@ void GL_Flush(void) // -----------------+ INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { - GLubyte *where, *terminator; + gconst GLubyte *where, *terminator; if (!extension || !start) return 0; - where = (GLubyte *) strchr(extension, ' '); + where = (gconst GLubyte *)strchr(extension, ' '); if (where || *extension == '\0') return 0; for (;;) { - where = (GLubyte *) strstr((const char *) start, extension); + where = (gconst GLubyte *)strstr((const char *)start, extension); if (!where) break; diff --git a/src/m_misc.c b/src/m_misc.c index 3a456d7a7..ee17e2098 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1454,9 +1454,9 @@ INT32 axtoi(const char *hexStg) void CopyCaretColors(char *p, const char *s, int n) { - char *t; - int m; - int c; + gconst char *t; + int m; + int c; if (!n) return; -- 2.54.0 From 6f2aba7ee3c47a9cedbd45fc177300f793555961 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 18:10:05 +0100 Subject: [PATCH 23/47] Windows is such a cool Operating System idk why we just dont use int32 there aswell and rely on whatever tf windows supplies which i dont trust ffs --- src/doomtype.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index b7f8a73e5..7d6017e27 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -71,11 +71,15 @@ extern "C" { // glibc 2.43 made alot of standard lib functions propagate the constness of its input pointers // to not cause warnings or compile issues on older glibc versions we do this silly thing // to not have a gazillion glibc version checks +#if defined(__GLIBC_PREREQ) #if __GLIBC_PREREQ(2, 43) #define gconst const #else #define gconst #endif +#else + #define gconst +#endif #ifndef _GNU_SOURCE char *nongnu_strcasestr(const char *in, const char *what); @@ -136,9 +140,9 @@ size_t strlcpy(char *dst, const char *src, size_t dsize); #define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst) /* Boolean type definition */ +#include #ifndef _WIN32 -#include // dont use stdbools _BOOL type // its smaller (1 byte) than the old interger bool (4 bytes) // which results in packed struct sizes being mismatched between vanilla and this @@ -146,9 +150,7 @@ size_t strlcpy(char *dst, const char *src, size_t dsize); // which we cant use as enumeration constants typedef int32_t boolean; #else -#define false FALSE -#define true TRUE -#define boolean BOOL +#define boolean int32_t #endif /* 7.18.2.1 Limits of exact-width integer types */ -- 2.54.0 From a287a6419f6a5857ecf163ad4bc46a98eb0da8df Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 23 Feb 2026 22:42:57 +0300 Subject: [PATCH 24/47] Use strncpy for zip entry filename because it might not be null-terminated inside zip --- src/w_wad.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 3009d503f..8cc3fd214 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -696,7 +696,8 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp) lump_p->size = LONG(zentry->size); fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); - strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); + strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); + fullname[zentry->namelen] = 0; // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != NULL) @@ -2237,7 +2238,8 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) if (verified == true) { fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); - strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); + strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); + fullname[zentry->namelen] = 0; // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != NULL) @@ -2482,7 +2484,8 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) } fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); - strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); + strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); + fullname[zentry->namelen] = 0; // Strip away file address and extension for the 8char name. if ((trimname = strrchr(fullname, '/')) != NULL) -- 2.54.0 From 2f684bba95a11f85961b7be842f7e0411415ac68 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 24 Feb 2026 12:34:11 +0100 Subject: [PATCH 25/47] ensure SIGINT/SIGTERM can quit out from wipes and serverconnection ticker --- src/d_clisrv.c | 5 +++++ src/f_wipe.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 2f3440362..0241f06e0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2782,6 +2782,11 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic { INT32 key; + if (I_Interrupted()) + { + I_Quit(); + } + I_OsPolling(); if (cl_mode == CL_CONFIRMCONNECT) diff --git a/src/f_wipe.c b/src/f_wipe.c index 6615cb53c..18100da4c 100644 --- a/src/f_wipe.c +++ b/src/f_wipe.c @@ -361,6 +361,11 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu) // on for fade-to-black for (;;) { + if (I_Interrupted()) + { + I_Quit(); + } + // get fademask first so we can tell if it exists or not fmask = F_GetFadeMask(wipetype, wipeframe++); -- 2.54.0 From 7c24d92613ef93affeb3fd5b571df14560b64d76 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 16:45:17 +0100 Subject: [PATCH 26/47] delet V_GetSkincolorChar this was unused and broken anyways think this came from snowy kart or smth --- src/v_video.c | 161 -------------------------------------------------- src/v_video.h | 2 - 2 files changed, 163 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index fde09cc0b..9898e9c29 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3309,167 +3309,6 @@ INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option) return max(i-1, 0); } -char V_GetSkincolorChar(INT32 color) -{ - char cstart = 0x80; - - switch (color) - { - case SKINCOLOR_WHITE: - case SKINCOLOR_SILVER: - case SKINCOLOR_SLATE: - cstart = 0x80; // White - break; - - case SKINCOLOR_GREY: - case SKINCOLOR_NICKEL: - case SKINCOLOR_BLACK: - case SKINCOLOR_SKUNK: - case SKINCOLOR_JET: - cstart = 0x86; // V_GRAYMAP - break; - - case SKINCOLOR_SEPIA: - case SKINCOLOR_BEIGE: - case SKINCOLOR_WALNUT: - case SKINCOLOR_BROWN: - case SKINCOLOR_LEATHER: - case SKINCOLOR_RUST: - case SKINCOLOR_WRISTWATCH: - cstart = 0x8e; // V_BROWNMAP - break; - - case SKINCOLOR_FAIRY: - case SKINCOLOR_SALMON: - case SKINCOLOR_PINK: - case SKINCOLOR_ROSE: - case SKINCOLOR_BRICK: - case SKINCOLOR_LEMONADE: - case SKINCOLOR_BUBBLEGUM: - case SKINCOLOR_LILAC: - cstart = 0x8d; // V_PINKMAP - break; - - case SKINCOLOR_CINNAMON: - case SKINCOLOR_RUBY: - case SKINCOLOR_RASPBERRY: - case SKINCOLOR_CHERRY: - case SKINCOLOR_RED: - case SKINCOLOR_CRIMSON: - case SKINCOLOR_MAROON: - case SKINCOLOR_FLAME: - case SKINCOLOR_SCARLET: - case SKINCOLOR_KETCHUP: - cstart = 0x85; // V_REDMAP - break; - - case SKINCOLOR_DAWN: - case SKINCOLOR_SUNSET: - case SKINCOLOR_CREAMSICLE: - case SKINCOLOR_ORANGE: - case SKINCOLOR_PUMPKIN: - case SKINCOLOR_ROSEWOOD: - case SKINCOLOR_BURGUNDY: - case SKINCOLOR_TANGERINE: - cstart = 0x87; // V_ORANGEMAP - break; - - case SKINCOLOR_PEACH: - case SKINCOLOR_CARAMEL: - case SKINCOLOR_CREAM: - cstart = 0x8f; // V_PEACHMAP - break; - - case SKINCOLOR_GOLD: - case SKINCOLOR_ROYAL: - case SKINCOLOR_BRONZE: - case SKINCOLOR_COPPER: - case SKINCOLOR_THUNDER: - cstart = 0x8a; // V_GOLDMAP - break; - - case SKINCOLOR_POPCORN: - case SKINCOLOR_QUARRY: - case SKINCOLOR_YELLOW: - case SKINCOLOR_MUSTARD: - case SKINCOLOR_CROCODILE: - case SKINCOLOR_OLIVE: - cstart = 0x82; // V_YELLOWMAP - break; - - case SKINCOLOR_ARTICHOKE: - case SKINCOLOR_VOMIT: - case SKINCOLOR_GARDEN: - case SKINCOLOR_TEA: - case SKINCOLOR_PISTACHIO: - cstart = 0x8b; // V_TEAMAP - break; - - case SKINCOLOR_LIME: - case SKINCOLOR_HANDHELD: - case SKINCOLOR_MOSS: - case SKINCOLOR_CAMOUFLAGE: - case SKINCOLOR_ROBOHOOD: - case SKINCOLOR_MINT: - case SKINCOLOR_GREEN: - case SKINCOLOR_PINETREE: - case SKINCOLOR_EMERALD: - case SKINCOLOR_SWAMP: - case SKINCOLOR_DREAM: - case SKINCOLOR_PLAGUE: - case SKINCOLOR_ALGAE: - cstart = 0x83; // V_GREENMAP - break; - - case SKINCOLOR_CARIBBEAN: - case SKINCOLOR_AZURE: - case SKINCOLOR_AQUA: - case SKINCOLOR_TEAL: - case SKINCOLOR_CYAN: - case SKINCOLOR_JAWZ: - case SKINCOLOR_CERULEAN: - case SKINCOLOR_NAVY: - case SKINCOLOR_SAPPHIRE: - cstart = 0x88; // V_SKYMAP - break; - - case SKINCOLOR_PIGEON: - case SKINCOLOR_PLATINUM: - case SKINCOLOR_STEEL: - cstart = 0x8c; // V_STEELMAP - break; - - case SKINCOLOR_PERIWINKLE: - case SKINCOLOR_BLUE: - case SKINCOLOR_BLUEBERRY: - case SKINCOLOR_NOVA: - cstart = 0x84; // V_BLUEMAP - break; - - case SKINCOLOR_ULTRAVIOLET: - case SKINCOLOR_PURPLE: - case SKINCOLOR_FUCHSIA: - cstart = 0x81; // V_PURPLEMAP - break; - - case SKINCOLOR_PASTEL: - case SKINCOLOR_MOONSLAM: - case SKINCOLOR_DUSK: - case SKINCOLOR_TOXIC: - case SKINCOLOR_MAUVE: - case SKINCOLOR_LAVENDER: - case SKINCOLOR_BYZANTIUM: - case SKINCOLOR_POMEGRANATE: - cstart = 0x89; // V_LAVENDERMAP - break; - - default: - break; - } - - return cstart; -} - INT32 V_SkinColorToHighlightcolor(skincolors_t color) { switch (color) diff --git a/src/v_video.h b/src/v_video.h index 7eea1468c..0a77c4bc2 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -287,8 +287,6 @@ INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option); // Find maximum length for substring taken from current string to fit into given width INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option); -char V_GetSkincolorChar(INT32 color); - INT32 V_SkinColorToHighlightcolor(skincolors_t color); // this is pretty dumb, but has to be done like this, otherwise the fps counter just disappears sometimes for no reason lol -- 2.54.0 From 3e327263c9e11a938cbebcad727f7a06e65c798e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 16:46:37 +0100 Subject: [PATCH 27/47] fix faulty papersprite flipping in opengl lol --- src/hardware/hw_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e9aa0532d..15434ec20 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -4850,7 +4850,7 @@ static void HWR_ProjectSprite(mobj_t *thing) flip = sprframe->flip; // Will only be 0x00 or 0xFF if (papersprite && ang < ANGLE_180) - flip ^= 0xFFFF; + flip ^= 0xFF; } else { -- 2.54.0 From 1b22c3af19cd9460564a976e8520cc334353608d Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 16:52:39 +0100 Subject: [PATCH 28/47] those should be boolean just for correctness! --- src/d_clisrv.c | 8 ++++---- src/d_clisrv.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0241f06e0..29dea3d19 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -173,11 +173,11 @@ static UINT16 resynch_delay[MAXNETNODES]; // delay time before the player can be static UINT32 resynch_status[MAXNETNODES]; // 0 bit means synched for that player, 1 means possibly desynched static UINT8 resynch_sent[MAXNETNODES][MAXPLAYERS]; // what synch packets have we attempted to send to the player static UINT8 resynch_inprogress[MAXNETNODES]; -static UINT8 resynch_local_inprogress = false; // WE are desynched and getting packets to fix it. -UINT8 hu_resynching = 0; +static boolean resynch_local_inprogress = false; // WE are desynched and getting packets to fix it. +boolean hu_resynching = false; #ifdef SATURNPAK -UINT8 hu_redownloadinggamestate = 0; +boolean hu_redownloadinggamestate = false; static UINT8 gamestate_resend_counter[MAXNETNODES]; #endif @@ -192,7 +192,7 @@ static UINT8 mynode; // my address pointofview server #ifdef SATURNPAK static boolean cl_redownloadinggamestate = false; -boolean is_client_saturn[MAXNETNODES]; +static boolean is_client_saturn[MAXNETNODES]; #endif #ifdef SATURNJOIN diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 430729bc2..396b2190c 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -654,9 +654,9 @@ void D_ResetTiccmds(void); tic_t GetLag(INT32 node); -extern UINT8 hu_resynching; +extern boolean hu_resynching; #ifdef SATURNPAK -extern UINT8 hu_redownloadinggamestate; +extern boolean hu_redownloadinggamestate; #endif extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player -- 2.54.0 From 2084cdc6d5679a779948d5002475b64866ec0d6b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 17:07:27 +0100 Subject: [PATCH 29/47] hw_md2: remove pointless float casts durs and tics are int32. and so is var2, anim_duration is uint16 but that still makes no sense lul --- src/hardware/hw_md2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 2fd33f65b..d9bf41645 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1336,8 +1336,8 @@ void HWR_DrawMD2(gl_vissprite_t *spr) if (spr->mobj->frame & FF_ANIMATE) { // set duration and tics to be the correct values for FF_ANIMATE states - durs = (float)spr->mobj->state->var2; - tics = (float)spr->mobj->anim_duration; + durs = spr->mobj->state->var2; + tics = (INT32)spr->mobj->anim_duration; } //FIXME: this is not yet correct -- 2.54.0 From 94026e43317cd66498022c7b2e687ffd557866c0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 17:44:56 +0100 Subject: [PATCH 30/47] makefile: comment out all the "Wno" flags we effectively fixed all of them, so this does not throw any warnings for me atleast in case we may screw up id rather have those warnings appear --- src/Makefile.d/versions.mk | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index c3989bb4f..cb13c286c 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,8 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +WFLAGS:=-Wall -Wnull-dereference +#WFLAGS+=-Wno-trigraphs ifdef GCC152 WFLAGS+=-Wzero-as-null-pointer-constant endif @@ -31,7 +32,7 @@ ifndef RELAXWARNINGS WFLAGS+=-W #WFLAGS+=-Wno-sign-compare ifndef GCC295 - WFLAGS+=-Wno-div-by-zero +# WFLAGS+=-Wno-div-by-zero endif #WFLAGS+=-Wsystem-headers WFLAGS+=-Wfloat-equal @@ -62,7 +63,7 @@ endif endif WFLAGS+=-Wsign-compare ifdef GCC91 - WFLAGS+=-Wno-error=address-of-packed-member +# WFLAGS+=-Wno-error=address-of-packed-member endif ifdef GCC45 WFLAGS+=-Wlogical-op @@ -105,14 +106,14 @@ endif endif WFLAGS+=-Wformat-y2k ifdef GCC71 -WFLAGS+=-Wno-error=format-overflow=2 +#WFLAGS+=-Wno-error=format-overflow=2 endif WFLAGS+=-Wformat-security ifndef GCC29 #WFLAGS+=-Winit-self endif ifdef GCC46 -WFLAGS+=-Wno-suggest-attribute=noreturn +#WFLAGS+=-Wno-suggest-attribute=noreturn endif ifdef NOLDWARNING @@ -130,21 +131,21 @@ ifdef GCC44 #WFLAGS+=-Wno-error=array-bounds endif ifdef GCC46 - WFLAGS+=-Wno-error=suggest-attribute=noreturn +# WFLAGS+=-Wno-error=suggest-attribute=noreturn endif ifdef GCC54 - WFLAGS+=-Wno-logical-op -Wno-error=logical-op +# WFLAGS+=-Wno-logical-op -Wno-error=logical-op endif ifdef GCC61 - WFLAGS+=-Wno-tautological-compare -Wno-error=tautological-compare +# WFLAGS+=-Wno-tautological-compare -Wno-error=tautological-compare endif ifdef GCC71 WFLAGS+=-Wimplicit-fallthrough=4 endif ifdef GCC81 - WFLAGS+=-Wno-error=format-overflow - WFLAGS+=-Wno-format-overflow - WFLAGS+=-Wno-error=multistatement-macros +# WFLAGS+=-Wno-error=format-overflow +# WFLAGS+=-Wno-format-overflow +# WFLAGS+=-Wno-error=multistatement-macros endif ifneq (,$(filter $(CC) $(CXX),clang clang++)) @@ -183,6 +184,6 @@ endif # Lua ifdef GCC43 ifndef GCC44 -WFLAGS+=-Wno-logical-op +#WFLAGS+=-Wno-logical-op endif endif -- 2.54.0 From 1e51365cadaa3d6075b00eb8214a59618224755e Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 17:43:08 +0100 Subject: [PATCH 31/47] add comment about K_KartUpdatePosition --- src/k_kart.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 0efd3a48b..2aa0377b2 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6175,6 +6175,13 @@ void K_KartUpdatePosition(player_t *player) } } + // the player should NOT be checked against themselves! lol + // otherwise prevcheck will effectively be halved + // sadly this stuff is exposed to lua and atleast one script uses those so we cant fix it + // oh well + //if (player == &players[i]) + //continue; + const boolean isprevcheckpointi = mo->health == players[i].starpostnum; const boolean isnextcheckpointi = mo->health == (players[i].starpostnum + 1); -- 2.54.0 From 1ec29c1c94579ffb9fc263bd202531b48daad8f0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 25 Feb 2026 21:27:02 +0100 Subject: [PATCH 32/47] better flags for ASAN and UBSAN compile with -O1 and -fno-omit-frame-pointer -fno-common for ASAN --- src/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index be4f995db..372594384 100644 --- a/src/Makefile +++ b/src/Makefile @@ -269,13 +269,13 @@ endif ifdef USEASAN # compile with asan -opts+=-fsanitize=address +opts+=-O1 -fsanitize=address -fno-omit-frame-pointer -fno-common libs+=-fsanitize=address endif ifdef USEUBSAN -# compile with asan -opts+=-fsanitize=undefined +# compile with ubsan +opts+=-O1 -fsanitize=undefined -fno-omit-frame-pointer libs+=-fsanitize=undefined endif -- 2.54.0 From db4cd73912b65e26ea2542b845ae6b2671db8455 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Feb 2026 01:05:08 +0100 Subject: [PATCH 33/47] fix keepmusic resuming not resetting with "tunes" command this code sucks ass wtf was i cooking if this breaks again i will just wipe it lmao --- src/s_sound.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index f2ee1dc03..1e19c83fe 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1438,7 +1438,7 @@ void S_LoadMusicDefs(UINT16 wadnum) stoken = strtok(stoken, " "); if (stoken) { - if (! ReadMusicDefFields(wadnum, line, stoken, &def)) + if (!ReadMusicDefFields(wadnum, line, stoken, &def)) break; } @@ -1982,7 +1982,7 @@ static void S_SetKeepMusResume(void) { keepmusic.resume = 0; - if (fasticmp(music.name, mapmusic.name)) + if (fasticmp(music.name, keepmusic.name)) { keepmusic.resume = I_GetSongPosition(); } @@ -2078,9 +2078,12 @@ void S_InitMapMusic(void) S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, keepmusic.resume, 0, 500); } + keepmusic.resume = 0; return; } + keepmusic.resume = 0; + // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); @@ -2208,6 +2211,8 @@ static void Command_Tunes_f(void) mapmusic.position = position; mapmusic.resume = 0; + keepmusic.resume = 0; + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); if (argc > 3) -- 2.54.0 From 6ff1cbf4b03c61ca2e4eac92834edec6347c7aee Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 26 Feb 2026 01:11:37 +0100 Subject: [PATCH 34/47] ok actually just remove keepmusic resume stuff well now it just broke with dynmusic this sucks, its probably fixable but the code was abysmal so shrug --- src/s_sound.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 1e19c83fe..546c183a8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -116,9 +116,7 @@ consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, boolean keepmapmusic = false; // keep the current music on map restart boolean skipintromus = false; // skip the intro fanfare -static boolean resumekeepmusic = false; static music_t keepmusic; -static void S_SetKeepMusResume(void); #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -1848,8 +1846,6 @@ void S_StopMusic(void) mapmusic.resume = (cv_resume.value && fasticmp(music.name, mapmusic.name)) ? I_GetSongPosition() : 0; - S_SetKeepMusResume(); - if (I_SongPaused()) I_ResumeSong(); @@ -1976,17 +1972,6 @@ void S_ResetKeepAndSpecialMus(void) keepmapmusic = skipintromus = false; } -// saves the current song position everytime a song stops -// so we can resume it in some cases -static void S_SetKeepMusResume(void) -{ - keepmusic.resume = 0; - - if (fasticmp(music.name, keepmusic.name)) - { - keepmusic.resume = I_GetSongPosition(); - } -} // determine if we should keep the music on a map restart // this gets called BEFORE the level gets loaded in G_DoLoadLevel @@ -1995,7 +1980,7 @@ void S_KeepMusic(void) static INT16 oldmap = -1; static boolean oldencore = false; - keepmapmusic = resumekeepmusic = false; + keepmapmusic = false; if (!cv_keepmusic.value) { @@ -2009,9 +1994,7 @@ void S_KeepMusic(void) if (oldmap == gamemap && oldencore == encoremode) { - const boolean musicchanged = S_CheckMusicException(); - resumekeepmusic = (musicchanged && keepmusic.resume); - keepmapmusic = (!musicchanged || resumekeepmusic); + keepmapmusic = (S_CheckMusicException() == false); } oldencore = encoremode; @@ -2072,18 +2055,9 @@ void S_InitMapMusic(void) if (keepmapmusic) { - // this is kinda silly, but we can use it to fade back into the map song at the saved point, should the current music be different from the map music - if (resumekeepmusic) - { - S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, keepmusic.resume, 0, 500); - } - - keepmusic.resume = 0; return; } - keepmusic.resume = 0; - // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); @@ -2211,8 +2185,6 @@ static void Command_Tunes_f(void) mapmusic.position = position; mapmusic.resume = 0; - keepmusic.resume = 0; - S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, mapmusic.position, 0, 0); if (argc > 3) -- 2.54.0 From 5577ba4c7ac98cb11339f4b416801ac100430c82 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 00:03:19 +0100 Subject: [PATCH 35/47] Autoload: dont add wads that contain maps --- src/d_main.c | 11 ++++++++++- src/w_wad.c | 13 ++++++++++++- src/w_wad.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 2832d6c6a..1a03b1972 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1124,9 +1124,18 @@ static void D_FindAddonsToAutoload(void) if (newline) *newline = '\0'; + // ok so theres still issues with players adding stuff to autoload by accident + // sometimes this stuff contains maps + // you can probably imagine how that goes in a netgame.... + if (W_CheckAutoLoadContainsMap(wadsToAutoload)) + { + CONS_Printf("Autoload: file %s contains map data! skipping...", wadsToAutoload); + continue; + } + if (!postload && W_CheckPostLoadList(wadsToAutoload)) { - CONS_Printf("forcing postload for file %s\n", wadsToAutoload); + CONS_Printf("Autoload: forcing postload for file %s\n", wadsToAutoload); postload = true; } diff --git a/src/w_wad.c b/src/w_wad.c index 8cc3fd214..4a1c1247a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2576,6 +2576,18 @@ static int W_CheckFileContains(const char *filename, lumpchecklist_t *checklist) return contains; } +int W_CheckAutoLoadContainsMap(const char *filename) +{ + // for now this checks for map marker + static lumpchecklist_t autoloadblacklist[] = + { + {"MAP", 3}, + {NULL, 0}, + }; + + return W_CheckFileContains(filename, autoloadblacklist); +} + int W_CheckPostLoadList(const char *filename) { static lumpchecklist_t postloadlist[] = @@ -2588,7 +2600,6 @@ int W_CheckPostLoadList(const char *filename) {"SOC_", 4}, {"MAINCFG", 7}, {"OBJCTCFG", 8}, - {"MAP", 3}, {NULL, 0}, }; diff --git a/src/w_wad.h b/src/w_wad.h index 6240c31f3..98c57173e 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -243,6 +243,7 @@ void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5); int W_VerifyNMUSlumps(const char *filename, FILE *handle, boolean exit_on_error); +int W_CheckAutoLoadContainsMap(const char *filename); int W_CheckPostLoadList(const char *filename); #ifdef __cplusplus -- 2.54.0 From 1cf04514b3b67685789182c83b95907be80a2154 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 1 Mar 2026 02:31:11 +0300 Subject: [PATCH 36/47] Fix W_MakeFileMD5 printing incorrect time --- src/w_wad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 4a1c1247a..3c37bf185 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -339,7 +339,7 @@ static inline INT32 W_MakeFileMD5(const char *filename, void *resblock) if ((fhandle = fopen(filename, "rb")) != NULL) { - tic_t t = I_GetTime(); + precise_t t = I_GetPreciseTime(); CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",filename); @@ -350,7 +350,7 @@ static inline INT32 W_MakeFileMD5(const char *filename, void *resblock) } CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f seconds\n", - filename, (float)(I_GetTime() - t)/NEWTICRATE); + filename, (float)(I_GetPreciseTime() - t)/I_GetPrecisePrecision()); fclose(fhandle); return 0; -- 2.54.0 From 5ca3ab5966f2d221db802d0ed1c0d99d6a1e100a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 00:57:44 +0100 Subject: [PATCH 37/47] Autoload: fix incorrectly incrementing wad count those should only be incremented if we actually add something to the filearray and not instantly execute or error out --- src/d_main.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 1a03b1972..85ef4d226 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -130,8 +130,8 @@ static size_t startuppwadcount = 0; // autoloading static char *autoloadwadfiles[MAX_WADFILES]; static char *autoloadwadfilespost[MAX_WADFILES]; -static size_t autoloadcount = 0; -static size_t postloadcount = 0; +static size_t autoloadwadcount = 0; +static size_t postloadwadcount = 0; // boolean devparm = false; // started game with -devparm @@ -1037,7 +1037,7 @@ static INT32 D_DetectFileType(const char* filename) } // autoload that shit -static void D_AutoloadFile(const char *file, char **filearray, size_t index) +static void D_AutoloadFile(const char *file, char **filearray, size_t *index) { char *newfile; INT32 fileType = D_DetectFileType(file); @@ -1052,10 +1052,11 @@ static void D_AutoloadFile(const char *file, char **filearray, size_t index) { newfile = malloc(strlen(file) + 1); if (!newfile) - I_Error("No more free memory to AutoloadFile %s",file); + I_Error("D_AutoloadFile: No more free memory to autoload file %s", file); strcpy(newfile, file); - filearray[index] = newfile; + filearray[*index] = newfile; + (*index)++; } else { @@ -1098,7 +1099,7 @@ static void D_FindAddonsToAutoload(void) // If the file is found, run our shit if (!autoloadconfigfile) // nope outta here { - autoloadcount = postloadcount = 0; // so D_AddAutoloadFiles can skip everything since nothings there to autoload + autoloadwadcount = postloadwadcount = 0; // so D_AddAutoloadFiles can skip everything since nothings there to autoload return; } @@ -1142,18 +1143,16 @@ static void D_FindAddonsToAutoload(void) // LOAD IT if (!postload) { - D_AutoloadFile(wadsToAutoload, autoloadwadfiles, autoloadcount); - autoloadcount++; + D_AutoloadFile(wadsToAutoload, autoloadwadfiles, &autoloadwadcount); } else { - D_AutoloadFile(wadsToAutoload, autoloadwadfilespost, postloadcount); - postloadcount++; + D_AutoloadFile(wadsToAutoload, autoloadwadfilespost, &postloadwadcount); } } - autoloadwadfiles[autoloadcount] = NULL; - autoloadwadfilespost[postloadcount] = NULL; + autoloadwadfiles[autoloadwadcount] = NULL; + autoloadwadfilespost[postloadwadcount] = NULL; // we dont want memory leaks around here do we? fclose(autoloadconfigfile); @@ -1162,7 +1161,7 @@ static void D_FindAddonsToAutoload(void) static void D_AddAutoloadFiles(void) { // nothing to autoload - if (autoloadcount == 0) + if (autoloadwadcount == 0) return; CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n"); @@ -1170,15 +1169,15 @@ static void D_AddAutoloadFiles(void) if (W_AddAutoloadedLocalFiles(autoloadwadfiles) == 0) CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n"); - D_CleanFile(autoloadwadfiles, autoloadcount); + D_CleanFile(autoloadwadfiles, autoloadwadcount); - autoloadcount = 0; + autoloadwadcount = 0; } void D_AddPostloadFiles(void) { // nothing to postload - if (postloadcount == 0 || !netgame) + if (postloadwadcount == 0 || !netgame) return; CONS_Printf("D_AddPostloadFiles(): Loading postloaded addons...\n"); @@ -1186,9 +1185,9 @@ void D_AddPostloadFiles(void) if (W_AddAutoloadedLocalFiles(autoloadwadfilespost) == 0) CONS_Printf("D_AddPostloadFiles(): Are you sure you put in valid files or what?\n"); - D_CleanFile(autoloadwadfilespost, postloadcount); + D_CleanFile(autoloadwadfilespost, postloadwadcount); - postloadcount = 0; + postloadwadcount = 0; } // ========================================================================== -- 2.54.0 From e8c7cc6a9b57ffba849ff6ccaa3935ea2633baa0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 00:59:51 +0100 Subject: [PATCH 38/47] D_AutoloadFile: add overflow safeguard --- src/d_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 85ef4d226..c312e3f59 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1042,6 +1042,12 @@ static void D_AutoloadFile(const char *file, char **filearray, size_t *index) char *newfile; INT32 fileType = D_DetectFileType(file); + if (*index >= MAX_WADFILES) + { + CONS_Printf("D_AutoloadFile: Failed to add file %s! Too many autoloaded files\n", file); + return; + } + if (!fileType) { CONS_Printf("D_AutoloadFile: File %s is unknown or invalid\n", file); -- 2.54.0 From 1a9fa94cbd44d129af33b395bfe09acc3785f9fb Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 01:01:20 +0100 Subject: [PATCH 39/47] Autoload: dont attempt to load directories lol --- src/d_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index c312e3f59..0ecce2047 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1054,6 +1054,12 @@ static void D_AutoloadFile(const char *file, char **filearray, size_t *index) return; } + if (fileType == 1) + { + CONS_Printf("D_AutoloadFile: File %s is a directory\n", file); + return; + } + if (fileType <= 6) { newfile = malloc(strlen(file) + 1); -- 2.54.0 From 397fb071e5eb9edfc4ca10b92770ae48d95d3c4b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 21:24:09 +0100 Subject: [PATCH 40/47] fix compiling with valgrind support --- src/z_zone.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 9e5b4f41e..f25f99e43 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -523,11 +523,19 @@ void Z_CheckHeap(INT32 tag) #ifdef VALGRIND_MEMPOOL_EXISTS if (!VALGRIND_MEMPOOL_EXISTS(block)) { - I_Error("Z_CheckHeap %d: block %u" + I_Error("Z_CheckHeap :" +#ifdef ZDEBUG + " %s %d" +#endif + " block %u" #ifdef ZDEBUG " (owned by %s:%d)" #endif - " should not exist", i, blocknumon + " should not exist" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif -- 2.54.0 From 82471339664b62115eb15cd9f1d44e7144acb4d5 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Mar 2026 21:32:25 +0100 Subject: [PATCH 41/47] w_wad: use strnlen to check lump length for map marker lump name may not be null terminated here, so strlen may read out of bounds garbo using strnlen ensures we read max 8 characters which is the name buffer size --- src/w_wad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/w_wad.c b/src/w_wad.c index 3c37bf185..ef9bd471e 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2660,11 +2660,12 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) { if (vsizecache[realentry] == 0) continue; + vlumps[i].size = vsizecache[realentry]; const char *name = (fileinfo + realentry)->name; - if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + if (strnlen(name, 8) == 5 && memcmp(name, "MAP", 3) == 0) { numlumps--; // We skip map marker, so 1 of entries becomes empty continue; // This will skip i++ so we will write to same entry -- 2.54.0 From f2b46fd1484e573babc3ab0f6e6da1843c942408 Mon Sep 17 00:00:00 2001 From: "X.organic" Date: Tue, 6 Apr 2021 01:01:33 +0200 Subject: [PATCH 42/47] Fix myhashfgets-related buffer overflows in deh_soc.c --- src/dehacked.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index a3513fbbe..6b09f0d5b 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -115,20 +115,25 @@ char *myfgets(char *buf, size_t bufsize, MYFILE *f) size_t i = 0; if (myfeof(f)) return NULL; + // we need one byte for a null terminated string bufsize--; + while (i < bufsize && !myfeof(f)) { char c = *f->curpos++; + if (c == '^') buf[i++] = myfget_color(f); else if (c == '\\') buf[i++] = myfget_hex(f); else if (c != '\r') buf[i++] = c; + if (c == '\n') break; } + buf[i] = '\0'; dbg_line++; @@ -138,25 +143,31 @@ char *myfgets(char *buf, size_t bufsize, MYFILE *f) static char *myhashfgets(char *buf, size_t bufsize, MYFILE *f) { size_t i = 0; + if (myfeof(f)) return NULL; + // we need one byte for a null terminated string bufsize--; + while (i < bufsize && !myfeof(f)) { char c = *f->curpos++; + if (c == '^') buf[i++] = myfget_color(f); else if (c == '\\') buf[i++] = myfget_hex(f); else if (c != '\r') buf[i++] = c; + if (c == '\n') // Ensure debug line is right... dbg_line++; + if (c == '#') break; } - i++; + buf[i] = '\0'; return buf; @@ -315,7 +326,10 @@ static void readPlayer(MYFILE *f, INT32 num) goto done; PlayerMenu[num].status = IT_CALL; - for (i = 0; i < MAXLINELEN-3; i++) + // A friendly neighborhood alias for brevity's sake + const size_t note_size = sizeof(description[num].notes); + + for (i = 0; i < (INT32)(MAXLINELEN-note_size-3); i++) { if (s[i] == '=') { @@ -323,10 +337,12 @@ static void readPlayer(MYFILE *f, INT32 num) break; } } + if (playertext) { - strcpy(description[num].notes, playertext); - strcat(description[num].notes, myhashfgets(playertext, sizeof (description[num].notes), f)); + strlcpy(description[num].notes, playertext, note_size); + strlcat(description[num].notes, + myhashfgets(playertext, note_size, f), note_size); } else strcpy(description[num].notes, ""); @@ -335,7 +351,7 @@ static void readPlayer(MYFILE *f, INT32 num) // It works down here, though. { INT32 numline = 0; - for (i = 0; (size_t)i < sizeof(description[num].notes)-1; i++) + for (i = 0; (size_t)i < note_size-1; i++) { if (numline < 20 && description[num].notes[i] == '\n') numline++; @@ -344,6 +360,7 @@ static void readPlayer(MYFILE *f, INT32 num) break; } } + description[num].notes[strlen(description[num].notes)-1] = '\0'; description[num].notes[i] = '\0'; continue; -- 2.54.0 From 07fc0eb03abd21ef36f96d345baf83f773ae7192 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Mar 2026 00:34:58 +0100 Subject: [PATCH 43/47] v_video: fix cv_palettenum bounds check mhhm yeah --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 9898e9c29..fcbeded5f 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -555,7 +555,7 @@ void V_SetPalette(INT32 palettenum) { palettenum = cv_palettenum.value; - if (palettenum * 256U > currentPaletteSize - 256) + if (palettenum * 256U > (currentPaletteSize - 256) / 3) { CONS_Alert(CONS_WARNING, "cv_palettenum %d out of range\n", palettenum); palettenum = 0; -- 2.54.0 From efe873218811aea5d718a96dc63726c96aeb4347 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Mar 2026 00:43:33 +0100 Subject: [PATCH 44/47] fix flashpals throwing random garbage into the renderer in some cases iirc, if the provided palette currently in use did not provide subpalettes, this will read past the bounds of allocated memory, which aint good lol i just dumped the white flashpal and threw it into there since idk if -file or autoload gets called before the palette gets initialised, which would carry a risk of copying more garbage, hence this big ass array --- src/v_video.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index fcbeded5f..2aa680153 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -92,6 +92,97 @@ consvar_t cv_menucaps = {"menucaps", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NUL RGBA_t *pLocalPalette = NULL; RGBA_t *pGammaCorrectedPalette = NULL; +// huge ass array les gooooooo! +// this is basically the white flashpal byte for byte from our main palette lmao +static RGBA_t pFallbackFlashPal[] = { + {.s={253, 253, 253, 255}}, {.s={251, 251, 251, 255}}, {.s={249, 249, 249, 255}}, + {.s={247, 247, 247, 255}}, {.s={245, 245, 245, 255}}, {.s={243, 243, 243, 255}}, + {.s={241, 241, 241, 255}}, {.s={239, 239, 239, 255}}, {.s={237, 237, 237, 255}}, + {.s={235, 235, 235, 255}}, {.s={233, 233, 233, 255}}, {.s={231, 231, 231, 255}}, + {.s={229, 229, 229, 255}}, {.s={227, 227, 227, 255}}, {.s={225, 225, 225, 255}}, + {.s={223, 223, 223, 255}}, {.s={221, 221, 221, 255}}, {.s={219, 219, 219, 255}}, + {.s={217, 217, 217, 255}}, {.s={215, 215, 215, 255}}, {.s={213, 213, 213, 255}}, + {.s={211, 211, 211, 255}}, {.s={209, 209, 209, 255}}, {.s={207, 207, 207, 255}}, + {.s={205, 205, 205, 255}}, {.s={203, 203, 203, 255}}, {.s={201, 201, 201, 255}}, + {.s={199, 199, 199, 255}}, {.s={197, 197, 197, 255}}, {.s={195, 195, 195, 255}}, + {.s={193, 193, 193, 255}}, {.s={192, 192, 192, 255}}, {.s={239, 233, 227, 255}}, + {.s={237, 231, 225, 255}}, {.s={235, 229, 223, 255}}, {.s={233, 227, 221, 255}}, + {.s={231, 225, 219, 255}}, {.s={229, 223, 217, 255}}, {.s={227, 221, 215, 255}}, + {.s={225, 220, 214, 255}}, {.s={223, 218, 212, 255}}, {.s={220, 216, 210, 255}}, + {.s={218, 214, 208, 255}}, {.s={216, 212, 206, 255}}, {.s={214, 210, 204, 255}}, + {.s={212, 208, 202, 255}}, {.s={210, 206, 200, 255}}, {.s={208, 204, 198, 255}}, + {.s={239, 222, 210, 255}}, {.s={236, 220, 209, 255}}, {.s={234, 219, 208, 255}}, + {.s={232, 218, 207, 255}}, {.s={230, 216, 206, 255}}, {.s={227, 215, 205, 255}}, + {.s={225, 213, 204, 255}}, {.s={223, 212, 203, 255}}, {.s={221, 211, 202, 255}}, + {.s={218, 209, 201, 255}}, {.s={215, 208, 200, 255}}, {.s={212, 207, 199, 255}}, + {.s={210, 205, 198, 255}}, {.s={207, 203, 197, 255}}, {.s={204, 202, 196, 255}}, + {.s={202, 200, 195, 255}}, {.s={255, 250, 247, 255}}, {.s={255, 248, 244, 255}}, + {.s={255, 246, 241, 255}}, {.s={255, 244, 238, 255}}, {.s={255, 243, 236, 255}}, + {.s={255, 241, 233, 255}}, {.s={255, 239, 230, 255}}, {.s={255, 238, 228, 255}}, + {.s={255, 236, 224, 255}}, {.s={253, 234, 222, 255}}, {.s={251, 232, 220, 255}}, + {.s={249, 230, 218, 255}}, {.s={247, 228, 216, 255}}, {.s={245, 226, 214, 255}}, + {.s={243, 224, 212, 255}}, {.s={242, 223, 211, 255}}, {.s={255, 250, 246, 255}}, + {.s={255, 246, 237, 255}}, {.s={255, 242, 229, 255}}, {.s={255, 237, 220, 255}}, + {.s={255, 233, 213, 255}}, {.s={255, 229, 205, 255}}, {.s={255, 225, 198, 255}}, + {.s={255, 220, 192, 255}}, {.s={252, 218, 192, 255}}, {.s={248, 216, 192, 255}}, + {.s={245, 214, 192, 255}}, {.s={242, 213, 192, 255}}, {.s={238, 211, 192, 255}}, + {.s={235, 209, 192, 255}}, {.s={232, 207, 192, 255}}, {.s={229, 205, 192, 255}}, + {.s={255, 255, 251, 255}}, {.s={255, 255, 243, 255}}, {.s={255, 255, 235, 255}}, + {.s={255, 255, 227, 255}}, {.s={255, 255, 219, 255}}, {.s={255, 255, 211, 255}}, + {.s={255, 255, 203, 255}}, {.s={255, 255, 195, 255}}, {.s={255, 255, 192, 255}}, + {.s={243, 243, 192, 255}}, {.s={235, 235, 192, 255}}, {.s={227, 227, 192, 255}}, + {.s={219, 219, 192, 255}}, {.s={211, 211, 192, 255}}, {.s={203, 203, 192, 255}}, + {.s={195, 195, 192, 255}}, {.s={255, 255, 220, 255}}, {.s={250, 246, 213, 255}}, + {.s={245, 238, 208, 255}}, {.s={240, 230, 203, 255}}, {.s={235, 222, 199, 255}}, + {.s={230, 214, 196, 255}}, {.s={225, 208, 193, 255}}, {.s={220, 202, 192, 255}}, + {.s={255, 255, 255, 255}}, {.s={255, 247, 247, 255}}, {.s={255, 239, 239, 255}}, + {.s={255, 231, 231, 255}}, {.s={255, 223, 223, 255}}, {.s={255, 215, 215, 255}}, + {.s={255, 207, 207, 255}}, {.s={255, 199, 199, 255}}, {.s={255, 192, 192, 255}}, + {.s={251, 192, 192, 255}}, {.s={247, 192, 192, 255}}, {.s={243, 192, 192, 255}}, + {.s={239, 192, 192, 255}}, {.s={235, 192, 192, 255}}, {.s={231, 192, 192, 255}}, + {.s={227, 192, 192, 255}}, {.s={223, 192, 192, 255}}, {.s={219, 192, 192, 255}}, + {.s={215, 192, 192, 255}}, {.s={211, 192, 192, 255}}, {.s={207, 192, 192, 255}}, + {.s={203, 192, 192, 255}}, {.s={199, 192, 192, 255}}, {.s={195, 192, 192, 255}}, + {.s={255, 237, 237, 255}}, {.s={252, 232, 232, 255}}, {.s={249, 227, 227, 255}}, + {.s={246, 222, 222, 255}}, {.s={242, 218, 218, 255}}, {.s={239, 214, 214, 255}}, + {.s={236, 211, 211, 255}}, {.s={233, 207, 207, 255}}, {.s={227, 203, 192, 255}}, + {.s={225, 201, 192, 255}}, {.s={223, 199, 192, 255}}, {.s={220, 198, 192, 255}}, + {.s={218, 196, 192, 255}}, {.s={216, 194, 192, 255}}, {.s={214, 193, 192, 255}}, + {.s={213, 192, 192, 255}}, {.s={221, 255, 211, 255}}, {.s={219, 251, 210, 255}}, + {.s={217, 247, 209, 255}}, {.s={215, 243, 208, 255}}, {.s={214, 239, 206, 255}}, + {.s={212, 235, 205, 255}}, {.s={210, 231, 204, 255}}, {.s={208, 227, 203, 255}}, + {.s={206, 223, 201, 255}}, {.s={205, 219, 200, 255}}, {.s={203, 215, 199, 255}}, + {.s={201, 211, 198, 255}}, {.s={199, 207, 196, 255}}, {.s={197, 203, 195, 255}}, + {.s={195, 199, 194, 255}}, {.s={193, 195, 192, 255}}, {.s={246, 255, 233, 255}}, + {.s={241, 248, 228, 255}}, {.s={234, 241, 223, 255}}, {.s={228, 234, 218, 255}}, + {.s={222, 228, 213, 255}}, {.s={216, 221, 208, 255}}, {.s={210, 214, 203, 255}}, + {.s={204, 207, 199, 255}}, {.s={192, 255, 192, 255}}, {.s={192, 247, 192, 255}}, + {.s={192, 239, 192, 255}}, {.s={192, 231, 192, 255}}, {.s={192, 223, 192, 255}}, + {.s={192, 215, 192, 255}}, {.s={192, 207, 192, 255}}, {.s={192, 199, 192, 255}}, + {.s={255, 219, 255, 255}}, {.s={255, 192, 255, 255}}, {.s={247, 192, 247, 255}}, + {.s={239, 192, 239, 255}}, {.s={231, 192, 231, 255}}, {.s={223, 192, 223, 255}}, + {.s={215, 192, 215, 255}}, {.s={207, 192, 207, 255}}, {.s={249, 249, 252, 255}}, + {.s={240, 240, 247, 255}}, {.s={230, 230, 242, 255}}, {.s={221, 221, 238, 255}}, + {.s={212, 212, 233, 255}}, {.s={208, 208, 224, 255}}, {.s={203, 203, 214, 255}}, + {.s={198, 198, 204, 255}}, {.s={244, 251, 255, 255}}, {.s={239, 250, 255, 255}}, + {.s={234, 248, 255, 255}}, {.s={228, 246, 255, 255}}, {.s={223, 244, 255, 255}}, + {.s={218, 243, 255, 255}}, {.s={213, 241, 255, 255}}, {.s={207, 239, 255, 255}}, + {.s={205, 230, 247, 255}}, {.s={203, 227, 239, 255}}, {.s={201, 221, 231, 255}}, + {.s={199, 215, 223, 255}}, {.s={192, 239, 239, 255}}, {.s={192, 223, 223, 255}}, + {.s={192, 215, 215, 255}}, {.s={192, 207, 207, 255}}, {.s={249, 249, 255, 255}}, + {.s={240, 240, 255, 255}}, {.s={234, 234, 255, 255}}, {.s={226, 226, 255, 255}}, + {.s={220, 220, 255, 255}}, {.s={212, 212, 255, 255}}, {.s={204, 204, 255, 255}}, + {.s={197, 197, 255, 255}}, {.s={192, 192, 255, 255}}, {.s={192, 192, 249, 255}}, + {.s={192, 192, 242, 255}}, {.s={192, 192, 236, 255}}, {.s={192, 192, 230, 255}}, + {.s={192, 192, 224, 255}}, {.s={192, 192, 218, 255}}, {.s={192, 192, 212, 255}}, + {.s={192, 192, 211, 255}}, {.s={192, 192, 207, 255}}, {.s={192, 192, 205, 255}}, + {.s={192, 192, 201, 255}}, {.s={192, 192, 199, 255}}, {.s={192, 192, 195, 255}}, + {.s={192, 192, 193, 255}}, {.s={192, 255, 255, 255}}, {.s={243, 223, 243, 255}}, + {.s={237, 219, 237, 255}}, {.s={231, 215, 231, 255}}, {.s={225, 211, 225, 255}}, + {.s={219, 207, 219, 255}}, {.s={213, 203, 213, 255}}, {.s={207, 199, 207, 255}}, + {.s={201, 195, 201, 255}} +}; + static size_t currentPaletteSize; /* @@ -543,6 +634,7 @@ void V_ReloadPalette(void) // -------------+ void V_SetPalette(INT32 palettenum) { + RGBA_t *pal = NULL; if (!pLocalPalette) V_ReloadPalette(); @@ -563,15 +655,31 @@ void V_SetPalette(INT32 palettenum) } } + // if the palettenum goes beyond our current palette, then just fallback to the white flash pal + // our srb2 palette mostly just contains that as subpalettes, so everything uses this + // and makes it a good fallback case + // otherwise we will throw random garbage to the renderer which calls memcpy on it + // which is not really a good thing lol + // we probably could just memcpy from localpalette, but i dont trust -file nor autoload so + if (palettenum * 256U > (currentPaletteSize - 256) / 3) + { + CONS_Debug(DBG_RENDER, "palettenum %d out of range\n", palettenum); + pal = pFallbackFlashPal; + } + else + { + pal = &pLocalPalette[palettenum*256]; + } + #ifdef HWRENDER if (rendermode == render_opengl) - HWR_SetPalette(&pLocalPalette[palettenum*256]); + HWR_SetPalette(pal); #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) else #endif #endif if (rendermode != render_none) - I_SetPalette(&pLocalPalette[palettenum*256]); + I_SetPalette(pal); } void V_SetPaletteLump(const char *pal) -- 2.54.0 From 16cf4ede89f511967808b5e8737a9529ba891aa8 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Mar 2026 08:31:27 +0100 Subject: [PATCH 45/47] v_video: generate missing flashpals instead not sure if this is more sane than the huge ass array from before but atleast this is more accurate and can basically generate flashpals from any palette while also still working with all the colour and gamma adjustments prob needs some cleanup idk this is all rather messy lol --- src/hardware/hw_main.cpp | 4 +- src/hardware/hw_main.h | 6 - src/m_menudefs.c | 2 - src/st_stuff.c | 2 +- src/v_paldeltas.h | 525 +++++++++++++++++++++++++++++++++++++++ src/v_video.c | 196 +++++++-------- 6 files changed, 614 insertions(+), 121 deletions(-) create mode 100644 src/v_paldeltas.h diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 15434ec20..e6ce072cf 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -242,7 +242,6 @@ consvar_t cv_glportals = {"gr_portals", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, consvar_t cv_glpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_glpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_glpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_glpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_glflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_glpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_gltexturedepth = {"gr_texturedepth", "32 bits", CV_CALL|CV_SAVE, gltexdepth_cons_t, CV_gltextureformat_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -5913,7 +5912,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_glpaletterendering); CV_RegisterVar(&cv_glpalettedepth); - CV_RegisterVar(&cv_glflashpal); } // -------------------------------------------------------------------------- @@ -6070,7 +6068,7 @@ static void HWR_DoPostProcessor(void) { // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (!HWR_PalRenderFlashpal()) + if (!HWR_ShouldUsePaletteRendering()) { const player_t *player = &players[displayplayers[viewssnum]]; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 8b5284acb..8a501f727 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -208,7 +208,6 @@ extern consvar_t cv_glportals; extern consvar_t cv_glpaletterendering; extern consvar_t cv_glpalettedepth; -extern consvar_t cv_glflashpal; FUNCINLINE static ATTRINLINE boolean HWR_UseShader(void) { @@ -220,11 +219,6 @@ FUNCINLINE static ATTRINLINE boolean HWR_ShouldUsePaletteRendering(void) return (cv_glpaletterendering.value && (pLocalPalette != NULL) && HWR_UseShader()); } -FUNCINLINE static ATTRINLINE boolean HWR_PalRenderFlashpal(void) -{ - return (cv_glflashpal.value && HWR_ShouldUsePaletteRendering()); -} - // Returns a pointer to the palette which should be used for caching textures. FUNCINLINE static ATTRINLINE RGBA_t *HWR_GetTexturePalette(void) { diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 00b927efd..aa3f186c8 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1023,8 +1023,6 @@ static menuitem_t OP_OpenGLOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Fallback Player 3D Model", &cv_glfallbackplayermodel, 20}, {IT_STRING | IT_CVAR, NULL, "Shaders", &cv_glshaders, 25}, {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_glpaletterendering, 30}, - {IT_STRING | IT_CVAR, NULL, "Palette Rendering Flashpals",&cv_glflashpal, 35}, - //{IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_glsecbright, 40}, {IT_STRING | IT_CVAR, NULL, "Texture Quality", &cv_gltexturedepth, 45}, {IT_STRING | IT_CVAR, NULL, "Texture Filter", &cv_glfiltermode, 50}, diff --git a/src/st_stuff.c b/src/st_stuff.c index 6dc7111f3..64bc4dc00 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -180,7 +180,7 @@ static void ST_doPaletteStuff(void) INT32 palette = 0; #ifdef HWRENDER - if (rendermode == render_opengl && !HWR_PalRenderFlashpal()) + if (rendermode == render_opengl && !HWR_ShouldUsePaletteRendering()) return; #endif diff --git a/src/v_paldeltas.h b/src/v_paldeltas.h new file mode 100644 index 000000000..30fc86dfc --- /dev/null +++ b/src/v_paldeltas.h @@ -0,0 +1,525 @@ +#ifndef H_PALDELTA +#define H_PALDELTA + +// those are the differences in palette indices between the main srb2 playpal and its white and nuke subpalettes +// this is probably not the best way of doing any of this, but it works lol + +static const INT16 pPaletteDeltaFlash[256][3] = { + { 6, 6, 6}, + { 12, 12, 12}, + { 18, 18, 18}, + { 24, 24, 24}, + { 30, 30, 30}, + { 36, 36, 36}, + { 42, 42, 42}, + { 48, 48, 48}, + { 54, 54, 54}, + { 60, 60, 60}, + { 66, 66, 66}, + { 72, 72, 72}, + { 78, 78, 78}, + { 84, 84, 84}, + { 90, 90, 90}, + { 95, 95, 95}, + { 101, 101, 101}, + { 107, 107, 107}, + { 113, 113, 113}, + { 119, 119, 119}, + { 125, 125, 125}, + { 131, 131, 131}, + { 137, 137, 137}, + { 143, 143, 143}, + { 149, 149, 149}, + { 155, 155, 155}, + { 161, 161, 161}, + { 167, 167, 167}, + { 173, 173, 173}, + { 179, 179, 179}, + { 185, 185, 185}, + { 191, 191, 191}, + { 48, 66, 84}, + { 54, 71, 89}, + { 60, 77, 95}, + { 66, 83, 100}, + { 72, 88, 105}, + { 79, 94, 111}, + { 85, 99, 117}, + { 91, 105, 123}, + { 96, 111, 129}, + { 102, 117, 135}, + { 108, 123, 141}, + { 114, 128, 146}, + { 120, 134, 152}, + { 127, 140, 158}, + { 133, 145, 163}, + { 140, 152, 170}, + { 48, 98, 134}, + { 57, 104, 137}, + { 63, 107, 140}, + { 69, 110, 143}, + { 75, 116, 146}, + { 84, 119, 149}, + { 90, 125, 152}, + { 95, 128, 155}, + { 101, 131, 158}, + { 110, 137, 161}, + { 119, 140, 164}, + { 128, 143, 167}, + { 134, 149, 170}, + { 143, 155, 173}, + { 152, 158, 176}, + { 158, 164, 179}, + { 0, 15, 24}, + { 0, 21, 33}, + { 0, 27, 42}, + { 0, 33, 51}, + { 0, 36, 57}, + { 0, 42, 66}, + { 0, 48, 75}, + { 0, 51, 81}, + { 0, 57, 93}, + { 6, 63, 98}, + { 12, 69, 104}, + { 18, 75, 110}, + { 24, 81, 116}, + { 30, 87, 122}, + { 36, 93, 128}, + { 39, 95, 131}, + { 0, 12, 26}, + { 0, 26, 52}, + { 0, 39, 78}, + { 0, 52, 102}, + { 0, 65, 127}, + { 0, 78, 150}, + { 0, 91, 172}, + { 0, 102, 191}, + { 9, 108, 191}, + { 19, 114, 191}, + { 29, 120, 191}, + { 39, 127, 191}, + { 48, 133, 191}, + { 58, 139, 191}, + { 68, 145, 191}, + { 78, 150, 191}, + { 0, 0, 12}, + { 0, 0, 36}, + { 0, 0, 60}, + { 0, 0, 84}, + { 0, 0, 107}, + { 0, 0, 131}, + { 0, 0, 155}, + { 0, 0, 179}, + { 0, 0, 191}, + { 36, 36, 191}, + { 60, 60, 191}, + { 84, 84, 191}, + { 107, 107, 191}, + { 131, 131, 191}, + { 155, 155, 191}, + { 179, 179, 191}, + { 0, 0, 104}, + { 15, 27, 125}, + { 30, 51, 140}, + { 45, 75, 155}, + { 60, 98, 167}, + { 75, 122, 176}, + { 90, 140, 185}, + { 104, 158, 191}, + { 0, 0, 0}, + { 0, 24, 24}, + { 0, 48, 48}, + { 0, 72, 72}, + { 0, 95, 95}, + { 0, 119, 119}, + { 0, 143, 143}, + { 0, 167, 167}, + { 0, 191, 191}, + { 12, 191, 191}, + { 24, 191, 191}, + { 36, 191, 191}, + { 48, 191, 191}, + { 60, 191, 191}, + { 72, 191, 191}, + { 84, 191, 191}, + { 95, 191, 191}, + { 107, 191, 191}, + { 119, 191, 191}, + { 131, 191, 191}, + { 143, 191, 191}, + { 155, 191, 191}, + { 167, 191, 191}, + { 179, 191, 191}, + { 0, 54, 54}, + { 9, 69, 69}, + { 18, 84, 84}, + { 27, 98, 98}, + { 39, 110, 110}, + { 48, 122, 122}, + { 57, 131, 131}, + { 66, 143, 143}, + { 85, 156, 191}, + { 91, 161, 191}, + { 96, 166, 191}, + { 102, 172, 191}, + { 108, 177, 191}, + { 114, 182, 191}, + { 120, 187, 191}, + { 127, 191, 191}, + { 101, 0, 131}, + { 106, 11, 134}, + { 111, 23, 138}, + { 117, 35, 142}, + { 123, 47, 145}, + { 129, 59, 149}, + { 134, 71, 153}, + { 140, 83, 157}, + { 145, 95, 160}, + { 151, 106, 164}, + { 157, 118, 168}, + { 162, 130, 172}, + { 168, 142, 175}, + { 173, 154, 179}, + { 179, 166, 183}, + { 185, 179, 187}, + { 24, 0, 65}, + { 42, 20, 80}, + { 61, 41, 95}, + { 79, 61, 110}, + { 97, 82, 124}, + { 115, 101, 139}, + { 135, 123, 154}, + { 153, 143, 169}, + { 191, 0, 191}, + { 191, 24, 191}, + { 191, 48, 191}, + { 191, 72, 191}, + { 191, 95, 191}, + { 191, 119, 191}, + { 191, 143, 191}, + { 191, 167, 191}, + { 0, 107, 0}, + { 0, 191, 0}, + { 24, 191, 24}, + { 48, 191, 48}, + { 72, 191, 72}, + { 95, 191, 95}, + { 119, 191, 119}, + { 143, 191, 143}, + { 16, 16, 9}, + { 44, 44, 22}, + { 73, 73, 36}, + { 101, 101, 51}, + { 127, 127, 66}, + { 142, 142, 93}, + { 156, 156, 121}, + { 170, 170, 151}, + { 31, 10, 0}, + { 48, 15, 0}, + { 64, 21, 0}, + { 79, 25, 0}, + { 95, 30, 0}, + { 111, 36, 0}, + { 127, 41, 0}, + { 143, 48, 0}, + { 149, 73, 24}, + { 155, 84, 48}, + { 161, 101, 72}, + { 167, 119, 95}, + { 191, 48, 48}, + { 191, 95, 95}, + { 191, 119, 119}, + { 191, 143, 143}, + { 18, 18, 0}, + { 42, 42, 0}, + { 61, 61, 0}, + { 86, 86, 0}, + { 104, 104, 0}, + { 129, 129, 0}, + { 154, 154, 0}, + { 172, 172, 0}, + { 191, 191, 0}, + { 191, 191, 18}, + { 191, 191, 36}, + { 191, 191, 55}, + { 191, 191, 74}, + { 191, 191, 92}, + { 191, 191, 110}, + { 191, 191, 129}, + { 191, 191, 131}, + { 191, 191, 143}, + { 191, 191, 149}, + { 191, 191, 161}, + { 191, 191, 167}, + { 191, 191, 179}, + { 191, 191, 185}, + { 191, 0, 0}, + { 36, 95, 36}, + { 54, 107, 54}, + { 72, 119, 72}, + { 90, 131, 90}, + { 107, 143, 107}, + { 125, 155, 125}, + { 143, 167, 143}, + { 161, 179, 161} +}; + +static const INT16 pPaletteDeltaNuke[256][3] = { + { 6,-133,-133}, + { 12,-125,-125}, + { 18,-117,-117}, + { 24,-109,-109}, + { 30,-101,-101}, + { 36, -93, -93}, + { 42, -85, -85}, + { 48, -77, -77}, + { 54, -69, -69}, + { 60, -61, -61}, + { 66, -53, -53}, + { 72, -45, -45}, + { 78, -37, -37}, + { 84, -29, -29}, + { 90, -21, -21}, + { 95, -14, -14}, + { 101, -6, -6}, + { 107, 2, 2}, + { 113, 10, 10}, + { 119, 18, 18}, + { 125, 26, 26}, + { 131, 34, 34}, + { 137, 42, 42}, + { 143, 50, 50}, + { 149, 58, 58}, + { 155, 66, 66}, + { 161, 74, 74}, + { 167, 82, 82}, + { 173, 90, 90}, + { 179, 98, 98}, + { 185, 106, 106}, + { 191, 113, 113}, + { 48, -53, -29}, + { 54, -46, -22}, + { 60, -38, -14}, + { 66, -30, -7}, + { 72, -23, 0}, + { 79, -15, 8}, + { 85, -8, 16}, + { 91, -1, 23}, + { 96, 7, 31}, + { 102, 15, 39}, + { 108, 23, 47}, + { 114, 30, 54}, + { 120, 38, 62}, + { 127, 46, 70}, + { 133, 53, 77}, + { 140, 62, 86}, + { 48, -10, 38}, + { 57, -2, 42}, + { 63, 2, 46}, + { 69, 6, 50}, + { 75, 14, 54}, + { 84, 18, 58}, + { 90, 26, 62}, + { 95, 30, 66}, + { 101, 34, 70}, + { 110, 42, 74}, + { 119, 46, 78}, + { 128, 50, 82}, + { 134, 58, 86}, + { 143, 66, 90}, + { 152, 70, 94}, + { 158, 78, 98}, + { 0,-121,-109}, + { 0,-113, -97}, + { 0,-105, -85}, + { 0, -97, -73}, + { 0, -93, -65}, + { 0, -85, -53}, + { 0, -77, -41}, + { 0, -73, -33}, + { 0, -65, -17}, + { 6, -57, -10}, + { 12, -49, -2}, + { 18, -41, 6}, + { 24, -33, 14}, + { 30, -25, 22}, + { 36, -17, 30}, + { 39, -14, 34}, + { 0,-124,-106}, + { 0,-106, -71}, + { 0, -89, -37}, + { 0, -71, -4}, + { 0, -54, 28}, + { 0, -37, 59}, + { 0, -20, 88}, + { 0, -4, 113}, + { 9, 4, 113}, + { 19, 12, 113}, + { 29, 20, 113}, + { 39, 28, 113}, + { 48, 36, 113}, + { 58, 44, 113}, + { 68, 52, 113}, + { 78, 59, 113}, + { 0,-141,-125}, + { 0,-141, -93}, + { 0,-141, -61}, + { 0,-141, -29}, + { 0,-141, 2}, + { 0,-141, 34}, + { 0,-141, 66}, + { 0,-141, 98}, + { 0,-141, 113}, + { 36, -93, 113}, + { 60, -61, 113}, + { 84, -29, 113}, + { 107, 2, 113}, + { 131, 34, 113}, + { 155, 66, 113}, + { 179, 98, 113}, + { 0,-141, -2}, + { 15,-105, 26}, + { 30, -73, 46}, + { 45, -41, 66}, + { 60, -10, 82}, + { 75, 22, 94}, + { 90, 46, 106}, + { 104, 70, 113}, + { 0,-141,-141}, + { 0,-109,-109}, + { 0, -77, -77}, + { 0, -45, -45}, + { 0, -14, -14}, + { 0, 18, 18}, + { 0, 50, 50}, + { 0, 82, 82}, + { 0, 113, 113}, + { 12, 113, 113}, + { 24, 113, 113}, + { 36, 113, 113}, + { 48, 113, 113}, + { 60, 113, 113}, + { 72, 113, 113}, + { 84, 113, 113}, + { 95, 113, 113}, + { 107, 113, 113}, + { 119, 113, 113}, + { 131, 113, 113}, + { 143, 113, 113}, + { 155, 113, 113}, + { 167, 113, 113}, + { 179, 113, 113}, + { 0, -69, -69}, + { 9, -49, -49}, + { 18, -29, -29}, + { 27, -10, -10}, + { 39, 6, 6}, + { 48, 22, 22}, + { 57, 34, 34}, + { 66, 50, 50}, + { 85, 67, 113}, + { 91, 74, 113}, + { 96, 81, 113}, + { 102, 88, 113}, + { 108, 95, 113}, + { 114, 102, 113}, + { 120, 108, 113}, + { 127, 113, 113}, + { 101,-141, 34}, + { 106,-126, 38}, + { 111,-110, 43}, + { 117, -94, 48}, + { 123, -78, 53}, + { 129, -62, 58}, + { 134, -46, 63}, + { 140, -30, 68}, + { 145, -14, 73}, + { 151, 1, 78}, + { 157, 17, 83}, + { 162, 33, 88}, + { 168, 49, 93}, + { 173, 65, 98}, + { 179, 81, 103}, + { 185, 98, 109}, + { 24,-141, -54}, + { 42,-114, -34}, + { 61, -86, -14}, + { 79, -59, 6}, + { 97, -32, 25}, + { 115, -6, 45}, + { 135, 23, 65}, + { 153, 50, 84}, + { 191,-141, 113}, + { 191,-109, 113}, + { 191, -77, 113}, + { 191, -45, 113}, + { 191, -14, 113}, + { 191, 18, 113}, + { 191, 50, 113}, + { 191, 82, 113}, + { 0, 2,-141}, + { 0, 113,-141}, + { 24, 113,-109}, + { 48, 113, -77}, + { 72, 113, -45}, + { 95, 113, -14}, + { 119, 113, 18}, + { 143, 113, 50}, + { 16,-119,-129}, + { 44, -82,-111}, + { 73, -43, -92}, + { 101, -6, -73}, + { 127, 29, -53}, + { 142, 48, -17}, + { 156, 67, 21}, + { 170, 86, 61}, + { 31,-127,-141}, + { 48,-121,-141}, + { 64,-113,-141}, + { 79,-107,-141}, + { 95,-100,-141}, + { 111, -93,-141}, + { 127, -86,-141}, + { 143, -77,-141}, + { 149, -43,-109}, + { 155, -29, -77}, + { 161, -6, -45}, + { 167, 18, -14}, + { 191, -77, -77}, + { 191, -14, -14}, + { 191, 18, 18}, + { 191, 50, 50}, + { 18,-117,-141}, + { 42, -84,-141}, + { 61, -59,-141}, + { 86, -26,-141}, + { 104, -2,-141}, + { 129, 31,-141}, + { 154, 64,-141}, + { 172, 89,-141}, + { 191, 113,-141}, + { 191, 113,-117}, + { 191, 113, -92}, + { 191, 113, -67}, + { 191, 113, -42}, + { 191, 113, -18}, + { 191, 113, 6}, + { 191, 113, 31}, + { 191, 113, 34}, + { 191, 113, 50}, + { 191, 113, 58}, + { 191, 113, 74}, + { 191, 113, 82}, + { 191, 113, 98}, + { 191, 113, 106}, + { 191,-141,-141}, + { 36, -14, -93}, + { 54, 2, -69}, + { 72, 18, -45}, + { 90, 34, -21}, + { 107, 50, 2}, + { 125, 66, 26}, + { 143, 82, 50}, + { 161, 98, 74} +}; + +#endif diff --git a/src/v_video.c b/src/v_video.c index 2aa680153..940dd190d 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -91,97 +91,7 @@ consvar_t cv_menucaps = {"menucaps", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NUL // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; RGBA_t *pGammaCorrectedPalette = NULL; - -// huge ass array les gooooooo! -// this is basically the white flashpal byte for byte from our main palette lmao -static RGBA_t pFallbackFlashPal[] = { - {.s={253, 253, 253, 255}}, {.s={251, 251, 251, 255}}, {.s={249, 249, 249, 255}}, - {.s={247, 247, 247, 255}}, {.s={245, 245, 245, 255}}, {.s={243, 243, 243, 255}}, - {.s={241, 241, 241, 255}}, {.s={239, 239, 239, 255}}, {.s={237, 237, 237, 255}}, - {.s={235, 235, 235, 255}}, {.s={233, 233, 233, 255}}, {.s={231, 231, 231, 255}}, - {.s={229, 229, 229, 255}}, {.s={227, 227, 227, 255}}, {.s={225, 225, 225, 255}}, - {.s={223, 223, 223, 255}}, {.s={221, 221, 221, 255}}, {.s={219, 219, 219, 255}}, - {.s={217, 217, 217, 255}}, {.s={215, 215, 215, 255}}, {.s={213, 213, 213, 255}}, - {.s={211, 211, 211, 255}}, {.s={209, 209, 209, 255}}, {.s={207, 207, 207, 255}}, - {.s={205, 205, 205, 255}}, {.s={203, 203, 203, 255}}, {.s={201, 201, 201, 255}}, - {.s={199, 199, 199, 255}}, {.s={197, 197, 197, 255}}, {.s={195, 195, 195, 255}}, - {.s={193, 193, 193, 255}}, {.s={192, 192, 192, 255}}, {.s={239, 233, 227, 255}}, - {.s={237, 231, 225, 255}}, {.s={235, 229, 223, 255}}, {.s={233, 227, 221, 255}}, - {.s={231, 225, 219, 255}}, {.s={229, 223, 217, 255}}, {.s={227, 221, 215, 255}}, - {.s={225, 220, 214, 255}}, {.s={223, 218, 212, 255}}, {.s={220, 216, 210, 255}}, - {.s={218, 214, 208, 255}}, {.s={216, 212, 206, 255}}, {.s={214, 210, 204, 255}}, - {.s={212, 208, 202, 255}}, {.s={210, 206, 200, 255}}, {.s={208, 204, 198, 255}}, - {.s={239, 222, 210, 255}}, {.s={236, 220, 209, 255}}, {.s={234, 219, 208, 255}}, - {.s={232, 218, 207, 255}}, {.s={230, 216, 206, 255}}, {.s={227, 215, 205, 255}}, - {.s={225, 213, 204, 255}}, {.s={223, 212, 203, 255}}, {.s={221, 211, 202, 255}}, - {.s={218, 209, 201, 255}}, {.s={215, 208, 200, 255}}, {.s={212, 207, 199, 255}}, - {.s={210, 205, 198, 255}}, {.s={207, 203, 197, 255}}, {.s={204, 202, 196, 255}}, - {.s={202, 200, 195, 255}}, {.s={255, 250, 247, 255}}, {.s={255, 248, 244, 255}}, - {.s={255, 246, 241, 255}}, {.s={255, 244, 238, 255}}, {.s={255, 243, 236, 255}}, - {.s={255, 241, 233, 255}}, {.s={255, 239, 230, 255}}, {.s={255, 238, 228, 255}}, - {.s={255, 236, 224, 255}}, {.s={253, 234, 222, 255}}, {.s={251, 232, 220, 255}}, - {.s={249, 230, 218, 255}}, {.s={247, 228, 216, 255}}, {.s={245, 226, 214, 255}}, - {.s={243, 224, 212, 255}}, {.s={242, 223, 211, 255}}, {.s={255, 250, 246, 255}}, - {.s={255, 246, 237, 255}}, {.s={255, 242, 229, 255}}, {.s={255, 237, 220, 255}}, - {.s={255, 233, 213, 255}}, {.s={255, 229, 205, 255}}, {.s={255, 225, 198, 255}}, - {.s={255, 220, 192, 255}}, {.s={252, 218, 192, 255}}, {.s={248, 216, 192, 255}}, - {.s={245, 214, 192, 255}}, {.s={242, 213, 192, 255}}, {.s={238, 211, 192, 255}}, - {.s={235, 209, 192, 255}}, {.s={232, 207, 192, 255}}, {.s={229, 205, 192, 255}}, - {.s={255, 255, 251, 255}}, {.s={255, 255, 243, 255}}, {.s={255, 255, 235, 255}}, - {.s={255, 255, 227, 255}}, {.s={255, 255, 219, 255}}, {.s={255, 255, 211, 255}}, - {.s={255, 255, 203, 255}}, {.s={255, 255, 195, 255}}, {.s={255, 255, 192, 255}}, - {.s={243, 243, 192, 255}}, {.s={235, 235, 192, 255}}, {.s={227, 227, 192, 255}}, - {.s={219, 219, 192, 255}}, {.s={211, 211, 192, 255}}, {.s={203, 203, 192, 255}}, - {.s={195, 195, 192, 255}}, {.s={255, 255, 220, 255}}, {.s={250, 246, 213, 255}}, - {.s={245, 238, 208, 255}}, {.s={240, 230, 203, 255}}, {.s={235, 222, 199, 255}}, - {.s={230, 214, 196, 255}}, {.s={225, 208, 193, 255}}, {.s={220, 202, 192, 255}}, - {.s={255, 255, 255, 255}}, {.s={255, 247, 247, 255}}, {.s={255, 239, 239, 255}}, - {.s={255, 231, 231, 255}}, {.s={255, 223, 223, 255}}, {.s={255, 215, 215, 255}}, - {.s={255, 207, 207, 255}}, {.s={255, 199, 199, 255}}, {.s={255, 192, 192, 255}}, - {.s={251, 192, 192, 255}}, {.s={247, 192, 192, 255}}, {.s={243, 192, 192, 255}}, - {.s={239, 192, 192, 255}}, {.s={235, 192, 192, 255}}, {.s={231, 192, 192, 255}}, - {.s={227, 192, 192, 255}}, {.s={223, 192, 192, 255}}, {.s={219, 192, 192, 255}}, - {.s={215, 192, 192, 255}}, {.s={211, 192, 192, 255}}, {.s={207, 192, 192, 255}}, - {.s={203, 192, 192, 255}}, {.s={199, 192, 192, 255}}, {.s={195, 192, 192, 255}}, - {.s={255, 237, 237, 255}}, {.s={252, 232, 232, 255}}, {.s={249, 227, 227, 255}}, - {.s={246, 222, 222, 255}}, {.s={242, 218, 218, 255}}, {.s={239, 214, 214, 255}}, - {.s={236, 211, 211, 255}}, {.s={233, 207, 207, 255}}, {.s={227, 203, 192, 255}}, - {.s={225, 201, 192, 255}}, {.s={223, 199, 192, 255}}, {.s={220, 198, 192, 255}}, - {.s={218, 196, 192, 255}}, {.s={216, 194, 192, 255}}, {.s={214, 193, 192, 255}}, - {.s={213, 192, 192, 255}}, {.s={221, 255, 211, 255}}, {.s={219, 251, 210, 255}}, - {.s={217, 247, 209, 255}}, {.s={215, 243, 208, 255}}, {.s={214, 239, 206, 255}}, - {.s={212, 235, 205, 255}}, {.s={210, 231, 204, 255}}, {.s={208, 227, 203, 255}}, - {.s={206, 223, 201, 255}}, {.s={205, 219, 200, 255}}, {.s={203, 215, 199, 255}}, - {.s={201, 211, 198, 255}}, {.s={199, 207, 196, 255}}, {.s={197, 203, 195, 255}}, - {.s={195, 199, 194, 255}}, {.s={193, 195, 192, 255}}, {.s={246, 255, 233, 255}}, - {.s={241, 248, 228, 255}}, {.s={234, 241, 223, 255}}, {.s={228, 234, 218, 255}}, - {.s={222, 228, 213, 255}}, {.s={216, 221, 208, 255}}, {.s={210, 214, 203, 255}}, - {.s={204, 207, 199, 255}}, {.s={192, 255, 192, 255}}, {.s={192, 247, 192, 255}}, - {.s={192, 239, 192, 255}}, {.s={192, 231, 192, 255}}, {.s={192, 223, 192, 255}}, - {.s={192, 215, 192, 255}}, {.s={192, 207, 192, 255}}, {.s={192, 199, 192, 255}}, - {.s={255, 219, 255, 255}}, {.s={255, 192, 255, 255}}, {.s={247, 192, 247, 255}}, - {.s={239, 192, 239, 255}}, {.s={231, 192, 231, 255}}, {.s={223, 192, 223, 255}}, - {.s={215, 192, 215, 255}}, {.s={207, 192, 207, 255}}, {.s={249, 249, 252, 255}}, - {.s={240, 240, 247, 255}}, {.s={230, 230, 242, 255}}, {.s={221, 221, 238, 255}}, - {.s={212, 212, 233, 255}}, {.s={208, 208, 224, 255}}, {.s={203, 203, 214, 255}}, - {.s={198, 198, 204, 255}}, {.s={244, 251, 255, 255}}, {.s={239, 250, 255, 255}}, - {.s={234, 248, 255, 255}}, {.s={228, 246, 255, 255}}, {.s={223, 244, 255, 255}}, - {.s={218, 243, 255, 255}}, {.s={213, 241, 255, 255}}, {.s={207, 239, 255, 255}}, - {.s={205, 230, 247, 255}}, {.s={203, 227, 239, 255}}, {.s={201, 221, 231, 255}}, - {.s={199, 215, 223, 255}}, {.s={192, 239, 239, 255}}, {.s={192, 223, 223, 255}}, - {.s={192, 215, 215, 255}}, {.s={192, 207, 207, 255}}, {.s={249, 249, 255, 255}}, - {.s={240, 240, 255, 255}}, {.s={234, 234, 255, 255}}, {.s={226, 226, 255, 255}}, - {.s={220, 220, 255, 255}}, {.s={212, 212, 255, 255}}, {.s={204, 204, 255, 255}}, - {.s={197, 197, 255, 255}}, {.s={192, 192, 255, 255}}, {.s={192, 192, 249, 255}}, - {.s={192, 192, 242, 255}}, {.s={192, 192, 236, 255}}, {.s={192, 192, 230, 255}}, - {.s={192, 192, 224, 255}}, {.s={192, 192, 218, 255}}, {.s={192, 192, 212, 255}}, - {.s={192, 192, 211, 255}}, {.s={192, 192, 207, 255}}, {.s={192, 192, 205, 255}}, - {.s={192, 192, 201, 255}}, {.s={192, 192, 199, 255}}, {.s={192, 192, 195, 255}}, - {.s={192, 192, 193, 255}}, {.s={192, 255, 255, 255}}, {.s={243, 223, 243, 255}}, - {.s={237, 219, 237, 255}}, {.s={231, 215, 231, 255}}, {.s={225, 211, 225, 255}}, - {.s={219, 207, 219, 255}}, {.s={213, 203, 213, 255}}, {.s={207, 199, 207, 255}}, - {.s={201, 195, 201, 255}} -}; +static RGBA_t *pFallbackFlashPal = NULL; static size_t currentPaletteSize; @@ -500,6 +410,58 @@ UINT32 V_GammaCorrect(UINT32 input, double power) return result.rgba; } +#include "v_paldeltas.h" +// remaps a palette with given "deltas" +// this is used with premade deltas between the srb2 palette and its both flashpals +// so we may approximate generate our own, should the current palette miss them +static void ApplyPaletteDelta(const RGBA_t *pal_in, RGBA_t *pal_out, const INT16 pal_delta[][3]) +{ + size_t i; + + for (i = 0; i < 256; i++) + { + INT16 r = (INT16)pal_in[i].s.red + pal_delta[i][0]; + INT16 g = (INT16)pal_in[i].s.green + pal_delta[i][1]; + INT16 b = (INT16)pal_in[i].s.blue + pal_delta[i][2]; + pal_out[i].s.red = (UINT8)CLAMP(r, 0 , 255); + pal_out[i].s.green = (UINT8)CLAMP(g, 0 , 255); + pal_out[i].s.blue = (UINT8)CLAMP(b, 0 , 255); + pal_out[i].s.alpha = 0xFF; // pal_in[i].s.alpha + } +} + +static void GenerateFlashPalettes(void) +{ + size_t i, palsize; + RGBA_t *pFlashPalGammaCorrectedPalette = NULL; + + // generate flashpalettes if the current palette does not provide any subpalettes + if (currentPaletteSize >= (14 * (256 * 3))) // 14 palettes are in playpal + return; + + palsize = (2*256); + + pFallbackFlashPal = Z_Malloc(sizeof(*pFallbackFlashPal)*palsize, PU_STATIC, NULL); + pFlashPalGammaCorrectedPalette = Z_Malloc(sizeof (*pFlashPalGammaCorrectedPalette)*palsize, PU_STATIC, NULL); + + // apply our deltas to the palettes to get the white and red "flashes" + ApplyPaletteDelta(pLocalPalette, pFallbackFlashPal, pPaletteDeltaFlash); + ApplyPaletteDelta(pLocalPalette, pFallbackFlashPal+256, pPaletteDeltaNuke); + + // apply colour and gamma correction if needed + if (Cubeapply) + { + for (i = 0; i < palsize; i++) + { + pFlashPalGammaCorrectedPalette[i].rgba = V_GammaDecode(pFallbackFlashPal[i].rgba); + V_CubeApply(&pFlashPalGammaCorrectedPalette[i]); + pFallbackFlashPal[i].rgba = V_GammaEncode(pFlashPalGammaCorrectedPalette[i].rgba); + } + } + + Z_Free(pFlashPalGammaCorrectedPalette); +} + // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { @@ -519,6 +481,8 @@ static void LoadPalette(const char *lumpname) Z_Free(pLocalPalette); Z_Free(pGammaCorrectedPalette); + Z_Free(pFallbackFlashPal); + pFallbackFlashPal = NULL; pLocalPalette = Z_Malloc(sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL); pGammaCorrectedPalette = Z_Malloc(sizeof (*pGammaCorrectedPalette)*palsize, PU_STATIC, NULL); @@ -538,12 +502,19 @@ static void LoadPalette(const char *lumpname) pLocalPalette[i].s.alpha = 0xFF; pGammaCorrectedPalette[i].rgba = V_GammaDecode(pLocalPalette[i].rgba); + } - if (!Cubeapply) - continue; + GenerateFlashPalettes(); - V_CubeApply(&pGammaCorrectedPalette[i]); - pLocalPalette[i].rgba = V_GammaEncode(pGammaCorrectedPalette[i].rgba); + // gotta apply any colour and gamma adjustments afterwards + // so we dont double apply it to the generated flashpals + if (Cubeapply) + { + for (i = 0; i < palsize; i++) + { + V_CubeApply(&pGammaCorrectedPalette[i]); + pLocalPalette[i].rgba = V_GammaEncode(pGammaCorrectedPalette[i].rgba); + } } } @@ -646,25 +617,32 @@ void V_SetPalette(INT32 palettenum) if (palettenum == 0) { palettenum = cv_palettenum.value; - - if (palettenum * 256U > (currentPaletteSize - 256) / 3) - { - CONS_Alert(CONS_WARNING, "cv_palettenum %d out of range\n", palettenum); - palettenum = 0; - } } } - // if the palettenum goes beyond our current palette, then just fallback to the white flash pal - // our srb2 palette mostly just contains that as subpalettes, so everything uses this - // and makes it a good fallback case - // otherwise we will throw random garbage to the renderer which calls memcpy on it - // which is not really a good thing lol - // we probably could just memcpy from localpalette, but i dont trust -file nor autoload so - if (palettenum * 256U > (currentPaletteSize - 256) / 3) + // in many cases custom palettes do not provide the needed subpalettes for flashpals to work + // before this would mean the renderer gets passed random data out of allocated memory bounds + // which was not very cool :chonkbuncle: + // gladly 2.1 only actually has 2 different subpalettes + // one for "white flash" and one red/pinkish one for nuke + // since we checked the palette earlier we should have generated those ourselves + if (((size_t)palettenum >= currentPaletteSize / (256 * 3))) { CONS_Debug(DBG_RENDER, "palettenum %d out of range\n", palettenum); - pal = pFallbackFlashPal; + + // if for some reason we did not generate flashpals + // just fall back to the main palette i guess? + if (pFallbackFlashPal != NULL) + { + if (palettenum == PAL_NUKE) + pal = &pFallbackFlashPal[256]; + else + pal = pFallbackFlashPal; + } + else + { + pal = pLocalPalette; + } } else { -- 2.54.0 From 6430150b63b9503e7e6cc97b3af13ec5125edbd5 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Mar 2026 17:53:16 +0100 Subject: [PATCH 46/47] fix parts of png info text for screenshots not being null terminated in some cases --- src/m_misc.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/m_misc.c b/src/m_misc.c index ee17e2098..97777a979 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -788,10 +788,10 @@ static void M_PNGText(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png else snprintf(locationtxt, 40, "Unknown"); - memset(png_infotext,0x00,sizeof (png_infotext)); + memset(png_infotext, 0x00, sizeof(png_infotext)); for (i = 0; i < SRB2PNGTXT; i++) - png_infotext[i].key = keytxt[i]; + png_infotext[i].key = keytxt[i]; png_infotext[0].text = titletxt; if (movie) @@ -804,9 +804,15 @@ static void M_PNGText(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png png_infotext[5].text = locationtxt; png_infotext[6].text = interfacetxt; png_infotext[7].text = rendermodetxt; - png_infotext[8].text = strncpy(ctrevision, comprevision, sizeof(ctrevision)-1); - png_infotext[9].text = strncpy(ctdate, compdate, sizeof(ctdate)-1); - png_infotext[10].text = strncpy(cttime, comptime, sizeof(cttime)-1); + strncpy(ctrevision, comprevision, sizeof(ctrevision)-1); + ctrevision[sizeof(ctrevision)-1] = '\0'; + png_infotext[8].text = ctrevision; + strncpy(ctdate, compdate, sizeof(ctdate)-1); + ctdate[sizeof(ctdate)-1] = '\0'; + png_infotext[9].text = ctdate; + strncpy(cttime, comptime, sizeof(cttime)-1); + cttime[sizeof(cttime)-1] = '\0'; + png_infotext[10].text = cttime; png_set_text(png_ptr, png_info_ptr, png_infotext, SRB2PNGTXT); #undef SRB2PNGTXT @@ -1564,6 +1570,7 @@ char *M_GetToken(const char *inputString) { startPos = endPos; } + if (stringToUse == NULL) return NULL; @@ -1634,7 +1641,8 @@ char *M_GetToken(const char *inputString) } // If the end of the string is reached, no token is to be read - if (startPos == stringLength) { + if (startPos == stringLength) + { endPos = stringLength; return NULL; } @@ -1644,7 +1652,7 @@ char *M_GetToken(const char *inputString) || stringToUse[startPos] == '}') { endPos = startPos + 1; - texturesToken = (char *)Z_Malloc(2*sizeof(char),PU_STATIC,NULL); + texturesToken = (char *)Z_Malloc(2*sizeof(char), PU_STATIC, NULL); texturesToken[0] = stringToUse[startPos]; texturesToken[1] = '\0'; return texturesToken; @@ -1855,8 +1863,10 @@ int M_PathParts(const char *path) int n; const char *p; const char *t; + if (path == NULL) return 0; + for (n = 0, p = path ;; ++n) { t = p; @@ -1869,6 +1879,7 @@ int M_PathParts(const char *path) break; } } + return n; } @@ -1911,7 +1922,9 @@ void M_MkdirEachUntil(const char *cpath, int start, int end, int mode) if (!( p = strchr(p, PATHSEP[0]) )) return; } + p += strspn(p, PATHSEP); + for (;;) { if (end > 0 && !--end) -- 2.54.0 From 9ee535066e8aa44a4fc07d0ebb21ac809ca33642 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 3 Mar 2026 02:22:02 +0100 Subject: [PATCH 47/47] =?UTF-8?q?OpenGL:=20initialize=20all=20FSurfaceInfo?= =?UTF-8?q?=C2=B4s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit seen this a bunch of times now that occasionally something tries to access uninit values from a surface info since those are really small we just always init them now --- src/hardware/hw_draw.c | 14 +++++++------- src/hardware/hw_main.cpp | 22 ++++++++++------------ src/hardware/hw_md2.c | 5 ++--- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 4797f21de..3602cef1b 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -222,7 +222,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p if (alphalevel) { - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; switch (alphalevel) @@ -385,7 +385,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // clip it since it is used for bunny scroll in doom I if (alphalevel) { - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; switch (alphalevel) @@ -490,7 +490,7 @@ void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum) void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) { FOutVector v[4]; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; FBITFIELD poly_flags = PF_NoTexture|PF_Modulated|PF_NoDepthTest; v[0].x = v[3].x = -1.0f; @@ -543,7 +543,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) void HWR_DrawConsoleBack(UINT32 color, INT32 height) { FOutVector v[4]; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; // setup some neat-o translucency effect if (!height) //cool hack 0 height is full height @@ -598,7 +598,7 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) { FOutVector v[4]; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; float fx, fy, fw, fh, fwait = 0; RGBA_t *palette; @@ -702,7 +702,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 options) { FOutVector v[4]; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; float fx, fy, fw, fh; if (w < 0 || h < 0) @@ -820,7 +820,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) { FOutVector v[4]; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; float fx, fy, fw, fh; if (w < 0 || h < 0) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e6ce072cf..bf11f0c7c 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -550,7 +550,7 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope, const sector_t // Render a floor or ceiling convex polygon static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; FOutVector *v3d; polyvertex_t *pv; pslope_t *slope = NULL; @@ -1375,7 +1375,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom extracolormap_t *colormap = gl_frontsector->extra_colormap; lightnum = HWR_CalcWallLight(lightnum, gl_curline, colormap); - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; Surf.PolyColor.s.alpha = 255; @@ -2674,7 +2674,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, float scrollx = 0.0f, scrolly = 0.0f; float anglef = 0.0f, cosangf = 0.0f, sinangf = 0.0f; angle_t angle = 0; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; fixed_t tempxsow, tempytow; size_t nrPlaneVerts; @@ -2841,9 +2841,8 @@ static void HWR_AddPolyObjectPlanes(void) light = R_GetPlaneLight(gl_frontsector, polyobjsector->floorheight, true); if (po_ptrs[i]->translucency > 0) { - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; FBITFIELD blendmode; - memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->floorpic].lumpnum, po_ptrs[i], false, polyobjsector->floorheight, (light == -1 ? gl_frontsector->lightlevel : *gl_frontsector->lightlist[light].lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, (light == -1 ? gl_frontsector->extra_colormap : gl_frontsector->lightlist[light].extra_colormap)); @@ -2864,9 +2863,8 @@ static void HWR_AddPolyObjectPlanes(void) light = R_GetPlaneLight(gl_frontsector, polyobjsector->ceilingheight, true); if (po_ptrs[i]->translucency > 0) { - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; FBITFIELD blendmode; - memset(&Surf, 0x00, sizeof(Surf)); blendmode = HWR_TranstableToAlpha(po_ptrs[i]->translucency, &Surf); HWR_AddTransparentPolyobjectFloor(levelflats[polyobjsector->ceilingpic].lumpnum, po_ptrs[i], true, polyobjsector->ceilingheight, (light == -1 ? gl_frontsector->lightlevel : *gl_frontsector->lightlist[light].lightlevel), Surf.PolyColor.s.alpha, polyobjsector, blendmode, (light == -1 ? gl_frontsector->extra_colormap : gl_frontsector->lightlist[light].extra_colormap)); @@ -3418,7 +3416,7 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t { float this_scale = 1.0f; FOutVector swallVerts[4]; - FSurfaceInfo sSurf; + FSurfaceInfo sSurf = {}; FBITFIELD blendmode = 0; fixed_t floorheight, mobjfloor; pslope_t *floorslope; @@ -3654,7 +3652,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) FOutVector baseWallVerts[4]; // This is what the verts should end up as patch_t *gpatch; GLPatch_t *hwrpatch; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; extracolormap_t *colormap; INT32 lightlevel; boolean lightset = true; @@ -3939,7 +3937,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) FOutVector wallVerts[4]; patch_t *gpatch; // sprite patch converted to hardware GLPatch_t *hwrpatch; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; FBITFIELD blend = 0; INT32 shader = SHADER_NONE; @@ -4104,7 +4102,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) FOutVector wallVerts[4]; patch_t *gpatch; // sprite patch converted to hardware GLPatch_t *hwrpatch; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; INT32 shader = SHADER_NONE; @@ -6081,7 +6079,7 @@ static void HWR_DoPostProcessor(void) {-4.0f, -4.0f, 4.0f, 0.0f, 0.0f} }; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; // This won't change if the flash palettes are changed unfortunately, but it works for its purpose if (player->flashpal == PAL_NUKE) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index d9bf41645..2aefecea1 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1099,7 +1099,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) INT32 frame = 0; INT32 nextFrame = -1; FTransform p; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; if (!cv_glmdls.value || spr->precip) return; @@ -1475,7 +1475,7 @@ void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t c patch_t *gpatch, *blendgpatch; GLPatch_t *hwrPatch = NULL, *hwrBlendPatch = NULL; FTransform p; - FSurfaceInfo Surf; + FSurfaceInfo Surf = {}; if (!md2->model) { @@ -1526,7 +1526,6 @@ void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t c if (blendgpatch) hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); - memset(&Surf, 0x00, sizeof(FSurfaceInfo)); Surf.PolyColor.rgba = 0xFFFFFFFF; Surf.PolyFlags = PF_Occlude | PF_Modulated; -- 2.54.0