2007-09-05 18:17:46 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Quake III Arena source code 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
2007-11-02 23:36:23 +00:00
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifndef DEDICATED
|
2007-11-02 23:36:23 +00:00
|
|
|
#ifdef USE_LOCAL_HEADERS
|
|
|
|
# include "SDL.h"
|
|
|
|
# include "SDL_cpuinfo.h"
|
|
|
|
#else
|
|
|
|
# include <SDL.h>
|
|
|
|
# include <SDL_cpuinfo.h>
|
|
|
|
#endif
|
2007-09-05 18:17:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "sys_local.h"
|
|
|
|
#include "sys_loadlib.h"
|
|
|
|
|
|
|
|
#include "../qcommon/q_shared.h"
|
|
|
|
#include "../qcommon/qcommon.h"
|
|
|
|
|
|
|
|
static char binaryPath[ MAX_OSPATH ] = { 0 };
|
|
|
|
static char installPath[ MAX_OSPATH ] = { 0 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_SetBinaryPath
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_SetBinaryPath(const char *path)
|
|
|
|
{
|
|
|
|
Q_strncpyz(binaryPath, path, sizeof(binaryPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_BinaryPath
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
char *Sys_BinaryPath(void)
|
|
|
|
{
|
|
|
|
return binaryPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_SetDefaultInstallPath
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_SetDefaultInstallPath(const char *path)
|
|
|
|
{
|
|
|
|
Q_strncpyz(installPath, path, sizeof(installPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_DefaultInstallPath
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
char *Sys_DefaultInstallPath(void)
|
|
|
|
{
|
|
|
|
if (*installPath)
|
|
|
|
return installPath;
|
|
|
|
else
|
|
|
|
return Sys_Cwd();
|
|
|
|
}
|
|
|
|
|
2007-12-14 21:53:57 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_DefaultAppPath
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
char *Sys_DefaultAppPath(void)
|
|
|
|
{
|
|
|
|
return Sys_BinaryPath();
|
|
|
|
}
|
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_In_Restart_f
|
|
|
|
|
|
|
|
Restart the input subsystem
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_In_Restart_f( void )
|
|
|
|
{
|
2008-08-09 13:20:00 +00:00
|
|
|
IN_Restart( );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_ConsoleInput
|
|
|
|
|
|
|
|
Handle new console input
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
char *Sys_ConsoleInput(void)
|
|
|
|
{
|
2007-11-30 18:32:52 +00:00
|
|
|
return CON_Input( );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 09:17:39 +00:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
Sys_GetClipboardData
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
char *Sys_GetClipboardData(void)
|
|
|
|
{
|
|
|
|
#ifdef DEDICATED
|
|
|
|
return NULL;
|
|
|
|
#else
|
|
|
|
char *data = NULL;
|
|
|
|
char *cliptext;
|
|
|
|
|
|
|
|
if ( ( cliptext = SDL_GetClipboardText() ) != NULL ) {
|
|
|
|
if ( cliptext[0] != '\0' ) {
|
|
|
|
size_t bufsize = strlen( cliptext ) + 1;
|
|
|
|
|
|
|
|
data = Z_Malloc( bufsize );
|
|
|
|
Q_strncpyz( data, cliptext, bufsize );
|
|
|
|
|
|
|
|
// find first listed char and set to '\0'
|
|
|
|
strtok( data, "\n\r\b" );
|
|
|
|
}
|
|
|
|
SDL_free( cliptext );
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
#ifdef DEDICATED
|
|
|
|
# define PID_FILENAME PRODUCT_NAME "_server.pid"
|
|
|
|
#else
|
|
|
|
# define PID_FILENAME PRODUCT_NAME ".pid"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_PIDFileName
|
|
|
|
=================
|
|
|
|
*/
|
2016-10-09 21:55:36 +00:00
|
|
|
static char *Sys_PIDFileName( const char *gamedir )
|
2010-02-15 16:20:33 +00:00
|
|
|
{
|
2014-10-27 20:49:23 +00:00
|
|
|
const char *homePath = Cvar_VariableString( "fs_homepath" );
|
2012-07-07 17:32:19 +00:00
|
|
|
|
2012-07-07 18:24:20 +00:00
|
|
|
if( *homePath != '\0' )
|
2016-10-09 21:55:36 +00:00
|
|
|
return va( "%s/%s/%s", homePath, gamedir, PID_FILENAME );
|
2012-07-07 17:32:19 +00:00
|
|
|
|
|
|
|
return NULL;
|
2010-02-15 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 21:55:36 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_RemovePIDFile
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_RemovePIDFile( const char *gamedir )
|
|
|
|
{
|
|
|
|
char *pidFile = Sys_PIDFileName( gamedir );
|
|
|
|
|
|
|
|
if( pidFile != NULL )
|
|
|
|
remove( pidFile );
|
|
|
|
}
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_WritePIDFile
|
|
|
|
|
|
|
|
Return qtrue if there is an existing stale PID file
|
|
|
|
=================
|
|
|
|
*/
|
2016-10-09 21:55:36 +00:00
|
|
|
static qboolean Sys_WritePIDFile( const char *gamedir )
|
2010-02-15 16:20:33 +00:00
|
|
|
{
|
2016-10-09 21:55:36 +00:00
|
|
|
char *pidFile = Sys_PIDFileName( gamedir );
|
2010-02-15 16:20:33 +00:00
|
|
|
FILE *f;
|
|
|
|
qboolean stale = qfalse;
|
|
|
|
|
2012-07-07 17:32:19 +00:00
|
|
|
if( pidFile == NULL )
|
|
|
|
return qfalse;
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
// First, check if the pid file is already there
|
|
|
|
if( ( f = fopen( pidFile, "r" ) ) != NULL )
|
|
|
|
{
|
|
|
|
char pidBuffer[ 64 ] = { 0 };
|
|
|
|
int pid;
|
|
|
|
|
2011-01-21 20:47:32 +00:00
|
|
|
pid = fread( pidBuffer, sizeof( char ), sizeof( pidBuffer ) - 1, f );
|
2010-02-15 16:20:33 +00:00
|
|
|
fclose( f );
|
|
|
|
|
2011-01-21 20:47:32 +00:00
|
|
|
if(pid > 0)
|
|
|
|
{
|
|
|
|
pid = atoi( pidBuffer );
|
|
|
|
if( !Sys_PIDIsRunning( pid ) )
|
|
|
|
stale = qtrue;
|
|
|
|
}
|
|
|
|
else
|
2010-02-15 16:20:33 +00:00
|
|
|
stale = qtrue;
|
|
|
|
}
|
|
|
|
|
2016-10-09 21:55:36 +00:00
|
|
|
if( FS_CreatePath( pidFile ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
if( ( f = fopen( pidFile, "w" ) ) != NULL )
|
|
|
|
{
|
|
|
|
fprintf( f, "%d", Sys_PID( ) );
|
|
|
|
fclose( f );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Com_Printf( S_COLOR_YELLOW "Couldn't write %s.\n", pidFile );
|
|
|
|
|
|
|
|
return stale;
|
|
|
|
}
|
|
|
|
|
2016-10-09 21:55:36 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_InitPIDFile
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_InitPIDFile( const char *gamedir ) {
|
|
|
|
if( Sys_WritePIDFile( gamedir ) ) {
|
|
|
|
#ifndef DEDICATED
|
|
|
|
char message[1024];
|
|
|
|
char modName[MAX_OSPATH];
|
|
|
|
|
|
|
|
FS_GetModDescription( gamedir, modName, sizeof ( modName ) );
|
|
|
|
Q_CleanStr( modName );
|
|
|
|
|
|
|
|
Com_sprintf( message, sizeof (message), "The last time %s ran, "
|
|
|
|
"it didn't exit properly. This may be due to inappropriate video "
|
|
|
|
"settings. Would you like to start with \"safe\" video settings?", modName );
|
|
|
|
|
|
|
|
if( Sys_Dialog( DT_YES_NO, message, "Abnormal Exit" ) == DR_YES ) {
|
|
|
|
Cvar_Set( "com_abnormalExit", "1" );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Exit
|
|
|
|
|
|
|
|
Single exit point (regular exit or in case of error)
|
|
|
|
=================
|
|
|
|
*/
|
2011-07-18 14:56:57 +00:00
|
|
|
static __attribute__ ((noreturn)) void Sys_Exit( int exitCode )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-11-30 18:32:52 +00:00
|
|
|
CON_Shutdown( );
|
2007-09-05 18:17:46 +00:00
|
|
|
|
|
|
|
#ifndef DEDICATED
|
|
|
|
SDL_Quit( );
|
|
|
|
#endif
|
|
|
|
|
2016-10-09 21:55:36 +00:00
|
|
|
if( exitCode < 2 && com_fullyInitialized )
|
2010-02-15 16:20:33 +00:00
|
|
|
{
|
|
|
|
// Normal exit
|
2016-10-09 21:55:36 +00:00
|
|
|
Sys_RemovePIDFile( FS_GetCurrentGameDir() );
|
2010-02-15 16:20:33 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 02:18:34 +00:00
|
|
|
NET_Shutdown( );
|
|
|
|
|
2011-04-09 12:33:56 +00:00
|
|
|
Sys_PlatformExit( );
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
exit( exitCode );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Quit
|
|
|
|
=================
|
|
|
|
*/
|
2007-11-30 18:32:52 +00:00
|
|
|
void Sys_Quit( void )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-11-30 18:32:52 +00:00
|
|
|
Sys_Exit( 0 );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_GetProcessorFeatures
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
cpuFeatures_t Sys_GetProcessorFeatures( void )
|
|
|
|
{
|
|
|
|
cpuFeatures_t features = 0;
|
|
|
|
|
|
|
|
#ifndef DEDICATED
|
2016-03-27 16:46:38 +00:00
|
|
|
if( SDL_HasRDTSC( ) ) features |= CF_RDTSC;
|
2016-03-27 17:02:12 +00:00
|
|
|
if( SDL_Has3DNow( ) ) features |= CF_3DNOW;
|
2016-03-27 16:46:38 +00:00
|
|
|
if( SDL_HasMMX( ) ) features |= CF_MMX;
|
|
|
|
if( SDL_HasSSE( ) ) features |= CF_SSE;
|
|
|
|
if( SDL_HasSSE2( ) ) features |= CF_SSE2;
|
|
|
|
if( SDL_HasAltiVec( ) ) features |= CF_ALTIVEC;
|
2007-09-05 18:17:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Init
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_Init(void)
|
|
|
|
{
|
|
|
|
Cmd_AddCommand( "in_restart", Sys_In_Restart_f );
|
|
|
|
Cvar_Set( "arch", OS_STRING " " ARCH_STRING );
|
|
|
|
Cvar_Set( "username", Sys_GetCurrentUser( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
2007-10-09 20:49:19 +00:00
|
|
|
Sys_AnsiColorPrint
|
2007-09-05 18:17:46 +00:00
|
|
|
|
|
|
|
Transform Q3 colour codes to ANSI escape sequences
|
|
|
|
=================
|
|
|
|
*/
|
2007-11-30 18:32:52 +00:00
|
|
|
void Sys_AnsiColorPrint( const char *msg )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-10-09 20:49:19 +00:00
|
|
|
static char buffer[ MAXPRINTMSG ];
|
|
|
|
int length = 0;
|
|
|
|
static int q3ToAnsi[ 8 ] =
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-10-09 20:49:19 +00:00
|
|
|
30, // COLOR_BLACK
|
|
|
|
31, // COLOR_RED
|
|
|
|
32, // COLOR_GREEN
|
|
|
|
33, // COLOR_YELLOW
|
|
|
|
34, // COLOR_BLUE
|
|
|
|
36, // COLOR_CYAN
|
|
|
|
35, // COLOR_MAGENTA
|
|
|
|
0 // COLOR_WHITE
|
|
|
|
};
|
|
|
|
|
|
|
|
while( *msg )
|
|
|
|
{
|
|
|
|
if( Q_IsColorString( msg ) || *msg == '\n' )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-10-09 20:49:19 +00:00
|
|
|
// First empty the buffer
|
|
|
|
if( length > 0 )
|
|
|
|
{
|
|
|
|
buffer[ length ] = '\0';
|
|
|
|
fputs( buffer, stderr );
|
|
|
|
length = 0;
|
|
|
|
}
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2007-10-09 20:49:19 +00:00
|
|
|
if( *msg == '\n' )
|
|
|
|
{
|
|
|
|
// Issue a reset and then the newline
|
|
|
|
fputs( "\033[0m\n", stderr );
|
|
|
|
msg++;
|
|
|
|
}
|
|
|
|
else
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2007-10-09 20:49:19 +00:00
|
|
|
// Print the color code
|
|
|
|
Com_sprintf( buffer, sizeof( buffer ), "\033[%dm",
|
|
|
|
q3ToAnsi[ ColorIndex( *( msg + 1 ) ) ] );
|
|
|
|
fputs( buffer, stderr );
|
|
|
|
msg += 2;
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-09 20:49:19 +00:00
|
|
|
if( length >= MAXPRINTMSG - 1 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
buffer[ length ] = *msg;
|
|
|
|
length++;
|
|
|
|
msg++;
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-09 20:49:19 +00:00
|
|
|
|
|
|
|
// Empty anything still left in the buffer
|
|
|
|
if( length > 0 )
|
|
|
|
{
|
|
|
|
buffer[ length ] = '\0';
|
|
|
|
fputs( buffer, stderr );
|
|
|
|
}
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Print
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_Print( const char *msg )
|
|
|
|
{
|
2007-11-30 18:32:52 +00:00
|
|
|
CON_LogWrite( msg );
|
|
|
|
CON_Print( msg );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Error
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_Error( const char *error, ... )
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr,error);
|
|
|
|
Q_vsnprintf (string, sizeof(string), error, argptr);
|
|
|
|
va_end (argptr);
|
2007-11-30 18:32:52 +00:00
|
|
|
|
|
|
|
Sys_ErrorDialog( string );
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
Sys_Exit( 3 );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 14:56:57 +00:00
|
|
|
#if 0
|
2007-09-05 18:17:46 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_Warn
|
|
|
|
=================
|
|
|
|
*/
|
2011-07-18 14:56:57 +00:00
|
|
|
static __attribute__ ((format (printf, 1, 2))) void Sys_Warn( char *warning, ... )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr,warning);
|
|
|
|
Q_vsnprintf (string, sizeof(string), warning, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
2007-11-30 18:32:52 +00:00
|
|
|
CON_Print( va( "Warning: %s", string ) );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
2011-07-18 14:56:57 +00:00
|
|
|
#endif
|
2007-09-05 18:17:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Sys_FileTime
|
|
|
|
|
|
|
|
returns -1 if not present
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
int Sys_FileTime( char *path )
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat (path,&buf) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return buf.st_mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_UnloadDll
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_UnloadDll( void *dllHandle )
|
|
|
|
{
|
|
|
|
if( !dllHandle )
|
|
|
|
{
|
|
|
|
Com_Printf("Sys_UnloadDll(NULL)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_UnloadLibrary(dllHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_LoadDll
|
|
|
|
|
2011-07-29 20:18:37 +00:00
|
|
|
First try to load library name from system library path,
|
|
|
|
from executable path, then fs_basepath.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
|
2011-08-01 09:33:48 +00:00
|
|
|
void *Sys_LoadDll(const char *name, qboolean useSystemLib)
|
2011-07-29 20:18:37 +00:00
|
|
|
{
|
|
|
|
void *dllhandle;
|
|
|
|
|
2017-03-13 21:14:00 +00:00
|
|
|
// Don't load any DLLs that end with the pk3 extension
|
|
|
|
if (COM_CompareExtension(name, ".pk3"))
|
|
|
|
{
|
|
|
|
Com_Printf("Rejecting DLL named \"%s\"", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-01 09:33:48 +00:00
|
|
|
if(useSystemLib)
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf("Trying to load \"%s\"...\n", name);
|
2011-08-01 09:33:48 +00:00
|
|
|
|
|
|
|
if(!useSystemLib || !(dllhandle = Sys_LoadLibrary(name)))
|
2011-07-29 20:18:37 +00:00
|
|
|
{
|
|
|
|
const char *topDir;
|
|
|
|
char libPath[MAX_OSPATH];
|
|
|
|
|
|
|
|
topDir = Sys_BinaryPath();
|
|
|
|
|
|
|
|
if(!*topDir)
|
|
|
|
topDir = ".";
|
|
|
|
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, topDir);
|
2011-07-29 20:18:37 +00:00
|
|
|
Com_sprintf(libPath, sizeof(libPath), "%s%c%s", topDir, PATH_SEP, name);
|
|
|
|
|
|
|
|
if(!(dllhandle = Sys_LoadLibrary(libPath)))
|
|
|
|
{
|
|
|
|
const char *basePath = Cvar_VariableString("fs_basepath");
|
|
|
|
|
|
|
|
if(!basePath || !*basePath)
|
|
|
|
basePath = ".";
|
|
|
|
|
|
|
|
if(FS_FilenameCompare(topDir, basePath))
|
|
|
|
{
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf("Trying to load \"%s\" from \"%s\"...\n", name, basePath);
|
2011-07-29 20:18:37 +00:00
|
|
|
Com_sprintf(libPath, sizeof(libPath), "%s%c%s", basePath, PATH_SEP, name);
|
|
|
|
dllhandle = Sys_LoadLibrary(libPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!dllhandle)
|
|
|
|
Com_Printf("Loading \"%s\" failed\n", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dllhandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
2011-08-03 14:32:49 +00:00
|
|
|
Sys_LoadGameDll
|
2011-07-29 20:18:37 +00:00
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
Used to load a development dll instead of a virtual machine
|
|
|
|
=================
|
|
|
|
*/
|
2011-08-03 14:32:49 +00:00
|
|
|
void *Sys_LoadGameDll(const char *name,
|
2011-06-13 09:56:39 +00:00
|
|
|
intptr_t (QDECL **entryPoint)(int, ...),
|
2011-06-15 22:09:26 +00:00
|
|
|
intptr_t (*systemcalls)(intptr_t, ...))
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
2011-06-15 22:09:26 +00:00
|
|
|
void *libHandle;
|
|
|
|
void (*dllEntry)(intptr_t (*syscallptr)(intptr_t, ...));
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2011-06-15 22:09:26 +00:00
|
|
|
assert(name);
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2011-06-15 22:09:26 +00:00
|
|
|
Com_Printf( "Loading DLL file: %s\n", name);
|
|
|
|
libHandle = Sys_LoadLibrary(name);
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2011-06-15 22:09:26 +00:00
|
|
|
if(!libHandle)
|
|
|
|
{
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf("Sys_LoadGameDll(%s) failed:\n\"%s\"\n", name, Sys_LibraryError());
|
2007-09-05 18:17:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dllEntry = Sys_LoadFunction( libHandle, "dllEntry" );
|
|
|
|
*entryPoint = Sys_LoadFunction( libHandle, "vmMain" );
|
|
|
|
|
|
|
|
if ( !*entryPoint || !dllEntry )
|
|
|
|
{
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf ( "Sys_LoadGameDll(%s) failed to find vmMain function:\n\"%s\" !\n", name, Sys_LibraryError( ) );
|
2007-09-05 18:17:46 +00:00
|
|
|
Sys_UnloadLibrary(libHandle);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-03 14:32:49 +00:00
|
|
|
Com_Printf ( "Sys_LoadGameDll(%s) found vmMain function at %p\n", name, *entryPoint );
|
2007-09-05 18:17:46 +00:00
|
|
|
dllEntry( systemcalls );
|
|
|
|
|
|
|
|
return libHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_ParseArgs
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Sys_ParseArgs( int argc, char **argv )
|
|
|
|
{
|
|
|
|
if( argc == 2 )
|
|
|
|
{
|
|
|
|
if( !strcmp( argv[1], "--version" ) ||
|
|
|
|
!strcmp( argv[1], "-v" ) )
|
|
|
|
{
|
2015-04-02 10:10:26 +00:00
|
|
|
const char* date = PRODUCT_DATE;
|
2007-09-05 18:17:46 +00:00
|
|
|
#ifdef DEDICATED
|
|
|
|
fprintf( stdout, Q3_VERSION " dedicated server (%s)\n", date );
|
|
|
|
#else
|
|
|
|
fprintf( stdout, Q3_VERSION " client (%s)\n", date );
|
|
|
|
#endif
|
2010-02-15 16:20:33 +00:00
|
|
|
Sys_Exit( 0 );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DEFAULT_BASEDIR
|
2016-06-12 21:06:54 +00:00
|
|
|
# ifdef __APPLE__
|
2007-09-05 18:17:46 +00:00
|
|
|
# define DEFAULT_BASEDIR Sys_StripAppBundle(Sys_BinaryPath())
|
|
|
|
# else
|
|
|
|
# define DEFAULT_BASEDIR Sys_BinaryPath()
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Sys_SigHandler
|
|
|
|
=================
|
|
|
|
*/
|
2007-09-15 02:22:58 +00:00
|
|
|
void Sys_SigHandler( int signal )
|
2007-09-05 18:17:46 +00:00
|
|
|
{
|
|
|
|
static qboolean signalcaught = qfalse;
|
|
|
|
|
|
|
|
if( signalcaught )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "DOUBLE SIGNAL FAULT: Received signal %d, exiting...\n",
|
|
|
|
signal );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
signalcaught = qtrue;
|
2011-10-14 13:52:28 +00:00
|
|
|
VM_Forced_Unload_Start();
|
2007-09-05 18:17:46 +00:00
|
|
|
#ifndef DEDICATED
|
2011-08-01 10:16:40 +00:00
|
|
|
CL_Shutdown(va("Received signal %d", signal), qtrue, qtrue);
|
2007-09-05 18:17:46 +00:00
|
|
|
#endif
|
2011-06-21 11:18:35 +00:00
|
|
|
SV_Shutdown(va("Received signal %d", signal) );
|
2011-10-14 13:52:28 +00:00
|
|
|
VM_Forced_Unload_Done();
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
2010-02-15 16:20:33 +00:00
|
|
|
if( signal == SIGTERM || signal == SIGINT )
|
|
|
|
Sys_Exit( 1 );
|
|
|
|
else
|
|
|
|
Sys_Exit( 2 );
|
2007-09-05 18:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
main
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char commandLine[ MAX_STRING_CHARS ] = { 0 };
|
|
|
|
|
2017-05-31 05:21:21 +00:00
|
|
|
extern void Sys_LaunchAutoupdater(int argc, char **argv);
|
|
|
|
Sys_LaunchAutoupdater(argc, argv);
|
2017-05-25 18:13:18 +00:00
|
|
|
|
2007-09-06 18:21:10 +00:00
|
|
|
#ifndef DEDICATED
|
2007-11-25 23:41:01 +00:00
|
|
|
// SDL version check
|
|
|
|
|
|
|
|
// Compile time
|
|
|
|
# if !SDL_VERSION_ATLEAST(MINSDL_MAJOR,MINSDL_MINOR,MINSDL_PATCH)
|
|
|
|
# error A more recent version of SDL is required
|
|
|
|
# endif
|
|
|
|
|
|
|
|
// Run time
|
2013-01-17 13:31:30 +00:00
|
|
|
SDL_version ver;
|
2013-09-15 22:54:52 +00:00
|
|
|
SDL_GetVersion( &ver );
|
2007-09-06 18:21:10 +00:00
|
|
|
|
|
|
|
#define MINSDL_VERSION \
|
2007-11-18 01:06:46 +00:00
|
|
|
XSTRING(MINSDL_MAJOR) "." \
|
|
|
|
XSTRING(MINSDL_MINOR) "." \
|
|
|
|
XSTRING(MINSDL_PATCH)
|
|
|
|
|
2013-01-17 13:31:30 +00:00
|
|
|
if( SDL_VERSIONNUM( ver.major, ver.minor, ver.patch ) <
|
2007-11-18 01:06:46 +00:00
|
|
|
SDL_VERSIONNUM( MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH ) )
|
|
|
|
{
|
2010-02-15 16:20:33 +00:00
|
|
|
Sys_Dialog( DT_ERROR, va( "SDL version " MINSDL_VERSION " or greater is required, "
|
|
|
|
"but only version %d.%d.%d was found. You may be able to obtain a more recent copy "
|
2013-01-17 13:31:30 +00:00
|
|
|
"from http://www.libsdl.org/.", ver.major, ver.minor, ver.patch ), "SDL Library Too Old" );
|
2010-02-15 16:20:33 +00:00
|
|
|
|
2007-11-18 01:06:46 +00:00
|
|
|
Sys_Exit( 1 );
|
|
|
|
}
|
2007-09-06 18:21:10 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-03 19:42:53 +00:00
|
|
|
Sys_PlatformInit( );
|
|
|
|
|
2009-03-02 22:26:36 +00:00
|
|
|
// Set the initial time base
|
|
|
|
Sys_Milliseconds( );
|
2009-03-02 18:08:21 +00:00
|
|
|
|
2016-06-12 21:06:54 +00:00
|
|
|
#ifdef __APPLE__
|
2013-10-19 05:47:21 +00:00
|
|
|
// This is passed if we are launched by double-clicking
|
|
|
|
if ( argc >= 2 && Q_strncmp ( argv[1], "-psn", 4 ) == 0 )
|
|
|
|
argc = 1;
|
|
|
|
#endif
|
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
Sys_ParseArgs( argc, argv );
|
|
|
|
Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) );
|
|
|
|
Sys_SetDefaultInstallPath( DEFAULT_BASEDIR );
|
|
|
|
|
|
|
|
// Concatenate the command line for passing to Com_Init
|
|
|
|
for( i = 1; i < argc; i++ )
|
|
|
|
{
|
2009-09-15 06:12:42 +00:00
|
|
|
const qboolean containsSpaces = strchr(argv[i], ' ') != NULL;
|
|
|
|
if (containsSpaces)
|
|
|
|
Q_strcat( commandLine, sizeof( commandLine ), "\"" );
|
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] );
|
2009-09-15 06:12:42 +00:00
|
|
|
|
|
|
|
if (containsSpaces)
|
|
|
|
Q_strcat( commandLine, sizeof( commandLine ), "\"" );
|
|
|
|
|
2007-09-05 18:17:46 +00:00
|
|
|
Q_strcat( commandLine, sizeof( commandLine ), " " );
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_Init( commandLine );
|
2007-11-30 18:32:52 +00:00
|
|
|
NET_Init( );
|
2007-09-05 18:17:46 +00:00
|
|
|
|
2007-11-30 18:32:52 +00:00
|
|
|
CON_Init( );
|
2007-09-05 18:17:46 +00:00
|
|
|
|
|
|
|
signal( SIGILL, Sys_SigHandler );
|
|
|
|
signal( SIGFPE, Sys_SigHandler );
|
|
|
|
signal( SIGSEGV, Sys_SigHandler );
|
|
|
|
signal( SIGTERM, Sys_SigHandler );
|
2009-12-24 01:39:30 +00:00
|
|
|
signal( SIGINT, Sys_SigHandler );
|
2007-09-05 18:17:46 +00:00
|
|
|
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
IN_Frame( );
|
|
|
|
Com_Frame( );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|