From e89191ed3972eee79a99c00d324fca78d8c64924 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 30 May 2024 05:58:31 +0300 Subject: [PATCH] engine: common: automatically precache wad files required by loaded map Makes it easier to host server with multiplayer maps and broken .res files. --- engine/common/mod_bmodel.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index ef91d848..bc510bf2 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -3093,6 +3093,7 @@ static qboolean Mod_LoadBmodelLumps( model_t *mod, const byte *mod_base, qboolea char wadvalue[2048]; size_t len = 0; int i, ret, flags = 0; + qboolean wadlist_warn = false; // always reset the intermediate struct memset( bmod, 0, sizeof( dbspmodel_t )); @@ -3197,15 +3198,27 @@ static qboolean Mod_LoadBmodelLumps( model_t *mod, const byte *mod_base, qboolea for( i = 0; i < bmod->wadlist.count; i++ ) { + string wadname; + if( !bmod->wadlist.wadusage[i] ) continue; - ret = Q_snprintf( &wadvalue[len], sizeof( wadvalue ), "%s.wad; ", bmod->wadlist.wadnames[i] ); - if( ret == -1 ) + + Q_snprintf( wadname, sizeof( wadname ), "%s.wad", bmod->wadlist.wadnames[i] ); + + // a1ba: automatically precache used wad files so client will download it + if( SV_Active( )) + SV_GenericIndex( wadname ); + + if( !wadlist_warn ) { - Con_DPrintf( S_WARN "Too many wad files for output!\n" ); - break; + ret = Q_snprintf( &wadvalue[len], sizeof( wadvalue ), "%s; ", wadname ); + if( ret == -1 ) + { + Con_DPrintf( S_WARN "Too many wad files for output!\n" ); + wadlist_warn = true; + } + len += ret; } - len += ret; } if( COM_CheckString( wadvalue ))