From aee99f6094398e1a52b8a579b62d90d80be48420 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 3 Aug 2023 01:11:06 +0300 Subject: [PATCH] engine: don't release DLL that wasn't loaded during settings.scr parsing. This should be deleted as soon as possible! --- engine/common/common.h | 2 +- engine/common/con_utils.c | 8 ++++++-- engine/server/sv_init.c | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/engine/common/common.h b/engine/common/common.h index fb9f8f88..08160029 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -747,7 +747,7 @@ void SV_ShutdownGame( void ); void SV_ExecLoadLevel( void ); void SV_ExecLoadGame( void ); void SV_ExecChangeLevel( void ); -void SV_InitGameProgs( void ); +qboolean SV_InitGameProgs( void ); void SV_FreeGameProgs( void ); void CL_WriteMessageHistory( void ); void CL_SendCmd( void ); diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 6bba1ac1..e111470d 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -1423,12 +1423,14 @@ save serverinfo variables into server.cfg (using for dedicated server too) */ void GAME_EXPORT Host_WriteServerConfig( const char *name ) { + qboolean already_loaded; file_t *f; string newconfigfile; Q_snprintf( newconfigfile, MAX_STRING, "%s.new", name ); - SV_InitGameProgs(); // collect user variables + // TODO: remove this mechanism, make it safer for now + already_loaded = SV_InitGameProgs(); // collect user variables // FIXME: move this out until menu parser is done CSCR_LoadDefaultCVars( "settings.scr" ); @@ -1447,7 +1449,9 @@ void GAME_EXPORT Host_WriteServerConfig( const char *name ) } else Con_DPrintf( S_ERROR "Couldn't write %s.\n", name ); - SV_FreeGameProgs(); // release progs with all variables + // don't unload library that wasn't loaded by us + if( already_loaded ) + SV_FreeGameProgs(); // release progs with all variables } /* diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index b33d12b6..ce2c7ac3 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -1115,16 +1115,18 @@ int SV_GetMaxClients( void ) return svs.maxclients; } -void SV_InitGameProgs( void ) +qboolean SV_InitGameProgs( void ) { string dllpath; - if( svgame.hInstance ) return; // already loaded + if( svgame.hInstance ) return true; // already loaded COM_GetCommonLibraryPath( LIBRARY_SERVER, dllpath, sizeof( dllpath )); // just try to initialize SV_LoadProgs( dllpath ); + + return false; } void SV_FreeGameProgs( void )