mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-10 14:52:00 +00:00
Patch by Simon McVittie to improve dynamic library loading (#4700)
This commit is contained in:
parent
d2f8b9f4bb
commit
7bb5906599
3 changed files with 38 additions and 39 deletions
|
@ -1220,6 +1220,32 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF
|
|||
}
|
||||
|
||||
|
||||
char *FS_FindDll( const char *filename ) {
|
||||
searchpath_t *search;
|
||||
directory_t *dir;
|
||||
|
||||
if ( !fs_searchpaths ) {
|
||||
Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
|
||||
}
|
||||
|
||||
for ( search = fs_searchpaths ; search ; search = search->next ) {
|
||||
if ( search->dir ) {
|
||||
FILE *f;
|
||||
char *netpath;
|
||||
|
||||
dir = search->dir;
|
||||
netpath = FS_BuildOSPath( dir->path, dir->gamedir, filename );
|
||||
f = fopen( netpath, "rb" );
|
||||
if (f) {
|
||||
fclose( f );
|
||||
return netpath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
FS_Read
|
||||
|
|
|
@ -606,6 +606,9 @@ void FS_FreeFileList( char **list );
|
|||
qboolean FS_FileExists( const char *file );
|
||||
|
||||
qboolean FS_CreatePath (char *OSPath);
|
||||
|
||||
char *FS_FindDll( const char *filename );
|
||||
|
||||
char *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
|
||||
qboolean FS_CompareZipChecksum(const char *zipfile);
|
||||
|
||||
|
|
|
@ -405,34 +405,6 @@ void Sys_UnloadDll( void *dllHandle )
|
|||
Sys_UnloadLibrary(dllHandle);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_TryLibraryLoad
|
||||
=================
|
||||
*/
|
||||
static void* Sys_TryLibraryLoad(const char* base, const char* gamedir, const char* fname, char* fqpath )
|
||||
{
|
||||
void* libHandle;
|
||||
char* fn;
|
||||
|
||||
*fqpath = 0;
|
||||
|
||||
fn = FS_BuildOSPath( base, gamedir, fname );
|
||||
Com_Printf( "Sys_LoadDll(%s)... \n", fn );
|
||||
|
||||
libHandle = Sys_LoadLibrary(fn);
|
||||
|
||||
if(!libHandle) {
|
||||
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", fn, Sys_LibraryError() );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Com_Printf ( "Sys_LoadDll(%s): succeeded ...\n", fn );
|
||||
Q_strncpyz ( fqpath , fn , MAX_QPATH ) ;
|
||||
|
||||
return libHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_LoadDll
|
||||
|
@ -449,26 +421,24 @@ void *Sys_LoadDll( const char *name, char *fqpath ,
|
|||
void *libHandle;
|
||||
void (*dllEntry)( intptr_t (*syscallptr)(intptr_t, ...) );
|
||||
char fname[MAX_OSPATH];
|
||||
char *basepath;
|
||||
char *homepath;
|
||||
char *gamedir;
|
||||
char *netpath;
|
||||
|
||||
assert( name );
|
||||
|
||||
Q_snprintf (fname, sizeof(fname), "%s" ARCH_STRING DLL_EXT, name);
|
||||
|
||||
// TODO: use fs_searchpaths from files.c
|
||||
basepath = Cvar_VariableString( "fs_basepath" );
|
||||
homepath = Cvar_VariableString( "fs_homepath" );
|
||||
gamedir = Cvar_VariableString( "fs_game" );
|
||||
netpath = FS_FindDll(fname);
|
||||
|
||||
libHandle = Sys_TryLibraryLoad(homepath, gamedir, fname, fqpath);
|
||||
if(!netpath) {
|
||||
Com_Printf( "Sys_LoadDll(%s) could not find it\n", fname );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!libHandle && basepath)
|
||||
libHandle = Sys_TryLibraryLoad(basepath, gamedir, fname, fqpath);
|
||||
Com_Printf( "Loading DLL file: %s\n", netpath);
|
||||
libHandle = Sys_LoadLibrary(netpath);
|
||||
|
||||
if(!libHandle) {
|
||||
Com_Printf ( "Sys_LoadDll(%s) failed to load library\n", name );
|
||||
Com_Printf( "Sys_LoadDll(%s) failed:\n\"%s\"\n", netpath, Sys_LibraryError() );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue