* 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.
This commit is contained in:
toaster 2018-08-29 12:50:25 +01:00
parent b6dbecd2f8
commit 0776460643
3 changed files with 43 additions and 48 deletions

View file

@ -957,43 +957,29 @@ static void IdentifyVersion(void)
D_AddFile(va(pandf,srb2waddir,"patch.dta")); D_AddFile(va(pandf,srb2waddir,"patch.dta"));
#endif #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 // 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,"gfx.kart"));
D_AddFile(va(pandf,srb2waddir,"chars.kart")); D_AddFile(va(pandf,srb2waddir,"chars.kart"));
D_AddFile(va(pandf,srb2waddir,"maps.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 #ifdef USE_PATCH_KART
D_AddFile(va(pandf,srb2waddir,"patch.kart")); D_AddFile(va(pandf,srb2waddir,"patch.kart"));
#endif #endif
#if !defined (HAVE_SDL) || defined (HAVE_MIXER) MUSICTEST("music.dta")
{ MUSICTEST("music.kart")
#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
} }
/* ======================================================================== */ /* ======================================================================== */
@ -1253,27 +1239,27 @@ void D_SRB2Main(void)
#endif #endif
D_CleanFile(); D_CleanFile();
mainwads = 0;
#ifndef DEVELOP // md5s last updated 12/14/14 #ifndef DEVELOP // md5s last updated 12/14/14
// Check MD5s of autoloaded files // Check MD5s of autoloaded files
W_VerifyFileMD5(mainwads, ASSET_HASH_SRB2_SRB); // srb2.srb/srb2.wad W_VerifyFileMD5(mainwads, ASSET_HASH_SRB2_SRB); // srb2.srb/srb2.wad
#ifdef USE_PATCH_DTA #ifdef USE_PATCH_DTA
W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_DTA); // patch.dta mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_DTA); // patch.dta
#endif #endif
W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_KART); // gfx.kart mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_KART); // gfx.kart
W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_KART); // chars.kart mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_KART); // chars.kart
W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_KART); // maps.kart mainwads++; 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(5, ASSET_HASH_SOUNDS_KART); -- sounds.kart - doesn't trigger modifiedgame, doesn't need an MD5...?
#ifdef USE_PATCH_KART #ifdef USE_PATCH_KART
W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_KART); // patch.kart mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_KART); // patch.kart
#endif #endif
mainwads++; // music.dta
// don't check music.dta because people like to modify it, and it doesn't matter if they do 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. // ...except it does if they slip maps in there, and that's what W_VerifyNMUSlumps is for.
#endif //ifndef DEVELOP #else
mainwads = 0;
mainwads++; // srb2.srb/srb2.wad
#ifdef USE_PATCH_DTA #ifdef USE_PATCH_DTA
mainwads++; // patch.dta mainwads++; // patch.dta
#endif #endif
@ -1284,7 +1270,9 @@ void D_SRB2Main(void)
#ifdef USE_PATCH_KART #ifdef USE_PATCH_KART
mainwads++; // patch.kart mainwads++; // patch.kart
#endif #endif
mainwads++; // music.dta
mainwads++; // music.kart mainwads++; // music.kart
#endif //ifndef DEVELOP
mainwadstally = packetsizetally; mainwadstally = packetsizetally;

View file

@ -563,9 +563,9 @@ static boolean filemenucmp(char *haystack, char *needle)
strlcpy(localhaystack, haystack, 128); strlcpy(localhaystack, haystack, 128);
if (!cv_addons_search_case.value) if (!cv_addons_search_case.value)
strupr(localhaystack); strupr(localhaystack);
return ((cv_addons_search_type.value) if (cv_addons_search_type.value)
? (strstr(localhaystack, needle) != 0) return (strstr(localhaystack, needle) != 0);
: (!strncmp(localhaystack, needle, menusearch[0]))); return (!strncmp(localhaystack, needle, menusearch[0]));
} }
void closefilemenu(boolean validsize) void closefilemenu(boolean validsize)
@ -673,7 +673,7 @@ void searchfilemenu(char *tempname)
{ {
if ((!(dirmenu = Z_Realloc(dirmenu, sizeof(char *), PU_STATIC, NULL))) if ((!(dirmenu = Z_Realloc(dirmenu, sizeof(char *), PU_STATIC, NULL)))
|| !(dirmenu[0] = Z_StrDup(va("%c\13No results...", EXT_NORESULTS)))) || !(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; sizedirmenu = 1;
dir_on[menudepthleft] = 0; dir_on[menudepthleft] = 0;
if (tempname) if (tempname)
@ -682,7 +682,7 @@ void searchfilemenu(char *tempname)
} }
if (!(dirmenu = Z_Realloc(dirmenu, sizedirmenu*sizeof(char *), PU_STATIC, NULL))) 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; sizedirmenu = 0;
for (i = first; i < sizecoredirmenu; i++) 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))) if (!(coredirmenu = Z_Realloc(coredirmenu, sizecoredirmenu*sizeof(char *), PU_STATIC, NULL)))
{ {
closedir(dirhandle); // just in case 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); rewinddir(dirhandle);
@ -868,7 +868,7 @@ boolean preparefilemenu(boolean samedepth)
len = 255; len = 255;
if (!(temp = Z_Malloc((len+DIR_STRING+folder) * sizeof (char), PU_STATIC, NULL))) 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_TYPE] = ext;
temp[DIR_LEN] = (UINT8)(len); temp[DIR_LEN] = (UINT8)(len);
strlcpy(temp+DIR_STRING, dent->d_name, 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 if ((menudepthleft != menudepth-1) // now for UP... entry
&& !(coredirmenu[0] = Z_StrDup(va("%c\5UP...", EXT_UP)))) && !(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; menupath[menupathindex[menudepthleft]] = 0;
sizecoredirmenu = (numfolders+pos); // just in case things shrink between opening and rewind sizecoredirmenu = (numfolders+pos); // just in case things shrink between opening and rewind

View file

@ -1250,6 +1250,7 @@ void V_DrawFadeConsBack(INT32 plines)
// //
const UINT8 *V_GetStringColormap(INT32 colorflags) const UINT8 *V_GetStringColormap(INT32 colorflags)
{ {
#if 0 // perfect
switch ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT) switch ((colorflags & V_CHARCOLORMASK) >> V_CHARCOLORSHIFT)
{ {
case 1: // 0x81, purple case 1: // 0x81, purple
@ -1271,6 +1272,12 @@ const UINT8 *V_GetStringColormap(INT32 colorflags)
default: // reset default: // reset
return NULL; 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) // Writes a single character (draw WHITE if bit 7 set)