engine: return full path in server's pfnGetGameDir, if possible

This commit is contained in:
Alibek Omarov 2024-11-30 09:28:10 +03:00
parent 4798cd6d1e
commit 1f5c97964b
4 changed files with 25 additions and 13 deletions

View file

@ -1167,6 +1167,14 @@ static void GAME_EXPORT pfnSetCursor( void *hCursor )
Platform_SetCursorType( cursor );
}
static void GAME_EXPORT pfnGetGameDir( char *out )
{
if( !out )
return;
Q_strncpy( out, GI->gamefolder, sizeof( GI->gamefolder ));
}
// engine callbacks
static const ui_enginefuncs_t gEngfuncs =
{

View file

@ -897,18 +897,6 @@ float GAME_EXPORT pfnTime( void )
return (float)Sys_DoubleTime();
}
/*
=============
pfnGetGameDir
=============
*/
void GAME_EXPORT pfnGetGameDir( char *szGetGameDir )
{
if( !szGetGameDir ) return;
Q_strncpy( szGetGameDir, GI->gamefolder, sizeof( GI->gamefolder ));
}
qboolean COM_IsSafeFileToDownload( const char *filename )
{
char lwrfilename[4096];

View file

@ -592,7 +592,6 @@ void *Cache_Check( poolhandle_t mempool, struct cache_user_s *c );
void COM_TrimSpace( const char *source, char *dest );
void pfnGetModelBounds( model_t *mod, float *mins, float *maxs );
int COM_CheckParm( char *parm, char **ppnext );
void pfnGetGameDir( char *szGetGameDir );
int pfnGetModelType( model_t *mod );
int pfnIsMapValid( char *filename );
void Con_Reportf( const char *szFmt, ... ) FORMAT_CHECK( 1 );

View file

@ -4631,6 +4631,23 @@ static int GAME_EXPORT pfnGetTimesTutorMessageShown( int mid )
return 0;
}
static void GAME_EXPORT pfnGetGameDir( char *out )
{
char rootdir[MAX_SYSPATH];
if( !out )
return;
// in GoldSrc, it's a full path to game directory, limited by 256 characters
// however the full path might easily overflow that limitation
// here we check if it would overflow and just return game folder in that case
if( !g_fsapi.GetRootDirectory( rootdir, sizeof( rootdir ))
|| Q_snprintf( out, 256, "%s/%s", rootdir, GI->gamefolder ) < 0 )
{
Q_strncpy( out, GI->gamefolder, 256 );
}
}
// engine callbacks
static enginefuncs_t gEngfuncs =
{