2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
con_utils.c - console helpers
|
|
|
|
Copyright (C) 2008 Uncle Mike
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "const.h"
|
2018-04-13 18:58:17 +02:00
|
|
|
#include "kbutton.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2023-05-19 06:43:40 +02:00
|
|
|
extern convar_t con_gamemaps;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-06-14 20:19:04 +02:00
|
|
|
#define CON_MAXCMDS 4096 // auto-complete intermediate list
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
typedef struct autocomplete_list_s
|
|
|
|
{
|
|
|
|
const char *name;
|
2019-07-09 14:08:00 +02:00
|
|
|
int arg; // argument number to handle
|
2018-04-13 18:23:45 +02:00
|
|
|
qboolean (*func)( const char *s, char *name, int length );
|
|
|
|
} autocomplete_list_t;
|
|
|
|
|
2018-06-14 20:19:04 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
// console auto-complete
|
|
|
|
string shortestMatch;
|
|
|
|
field_t *completionField; // con.input or dedicated server fake field-line
|
|
|
|
const char *completionString;
|
|
|
|
const char *completionBuffer;
|
|
|
|
char *cmds[CON_MAXCMDS];
|
|
|
|
int matchCount;
|
|
|
|
} con_autocomplete_t;
|
|
|
|
|
|
|
|
static con_autocomplete_t con;
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
=======================================================================
|
|
|
|
|
|
|
|
FILENAME AUTOCOMPLETION
|
2018-06-14 20:19:04 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
=======================================================================
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
=====================================
|
2021-06-17 23:05:01 +02:00
|
|
|
Cmd_ListMaps
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
=====================================
|
|
|
|
*/
|
2021-06-17 23:05:01 +02:00
|
|
|
int Cmd_ListMaps( search_t *t, char *lastmapname, size_t len )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2021-06-17 23:05:01 +02:00
|
|
|
byte buf[MAX_SYSPATH]; // 1 kb
|
|
|
|
file_t *f;
|
|
|
|
int i, nummaps;
|
|
|
|
string mapname, message, compiler, generator;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
for( i = 0, nummaps = 0; i < t->numfilenames; i++ )
|
|
|
|
{
|
|
|
|
char entfilename[MAX_QPATH];
|
2021-01-03 02:28:45 +01:00
|
|
|
const char *ext = COM_FileExtension( t->filenames[i] );
|
2018-04-13 18:23:45 +02:00
|
|
|
int ver = -1, lumpofs = 0, lumplen = 0;
|
|
|
|
char *ents = NULL, *pfile;
|
|
|
|
int version = 0;
|
2019-07-13 22:25:03 +02:00
|
|
|
string version_description;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( Q_stricmp( ext, "bsp" )) continue;
|
|
|
|
Q_strncpy( message, "^1error^7", sizeof( message ));
|
2020-11-22 07:49:39 +01:00
|
|
|
compiler[0] = '\0';
|
|
|
|
generator[0] = '\0';
|
|
|
|
|
2023-05-19 06:43:40 +02:00
|
|
|
f = FS_Open( t->filenames[i], "rb", con_gamemaps.value );
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
if( f )
|
|
|
|
{
|
2023-01-03 05:01:36 +01:00
|
|
|
dheader_t *header;
|
2018-04-13 18:23:45 +02:00
|
|
|
dextrahdr_t *hdrext;
|
2023-01-03 05:01:36 +01:00
|
|
|
dlump_t entities;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ));
|
|
|
|
FS_Read( f, buf, sizeof( buf ));
|
|
|
|
header = (dheader_t *)buf;
|
|
|
|
ver = header->version;
|
|
|
|
|
|
|
|
// check all the lumps and some other errors
|
2023-01-03 05:01:36 +01:00
|
|
|
if( Mod_TestBmodelLumps( f, t->filenames[i], buf, true, &entities ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2023-01-03 05:01:36 +01:00
|
|
|
lumpofs = entities.fileofs;
|
|
|
|
lumplen = entities.filelen;
|
2018-04-13 18:23:45 +02:00
|
|
|
ver = header->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdrext = (dextrahdr_t *)((byte *)buf + sizeof( dheader_t ));
|
|
|
|
if( hdrext->id == IDEXTRAHEADER ) version = hdrext->version;
|
|
|
|
|
|
|
|
Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename ));
|
2023-04-26 03:57:28 +02:00
|
|
|
COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename ));
|
2019-07-13 22:25:03 +02:00
|
|
|
ents = (char *)FS_LoadFile( entfilename, NULL, true );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !ents && lumplen >= 10 )
|
|
|
|
{
|
|
|
|
FS_Seek( f, lumpofs, SEEK_SET );
|
2018-06-09 00:28:35 +02:00
|
|
|
ents = (char *)Mem_Calloc( host.mempool, lumplen + 1 );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Read( f, ents, lumplen );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ents )
|
|
|
|
{
|
|
|
|
// if there are entities to parse, a missing message key just
|
|
|
|
// means there is no title, so clear the message string now
|
|
|
|
char token[2048];
|
|
|
|
|
|
|
|
message[0] = 0; // remove 'error'
|
|
|
|
pfile = ents;
|
|
|
|
|
2021-10-01 19:40:36 +02:00
|
|
|
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( !Q_strcmp( token, "{" )) continue;
|
|
|
|
else if( !Q_strcmp( token, "}" )) break;
|
|
|
|
else if( !Q_strcmp( token, "message" ))
|
|
|
|
{
|
|
|
|
// get the message contents
|
2021-10-01 19:40:36 +02:00
|
|
|
pfile = COM_ParseFile( pfile, message, sizeof( message ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else if( !Q_strcmp( token, "compiler" ) || !Q_strcmp( token, "_compiler" ))
|
|
|
|
{
|
|
|
|
// get the message contents
|
2021-10-01 19:40:36 +02:00
|
|
|
pfile = COM_ParseFile( pfile, compiler, sizeof( compiler ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else if( !Q_strcmp( token, "generator" ) || !Q_strcmp( token, "_generator" ))
|
|
|
|
{
|
|
|
|
// get the message contents
|
2021-10-01 19:40:36 +02:00
|
|
|
pfile = COM_ParseFile( pfile, generator, sizeof( generator ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Mem_Free( ents );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( f ) FS_Close(f);
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], mapname, sizeof( mapname ));
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
switch( ver )
|
|
|
|
{
|
|
|
|
case Q1BSP_VERSION:
|
2019-07-13 22:25:03 +02:00
|
|
|
Q_strncpy( version_description, "Quake", sizeof( version_description ));
|
2018-04-13 18:23:45 +02:00
|
|
|
break;
|
|
|
|
case QBSP2_VERSION:
|
2019-07-13 22:25:03 +02:00
|
|
|
Q_strncpy( version_description, "Darkplaces BSP2", sizeof( version_description ));
|
2018-04-13 18:23:45 +02:00
|
|
|
break;
|
|
|
|
case HLBSP_VERSION:
|
|
|
|
switch( version )
|
|
|
|
{
|
2019-07-13 22:25:03 +02:00
|
|
|
case 1: Q_strncpy( version_description, "XashXT old format", sizeof( version_description )); break;
|
|
|
|
case 2: Q_strncpy( version_description, "Paranoia 2: Savior", sizeof( version_description )); break;
|
|
|
|
case 4: Q_strncpy( version_description, "Half-Life extended", sizeof( version_description )); break;
|
|
|
|
default: Q_strncpy( version_description, "Half-Life", sizeof( version_description )); break;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-07-13 22:25:03 +02:00
|
|
|
default: Q_strncpy( version_description, "??", sizeof( version_description )); break;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2021-06-17 23:05:01 +02:00
|
|
|
Con_Printf( "%16s (%s) ^3%s^7 ^2%s %s^7\n", mapname, version_description, message, compiler, generator );
|
2018-04-13 18:23:45 +02:00
|
|
|
nummaps++;
|
|
|
|
}
|
|
|
|
|
2021-06-17 23:05:01 +02:00
|
|
|
if( lastmapname && len )
|
|
|
|
Q_strncpy( lastmapname, mapname, len );
|
|
|
|
|
|
|
|
return nummaps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetMapList
|
|
|
|
|
|
|
|
Prints or complete map filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetMapList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, nummaps;
|
|
|
|
|
2023-05-19 06:43:40 +02:00
|
|
|
t = FS_Search( va( "maps/%s*.bsp", s ), true, con_gamemaps.value );
|
2021-06-17 23:05:01 +02:00
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2021-06-17 23:05:01 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
nummaps = Cmd_ListMaps( t, matchbuf, sizeof( matchbuf ));
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %d maps found.\n", nummaps );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetDemoList
|
|
|
|
|
|
|
|
Prints or complete demo filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetDemoList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numdems;
|
|
|
|
|
2018-11-27 14:11:26 +01:00
|
|
|
// lookup only in gamedir
|
|
|
|
t = FS_Search( va( "%s*.dem", s ), true, true );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0, numdems = 0; i < t->numfilenames; i++ )
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "dem" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numdems++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i demos found.\n", numdems );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetMovieList
|
|
|
|
|
|
|
|
Prints or complete movie filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetMovieList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, nummovies;
|
|
|
|
|
|
|
|
t = FS_Search( va( "media/%s*.avi", s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for(i = 0, nummovies = 0; i < t->numfilenames; i++)
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "avi" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
nummovies++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i movies found.\n", nummovies );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetMusicList
|
|
|
|
|
|
|
|
Prints or complete background track filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetMusicList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numtracks;
|
|
|
|
|
|
|
|
t = FS_Search( va( "media/%s*.*", s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for(i = 0, numtracks = 0; i < t->numfilenames; i++)
|
|
|
|
{
|
2021-01-03 02:28:45 +01:00
|
|
|
const char *ext = COM_FileExtension( t->filenames[i] );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( Q_stricmp( ext, "wav" ) && Q_stricmp( ext, "mp3" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numtracks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i soundtracks found.\n", numtracks );
|
|
|
|
Mem_Free(t);
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetSavesList
|
|
|
|
|
|
|
|
Prints or complete savegame filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetSavesList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numsaves;
|
|
|
|
|
2022-12-04 16:08:28 +01:00
|
|
|
t = FS_Search( va( DEFAULT_SAVE_DIRECTORY "%s*.sav", s ), true, true ); // lookup only in gamedir
|
2018-04-13 18:23:45 +02:00
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0, numsaves = 0; i < t->numfilenames; i++ )
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "sav" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numsaves++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i saves found.\n", numsaves );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetConfigList
|
|
|
|
|
|
|
|
Prints or complete .cfg filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetConfigList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numconfigs;
|
|
|
|
|
|
|
|
t = FS_Search( va( "%s*.cfg", s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0, numconfigs = 0; i < t->numfilenames; i++ )
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "cfg" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numconfigs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i configs found.\n", numconfigs );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetSoundList
|
|
|
|
|
|
|
|
Prints or complete sound filename
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetSoundList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numsounds;
|
|
|
|
|
|
|
|
t = FS_Search( va( "%s%s*.*", DEFAULT_SOUNDPATH, s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
Q_strncpy( matchbuf, t->filenames[0] + sizeof( DEFAULT_SOUNDPATH ) - 1, MAX_STRING );
|
|
|
|
COM_StripExtension( matchbuf );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for(i = 0, numsounds = 0; i < t->numfilenames; i++)
|
|
|
|
{
|
2021-01-03 02:28:45 +01:00
|
|
|
const char *ext = COM_FileExtension( t->filenames[i] );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( Q_stricmp( ext, "wav" ) && Q_stricmp( ext, "mp3" ))
|
|
|
|
continue;
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
Q_strncpy( matchbuf, t->filenames[i] + sizeof( DEFAULT_SOUNDPATH ) - 1, MAX_STRING );
|
2018-04-13 18:23:45 +02:00
|
|
|
COM_StripExtension( matchbuf );
|
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numsounds++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i sounds found.\n", numsounds );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_DEDICATED
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetItemsList
|
|
|
|
|
|
|
|
Prints or complete item classname (weapons only)
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetItemsList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numitems;
|
|
|
|
|
|
|
|
if( !clgame.itemspath[0] ) return false; // not in game yet
|
|
|
|
t = FS_Search( va( "%s/%s*.txt", clgame.itemspath, s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for(i = 0, numitems = 0; i < t->numfilenames; i++)
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "txt" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numitems++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i items found.\n", numitems );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-09 14:08:00 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetKeysList
|
|
|
|
|
|
|
|
Autocomplete for bind command
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetKeysList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
size_t i, numkeys;
|
|
|
|
string keys[256];
|
|
|
|
string matchbuf;
|
2020-11-22 07:49:39 +01:00
|
|
|
int len;
|
2019-07-09 14:08:00 +02:00
|
|
|
|
|
|
|
// compare keys list with current keyword
|
2020-11-22 07:49:39 +01:00
|
|
|
len = Q_strlen( s );
|
|
|
|
|
2019-07-09 14:08:00 +02:00
|
|
|
for( i = 0, numkeys = 0; i < 255; i++ )
|
|
|
|
{
|
|
|
|
const char *keyname = Key_KeynumToString( i );
|
|
|
|
|
2020-11-22 07:49:39 +01:00
|
|
|
if(( *s == '*' ) || !Q_strnicmp( keyname, s, len))
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( keys[numkeys++], keyname, sizeof( keys[0] ));
|
2019-07-09 14:08:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !numkeys ) return false;
|
|
|
|
Q_strncpy( matchbuf, keys[0], sizeof( matchbuf ));
|
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( numkeys == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0; i < numkeys; i++ )
|
|
|
|
{
|
|
|
|
Q_strncpy( matchbuf, keys[i], sizeof( matchbuf ));
|
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
}
|
|
|
|
|
2019-10-19 15:47:16 +02:00
|
|
|
Con_Printf( "\n^3 %lu keys found.\n", numkeys );
|
2019-07-09 14:08:00 +02:00
|
|
|
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // XASH_DEDICATED
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Con_AddCommandToList
|
|
|
|
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void Con_AddCommandToList( const char *s, const char *unused1, const char *unused2, void *_autocompleteList )
|
|
|
|
{
|
|
|
|
con_autocomplete_t *list = (con_autocomplete_t*)_autocompleteList;
|
|
|
|
|
|
|
|
if( *s == '@' ) return; // never show system cvars or cmds
|
|
|
|
if( list->matchCount >= CON_MAXCMDS ) return; // list is full
|
|
|
|
|
|
|
|
if( Q_strnicmp( s, list->completionString, Q_strlen( list->completionString ) ) )
|
|
|
|
return; // no match
|
|
|
|
|
|
|
|
list->cmds[list->matchCount++] = copystring( s );
|
|
|
|
}
|
|
|
|
|
2019-07-09 14:10:32 +02:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Con_SortCmds
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
static int Con_SortCmds( const void *arg1, const void *arg2 )
|
|
|
|
{
|
|
|
|
return Q_stricmp( *(const char **)arg1, *(const char **)arg2 );
|
|
|
|
}
|
|
|
|
|
2019-07-09 14:08:00 +02:00
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetCommandsList
|
|
|
|
|
|
|
|
Autocomplete for bind command
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetCommandsList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
string matchbuf;
|
|
|
|
con_autocomplete_t list; // local autocomplete list
|
|
|
|
|
|
|
|
memset( &list, 0, sizeof( list ));
|
|
|
|
|
|
|
|
list.completionString = s;
|
|
|
|
|
|
|
|
// skip backslash
|
|
|
|
while( *list.completionString && (*list.completionString == '\\' || *list.completionString == '/') )
|
|
|
|
list.completionString++;
|
|
|
|
|
2020-11-22 07:49:39 +01:00
|
|
|
if( !COM_CheckStringEmpty( list.completionString ) )
|
2019-07-09 14:08:00 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// find matching commands and variables
|
|
|
|
Cmd_LookupCmds( NULL, &list, (setpair_t)Con_AddCommandToList );
|
|
|
|
Cvar_LookupVars( 0, NULL, &list, (setpair_t)Con_AddCommandToList );
|
|
|
|
|
|
|
|
if( !list.matchCount ) return false;
|
|
|
|
Q_strncpy( matchbuf, list.cmds[0], sizeof( matchbuf ));
|
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( list.matchCount == 1 ) return true;
|
|
|
|
|
2019-07-09 14:10:32 +02:00
|
|
|
qsort( list.cmds, list.matchCount, sizeof( char* ), Con_SortCmds );
|
|
|
|
|
2019-07-09 14:08:00 +02:00
|
|
|
for( i = 0; i < list.matchCount; i++ )
|
|
|
|
{
|
|
|
|
Q_strncpy( matchbuf, list.cmds[i], sizeof( matchbuf ));
|
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i commands found.\n", list.matchCount );
|
|
|
|
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0; i < list.matchCount; i++ )
|
|
|
|
{
|
|
|
|
if( list.cmds[i] != NULL )
|
|
|
|
{
|
|
|
|
Mem_Free( list.cmds[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetCustomList
|
|
|
|
|
|
|
|
Prints or complete .HPK filenames
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetCustomList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
search_t *t;
|
|
|
|
string matchbuf;
|
|
|
|
int i, numitems;
|
|
|
|
|
|
|
|
t = FS_Search( va( "%s*.hpk", s ), true, false );
|
|
|
|
if( !t ) return false;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[0], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( t->numfilenames == 1 ) return true;
|
|
|
|
|
|
|
|
for(i = 0, numitems = 0; i < t->numfilenames; i++)
|
|
|
|
{
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "hpk" ))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], matchbuf, sizeof( matchbuf ));
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
numitems++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i items found.\n", numitems );
|
|
|
|
Mem_Free( t );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetGameList
|
|
|
|
|
|
|
|
Prints or complete gamedir name
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetGamesList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
int i, numgamedirs;
|
|
|
|
string gamedirs[MAX_MODS];
|
|
|
|
string matchbuf;
|
2020-11-22 07:49:39 +01:00
|
|
|
int len;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// stand-alone games doesn't have cmd "game"
|
|
|
|
if( !Cmd_Exists( "game" ))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// compare gamelist with current keyword
|
2020-11-22 07:49:39 +01:00
|
|
|
len = Q_strlen( s );
|
|
|
|
|
2022-07-01 18:37:21 +02:00
|
|
|
for( i = 0, numgamedirs = 0; i < FI->numgames; i++ )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-07-01 18:37:21 +02:00
|
|
|
if(( *s == '*' ) || !Q_strnicmp( FI->games[i]->gamefolder, s, len))
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( gamedirs[numgamedirs++], FI->games[i]->gamefolder, sizeof( gamedirs[0] ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !numgamedirs ) return false;
|
2021-01-03 02:28:45 +01:00
|
|
|
Q_strncpy( matchbuf, gamedirs[0], MAX_STRING );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( numgamedirs == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0; i < numgamedirs; i++ )
|
|
|
|
{
|
2021-01-03 02:28:45 +01:00
|
|
|
Q_strncpy( matchbuf, gamedirs[i], MAX_STRING );
|
2018-04-13 18:23:45 +02:00
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i games found.\n", numgamedirs );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================================
|
|
|
|
Cmd_GetCDList
|
|
|
|
|
|
|
|
Prints or complete CD command name
|
|
|
|
=====================================
|
|
|
|
*/
|
|
|
|
qboolean Cmd_GetCDList( const char *s, char *completedname, int length )
|
|
|
|
{
|
|
|
|
int i, numcdcommands;
|
|
|
|
string cdcommands[8];
|
|
|
|
string matchbuf;
|
2020-11-22 07:49:39 +01:00
|
|
|
int len;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
const char *cd_command[] =
|
|
|
|
{
|
|
|
|
"info",
|
|
|
|
"loop",
|
|
|
|
"off",
|
|
|
|
"on",
|
|
|
|
"pause",
|
|
|
|
"play",
|
|
|
|
"resume",
|
|
|
|
"stop",
|
|
|
|
};
|
|
|
|
|
|
|
|
// compare CD command list with current keyword
|
2020-11-22 07:49:39 +01:00
|
|
|
len = Q_strlen( s );
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
for( i = 0, numcdcommands = 0; i < 8; i++ )
|
|
|
|
{
|
2020-11-22 07:49:39 +01:00
|
|
|
if(( *s == '*' ) || !Q_strnicmp( cd_command[i], s, len))
|
2023-04-24 01:18:40 +02:00
|
|
|
Q_strncpy( cdcommands[numcdcommands++], cd_command[i], sizeof( cdcommands[0] ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !numcdcommands ) return false;
|
|
|
|
Q_strncpy( matchbuf, cdcommands[0], MAX_STRING );
|
|
|
|
if( completedname && length )
|
|
|
|
Q_strncpy( completedname, matchbuf, length );
|
|
|
|
if( numcdcommands == 1 ) return true;
|
|
|
|
|
|
|
|
for( i = 0; i < numcdcommands; i++ )
|
|
|
|
{
|
|
|
|
Q_strncpy( matchbuf, cdcommands[i], MAX_STRING );
|
|
|
|
Con_Printf( "%16s\n", matchbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
Con_Printf( "\n^3 %i commands found.\n", numcdcommands );
|
|
|
|
|
|
|
|
// cut shortestMatch to the amount common with s
|
|
|
|
if( completedname && length )
|
|
|
|
{
|
|
|
|
for( i = 0; matchbuf[i]; i++ )
|
|
|
|
{
|
|
|
|
if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] ))
|
|
|
|
completedname[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean Cmd_CheckMapsList_R( qboolean fRefresh, qboolean onlyingamedir )
|
|
|
|
{
|
2018-10-27 22:31:55 +02:00
|
|
|
qboolean use_filter = false;
|
2018-04-13 18:23:45 +02:00
|
|
|
byte buf[MAX_SYSPATH];
|
2018-10-27 22:31:55 +02:00
|
|
|
string mpfilter;
|
2018-04-13 18:23:45 +02:00
|
|
|
char *buffer;
|
2023-04-23 21:56:05 +02:00
|
|
|
size_t buffersize;
|
2018-04-13 18:23:45 +02:00
|
|
|
string result;
|
|
|
|
int i, size;
|
|
|
|
search_t *t;
|
|
|
|
file_t *f;
|
|
|
|
|
|
|
|
if( FS_FileSize( "maps.lst", onlyingamedir ) > 0 && !fRefresh )
|
2021-01-03 02:28:45 +01:00
|
|
|
return true; // exist
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-10-27 22:31:55 +02:00
|
|
|
// setup mpfilter
|
2020-11-22 07:49:39 +01:00
|
|
|
size = Q_snprintf( mpfilter, sizeof( mpfilter ), "maps/%s", GI->mp_filter );
|
2018-04-13 18:23:45 +02:00
|
|
|
t = FS_Search( "maps/*.bsp", false, onlyingamedir );
|
|
|
|
|
|
|
|
if( !t )
|
|
|
|
{
|
|
|
|
if( onlyingamedir )
|
|
|
|
{
|
|
|
|
// mod doesn't contain any maps (probably this is a bot)
|
|
|
|
return Cmd_CheckMapsList_R( fRefresh, false );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-23 21:56:05 +02:00
|
|
|
buffersize = t->numfilenames * 2 * sizeof( result );
|
|
|
|
buffer = Mem_Calloc( host.mempool, buffersize );
|
2020-11-22 07:49:39 +01:00
|
|
|
use_filter = COM_CheckStringEmpty( GI->mp_filter ) ? true : false;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
for( i = 0; i < t->numfilenames; i++ )
|
|
|
|
{
|
|
|
|
char *ents = NULL, *pfile;
|
|
|
|
int lumpofs = 0, lumplen = 0;
|
|
|
|
string mapname, message, entfilename;
|
|
|
|
|
|
|
|
if( Q_stricmp( COM_FileExtension( t->filenames[i] ), "bsp" ))
|
|
|
|
continue;
|
|
|
|
|
2021-06-07 14:53:20 +02:00
|
|
|
if( use_filter && Q_stristr( t->filenames[i], mpfilter ))
|
2018-10-27 22:31:55 +02:00
|
|
|
continue;
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
f = FS_Open( t->filenames[i], "rb", onlyingamedir );
|
2023-04-26 03:04:48 +02:00
|
|
|
COM_FileBase( t->filenames[i], mapname, sizeof( mapname ));
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
int num_spawnpoints = 0;
|
|
|
|
dheader_t *header;
|
2023-01-03 05:01:36 +01:00
|
|
|
dlump_t entities;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
memset( buf, 0, MAX_SYSPATH );
|
|
|
|
FS_Read( f, buf, MAX_SYSPATH );
|
|
|
|
header = (dheader_t *)buf;
|
|
|
|
|
|
|
|
// check all the lumps and some other errors
|
2023-01-03 05:01:36 +01:00
|
|
|
if( !Mod_TestBmodelLumps( f, t->filenames[i], buf, true, &entities ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
FS_Close( f );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-07-19 19:23:08 +02:00
|
|
|
// after call Mod_TestBmodelLumps we gurantee what map is valid
|
2023-01-03 05:01:36 +01:00
|
|
|
lumpofs = entities.fileofs;
|
|
|
|
lumplen = entities.filelen;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename ));
|
2023-04-26 03:57:28 +02:00
|
|
|
COM_ReplaceExtension( entfilename, ".ent", sizeof( entfilename ));
|
2019-07-13 22:25:03 +02:00
|
|
|
ents = (char *)FS_LoadFile( entfilename, NULL, true );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !ents && lumplen >= 10 )
|
|
|
|
{
|
|
|
|
FS_Seek( f, lumpofs, SEEK_SET );
|
2018-06-09 00:28:35 +02:00
|
|
|
ents = Z_Calloc( lumplen + 1 );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Read( f, ents, lumplen );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ents )
|
|
|
|
{
|
|
|
|
// if there are entities to parse, a missing message key just
|
|
|
|
// means there is no title, so clear the message string now
|
|
|
|
char token[MAX_TOKEN];
|
|
|
|
qboolean worldspawn = true;
|
|
|
|
|
|
|
|
Q_strncpy( message, "No Title", MAX_STRING );
|
|
|
|
pfile = ents;
|
|
|
|
|
2021-10-01 19:40:36 +02:00
|
|
|
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( token[0] == '}' && worldspawn )
|
|
|
|
worldspawn = false;
|
|
|
|
else if( !Q_strcmp( token, "message" ) && worldspawn )
|
|
|
|
{
|
|
|
|
// get the message contents
|
2021-10-01 19:40:36 +02:00
|
|
|
pfile = COM_ParseFile( pfile, message, sizeof( message ));
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else if( !Q_strcmp( token, "classname" ))
|
|
|
|
{
|
2021-10-01 19:40:36 +02:00
|
|
|
pfile = COM_ParseFile( pfile, token, sizeof( token ));
|
2018-10-27 22:31:55 +02:00
|
|
|
if( !Q_strcmp( token, GI->mp_entity ) || use_filter )
|
2018-04-13 18:23:45 +02:00
|
|
|
num_spawnpoints++;
|
|
|
|
}
|
|
|
|
if( num_spawnpoints ) break; // valid map
|
|
|
|
}
|
|
|
|
Mem_Free( ents );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( f ) FS_Close( f );
|
|
|
|
|
|
|
|
if( num_spawnpoints )
|
|
|
|
{
|
|
|
|
// format: mapname "maptitle"\n
|
2023-04-23 21:56:05 +02:00
|
|
|
Q_snprintf( result, sizeof( result ), "%s \"%s\"\n", mapname, message );
|
|
|
|
Q_strncat( buffer, result, buffersize ); // add new string
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( t ) Mem_Free( t ); // free search result
|
|
|
|
size = Q_strlen( buffer );
|
|
|
|
|
|
|
|
if( !size )
|
|
|
|
{
|
2019-07-19 19:23:08 +02:00
|
|
|
if( buffer ) Mem_Free( buffer );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( onlyingamedir )
|
|
|
|
return Cmd_CheckMapsList_R( fRefresh, false );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write generated maps.lst
|
2020-11-22 07:49:39 +01:00
|
|
|
if( FS_WriteFile( "maps.lst", buffer, size))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-07-19 19:23:08 +02:00
|
|
|
if( buffer ) Mem_Free( buffer );
|
2018-04-13 18:23:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-19 02:15:54 +01:00
|
|
|
int GAME_EXPORT Cmd_CheckMapsList( int fRefresh )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
return Cmd_CheckMapsList_R( fRefresh, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
autocomplete_list_t cmd_list[] =
|
|
|
|
{
|
2019-07-09 14:08:00 +02:00
|
|
|
{ "map_background", 1, Cmd_GetMapList },
|
|
|
|
{ "changelevel2", 1, Cmd_GetMapList },
|
|
|
|
{ "changelevel", 1, Cmd_GetMapList },
|
|
|
|
{ "playdemo", 1, Cmd_GetDemoList, },
|
|
|
|
{ "timedemo", 1, Cmd_GetDemoList, },
|
|
|
|
{ "playvol", 1, Cmd_GetSoundList },
|
|
|
|
{ "hpkval", 1, Cmd_GetCustomList },
|
2019-07-09 14:23:55 +02:00
|
|
|
{ "hpklist", 1, Cmd_GetCustomList },
|
|
|
|
{ "hpkextract", 1, Cmd_GetCustomList },
|
2019-07-09 14:08:00 +02:00
|
|
|
{ "entpatch", 1, Cmd_GetMapList },
|
|
|
|
{ "music", 1, Cmd_GetMusicList, },
|
|
|
|
{ "movie", 1, Cmd_GetMovieList },
|
|
|
|
{ "exec", 1, Cmd_GetConfigList },
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_DEDICATED
|
2019-07-09 14:08:00 +02:00
|
|
|
{ "give", 1, Cmd_GetItemsList },
|
|
|
|
{ "drop", 1, Cmd_GetItemsList },
|
|
|
|
{ "bind", 1, Cmd_GetKeysList },
|
|
|
|
{ "unbind", 1, Cmd_GetKeysList },
|
|
|
|
{ "bind", 2, Cmd_GetCommandsList },
|
2018-04-18 17:32:30 +02:00
|
|
|
#endif
|
2019-07-09 14:08:00 +02:00
|
|
|
{ "game", 1, Cmd_GetGamesList },
|
|
|
|
{ "save", 1, Cmd_GetSavesList },
|
|
|
|
{ "load", 1, Cmd_GetSavesList },
|
|
|
|
{ "play", 1, Cmd_GetSoundList },
|
|
|
|
{ "map", 1, Cmd_GetMapList },
|
|
|
|
{ "cd", 1, Cmd_GetCDList },
|
2023-04-19 16:54:45 +02:00
|
|
|
{ "mp3", 1, Cmd_GetCDList },
|
2018-04-13 18:23:45 +02:00
|
|
|
{ NULL }, // termiantor
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Cmd_CheckName
|
|
|
|
|
|
|
|
compare first argument with string
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static qboolean Cmd_CheckName( const char *name )
|
|
|
|
{
|
2023-03-13 22:35:07 +01:00
|
|
|
const char *p = Cmd_Argv( 0 );
|
2023-03-13 04:08:36 +01:00
|
|
|
|
|
|
|
if( !Q_stricmp( p, name ))
|
2018-04-13 18:23:45 +02:00
|
|
|
return true;
|
2023-03-13 04:08:36 +01:00
|
|
|
|
|
|
|
if( p[0] == '\\' && !Q_stricmp( &p[1], name ))
|
2018-04-13 18:23:45 +02:00
|
|
|
return true;
|
2023-03-13 04:08:36 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cmd_AutocompleteName
|
|
|
|
|
|
|
|
Autocomplete filename
|
|
|
|
for various cmds
|
|
|
|
============
|
|
|
|
*/
|
2019-07-09 14:08:00 +02:00
|
|
|
qboolean Cmd_AutocompleteName( const char *source, int arg, char *buffer, size_t bufsize )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
autocomplete_list_t *list;
|
|
|
|
|
|
|
|
for( list = cmd_list; list->name; list++ )
|
|
|
|
{
|
2019-07-09 14:08:00 +02:00
|
|
|
if( list->arg == arg && Cmd_CheckName( list->name ))
|
2021-01-03 02:28:45 +01:00
|
|
|
return list->func( source, buffer, bufsize );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-14 20:19:04 +02:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Con_PrintCmdMatches
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void Con_PrintCmdMatches( const char *s, const char *unused1, const char *m, void *unused2 )
|
|
|
|
{
|
|
|
|
if( !Q_strnicmp( s, con.shortestMatch, Q_strlen( con.shortestMatch ) ) )
|
|
|
|
{
|
|
|
|
if( COM_CheckString( m ) ) Con_Printf( " %s ^3\"%s\"\n", s, m );
|
|
|
|
else Con_Printf( " %s\n", s ); // variable or command without description
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Con_PrintCvarMatches
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void Con_PrintCvarMatches( const char *s, const char *value, const char *m, void *unused2 )
|
|
|
|
{
|
|
|
|
if( !Q_strnicmp( s, con.shortestMatch, Q_strlen( con.shortestMatch ) ) )
|
|
|
|
{
|
|
|
|
if( COM_CheckString( m ) ) Con_Printf( " %s (%s) ^3\"%s\"\n", s, value, m );
|
|
|
|
else Con_Printf( " %s (%s)\n", s, value ); // variable or command without description
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Con_ConcatRemaining
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void Con_ConcatRemaining( const char *src, const char *start )
|
|
|
|
{
|
|
|
|
const char *arg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
arg = Q_strstr( src, start );
|
|
|
|
|
|
|
|
if( !arg )
|
|
|
|
{
|
|
|
|
for( i = 1; i < Cmd_Argc(); i++ )
|
|
|
|
{
|
|
|
|
Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer ) );
|
|
|
|
arg = Cmd_Argv( i );
|
|
|
|
while( *arg )
|
|
|
|
{
|
|
|
|
if( *arg == ' ' )
|
|
|
|
{
|
|
|
|
Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_strncat( con.completionField->buffer, Cmd_Argv( i ), sizeof( con.completionField->buffer ) );
|
|
|
|
if( *arg == ' ' ) Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer ) );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
arg += Q_strlen( start );
|
|
|
|
Q_strncat( con.completionField->buffer, arg, sizeof( con.completionField->buffer ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Con_CompleteCommand
|
|
|
|
|
|
|
|
perform Tab expansion
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Con_CompleteCommand( field_t *field )
|
|
|
|
{
|
|
|
|
field_t temp;
|
|
|
|
string filename;
|
|
|
|
qboolean nextcmd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// setup the completion field
|
|
|
|
con.completionField = field;
|
|
|
|
|
|
|
|
// only look at the first token for completion purposes
|
|
|
|
Cmd_TokenizeString( con.completionField->buffer );
|
|
|
|
|
|
|
|
nextcmd = (con.completionField->buffer[Q_strlen( con.completionField->buffer ) - 1] == ' ') ? true : false;
|
|
|
|
|
|
|
|
con.completionString = Cmd_Argv( 0 );
|
|
|
|
|
|
|
|
// skip backslash
|
|
|
|
while( *con.completionString && (*con.completionString == '\\' || *con.completionString == '/') )
|
|
|
|
con.completionString++;
|
|
|
|
|
2020-11-22 07:49:39 +01:00
|
|
|
if( !COM_CheckStringEmpty( con.completionString ) )
|
2018-06-14 20:19:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// free the old autocomplete list
|
|
|
|
for( i = 0; i < con.matchCount; i++ )
|
|
|
|
{
|
|
|
|
if( con.cmds[i] != NULL )
|
|
|
|
{
|
|
|
|
Mem_Free( con.cmds[i] );
|
|
|
|
con.cmds[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
con.matchCount = 0;
|
|
|
|
con.shortestMatch[0] = 0;
|
|
|
|
|
|
|
|
// find matching commands and variables
|
2019-07-09 14:08:00 +02:00
|
|
|
Cmd_LookupCmds( NULL, &con, (setpair_t)Con_AddCommandToList );
|
|
|
|
Cvar_LookupVars( 0, NULL, &con, (setpair_t)Con_AddCommandToList );
|
2018-06-14 20:19:04 +02:00
|
|
|
|
|
|
|
if( !con.matchCount ) return; // no matches
|
|
|
|
|
|
|
|
memcpy( &temp, con.completionField, sizeof( field_t ) );
|
|
|
|
|
|
|
|
// autocomplete second arg
|
2019-07-09 14:08:00 +02:00
|
|
|
if( (Cmd_Argc() >= 2) || ((Cmd_Argc() == 1) && nextcmd) )
|
2018-06-14 20:19:04 +02:00
|
|
|
{
|
2019-07-09 14:08:00 +02:00
|
|
|
con.completionBuffer = Cmd_Argv( Cmd_Argc() - 1 );
|
|
|
|
|
|
|
|
// skip backslash
|
|
|
|
while( *con.completionBuffer && (*con.completionBuffer == '\\' || *con.completionBuffer == '/') )
|
|
|
|
con.completionBuffer++;
|
|
|
|
|
2020-11-22 07:49:39 +01:00
|
|
|
if( !COM_CheckStringEmpty( con.completionBuffer ) )
|
2018-06-14 20:19:04 +02:00
|
|
|
return;
|
|
|
|
|
2019-07-09 14:08:00 +02:00
|
|
|
if( Cmd_AutocompleteName( con.completionBuffer, Cmd_Argc() - 1, filename, sizeof( filename ) ) )
|
2018-06-14 20:19:04 +02:00
|
|
|
{
|
2019-07-09 14:08:00 +02:00
|
|
|
con.completionField->buffer[0] = 0;
|
|
|
|
|
|
|
|
for( i = 0; i < Cmd_Argc() - 1; i++ )
|
|
|
|
{
|
|
|
|
Q_strncat( con.completionField->buffer, Cmd_Argv( i ), sizeof( con.completionField->buffer ));
|
|
|
|
Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer ));
|
|
|
|
}
|
|
|
|
Q_strncat( con.completionField->buffer, filename, sizeof( con.completionField->buffer ));
|
2018-06-14 20:19:04 +02:00
|
|
|
con.completionField->cursor = Q_strlen( con.completionField->buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't adjusting cursor pos if we nothing found
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( con.matchCount == 1 )
|
|
|
|
{
|
2022-01-04 00:31:41 +01:00
|
|
|
Q_strncpy( con.completionField->buffer, con.cmds[0], sizeof( con.completionField->buffer ));
|
2018-06-14 20:19:04 +02:00
|
|
|
if( Cmd_Argc() == 1 ) Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer ) );
|
|
|
|
else Con_ConcatRemaining( temp.buffer, con.completionString );
|
|
|
|
con.completionField->cursor = Q_strlen( con.completionField->buffer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *first, *last;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
qsort( con.cmds, con.matchCount, sizeof( char* ), Con_SortCmds );
|
|
|
|
|
|
|
|
// find the number of matching characters between the first and
|
|
|
|
// the last element in the list and copy it
|
|
|
|
first = con.cmds[0];
|
|
|
|
last = con.cmds[con.matchCount - 1];
|
|
|
|
|
|
|
|
while( *first && *last && Q_tolower( *first ) == Q_tolower( *last ) )
|
|
|
|
{
|
|
|
|
first++;
|
|
|
|
last++;
|
|
|
|
|
|
|
|
con.shortestMatch[len] = con.cmds[0][len];
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
con.shortestMatch[len] = 0;
|
|
|
|
|
|
|
|
// multiple matches, complete to shortest
|
2022-01-04 00:31:41 +01:00
|
|
|
Q_strncpy( con.completionField->buffer, con.shortestMatch, sizeof( con.completionField->buffer ));
|
2018-06-14 20:19:04 +02:00
|
|
|
con.completionField->cursor = Q_strlen( con.completionField->buffer );
|
|
|
|
Con_ConcatRemaining( temp.buffer, con.completionString );
|
|
|
|
|
|
|
|
Con_Printf( "]%s\n", con.completionField->buffer );
|
|
|
|
|
|
|
|
// run through again, printing matches
|
2019-05-02 18:12:23 +02:00
|
|
|
Cmd_LookupCmds( NULL, NULL, (setpair_t)Con_PrintCmdMatches );
|
|
|
|
Cvar_LookupVars( 0, NULL, NULL, (setpair_t)Con_PrintCvarMatches );
|
2018-06-14 20:19:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=========
|
|
|
|
Cmd_AutoComplete
|
|
|
|
|
|
|
|
NOTE: input string must be equal or longer than MAX_STRING
|
|
|
|
=========
|
|
|
|
*/
|
|
|
|
void Cmd_AutoComplete( char *complete_string )
|
|
|
|
{
|
|
|
|
field_t input;
|
|
|
|
|
|
|
|
if( !complete_string || !*complete_string )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// setup input
|
|
|
|
Q_strncpy( input.buffer, complete_string, sizeof( input.buffer ) );
|
|
|
|
input.cursor = input.scroll = 0;
|
|
|
|
|
|
|
|
Con_CompleteCommand( &input );
|
|
|
|
|
|
|
|
// setup output
|
|
|
|
if( input.buffer[0] == '\\' || input.buffer[0] == '/' )
|
|
|
|
Q_strncpy( complete_string, input.buffer + 1, sizeof( input.buffer ) );
|
|
|
|
else Q_strncpy( complete_string, input.buffer, sizeof( input.buffer ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cmd_AutoCompleteClear
|
|
|
|
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void Cmd_AutoCompleteClear( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// free the old autocomplete list
|
|
|
|
for( i = 0; i < con.matchCount; i++ )
|
|
|
|
{
|
|
|
|
if( con.cmds[i] != NULL )
|
|
|
|
{
|
|
|
|
Mem_Free( con.cmds[i] );
|
|
|
|
con.cmds[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
con.matchCount = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
============
|
|
|
|
Cmd_WriteVariables
|
|
|
|
|
|
|
|
Appends lines containing "set variable value" for all variables
|
|
|
|
with the archive flag set to true.
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
static void Cmd_WriteOpenGLCvar( const char *name, const char *string, const char *desc, void *f )
|
|
|
|
{
|
2018-04-20 10:41:02 +02:00
|
|
|
if( !COM_CheckString( desc ))
|
|
|
|
return; // ignore cvars without description (fantom variables)
|
|
|
|
FS_Printf( f, "%s \"%s\"\n", name, string );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Cmd_WriteHelp(const char *name, const char *unused, const char *desc, void *f )
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
2022-12-04 03:24:35 +01:00
|
|
|
if( !COM_CheckString( desc ))
|
2018-04-13 18:23:45 +02:00
|
|
|
return; // ignore fantom cmds
|
2022-12-04 03:24:35 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
if( name[0] == '+' || name[0] == '-' )
|
2021-01-03 02:28:45 +01:00
|
|
|
return; // key bindings
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
length = 3 - (Q_strlen( name ) / 10); // Asm_Ed default tab stop is 10
|
|
|
|
|
|
|
|
if( length == 3 ) FS_Printf( f, "%s\t\t\t\"%s\"\n", name, desc );
|
|
|
|
if( length == 2 ) FS_Printf( f, "%s\t\t\"%s\"\n", name, desc );
|
|
|
|
if( length == 1 ) FS_Printf( f, "%s\t\"%s\"\n", name, desc );
|
|
|
|
if( length == 0 ) FS_Printf( f, "%s \"%s\"\n", name, desc );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cmd_WriteOpenGLVariables( file_t *f )
|
|
|
|
{
|
2018-04-23 20:49:37 +02:00
|
|
|
Cvar_LookupVars( FCVAR_GLCONFIG, NULL, f, (setpair_t)Cmd_WriteOpenGLCvar );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_DEDICATED
|
2019-07-27 23:27:35 +02:00
|
|
|
void Host_FinalizeConfig( file_t *f, const char *config )
|
|
|
|
{
|
|
|
|
string backup, newcfg;
|
|
|
|
|
|
|
|
Q_snprintf( backup, sizeof( backup ), "%s.bak", config );
|
|
|
|
Q_snprintf( newcfg, sizeof( newcfg ), "%s.new", config );
|
|
|
|
|
|
|
|
FS_Printf( f, "// end of %s\n", config );
|
|
|
|
FS_Close( f );
|
|
|
|
FS_Delete( backup );
|
|
|
|
FS_Rename( config, backup );
|
|
|
|
FS_Rename( newcfg, config );
|
|
|
|
}
|
2018-10-04 11:04:47 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Host_WriteConfig
|
|
|
|
|
|
|
|
Writes key bindings and archived cvars to config.cfg
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Host_WriteConfig( void )
|
|
|
|
{
|
|
|
|
kbutton_t *mlook = NULL;
|
|
|
|
kbutton_t *jlook = NULL;
|
|
|
|
file_t *f;
|
|
|
|
|
2018-10-04 11:04:47 +02:00
|
|
|
if( !clgame.hInstance || Sys_CheckParm( "-nowriteconfig" ) ) return;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2018-10-04 08:08:48 +02:00
|
|
|
|
2018-10-04 11:04:47 +02:00
|
|
|
f = FS_Open( "config.cfg.new", "w", false );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( f )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
Con_Reportf( "Host_WriteConfig()\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//=======================================================================\n");
|
2019-07-27 23:27:35 +02:00
|
|
|
FS_Printf( f, "//\t\t\tCopyright XashXT Group & Flying With Gauss %s (C)\n", Q_timestamp( TIME_YEAR_ONLY ));
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//\t\t\tconfig.cfg - archive of cvars\n" );
|
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
|
|
|
Key_WriteBindings( f );
|
|
|
|
Cvar_WriteVariables( f, FCVAR_ARCHIVE );
|
|
|
|
Info_WriteVars( f );
|
|
|
|
|
|
|
|
if( clgame.hInstance )
|
|
|
|
{
|
|
|
|
mlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_mlook" );
|
|
|
|
jlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_jlook" );
|
|
|
|
}
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
if( mlook && ( mlook->state & 1 ))
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "+mlook\n" );
|
|
|
|
|
|
|
|
if( jlook && ( jlook->state & 1 ))
|
|
|
|
FS_Printf( f, "+jlook\n" );
|
|
|
|
|
2018-12-25 04:12:01 +01:00
|
|
|
FS_Printf( f, "exec userconfig.cfg\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2019-07-27 23:27:35 +02:00
|
|
|
Host_FinalizeConfig( f, "config.cfg" );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2018-10-04 08:08:48 +02:00
|
|
|
else Con_DPrintf( S_ERROR "Couldn't write config.cfg.\n" );
|
2018-06-01 19:44:16 +02:00
|
|
|
|
|
|
|
NET_SaveMasters();
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Host_WriteServerConfig
|
|
|
|
|
|
|
|
save serverinfo variables into server.cfg (using for dedicated server too)
|
|
|
|
===============
|
|
|
|
*/
|
2020-01-19 02:15:54 +01:00
|
|
|
void GAME_EXPORT Host_WriteServerConfig( const char *name )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
file_t *f;
|
2019-07-27 23:27:35 +02:00
|
|
|
string newconfigfile;
|
2018-10-04 11:04:47 +02:00
|
|
|
|
|
|
|
Q_snprintf( newconfigfile, MAX_STRING, "%s.new", name );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// FIXME: move this out until menu parser is done
|
|
|
|
CSCR_LoadDefaultCVars( "settings.scr" );
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-10-04 11:04:47 +02:00
|
|
|
if(( f = FS_Open( newconfigfile, "w", false )) != NULL )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
2019-07-27 23:27:35 +02:00
|
|
|
FS_Printf( f, "//\t\t\tCopyright XashXT Group & Flying With Gauss %s (C)\n", Q_timestamp( TIME_YEAR_ONLY ));
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//\t\tgame.cfg - multiplayer server temporare config\n" );
|
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
2018-10-04 11:04:47 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
Cvar_WriteVariables( f, FCVAR_SERVER );
|
|
|
|
CSCR_WriteGameCVars( f, "settings.scr" );
|
2018-10-04 11:04:47 +02:00
|
|
|
|
2019-07-27 23:27:35 +02:00
|
|
|
Host_FinalizeConfig( f, name );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2018-10-04 08:08:48 +02:00
|
|
|
else Con_DPrintf( S_ERROR "Couldn't write %s.\n", name );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Host_WriteOpenGLConfig
|
|
|
|
|
|
|
|
save opengl variables into opengl.cfg
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Host_WriteOpenGLConfig( void )
|
|
|
|
{
|
2019-07-27 23:27:35 +02:00
|
|
|
string name;
|
2018-04-13 18:23:45 +02:00
|
|
|
file_t *f;
|
|
|
|
|
2018-10-04 11:04:47 +02:00
|
|
|
if( Sys_CheckParm( "-nowriteconfig" ) )
|
|
|
|
return;
|
2018-10-04 08:08:48 +02:00
|
|
|
|
2019-07-27 23:27:35 +02:00
|
|
|
Q_snprintf( name, sizeof( name ), "%s.cfg", ref.dllFuncs.R_GetConfigName() );
|
|
|
|
|
|
|
|
|
|
|
|
f = FS_Open( va( "%s.new", name ), "w", false );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( f )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
Con_Reportf( "Host_WriteGLConfig()\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
2019-07-27 23:27:35 +02:00
|
|
|
FS_Printf( f, "//\t\t\tCopyright XashXT Group & Flying With Gauss %s (C)\n", Q_timestamp( TIME_YEAR_ONLY ));
|
|
|
|
FS_Printf( f, "//\t\t %s - archive of renderer implementation cvars\n", name );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
|
|
|
FS_Printf( f, "\n" );
|
|
|
|
Cmd_WriteOpenGLVariables( f );
|
2019-07-27 23:27:35 +02:00
|
|
|
|
|
|
|
Host_FinalizeConfig( f, name );
|
2018-11-01 21:31:16 +01:00
|
|
|
}
|
2019-07-27 23:27:35 +02:00
|
|
|
else Con_DPrintf( S_ERROR "can't update %s.\n", name );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
Host_WriteVideoConfig
|
|
|
|
|
|
|
|
save render variables into video.cfg
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void Host_WriteVideoConfig( void )
|
|
|
|
{
|
|
|
|
file_t *f;
|
|
|
|
|
2018-10-04 11:04:47 +02:00
|
|
|
if( Sys_CheckParm( "-nowriteconfig" ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
f = FS_Open( "video.cfg.new", "w", false );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( f )
|
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
Con_Reportf( "Host_WriteVideoConfig()\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
2019-07-27 23:27:35 +02:00
|
|
|
FS_Printf( f, "//\t\t\tCopyright XashXT Group & Flying With Gauss %s (C)\n", Q_timestamp( TIME_YEAR_ONLY ));
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//\t\tvideo.cfg - archive of renderer variables\n");
|
|
|
|
FS_Printf( f, "//=======================================================================\n" );
|
|
|
|
Cvar_WriteVariables( f, FCVAR_RENDERINFO );
|
2019-07-27 23:27:35 +02:00
|
|
|
Host_FinalizeConfig( f, "video.cfg" );
|
2019-07-19 19:23:08 +02:00
|
|
|
}
|
2018-10-04 08:08:48 +02:00
|
|
|
else Con_DPrintf( S_ERROR "can't update video.cfg.\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2018-11-01 21:31:16 +01:00
|
|
|
#endif // XASH_DEDICATED
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
void Key_EnumCmds_f( void )
|
|
|
|
{
|
|
|
|
file_t *f;
|
|
|
|
|
|
|
|
FS_AllowDirectPaths( true );
|
|
|
|
if( FS_FileExists( "../help.txt", false ))
|
|
|
|
{
|
|
|
|
Con_Printf( "help.txt already exist\n" );
|
|
|
|
FS_AllowDirectPaths( false );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
f = FS_Open( "../help.txt", "w", false );
|
|
|
|
if( f )
|
|
|
|
{
|
|
|
|
FS_Printf( f, "//=======================================================================\n");
|
2019-07-27 23:27:35 +02:00
|
|
|
FS_Printf( f, "//\t\t\tCopyright XashXT Group & Flying With Gauss %s (C)\n", Q_timestamp( TIME_YEAR_ONLY ));
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "//\t\thelp.txt - xash commands and console variables\n");
|
|
|
|
FS_Printf( f, "//=======================================================================\n");
|
|
|
|
|
|
|
|
FS_Printf( f, "\n\n\t\t\tconsole variables\n\n");
|
2018-04-23 20:49:37 +02:00
|
|
|
Cvar_LookupVars( 0, NULL, f, (setpair_t)Cmd_WriteHelp );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "\n\n\t\t\tconsole commands\n\n");
|
2018-04-23 20:49:37 +02:00
|
|
|
Cmd_LookupCmds( NULL, f, (setpair_t)Cmd_WriteHelp );
|
2018-04-13 18:23:45 +02:00
|
|
|
FS_Printf( f, "\n\n");
|
|
|
|
FS_Close( f );
|
|
|
|
Con_Printf( "help.txt created\n" );
|
|
|
|
}
|
|
|
|
else Con_Printf( S_ERROR "couldn't write help.txt.\n");
|
|
|
|
FS_AllowDirectPaths( false );
|
2018-04-13 18:58:17 +02:00
|
|
|
}
|