engine: Haiku BeGameLauncher support

This commit is contained in:
exstrim401 2021-06-05 19:44:34 +05:00 committed by Alibek Omarov #SupportRMS
parent 6063149b93
commit a89f9fa181
3 changed files with 79 additions and 1 deletions

View File

@ -1390,6 +1390,9 @@ void FS_Rescan( void )
{
const char *str;
const int extrasFlags = FS_NOWRITE_PATH | FS_CUSTOM_PATH;
#if XASH_HAIKU
char *dir;
#endif
Con_Reportf( "FS_Rescan( %s )\n", GI->title );
FS_ClearSearchPath();
@ -1399,6 +1402,11 @@ void FS_Rescan( void )
FS_AddPak_Fullpath( va( "%sextras.pak", SDL_GetBasePath() ), NULL, extrasFlags );
FS_AddPak_Fullpath( va( "%sextras_%s.pak", SDL_GetBasePath(), GI->gamefolder ), NULL, extrasFlags );
}
#elif XASH_HAIKU
if( ( dir = getenv( "XASH3D_MIRRORDIR" ) ) )
FS_AddPak_Fullpath( va( "%s/extras.pak", dir ), NULL, extrasFlags );
if( ( dir = getenv( "XASH3D_BASEDIR" ) ) )
FS_AddPak_Fullpath( va( "%s/%s/extras.pak", dir , GI->gamefolder ), NULL, extrasFlags );
#else
str = getenv( "XASH3D_EXTRAS_PAK1" );
if( COM_CheckString( str ) )

View File

@ -79,6 +79,9 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
{
dll_user_t *hInst = NULL;
void *pHandle = NULL;
#if XASH_HAIKU
const char *libdir;
#endif
COM_ResetLibraryError();
@ -87,6 +90,24 @@ void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean d
return Platform_POSIX_LoadLibrary( dllname );
#endif
#if XASH_HAIKU
// First look for libraries in the mirror directory
libdir = getenv( "XASH3D_MIRRORDIR" );
if( libdir ) {
char path[MAX_SYSPATH];
char game[MAX_SYSPATH] = { 0 };
if( GI && !Q_strstr( dllname, "menu" ) )
Q_snprintf( game, MAX_SYSPATH, "/%s", GI->gamefolder );
Q_snprintf( path, MAX_SYSPATH, "%s%s/%s", libdir, game, dllname );
pHandle = dlopen( path, RTLD_NOW );
if( pHandle )
return pHandle;
COM_PushLibraryError( dlerror() );
}
// Then through FS_FindLibrary() function in the gamebase directory
#endif
// platforms where gameinfo mechanism is working goes here
// and use FS_FindLibrary
hInst = FS_FindLibrary( dllname, directpath );

View File

@ -20,8 +20,14 @@ GNU General Public License for more details.
#include <stdlib.h>
#include <stdarg.h>
#if defined(__APPLE__) || defined(__unix__) || defined(__HAIKU__)
#if defined(__APPLE__) || defined(__unix__)
#define XASHLIB "libxash." OS_LIB_EXT
#elif __HAIKU__
#include <libgen.h>
#define XASHLIB "libxash." OS_LIB_EXT
#define E_GAME "XASH3D_GAME"
#define E_BASEDIR "XASH3D_BASEDIR"
#define E_MIRRORDIR "XASH3D_MIRRORDIR"
#elif _WIN32
#if !__MINGW32__ && _MSC_VER >= 1200
#define USE_WINMAIN
@ -87,7 +93,15 @@ static const char *GetStringLastError()
static void Sys_LoadEngine( void )
{
#ifdef __HAIKU__
char path[PATH_MAX];
char *engine = getenv( E_MIRRORDIR );
strncpy( path, engine, PATH_MAX );
strncat( path, "/"XASHLIB, PATH_MAX );
if(( hEngine = LoadLibrary( path )) == NULL )
#else
if(( hEngine = LoadLibrary( XASHLIB )) == NULL )
#endif
{
Xash_Error("Unable to load the " XASHLIB ": %s", dlerror() );
}
@ -138,7 +152,13 @@ _inline int Sys_Start( void )
changeGame = Sys_ChangeGame;
#endif
#ifdef __HAIKU__
const char* game = getenv( E_GAME );
ret = Xash_Main( szArgc, szArgv, game, 0, changeGame );
#else
ret = Xash_Main( szArgc, szArgv, GAME_PATH, 0, changeGame );
#endif
Sys_UnloadEngine();
return ret;
@ -150,6 +170,35 @@ int main( int argc, char **argv )
szArgc = argc;
szArgv = argv;
#ifdef __HAIKU__
// To make it able to start from Deskbar
chdir( dirname( argv[0] ) );
char path[PATH_MAX];
getcwd( path, PATH_MAX );
const char *game = getenv( E_GAME );
if( !game )
setenv( E_GAME, GAME_PATH, 1 );
const char *basedir = getenv( E_BASEDIR );
if( !basedir )
setenv( E_BASEDIR, path, 1 );
const char *mirrordir = getenv( E_MIRRORDIR );
// The mirror "extras/" directory structure for Haiku OS which is needeed for the HPGK-package:
// extras.pak
// libmenu.so
// libxash.so
// valve/
// cl_dlls/
// client_haiku_amd64.so
// dlls/
// hl_haiku_amd64.so
if( !mirrordir )
{
strncpy( path, getenv( E_BASEDIR ), PATH_MAX );
strncat( path, "/extras", PATH_MAX );
setenv( E_MIRRORDIR, path, 1 );
}
#endif
return Sys_Start();
}
#else