From fce8afabfb0629d88ae02c87e62cb27e666c7010 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 25 Aug 2022 20:33:16 +0300 Subject: [PATCH] filesystem: allow acquiring C interface through CreateInterface export --- filesystem/VFileSystem009.cpp | 12 ++++++++++++ filesystem/filesystem.c | 2 +- filesystem/filesystem.h | 1 + filesystem/filesystem_internal.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/filesystem/VFileSystem009.cpp b/filesystem/VFileSystem009.cpp index ffcffe40..7bfee6ba 100644 --- a/filesystem/VFileSystem009.cpp +++ b/filesystem/VFileSystem009.cpp @@ -492,6 +492,18 @@ extern "C" void EXPORT *CreateInterface( const char *interface, int *retval ) return &g_VFileSystem009; } + if( !Q_strcmp( interface, FS_API_CREATEINTERFACE_TAG )) + { + // return a copy, to disallow overriding + static fs_api_t copy = { 0 }; + + if( !copy.InitStdio ) + memcpy( ©, &g_api, sizeof( copy )); + + if( retval ) *retval = 0; + return © + } + if( retval ) *retval = 1; return NULL; } diff --git a/filesystem/filesystem.c b/filesystem/filesystem.c index 66a9b5ae..5e9e3926 100644 --- a/filesystem/filesystem.c +++ b/filesystem/filesystem.c @@ -2868,7 +2868,7 @@ static qboolean FS_InitInterface( int version, fs_interface_t *engfuncs ) return true; } -static fs_api_t g_api = +fs_api_t g_api = { FS_InitStdio, FS_ShutdownStdio, diff --git a/filesystem/filesystem.h b/filesystem/filesystem.h index 6a7a1f4c..54eac76c 100644 --- a/filesystem/filesystem.h +++ b/filesystem/filesystem.h @@ -29,6 +29,7 @@ extern "C" #endif // __cplusplus #define FS_API_VERSION 1 // not stable yet! +#define FS_API_CREATEINTERFACE_TAG "XashFileSystem001" // follow FS_API_VERSION!!! // search path flags enum diff --git a/filesystem/filesystem_internal.h b/filesystem/filesystem_internal.h index 3cf5a462..5f11f52f 100644 --- a/filesystem/filesystem_internal.h +++ b/filesystem/filesystem_internal.h @@ -86,6 +86,7 @@ extern qboolean fs_ext_path; extern char fs_rodir[MAX_SYSPATH]; extern char fs_rootdir[MAX_SYSPATH]; extern char fs_writedir[MAX_SYSPATH]; +extern fs_api_t g_api; #define GI FI.GameInfo