Skip to content

Commit

Permalink
filesystem: put FS_FindLibrary arguments into a structure, fix incorr…
Browse files Browse the repository at this point in the history
…ect call on the engine side
  • Loading branch information
a1batross committed Jul 26, 2022
1 parent b3e64e6 commit 04acd13
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
23 changes: 12 additions & 11 deletions engine/common/lib_common.c
Expand Up @@ -87,24 +87,25 @@ const char *COM_OffsetNameForFunction( void *function )

dll_user_t *COM_FindLibrary( const char *dllname, qboolean directpath )
{
dll_user_t hInst, *p;
string dllpath;

memset( &hInst, 0, sizeof( hInst ));
dll_user_t *p;
fs_dllinfo_t dllInfo;

if( FS_FindLibrary && !FS_FindLibrary( dllname, directpath, hInst.dllName, sizeof( hInst.dllName ), &hInst.encrypted, &hInst.custom_loader, hInst.fullPath, sizeof( hInst.fullPath )))
{
// no fs loaded, can't search
if( !FS_FindLibrary )
return NULL;
}

// save dllname for debug purposes
Q_strncpy( hInst.dllName, dllname, sizeof( hInst.dllName ));
// fs can't find library
if( !FS_FindLibrary( dllname, directpath, &dllInfo ))
return NULL;

// NOTE: for libraries we not fail even if search is NULL
// let the OS find library himself
p = Mem_Calloc( host.mempool, sizeof( dll_user_t ));

memcpy( p, &hInst, sizeof( *p ));
Q_strncpy( p->shortPath, dllInfo.shortPath, sizeof( p->shortPath ));
Q_strncpy( p->fullPath, dllInfo.fullPath, sizeof( p->fullPath ));
Q_strncpy( p->dllName, dllname, sizeof( p->dllName ));
p->custom_loader = dllInfo.custom_loader;
p->encrypted = dllInfo.encrypted;

return p;
}
Expand Down
31 changes: 16 additions & 15 deletions filesystem/filesystem.c
Expand Up @@ -1257,7 +1257,7 @@ FS_FindLibrary
search for library, assume index is valid
==================
*/
qboolean FS_FindLibrary( const char *dllname, qboolean directpath, char *dllpath, size_t dllpathlen, qboolean *encrypted, qboolean *custom_loader, char *fullPath, size_t fullpathlen )
static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dllinfo_t *dllInfo )
{
searchpath_t *search;
int index, start = 0, i, len;
Expand All @@ -1277,36 +1277,37 @@ qboolean FS_FindLibrary( const char *dllname, qboolean directpath, char *dllpath

for( i = 0; i < len; i++ )
{
if( dllname[i+start] == '\\' ) dllpath[i] = '/';
else dllpath[i] = Q_tolower( dllname[i+start] );
if( dllname[i+start] == '\\' ) dllInfo->shortPath[i] = '/';
else dllInfo->shortPath[i] = Q_tolower( dllname[i+start] );
}
dllpath[i] = '\0';
dllInfo->shortPath[i] = '\0';

COM_DefaultExtension( dllpath, "."OS_LIB_EXT ); // apply ext if forget
COM_DefaultExtension( dllInfo->shortPath, "."OS_LIB_EXT ); // apply ext if forget

search = FS_FindFile( dllpath, &index, false );
search = FS_FindFile( dllInfo->shortPath, &index, false );

if( !search && !directpath )
{
fs_ext_path = false;

// trying check also 'bin' folder for indirect paths
Q_strncpy( dllpath, dllname, dllpathlen );
search = FS_FindFile( dllpath, &index, false );
Q_strncpy( dllInfo->shortPath, dllname, sizeof( dllInfo->shortPath ));
search = FS_FindFile( dllInfo->shortPath, &index, false );
if( !search ) return false; // unable to find
}

*encrypted = FS_CheckForCrypt( dllpath );
dllInfo->encrypted = FS_CheckForCrypt( dllInfo->shortPath );

if( index < 0 && !*encrypted && search )
if( index < 0 && !dllInfo->encrypted && search )
{
Q_snprintf( fullPath, fullpathlen, "%s%s", search->filename, dllpath );
*custom_loader = false; // we can loading from disk and use normal debugging
Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ),
"%s%s", search->filename, dllInfo->shortPath );
dllInfo->custom_loader = false; // we can loading from disk and use normal debugging
}
else
{
// NOTE: if search is NULL let the OS found library himself
Q_strncpy( fullPath, dllpath, fullpathlen );
Q_strncpy( dllInfo->fullPath, dllInfo->shortPath, sizeof( dllInfo->fullPath ));

if( search && search->type != SEARCHPATH_PLAIN )
{
Expand All @@ -1317,12 +1318,12 @@ qboolean FS_FindLibrary( const char *dllname, qboolean directpath, char *dllpath
#else
Con_Printf( S_WARN "%s: loading libraries from packs is unsupported on "
"this platform\n", __FUNCTION__ );
*custom_loader = false;
dllInfo->custom_loader = false;
#endif
}
else
{
*custom_loader = false;
dllInfo->custom_loader = false;
}
}
fs_ext_path = false; // always reset direct paths
Expand Down
10 changes: 9 additions & 1 deletion filesystem/filesystem.h
Expand Up @@ -104,6 +104,14 @@ typedef enum
GAME_MULTIPLAYER_ONLY
} gametype_t;

typedef struct fs_dllinfo_t
{
string fullPath;
string shortPath;
qboolean encrypted;
qboolean custom_loader;
} fs_dllinfo_t;

typedef struct fs_globals_t
{
gameinfo_t *GameInfo; // current GameInfo
Expand All @@ -124,7 +132,7 @@ typedef struct fs_api_t
void (*AddGameHierarchy)( const char *dir, uint flags );
search_t *(*Search)( const char *pattern, int caseinsensitive, int gamedironly );
int (*SetCurrentDirectory)( const char *path );
qboolean (*FindLibrary)( const char *dllname, qboolean directpath, char *dllpath, size_t dllpathlen, qboolean *encrypted, qboolean *custom_loader, char *fullPath, size_t fullpathlen );
qboolean (*FindLibrary)( const char *dllname, qboolean directpath, fs_dllinfo_t *dllinfo );
void (*Path_f)( void );

// gameinfo utils
Expand Down
1 change: 0 additions & 1 deletion filesystem/filesystem_internal.h
Expand Up @@ -112,7 +112,6 @@ void FS_AddGameDirectory( const char *dir, uint flags );
void FS_AddGameHierarchy( const char *dir, uint flags );
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly );
int FS_SetCurrentDirectory( const char *path );
qboolean FS_FindLibrary( const char *dllname, qboolean directpath, char *dllpath, size_t dllpathlen, qboolean *encrypted, qboolean *custom_loader, char *fullPath, size_t fullpathlen );
void FS_Path_f( void );

// gameinfo utils
Expand Down

0 comments on commit 04acd13

Please sign in to comment.