From d0f09b467b3a5f1669e7a70e21f7d5082feb12f8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 02:41:06 +0200 Subject: [PATCH 01/15] Put votescreen background stuff into a struct + some refactoring and renaming - removed some unused and redundant variables - renamed some variables turns out the lua votescreens always used the animated votescreen drawer, so i renamed it to lua votescreen drawer --- src/hu_stuff.c | 2 - src/lua_hudlib.c | 16 +++---- src/p_setup.c | 29 ++++++------ src/p_setup.h | 5 -- src/y_inter.c | 116 ++++++++++++++++++++++++----------------------- src/y_inter.h | 25 +++++++++- 6 files changed, 105 insertions(+), 88 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2821c4021..b7d0c10d9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -259,8 +259,6 @@ INT32 HU_FallBackFrSpecialLetter(INT32 key) } } - - static char cechotext[1024]; static tic_t cechotimer = 0; static tic_t cechoduration = 5*TICRATE; diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index d1dce0ae0..d2db7dbea 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1262,12 +1262,12 @@ static int lib_hudsetvotebackground(lua_State *L) { if (lua_isnoneornil(L, 1)) { - if (luaVoteScreen) + if (VoteScreen.luaVoteScreen) { - free(luaVoteScreen); + free(VoteScreen.luaVoteScreen); } - luaVoteScreen = NULL; + VoteScreen.luaVoteScreen = NULL; return 0; } @@ -1279,15 +1279,15 @@ static int lib_hudsetvotebackground(lua_State *L) return luaL_argerror(L, 1, "prefix should 4 characters wide"); } - if (!luaVoteScreen) + if (!VoteScreen.luaVoteScreen) { - luaVoteScreen = (char*)malloc(5); - luaVoteScreen[4] = 0; + VoteScreen.luaVoteScreen = (char*)malloc(5); + VoteScreen.luaVoteScreen[4] = 0; } - strncpy(luaVoteScreen, prefix, 4); + strncpy(VoteScreen.luaVoteScreen, prefix, 4); - strupr(luaVoteScreen); + strupr(VoteScreen.luaVoteScreen); return 0; } diff --git a/src/p_setup.c b/src/p_setup.c index 0459a03f5..0fcc06542 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -67,6 +67,8 @@ #include "lua_script.h" #include "lua_hook.h" +#include "y_inter.h" + #if !defined (UNDER_CE) #include #endif @@ -3106,12 +3108,6 @@ boolean P_AddWadFile(const char *wadfilename, boolean local) return true; } -// check for replacement votescreen backgrounds -boolean wideracereplaced = false; -boolean racereplaced = false; -boolean widebattlereplaced = false; -boolean battlereplaced = false; - // // Add a WAD file and do the per-WAD setup stages. // Call P_MultiSetupWadFiles as soon as possible after any number of these. @@ -3245,10 +3241,11 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // TODO: Experimental SPRTINFO support, test first R_LoadSpriteInfoLumps(wadnum, wadfiles[wadnum]->numlumps); + // - // check for votescreen replacements + // check for non Lua votescreen replacements // - if (!wideracereplaced && !racereplaced && !widebattlereplaced && !battlereplaced) + if (!VoteScreen.wideracereplaced && !VoteScreen.racereplaced && !VoteScreen.widebattlereplaced && !VoteScreen.battlereplaced) { lumpinfo = wadfiles[wadnum]->lumpinfo; for (i = 0; i < numlumps; i++, lumpinfo++) @@ -3256,28 +3253,28 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) name = lumpinfo->name; // widescreen patch Race - if (!wideracereplaced && !strncmp(name, "INTERSCW", 8)) + if (!VoteScreen.wideracereplaced && !strncmp(name, "INTERSCW", 8)) { - wideracereplaced = true; + VoteScreen.wideracereplaced = true; continue; } - if (!racereplaced && !strncmp(name, "INTERSCR", 8)) + if (!VoteScreen.racereplaced && !strncmp(name, "INTERSCR", 8)) { - racereplaced = true; + VoteScreen.racereplaced = true; continue; } // widescreen patch Battle - if (!widebattlereplaced && !strncmp(name, "BATTLSCW", 8)) + if (!VoteScreen.widebattlereplaced && !strncmp(name, "BATTLSCW", 8)) { - widebattlereplaced = true; + VoteScreen.widebattlereplaced = true; continue; } - if (!battlereplaced && !strncmp(name, "BATTLSCR", 8)) + if (!VoteScreen.battlereplaced && !strncmp(name, "BATTLSCR", 8)) { - battlereplaced = true; + VoteScreen.battlereplaced = true; continue; } } diff --git a/src/p_setup.h b/src/p_setup.h index 97209e154..1a437a778 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -68,11 +68,6 @@ void HWR_LoadLevel(boolean reloadinggamestate); boolean P_AddWadFile(const char *wadfilename, boolean local); -extern boolean wideracereplaced; -extern boolean racereplaced; -extern boolean widebattlereplaced; -extern boolean battlereplaced; - // WARNING: The following functions should be grouped as follows: // any amount of PartialAdds followed by MultiSetups until returned true, // as soon as possible. diff --git a/src/y_inter.c b/src/y_inter.c index 3c0a77ac1..fdb045ef5 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -57,29 +57,17 @@ typedef struct static y_data_t data; - // graphics -static patch_t *bgpatch = NULL; // INTERSCR -static patch_t *widebgpatch = NULL; // INTERSCW static patch_t *bgtile = NULL; // SPECTILE/SRB2BACK + static INT32 timer; static INT32 intertic; static INT32 endtic = -1; static INT32 sorttic = -1; -patch_t *animVoteFramesPatches = NULL; -// VEXTRN - Vote (V) Extra (EXT) Race (R) Normal (N - Normal sized patch) -// VEXTBN - Vote (V) Extra (EXT) Battle (B) Normal (N - Normal sized patch) -// VEXTBW - Vote (V) Extra (EXT) Battle (B) Normal (W - Wide patch used in software) -// VEXTRW - Vote (V) Extra (EXT) Race (R) Normal (W - Wide patch used in software) -char animPrefix[] = "INTSC"; -char animWidePrefix[] = "INTSW"; -char *luaVoteScreen = NULL; - -INT32 currentAnimFrame = 0; -static INT32 foundAnimVoteFrames = 0; -static INT32 foundAnimVoteWideFrames = 0; +// votescreen stuff +votescreen_t VoteScreen = {0}; intertype_t intertype = int_none; @@ -288,46 +276,55 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) } // -// Y_AnimatedVoteScreenCheck +// Y_VoteScreenCheck // -// Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) -static void Y_AnimatedVoteScreenCheck(void) +static void Y_VoteScreenCheck(void) { - char tmpPrefix[] = "INTS"; + strcpy(VoteScreen.Prefix, "INTS"); - if (luaVoteScreen) - strncpy(tmpPrefix, luaVoteScreen, 4); + if (VoteScreen.luaVoteScreen) + strncpy(VoteScreen.Prefix, VoteScreen.luaVoteScreen, 4); else if (G_BattleGametype()) - strcpy(tmpPrefix, "BTLS"); + strcpy(VoteScreen.Prefix, "BTLS"); - strncpy(animPrefix, tmpPrefix, 4); - animPrefix[4] = 'C'; - strncpy(animWidePrefix, tmpPrefix, 4); - animWidePrefix[4] = 'W'; - - foundAnimVoteFrames = foundAnimVoteWideFrames = 0; - currentAnimFrame = 0; + VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; + VoteScreen.currentAnimFrame = 0; INT32 i = 1; + // check for lua vote background replacements for (;;) { - boolean normalLumpExists = W_LumpExists(va("%sC%d", tmpPrefix, i)); - boolean wideLumpExists = W_LumpExists(va("%sW%d", tmpPrefix, i)); + // Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) + boolean normalLumpExists = W_LumpExists(va("%sC%d", VoteScreen.Prefix, i)); + boolean wideLumpExists = W_LumpExists(va("%sW%d", VoteScreen.Prefix, i)); if (normalLumpExists || wideLumpExists) { if (normalLumpExists) - foundAnimVoteFrames++; + VoteScreen.foundLuaVoteFrames++; if (wideLumpExists) - foundAnimVoteWideFrames++; + VoteScreen.foundLuaVoteWideFrames++; } else // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking break; i++; } + + // non lua vote background handling + UINT8 prefgametype = (votelevels[0][1] & ~0x80); + + VoteScreen.widebgpatch = VoteScreen.bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_PATCH); + + if (VoteScreen.wideracereplaced || VoteScreen.widebattlereplaced) + { + if (prefgametype == GT_MATCH && VoteScreen.widebattlereplaced) + VoteScreen.widebgpatch = W_CachePatchName("BATTLSCW", PU_PATCH); + else if (VoteScreen.wideracereplaced) + VoteScreen.widebgpatch = W_CachePatchName("INTERSCW", PU_PATCH); + } } // Y_PlayerStandingsDrawer @@ -894,8 +891,8 @@ static void Y_UnloadData(void) return; // unload the background patches - UNLOAD(bgpatch); - UNLOAD(widebgpatch); + UNLOAD(VoteScreen.bgpatch); + UNLOAD(VoteScreen.widebgpatch); UNLOAD(bgtile); //UNLOAD(interpic); } @@ -928,27 +925,35 @@ static void Y_DrawVoteBackground(patch_t *patch) // // Draw animated patch based on frame counter on vote screen // -static void Y_DrawAnimatedVoteScreenPatch(boolean widePatch) +static void Y_DrawLuaVoteScreenPatch(boolean widePatch) { INT32 nextframe = 0; patch_t *votebg = NULL; - char tempAnimPrefix[7]; - const INT32 tempFoundAnimVoteFrames = ((widePatch ? foundAnimVoteWideFrames : foundAnimVoteFrames) - 1); + char tempPrefix[7]; + const INT32 tempfoundAnimLuaVoteFrames = ((widePatch ? VoteScreen.foundLuaVoteWideFrames : VoteScreen.foundLuaVoteFrames) - 1); - strcpy(tempAnimPrefix, (widePatch ? animWidePrefix : animPrefix)); + strcpy(tempPrefix, va("%s%s", VoteScreen.Prefix, (widePatch ? "W" : "C"))); + + // non animated votescreen + if (!tempfoundAnimLuaVoteFrames) + { + votebg = W_CachePatchName(va("%s1", tempPrefix), PU_PATCH); + Y_DrawVoteBackground(votebg); + return; + } // Just in case someone provides LESS widescreen frames than normal frames or vice versa, reset the frame counter to 0 - if (currentAnimFrame > tempFoundAnimVoteFrames) - currentAnimFrame = 0; + if (VoteScreen.currentAnimFrame > tempfoundAnimLuaVoteFrames) + VoteScreen.currentAnimFrame = 0; - nextframe = (currentAnimFrame + 1); + nextframe = (VoteScreen.currentAnimFrame + 1); - votebg = W_CachePatchName(va("%s%d", (widePatch ? animWidePrefix : animPrefix), nextframe), PU_PATCH); + votebg = W_CachePatchName(va("%s%d", tempPrefix, nextframe), PU_PATCH); Y_DrawVoteBackground(votebg); if (renderisnewtic && (votetic % 2 == 0) && !paused) - currentAnimFrame = (nextframe > tempFoundAnimVoteFrames) ? 0 : nextframe; + VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe; } static void Y_DrawVoteScreenPatch(void) @@ -956,22 +961,24 @@ static void Y_DrawVoteScreenPatch(void) patch_t *votebg = NULL; const boolean widescreen = (vid.width / vid.dupx > 320); - if (foundAnimVoteWideFrames || foundAnimVoteFrames) + if (VoteScreen.foundLuaVoteWideFrames || VoteScreen.foundLuaVoteFrames) { - Y_DrawAnimatedVoteScreenPatch((foundAnimVoteWideFrames && widescreen)); + Y_DrawLuaVoteScreenPatch(((widescreen && VoteScreen.foundLuaVoteWideFrames) || !VoteScreen.foundLuaVoteFrames)); return; } - votebg = bgpatch; // non widescreen patch + // non widescreen patch + votebg = VoteScreen.bgpatch; UINT8 prefgametype = (votelevels[0][1] & ~0x80); - const boolean widebgreplaced = (prefgametype == GT_MATCH) ? widebattlereplaced : wideracereplaced; - const boolean bgreplaced = (prefgametype == GT_MATCH) ? battlereplaced : racereplaced; + const boolean widebgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.widebattlereplaced : VoteScreen.wideracereplaced; + const boolean bgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.battlereplaced : VoteScreen.racereplaced; + // we check a bunch of stuff to always have a "valid" fallback if ((widescreen && (widebgreplaced || !bgreplaced)) || (!widescreen && (widebgreplaced && !bgreplaced))) { - votebg = widebgpatch; + votebg = VoteScreen.widebgpatch; // widescreen patch } Y_DrawVoteBackground(votebg); @@ -1474,7 +1481,6 @@ void Y_VoteTicker(void) void Y_StartVote(void) { INT32 i = 0; - UINT8 prefgametype = (votelevels[0][1] & ~0x80); votetic = -1; @@ -1483,10 +1489,8 @@ void Y_StartVote(void) I_Error("voteendtic is dirty"); #endif - Y_AnimatedVoteScreenCheck(); + Y_VoteScreenCheck(); - widebgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCW" : "INTERSCW"), PU_PATCH); - bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_PATCH); cursor = W_CachePatchName("M_CURSOR", PU_PATCH); cursor1 = W_CachePatchName("P1CURSOR", PU_PATCH); cursor2 = W_CachePatchName("P2CURSOR", PU_PATCH); @@ -1591,8 +1595,8 @@ static void Y_UnloadVoteData(void) if (rendermode != render_soft) return; - UNLOAD(widebgpatch); - UNLOAD(bgpatch); + UNLOAD(VoteScreen.widebgpatch); + UNLOAD(VoteScreen.bgpatch); UNLOAD(cursor); UNLOAD(cursor1); UNLOAD(cursor2); diff --git a/src/y_inter.h b/src/y_inter.h index be0192a27..eaed11397 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -10,7 +10,6 @@ /// \brief Tally screens, or "Intermissions" as they were formally called in Doom extern boolean usebuffer; -extern char *luaVoteScreen; void Y_IntermissionDrawer(void); void Y_Ticker(void); @@ -55,3 +54,27 @@ typedef enum int_classicrace, // Competition } intertype_t; extern intertype_t intertype; + +// VEXTRN - Vote (V) Extra (EXT) Race (R) Normal (N - Normal sized patch) +// VEXTRW - Vote (V) Extra (EXT) Race (R) Normal (W - Wide patch) +// VEXTBN - Vote (V) Extra (EXT) Battle (B) Normal (N - Normal sized patch) +// VEXTBW - Vote (V) Extra (EXT) Battle (B) Normal (W - Wide patch) +typedef struct +{ + char Prefix[5]; // Race = INTSX, Battle = BTLSX + char *luaVoteScreen; // lua prefix + + INT32 currentAnimFrame; // current animated background frame + + INT32 foundLuaVoteFrames; // normal lua patch frames + INT32 foundLuaVoteWideFrames; // wide lua patch frames + + boolean racereplaced; // non lua race patch replaced + boolean wideracereplaced; // non lua wide race patch replaced + boolean battlereplaced; // non lua battle patch replaced + boolean widebattlereplaced; // non lua wide battle patch replaced + + patch_t *bgpatch; // votebackground patch + patch_t *widebgpatch; // wide votebackground patch +} votescreen_t; +extern votescreen_t VoteScreen; -- 2.54.0 From e28ec4e7cbc97712b30a18a15fea940f2ca5452e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:31:58 +0200 Subject: [PATCH 02/15] unnest loop stuff in P_PartialAddWadFile may speed this up ever so slightly since we dont need to go through all wad lumps 3 times per call anymore --- src/p_setup.c | 239 ++++++++++++++++++++++++++++---------------------- 1 file changed, 134 insertions(+), 105 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 0fcc06542..bb7811b73 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3108,18 +3108,138 @@ boolean P_AddWadFile(const char *wadfilename, boolean local) return true; } +static size_t sreplaces = 0, mreplaces = 0, digmreplaces = 0; + +// +// search for sound replacements +// +static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) +{ + size_t j; + lumpnum_t lumpnum = (i|(wadnum<<16)); + + if (name[0] == 'D') + { + if (name[1] == 'S') + { + for (j = 1; j < NUMSFX; j++) + { + if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6) + && (S_sfx[j].lumpnum != lumpnum) && (S_sfx[j].lumpnum != LUMPERROR)) + { + // the sound will be reloaded when needed, + // since sfx->data will be NULL + CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", name); + + I_FreeSfx(&S_sfx[j]); + + // Re-cache it + if (S_PrecacheSound()) + S_sfx[j].data = I_GetSfx(&S_sfx[j]); + + sreplaces++; + return true; + } + } + } + else if (name[1] == '_') + { + CONS_Debug(DBG_SETUP, "Music %.8s ignored\n", name); + mreplaces++; + return true; + } + } + else if (name[0] == 'O' && name[1] == '_') + { + CONS_Debug(DBG_SETUP, "Music %.8s replaced\n", name); + digmreplaces++; + return true; + } + + return false; +} + +// +// search for maps +// +static boolean P_CheckMapReplacements(char *name) +{ + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers + { + INT16 num; + + if (name[5] != '\0') + return false; + + num = (INT16)M_MapNumber(name[3], name[4]); + + // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant + if (num <= NUMMAPS && mapheaderinfo[num-1]) + { + if (mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) + G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you + mapheaderinfo[num-1]->menuflags |= LF2_EXISTSHACK; + } + + if (num == gamemap) + partadd_replacescurrentmap = true; + + CONS_Printf("%s\n", name); + return true; + } + + return false; +} + +// +// check for non Lua votescreen replacements +// +static boolean P_CheckVoteReplacements(char *name) +{ + // widescreen patch Race + if (!VoteScreen.wideracereplaced && !memcmp(name, "INTERSCW", 8)) + { + VoteScreen.wideracereplaced = true; + return false; + } + + if (!VoteScreen.racereplaced && !memcmp(name, "INTERSCR", 8)) + { + VoteScreen.racereplaced = true; + return false; + } + + // widescreen patch Battle + if (!VoteScreen.widebattlereplaced && !memcmp(name, "BATTLSCW", 8)) + { + VoteScreen.widebattlereplaced = true; + return false; + } + + if (!VoteScreen.battlereplaced && !memcmp(name, "BATTLSCR", 8)) + { + VoteScreen.battlereplaced = true; + return false; + } + + return true; +} + // // Add a WAD file and do the per-WAD setup stages. // Call P_MultiSetupWadFiles as soon as possible after any number of these. // UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) { - size_t i, j, sreplaces = 0, mreplaces = 0, digmreplaces = 0; + size_t i; UINT16 numlumps, wadnum; char *name; boolean mapsadded = false; + static boolean allvotereplaced = false; lumpinfo_t *lumpinfo; + sreplaces = mreplaces = digmreplaces = 0; + if ((numlumps = W_InitFile(wadfilename, local)) == INT16_MAX) { refreshdirmenu |= REFRESHDIR_NOTLOADED; @@ -3134,46 +3254,24 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) wadfiles[wadnum]->localfile = local; - // - // search for sound replacements - // lumpinfo = wadfiles[wadnum]->lumpinfo; for (i = 0; i < numlumps; i++, lumpinfo++) { name = lumpinfo->name; - lumpnum_t lumpnum = i|(wadnum<<16); - if (name[0] == 'D') + if (P_CheckSoundReplacements(wadnum, name, i)) + continue; + + if (P_CheckMapReplacements(name)) { - if (name[1] == 'S') for (j = 1; j < NUMSFX; j++) - { - if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6) && S_sfx[j].lumpnum != lumpnum && S_sfx[j].lumpnum != LUMPERROR) - { - // the sound will be reloaded when needed, - // since sfx->data will be NULL - CONS_Debug(DBG_SETUP, "Sound %.8s replaced\n", name); - - I_FreeSfx(&S_sfx[j]); - - // Re-cache it - if (S_PrecacheSound()) - S_sfx[j].data = I_GetSfx(&S_sfx[j]); - - sreplaces++; - } - } - else if (name[1] == '_') - { - CONS_Debug(DBG_SETUP, "Music %.8s ignored\n", name); - mreplaces++; - } - } - else if (name[0] == 'O' && name[1] == '_') - { - CONS_Debug(DBG_SETUP, "Music %.8s replaced\n", name); - digmreplaces++; + mapsadded = true; + continue; } + + if (!allvotereplaced && P_CheckVoteReplacements(name)) + allvotereplaced = true; } + if (!devparm && sreplaces) CONS_Printf(M_GetText("%s sounds replaced\n"), sizeu1(sreplaces)); if (!devparm && mreplaces) @@ -3181,6 +3279,9 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); + if (!mapsadded) + CONS_Printf(M_GetText("No maps added\n")); + // // search for sprite replacements // @@ -3205,81 +3306,9 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // S_LoadMusicDefs(wadnum); - // - // search for maps - // - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers - { - INT16 num; - if (name[5]!='\0') - continue; - num = (INT16)M_MapNumber(name[3], name[4]); - - // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant - if (num <= NUMMAPS && mapheaderinfo[num-1]) - { - if (mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) - G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you - mapheaderinfo[num-1]->menuflags |= LF2_EXISTSHACK; - } - - if (num == gamemap) - partadd_replacescurrentmap = true; - - CONS_Printf("%s\n", name); - mapsadded = true; - } - } - if (!mapsadded) - CONS_Printf(M_GetText("No maps added\n")); - // TODO: Experimental SPRTINFO support, test first R_LoadSpriteInfoLumps(wadnum, wadfiles[wadnum]->numlumps); - - // - // check for non Lua votescreen replacements - // - if (!VoteScreen.wideracereplaced && !VoteScreen.racereplaced && !VoteScreen.widebattlereplaced && !VoteScreen.battlereplaced) - { - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - // widescreen patch Race - if (!VoteScreen.wideracereplaced && !strncmp(name, "INTERSCW", 8)) - { - VoteScreen.wideracereplaced = true; - continue; - } - - if (!VoteScreen.racereplaced && !strncmp(name, "INTERSCR", 8)) - { - VoteScreen.racereplaced = true; - continue; - } - - // widescreen patch Battle - if (!VoteScreen.widebattlereplaced && !strncmp(name, "BATTLSCW", 8)) - { - VoteScreen.widebattlereplaced = true; - continue; - } - - if (!VoteScreen.battlereplaced && !strncmp(name, "BATTLSCR", 8)) - { - VoteScreen.battlereplaced = true; - continue; - } - } - } - refreshdirmenu &= ~REFRESHDIR_GAMEDATA; // Under usual circumstances we'd wait for REFRESHDIR_GAMEDATA to disappear the next frame, but it's a bit too dangerous for that... partadd_stage = 0; return wadnum; -- 2.54.0 From e19b9d1c60029470deb25a406ba89773adde6555 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 02:53:44 +0200 Subject: [PATCH 03/15] fix smol mistake votescreen check --- src/p_setup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index bb7811b73..51f7312dc 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3222,7 +3222,13 @@ static boolean P_CheckVoteReplacements(char *name) return false; } - return true; + if (VoteScreen.wideracereplaced && VoteScreen.racereplaced + && VoteScreen.widebattlereplaced && VoteScreen.battlereplaced) + { + return true; + } + + return false; } // -- 2.54.0 From a8f3a8dfb02ef17517832a9715382bc33f13689b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:16:51 +0200 Subject: [PATCH 04/15] fix oopsie that caused use after free --- src/y_inter.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index fdb045ef5..bec12d627 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -314,17 +314,9 @@ static void Y_VoteScreenCheck(void) } // non lua vote background handling - UINT8 prefgametype = (votelevels[0][1] & ~0x80); - - VoteScreen.widebgpatch = VoteScreen.bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_PATCH); - - if (VoteScreen.wideracereplaced || VoteScreen.widebattlereplaced) - { - if (prefgametype == GT_MATCH && VoteScreen.widebattlereplaced) - VoteScreen.widebgpatch = W_CachePatchName("BATTLSCW", PU_PATCH); - else if (VoteScreen.wideracereplaced) - VoteScreen.widebgpatch = W_CachePatchName("INTERSCW", PU_PATCH); - } + boolean prefbattletype = ((votelevels[0][1] & ~0x80) == GT_MATCH); + VoteScreen.widebgpatch = W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH); + VoteScreen.bgpatch = W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH); } // Y_PlayerStandingsDrawer @@ -878,7 +870,7 @@ static void Y_FollowIntermission(void) G_AfterIntermission(); } -#define UNLOAD(x) if (x) {Patch_Free(x);} x = NULL; +#define UNLOAD(x) {if ((x) != NULL) {Patch_Free(x);} x = NULL;} // // Y_UnloadData -- 2.54.0 From e4a4496be6c58c5aca5e8933559f90528fc24e99 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:19:02 +0200 Subject: [PATCH 05/15] rename luaVoteScreen to luaPrefix + make it static buffer since its effectively just a prefix, --- src/lua_hudlib.c | 20 ++++---------------- src/y_inter.c | 4 ++-- src/y_inter.h | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index d2db7dbea..ff10a34c1 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1260,15 +1260,10 @@ extern int lib_hudadd(lua_State *L); static int lib_hudsetvotebackground(lua_State *L) { + memset(VoteScreen.luaPrefix, 0, sizeof(VoteScreen.luaPrefix)); + if (lua_isnoneornil(L, 1)) { - if (VoteScreen.luaVoteScreen) - { - free(VoteScreen.luaVoteScreen); - } - - VoteScreen.luaVoteScreen = NULL; - return 0; } @@ -1279,15 +1274,8 @@ static int lib_hudsetvotebackground(lua_State *L) return luaL_argerror(L, 1, "prefix should 4 characters wide"); } - if (!VoteScreen.luaVoteScreen) - { - VoteScreen.luaVoteScreen = (char*)malloc(5); - VoteScreen.luaVoteScreen[4] = 0; - } - - strncpy(VoteScreen.luaVoteScreen, prefix, 4); - - strupr(VoteScreen.luaVoteScreen); + strncpy(VoteScreen.luaPrefix, prefix, 4); + strupr(VoteScreen.luaPrefix); return 0; } diff --git a/src/y_inter.c b/src/y_inter.c index bec12d627..856ca3ac7 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -282,8 +282,8 @@ static void Y_VoteScreenCheck(void) { strcpy(VoteScreen.Prefix, "INTS"); - if (VoteScreen.luaVoteScreen) - strncpy(VoteScreen.Prefix, VoteScreen.luaVoteScreen, 4); + if (VoteScreen.luaPrefix[0] != 0) + strlcpy(VoteScreen.Prefix, VoteScreen.luaPrefix, sizeof(VoteScreen.Prefix)); else if (G_BattleGametype()) strcpy(VoteScreen.Prefix, "BTLS"); diff --git a/src/y_inter.h b/src/y_inter.h index eaed11397..4a665e5d9 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -62,7 +62,7 @@ extern intertype_t intertype; typedef struct { char Prefix[5]; // Race = INTSX, Battle = BTLSX - char *luaVoteScreen; // lua prefix + char luaPrefix[5]; // prefix for lua votescreens INT32 currentAnimFrame; // current animated background frame -- 2.54.0 From a73de55f9671309d7d08de8aba3e2c6cf1815e0c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:20:42 +0200 Subject: [PATCH 06/15] also put votescreen patches into votescreen struct + more cleanup --- src/p_setup.c | 20 +++---- src/y_inter.c | 152 ++++++++++++++++++++++++++++++++++---------------- src/y_inter.h | 20 +++++-- 3 files changed, 130 insertions(+), 62 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 51f7312dc..3ab1f8816 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3197,33 +3197,33 @@ static boolean P_CheckMapReplacements(char *name) static boolean P_CheckVoteReplacements(char *name) { // widescreen patch Race - if (!VoteScreen.wideracereplaced && !memcmp(name, "INTERSCW", 8)) + if (!VoteScreen.replaced.widerace && !memcmp(name, "INTERSCW", 8)) { - VoteScreen.wideracereplaced = true; + VoteScreen.replaced.widerace = true; return false; } - if (!VoteScreen.racereplaced && !memcmp(name, "INTERSCR", 8)) + if (!VoteScreen.replaced.race && !memcmp(name, "INTERSCR", 8)) { - VoteScreen.racereplaced = true; + VoteScreen.replaced.race = true; return false; } // widescreen patch Battle - if (!VoteScreen.widebattlereplaced && !memcmp(name, "BATTLSCW", 8)) + if (!VoteScreen.replaced.widebattle && !memcmp(name, "BATTLSCW", 8)) { - VoteScreen.widebattlereplaced = true; + VoteScreen.replaced.widebattle = true; return false; } - if (!VoteScreen.battlereplaced && !memcmp(name, "BATTLSCR", 8)) + if (!VoteScreen.replaced.battle && !memcmp(name, "BATTLSCR", 8)) { - VoteScreen.battlereplaced = true; + VoteScreen.replaced.battle = true; return false; } - if (VoteScreen.wideracereplaced && VoteScreen.racereplaced - && VoteScreen.widebattlereplaced && VoteScreen.battlereplaced) + if (VoteScreen.replaced.widerace && VoteScreen.replaced.race + && VoteScreen.replaced.widebattle && VoteScreen.replaced.battle) { return true; } diff --git a/src/y_inter.c b/src/y_inter.c index 856ca3ac7..ce2b3081c 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -66,9 +66,6 @@ static INT32 intertic; static INT32 endtic = -1; static INT32 sorttic = -1; -// votescreen stuff -votescreen_t VoteScreen = {0}; - intertype_t intertype = int_none; static huddrawlist_h luahuddrawlist_intermission = NULL; @@ -106,17 +103,13 @@ typedef struct boolean loaded; } y_voteclient; +// votescreen stuff +votescreen_t VoteScreen = {0}; + static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; static INT32 votetic; static INT32 voteendtic = -1; -static patch_t *cursor = NULL; -static patch_t *cursor1 = NULL; -static patch_t *cursor2 = NULL; -static patch_t *cursor3 = NULL; -static patch_t *cursor4 = NULL; -static patch_t *randomlvl = NULL; -static patch_t *rubyicon = NULL; static void Y_UnloadVoteData(void); @@ -891,7 +884,56 @@ static void Y_UnloadData(void) // SRB2Kart: Voting! -static void Y_DrawVoteBackground(patch_t *patch) +// +// Y_VoteScreenCheck +// +static void Y_VoteScreenCheck(void) +{ + strcpy(VoteScreen.Prefix, "INTS"); + + if (VoteScreen.luaPrefix[0] != 0) + strlcpy(VoteScreen.Prefix, VoteScreen.luaPrefix, sizeof(VoteScreen.Prefix)); + else if (G_BattleGametype()) + strcpy(VoteScreen.Prefix, "BTLS"); + + VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; + VoteScreen.currentAnimFrame = 0; + + INT32 i = 1; + + // check for lua vote background replacements + for (;;) + { + // Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) + boolean normalLumpExists = W_LumpExists(va("%sC%d", VoteScreen.Prefix, i)); + boolean wideLumpExists = W_LumpExists(va("%sW%d", VoteScreen.Prefix, i)); + + if (normalLumpExists || wideLumpExists) + { + if (normalLumpExists) + VoteScreen.foundLuaVoteFrames++; + + if (wideLumpExists) + VoteScreen.foundLuaVoteWideFrames++; + } + else // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking + break; + + i++; + } + + // non lua vote background handling + boolean prefbattletype = ((votelevels[0][1] & ~0x80) == GT_MATCH); + VoteScreen.widebgpatch = W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH); + VoteScreen.bgpatch = W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH); +} + +// +// Y_VoteBackgroundDrawer +// +// Determines which patch drawer to use for scaling +// +static void Y_VoteBackgroundDrawer(patch_t *patch) { switch (cv_votebgscaling.value) { @@ -913,27 +955,31 @@ static void Y_DrawVoteBackground(patch_t *patch) } } -// Y_DrawAnimatedVoteScreenPatch // -// Draw animated patch based on frame counter on vote screen +// Y_DrawLuaVoteScreenPatch +// +// Handles votebackgrounds set by "setVoteBackground" +// Aswell as animated patches // static void Y_DrawLuaVoteScreenPatch(boolean widePatch) { INT32 nextframe = 0; patch_t *votebg = NULL; - char tempPrefix[7]; + char tempPrefix[6]; const INT32 tempfoundAnimLuaVoteFrames = ((widePatch ? VoteScreen.foundLuaVoteWideFrames : VoteScreen.foundLuaVoteFrames) - 1); strcpy(tempPrefix, va("%s%s", VoteScreen.Prefix, (widePatch ? "W" : "C"))); - // non animated votescreen + // Draw non animated patch if (!tempfoundAnimLuaVoteFrames) { votebg = W_CachePatchName(va("%s1", tempPrefix), PU_PATCH); - Y_DrawVoteBackground(votebg); + Y_VoteBackgroundDrawer(votebg); return; } + // Draw animated patch based on frame counter on vote screen + // Just in case someone provides LESS widescreen frames than normal frames or vice versa, reset the frame counter to 0 if (VoteScreen.currentAnimFrame > tempfoundAnimLuaVoteFrames) VoteScreen.currentAnimFrame = 0; @@ -942,12 +988,15 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch) votebg = W_CachePatchName(va("%s%d", tempPrefix, nextframe), PU_PATCH); - Y_DrawVoteBackground(votebg); + Y_VoteBackgroundDrawer(votebg); if (renderisnewtic && (votetic % 2 == 0) && !paused) VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe; } +// +// Y_DrawVoteScreenPatch +// static void Y_DrawVoteScreenPatch(void) { patch_t *votebg = NULL; @@ -963,8 +1012,8 @@ static void Y_DrawVoteScreenPatch(void) votebg = VoteScreen.bgpatch; UINT8 prefgametype = (votelevels[0][1] & ~0x80); - const boolean widebgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.widebattlereplaced : VoteScreen.wideracereplaced; - const boolean bgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.battlereplaced : VoteScreen.racereplaced; + const boolean widebgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.replaced.widebattle : VoteScreen.replaced.widerace; + const boolean bgreplaced = (prefgametype == GT_MATCH) ? VoteScreen.replaced.battle : VoteScreen.replaced.race; // we check a bunch of stuff to always have a "valid" fallback if ((widescreen && (widebgreplaced || !bgreplaced)) @@ -973,7 +1022,7 @@ static void Y_DrawVoteScreenPatch(void) votebg = VoteScreen.widebgpatch; // widescreen patch } - Y_DrawVoteBackground(votebg); + Y_VoteBackgroundDrawer(votebg); } // @@ -1036,7 +1085,7 @@ void Y_VoteDrawer(void) if (i == 3) { str = "RANDOM"; - pic = randomlvl; + pic = VoteScreen.randomlvl; } else { @@ -1060,7 +1109,7 @@ void Y_VoteDrawer(void) if (!splitscreen) { - thiscurs = cursor; + thiscurs = VoteScreen.cursor[0]; p = consoleplayer; color = levelinfo[i].gtc; colormap = NULL; @@ -1070,19 +1119,19 @@ void Y_VoteDrawer(void) switch (j) { case 1: - thiscurs = cursor2; + thiscurs = VoteScreen.cursor[2]; p = displayplayers[1]; break; case 2: - thiscurs = cursor3; + thiscurs = VoteScreen.cursor[3]; p = displayplayers[2]; break; case 3: - thiscurs = cursor4; + thiscurs = VoteScreen.cursor[4]; p = displayplayers[3]; break; default: - thiscurs = cursor1; + thiscurs = VoteScreen.cursor[1]; p = displayplayers[0]; break; } @@ -1110,7 +1159,7 @@ void Y_VoteDrawer(void) else { V_DrawFixedPatch((BASEVIDWIDTH-20)<= 3 && (i != pickedvote || voteendtic == -1)) - pic = randomlvl; + pic = VoteScreen.randomlvl; else pic = levelinfo[votes[i]].pic; if (!timer && i == voteclient.ranim) { - V_DrawScaledPatch(x-18, y+9, V_SNAPTOLEFT, cursor); + V_DrawScaledPatch(x-18, y+9, V_SNAPTOLEFT, VoteScreen.cursor[0]); if (voteendtic != -1 && !(votetic % 4)) V_DrawFill(x-1, y-1, 42, 27, 120|V_SNAPTOLEFT); else @@ -1181,7 +1230,7 @@ void Y_VoteDrawer(void) else { V_DrawFixedPatch((x+40)< Date: Sat, 31 May 2025 15:21:20 +0200 Subject: [PATCH 07/15] free votepatches also in ogl not just software --- src/y_inter.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index ce2b3081c..cd495f8a9 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -870,11 +870,6 @@ static void Y_FollowIntermission(void) // static void Y_UnloadData(void) { - // In hardware mode, don't Z_ChangeTag a pointer returned by W_CachePatchName(). - // It doesn't work and is unnecessary. - if (rendermode != render_soft) - return; - // unload the background patches UNLOAD(VoteScreen.bgpatch); UNLOAD(VoteScreen.widebgpatch); @@ -1642,9 +1637,6 @@ static void Y_UnloadVoteData(void) { voteclient.loaded = false; - if (rendermode != render_soft) - return; - UNLOAD(VoteScreen.widebgpatch); UNLOAD(VoteScreen.bgpatch); UNLOAD(VoteScreen.cursor[0]); -- 2.54.0 From 448a603a563ff3655fc67a0a87085426d7596bfc Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:23:07 +0200 Subject: [PATCH 08/15] dont let dedi free votepatches lel --- src/y_inter.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/y_inter.c b/src/y_inter.c index cd495f8a9..041eeb6e0 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -845,7 +845,8 @@ void Y_StartIntermission(void) // void Y_EndIntermission(void) { - Y_UnloadData(); + if (!dedicated) + Y_UnloadData(); endtic = -1; sorttic = -1; @@ -1637,6 +1638,9 @@ static void Y_UnloadVoteData(void) { voteclient.loaded = false; + if (dedicated) + return; + UNLOAD(VoteScreen.widebgpatch); UNLOAD(VoteScreen.bgpatch); UNLOAD(VoteScreen.cursor[0]); -- 2.54.0 From c168832f8e874458cd0ad897c94220d6e6ba8e16 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:24:14 +0200 Subject: [PATCH 09/15] forgor to remove this --- src/y_inter.c | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index 041eeb6e0..486ea237e 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -268,50 +268,6 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) } } -// -// Y_VoteScreenCheck -// -static void Y_VoteScreenCheck(void) -{ - strcpy(VoteScreen.Prefix, "INTS"); - - if (VoteScreen.luaPrefix[0] != 0) - strlcpy(VoteScreen.Prefix, VoteScreen.luaPrefix, sizeof(VoteScreen.Prefix)); - else if (G_BattleGametype()) - strcpy(VoteScreen.Prefix, "BTLS"); - - VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; - VoteScreen.currentAnimFrame = 0; - - INT32 i = 1; - - // check for lua vote background replacements - for (;;) - { - // Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) - boolean normalLumpExists = W_LumpExists(va("%sC%d", VoteScreen.Prefix, i)); - boolean wideLumpExists = W_LumpExists(va("%sW%d", VoteScreen.Prefix, i)); - - if (normalLumpExists || wideLumpExists) - { - if (normalLumpExists) - VoteScreen.foundLuaVoteFrames++; - - if (wideLumpExists) - VoteScreen.foundLuaVoteWideFrames++; - } - else // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking - break; - - i++; - } - - // non lua vote background handling - boolean prefbattletype = ((votelevels[0][1] & ~0x80) == GT_MATCH); - VoteScreen.widebgpatch = W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH); - VoteScreen.bgpatch = W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH); -} - // Y_PlayerStandingsDrawer // // Handles drawing the center-of-screen player standings. -- 2.54.0 From d8b2134aef18e08f0ba70a56f723683156ca894a Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:29:39 +0200 Subject: [PATCH 10/15] dont let dedi cache vote patches lol --- src/y_inter.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index 486ea237e..3a69b06de 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1474,6 +1474,9 @@ void Y_VoteTicker(void) static void Y_InitVoteDrawing(void) { + if (dedicated) + return; + // setup the background patches Y_VoteScreenCheck(); @@ -1565,11 +1568,14 @@ void Y_StartVote(void) levelinfo[i].gts = NULL; // set up the pic - lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(votelevels[i][0]+1))); - if (lumpnum != LUMPERROR) - levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_PATCH); - else - levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_PATCH); + if (!dedicated) + { + lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(votelevels[i][0]+1))); + if (lumpnum != LUMPERROR) + levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_PATCH); + else + levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_PATCH); + } } voteclient.loaded = true; -- 2.54.0 From 55c6ba6d12fb4222e6baf15cbc85ea8d7dd2b6d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 15:57:03 +0200 Subject: [PATCH 11/15] fix awayview join crash player->awayviewmobj may not exist yet in some cases --- src/r_main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index f16d138ee..15f17db9d 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1063,7 +1063,7 @@ static void R_SetupCommonFrame(player_t * player, sector_t * sector) static void R_SetupAimingFrame(player_t *player, camera_t *thiscam) { - if (player->awayviewtics) + if (player->awayviewtics && player->awayviewmobj) { newview->aim = player->awayviewaiming; newview->angle = player->awayviewmobj->angle; @@ -1169,7 +1169,7 @@ void R_SkyboxFrame(int s) { mapheader_t *mh = mapheaderinfo[gamemap-1]; - if (player->awayviewtics) + if (player->awayviewtics && player->awayviewmobj) { SETUPSKYVIEW(player->awayviewmobj, (player->awayviewmobj->z + 20*FRACUNIT)); } @@ -1226,7 +1226,7 @@ void R_SetupFrame(int s, boolean skybox) R_SetupAimingFrame(player, thiscam); - if (player->awayviewtics) // cut-away view stuff + if (player->awayviewtics && player->awayviewmobj) // cut-away view stuff { viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN I_Assert(viewmobj != NULL); @@ -1235,7 +1235,7 @@ void R_SetupFrame(int s, boolean skybox) newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; - if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && viewmobj->subsector->sector) + if (viewmobj->subsector && viewmobj->subsector->sector) sector = viewmobj->subsector->sector; R_SetupCommonFrame(player, sector); @@ -1253,7 +1253,7 @@ void R_SetupFrame(int s, boolean skybox) R_SetupCommonFrame(player, sector); } - else // use the player's eyes view + else if (player->mo) // use the player's eyes view { viewmobj = player->mo; I_Assert(viewmobj != NULL); @@ -1262,7 +1262,7 @@ void R_SetupFrame(int s, boolean skybox) newview->y = viewmobj->y; newview->z = player->viewz; - if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && viewmobj->subsector->sector) + if (viewmobj->subsector && viewmobj->subsector->sector) sector = viewmobj->subsector->sector; R_SetupCommonFrame(player, sector); -- 2.54.0 From 5c53a90eea949af6f5316b260e78d1e297e0d494 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 16:20:58 +0200 Subject: [PATCH 12/15] hack: reset musiccredits when changing gamestate otherwise they may persist if theyve been currently displayed --- src/g_game.c | 5 +++++ src/s_sound.c | 5 +++++ src/s_sound.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/g_game.c b/src/g_game.c index dd3823f8a..31eed2fd4 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -8234,6 +8234,11 @@ boolean G_DemoTitleResponder(event_t *ev) void G_SetGamestate(gamestate_t newstate) { gamestate = newstate; + + //HACK: reset musiccredits whenever we change gamestate + // since we allow them to run everywhere now + S_ResetMusicCredit(); + #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif diff --git a/src/s_sound.c b/src/s_sound.c index cf75df56a..2f79e0540 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1436,6 +1436,11 @@ musicdef_t *S_FindMusicCredit(const char *musname) return NULL; } +void S_ResetMusicCredit(void) +{ + memset(&cursongcredit, 0, sizeof(cursongcredit)); +} + // // S_ShowSpecifiedMusicCredit // diff --git a/src/s_sound.h b/src/s_sound.h index 92e206e1b..eec99d802 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -206,6 +206,7 @@ void S_InitMTDefs(void); musicdef_t *S_FindMusicCredit(const char *musname); void S_ShowSpecifiedMusicCredit(const char *musname); void S_ShowMusicCredit(void); +void S_ResetMusicCredit(void); boolean S_PrepareSoundTest(void); -- 2.54.0 From e13ba89f1a03d21e084eb564efecf4a37671084e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 May 2025 17:20:26 +0200 Subject: [PATCH 13/15] use memcmp during startup map check prob not faster just looks a bit better tbh --- src/d_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index d10ba05ab..87596ca1c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1812,7 +1812,7 @@ void D_SRB2Main(void) { name = lumpinfo->name; - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers { INT16 num; if (name[5] != '\0') @@ -1842,7 +1842,7 @@ void D_SRB2Main(void) { name = lumpinfo->name; - if (name[0] == 'M' && name[1] == 'A' && name[2] == 'P') // Ignore the headers + if (memcmp(name, "MAP", 3) == 0) // Ignore the headers { INT16 num; if (name[5] != '\0') -- 2.54.0 From 0e9a825f63d989309ef75a540531259d86ae942e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 30 May 2025 20:52:38 +0200 Subject: [PATCH 14/15] some crap from ceepeepeecheck --- src/g_game.c | 51 ++++++++++++++++++++++-------------------- src/g_input.c | 2 +- src/hardware/hw_main.c | 5 ++++- src/k_kart.c | 5 +++-- src/r_data.c | 21 ++++++++++++----- 5 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 31eed2fd4..a872fc571 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5464,33 +5464,36 @@ void G_GhostTicker(void) break; } } - if (type == MT_GHOST) + if (type != -1) { - mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us - mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); - mobj->sprite = states[mobjinfo[type].spawnstate].sprite; - mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. - mobj->color = g->mo->color; - if (g->mo->eflags & MFE_VERTICALFLIP) + if (type == MT_GHOST) { - mobj->flags2 |= MF2_OBJECTFLIP; - mobj->eflags |= MFE_VERTICALFLIP; + mobj = P_SpawnGhostMobj(g->mo); // does a large portion of the work for us + mobj->frame = (mobj->frame & ~FF_FRAMEMASK)|tr_trans60<mo->scale); - mobj->destscale = g->mo->scale; + else + { + mobj = P_SpawnMobj(g->mo->x, g->mo->y, g->mo->z - FixedDiv(FixedMul(g->mo->info->height, g->mo->scale) - g->mo->height,3*FRACUNIT), MT_THOK); + mobj->sprite = states[mobjinfo[type].spawnstate].sprite; + mobj->frame = (states[mobjinfo[type].spawnstate].frame & FF_FRAMEMASK) | tr_trans60<tics = -1; // nope. + mobj->color = g->mo->color; + if (g->mo->eflags & MFE_VERTICALFLIP) + { + mobj->flags2 |= MF2_OBJECTFLIP; + mobj->eflags |= MFE_VERTICALFLIP; + } + P_SetScale(mobj, g->mo->scale); + mobj->destscale = g->mo->scale; + } + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_UnsetThingPosition(mobj); + mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... + P_SetThingPosition(mobj); + mobj->fuse = 8; + P_SetTarget(&mobj->target, g->mo); } - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_UnsetThingPosition(mobj); - mobj->flags = MF_NOBLOCKMAP|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY; // make an ATTEMPT to curb crazy SOCs fucking stuff up... - P_SetThingPosition(mobj); - mobj->fuse = 8; - P_SetTarget(&mobj->target, g->mo); } if (ziptic & EZT_HIT) { // Spawn hit poofs for killing things! @@ -8143,7 +8146,7 @@ void G_SaveDemo(void) size_t i, strindex = 0; boolean dash = true; - for (i = 0; i < 127 && demo.titlename[i]; i++) + for (i = 0; demo.titlename[i] && i < 127; i++) { if ((demo.titlename[i] >= 'a' && demo.titlename[i] <= 'z') || (demo.titlename[i] >= '0' && demo.titlename[i] <= '9')) diff --git a/src/g_input.c b/src/g_input.c index 43b7f48ca..8d5b38bf2 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -1030,7 +1030,7 @@ INT32 G_KeyStringtoNum(const char *keystr) if (!keystr[0]) return 0; - if (!keystr[0] || (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z')) + if (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z') return keystr[0]; if (!strncmp(keystr, "KEY", 3) && keystr[3] >= '0' && keystr[3] <= '9') diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e25364bee..43cb25aed 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4464,7 +4464,10 @@ static void HWR_DrawModels(void) continue; } - if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + if (!spr->mobj) + continue; + + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { md2_t *md2; diff --git a/src/k_kart.c b/src/k_kart.c index c63433fb4..5589bdb6e 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -10525,11 +10525,12 @@ static void K_drawKartWanted(void) { INT32 x = basex+(splitscreen > 1 ? 13 : 8), y = basey+(splitscreen > 1 ? 16 : 21); fixed_t scale = FRACUNIT/2; - player_t *p = &players[battlewanted[i]]; if (battlewanted[i] == -1) break; + player_t *p = &players[battlewanted[i]]; + if (numwanted == 1) scale = FRACUNIT; else @@ -10540,7 +10541,7 @@ static void K_drawKartWanted(void) y += 16; } - if (players[battlewanted[i]].skincolor) + if (p->skincolor) { colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); V_DrawFixedPatch(x<8) + + if (texturesTokenLength > 8) { I_Error("Error parsing TEXTURES lump: Patch name \"%s\" exceeds 8 characters",texturesToken); } @@ -713,10 +716,12 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // Comma 1 Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after \"%s\"'s patch name should be",patchName); } + if (strcmp(texturesToken,",")!=0) { I_Error("Error parsing TEXTURES lump: Expected \",\" after %s's patch name, got \"%s\"",patchName,texturesToken); @@ -725,14 +730,17 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // XPos Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s x coordinate should be",patchName); } + endPos = NULL; #ifndef AVOID_ERRNO errno = 0; #endif + patchXPos = strtol(texturesToken,&endPos,10); (void)patchXPos; //unused for now if (endPos == texturesToken // Empty string @@ -748,10 +756,12 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // Comma 2 Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where comma after patch \"%s\"'s x coordinate should be",patchName); } + if (strcmp(texturesToken,",")!=0) { I_Error("Error parsing TEXTURES lump: Expected \",\" after patch \"%s\"'s x coordinate, got \"%s\"",patchName,texturesToken); @@ -760,6 +770,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) // YPos Z_Free(texturesToken); texturesToken = M_GetToken(NULL); + if (texturesToken == NULL) { I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s y coordinate should be",patchName); @@ -1131,9 +1142,9 @@ static void R_InitExtraColormaps(void) lumpnum_t R_GetFlatNumForName(const char *name) { INT32 i; - lumpnum_t lump; - lumpnum_t start; - lumpnum_t end; + lumpnum_t lump = LUMPERROR; + lumpnum_t start = LUMPERROR; + lumpnum_t end = LUMPERROR; // Scan wad files backwards so patched flats take preference. for (i = numwadfiles - 1; i >= 0; i--) @@ -1608,7 +1619,7 @@ const char *R_ColormapNameForNum(INT32 num) if (num == -1) return "NONE"; - if (num < 0 || num > MAXCOLORMAPS) + if (num < 0 || num >= MAXCOLORMAPS) I_Error("R_ColormapNameForNum: num %d is invalid!\n", num); if (foundcolormaps[num] == LUMPERROR) -- 2.54.0 From f1f07822569149c6d94cd68c8c5c8b5f7ec2343d Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 30 May 2025 20:56:43 +0200 Subject: [PATCH 15/15] fix memoryleak in pk3 verify functions --- src/w_wad.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 0c7fdbaf0..305e4b3bd 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2039,8 +2039,7 @@ static lumpchecklist_t folderblacklist[] = {NULL, 0}, }; -static int -W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) +static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) { int verified = true; @@ -2082,7 +2081,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) char *cdir = (char*)(malloc(LONG(zend.cdirsize))); if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + { + free(cdir); return true; + } size_t offset = 0; @@ -2094,7 +2096,10 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) char* dotpos; if (memcmp(zentry->signature, pat_central, 4) != 0) + { + free(cdir); return true; + } if (verified == true) { @@ -2132,10 +2137,16 @@ W_VerifyPK3 (FILE *fp, lumpchecklist_t *checklist, boolean status) sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) + { + free(cdir); return true; + } if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) + { + free(cdir); return true; + } data_size += sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize); @@ -2186,7 +2197,9 @@ static int W_VerifyFile(const char *filename, lumpchecklist_t *checklist, goodfile = W_VerifyWAD(handle, checklist, status); } } + fclose(handle); + return goodfile; } @@ -2341,7 +2354,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) char *cdir = (char*)(malloc(LONG(zend.cdirsize))); if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) + { + free(cdir); return true; + } size_t offset = 0; @@ -2353,7 +2369,10 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) char* dotpos; if (memcmp(zentry->signature, pat_central, 4) != 0) + { + free(cdir); return false; + } fullname = (char*)(malloc(SHORT(zentry->namelen) + 1)); strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); @@ -2373,11 +2392,19 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) strncpy(lumpname, trimname, min(8, dotpos - trimname)); if (W_NameStartsWith(lumpname, checklist)) + { + free(fullname); + free(cdir); return true; + } } if (W_NameStartsWith(fullname, checklist)) + { + free(fullname); + free(cdir); return true; + } free(fullname); @@ -2387,10 +2414,16 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) sizeof *zentry + SHORT(zentry->namelen) + SHORT(zentry->xtralen) + SHORT(zentry->commlen); if (fseek(fp, LONG(zentry->offset), SEEK_SET) != 0) + { + free(cdir); return false; + } if (fread(&zlentry, 1, sizeof(zlentry_t), fp) < sizeof (zlentry_t)) + { + free(cdir); return false; + } data_size += sizeof zlentry + SHORT(zlentry.namelen) + SHORT(zlentry.xtralen) + LONG(zlentry.compsize); -- 2.54.0