filesystem: fix writedir being prepended to rodir path when searching for library

* Refactor generating shortName
* Refactor library origin checks
This commit is contained in:
Alibek Omarov 2024-06-27 08:16:54 +03:00
parent ec107dfba5
commit 5694610478
2 changed files with 32 additions and 37 deletions

View file

@ -1325,15 +1325,8 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll
start += len; start += len;
} }
// replace all backward slashes Q_strnlwr( &dllname[start], dllInfo->shortPath, sizeof( dllInfo->shortPath )); // always in lower case (why?)
len = Q_strlen( dllname ); COM_FixSlashes( dllInfo->shortPath ); // replace all backward slashes
for( i = 0; i < len; i++ )
{
if( dllname[i+start] == '\\' ) dllInfo->shortPath[i] = '/';
else dllInfo->shortPath[i] = Q_tolower( dllname[i+start] );
}
dllInfo->shortPath[i] = '\0';
COM_DefaultExtension( dllInfo->shortPath, "."OS_LIB_EXT, sizeof( dllInfo->shortPath )); // apply ext if forget COM_DefaultExtension( dllInfo->shortPath, "."OS_LIB_EXT, sizeof( dllInfo->shortPath )); // apply ext if forget
search = FS_FindFile( dllInfo->shortPath, &index, fixedname, sizeof( fixedname ), false ); search = FS_FindFile( dllInfo->shortPath, &index, fixedname, sizeof( fixedname ), false );
@ -1354,41 +1347,43 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll
Q_strncpy( dllInfo->shortPath, fixedname, sizeof( dllInfo->shortPath )); Q_strncpy( dllInfo->shortPath, fixedname, sizeof( dllInfo->shortPath ));
} }
dllInfo->encrypted = dllInfo->custom_loader = false; // predict state
if( search && index >= 0 ) // when library is available through VFS
{
dllInfo->encrypted = FS_CheckForCrypt( dllInfo->shortPath ); dllInfo->encrypted = FS_CheckForCrypt( dllInfo->shortPath );
if( index >= 0 && !dllInfo->encrypted && search ) if( search->type == SEARCHPATH_PLAIN ) // is it on the disk? (intentionally omit pk3dir here)
{ {
// gamedll might resolve it's own path using dladdr() // NOTE: gamedll might resolve it's own path using dladdr() and expects absolute path
// combine it with engine returned path to gamedir // NOTE: the only allowed case when searchpath is set by absolute path is the RoDir
// it might lead to double gamedir like this // rather than figuring out whether path is absolute, just check if it matches
// - valve/valve/dlls/hl.so if( !Q_strnicmp( search->filename, fs_rodir, Q_strlen( fs_rodir )))
// instead of expected {
// - valve/dlls/hl.so Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), "%s%s", search->filename, dllInfo->shortPath );
Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), "%s/%s%s", fs_rootdir, search->filename, dllInfo->shortPath );
dllInfo->custom_loader = false; // we can loading from disk and use normal debugging
} }
else else
{ {
// NOTE: if search is NULL let the OS found library himself Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), "%s/%s%s", fs_rootdir, search->filename, dllInfo->shortPath );
Q_strncpy( dllInfo->fullPath, dllInfo->shortPath, sizeof( dllInfo->fullPath )); }
}
if( search && search->type != SEARCHPATH_PLAIN ) else
{ {
Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), "%s%s", search->filename, dllInfo->shortPath );
#if XASH_WIN32 && XASH_X86 // a1ba: custom loader is non-portable (I just don't want to touch it) #if XASH_WIN32 && XASH_X86 // a1ba: custom loader is non-portable (I just don't want to touch it)
Con_Printf( S_WARN "%s: loading libraries from packs is deprecated " Con_Printf( S_WARN "%s: loading libraries from archives is deprecated and will be removed in the future\n", __func__ );
"and will be removed in the future\n", __func__ );
dllInfo->custom_loader = true; dllInfo->custom_loader = true;
#else #else
Con_Printf( S_WARN "%s: loading libraries from packs is unsupported on " Con_Printf( S_WARN "%s: loading libraries from archives is unsupported on this platform\n", __func__ );
"this platform\n", __func__ );
dllInfo->custom_loader = false;
#endif #endif
} }
}
else else
{ {
dllInfo->custom_loader = false; // NOTE: if search is NULL let OS to find the library
} Q_strncpy( dllInfo->fullPath, dllInfo->shortPath, sizeof( dllInfo->fullPath ));
} }
FS_AllowDirectPaths( false ); // always reset direct paths FS_AllowDirectPaths( false ); // always reset direct paths
return true; return true;

View file

@ -123,8 +123,8 @@ typedef struct fs_dllinfo_t
{ {
char fullPath[2048]; // absolute disk path char fullPath[2048]; // absolute disk path
string shortPath; // vfs path string shortPath; // vfs path
qboolean encrypted; qboolean encrypted; // do we need encrypted DLL loader?
qboolean custom_loader; qboolean custom_loader; // do we need memory DLL loader?
} fs_dllinfo_t; } fs_dllinfo_t;
typedef struct fs_globals_t typedef struct fs_globals_t