1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-20 04:26:03 +08:00

Add WIP tier1 interface changes / tier0.

Not done, but this should fix current MM:S build from tier1 headers not
matching lib on Windows.
This commit is contained in:
Nick Hastings
2018-05-05 10:55:21 -04:00
parent 27fe1b091f
commit 26556b4aa6
8 changed files with 12 additions and 197 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -701,7 +701,11 @@ typedef unsigned int uint;
// Returns true if debugger attached, false otherwise // Returns true if debugger attached, false otherwise
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if defined( PLATFORM_WINDOWS ) || defined( PLATFORM_LINUX ) || defined( PLATFORM_OSX ) #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 * ); PLATFORM_INTERFACE void Plat_DebugString( const tchar * );
#else #else
inline bool Plat_IsInDebugSession() { return false; } inline bool Plat_IsInDebugSession() { return false; }
@ -1638,6 +1642,13 @@ FORCEINLINE uint64 RotateBitsRight64( uint64 nValue, int nRotateBits )
} }
#endif #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" #include "tier0/valve_on.h"

View File

@ -143,202 +143,6 @@ struct ThreadedLoadLibaryContext_t
HMODULE m_hLibrary; 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<CSysModule *>(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<HMODULE>(pModule);
#ifdef _WIN32
FreeLibrary( hDLL );
#elif defined(_LINUX) || defined(__APPLE__)
dlclose((void *)hDLL);
#endif
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: returns a pointer to a function, given a module // Purpose: returns a pointer to a function, given a module
// Input : module - windows HMODULE from Sys_LoadModule() // Input : module - windows HMODULE from Sys_LoadModule()