Example #1
0
bool Sys_SaveFileCodes(void)
{
	bool ret;
	int res;

	// get the number of files
	int count;
	count = _buildFileList(Sys_Cwd(), false, false);

	// open a file for writing
	FILE* out;
	out = fopen("d:\\xbx_filelist","wb");
	if(!out)
	{
		return false;
	}

	// allocate a buffer for writing
	byte*	baseAddr;
	int		bufferSize;
	
	bufferSize	= sizeof(int) + ( count * ( 2 * sizeof(int) + MAX_OSPATH ) );
	baseAddr	= (byte*)Z_Malloc(bufferSize,TAG_TEMP_WORKSPACE,qtrue,32);
	buffer		= baseAddr;

	// write the number of files to the buffer
	*(int*)buffer	=  count;
	buffer			+= sizeof(count);

	// fill up the rest of the buffer
	ret = _buildFileList(Sys_Cwd(), false, true);

	if(!ret)
	{
		// there was a problem
		fclose(out);
		Z_Free(baseAddr);
		return false;
	}

	// attempt to write out the data
	if(!(fwrite(baseAddr,bufferSize,1,out)))
	{
		// there was a problem
		fclose(out);
		Z_Free(baseAddr);
		return false;
	}

	// everything went ok
	fclose(out);
	Z_Free(baseAddr);
	return true;
}
char *Sys_DefaultInstallPath( char * buffer, int size )
{
#ifdef USE_BOOTWITHNOFILES
	if( SHGetSpecialFolderPath( NULL, buffer, CSIDL_COMMON_APPDATA, TRUE ) != NOERROR )
	{
		Q_strcat( buffer, size, "\\HermitWorks\\SpaceTrader" );
		return buffer;
	}

	return Sys_Cwd( buffer, size );
#else
	return Sys_Cwd( buffer, size );
#endif
}
Example #3
0
/*
=================
Sys_DefaultLibPath
=================
*/
char *Sys_DefaultLibPath(void) {
	if (*libPath) {
		return libPath;
	} else {
		return Sys_Cwd();
	}
}
Example #4
0
/*
=================
Sys_DefaultInstallPath
=================
*/
char *Sys_DefaultInstallPath(void) {
	static char installdir[MAX_OSPATH];

	Com_sprintf(installdir, sizeof(installdir), "%s", Sys_Cwd());

	Q_strreplace(installdir, sizeof(installdir), "bin32", "");
	Q_strreplace(installdir, sizeof(installdir), "bin64", "");

	Q_strreplace(installdir, sizeof(installdir), "src/engine", "");
	Q_strreplace(installdir, sizeof(installdir), "src\\engine", "");
	
	Q_strreplace(installdir, sizeof(installdir), "bin/win32", "");
	Q_strreplace(installdir, sizeof(installdir), "bin\\win32", "");
	
	Q_strreplace(installdir, sizeof(installdir), "bin/win64", "");
	Q_strreplace(installdir, sizeof(installdir), "bin\\win64", "");
	
	Q_strreplace(installdir, sizeof(installdir), "bin/linux-x86", "");
	Q_strreplace(installdir, sizeof(installdir), "bin/linux-x86_64", "");

	Q_strreplace(installdir, sizeof(installdir), "bin/freebsd-i386", "");
	Q_strreplace(installdir, sizeof(installdir), "bin/freebsd-amd64", "");
	
	// MacOS X x86 and x64
	Q_strreplace(installdir, sizeof(installdir), "bin/macosx", "");	

	return installdir;
}
Example #5
0
char *Sys_DefaultCDPath(void)
{
	if (*programpath)
		return programpath;
	else
		return Sys_Cwd();
}
Example #6
0
char *Sys_DefaultInstallPath( void ) {
	if ( *installPath ) {
		return installPath;
	} else {
		return Sys_Cwd();
	}
}
Example #7
0
char *Sys_DefaultInstallPath(void)
{
	if (*installPath)
		return installPath;
	else
		return Sys_Cwd();
}
Example #8
0
/*
==============
Sys_DefaultBasePath
==============
*/
char *Sys_DefaultBasePath( void ) {
	if ( installPath[0] ) {
		return installPath;
	} else {
		return Sys_Cwd();
	}
}
Example #9
0
/*
=================
Sys_OpenURL
=================
*/
void Sys_OpenURL( const char *url, qboolean doexit ) {
	char *basepath, *homepath, *pwdpath;
	char fname[20];
	char fn[MAX_OSPATH];
	char cmdline[MAX_CMD];

	static qboolean doexit_spamguard = qfalse;

	if ( doexit_spamguard ) {
		Com_DPrintf( "Sys_OpenURL: already in a doexit sequence, ignoring %s\n", url );
		return;
	}

	Com_Printf( "Open URL: %s\n", url );
	// opening an URL on *nix can mean a lot of things ..
	// just spawn a script instead of deciding for the user :-)

	// do the setup before we fork
	// search for an openurl.sh script
	// search procedure taken from Sys_LoadDll
	Q_strncpyz( fname, "openurl.sh", 20 );

	pwdpath = Sys_Cwd();
	Com_sprintf( fn, MAX_OSPATH, "%s/%s", pwdpath, fname );
	if ( access( fn, X_OK ) == -1 ) {
		Com_DPrintf( "%s not found\n", fn );
		// try in home path
		homepath = Cvar_VariableString( "fs_homepath" );
		Com_sprintf( fn, MAX_OSPATH, "%s/%s", homepath, fname );
		if ( access( fn, X_OK ) == -1 ) {
			Com_DPrintf( "%s not found\n", fn );
			// basepath, last resort
			basepath = Cvar_VariableString( "fs_basepath" );
			Com_sprintf( fn, MAX_OSPATH, "%s/%s", basepath, fname );
			if ( access( fn, X_OK ) == -1 ) {
				Com_DPrintf( "%s not found\n", fn );
				Com_Printf( "Can't find script '%s' to open requested URL (use +set developer 1 for more verbosity)\n", fname );
				// we won't quit
				return;
			}
		}
	}

	// show_bug.cgi?id=612
	if ( doexit ) {
		doexit_spamguard = qtrue;
	}

	Com_DPrintf( "URL script: %s\n", fn );

	// build the command line
	Com_sprintf( cmdline, MAX_CMD, "%s '%s' &", fn, url );

	Sys_StartProcess( cmdline, doexit );

}
Example #10
0
/*
=================
Sys_LoadDll

Used to load a development dll instead of a virtual machine
#1 look down current path
#2 look in fs_homepath
#3 look in fs_basepath
=================
*/
void *Sys_LoadDll( const char *name, char *fqpath ,
	intptr_t (**entryPoint)(int, ...),
	intptr_t (*systemcalls)(intptr_t, ...) )
{
	void  *libHandle;
	void  (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) );
	char  fname[MAX_OSPATH];
	char  *basepath;
	char  *homepath;
	char  *pwdpath;
	char  *gamedir;

	assert( name );

	Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name);

	// TODO: use fs_searchpaths from files.c
	pwdpath = Sys_Cwd();
	basepath = Cvar_VariableString( "fs_basepath" );
	homepath = Cvar_VariableString( "fs_homepath" );
	gamedir = Cvar_VariableString( "fs_game" );

	libHandle = Sys_TryLibraryLoad(pwdpath, gamedir, fname, fqpath);

	if(!libHandle && homepath)
		libHandle = Sys_TryLibraryLoad(homepath, gamedir, fname, fqpath);

	if(!libHandle && basepath)
		libHandle = Sys_TryLibraryLoad(basepath, gamedir, fname, fqpath);

	if(!libHandle) {
		Com_Printf ( "Sys_LoadDll(%s) failed to load library\n", name );
		return NULL;
	}

	dllEntry = Sys_LoadFunction( libHandle, "dllEntry" );
	*entryPoint = Sys_LoadFunction( libHandle, "vmMain" );

	if ( !*entryPoint || !dllEntry )
	{
		Com_Printf ( "Sys_LoadDll(%s) failed to find vmMain function:\n\"%s\" !\n", name, Sys_LibraryError( ) );
		Sys_UnloadLibrary(libHandle);

		return NULL;
	}

	Com_Printf ( "Sys_LoadDll(%s) found vmMain function at %p\n", name, *entryPoint );
	dllEntry( systemcalls );

	return libHandle;
}
Example #11
0
void Sys_OpenURL(const char *url, qboolean doexit)
{
	char fname[20], fn[MAX_OSPATH];
	char cmdline[MAX_CMD], *basename[3];
	int i, r;

	static qboolean doexit_spamguard = qfalse;

// XXX: UrtDevs: disabled until it matures (possible security risks)
	return;
//////////////////////////
	if(doexit_spamguard) {
		Com_DPrintf("Sys_OpenURL: already in a doexit sequence, ignoring %s\n", url);
		return;
	}

	Com_Printf("Open URL: %s\n", url);

	basename[0] = Sys_Cwd();
	basename[1] = Cvar_VariableString("fs_homepath");
	basename[2] = Cvar_VariableString("fs_basepath");

	for(i = 0; i < 3; i++) {
		Com_sprintf(fn, MAX_OSPATH, "%s/%s", basename[i], fname);
		r = access(fn, X_OK);

		if(r != -1) break;
	}

	if(r == -1) {
		Com_DPrintf("%s not found\n", fn);
		Com_Printf("Can't find script '%s' to open requested URL (use +set developer 1 for more verbosity)\n", fname);
		return;
	}

	if(doexit) doexit_spamguard = qtrue;

	Com_DPrintf("URL script: %s\n", fn);
	
	Com_sprintf(cmdline, MAX_CMD, "%s '%s' &", fn, url);
	Sys_StartProcess(cmdline, doexit);
}
Example #12
0
static qboolean JVM_JNI_Init()
{
	if(javaLib)
		return qtrue;

	Com_Printf("Loading \"%s\"...\n", jvm_javaLib->string);
	if((javaLib = Sys_LoadLibrary(jvm_javaLib->string)) == 0)
	{
#ifdef _WIN32
		return qfalse;
#else
		char            fn[1024];

		Com_Printf("JVM_JNI_Init() failed:\n\"%s\"\n", Sys_LibraryError());

		Q_strncpyz(fn, Sys_Cwd(), sizeof(fn));
		strncat(fn, "/", sizeof(fn) - strlen(fn) - 1);
		strncat(fn, jvm_javaLib->string, sizeof(fn) - strlen(fn) - 1);

		if((javaLib = Sys_LoadLibrary(fn)) == 0)
		{
			Com_Printf("JVM_JNI_Init() failed:\n\"%s\"\n", Sys_LibraryError());
			return qfalse;
		}
#endif							/* _WIN32 */
	}

	javaEnabled = qtrue;

	QJNI_CreateJavaVM = GPA("JNI_CreateJavaVM");
	QJNI_GetCreatedJavaVMs = GPA("JNI_GetCreatedJavaVMs");

	if(!javaEnabled)
	{
		//JVM_JNI_Shutdown();
		return qfalse;
	}

	return qtrue;
}
Example #13
0
void *Sys_LoadDll( const char *name, char *fqpath,
				   int( **entryPoint ) ( int, ... ),
				   int ( *systemcalls )( int, ... ) ) {
	void *libHandle;
	void ( *dllEntry )( int ( *syscallptr )( int, ... ) );
	char fname[MAX_OSPATH];
	char  *pwdpath;
	char  *homepath;
	char  *basepath;
	char  *gamedir;
	char  *fn;
	const char*  err = NULL; // bk001206 // rb0101023 - now const
#if !defined( DEDICATED )
	char *cvar_name = NULL;
#endif

	*fqpath = 0 ;       // added 2/15/02 by T.Ray

	// bk001206 - let's have some paranoia
	assert( name );

	Q_strncpyz( fname, Sys_GetDLLName( name ), sizeof( fname ) );

// bk001129 - was RTLD_LAZY
#define Q_RTLD    RTLD_NOW

	pwdpath = Sys_Cwd();
	homepath = Cvar_VariableString( "fs_homepath" );
	basepath = Cvar_VariableString( "fs_basepath" );
	gamedir = Cvar_VariableString( "fs_game" );

	// this is relevant to client only
	// this code is in for full client hosting a game, but it's not affected by it
#if !defined( DEDICATED )
	// do a first scan to identify what we are going to dlopen
	// we need to pass this to FS_ExtractFromPakFile so that it checksums the right file
	// NOTE: if something fails (not found, or file operation failed), we will ERR_FATAL (in the checksum itself, we only ERR_DROP)
#ifndef NDEBUG
	fn = FS_BuildOSPath( pwdpath, gamedir, fname );
	if ( access( fn, R_OK ) == -1 ) {
#endif
	fn = FS_BuildOSPath( homepath, gamedir, fname );
	if ( access( fn, R_OK ) == 0 ) {
		// there is a .so in fs_homepath, but is it a valid one version-wise?
		// we use a persistent variable in config.cfg to make sure
		// this is set in FS_CL_ExtractFromPakFile when the file is extracted
		cvar_t *lastVersion;
		cvar_name = va( "cl_lastVersion%s", name );
		lastVersion = Cvar_Get( cvar_name, "(uninitialized)", CVAR_ARCHIVE );
		if ( Q_stricmp( Cvar_VariableString( "version" ), lastVersion->string ) ) {
			Com_DPrintf( "clearing non matching version of %s .so: %s\n", name, fn );
			if ( remove( fn ) == -1 ) {
				Com_Error( ERR_FATAL, "failed to remove outdated '%s' file:\n\"%s\"\n", fn, strerror( errno ) );
			}
			// we cancelled fs_homepath, go work on basepath now
			fn = FS_BuildOSPath( basepath, gamedir, fname );
			if ( access( fn, R_OK ) == -1 ) {
				// we may be dealing with a media-only mod, check wether we can find 'reference' DLLs and copy them over
				if ( !CopyDLLForMod( &fn, gamedir, pwdpath, homepath, basepath, fname ) ) {
					Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed, no corresponding .so file found in fs_homepath or fs_basepath\n", name );
				}
			}
		}
		// the .so in fs_homepath is valid version-wise .. FS_CL_ExtractFromPakFile will have to decide wether it's valid pk3-wise later
	} else {
		fn = FS_BuildOSPath( basepath, gamedir, fname );
		if ( access( fn, R_OK ) == -1 ) {
			// we may be dealing with a media-only mod, check wether we can find 'reference' DLLs and copy them over
			if ( !CopyDLLForMod( &fn, gamedir, pwdpath, homepath, basepath, fname ) ) {
				Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed, no corresponding .so file found in fs_homepath or fs_basepath\n", name );
			}
		}
	}
#ifndef NDEBUG
}
#endif

	// NERVE - SMF - extract dlls from pak file for security
	// we have to handle the game dll a little differently
	// NOTE #2: we may have found a file in fs_basepath, and if the checksum is wrong, FS_Extract will write in fs_homepath
	//   won't be a problem since we start a brand new scan next
	if ( cl_connectedToPureServer && Q_strncmp( name, "qagame", 6 ) ) {
		if ( !FS_CL_ExtractFromPakFile( fn, gamedir, fname, cvar_name ) ) {
			Com_Error( ERR_DROP, "Game code(%s) failed Pure Server check", fname );
		}
	}
#endif

#ifndef NDEBUG
	// current directory
	// NOTE: only for debug build, see Sys_LoadDll discussion
	fn = FS_BuildOSPath( pwdpath, gamedir, fname );
	Com_Printf( "Sys_LoadDll(%s)... ", fn );
	libHandle = dlopen( fn, Q_RTLD );

	if ( !libHandle ) {
		Com_Printf( "\nSys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
#endif

	// homepath
	fn = FS_BuildOSPath( homepath, gamedir, fname );
	Com_Printf( "Sys_LoadDll(%s)... ", fn );
	libHandle = dlopen( fn, Q_RTLD );

	if ( !libHandle ) {
		Com_Printf( "\nSys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );

		// basepath
		fn = FS_BuildOSPath( basepath, gamedir, fname );
		Com_Printf( "Sys_LoadDll(%s)... ", fn );
		libHandle = dlopen( fn, Q_RTLD );
		if ( !libHandle ) {
			// report any problem
			Com_Printf( "\nSys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
		} else {
			Com_Printf( "ok\n" );
		}

		// not found, bail
		if ( !libHandle ) {
#ifndef NDEBUG // in debug abort on failure
			Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name  );
#else
			Com_Printf( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
#endif
			return NULL;
		}

	} else {
		Com_Printf( "ok\n" );
	}

#ifndef NDEBUG
} else {
	Com_Printf( "ok\n" );
}
#endif

	Q_strncpyz( fqpath, fn, MAX_QPATH ) ;           // added 2/15/02 by T.Ray

	dllEntry = dlsym( libHandle, "dllEntry" );
	*entryPoint = dlsym( libHandle, "vmMain" );
	if ( !*entryPoint || !dllEntry ) {
		err = dlerror();
#ifndef NDEBUG // in debug abort on failure
		Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#else
		Com_Printf( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#endif
		dlclose( libHandle );
		err = dlerror();
		if ( err != NULL ) {
			Com_Printf( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err );
		}
		return NULL;
	}
	Com_Printf( "Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint );
	dllEntry( systemcalls );
	Com_Printf( "Sys_LoadDll(%s) succeeded!\n", name );
	return libHandle;
}
Example #14
0
/*
==============
Sys_DefaultBasePath
==============
*/
char *Sys_DefaultBasePath( void ) {
	return Sys_Cwd();
}
Example #15
0
char *Sys_DefaultInstallPath(void)
{
	return Sys_Cwd();
}
Example #16
0
/*
=================
QAL_Init
=================
*/
qboolean QAL_Init(const char *libname)
{
	if(OpenALLib)
		return qtrue;

	Com_Printf( "Loading \"%s\"...\n", libname);
	if( (OpenALLib = Sys_LoadLibrary(libname)) == 0 )
	{
#ifdef _WIN32
		return qfalse;
#else
		char fn[1024];
		Q_strncpyz( fn, Sys_Cwd( ), sizeof( fn ) );
		strncat(fn, "/", sizeof(fn) - strlen(fn) - 1);
		strncat(fn, libname, sizeof(fn) - strlen(fn) - 1);

		if( (OpenALLib = Sys_LoadLibrary(fn)) == 0 )
		{
			return qfalse;
		}
#endif
	}

	alinit_fail = qfalse;

	qalEnable = GPA("alEnable");
	qalDisable = GPA("alDisable");
	qalIsEnabled = GPA("alIsEnabled");
	qalGetString = GPA("alGetString");
	qalGetBooleanv = GPA("alGetBooleanv");
	qalGetIntegerv = GPA("alGetIntegerv");
	qalGetFloatv = GPA("alGetFloatv");
	qalGetDoublev = GPA("alGetDoublev");
	qalGetBoolean = GPA("alGetBoolean");
	qalGetInteger = GPA("alGetInteger");
	qalGetFloat = GPA("alGetFloat");
	qalGetDouble = GPA("alGetDouble");
	qalGetError = GPA("alGetError");
	qalIsExtensionPresent = GPA("alIsExtensionPresent");
	qalGetProcAddress = GPA("alGetProcAddress");
	qalGetEnumValue = GPA("alGetEnumValue");
	qalListenerf = GPA("alListenerf");
	qalListener3f = GPA("alListener3f");
	qalListenerfv = GPA("alListenerfv");
	qalListeneri = GPA("alListeneri");
	qalGetListenerf = GPA("alGetListenerf");
	qalGetListener3f = GPA("alGetListener3f");
	qalGetListenerfv = GPA("alGetListenerfv");
	qalGetListeneri = GPA("alGetListeneri");
	qalGenSources = GPA("alGenSources");
	qalDeleteSources = GPA("alDeleteSources");
	qalIsSource = GPA("alIsSource");
	qalSourcef = GPA("alSourcef");
	qalSource3f = GPA("alSource3f");
	qalSourcefv = GPA("alSourcefv");
	qalSourcei = GPA("alSourcei");
	qalGetSourcef = GPA("alGetSourcef");
	qalGetSource3f = GPA("alGetSource3f");
	qalGetSourcefv = GPA("alGetSourcefv");
	qalGetSourcei = GPA("alGetSourcei");
	qalSourcePlayv = GPA("alSourcePlayv");
	qalSourceStopv = GPA("alSourceStopv");
	qalSourceRewindv = GPA("alSourceRewindv");
	qalSourcePausev = GPA("alSourcePausev");
	qalSourcePlay = GPA("alSourcePlay");
	qalSourceStop = GPA("alSourceStop");
	qalSourceRewind = GPA("alSourceRewind");
	qalSourcePause = GPA("alSourcePause");
	qalSourceQueueBuffers = GPA("alSourceQueueBuffers");
	qalSourceUnqueueBuffers = GPA("alSourceUnqueueBuffers");
	qalGenBuffers = GPA("alGenBuffers");
	qalDeleteBuffers = GPA("alDeleteBuffers");
	qalIsBuffer = GPA("alIsBuffer");
	qalBufferData = GPA("alBufferData");
	qalGetBufferf = GPA("alGetBufferf");
	qalGetBufferi = GPA("alGetBufferi");
	qalDopplerFactor = GPA("alDopplerFactor");
	qalDopplerVelocity = GPA("alDopplerVelocity");
	qalDistanceModel = GPA("alDistanceModel");

	qalcCreateContext = GPA("alcCreateContext");
	qalcMakeContextCurrent = GPA("alcMakeContextCurrent");
	qalcProcessContext = GPA("alcProcessContext");
	qalcSuspendContext = GPA("alcSuspendContext");
	qalcDestroyContext = GPA("alcDestroyContext");
	qalcGetCurrentContext = GPA("alcGetCurrentContext");
	qalcGetContextsDevice = GPA("alcGetContextsDevice");
	qalcOpenDevice = GPA("alcOpenDevice");
	qalcCloseDevice = GPA("alcCloseDevice");
	qalcGetError = GPA("alcGetError");
	qalcIsExtensionPresent = GPA("alcIsExtensionPresent");
	qalcGetProcAddress = GPA("alcGetProcAddress");
	qalcGetEnumValue = GPA("alcGetEnumValue");
	qalcGetString = GPA("alcGetString");
	qalcGetIntegerv = GPA("alcGetIntegerv");
	qalcCaptureOpenDevice = GPA("alcCaptureOpenDevice");
	qalcCaptureCloseDevice = GPA("alcCaptureCloseDevice");
	qalcCaptureStart = GPA("alcCaptureStart");
	qalcCaptureStop = GPA("alcCaptureStop");
	qalcCaptureSamples = GPA("alcCaptureSamples");

	if(alinit_fail)
	{
		QAL_Shutdown();
		Com_Printf( " One or more symbols not found\n");
		return qfalse;
	}

	return qtrue;
}
Example #17
0
/*
==============
Sys_DefaultCDPath
==============
*/
char *Sys_DefaultCDPath( void ) {
    return Sys_Cwd();
}
Example #18
0
void *Sys_LoadDll( const char *name, char *fqpath ,
                   int (**entryPoint)(int, ...),
                   int (*systemcalls)(int, ...) ) 
{
  void *libHandle;
  void  (*dllEntry)( int (*syscallptr)(int, ...) );
  char  fname[MAX_OSPATH];
  char  *cdpath;
  char  *basepath;
  char  *homepath;
  char  *pwdpath;
  char  *gamedir;
  char  *fn;
  const char*  err = NULL;
  
  *fqpath = 0;

  // bk001206 - let's have some paranoia
  assert( name );

#ifdef _PANDORA_
  snprintf (fname, sizeof(fname), "%s.so", name);
#else
  snprintf (fname, sizeof(fname), "%s." SHLIB_SUFFIX, name);
#endif

// bk001129 - was RTLD_LAZY 
#define Q_RTLD    RTLD_NOW

  pwdpath = Sys_Cwd();
  cdpath = Cvar_VariableString( "fs_cdpath" );
  basepath = Cvar_VariableString( "fs_basepath" );
  homepath = Cvar_VariableString( "fs_homepath" );
  gamedir = Cvar_VariableString( "fs_game" );

  // pwdpath
  fn = FS_BuildOSPath( pwdpath, gamedir, fname );
  Com_Printf( "Loading '%s'.\n", fn );
  libHandle = dlopen( fn, Q_RTLD );

  if ( !libHandle )
  {
    Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
    // fs_cdpath
    fn = FS_BuildOSPath( cdpath, gamedir, fname );
    Com_Printf( "Loading '%s'.\n", fn );
    libHandle = dlopen( fn, Q_RTLD);

    if ( !libHandle )
    {
      Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
      // fs_homepath
      fn = FS_BuildOSPath( homepath, gamedir, fname );
      Com_Printf( "Loading '%s'.\n", fn );
      libHandle = dlopen( fn, Q_RTLD );

      if ( !libHandle )
      {
        Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
        // fs_basepath
        fn = FS_BuildOSPath( basepath, gamedir, fname );
        Com_Printf( "Loading '%s'.\n", fn );
        libHandle = dlopen( fn, Q_RTLD );

        if ( !libHandle )
        {
#ifndef NDEBUG // bk001206 - in debug abort on failure
          Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name  );
#else
          Com_Printf ( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
#endif
          return NULL;
        } else
          Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
      } else
        Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
    } else
      Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn ); 
  } else
    Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn);

  dllEntry = dlsym( libHandle, "dllEntry" ); 
  *entryPoint = dlsym( libHandle, "vmMain" );
  if ( !*entryPoint || !dllEntry )
  {
    err = dlerror();
#ifndef NDEBUG // bk001206 - in debug abort on failure
    Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#else
    Com_Printf ( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#endif
    dlclose( libHandle );
    err = dlerror();
    if ( err != NULL )
      Com_Printf ( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err );
    return NULL;
  }
  Com_DPrintf ( "Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint ); // bk001212
  dllEntry( systemcalls );
  Com_DPrintf ( "Sys_LoadDll(%s) succeeded!\n", name );
  if ( libHandle ) Q_strncpyz ( fqpath , fn , MAX_QPATH ) ;		// added 7/20/02 by T.Ray
  return libHandle;
}
Example #19
0
/*
=================
CL_cURL_Init
=================
*/
qboolean CL_cURL_Init()
{
#ifdef USE_CURL_DLOPEN
    if(cURLLib)
        return qtrue;


    Com_Printf("Loading \"%s\"...", cl_cURLLib->string);
    if( (cURLLib = Sys_LoadLibrary(cl_cURLLib->string)) == 0 )
    {
#ifdef _WIN32
        return qfalse;
#else
        char fn[1024];

        Q_strncpyz( fn, Sys_Cwd( ), sizeof( fn ) );
        strncat(fn, "/", sizeof(fn)-strlen(fn)-1);
        strncat(fn, cl_cURLLib->string, sizeof(fn)-strlen(fn)-1);

        if((cURLLib = Sys_LoadLibrary(fn)) == 0)
        {
#ifdef ALTERNATE_CURL_LIB
            // On some linux distributions there is no libcurl.so.3, but only libcurl.so.4. That one works too.
            if( (cURLLib = Sys_LoadLibrary(ALTERNATE_CURL_LIB)) == 0 )
            {
                return qfalse;
            }
#else
            return qfalse;
#endif
        }
#endif /* _WIN32 */
    }

    clc.cURLEnabled = qtrue;

    qcurl_version = GPA("curl_version");

    qcurl_easy_init = GPA("curl_easy_init");
    qcurl_easy_setopt = GPA("curl_easy_setopt");
    qcurl_easy_perform = GPA("curl_easy_perform");
    qcurl_easy_cleanup = GPA("curl_easy_cleanup");
    qcurl_easy_getinfo = GPA("curl_easy_getinfo");
    qcurl_easy_duphandle = GPA("curl_easy_duphandle");
    qcurl_easy_reset = GPA("curl_easy_reset");
    qcurl_easy_strerror = GPA("curl_easy_strerror");

    qcurl_multi_init = GPA("curl_multi_init");
    qcurl_multi_add_handle = GPA("curl_multi_add_handle");
    qcurl_multi_remove_handle = GPA("curl_multi_remove_handle");
    qcurl_multi_fdset = GPA("curl_multi_fdset");
    qcurl_multi_perform = GPA("curl_multi_perform");
    qcurl_multi_cleanup = GPA("curl_multi_cleanup");
    qcurl_multi_info_read = GPA("curl_multi_info_read");
    qcurl_multi_strerror = GPA("curl_multi_strerror");

    if(!clc.cURLEnabled)
    {
        CL_cURL_Shutdown();
        Com_Printf("FAIL One or more symbols not found\n");
        return qfalse;
    }
    Com_Printf("OK\n");

    return qtrue;
#else
    clc.cURLEnabled = qtrue;
    return qtrue;
#endif /* USE_CURL_DLOPEN */
}
Example #20
0
void *Sys_LoadDll(const char *name, char *fqpath, int (**entryPoint)(int, ...), int (*systemcalls)(int, ...)) {

	image_id libHandle = -1;
	void  (*dllEntry)( int (*syscallptr)(int, ...) );
	char  curpath[MAX_OSPATH];
	char  fname[MAX_OSPATH];
	char  *basepath;
	char  *homepath;
	char  *pwdpath;
	char  *gamedir;
	char  *fn;
	const char*  err = NULL;
	
	*fqpath = 0;

  // bk001206 - let's have some paranoia
	assert(name);
	getcwd(curpath, sizeof(curpath));
	snprintf (fname, sizeof(fname), "%si386.so", name);

	// bk001129 - was RTLD_LAZY 
	#define Q_RTLD    RTLD_NOW

	pwdpath = Sys_Cwd();
	basepath = Cvar_VariableString( "fs_basepath" );
	homepath = Cvar_VariableString( "fs_homepath" );
	gamedir = Cvar_VariableString( "fs_game" );

	//pwdpath
	fn = FS_BuildOSPath( pwdpath, gamedir, fname );
	Com_Printf( "Sys_LoadDll(%s)... \n", fn );
	
	//libHandle = dlopen( fn, Q_RTLD );
	libHandle = load_add_on(fn);

	if (/*!libHandle*/libHandle < 0) {
		Com_Printf("Sys_LoadDll(%s) failed:\n", fn /*dlerror()*/);
		// fs_homepath
		fn = FS_BuildOSPath( homepath, gamedir, fname );
		Com_Printf( "Sys_LoadDll(%s)... \n", fn );
		//libHandle = dlopen( fn, Q_RTLD );
		libHandle = load_add_on(fn);

		if (/*!libHandle*/libHandle < 0) {
			Com_Printf("Sys_LoadDll(%s) failed:\n", fn /*dlerror()*/);
			// fs_basepath
			fn = FS_BuildOSPath( basepath, gamedir, fname );
			Com_Printf("Sys_LoadDll(%s)... \n", fn);
			//libHandle = dlopen( fn, Q_RTLD );
			libHandle = load_add_on(fn);

			if (/*!libHandle*/libHandle < 0) {
#ifndef NDEBUG // bk001206 - in debug abort on failure
				Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name  );
#else
				Com_Printf ( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
#endif
				return NULL;
			} else
				Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
		} else
			Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
	} else
		Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn ); 

	get_image_symbol(libHandle, "dllEntry", B_SYMBOL_TYPE_TEXT, (void**)&dllEntry);
	get_image_symbol(libHandle, "vmMain", B_SYMBOL_TYPE_TEXT, (void**)entryPoint);

	if (!*entryPoint || !dllEntry) {
		//jens err = dlerror();
#ifndef NDEBUG // bk001206 - in debug abort on failure
		Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err);
#else
		Com_Printf ( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err);
#endif
		//dlclose(libHandle);
		unload_add_on(libHandle);
		//jenserr = dlerror();
		if (err != NULL)
			Com_Printf ( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err);
		return NULL;
	}
	Com_Printf("Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint); // bk001212

	dllEntry(systemcalls);
	Com_Printf("Sys_LoadDll(%s) succeeded!\n", name );
	if (libHandle)
		Q_strncpyz(fqpath, fn, MAX_QPATH);	// added 7/20/02 by T.Ray

	return (void*)libHandle;
}
/*
==============
Sys_DefaultBasePath
==============
*/
const char *Sys_DefaultBasePath() {
	return Sys_Cwd();
}
Example #22
0
void *Sys_LoadDll( const char *name,
				   int( **entryPoint ) ( int, ... ),
				   int ( *systemcalls )( int, ... ) )
#endif
{
	void *libHandle;
	void ( *dllEntry )( int ( *syscallptr )( int, ... ) );
	char fname[MAX_OSPATH];
	char  *homepath;
	char  *basepath;
	char  *pwdpath;
	char  *gamedir;
	char  *fn;
	const char*  err = NULL; // bk001206 // rb0101023 - now const

	// bk001206 - let's have some paranoia
	assert( name );

#if defined __i386__
	snprintf( fname, sizeof( fname ), "%si386.so", name );
#elif defined __powerpc__   //rcg010207 - PPC support.
	snprintf( fname, sizeof( fname ), "%sppc.so", name );
#elif defined __axp__
	snprintf( fname, sizeof( fname ), "%saxp.so", name );
#elif defined __mips__
	snprintf( fname, sizeof( fname ), "%smips.so", name );
#elif defined __arm__
        snprintf( fname, sizeof( fname ), "%sarm.so", name );
#else
#error Unknown arch
#endif

// bk001129 - was RTLD_LAZY
#define Q_RTLD    RTLD_NOW

	homepath = Cvar_VariableString( "fs_homepath" );
	basepath = Cvar_VariableString( "fs_basepath" );
	gamedir = Cvar_VariableString( "fs_game" );

	pwdpath = Sys_Cwd();
	fn = FS_BuildOSPath( pwdpath, gamedir, fname );
	// bk001206 - verbose
	Com_Printf( "Sys_LoadDll(%s)... ", fn );

	// bk001129 - from cvs1.17 (mkv), was fname not fn
	libHandle = dlopen( fn, Q_RTLD );

	if ( !libHandle ) {
		Com_Printf( "failed (%s)\n", dlerror() );
		// homepath
		fn = FS_BuildOSPath( homepath, gamedir, fname );
		Com_Printf( "Sys_LoadDll(%s)... ", fn );
		libHandle = dlopen( fn, Q_RTLD );

		if ( !libHandle ) {
			Com_Printf( "failed (%s)\n", dlerror() );
			// basepath
			fn = FS_BuildOSPath( basepath, gamedir, fname );
			Com_Printf( "Sys_LoadDll(%s)... ", fn );
			libHandle = dlopen( fn, Q_RTLD );

			if ( !libHandle ) {
				Com_Printf( "failed (%s)\n", dlerror() );

				if ( strlen( gamedir ) && Q_stricmp( gamedir, BASEGAME ) ) { // begin BASEGAME != fs_game section

					// media-only mods: no DLL whatsoever in the fs_game
					// start the loop again using the hardcoded BASEDIRNAME
					fn = FS_BuildOSPath( pwdpath, BASEGAME, fname );
					Com_Printf( "Sys_LoadDll(%s)... ", fn );
					libHandle = dlopen( fn, Q_RTLD );

					if ( !libHandle ) {
						Com_Printf( "failed (%s)\n", dlerror() );
						// homepath
						fn = FS_BuildOSPath( homepath, BASEGAME, fname );
						Com_Printf( "Sys_LoadDll(%s)... ", fn );
						libHandle = dlopen( fn, Q_RTLD );

						if ( !libHandle ) {
							Com_Printf( "failed (%s)\n", dlerror() );
							// homepath
							fn = FS_BuildOSPath( basepath, BASEGAME, fname );
							Com_Printf( "Sys_LoadDll(%s)... ", fn );
							libHandle = dlopen( fn, Q_RTLD );

							if ( !libHandle ) {
								// ok, this time things are really f****d
								Com_Printf( "failed (%s)\n", dlerror() );
							} else {
								Com_Printf( "ok\n" );
							}
						} else {
							Com_Printf( "ok\n" );
						}
					} else {
						Com_Printf( "ok\n" );
					}
				} // end BASEGAME != fs_game section
			} else {
				Com_Printf( "ok\n" );
			}
		} else {
			Com_Printf( "ok\n" );
		}
	} else {
		Com_Printf( "ok\n" );
	}

	if ( !libHandle ) {
#ifndef NDEBUG // in debug, abort on failure
		Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name  );
#else
		Com_Printf( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
#endif
		return NULL;
	}

	dllEntry = dlsym( libHandle, "dllEntry" );
	*entryPoint = dlsym( libHandle, "vmMain" );
	if ( !*entryPoint || !dllEntry ) {
		err = dlerror();
#ifndef NDEBUG // bk001206 - in debug abort on failure
		Com_Error( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#else
		Com_Printf( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#endif
		dlclose( libHandle );
		err = dlerror();
		if ( err != NULL ) {
			Com_Printf( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err );
		}
		return NULL;
	}
	Com_Printf( "Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint ); // bk001212
	dllEntry( systemcalls );
	Com_Printf( "Sys_LoadDll(%s) succeeded!\n", name );
	return libHandle;
}
void *Sys_LoadDll( const char *name, char *fqpath ,
                   int (**entryPoint)(int, ...),
                   int (*systemcalls)(int, ...) ) 
{
#ifdef IPHONE
  extern int baseq3_ui_vmMain(int, ...), baseq3_qagame_vmMain(int, ...), baseq3_cgame_vmMain(int, ...);
  extern void baseq3_ui_dllEntry(int (*)(int, ...)), baseq3_qagame_dllEntry(int (*)(int, ...)), baseq3_cgame_dllEntry(int (*)(int, ...));
  static const struct
  {
    const char *game;
    const char *name;
    void (*dllEntry)(int (*)(int, ...));
    int (*entryPoint)(int, ...);
  } dllDescriptions[] =
  {
    {"", "ui", baseq3_ui_dllEntry, baseq3_ui_vmMain},
    {"", "qagame", baseq3_qagame_dllEntry, baseq3_qagame_vmMain},
    {"", "cgame", baseq3_cgame_dllEntry, baseq3_cgame_vmMain},
  };
  char *game = Cvar_VariableString("fs_game");
  int i;
  
  for (i = 0; i < sizeof(dllDescriptions) / sizeof(dllDescriptions[0]); ++i)
  {
    if (!strcmp(game, dllDescriptions[i].game) && !strcmp(name, dllDescriptions[i].name))
    {
      *entryPoint = dllDescriptions[i].entryPoint;
      dllDescriptions[i].dllEntry(systemcalls);
      return (void *)0xdeadc0de;
    }
  }

  Com_Printf("Sys_LoadDll(%s) could not find appropriate entry point for game %s\n", name, game);
  return NULL;
#else
  void *libHandle;
  void  (*dllEntry)( int (*syscallptr)(int, ...) );
  char  fname[MAX_OSPATH];
  char  *cdpath;
  char  *basepath;
  char  *homepath;
  char  *pwdpath;
  char  *gamedir;
  char  *fn;
  const char*  err = NULL;
  
  *fqpath = 0;

  // bk001206 - let's have some paranoia
  assert( name );

  snprintf (fname, sizeof(fname), "%s." SHLIB_SUFFIX, name);

// bk001129 - was RTLD_LAZY 
#define Q_RTLD    RTLD_NOW

  pwdpath = Sys_Cwd();
  cdpath = Cvar_VariableString( "fs_cdpath" );
  basepath = Cvar_VariableString( "fs_basepath" );
  homepath = Cvar_VariableString( "fs_homepath" );
  gamedir = Cvar_VariableString( "fs_game" );

  // pwdpath
  fn = FS_BuildOSPath( pwdpath, gamedir, fname );
  Com_Printf( "Loading '%s'.\n", fn );
  libHandle = dlopen( fn, Q_RTLD );

  if ( !libHandle )
  {
    Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
    // fs_cdpath
    fn = FS_BuildOSPath( cdpath, gamedir, fname );
    Com_Printf( "Loading '%s'.\n", fn );
    libHandle = dlopen( fn, Q_RTLD);

    if ( !libHandle )
    {
      Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
      // fs_homepath
      fn = FS_BuildOSPath( homepath, gamedir, fname );
      Com_Printf( "Loading '%s'.\n", fn );
      libHandle = dlopen( fn, Q_RTLD );

      if ( !libHandle )
      {
        Com_DPrintf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, dlerror() );
        // fs_basepath
        fn = FS_BuildOSPath( basepath, gamedir, fname );
        Com_Printf( "Loading '%s'.\n", fn );
        libHandle = dlopen( fn, Q_RTLD );

        if ( !libHandle )
        {
#ifndef NDEBUG // bk001206 - in debug abort on failure
          Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlopen() completely!\n", name  );
#else
          Com_Printf ( "Sys_LoadDll(%s) failed dlopen() completely!\n", name );
#endif
          return NULL;
        } else
          Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
      } else
        Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
    } else
      Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn ); 
  } else
    Com_DPrintf ( "Sys_LoadDll(%s): succeeded ...\n", fn);

  dllEntry = dlsym( libHandle, "dllEntry" ); 
  *entryPoint = dlsym( libHandle, "vmMain" );
  if ( !*entryPoint || !dllEntry )
  {
    err = dlerror();
#ifndef NDEBUG // bk001206 - in debug abort on failure
    Com_Error ( ERR_FATAL, "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#else
    Com_Printf ( "Sys_LoadDll(%s) failed dlsym(vmMain):\n\"%s\" !\n", name, err );
#endif
    dlclose( libHandle );
    err = dlerror();
    if ( err != NULL )
      Com_Printf ( "Sys_LoadDll(%s) failed dlcose:\n\"%s\"\n", name, err );
    return NULL;
  }
  Com_DPrintf ( "Sys_LoadDll(%s) found **vmMain** at  %p  \n", name, *entryPoint ); // bk001212
  dllEntry( systemcalls );
  Com_DPrintf ( "Sys_LoadDll(%s) succeeded!\n", name );
  if ( libHandle ) Q_strncpyz ( fqpath , fn , MAX_QPATH ) ;		// added 7/20/02 by T.Ray
  return libHandle;
#endif // IPHONE
}