diff --git a/lib/public/tier0.lib b/lib/public/tier0.lib index 7f34c588..c10640c3 100644 Binary files a/lib/public/tier0.lib and b/lib/public/tier0.lib differ diff --git a/lib/public/tier1.lib b/lib/public/tier1.lib index 62098e27..57e3e6ec 100644 Binary files a/lib/public/tier1.lib and b/lib/public/tier1.lib differ diff --git a/lib/public/vstdlib.lib b/lib/public/vstdlib.lib index ca44b9eb..d3e758eb 100644 Binary files a/lib/public/vstdlib.lib and b/lib/public/vstdlib.lib differ diff --git a/lib/public/win64/tier0.lib b/lib/public/win64/tier0.lib index 2bb6b833..67f1247b 100644 Binary files a/lib/public/win64/tier0.lib and b/lib/public/win64/tier0.lib differ diff --git a/lib/public/win64/tier1.lib b/lib/public/win64/tier1.lib index ea0d9584..545677e7 100644 Binary files a/lib/public/win64/tier1.lib and b/lib/public/win64/tier1.lib differ diff --git a/lib/public/win64/vstdlib.lib b/lib/public/win64/vstdlib.lib index 27a41040..7622253c 100644 Binary files a/lib/public/win64/vstdlib.lib and b/lib/public/win64/vstdlib.lib differ diff --git a/public/tier0/platform.h b/public/tier0/platform.h index c59f17be..a24a004d 100644 --- a/public/tier0/platform.h +++ b/public/tier0/platform.h @@ -701,7 +701,11 @@ typedef unsigned int uint; // Returns true if debugger attached, false otherwise //----------------------------------------------------------------------------- #if defined( PLATFORM_WINDOWS ) || defined( PLATFORM_LINUX ) || defined( PLATFORM_OSX ) -PLATFORM_INTERFACE bool Plat_IsInDebugSession(); +PLATFORM_INTERFACE bool Plat_IsInDebugSessionRaw(); +inline bool Plat_IsInDebugSession() +{ + return Plat_IsInDebugSessionRaw(); +} PLATFORM_INTERFACE void Plat_DebugString( const tchar * ); #else inline bool Plat_IsInDebugSession() { return false; } @@ -1638,6 +1642,13 @@ FORCEINLINE uint64 RotateBitsRight64( uint64 nValue, int nRotateBits ) } #endif +#if !defined COMPILER_MSVC && !defined HMODULE +#define HMODULE void * +#endif + +PLATFORM_INTERFACE void *Plat_LoadModule( const char *pModuleName ); +PLATFORM_INTERFACE void *Plat_FindModuleByAddress( void *pAddress ); + #include "tier0/valve_on.h" diff --git a/tier1/interface.cpp b/tier1/interface.cpp index 062504c5..8725e98e 100644 --- a/tier1/interface.cpp +++ b/tier1/interface.cpp @@ -143,202 +143,6 @@ struct ThreadedLoadLibaryContext_t HMODULE m_hLibrary; }; -#ifdef _WIN32 - -// wraps LoadLibraryEx() since 360 doesn't support that -static HMODULE InternalLoadLibrary( const char *pName ) -{ -#if defined(_X360) - return LoadLibrary( pName ); -#else - return LoadLibraryEx( pName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); -#endif -} -uintp ThreadedLoadLibraryFunc(void *pParam) -{ - ThreadedLoadLibaryContext_t *pContext = (ThreadedLoadLibaryContext_t*)pParam; - pContext->m_hLibrary = InternalLoadLibrary(pContext->m_pLibraryName); - return 0; -} -#endif - -HMODULE Sys_LoadLibrary( const char *pLibraryName ) -{ - char str[1024]; -#if defined( _WIN32 ) && !defined( _X360 ) - const char *pModuleExtension = ".dll"; - const char *pModuleAddition = pModuleExtension; -#elif defined( _X360 ) - const char *pModuleExtension = "_360.dll"; - const char *pModuleAddition = pModuleExtension; -#elif defined( _LINUX ) - const char *pModuleExtension = ".so"; - const char *pModuleAddition = ".so"; -#elif defined( __APPLE__ ) - const char *pModuleExtension = ".dylib"; - const char *pModuleAddition = ".dylib"; -#endif - Q_strncpy( str, pLibraryName, sizeof(str) ); - if ( !Q_stristr( str, pModuleExtension ) ) - { - if ( IsX360() ) - { - Q_StripExtension( str, str, sizeof(str) ); - } - Q_strncat( str, pModuleAddition, sizeof(str) ); - } - Q_FixSlashes( str ); - -#ifdef _WIN32 - ThreadedLoadLibraryFunc_t threadFunc = GetThreadedLoadLibraryFunc(); - if ( !threadFunc ) - return InternalLoadLibrary( str ); - - ThreadedLoadLibaryContext_t context; - context.m_pLibraryName = str; - context.m_hLibrary = 0; - - ThreadHandle_t h = CreateSimpleThread( ThreadedLoadLibraryFunc, &context ); - -#ifdef _X360 - ThreadSetAffinity( h, XBOX_PROCESSOR_3 ); -#endif - - unsigned int nTimeout = 0; - while( WaitForSingleObject(h, nTimeout) == WAIT_TIMEOUT ) - { - nTimeout = threadFunc(); - } - - ReleaseThreadHandle( h ); - return context.m_hLibrary; - -#elif defined _LINUX || defined __APPLE__ - HMODULE ret = dlopen( str, RTLD_NOW ); - if ( ! ret ) - { - const char *pError = dlerror(); - if ( pError && ( strstr( pError, "No such file" ) == 0 ) ) - { - Msg( " failed to dlopen %s error=%s\n", str, pError ); - - } - } - - return ret; -#endif -} - -//----------------------------------------------------------------------------- -// Purpose: Loads a DLL/component from disk and returns a handle to it -// Input : *pModuleName - filename of the component -// Output : opaque handle to the module (hides system dependency) -//----------------------------------------------------------------------------- -CSysModule *Sys_LoadModule( const char *pModuleName ) -{ - // If using the Steam filesystem, either the DLL must be a minimum footprint - // file in the depot (MFP) or a filesystem GetLocalCopy() call must be made - // prior to the call to this routine. - char szCwd[1024]; - HMODULE hDLL = NULL; - - if ( !Q_IsAbsolutePath( pModuleName ) ) - { - // full path wasn't passed in, using the current working dir - _getcwd( szCwd, sizeof( szCwd ) ); - if ( IsX360() ) - { - int i = CommandLine()->FindParm( "-basedir" ); - if ( i ) - { - strcpy( szCwd, CommandLine()->GetParm( i+1 ) ); - } - } - if (szCwd[strlen(szCwd) - 1] == '/' || szCwd[strlen(szCwd) - 1] == '\\' ) - { - szCwd[strlen(szCwd) - 1] = 0; - } - - char szAbsoluteModuleName[1024]; - if ( strstr( pModuleName, "bin/") == pModuleName ) - { - // don't make bin/bin path - Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/%s", szCwd, pModuleName ); - } - else - { - Q_snprintf( szAbsoluteModuleName, sizeof(szAbsoluteModuleName), "%s/bin/%s", szCwd, pModuleName ); - } - hDLL = Sys_LoadLibrary( szAbsoluteModuleName ); - } - - if ( !hDLL ) - { - // full path failed, let LoadLibrary() try to search the PATH now - hDLL = Sys_LoadLibrary( pModuleName ); -#if defined( _DEBUG ) - if ( !hDLL ) - { -// So you can see what the error is in the debugger... -#if defined( _WIN32 ) && !defined( _X360 ) - char *lpMsgBuf; - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - - LocalFree( (HLOCAL)lpMsgBuf ); -#elif defined( _X360 ) - Msg( "Failed to load %s:\n", pModuleName ); -#else - Error( "Failed to load %s: %s\n", pModuleName, dlerror() ); -#endif // _WIN32 - } -#endif // DEBUG - } - - // If running in the debugger, assume debug binaries are okay, otherwise they must run with -allowdebug - if ( !IsX360() && hDLL && - !CommandLine()->FindParm( "-allowdebug" ) && - !Sys_IsDebuggerPresent() ) - { - if ( Sys_GetProcAddress( hDLL, "BuiltDebug" ) ) - { - Error( "Module %s is a debug build\n", pModuleName ); - } - } - - return reinterpret_cast(hDLL); -} - - -//----------------------------------------------------------------------------- -// Purpose: Unloads a DLL/component from -// Input : *pModuleName - filename of the component -// Output : opaque handle to the module (hides system dependency) -//----------------------------------------------------------------------------- -void Sys_UnloadModule( CSysModule *pModule ) -{ - if ( !pModule ) - return; - - HMODULE hDLL = reinterpret_cast(pModule); - -#ifdef _WIN32 - FreeLibrary( hDLL ); -#elif defined(_LINUX) || defined(__APPLE__) - dlclose((void *)hDLL); -#endif -} - //----------------------------------------------------------------------------- // Purpose: returns a pointer to a function, given a module // Input : module - windows HMODULE from Sys_LoadModule()