mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Merge branch 'eid/md5-only-once' into 'master'
Only MD5 assets once, regardless of build mode See merge request kart-krew-dev/ring-racers-internal!2508
This commit is contained in:
commit
6aad78824b
4 changed files with 117 additions and 142 deletions
127
src/d_main.cpp
127
src/d_main.cpp
|
|
@ -141,8 +141,10 @@ INT32 window_y;
|
|||
//
|
||||
// DEMO LOOP
|
||||
//
|
||||
static char *startupiwads[MAX_WADFILES];
|
||||
static char *startuppwads[MAX_WADFILES];
|
||||
static size_t num_startupiwads = 0;
|
||||
static initmultiplefilesentry_t startupiwads[MAX_WADFILES];
|
||||
static size_t num_startuppwads = 0;
|
||||
static initmultiplefilesentry_t startuppwads[MAX_WADFILES];
|
||||
|
||||
boolean devparm = false; // started game with -devparm
|
||||
|
||||
|
|
@ -1282,31 +1284,36 @@ boolean D_IsDeferredStartTitle(void)
|
|||
//
|
||||
// D_AddFile
|
||||
//
|
||||
static void D_AddFile(char **list, const char *file)
|
||||
static void D_AddFile(initmultiplefilesentry_t *list, size_t index, const char *file, const char *md5sum)
|
||||
{
|
||||
size_t pnumwadfiles;
|
||||
char *newfile;
|
||||
|
||||
for (pnumwadfiles = 0; list[pnumwadfiles]; pnumwadfiles++)
|
||||
;
|
||||
|
||||
newfile = static_cast<char*>(malloc(strlen(file) + 1));
|
||||
if (!newfile)
|
||||
char *filecopy = NULL;
|
||||
if (file)
|
||||
{
|
||||
I_Error("No more free memory to AddFile %s",file);
|
||||
size_t len = strlen(file) + 1;
|
||||
filecopy = (char*)malloc(len);
|
||||
memcpy(filecopy, file, len);
|
||||
}
|
||||
strcpy(newfile, file);
|
||||
|
||||
list[pnumwadfiles] = newfile;
|
||||
char *md5copy = NULL;
|
||||
if (md5sum)
|
||||
{
|
||||
size_t len = strlen(md5sum) + 1;
|
||||
md5copy = (char*)malloc(len);
|
||||
memcpy(md5copy, md5sum, len);
|
||||
}
|
||||
list[index].filename = filecopy;
|
||||
list[index].md5sum = md5copy;
|
||||
}
|
||||
|
||||
static inline void D_CleanFile(char **list)
|
||||
static inline void D_CleanFile(initmultiplefilesentry_t *list, size_t count)
|
||||
{
|
||||
size_t pnumwadfiles;
|
||||
for (pnumwadfiles = 0; list[pnumwadfiles]; pnumwadfiles++)
|
||||
for (INT32 i = 0; i < count; ++i)
|
||||
{
|
||||
free(list[pnumwadfiles]);
|
||||
list[pnumwadfiles] = NULL;
|
||||
if (list[i].filename != NULL)
|
||||
free((void*)list[i].filename);
|
||||
list[i].filename = NULL;
|
||||
if (list[i].md5sum != NULL)
|
||||
free((void*)list[i].md5sum);
|
||||
list[i].md5sum = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1354,7 +1361,7 @@ static boolean AddIWAD(void)
|
|||
|
||||
if (FIL_ReadFileOK(path))
|
||||
{
|
||||
D_AddFile(startupiwads, path);
|
||||
D_AddFile(startupiwads, num_startupiwads++, path, ASSET_HASH_BIOS_PK3);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
@ -1395,21 +1402,18 @@ static void IdentifyVersion(void)
|
|||
snprintf(configfile, sizeof configfile, "%s" PATHSEP CONFIGFILENAME, srb2waddir);
|
||||
configfile[sizeof configfile - 1] = '\0';
|
||||
|
||||
// if you change the ordering of this or add/remove a file, be sure to update the md5
|
||||
// checking in D_SRB2Main
|
||||
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","scripts.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","gfx.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","textures_general.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","textures_segazones.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","textures_originalzones.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","chars.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","followers.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","maps.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","unlocks.pk3"));
|
||||
D_AddFile(startupiwads, va(spandf,srb2waddir,"data","staffghosts.pk3"));
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","scripts.pk3"), ASSET_HASH_SCRIPTS_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","gfx.pk3"), ASSET_HASH_GFX_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","textures_general.pk3"), ASSET_HASH_TEXTURES_GENERAL_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","textures_segazones.pk3"), ASSET_HASH_TEXTURES_SEGAZONES_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","textures_originalzones.pk3"), ASSET_HASH_TEXTURES_ORIGINALZONES_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","chars.pk3"), ASSET_HASH_CHARS_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","followers.pk3"), ASSET_HASH_FOLLOWERS_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","maps.pk3"), ASSET_HASH_MAPS_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","unlocks.pk3"), ASSET_HASH_UNLOCKS_PK3);
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(spandf,srb2waddir,"data","staffghosts.pk3"), ASSET_HASH_STAFFGHOSTS_PK3);
|
||||
#ifdef USE_PATCH_FILE
|
||||
D_AddFile(startupiwads, va(pandf,srb2waddir,"patch.pk3"));
|
||||
D_AddFile(startupiwads, num_startupiwads++, va(pandf,srb2waddir,"patch.pk3"), ASSET_HASH_PATCH_PK3);
|
||||
#endif
|
||||
|
||||
#define MUSICTEST(str) \
|
||||
|
|
@ -1418,7 +1422,7 @@ static void IdentifyVersion(void)
|
|||
int ms = W_VerifyNMUSlumps(musicpath, false); \
|
||||
if (ms == 1) \
|
||||
{ \
|
||||
D_AddFile(startupiwads, musicpath); \
|
||||
D_AddFile(startupiwads, num_startupiwads++, musicpath, NULL); \
|
||||
musicwads++; \
|
||||
} \
|
||||
else if (ms == 0) \
|
||||
|
|
@ -1687,7 +1691,7 @@ void D_SRB2Main(void)
|
|||
const char *s = M_GetNextParm();
|
||||
|
||||
if (s) // Check for NULL?
|
||||
D_AddFile(startuppwads, s);
|
||||
D_AddFile(startuppwads, num_startuppwads++, s, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1713,44 +1717,10 @@ void D_SRB2Main(void)
|
|||
|
||||
// load wad, including the main wad file
|
||||
CONS_Printf("W_InitMultipleFiles(): Adding IWAD and main PWADs.\n");
|
||||
W_InitMultipleFiles(startupiwads, false);
|
||||
D_CleanFile(startupiwads);
|
||||
|
||||
mainwads = 0;
|
||||
|
||||
#ifndef DEVELOP
|
||||
// Check MD5s of autoloaded files
|
||||
// Note: Do not add any files that ignore MD5!
|
||||
W_VerifyFileMD5(mainwads, ASSET_HASH_BIOS_PK3); // bios.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_SCRIPTS_PK3); // scripts.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_GFX_PK3); // gfx.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_TEXTURES_GENERAL_PK3); // textures_general.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_TEXTURES_SEGAZONES_PK3); // textures_segazones.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_TEXTURES_ORIGINALZONES_PK3); // textures_originalzones.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_CHARS_PK3); // chars.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_FOLLOWERS_PK3); // followers.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_PK3); // maps.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_UNLOCKS_PK3); // unlocks.pk3
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_STAFFGHOSTS_PK3); // staffghosts.pk3
|
||||
#ifdef USE_PATCH_FILE
|
||||
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3
|
||||
#endif
|
||||
#else
|
||||
mainwads++; // scripts.pk3
|
||||
mainwads++; // gfx.pk3
|
||||
mainwads++; // textures_general.pk3
|
||||
mainwads++; // textures_segazones.pk3
|
||||
mainwads++; // textures_originalzones.pk3
|
||||
mainwads++; // chars.pk3
|
||||
mainwads++; // followers.pk3
|
||||
mainwads++; // maps.pk3
|
||||
mainwads++; // unlocks.pk3
|
||||
mainwads++; // staffghosts.pk3
|
||||
#ifdef USE_PATCH_FILE
|
||||
mainwads++; // patch.pk3
|
||||
#endif
|
||||
|
||||
#endif //ifndef DEVELOP
|
||||
W_InitMultipleFiles(startupiwads, num_startupiwads, false);
|
||||
mainwads = num_startupiwads - musicwads;
|
||||
D_CleanFile(startupiwads, num_startupiwads);
|
||||
num_startupiwads = 0;
|
||||
|
||||
// Load credits_def lump
|
||||
F_LoadCreditsDefinitions();
|
||||
|
|
@ -1815,10 +1785,10 @@ void D_SRB2Main(void)
|
|||
|
||||
// HACK: Refer to https://git.do.srb2.org/KartKrew/RingRacers/-/merge_requests/29#note_61574
|
||||
partadd_earliestfile = numwadfiles;
|
||||
W_InitMultipleFiles(startuppwads, true);
|
||||
W_InitMultipleFiles(startuppwads, num_startuppwads, true);
|
||||
|
||||
// Only search for pwad maps and reload graphics if we actually have a pwad added
|
||||
if (startuppwads[0] != NULL)
|
||||
if (num_startuppwads > 0)
|
||||
{
|
||||
//
|
||||
// search for pwad maps
|
||||
|
|
@ -1827,7 +1797,8 @@ void D_SRB2Main(void)
|
|||
HU_LoadGraphics();
|
||||
}
|
||||
|
||||
D_CleanFile(startuppwads);
|
||||
D_CleanFile(startuppwads, num_startuppwads);
|
||||
num_startuppwads = 0;
|
||||
partadd_earliestfile = UINT16_MAX;
|
||||
|
||||
CON_SetLoadingProgress(LOADED_PWAD);
|
||||
|
|
|
|||
|
|
@ -9428,7 +9428,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename)
|
|||
// UINT16 mapPos, mapNum = 0;
|
||||
|
||||
// Init file.
|
||||
if ((numlumps = W_InitFile(wadfilename, false, false)) == INT16_MAX)
|
||||
if ((numlumps = W_InitFile(wadfilename, false, false, nullptr)) == INT16_MAX)
|
||||
{
|
||||
refreshdirmenu |= REFRESHDIR_NOTLOADED;
|
||||
return false;
|
||||
|
|
|
|||
119
src/w_wad.cpp
119
src/w_wad.cpp
|
|
@ -118,6 +118,10 @@ static FILE *g_shaderspk3file;
|
|||
static UINT16 g_shaderspk3numlumps;
|
||||
static lumpinfo_t *g_shaderspk3lumps;
|
||||
|
||||
#ifndef NOMD5
|
||||
static void PrintMD5String(const UINT8 *md5, char *buf);
|
||||
#endif
|
||||
|
||||
// W_Shutdown
|
||||
// Closes all of the WAD files before quitting
|
||||
// If not done on a Mac then open wad files
|
||||
|
|
@ -803,7 +807,7 @@ static UINT16 W_InitFileError (const char *filename, boolean exitworthy)
|
|||
//
|
||||
// Can now load dehacked files (.soc)
|
||||
//
|
||||
UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
|
||||
UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, const char *md5expected)
|
||||
{
|
||||
FILE *handle;
|
||||
lumpinfo_t *lumpinfo = NULL;
|
||||
|
|
@ -862,6 +866,53 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
|
|||
//
|
||||
W_MakeFileMD5(filename, md5sum);
|
||||
|
||||
if (md5expected)
|
||||
{
|
||||
// moved Graue's <graue@oceanbase.org> W_VerifyFileMD5 inline here
|
||||
UINT8 realmd5[MD5_LEN];
|
||||
INT32 ix;
|
||||
|
||||
I_Assert(strlen(md5expected) == 2*MD5_LEN);
|
||||
|
||||
// Convert an md5 string like "7d355827fa8f981482246d6c95f9bd48"
|
||||
// into a real md5.
|
||||
for (ix = 0; ix < 2*MD5_LEN; ix++)
|
||||
{
|
||||
INT32 n, c = md5expected[ix];
|
||||
if (isdigit(c))
|
||||
n = c - '0';
|
||||
else
|
||||
{
|
||||
I_Assert(isxdigit(c));
|
||||
if (isupper(c)) n = c - 'A' + 10;
|
||||
else n = c - 'a' + 10;
|
||||
}
|
||||
if (ix & 1) realmd5[ix>>1] = (UINT8)(realmd5[ix>>1]+n);
|
||||
else realmd5[ix>>1] = (UINT8)(n<<4);
|
||||
}
|
||||
|
||||
if (memcmp(realmd5, md5sum, 16) != 0)
|
||||
{
|
||||
char actualmd5text[2*MD5_LEN+1];
|
||||
PrintMD5String(md5sum, actualmd5text);
|
||||
#ifdef DEVELOP
|
||||
CONS_Printf("File %s does not match expected md5\n", filename);
|
||||
#else
|
||||
if (startup)
|
||||
{
|
||||
I_Error(M_GetText("File is old, is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), filename, actualmd5text, md5expected);
|
||||
}
|
||||
else
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("Did not load file %s because it did not match expected md5sum %s\n"), filename, md5expected);
|
||||
if (handle)
|
||||
fclose(handle);
|
||||
return W_InitFileError(filename, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < numwadfiles; i++)
|
||||
{
|
||||
if (!memcmp(wadfiles[i]->md5sum, md5sum, 16))
|
||||
|
|
@ -987,24 +1038,25 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup)
|
|||
* Each file is optional, but at least one file must be found or an error will
|
||||
* result. Lump names can appear multiple times. The name searcher looks
|
||||
* backwards, so a later file overrides all earlier ones.
|
||||
*
|
||||
* \param filenames A null-terminated list of files to use.
|
||||
*/
|
||||
INT32 W_InitMultipleFiles(char **filenames, boolean addons)
|
||||
INT32 W_InitMultipleFiles(const initmultiplefilesentry_t *entries, INT32 count, boolean addons)
|
||||
{
|
||||
INT32 i;
|
||||
INT32 rc = 1;
|
||||
INT32 overallrc = 1;
|
||||
|
||||
// will be realloced as lumps are added
|
||||
for (; *filenames; filenames++)
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
if (addons && !W_VerifyNMUSlumps(*filenames, !addons))
|
||||
const initmultiplefilesentry_t *entry = &entries[i];
|
||||
|
||||
if (addons && !W_VerifyNMUSlumps(entry->filename, !addons))
|
||||
G_SetGameModified(true, false);
|
||||
|
||||
//CONS_Debug(DBG_SETUP, "Loading %s\n", *filenames);
|
||||
rc = W_InitFile(*filenames, !addons, true);
|
||||
rc = W_InitFile(entry->filename, !addons, true, entry->md5sum);
|
||||
if (rc == INT16_MAX)
|
||||
CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), *filenames);
|
||||
CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), entry->filename);
|
||||
overallrc &= (rc != INT16_MAX) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
@ -2096,57 +2148,6 @@ static void PrintMD5String(const UINT8 *md5, char *buf)
|
|||
md5[12], md5[13], md5[14], md5[15]);
|
||||
}
|
||||
#endif
|
||||
/** Verifies a file's MD5 is as it should be.
|
||||
* For releases, used as cheat prevention -- if the MD5 doesn't match, a
|
||||
* fatal error is thrown. In debug mode, an MD5 mismatch only triggers a
|
||||
* warning.
|
||||
*
|
||||
* \param wadfilenum Number of the loaded wad file to check.
|
||||
* \param matchmd5 The MD5 sum this wad should have, expressed as a
|
||||
* textual string.
|
||||
* \author Graue <graue@oceanbase.org>
|
||||
*/
|
||||
void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5)
|
||||
{
|
||||
#ifdef NOMD5
|
||||
(void)wadfilenum;
|
||||
(void)matchmd5;
|
||||
#else
|
||||
UINT8 realmd5[MD5_LEN];
|
||||
INT32 ix;
|
||||
|
||||
I_Assert(strlen(matchmd5) == 2*MD5_LEN);
|
||||
I_Assert(wadfilenum < numwadfiles);
|
||||
// Convert an md5 string like "7d355827fa8f981482246d6c95f9bd48"
|
||||
// into a real md5.
|
||||
for (ix = 0; ix < 2*MD5_LEN; ix++)
|
||||
{
|
||||
INT32 n, c = matchmd5[ix];
|
||||
if (isdigit(c))
|
||||
n = c - '0';
|
||||
else
|
||||
{
|
||||
I_Assert(isxdigit(c));
|
||||
if (isupper(c)) n = c - 'A' + 10;
|
||||
else n = c - 'a' + 10;
|
||||
}
|
||||
if (ix & 1) realmd5[ix>>1] = (UINT8)(realmd5[ix>>1]+n);
|
||||
else realmd5[ix>>1] = (UINT8)(n<<4);
|
||||
}
|
||||
|
||||
if (memcmp(realmd5, wadfiles[wadfilenum]->md5sum, 16))
|
||||
{
|
||||
char actualmd5text[2*MD5_LEN+1];
|
||||
PrintMD5String(wadfiles[wadfilenum]->md5sum, actualmd5text);
|
||||
#ifdef _DEBUG
|
||||
CONS_Printf
|
||||
#else
|
||||
I_Error
|
||||
#endif
|
||||
(M_GetText("File is old, is corrupt or has been modified: %s (found md5: %s, wanted: %s)\n"), wadfiles[wadfilenum]->filename, actualmd5text, matchmd5);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Verify versions for different archive
|
||||
// formats. checklist assumed to be valid.
|
||||
|
|
|
|||
11
src/w_wad.h
11
src/w_wad.h
|
|
@ -145,12 +145,17 @@ void W_Shutdown(void);
|
|||
// Opens a WAD file. Returns the FILE * handle for the file, or NULL if not found or could not be opened
|
||||
FILE *W_OpenWadFile(const char **filename, boolean useerrors);
|
||||
// Load and add a wadfile to the active wad files, returns numbers of lumps, INT16_MAX on error
|
||||
UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup);
|
||||
UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, const char *md5expected);
|
||||
|
||||
typedef struct initmultiplefilesentry_t
|
||||
{
|
||||
const char *filename;
|
||||
const char *md5sum;
|
||||
} initmultiplefilesentry_t;
|
||||
// W_InitMultipleFiles returns 1 if all is okay, 0 otherwise,
|
||||
// so that it stops with a message if a file was not found, but not if all is okay.
|
||||
// W_InitMultipleFiles exits if a file was not found, but not if all is okay.
|
||||
INT32 W_InitMultipleFiles(char **filenames, boolean addons);
|
||||
INT32 W_InitMultipleFiles(const initmultiplefilesentry_t *entries, INT32 count, boolean addons);
|
||||
|
||||
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);
|
||||
const char *W_CheckNameForNum(lumpnum_t lumpnum);
|
||||
|
|
@ -217,8 +222,6 @@ void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag);
|
|||
|
||||
void W_UnlockCachedPatch(void *patch);
|
||||
|
||||
void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5);
|
||||
|
||||
int W_VerifyNMUSlumps(const char *filename, boolean exit_on_error);
|
||||
|
||||
/// Initialize non-legacy GL shader lookup, which lives outside the lump management system.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue