From 60c6767337613b0722c9095575938fb7f6f16d10 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 22 Apr 2024 03:39:21 +0300 Subject: [PATCH] filesystem: copy absolute path to library in FS_FindLibrary for compatibility Extend fullPath for longer absolute paths. --- engine/common/filesystem_engine.c | 12 ++++++------ engine/common/library.h | 3 ++- filesystem/filesystem.c | 9 +++++++-- filesystem/filesystem.h | 6 +++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/engine/common/filesystem_engine.c b/engine/common/filesystem_engine.c index 2b1e341e..79ba2398 100644 --- a/engine/common/filesystem_engine.c +++ b/engine/common/filesystem_engine.c @@ -89,32 +89,32 @@ qboolean FS_LoadProgs( void ) if( !fs_hInstance ) { - Host_Error( "FS_LoadProgs: can't load filesystem library %s: %s\n", name, COM_GetLibraryError() ); + Host_Error( "%s: can't load filesystem library %s: %s\n", __func__, name, COM_GetLibraryError() ); return false; } if( !( GetFSAPI = (FSAPI)COM_GetProcAddress( fs_hInstance, GET_FS_API ))) { FS_UnloadProgs(); - Host_Error( "FS_LoadProgs: can't find GetFSAPI entry point in %s\n", name ); + Host_Error( "%s: can't find GetFSAPI entry point in %s\n", __func__, name ); return false; } - if( !GetFSAPI( FS_API_VERSION, &g_fsapi, &FI, &fs_memfuncs )) + if( GetFSAPI( FS_API_VERSION, &g_fsapi, &FI, &fs_memfuncs ) != FS_API_VERSION ) { FS_UnloadProgs(); - Host_Error( "FS_LoadProgs: can't initialize filesystem API: wrong version\n" ); + Host_Error( "%s: can't initialize filesystem API: wrong version\n", __func__ ); return false; } if( !( fs_pfnCreateInterface = (pfnCreateInterface_t)COM_GetProcAddress( fs_hInstance, "CreateInterface" ))) { FS_UnloadProgs(); - Host_Error( "FS_LoadProgs: can't find CreateInterface entry point in %s\n", name ); + Host_Error( "%s: can't find CreateInterface entry point in %s\n", __func__, name ); return false; } - Con_DPrintf( "FS_LoadProgs: filesystem_stdio successfully loaded\n" ); + Con_DPrintf( "%s: filesystem_stdio successfully loaded\n", __func__ ); return true; } diff --git a/engine/common/library.h b/engine/common/library.h index 10524249..65572ad0 100644 --- a/engine/common/library.h +++ b/engine/common/library.h @@ -24,7 +24,8 @@ typedef struct dll_user_s qboolean custom_loader; // a bit who indicated loader type qboolean encrypted; // dll is crypted (some client.dll in HL, CS etc) char dllName[32]; // for debug messages - string fullPath, shortPath; // actual dll paths + char fullPath[2048]; + string shortPath; // actual dll paths // ordinals stuff, valid only on Win32 word *ordinals; diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index eab49eb7..18d92839 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -1363,8 +1363,13 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll if( index >= 0 && !dllInfo->encrypted && search ) { - Q_snprintf( dllInfo->fullPath, sizeof( dllInfo->fullPath ), - "%s%s", search->filename, dllInfo->shortPath ); + // gamedll might resolve it's own path using dladdr() + // combine it with engine returned path to gamedir + // it might lead to double gamedir like this + // - valve/valve/dlls/hl.so + // instead of expected + // - valve/dlls/hl.so + 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 diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index 716fb4d6..f6d3e85d 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -31,7 +31,7 @@ extern "C" { #endif // __cplusplus -#define FS_API_VERSION 2 // not stable yet! +#define FS_API_VERSION 3 // not stable yet! #define FS_API_CREATEINTERFACE_TAG "XashFileSystem002" // follow FS_API_VERSION!!! #define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" // never change this! @@ -121,8 +121,8 @@ typedef enum typedef struct fs_dllinfo_t { - string fullPath; - string shortPath; + char fullPath[2048]; // absolute disk path + string shortPath; // vfs path qboolean encrypted; qboolean custom_loader; } fs_dllinfo_t;