engine: common: add host.default_gamedir containing gamedir passed to us from game launcher

This commit is contained in:
Alibek Omarov
2026-04-03 03:49:23 +05:00
parent e8ef7ad60c
commit 8e450d869b
9 changed files with 29 additions and 23 deletions

View File

@@ -344,6 +344,9 @@ typedef struct host_parm_s
string gamedll; string gamedll;
string clientlib; string clientlib;
string menulib; string menulib;
// default game directory, passed to us from game launcher
string default_gamedir;
} host_parm_t; } host_parm_t;
extern host_parm_t host; extern host_parm_t host;
@@ -389,7 +392,7 @@ void Mem_Stats_f( void );
// //
// filesystem_engine.c // filesystem_engine.c
// //
void FS_Init( const char *basedir ); void FS_Init( void );
void FS_Shutdown( void ); void FS_Shutdown( void );
void *FS_GetNativeObject( const char *obj ); void *FS_GetNativeObject( const char *obj );
int FS_Close( file_t *file ); int FS_Close( file_t *file );

View File

@@ -328,7 +328,7 @@ static qboolean FS_DetermineReadOnlyRootDirectory( char *out, size_t size )
FS_Init FS_Init
================ ================
*/ */
void FS_Init( const char *basedir ) void FS_Init( void )
{ {
string gamedir; string gamedir;
char rodir[MAX_OSPATH], rootdir[MAX_OSPATH]; char rodir[MAX_OSPATH], rootdir[MAX_OSPATH];
@@ -352,7 +352,7 @@ void FS_Init( const char *basedir )
if( env ) if( env )
Q_strncpy( gamedir, env, sizeof( gamedir )); Q_strncpy( gamedir, env, sizeof( gamedir ));
else else
Q_strncpy( gamedir, basedir, sizeof( gamedir )); // gamedir == basedir Q_strncpy( gamedir, host.default_gamedir, sizeof( gamedir )); // gamedir == basedir
} }
FS_LoadProgs(); FS_LoadProgs();
@@ -364,7 +364,7 @@ void FS_Init( const char *basedir )
// and this better be reworked at some point // and this better be reworked at some point
g_fsapi.SetCurrentDirectory( rootdir ); g_fsapi.SetCurrentDirectory( rootdir );
if( !g_fsapi.InitStdio( true, rootdir, basedir, gamedir, rodir )) if( !g_fsapi.InitStdio( true, rootdir, host.default_gamedir, gamedir, rodir ))
{ {
Sys_Error( "Can't init filesystem_stdio!\n" ); Sys_Error( "Can't init filesystem_stdio!\n" );
return; return;

View File

@@ -892,6 +892,7 @@ static void Host_InitCommon( int argc, char **argv, const char *progname, qboole
host.config_executed = false; host.config_executed = false;
host.status = HOST_INIT; // initialzation started host.status = HOST_INIT; // initialzation started
host.type = HOST_DEDICATED; // predict state host.type = HOST_DEDICATED; // predict state
Q_strncpy( host.default_gamedir, basedir, sizeof( host.default_gamedir ));
#ifndef XASH_DEDICATED #ifndef XASH_DEDICATED
if( !Sys_CheckParm( "-dedicated" )) if( !Sys_CheckParm( "-dedicated" ))
@@ -964,8 +965,8 @@ static void Host_InitCommon( int argc, char **argv, const char *progname, qboole
#if XASH_DEDICATED #if XASH_DEDICATED
Platform_SetupSigtermHandling(); Platform_SetupSigtermHandling();
#endif #endif
Platform_Init( Host_IsDedicated( ) || developer >= DEV_EXTENDED, basedir ); Platform_Init( Host_IsDedicated( ) || developer >= DEV_EXTENDED );
FS_Init( basedir ); FS_Init();
// print current developer level to simplify processing users feedback // print current developer level to simplify processing users feedback
if( developer > 0 ) if( developer > 0 )

View File

@@ -21,9 +21,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "dlfcn.h" #include "dlfcn.h"
#ifndef XASH_GAMEDIR
#define XASH_GAMEDIR "valve" // !!! Replace with your default (base) game directory !!!
#endif
#define XASHLIB "@rpath/libxash.dylib" #define XASHLIB "@rpath/libxash.dylib"
@@ -331,4 +328,4 @@ int IOS_GetArgs( char ***out )
{ {
*out = szArgv; *out = szArgv;
return szArgc; return szArgc;
} }

View File

@@ -14,11 +14,11 @@ GNU General Public License for more details.
*/ */
#include <string.h> #include <string.h>
#include <SDL.h> #include <SDL.h>
#include <dlfcn.h>
#include "crtlib.h" #include "crtlib.h"
#include "fscallback.h"
#include "library.h" #include "library.h"
#include "platform/ios/lib_ios.h" #include "platform/ios/lib_ios.h"
#include <dlfcn.h> #include "common.h"
#define EXT_LENGTH 5 #define EXT_LENGTH 5
@@ -55,7 +55,7 @@ void *IOS_LoadLibrary( const char *dllname )
if( !postfix ) if( !postfix )
{ {
if ( Q_strcmp(FS_Gamedir(), "valve" ) ) if ( Q_strcmp(FS_Gamedir(), host.default_gamedir ) )
{ {
postfix = FS_Gamedir( ); postfix = FS_Gamedir( );
} }

View File

@@ -66,10 +66,15 @@ qboolean Platform_DebuggerPresent( void )
tracer_pid = (const byte*)Q_strstr( buf, TracerPid ); tracer_pid = (const byte*)Q_strstr( buf, TracerPid );
if( !tracer_pid ) if( !tracer_pid )
return false; return false;
//printf( "%s\n", tracer_pid ); //printf( "%s\n", tracer_pid );
while( *tracer_pid < '0' || *tracer_pid > '9' )
while(( *tracer_pid < '0' ) || ( *tracer_pid > '9' ))
{
if( *tracer_pid++ == '\n' ) if( *tracer_pid++ == '\n' )
return false; return false;
}
//printf( "%s\n", tracer_pid ); //printf( "%s\n", tracer_pid );
return !!Q_atoi( (const char*)tracer_pid ); return !!Q_atoi( (const char*)tracer_pid );
} }

View File

@@ -58,7 +58,7 @@ char *Posix_Input( void );
#endif #endif
#if XASH_SDL #if XASH_SDL
void SDLash_Init( const char *basedir ); void SDLash_Init( void );
void SDLash_Shutdown( void ); void SDLash_Shutdown( void );
void SDLash_NanoSleep( int nsec ); void SDLash_NanoSleep( int nsec );
#endif #endif
@@ -111,7 +111,7 @@ void Linux_SetTimer( float time );
int Linux_GetProcessID( void ); int Linux_GetProcessID( void );
#endif #endif
static inline void Platform_Init( qboolean con_showalways, const char *basedir ) static inline void Platform_Init( qboolean con_showalways )
{ {
#if XASH_POSIX #if XASH_POSIX
// daemonize as early as possible, because we need to close our file descriptors // daemonize as early as possible, because we need to close our file descriptors
@@ -119,7 +119,7 @@ static inline void Platform_Init( qboolean con_showalways, const char *basedir )
#endif #endif
#if XASH_SDL #if XASH_SDL
SDLash_Init( basedir ); SDLash_Init( );
#endif #endif
#if XASH_ANDROID #if XASH_ANDROID

View File

@@ -79,20 +79,23 @@ static void SDLCALL SDLash_LogOutputFunction( void *userdata, int category, SDL_
case SDL_LOG_PRIORITY_INFO: case SDL_LOG_PRIORITY_INFO:
str = S_NOTE; str = S_NOTE;
break; break;
default:
str = "";
break;
} }
Con_Reportf( "%s" S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", str, SDLash_CategoryToString( category ), message ); Con_Reportf( "%s" S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", str, SDLash_CategoryToString( category ), message );
} }
void SDLash_Init( const char *basedir ) void SDLash_Init( void )
{ {
#if XASH_APPLE #if XASH_IOS
char *path = SDL_GetBasePath(); char *path = SDL_GetBasePath();
if( path != NULL ) if( path != NULL )
{ {
char buf[MAX_VA_STRING]; char buf[MAX_VA_STRING];
Q_snprintf( buf, sizeof( buf ), "%s%s/extras.pk3", path, basedir ); Q_snprintf( buf, sizeof( buf ), "%s%s/extras.pk3", path, host.default_gamedir );
setenv( "XASH3D_EXTRAS_PAK1", buf, true ); setenv( "XASH3D_EXTRAS_PAK1", buf, true );
} }
#endif #endif

View File

@@ -27,9 +27,6 @@ extern fs_globals_t *FI;
#define FS_Gamedir() GI->gamefolder #define FS_Gamedir() GI->gamefolder
#define FS_Title() GI->title #define FS_Title() GI->title
#define FS_InitStdio (*g_fsapi.InitStdio)
#define FS_ShutdownStdio (*g_fsapi.ShutdownStdio)
// search path utils // search path utils
#define FS_Rescan (*g_fsapi.Rescan) #define FS_Rescan (*g_fsapi.Rescan)
#define FS_ClearSearchPath (*g_fsapi.ClearSearchPath) #define FS_ClearSearchPath (*g_fsapi.ClearSearchPath)