From 12f414860896040382b4ad7afe89d659754888ca Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 13:20:36 +0300 Subject: [PATCH 1/9] Allow installation to global directories. This commit now install everything with FHS-compliant structure (/usr/local/bin/hl2_launcher and lib/libtier0.so lib/lib...). Binaries and libraries now uses rpath and not depends on local bin/ directory unlike original Valve's Source. --- appframework/posixapp.cpp | 2 +- dedicated_main/main.cpp | 12 +- engine/cdll_engine_int.cpp | 16 +++ engine/sys_dll.cpp | 16 ++- filesystem/basefilesystem.cpp | 13 +-- game/client/wscript | 4 +- game/server/wscript | 4 +- launcher_main/main.cpp | 10 +- materialsystem/cmaterialsystem.cpp | 2 - public/filesystem_init.cpp | 174 ++--------------------------- public/filesystem_init.h | 5 - scripts/tests-macos-amd64.sh | 2 +- scripts/tests-ubuntu-amd64.sh | 2 +- scripts/tests-ubuntu-i386.sh | 2 +- tier1/interface.cpp | 24 +--- tier1/wscript | 2 +- waf | 2 +- wscript | 27 ++--- 18 files changed, 79 insertions(+), 240 deletions(-) diff --git a/appframework/posixapp.cpp b/appframework/posixapp.cpp index ee4c69534..722675dc5 100644 --- a/appframework/posixapp.cpp +++ b/appframework/posixapp.cpp @@ -118,7 +118,7 @@ bool CSteamApplication::Create( ) m_pFileSystem = (IFileSystem*)AddSystem( fileSystemModule, FILESYSTEM_INTERFACE_VERSION ); if ( !m_pFileSystem ) { - Error( "Unable to load %s", pFileSystemDLL ); + Error( "Unable to load %s\n", pFileSystemDLL ); return false; } diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp index 418c857cf..d38f73f8d 100644 --- a/dedicated_main/main.cpp +++ b/dedicated_main/main.cpp @@ -188,6 +188,7 @@ static void WaitForDebuggerConnect( int argc, char *argv[], int time ) int main( int argc, char *argv[] ) { +#if 0 // Must add 'bin' to the path.... char* pPath = getenv("LD_LIBRARY_PATH"); char szBuffer[4096]; @@ -203,14 +204,11 @@ int main( int argc, char *argv[] ) { printf( "%s\n", strerror(errno) ); } - void *tier0 = dlopen( "libtier0" DLL_EXT_STRING, RTLD_NOW ); - void *vstdlib = dlopen( "libvstdlib" DLL_EXT_STRING, RTLD_NOW ); - - const char *pBinaryName = "bin/dedicated" DLL_EXT_STRING; +#endif - void *dedicated = dlopen( pBinaryName, RTLD_NOW ); + void *dedicated = dlopen( "libdedicated", RTLD_NOW ); if ( !dedicated ) - dedicated = dlopen( "bin/libdedicated" DLL_EXT_STRING, RTLD_NOW ); + dedicated = dlopen( "dedicated" DLL_EXT_STRING, RTLD_NOW ); if ( !dedicated ) { @@ -228,7 +226,5 @@ int main( int argc, char *argv[] ) ret = dedicated_main( argc,argv ); dlclose( dedicated ); - dlclose( vstdlib ); - dlclose( tier0 ); } #endif diff --git a/engine/cdll_engine_int.cpp b/engine/cdll_engine_int.cpp index f986a207b..f70bebe01 100644 --- a/engine/cdll_engine_int.cpp +++ b/engine/cdll_engine_int.cpp @@ -1715,6 +1715,7 @@ bool ClientDLL_Load() { Assert ( !g_ClientDLLModule ); +#if 0 // Check the signature on the client dll. If this fails we load it anyway but put this client // into insecure mode so it won't connect to secure servers and get VAC banned if ( !Host_AllowLoadModule( "client.dll", "GAMEBIN", true ) ) @@ -1723,8 +1724,23 @@ bool ClientDLL_Load() Host_DisallowSecureServers(); Host_AllowLoadModule( "client.dll","GAMEBIN", true ); } +#endif +#if 0 g_ClientDLLModule = g_pFileSystem->LoadModule( "client", "GAMEBIN", false ); +#else + char clientPath[MAX_PATH]; + const char *modName = CommandLine()->ParmValue("-game"); + + Q_snprintf(clientPath, MAX_PATH, "%s/libclient", modName); + g_ClientDLLModule = Sys_LoadModule(clientPath); + + if (!g_ClientDLLModule) + { + Q_snprintf(clientPath, MAX_PATH, "%s/client", modName); + g_ClientDLLModule = Sys_LoadModule(clientPath); + } +#endif if ( g_ClientDLLModule ) { g_ClientFactory = Sys_GetFactory( g_ClientDLLModule ); diff --git a/engine/sys_dll.cpp b/engine/sys_dll.cpp index 1a041f902..df25fdd19 100644 --- a/engine/sys_dll.cpp +++ b/engine/sys_dll.cpp @@ -464,7 +464,7 @@ void Sys_Error_Internal( bool bMinidump, const char *error, va_list argsList ) // Doing this doesn't quite work the way we want because there is no "crashing" thread // and we see "No thread was identified as the cause of the crash; No signature could be created because we do not know which thread crashed" on the back end //SteamAPI_WriteMiniDump( 0, NULL, build_number() ); - printf("\n ##### Sys_Error: %s", text ); + printf("\n ##### Sys_Error: %s\n", text ); fflush(stdout ); raise(SIGTRAP); @@ -1117,12 +1117,12 @@ void Sys_ShutdownGame( void ) CreateInterfaceFn g_ServerFactory; - #pragma optimize( "g", off ) static bool LoadThisDll( char *szDllFilename, bool bIsServerOnly ) { CSysModule *pDLL = NULL; +#if 0 // check signature, don't let users with modified binaries connect to secure servers, they will get VAC banned if ( !Host_AllowLoadModule( szDllFilename, "GAMEBIN", true, bIsServerOnly ) ) { @@ -1134,6 +1134,16 @@ static bool LoadThisDll( char *szDllFilename, bool bIsServerOnly ) // ensures that the game.dll is running under Steam // this will have to be undone when we want mods to be able to run if ((pDLL = g_pFileSystem->LoadModule(szDllFilename, "GAMEBIN", false)) == NULL) +#endif + char dllPath[MAX_PATH]; + const char *modName = CommandLine()->ParmValue("-game"); + Q_snprintf(dllPath, MAX_PATH, "%s/lib%s", modName, szDllFilename); + if (!(pDLL = Sys_LoadModule(dllPath))) + { + Q_snprintf(dllPath, MAX_PATH, "%s/%s",modName, szDllFilename); + pDLL = Sys_LoadModule(dllPath); + } + if (!pDLL) { ConMsg("Failed to load %s\n", szDllFilename); goto IgnoreThisDLL; @@ -1255,7 +1265,7 @@ void LoadEntityDLLs( const char *szBaseDir, bool bIsServerOnly ) if ( serverGameDLL ) { - Msg("server%s loaded for \"%s\"\n", DLL_EXT_STRING, (char *)serverGameDLL->GetGameDescription()); + Msg("server" DLL_EXT_STRING " loaded for \"%s\"\n", (char *)serverGameDLL->GetGameDescription()); } } diff --git a/filesystem/basefilesystem.cpp b/filesystem/basefilesystem.cpp index 26bb8372a..38d2409e8 100644 --- a/filesystem/basefilesystem.cpp +++ b/filesystem/basefilesystem.cpp @@ -5057,20 +5057,17 @@ CSysModule *CBaseFileSystem::LoadModule( const char *pFileName, const char *pPat if ( FilterByPathID( &m_SearchPaths[i], lookup ) ) continue; - Q_snprintf( tempPathID, sizeof(tempPathID), "%s%s", m_SearchPaths[i].GetPathString(), pFileName ); // append the path to this dir. - pModule = Sys_LoadModule( tempPathID ); - if ( pModule ) - { - // we found the binary in one of our search paths - return pModule; - } - #ifdef POSIX Q_snprintf( tempPathID, sizeof(tempPathID), "%slib%s", m_SearchPaths[i].GetPathString(), pFileName ); // append the path to this dir. pModule = Sys_LoadModule( tempPathID ); if ( pModule ) return pModule; #endif + + Q_snprintf( tempPathID, sizeof(tempPathID), "%s%s", m_SearchPaths[i].GetPathString(), pFileName ); // append the path to this dir. + pModule = Sys_LoadModule( tempPathID ); + if ( pModule ) + return pModule; } #endif diff --git a/game/client/wscript b/game/client/wscript index c454d535c..454f66b70 100755 --- a/game/client/wscript +++ b/game/client/wscript @@ -65,9 +65,9 @@ def build(bld): 'ZLIB' ] - install_path = bld.env.PREFIX + install_path = bld.env.LIBDIR if bld.env.DEST_OS != 'android': - install_path += '/'+bld.env.GAMES+'/bin' + install_path += '/'+bld.env.GAMES source = [ 'in_touch.cpp' ] if bld.env.DEST_OS == 'win32': diff --git a/game/server/wscript b/game/server/wscript index 1b6d834d0..8200e7549 100755 --- a/game/server/wscript +++ b/game/server/wscript @@ -59,9 +59,9 @@ def build(bld): if bld.env.DEST_OS == 'win32': libs += ['USER32'] - install_path = bld.env.PREFIX + install_path = bld.env.LIBDIR if bld.env.DEST_OS != 'android': - install_path += '/'+bld.env.GAMES+'/bin' + install_path += '/'+bld.env.GAMES source = game["sources"] + ['../../public/tier0/memoverride.cpp'] includes += game["includes"] diff --git a/launcher_main/main.cpp b/launcher_main/main.cpp index bc075b945..0e7201d26 100644 --- a/launcher_main/main.cpp +++ b/launcher_main/main.cpp @@ -216,6 +216,7 @@ static void WaitForDebuggerConnect( int argc, char *argv[], int time ) int main( int argc, char *argv[] ) { +#if 0 char ld_path[4196]; char *path = "bin/"; char *ld_env; @@ -234,13 +235,14 @@ int main( int argc, char *argv[] ) setenv("NO_EXECVE_AGAIN", "1", 1); execve(argv[0], argv, environ); } +#endif - void *launcher = dlopen( "bin/liblauncher" DLL_EXT_STRING, RTLD_NOW ); + void *launcher = dlopen( "liblauncher" DLL_EXT_STRING, RTLD_NOW ); if ( !launcher ) + { fprintf( stderr, "%s\nFailed to load the launcher\n", dlerror() ); - - if( !launcher ) - launcher = dlopen( "bin/launcher" DLL_EXT_STRING, RTLD_NOW ); + launcher = dlopen( "launcher" DLL_EXT_STRING, RTLD_NOW ); + } if ( !launcher ) { diff --git a/materialsystem/cmaterialsystem.cpp b/materialsystem/cmaterialsystem.cpp index e7870712f..5a2a98e7c 100644 --- a/materialsystem/cmaterialsystem.cpp +++ b/materialsystem/cmaterialsystem.cpp @@ -3102,8 +3102,6 @@ void CMaterialSystem::ResetTempHWMemory( bool bExitingLevel ) //----------------------------------------------------------------------------- void CMaterialSystem::CacheUsedMaterials( ) { - printf("Cache materials\n"); - g_pShaderAPI->EvictManagedResources(); for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index d309efcd3..e7738b002 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -305,96 +305,13 @@ static bool Sys_GetExecutableName( char *out, int len ) return true; } -bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) -{ -#ifdef ANDROID - Q_snprintf( exedir, exeDirLen, "%s", getenv("APP_LIB_PATH") ); -#else - exedir[0] = 0; - - if ( s_bUseVProjectBinDir ) - { - const char *pProject = GetVProjectCmdLineValue(); - if ( !pProject ) - { - // Check their registry. - pProject = getenv( GAMEDIR_TOKEN ); - } - if ( pProject ) - { - Q_snprintf( exedir, exeDirLen, "%s%c..%cbin", pProject, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR ); - return true; - } - return false; - } - - if ( !Sys_GetExecutableName( exedir, exeDirLen ) ) - return false; - Q_StripFilename( exedir ); - - if ( IsX360() ) - { - // The 360 can have its exe and dlls reside on different volumes - // use the optional basedir as the exe dir - if ( CommandLine()->FindParm( "-basedir" ) ) - { - strcpy( exedir, CommandLine()->ParmValue( "-basedir", "" ) ); - } - } - - Q_FixSlashes( exedir ); - - const char* libDir = "bin"; - - // Return the bin directory as the executable dir if it's not in there - // because that's really where we're running from... - char ext[MAX_PATH]; - Q_StrRight( exedir, 4, ext, sizeof( ext ) ); - if ( ext[0] != CORRECT_PATH_SEPARATOR || Q_stricmp( ext+1, libDir ) != 0 ) - { - Q_strncat( exedir, CORRECT_PATH_SEPARATOR_S, exeDirLen, COPY_ALL_CHARACTERS ); - Q_strncat( exedir, libDir, exeDirLen, COPY_ALL_CHARACTERS ); - Q_FixSlashes( exedir ); - } -#endif - - return true; -} - static bool FileSystem_GetBaseDir( char *baseDir, int baseDirLen ) { #ifdef ANDROID strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); return true; #else - if ( FileSystem_GetExecutableDir( baseDir, baseDirLen ) ) - { - Q_StripFilename( baseDir ); - return true; - } - - return false; -#endif -} - -void LaunchVConfig() -{ -#if defined( _WIN32 ) && !defined( _X360 ) - char vconfigExe[MAX_PATH]; - FileSystem_GetExecutableDir( vconfigExe, sizeof( vconfigExe ) ); - Q_AppendSlash( vconfigExe, sizeof( vconfigExe ) ); - Q_strncat( vconfigExe, "vconfig.exe", sizeof( vconfigExe ), COPY_ALL_CHARACTERS ); - - char *argv[] = - { - vconfigExe, - "-allowdebug", - NULL - }; - - _spawnv( _P_NOWAIT, vconfigExe, argv ); -#elif defined( _X360 ) - Msg( "Launching vconfig.exe not supported\n" ); + return getcwd(baseDir, baseDirLen) != NULL; #endif } @@ -412,13 +329,6 @@ FSReturnCode_t SetupFileSystemError( bool bRunVConfig, FSReturnCode_t retVal, co Warning( "%s\n", g_FileSystemError ); - // Run vconfig? - // Don't do it if they specifically asked for it not to, or if they manually specified a vconfig with -game or -vproject. - if ( bRunVConfig && g_FileSystemErrorMode == FS_ERRORMODE_VCONFIG && !CommandLine()->FindParm( CMDLINEOPTION_NOVCONFIG ) && !GetVProjectCmdLineValue() ) - { - LaunchVConfig(); - } - if ( g_FileSystemErrorMode == FS_ERRORMODE_AUTO || g_FileSystemErrorMode == FS_ERRORMODE_VCONFIG ) { Error( "%s\n", g_FileSystemError ); @@ -1012,32 +922,6 @@ bool DoesPathExistAlready( const char *pPathEnvVar, const char *pTestPath ) } -FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ) -{ - steamCfgPath[0] = 0; - char executablePath[MAX_PATH]; - if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) - { - return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); - } - Q_strncpy( steamCfgPath, executablePath, steamCfgPathLen ); - while ( 1 ) - { - if ( DoesFileExistIn( steamCfgPath, "steam.cfg" ) ) - break; - - if ( !Q_StripLastDir( steamCfgPath, steamCfgPathLen) ) - { - // the file isnt found, thats ok, its not mandatory - return FS_OK; - } - } - Q_AppendSlash( steamCfgPath, steamCfgPathLen ); - Q_strncat( steamCfgPath, "steam.cfg", steamCfgPathLen, COPY_ALL_CHARACTERS ); - - return FS_OK; -} - void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CSteamEnvVars &steamEnvVars ) { // Always inherit the Steam user if it's already set, since it probably means we (or the @@ -1092,19 +976,7 @@ void SetSteamUserPassphrase( KeyValues *pSteamInfo, CSteamEnvVars &steamEnvVars FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) { - pFileSystem->RemoveSearchPaths( "EXECUTABLE_PATH" ); - - char executablePath[MAX_PATH]; - if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) - return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); - - pFileSystem->AddSearchPath( executablePath, "EXECUTABLE_PATH" ); - - if ( !FileSystem_GetBaseDir( executablePath, sizeof( executablePath ) ) ) - return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); - - pFileSystem->AddSearchPath( executablePath, "BASE_PATH" ); - + // Er2: Deprecated. Used only in hammer return FS_OK; } @@ -1113,43 +985,14 @@ FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) //----------------------------------------------------------------------------- FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLen, bool &bSteam ) { -#if 0 - bSteam = false; - - // Inside of here, we don't have a filesystem yet, so we have to assume that the filesystem_stdio or filesystem_steam - // is in this same directory with us. - char executablePath[MAX_PATH]; - if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) - return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); - // Assume we'll use local files - Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); - - #if !defined( _X360 ) - - // Use filsystem_steam if it exists? - #if defined( OSX ) || defined( LINUX ) - struct stat statBuf; - #endif - if ( - #if defined( OSX ) || defined( LINUX ) - stat( pFileSystemDLL, &statBuf ) != 0 - #else - _access( pFileSystemDLL, 0 ) != 0 - #endif - ) { - Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_steam" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); - bSteam = true; - } - #endif +#ifdef POSIX + Q_strncpy( pFileSystemDLL, "libfilesystem_stdio" DLL_EXT_STRING, nMaxLen ); #else - char executablePath[MAX_PATH]; - if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) - return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); - - // Assume we'll use local files - Q_snprintf( pFileSystemDLL, nMaxLen, "%s%clibfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); + Q_strncpy( pFileSystemDLL, "filesystem_stdio" DLL_EXT_STRING, nMaxLen ); +#endif +#if 0 #if !defined( _X360 ) // Use filsystem_steam if it exists? #if defined( OSX ) || defined( LINUX ) @@ -1162,10 +1005,9 @@ FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLe _access( pFileSystemDLL, 0 ) != 0 #endif ) { - Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); + Q_snprintf( pFileSystemDLL, nMaxLen, "filesystem_stdio" DLL_EXT_STRING ); } #endif - #endif return FS_OK; diff --git a/public/filesystem_init.h b/public/filesystem_init.h index 9274a5cb1..dbeba00b1 100644 --- a/public/filesystem_init.h +++ b/public/filesystem_init.h @@ -199,16 +199,11 @@ void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *sz // See FSErrorMode_t. If you don't specify one here, then the default is FS_ERRORMODE_VCONFIG. void FileSystem_SetErrorMode( FSErrorMode_t errorMode = FS_ERRORMODE_VCONFIG ); -bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ); - // Clear SteamAppUser, SteamUserPassphrase, and SteamAppId from this process's environment. // TODO: always do this after LoadFileSysteModule.. there's no reason it should be // in the environment. void FileSystem_ClearSteamEnvVars(); -// Find the steam.cfg above you for optional stuff -FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ); - // Returns the last error. const char *FileSystem_GetLastErrorString(); diff --git a/scripts/tests-macos-amd64.sh b/scripts/tests-macos-amd64.sh index ff4e46b27..47faea23a 100755 --- a/scripts/tests-macos-amd64.sh +++ b/scripts/tests-macos-amd64.sh @@ -4,4 +4,4 @@ git submodule init && git submodule update ./waf configure -T release --sanitize=address,undefined --disable-warns --tests -8 --prefix=out/ $* && ./waf install && cd out && -DYLD_LIBRARY_PATH=bin/ ./unittest || exit 1 +./bin/unittest || exit 1 diff --git a/scripts/tests-ubuntu-amd64.sh b/scripts/tests-ubuntu-amd64.sh index 1cef058e9..bdc5bc752 100755 --- a/scripts/tests-ubuntu-amd64.sh +++ b/scripts/tests-ubuntu-amd64.sh @@ -7,4 +7,4 @@ sudo apt-get install -y libbz2-dev ./waf configure -T release --sanitize=address,undefined --disable-warns --tests --prefix=out/ --64bits $* && ./waf install && cd out && -LD_LIBRARY_PATH=bin/ ./unittest +./bin/unittest diff --git a/scripts/tests-ubuntu-i386.sh b/scripts/tests-ubuntu-i386.sh index f14fc3616..f310b258d 100755 --- a/scripts/tests-ubuntu-i386.sh +++ b/scripts/tests-ubuntu-i386.sh @@ -8,4 +8,4 @@ sudo apt-get install -y g++-multilib gcc-multilib libbz2-dev:i386 PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig ./waf configure -T release --sanitize=address,undefined --disable-warns --tests --prefix=out/ $* && ./waf install && cd out && -LD_LIBRARY_PATH=bin/ ./unittest +./bin/unittest diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 47fda8f94..cd9f968d8 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -269,12 +269,6 @@ static bool s_bRunningWithDebugModules = false; #ifdef POSIX -#ifdef ANDROID -#define DEFAULT_LIB_PATH "" -#else -#define DEFAULT_LIB_PATH "bin/" -#endif - bool foundLibraryWithPrefix( char *pModuleAbsolutePath, size_t AbsolutePathSize, const char *pPath, const char *pModuleName ) { char str[1024]; @@ -283,21 +277,9 @@ bool foundLibraryWithPrefix( char *pModuleAbsolutePath, size_t AbsolutePathSize, bool bFound = false; struct stat statBuf; - Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/" DEFAULT_LIB_PATH "lib%s", pPath, str); + Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/lib%s", pPath, str); bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; - if( !bFound ) - { - Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/" DEFAULT_LIB_PATH "%s", pPath, str); - bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; - } - - if( !bFound ) - { - Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/lib%s", pPath, str); - bFound |= stat(pModuleAbsolutePath, &statBuf) == 0; - } - if( !bFound ) { Q_snprintf(pModuleAbsolutePath, AbsolutePathSize, "%s/%s", pPath, str); @@ -321,7 +303,7 @@ CSysModule *Sys_LoadModule( const char *pModuleName, Sys_Flags flags /* = SYS_NO // prior to the call to this routine. char szCwd[1024]; #ifdef POSIX - char szModuleName[1024] = { 0 }; + char szModuleName[1024] = { '\0' }; #endif HMODULE hDLL = NULL; @@ -367,7 +349,7 @@ CSysModule *Sys_LoadModule( const char *pModuleName, Sys_Flags flags /* = SYS_NO } #elif defined( POSIX ) - if( !foundLibraryWithPrefix(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), szCwd, pModuleName) ) + if( !foundLibraryWithPrefix(szAbsoluteModuleName, sizeof(szAbsoluteModuleName), LIBDIR, pModuleName) ) { Warning("Can't find module - %s\n", pModuleName); return reinterpret_cast(hDLL); diff --git a/tier1/wscript b/tier1/wscript index 0a5f684b5..6bdf8758c 100755 --- a/tier1/wscript +++ b/tier1/wscript @@ -79,7 +79,7 @@ def build(bld): '../common' ] - defines = [] + defines = ['LIBDIR="%s"' % bld.env.LIBDIR] libs = [] if bld.env.DEST_OS == 'win32': diff --git a/waf b/waf index b2f4c6f49..f754d112d 100755 --- a/waf +++ b/waf @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # encoding: latin-1 # Thomas Nagy, 2005-2018 # diff --git a/wscript b/wscript index 352e3209b..5c0f62365 100644 --- a/wscript +++ b/wscript @@ -1,4 +1,5 @@ #! /usr/bin/env python +# vim: noexpandtab # encoding: utf-8 # nillerusr @@ -461,6 +462,12 @@ def configure(conf): cflags, linkflags = conf.get_optimization_flags() + # installation paths + if conf.env.DEST_OS == 'android': + conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX + else: + conf.env.LIBDIR = conf.env.LIBDIR + '/srceng' + conf.env.TESTDIR = conf.env.BINDIR + 'tests' flags = [] @@ -468,12 +475,14 @@ def configure(conf): flags += ['-fsanitize=%s'%conf.options.SANITIZE, '-fno-sanitize=vptr'] if conf.env.DEST_OS != 'win32': - flags += ['-pipe', '-fPIC', '-L'+os.path.abspath('.')+'/lib/'+conf.env.DEST_OS+'/'+conf.env.DEST_CPU+'/'] + flags += ['-pipe', '-fPIC'] + linkflags += ['-Wl,-rpath=%s' % conf.env.LIBDIR] if conf.env.COMPILER_CC != 'msvc': flags += ['-pthread'] if conf.env.DEST_OS == 'android': flags += [ + '-L'+os.path.abspath('.')+'/lib/android/'+conf.env.DEST_CPU+'/', '-I'+os.path.abspath('.')+'/thirdparty/curl/include', '-I'+os.path.abspath('.')+'/thirdparty/SDL', '-I'+os.path.abspath('.')+'/thirdparty/openal-soft/include/', @@ -484,7 +493,10 @@ def configure(conf): ] flags += ['-funwind-tables', '-g'] - elif conf.env.COMPILER_CC != 'msvc' and conf.env.DEST_OS != 'darwin' and conf.env.DEST_CPU in ['x86', 'x86_64']: + elif conf.env.DEST_OS == 'win32': + flags += ['-L'+os.path.abspath('.')+'/lib/win32/'+conf.env.DEST_CPU+'/'] + + if conf.env.COMPILER_CC != 'msvc' and conf.env.DEST_OS != 'darwin' and conf.env.DEST_CPU in ['x86', 'x86_64']: flags += ['-march=core2'] if conf.env.DEST_CPU in ['x86', 'x86_64']: @@ -495,9 +507,6 @@ def configure(conf): if conf.env.DEST_CPU == 'arm': flags += ['-mfpu=neon-vfpv4'] - if conf.env.DEST_OS == 'freebsd': - linkflags += ['-lexecinfo'] - if conf.env.DEST_OS != 'win32': cflags += flags linkflags += flags @@ -571,14 +580,6 @@ def configure(conf): check_deps( conf ) - # indicate if we are packaging for Linux/BSD - if conf.env.DEST_OS != 'android': - conf.env.LIBDIR = conf.env.PREFIX+'/bin/' - conf.env.TESTDIR = conf.env.PREFIX+'/tests/' - conf.env.BINDIR = conf.env.PREFIX - else: - conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX - if conf.options.CCACHE: conf.env.CC.insert(0, 'ccache') conf.env.CXX.insert(0, 'ccache') From 4147bb5817a54a0824d89cd3e138ded1925bbf6a Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 14:02:05 +0300 Subject: [PATCH 2/9] fix rpath on non-linux --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 5c0f62365..1c830a95a 100644 --- a/wscript +++ b/wscript @@ -476,7 +476,7 @@ def configure(conf): if conf.env.DEST_OS != 'win32': flags += ['-pipe', '-fPIC'] - linkflags += ['-Wl,-rpath=%s' % conf.env.LIBDIR] + conf.env.RPATH = [conf.env.LIBDIR] if conf.env.COMPILER_CC != 'msvc': flags += ['-pthread'] From 36cc43902b958e1ca56a96ff6bb2bcdc92178287 Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 14:40:38 +0300 Subject: [PATCH 3/9] mustdie --- dedicated_main/main.cpp | 2 +- utils/unittest/unittest.cpp | 4 ++-- utils/unittest/wscript | 2 +- wscript | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp index d38f73f8d..9b812a159 100644 --- a/dedicated_main/main.cpp +++ b/dedicated_main/main.cpp @@ -212,7 +212,7 @@ int main( int argc, char *argv[] ) if ( !dedicated ) { - printf( "Failed to open %s (%s)\n", pBinaryName, dlerror()); + printf( "Failed to open dedicated" DLL_EXT_STRING " (%s)\n", dlerror()); return -1; } DedicatedMain_t dedicated_main = (DedicatedMain_t)dlsym( dedicated, "DedicatedMain" ); diff --git a/utils/unittest/unittest.cpp b/utils/unittest/unittest.cpp index 898e86e7a..0965fc4dd 100644 --- a/utils/unittest/unittest.cpp +++ b/utils/unittest/unittest.cpp @@ -94,7 +94,7 @@ bool CUnitTestApp::Create() #ifdef WIN32 WIN32_FIND_DATA findFileData; - HANDLE hFind= FindFirstFile("tests/*.dll", &findFileData); + HANDLE hFind= FindFirstFile(LIBDIR "/tests/*.dll", &findFileData); while (hFind != INVALID_HANDLE_VALUE) { @@ -122,7 +122,7 @@ bool CUnitTestApp::Create() #elif POSIX DIR *d; struct dirent *dir; - d = opendir("tests"); + d = opendir(LIBDIR "/tests"); if (d) { while ((dir = readdir(d)) != NULL) diff --git a/utils/unittest/wscript b/utils/unittest/wscript index 14143def6..d966d9344 100755 --- a/utils/unittest/wscript +++ b/utils/unittest/wscript @@ -17,7 +17,7 @@ def configure(conf): def build(bld): source = ['unittest.cpp'] includes = ['../../public'] - defines = [] + defines = ['LIBDIR="%s"' % bld.env.LIBDIR] libs = ['tier0', 'appframework', 'tier1', 'tier2','tier3', 'vstdlib', 'unitlib'] if bld.env.DEST_OS != 'win32': diff --git a/wscript b/wscript index 1c830a95a..4bd276261 100644 --- a/wscript +++ b/wscript @@ -465,9 +465,14 @@ def configure(conf): # installation paths if conf.env.DEST_OS == 'android': conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX + elif conf.env.DEST_OS == 'win32': + # mustdie + conf.env.LIBDIR = conf.env.PREFIX + '/bin' + conf.env.BINDIR = conf.env.PREFIX else: conf.env.LIBDIR = conf.env.LIBDIR + '/srceng' - conf.env.TESTDIR = conf.env.BINDIR + 'tests' + + conf.env.TESTDIR = conf.env.LIBDIR + '/tests' flags = [] From e502d4e14ceb2990da81b6b92976cd5668f69525 Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 15:08:14 +0300 Subject: [PATCH 4/9] fixes --- dedicated_main/main.cpp | 3 ++- utils/unittest/unittest.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp index 9b812a159..6cde15869 100644 --- a/dedicated_main/main.cpp +++ b/dedicated_main/main.cpp @@ -224,7 +224,8 @@ int main( int argc, char *argv[] ) WaitForDebuggerConnect( argc, argv, 30 ); - ret = dedicated_main( argc,argv ); + int ret = dedicated_main( argc,argv ); dlclose( dedicated ); + return ret; } #endif diff --git a/utils/unittest/unittest.cpp b/utils/unittest/unittest.cpp index 0965fc4dd..bee9b505a 100644 --- a/utils/unittest/unittest.cpp +++ b/utils/unittest/unittest.cpp @@ -94,7 +94,7 @@ bool CUnitTestApp::Create() #ifdef WIN32 WIN32_FIND_DATA findFileData; - HANDLE hFind= FindFirstFile(LIBDIR "/tests/*.dll", &findFileData); + HANDLE hFind= FindFirstFile("bin/tests/*.dll", &findFileData); while (hFind != INVALID_HANDLE_VALUE) { From adbe75007a9e6f93d3ef52f2d2496db10aedb794 Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 20:07:01 +0300 Subject: [PATCH 5/9] revert some code --- dedicated_main/main.cpp | 3 +- engine/cdll_engine_int.cpp | 16 ---- engine/sys_dll.cpp | 11 --- public/filesystem_init.cpp | 184 +++++++++++++++++++++++++++++++++++-- public/filesystem_init.h | 5 + tier1/wscript | 2 +- utils/unittest/wscript | 2 +- wscript | 2 + 8 files changed, 186 insertions(+), 39 deletions(-) diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp index 6cde15869..7629f07a5 100644 --- a/dedicated_main/main.cpp +++ b/dedicated_main/main.cpp @@ -205,8 +205,7 @@ int main( int argc, char *argv[] ) printf( "%s\n", strerror(errno) ); } #endif - - void *dedicated = dlopen( "libdedicated", RTLD_NOW ); + void *dedicated = dlopen( "libdedicated" DLL_EXT_STRING, RTLD_NOW ); if ( !dedicated ) dedicated = dlopen( "dedicated" DLL_EXT_STRING, RTLD_NOW ); diff --git a/engine/cdll_engine_int.cpp b/engine/cdll_engine_int.cpp index f70bebe01..f986a207b 100644 --- a/engine/cdll_engine_int.cpp +++ b/engine/cdll_engine_int.cpp @@ -1715,7 +1715,6 @@ bool ClientDLL_Load() { Assert ( !g_ClientDLLModule ); -#if 0 // Check the signature on the client dll. If this fails we load it anyway but put this client // into insecure mode so it won't connect to secure servers and get VAC banned if ( !Host_AllowLoadModule( "client.dll", "GAMEBIN", true ) ) @@ -1724,23 +1723,8 @@ bool ClientDLL_Load() Host_DisallowSecureServers(); Host_AllowLoadModule( "client.dll","GAMEBIN", true ); } -#endif -#if 0 g_ClientDLLModule = g_pFileSystem->LoadModule( "client", "GAMEBIN", false ); -#else - char clientPath[MAX_PATH]; - const char *modName = CommandLine()->ParmValue("-game"); - - Q_snprintf(clientPath, MAX_PATH, "%s/libclient", modName); - g_ClientDLLModule = Sys_LoadModule(clientPath); - - if (!g_ClientDLLModule) - { - Q_snprintf(clientPath, MAX_PATH, "%s/client", modName); - g_ClientDLLModule = Sys_LoadModule(clientPath); - } -#endif if ( g_ClientDLLModule ) { g_ClientFactory = Sys_GetFactory( g_ClientDLLModule ); diff --git a/engine/sys_dll.cpp b/engine/sys_dll.cpp index df25fdd19..0c2d255e4 100644 --- a/engine/sys_dll.cpp +++ b/engine/sys_dll.cpp @@ -1122,7 +1122,6 @@ static bool LoadThisDll( char *szDllFilename, bool bIsServerOnly ) { CSysModule *pDLL = NULL; -#if 0 // check signature, don't let users with modified binaries connect to secure servers, they will get VAC banned if ( !Host_AllowLoadModule( szDllFilename, "GAMEBIN", true, bIsServerOnly ) ) { @@ -1134,16 +1133,6 @@ static bool LoadThisDll( char *szDllFilename, bool bIsServerOnly ) // ensures that the game.dll is running under Steam // this will have to be undone when we want mods to be able to run if ((pDLL = g_pFileSystem->LoadModule(szDllFilename, "GAMEBIN", false)) == NULL) -#endif - char dllPath[MAX_PATH]; - const char *modName = CommandLine()->ParmValue("-game"); - Q_snprintf(dllPath, MAX_PATH, "%s/lib%s", modName, szDllFilename); - if (!(pDLL = Sys_LoadModule(dllPath))) - { - Q_snprintf(dllPath, MAX_PATH, "%s/%s",modName, szDllFilename); - pDLL = Sys_LoadModule(dllPath); - } - if (!pDLL) { ConMsg("Failed to load %s\n", szDllFilename); goto IgnoreThisDLL; diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index e7738b002..500f57036 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -305,13 +305,103 @@ static bool Sys_GetExecutableName( char *out, int len ) return true; } +bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) +{ +#ifdef ANDROID + Q_strncpy( exedir, getenv("APP_LIB_PATH"), exeDirLen ); +#else +# if 0 + exedir[0] = 0; + + if ( s_bUseVProjectBinDir ) + { + const char *pProject = GetVProjectCmdLineValue(); + if ( !pProject ) + { + // Check their registry. + pProject = getenv( GAMEDIR_TOKEN ); + } + if ( pProject ) + { + Q_snprintf( exedir, exeDirLen, "%s%c..%cbin", pProject, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR ); + return true; + } + return false; + } + + if ( !Sys_GetExecutableName( exedir, exeDirLen ) ) + return false; + Q_StripFilename( exedir ); + + if ( IsX360() ) + { + // The 360 can have its exe and dlls reside on different volumes + // use the optional basedir as the exe dir + if ( CommandLine()->FindParm( "-basedir" ) ) + { + strcpy( exedir, CommandLine()->ParmValue( "-basedir", "" ) ); + } + } + + Q_FixSlashes( exedir ); + + const char* libDir = "bin"; + + // Return the bin directory as the executable dir if it's not in there + // because that's really where we're running from... + char ext[MAX_PATH]; + Q_StrRight( exedir, 4, ext, sizeof( ext ) ); + if ( ext[0] != CORRECT_PATH_SEPARATOR || Q_stricmp( ext+1, libDir ) != 0 ) + { + Q_strncat( exedir, CORRECT_PATH_SEPARATOR_S, exeDirLen, COPY_ALL_CHARACTERS ); + Q_strncat( exedir, libDir, exeDirLen, COPY_ALL_CHARACTERS ); + Q_FixSlashes( exedir ); + } +# endif + Q_strncpy( exedir, LIBDIR, exeDirLen ); +#endif + + return true; +} + static bool FileSystem_GetBaseDir( char *baseDir, int baseDirLen ) { #ifdef ANDROID - strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); + Q_strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); return true; #else +# if 0 + if ( FileSystem_GetExecutableDir( baseDir, baseDirLen ) ) + { + Q_StripFilename( baseDir ); + return true; + } + + return false; +# else return getcwd(baseDir, baseDirLen) != NULL; +# endif +#endif +} + +void LaunchVConfig() +{ +#if defined( _WIN32 ) && !defined( _X360 ) + char vconfigExe[MAX_PATH]; + FileSystem_GetExecutableDir( vconfigExe, sizeof( vconfigExe ) ); + Q_AppendSlash( vconfigExe, sizeof( vconfigExe ) ); + Q_strncat( vconfigExe, "vconfig.exe", sizeof( vconfigExe ), COPY_ALL_CHARACTERS ); + + char *argv[] = + { + vconfigExe, + "-allowdebug", + NULL + }; + + _spawnv( _P_NOWAIT, vconfigExe, argv ); +#elif defined( _X360 ) + Msg( "Launching vconfig.exe not supported\n" ); #endif } @@ -329,6 +419,13 @@ FSReturnCode_t SetupFileSystemError( bool bRunVConfig, FSReturnCode_t retVal, co Warning( "%s\n", g_FileSystemError ); + // Run vconfig? + // Don't do it if they specifically asked for it not to, or if they manually specified a vconfig with -game or -vproject. + if ( bRunVConfig && g_FileSystemErrorMode == FS_ERRORMODE_VCONFIG && !CommandLine()->FindParm( CMDLINEOPTION_NOVCONFIG ) && !GetVProjectCmdLineValue() ) + { + LaunchVConfig(); + } + if ( g_FileSystemErrorMode == FS_ERRORMODE_AUTO || g_FileSystemErrorMode == FS_ERRORMODE_VCONFIG ) { Error( "%s\n", g_FileSystemError ); @@ -922,6 +1019,32 @@ bool DoesPathExistAlready( const char *pPathEnvVar, const char *pTestPath ) } +FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ) +{ + steamCfgPath[0] = 0; + char executablePath[MAX_PATH]; + if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) + { + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); + } + Q_strncpy( steamCfgPath, executablePath, steamCfgPathLen ); + while ( 1 ) + { + if ( DoesFileExistIn( steamCfgPath, "steam.cfg" ) ) + break; + + if ( !Q_StripLastDir( steamCfgPath, steamCfgPathLen) ) + { + // the file isnt found, thats ok, its not mandatory + return FS_OK; + } + } + Q_AppendSlash( steamCfgPath, steamCfgPathLen ); + Q_strncat( steamCfgPath, "steam.cfg", steamCfgPathLen, COPY_ALL_CHARACTERS ); + + return FS_OK; +} + void SetSteamAppUser( KeyValues *pSteamInfo, const char *steamInstallPath, CSteamEnvVars &steamEnvVars ) { // Always inherit the Steam user if it's already set, since it probably means we (or the @@ -976,7 +1099,22 @@ void SetSteamUserPassphrase( KeyValues *pSteamInfo, CSteamEnvVars &steamEnvVars FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) { - // Er2: Deprecated. Used only in hammer + pFileSystem->RemoveSearchPaths( "EXECUTABLE_PATH" ); + + char path[MAX_PATH]; + if ( !FileSystem_GetExecutableDir( path, MAX_PATH ) ) + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); + + pFileSystem->AddSearchPath( path, "EXECUTABLE_PATH" ); + + if ( !FileSystem_GetBaseDir( path, MAX_PATH ) ) + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetBaseDir failed." ); + + pFileSystem->AddSearchPath( path, "BASE_PATH" ); + + Q_snprintf( path, MAX_PATH, "%s/%s", LIBDIR, CommandLine()->ParmValue("-game") ); + pFileSystem->AddSearchPath( path, "GAMEBIN" ); + return FS_OK; } @@ -985,14 +1123,43 @@ FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) //----------------------------------------------------------------------------- FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLen, bool &bSteam ) { +#if 0 + bSteam = false; + + // Inside of here, we don't have a filesystem yet, so we have to assume that the filesystem_stdio or filesystem_steam + // is in this same directory with us. + char executablePath[MAX_PATH]; + if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); + // Assume we'll use local files -#ifdef POSIX - Q_strncpy( pFileSystemDLL, "libfilesystem_stdio" DLL_EXT_STRING, nMaxLen ); + Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); + + #if !defined( _X360 ) + + // Use filsystem_steam if it exists? + #if defined( OSX ) || defined( LINUX ) + struct stat statBuf; + #endif + if ( + #if defined( OSX ) || defined( LINUX ) + stat( pFileSystemDLL, &statBuf ) != 0 + #else + _access( pFileSystemDLL, 0 ) != 0 + #endif + ) { + Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_steam" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); + bSteam = true; + } + #endif #else - Q_strncpy( pFileSystemDLL, "filesystem_stdio" DLL_EXT_STRING, nMaxLen ); -#endif + char executablePath[MAX_PATH]; + if ( !FileSystem_GetExecutableDir( executablePath, sizeof( executablePath ) ) ) + return SetupFileSystemError( false, FS_INVALID_PARAMETERS, "FileSystem_GetExecutableDir failed." ); + + // Assume we'll use local files + Q_snprintf( pFileSystemDLL, nMaxLen, "%s%clibfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); -#if 0 #if !defined( _X360 ) // Use filsystem_steam if it exists? #if defined( OSX ) || defined( LINUX ) @@ -1005,9 +1172,10 @@ FSReturnCode_t FileSystem_GetFileSystemDLLName( char *pFileSystemDLL, int nMaxLe _access( pFileSystemDLL, 0 ) != 0 #endif ) { - Q_snprintf( pFileSystemDLL, nMaxLen, "filesystem_stdio" DLL_EXT_STRING ); + Q_snprintf( pFileSystemDLL, nMaxLen, "%s%cfilesystem_stdio" DLL_EXT_STRING, executablePath, CORRECT_PATH_SEPARATOR ); } #endif + #endif return FS_OK; diff --git a/public/filesystem_init.h b/public/filesystem_init.h index dbeba00b1..9274a5cb1 100644 --- a/public/filesystem_init.h +++ b/public/filesystem_init.h @@ -199,11 +199,16 @@ void FileSystem_AddSearchPath_Platform( IFileSystem *pFileSystem, const char *sz // See FSErrorMode_t. If you don't specify one here, then the default is FS_ERRORMODE_VCONFIG. void FileSystem_SetErrorMode( FSErrorMode_t errorMode = FS_ERRORMODE_VCONFIG ); +bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ); + // Clear SteamAppUser, SteamUserPassphrase, and SteamAppId from this process's environment. // TODO: always do this after LoadFileSysteModule.. there's no reason it should be // in the environment. void FileSystem_ClearSteamEnvVars(); +// Find the steam.cfg above you for optional stuff +FSReturnCode_t GetSteamCfgPath( char *steamCfgPath, int steamCfgPathLen ); + // Returns the last error. const char *FileSystem_GetLastErrorString(); diff --git a/tier1/wscript b/tier1/wscript index 6bdf8758c..0a5f684b5 100755 --- a/tier1/wscript +++ b/tier1/wscript @@ -79,7 +79,7 @@ def build(bld): '../common' ] - defines = ['LIBDIR="%s"' % bld.env.LIBDIR] + defines = [] libs = [] if bld.env.DEST_OS == 'win32': diff --git a/utils/unittest/wscript b/utils/unittest/wscript index d966d9344..14143def6 100755 --- a/utils/unittest/wscript +++ b/utils/unittest/wscript @@ -17,7 +17,7 @@ def configure(conf): def build(bld): source = ['unittest.cpp'] includes = ['../../public'] - defines = ['LIBDIR="%s"' % bld.env.LIBDIR] + defines = [] libs = ['tier0', 'appframework', 'tier1', 'tier2','tier3', 'vstdlib', 'unitlib'] if bld.env.DEST_OS != 'win32': diff --git a/wscript b/wscript index 4bd276261..9c7daab64 100644 --- a/wscript +++ b/wscript @@ -473,6 +473,8 @@ def configure(conf): conf.env.LIBDIR = conf.env.LIBDIR + '/srceng' conf.env.TESTDIR = conf.env.LIBDIR + '/tests' + conf.define('BINDIR', conf.env.BINDIR) + conf.define('LIBDIR', conf.env.LIBDIR) flags = [] From 05978bfde17092206cc4cf716cbc898a4841e17f Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 22:04:50 +0300 Subject: [PATCH 6/9] mustdie --- public/filesystem_init.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index 500f57036..f503d19c7 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -358,7 +358,11 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) Q_FixSlashes( exedir ); } # endif +# ifdef POSIX Q_strncpy( exedir, LIBDIR, exeDirLen ); +# else + exedir = "bin"; +# endif #endif return true; From 49cde1ac27db19961509612cdff6012871c849f9 Mon Sep 17 00:00:00 2001 From: Er2 Date: Mon, 1 May 2023 22:09:52 +0300 Subject: [PATCH 7/9] mustdie --- public/filesystem_init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index f503d19c7..c6baf73a5 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -361,7 +361,7 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) # ifdef POSIX Q_strncpy( exedir, LIBDIR, exeDirLen ); # else - exedir = "bin"; + Q_strncpy( exedir, "./bin", exeDirLen ); # endif #endif From 84745a208564abf27bbd26c4e4b50de4f79d13e8 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 6 May 2023 17:32:13 +0300 Subject: [PATCH 8/9] fix dedicated and allow to start from everywhere --- dedicated/sys_ded.cpp | 9 ++-- dedicated_main/main.cpp | 17 ------- engine/sys_dll.cpp | 53 ++++++++++---------- launcher/launcher.cpp | 6 +-- launcher_main/main.cpp | 21 -------- materialsystem/cmaterialsystem.cpp | 2 +- public/filesystem_init.cpp | 77 ++++++------------------------ tier0/assert_dialog.cpp | 10 ++++ 8 files changed, 56 insertions(+), 139 deletions(-) diff --git a/dedicated/sys_ded.cpp b/dedicated/sys_ded.cpp index f1ff4449d..1f37318a6 100644 --- a/dedicated/sys_ded.cpp +++ b/dedicated/sys_ded.cpp @@ -360,12 +360,9 @@ void CDedicatedAppSystemGroup::Destroy() bool GetExecutableName( char *out, int nMaxLen ) { #ifdef _WIN32 - if ( !::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), out, nMaxLen ) ) - return false; - return true; -#elif POSIX - Q_strncpy( out, g_szEXEName, nMaxLen ); - return true; + return !!::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), out, nMaxLen ); +#else + return false; #endif } diff --git a/dedicated_main/main.cpp b/dedicated_main/main.cpp index 7629f07a5..5f56c578a 100644 --- a/dedicated_main/main.cpp +++ b/dedicated_main/main.cpp @@ -188,23 +188,6 @@ static void WaitForDebuggerConnect( int argc, char *argv[], int time ) int main( int argc, char *argv[] ) { -#if 0 - // Must add 'bin' to the path.... - char* pPath = getenv("LD_LIBRARY_PATH"); - char szBuffer[4096]; - char cwd[ MAX_PATH ]; - if ( !getcwd( cwd, sizeof(cwd)) ) - { - printf( "getcwd failed (%s)", strerror(errno)); - } - - snprintf( szBuffer, sizeof( szBuffer ) - 1, "LD_LIBRARY_PATH=%s/bin:%s", cwd, pPath ); - int ret = putenv( szBuffer ); - if ( ret ) - { - printf( "%s\n", strerror(errno) ); - } -#endif void *dedicated = dlopen( "libdedicated" DLL_EXT_STRING, RTLD_NOW ); if ( !dedicated ) dedicated = dlopen( "dedicated" DLL_EXT_STRING, RTLD_NOW ); diff --git a/engine/sys_dll.cpp b/engine/sys_dll.cpp index 0c2d255e4..3c00cdc35 100644 --- a/engine/sys_dll.cpp +++ b/engine/sys_dll.cpp @@ -342,33 +342,34 @@ bool Sys_MessageBox(const char *title, const char *info, bool bShowOkAndCancel) return true; } return false; - -#elif defined( USE_SDL ) - - int buttonid = 0; - SDL_MessageBoxData messageboxdata = { 0 }; - SDL_MessageBoxButtonData buttondata[] = - { - { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "OK" }, - { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel" }, - }; - - messageboxdata.window = GetAssertDialogParent(); - messageboxdata.title = title; - messageboxdata.message = info; - messageboxdata.numbuttons = bShowOkAndCancel ? 2 : 1; - messageboxdata.buttons = buttondata; - - SDL_ShowMessageBox( &messageboxdata, &buttonid ); - return ( buttonid == 1 ); - -#elif defined( POSIX ) - - Warning( "%s\n", info ); - return true; - #else -#error "implement me" +#if defined( USE_SDL ) + SDL_Window *dialogParent = GetAssertDialogParent(); + if (dialogParent) + { + int buttonid = 0; + SDL_MessageBoxData messageboxdata = { 0 }; + SDL_MessageBoxButtonData buttondata[] = + { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "OK" }, + { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel" }, + }; + + messageboxdata.window = GetAssertDialogParent(); + messageboxdata.title = title; + messageboxdata.message = info; + messageboxdata.numbuttons = bShowOkAndCancel ? 2 : 1; + messageboxdata.buttons = buttondata; + + SDL_ShowMessageBox( &messageboxdata, &buttonid ); + return ( buttonid == 1 ); + } + else +#endif + { + Warning( "%s\n", info ); + return true; + } #endif } diff --git a/launcher/launcher.cpp b/launcher/launcher.cpp index 0b27da73e..ca1f1393b 100644 --- a/launcher/launcher.cpp +++ b/launcher/launcher.cpp @@ -239,11 +239,7 @@ void SetGameDirectory( const char *game ) bool GetExecutableName( char *out, int outSize ) { #ifdef WIN32 - if ( !::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), out, outSize ) ) - { - return false; - } - return true; + return !!::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), out, outSize ); #else return false; #endif diff --git a/launcher_main/main.cpp b/launcher_main/main.cpp index 0e7201d26..1929915b8 100644 --- a/launcher_main/main.cpp +++ b/launcher_main/main.cpp @@ -216,27 +216,6 @@ static void WaitForDebuggerConnect( int argc, char *argv[], int time ) int main( int argc, char *argv[] ) { -#if 0 - char ld_path[4196]; - char *path = "bin/"; - char *ld_env; - - if( (ld_env = getenv("LD_LIBRARY_PATH")) != NULL ) - { - snprintf(ld_path, sizeof(ld_path), "%s:bin/", ld_env); - path = ld_path; - } - - setenv("LD_LIBRARY_PATH", path, 1); - - extern char** environ; - if( getenv("NO_EXECVE_AGAIN") == NULL ) - { - setenv("NO_EXECVE_AGAIN", "1", 1); - execve(argv[0], argv, environ); - } -#endif - void *launcher = dlopen( "liblauncher" DLL_EXT_STRING, RTLD_NOW ); if ( !launcher ) { diff --git a/materialsystem/cmaterialsystem.cpp b/materialsystem/cmaterialsystem.cpp index 5a2a98e7c..d0db83ea6 100644 --- a/materialsystem/cmaterialsystem.cpp +++ b/materialsystem/cmaterialsystem.cpp @@ -672,7 +672,7 @@ bool CMaterialSystem::Connect( CreateInterfaceFn factory ) g_pLauncherMgr = (ILauncherMgr *)factory( "SDLMgrInterface001" /*SDL_MGR_INTERFACE_VERSION*/, NULL ); if ( !g_pLauncherMgr ) { - return false; + Warning("Cannot connect SDL\n"); } #endif // USE_SDL #endif // !DEDICATED diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index c6baf73a5..fa69ae6aa 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -310,58 +310,10 @@ bool FileSystem_GetExecutableDir( char *exedir, int exeDirLen ) #ifdef ANDROID Q_strncpy( exedir, getenv("APP_LIB_PATH"), exeDirLen ); #else -# if 0 - exedir[0] = 0; - - if ( s_bUseVProjectBinDir ) - { - const char *pProject = GetVProjectCmdLineValue(); - if ( !pProject ) - { - // Check their registry. - pProject = getenv( GAMEDIR_TOKEN ); - } - if ( pProject ) - { - Q_snprintf( exedir, exeDirLen, "%s%c..%cbin", pProject, CORRECT_PATH_SEPARATOR, CORRECT_PATH_SEPARATOR ); - return true; - } - return false; - } - - if ( !Sys_GetExecutableName( exedir, exeDirLen ) ) - return false; - Q_StripFilename( exedir ); - - if ( IsX360() ) - { - // The 360 can have its exe and dlls reside on different volumes - // use the optional basedir as the exe dir - if ( CommandLine()->FindParm( "-basedir" ) ) - { - strcpy( exedir, CommandLine()->ParmValue( "-basedir", "" ) ); - } - } - - Q_FixSlashes( exedir ); - - const char* libDir = "bin"; - - // Return the bin directory as the executable dir if it's not in there - // because that's really where we're running from... - char ext[MAX_PATH]; - Q_StrRight( exedir, 4, ext, sizeof( ext ) ); - if ( ext[0] != CORRECT_PATH_SEPARATOR || Q_stricmp( ext+1, libDir ) != 0 ) - { - Q_strncat( exedir, CORRECT_PATH_SEPARATOR_S, exeDirLen, COPY_ALL_CHARACTERS ); - Q_strncat( exedir, libDir, exeDirLen, COPY_ALL_CHARACTERS ); - Q_FixSlashes( exedir ); - } -# endif -# ifdef POSIX - Q_strncpy( exedir, LIBDIR, exeDirLen ); -# else +# ifdef _WIN32 Q_strncpy( exedir, "./bin", exeDirLen ); +# else + Q_strncpy( exedir, LIBDIR, exeDirLen ); # endif #endif @@ -374,17 +326,12 @@ static bool FileSystem_GetBaseDir( char *baseDir, int baseDirLen ) Q_strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); return true; #else -# if 0 - if ( FileSystem_GetExecutableDir( baseDir, baseDirLen ) ) - { - Q_StripFilename( baseDir ); - return true; - } - - return false; -# else - return getcwd(baseDir, baseDirLen) != NULL; -# endif + // get relative base dir which appends to other paths + // allows to run from everywhere + // "hl2/portal" -> "hl2"; "hl2" -> "" + Q_strncpy( baseDir, CommandLine()->ParmValue("-game"), baseDirLen ); + Q_StripFilename( baseDir ); + return true; #endif } @@ -1116,7 +1063,11 @@ FSReturnCode_t FileSystem_SetBasePaths( IFileSystem *pFileSystem ) pFileSystem->AddSearchPath( path, "BASE_PATH" ); - Q_snprintf( path, MAX_PATH, "%s/%s", LIBDIR, CommandLine()->ParmValue("-game") ); + // path for client/server libraries + // "hl2/portal" -> "LIBDIR/portal"; "hl2" -> "LIBDIR/hl2" + char gamePath[MAX_PATH]; + V_FileBase( CommandLine()->ParmValue("-game"), gamePath, MAX_PATH ); + Q_snprintf( path, MAX_PATH, "%s/%s", LIBDIR, gamePath ); pFileSystem->AddSearchPath( path, "GAMEBIN" ); return FS_OK; diff --git a/tier0/assert_dialog.cpp b/tier0/assert_dialog.cpp index d0a73b8ee..a5ab80d02 100644 --- a/tier0/assert_dialog.cpp +++ b/tier0/assert_dialog.cpp @@ -369,6 +369,16 @@ DBG_INTERFACE struct SDL_Window * GetAssertDialogParent() { return g_SDLWindow; } +#elif !defined( _WIN32 ) +DBG_INTERFACE void SetAssertDialogParent( void *window) +{ + (void)window; +} + +DBG_INTERFACE void * GetAssertDialogParent() +{ + return NULL; +} #endif DBG_INTERFACE bool ShouldUseNewAssertDialog() From a66efd6102a374f7c1e34cc9feffd06b281b3ae1 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 6 May 2023 19:07:53 +0300 Subject: [PATCH 9/9] fix error when no -game was provided --- public/filesystem_init.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/filesystem_init.cpp b/public/filesystem_init.cpp index fa69ae6aa..c3729707f 100644 --- a/public/filesystem_init.cpp +++ b/public/filesystem_init.cpp @@ -324,15 +324,14 @@ static bool FileSystem_GetBaseDir( char *baseDir, int baseDirLen ) { #ifdef ANDROID Q_strncpy(baseDir, getenv("VALVE_GAME_PATH"), baseDirLen); - return true; #else // get relative base dir which appends to other paths // allows to run from everywhere // "hl2/portal" -> "hl2"; "hl2" -> "" - Q_strncpy( baseDir, CommandLine()->ParmValue("-game"), baseDirLen ); + Q_strncpy( baseDir, CommandLine()->ParmValue("-game", ""), baseDirLen ); Q_StripFilename( baseDir ); - return true; #endif + return true; } void LaunchVConfig()