From 0776460643463490c475eb22f26bc0efb89ff3f6 Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 29 Aug 2018 12:50:25 +0100 Subject: [PATCH] * Make some minor performance improvements. * Make the I_Errors in filesrch.c more descriptive. * Fix up the loading of sounds.kart such that it has SOME protection against being loaded with game-modifying lumps. * SERIOUSLY fix up the MD5/mainwads++ section in D_SRB2Main, since 1) I broke it and 2) it was already a little broken in the first place but we just didn't notice it because #ifndef DEVELOP. --- src/d_main.c | 68 +++++++++++++++++++++----------------------------- src/filesrch.c | 16 ++++++------ src/v_video.c | 7 ++++++ 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 65a2bc5a..f2063861 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -957,43 +957,29 @@ static void IdentifyVersion(void) D_AddFile(va(pandf,srb2waddir,"patch.dta")); #endif +#define MUSICTEST(str) \ + {\ + const char *musicpath = va(pandf,srb2waddir,str);\ + int ms = W_VerifyNMUSlumps(musicpath); \ + if (ms == 1) \ + D_AddFile(musicpath); \ + else if (ms == 0) \ + I_Error("File "str" has been modified with non-music/sound lumps"); \ + } + // SRB2kart - Add graphics (temp) // The command for md5 checks is "W_VerifyFileMD5" - looks for ASSET_HASH_SRB2_SRB in config.h.in D_AddFile(va(pandf,srb2waddir,"gfx.kart")); D_AddFile(va(pandf,srb2waddir,"chars.kart")); D_AddFile(va(pandf,srb2waddir,"maps.kart")); - D_AddFile(va(pandf,srb2waddir,"sounds.kart")); + //D_AddFile(va(pandf,srb2waddir,"sounds.kart")); + MUSICTEST("sounds.kart") #ifdef USE_PATCH_KART D_AddFile(va(pandf,srb2waddir,"patch.kart")); #endif -#if !defined (HAVE_SDL) || defined (HAVE_MIXER) - { -#if defined (DC) && 0 - const char *musicfile = "music_dc.dta"; -#else - const char *musicfile = "music.dta"; -#endif - const char *kmusicfile; - const char *musicpath = va(pandf,srb2waddir,musicfile); - const char *kmusicpath; - int ms = W_VerifyNMUSlumps(musicpath); // Don't forget the music! - int kms; - if (ms == 1) - D_AddFile(musicpath); - else if (ms == 0) - I_Error("File %s has been modified with non-music lumps",musicfile); - - kmusicfile = "music.kart"; - kmusicpath = va(pandf,srb2waddir,kmusicfile); - kms = W_VerifyNMUSlumps(kmusicpath); // kill me now - - if (kms == 1) - D_AddFile(kmusicpath); - else if (kms == 0) - I_Error("File %s has been modified with non-music lumps",kmusicfile); - } -#endif + MUSICTEST("music.dta") + MUSICTEST("music.kart") } /* ======================================================================== */ @@ -1253,27 +1239,27 @@ void D_SRB2Main(void) #endif D_CleanFile(); + mainwads = 0; + #ifndef DEVELOP // md5s last updated 12/14/14 // Check MD5s of autoloaded files W_VerifyFileMD5(mainwads, ASSET_HASH_SRB2_SRB); // srb2.srb/srb2.wad #ifdef USE_PATCH_DTA - W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_DTA); // patch.dta + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_DTA); // patch.dta #endif - W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_KART); // gfx.kart - W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_KART); // chars.kart - W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_KART); // maps.kart - /*W_VerifyFileMD5(mainwads, ASSET_HASH_SOUNDS_KART);*/ // sounds.kart - doesn't trigger modifiedgame, doesn't need an MD5...? + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_KART); // gfx.kart + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_KART); // chars.kart + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_KART); // maps.kart + mainwads++; //W_VerifyFileMD5(5, ASSET_HASH_SOUNDS_KART); -- sounds.kart - doesn't trigger modifiedgame, doesn't need an MD5...? #ifdef USE_PATCH_KART - W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_KART); // patch.kart + mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_KART); // patch.kart #endif - - // don't check music.dta because people like to modify it, and it doesn't matter if they do + mainwads++; // music.dta + mainwads++; // music.kart + // don't check music.dta or kart because people like to modify it, and it doesn't matter if they do // ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for. -#endif //ifndef DEVELOP - - mainwads = 0; - mainwads++; // srb2.srb/srb2.wad +#else #ifdef USE_PATCH_DTA mainwads++; // patch.dta #endif @@ -1284,7 +1270,9 @@ void D_SRB2Main(void) #ifdef USE_PATCH_KART mainwads++; // patch.kart #endif + mainwads++; // music.dta mainwads++; // music.kart +#endif //ifndef DEVELOP mainwadstally = packetsizetally; diff --git a/src/filesrch.c b/src/filesrch.c index 59868653..94c1190b 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -563,9 +563,9 @@ static boolean filemenucmp(char *haystack, char *needle) strlcpy(localhaystack, haystack, 128); if (!cv_addons_search_case.value) strupr(localhaystack); - return ((cv_addons_search_type.value) - ? (strstr(localhaystack, needle) != 0) - : (!strncmp(localhaystack, needle, menusearch[0]))); + if (cv_addons_search_type.value) + return (strstr(localhaystack, needle) != 0); + return (!strncmp(localhaystack, needle, menusearch[0])); } void closefilemenu(boolean validsize) @@ -673,7 +673,7 @@ void searchfilemenu(char *tempname) { if ((!(dirmenu = Z_Realloc(dirmenu, sizeof(char *), PU_STATIC, NULL))) || !(dirmenu[0] = Z_StrDup(va("%c\13No results...", EXT_NORESULTS)))) - I_Error("Ran out of memory whilst preparing add-ons menu"); + I_Error("searchfilemenu(): could not create \"No results...\"."); sizedirmenu = 1; dir_on[menudepthleft] = 0; if (tempname) @@ -682,7 +682,7 @@ void searchfilemenu(char *tempname) } if (!(dirmenu = Z_Realloc(dirmenu, sizedirmenu*sizeof(char *), PU_STATIC, NULL))) - I_Error("Ran out of memory whilst preparing add-ons menu"); + I_Error("searchfilemenu(): could not reallocate dirmenu."); sizedirmenu = 0; for (i = first; i < sizecoredirmenu; i++) @@ -793,7 +793,7 @@ boolean preparefilemenu(boolean samedepth) if (!(coredirmenu = Z_Realloc(coredirmenu, sizecoredirmenu*sizeof(char *), PU_STATIC, NULL))) { closedir(dirhandle); // just in case - I_Error("Ran out of memory whilst preparing add-ons menu"); + I_Error("preparefilemenu(): could not reallocate coredirmenu."); } rewinddir(dirhandle); @@ -868,7 +868,7 @@ boolean preparefilemenu(boolean samedepth) len = 255; if (!(temp = Z_Malloc((len+DIR_STRING+folder) * sizeof (char), PU_STATIC, NULL))) - I_Error("Ran out of memory whilst preparing add-ons menu"); + I_Error("preparefilemenu(): could not create file entry."); temp[DIR_TYPE] = ext; temp[DIR_LEN] = (UINT8)(len); strlcpy(temp+DIR_STRING, dent->d_name, len); @@ -886,7 +886,7 @@ boolean preparefilemenu(boolean samedepth) if ((menudepthleft != menudepth-1) // now for UP... entry && !(coredirmenu[0] = Z_StrDup(va("%c\5UP...", EXT_UP)))) - I_Error("Ran out of memory whilst preparing add-ons menu"); + I_Error("searchfilemenu(): could not create \"UP...\"."); menupath[menupathindex[menudepthleft]] = 0; sizecoredirmenu = (numfolders+pos); // just in case things shrink between opening and rewind diff --git a/src/v_video.c b/src/v_video.c index e39663a7..8c8bd342 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1250,6 +1250,7 @@ void V_DrawFadeConsBack(INT32 plines) // const UINT8 *V_GetStringColormap(INT32 colorflags) { +#if 0 // perfect switch ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT) { case 1: // 0x81, purple @@ -1271,6 +1272,12 @@ const UINT8 *V_GetStringColormap(INT32 colorflags) default: // reset return NULL; } +#else // optimised + colorflags = ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT); + if (!colorflags || colorflags > 8) // INT32 is signed, but V_CHARCOLORMASK is a very restrictive mask. + return NULL; + return (purplemap+((colorflags-1)<<8)); +#endif } // Writes a single character (draw WHITE if bit 7 set)