mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-01-04 00:23:25 +08:00
More Source 2 / Dota shuffling.
- Remove tier1 interface/factory funcs that no longer exist. - Add/fix tier0 interface funcs. - Fix tier0 win64 link lib to have correct decorated names for Msg, Warning, etc. - Update Error() shim to act more closely to old behavior. - Moved CreateInterface impl to interfaces lib (appears to not be in tier1 anymore). - Removed exports log channels that aren't exported in S2.
This commit is contained in:
parent
4f463be480
commit
f60592b4f9
@ -386,3 +386,44 @@ void ReconnectInterface(CreateInterfaceFn factory, const char *pInterfaceName)
|
||||
ReconnectInterface(factory, iface.m_pInterfaceName, (void **)iface.m_ppGlobal);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// InterfaceReg.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
InterfaceReg *s_pInterfaceRegs = NULL;
|
||||
|
||||
InterfaceReg::InterfaceReg(InstantiateInterfaceFn fn, const char *pName) :
|
||||
m_pName(pName)
|
||||
{
|
||||
m_CreateFn = fn;
|
||||
m_pNext = s_pInterfaceRegs;
|
||||
s_pInterfaceRegs = this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// CreateInterface.
|
||||
// This is the primary exported function by a dll, referenced by name via dynamic binding
|
||||
// that exposes an opqaue function pointer to the interface.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
void* CreateInterface(const char *pName, int *pReturnCode)
|
||||
{
|
||||
InterfaceReg *pCur;
|
||||
|
||||
for (pCur = s_pInterfaceRegs; pCur; pCur = pCur->m_pNext)
|
||||
{
|
||||
if (strcmp(pCur->m_pName, pName) == 0)
|
||||
{
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_OK;
|
||||
}
|
||||
return pCur->m_CreateFn();
|
||||
}
|
||||
}
|
||||
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_FAILED;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,6 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier1/interface.h"
|
||||
#include "interfaces/interfaces.h"
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "tier0/threadtools.h"
|
||||
#include "tier0/memalloc.h"
|
||||
#include "tier0/tslist.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier0/interface.h"
|
||||
#include "tier1/utlsymbol.h"
|
||||
#include "tier1/utlstring.h"
|
||||
//#include "tier1/functors.h"
|
||||
@ -537,8 +537,8 @@ public:
|
||||
//--------------------------------------------------------
|
||||
|
||||
// load/unload modules
|
||||
virtual CSysModule *LoadModule( const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true ) = 0;
|
||||
virtual void UnloadModule( CSysModule *pModule ) = 0;
|
||||
virtual HMODULE *LoadModule( const char *pFileName, const char *pPathID = 0, bool bValidatedDllOnly = true ) = 0;
|
||||
virtual void UnloadModule( HMODULE *pModule ) = 0;
|
||||
|
||||
//--------------------------------------------------------
|
||||
// File searching operations
|
||||
|
@ -12,12 +12,107 @@
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/interface.h"
|
||||
|
||||
// All interfaces derive from this.
|
||||
class IBaseInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IBaseInterface() {}
|
||||
};
|
||||
|
||||
typedef void* (*InstantiateInterfaceFn)();
|
||||
|
||||
// Used internally to register classes.
|
||||
class InterfaceReg
|
||||
{
|
||||
public:
|
||||
InterfaceReg(InstantiateInterfaceFn fn, const char *pName);
|
||||
|
||||
public:
|
||||
InstantiateInterfaceFn m_CreateFn;
|
||||
const char *m_pName;
|
||||
|
||||
InterfaceReg *m_pNext; // For the global list.
|
||||
};
|
||||
|
||||
// Use this to expose an interface that can have multiple instances.
|
||||
// e.g.:
|
||||
// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" )
|
||||
// This will expose a class called CInterfaceImp that implements IInterface (a pure class)
|
||||
// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" )
|
||||
//
|
||||
// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001")
|
||||
// so that each component can use these names/vtables to communicate
|
||||
//
|
||||
// A single class can support multiple interfaces through multiple inheritance
|
||||
//
|
||||
// Use this if you want to write the factory function.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName);
|
||||
#else
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName );
|
||||
#else
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface with a global variable you've created.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName);
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface. This creates the global variable for you automatically.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
static className __g_##className##_singleton; \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static className __g_##className##_singleton; \
|
||||
} \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#endif
|
||||
|
||||
// interface return status
|
||||
enum
|
||||
{
|
||||
IFACE_OK = 0,
|
||||
IFACE_FAILED
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface creation function
|
||||
// This function is automatically exported and allows you to access any interfaces exposed with the above macros.
|
||||
// if pReturnCode is set, it will return one of the following values (IFACE_OK, IFACE_FAILED)
|
||||
// extend this for other error conditions/code
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
|
||||
DLL_EXPORT void* CreateInterface(const char *pName, int *pReturnCode);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Macros to declare interfaces appropriate for various tiers
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/basetypes.h"
|
||||
#include <tier1/strtools.h>
|
||||
#include "dbgflag.h"
|
||||
#include "logging.h"
|
||||
#include <math.h>
|
||||
@ -231,20 +232,10 @@ PLATFORM_INTERFACE bool SetupWin32ConsoleIO();
|
||||
// Legacy Logging System
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Channels which map the legacy logging system to the new system.
|
||||
// Channels which map the legacy logging system to the new system. Only LOG_GENERAL exists as shared in Source 2
|
||||
|
||||
// Channel for all default Msg/Warning/Error commands.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_GENERAL );
|
||||
// Channel for all asserts.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_ASSERT );
|
||||
// Channel for all ConMsg and ConColorMsg commands.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_CONSOLE );
|
||||
// Channel for all DevMsg and DevWarning commands with level < 2.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER );
|
||||
// Channel for ConDMsg commands.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER_CONSOLE );
|
||||
// Channel for all DevMsg and DevWarning commands with level >= 2.
|
||||
DECLARE_LOGGING_CHANNEL( LOG_DEVELOPER_VERBOSE );
|
||||
PLATFORM_INTERFACE LoggingChannelID_t LOG_GENERAL;
|
||||
|
||||
// Legacy logging functions
|
||||
|
||||
@ -252,21 +243,15 @@ PLATFORM_INTERFACE void Msg( const tchar* pMsg, ... );
|
||||
PLATFORM_INTERFACE void Warning( const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 );
|
||||
PLATFORM_INTERFACE void Warning_SpewCallStack( int iMaxCallStackLength, const tchar *pMsg, ... ) FMTFUNCTION( 2, 3 );
|
||||
|
||||
// This is gone in Source2. Provide helper to roughyl mimic Source1 behavior
|
||||
void Error( const tchar *pMsg, ... ) FMTFUNCTION( 1, 2 );
|
||||
inline void Error( const tchar *pMsg, ... )
|
||||
// This is gone in Source2. Provide helper to roughly mimic Source1 behavior
|
||||
inline void Error( const tchar* pMsg, ... ) FMTFUNCTION( 1, 2 )
|
||||
{
|
||||
char szBuf[256];
|
||||
va_list arg_ptr;
|
||||
|
||||
va_start(arg_ptr, pMsg);
|
||||
vsnprintf(szBuf, sizeof(szBuf)-1, pMsg, arg_ptr);
|
||||
va_end(arg_ptr);
|
||||
|
||||
szBuf[sizeof(szBuf)-1] = 0;
|
||||
|
||||
Msg("%s", szBuf);
|
||||
Plat_ExitProcess(1);
|
||||
static char szBuffer[MAX_LOGGING_MESSAGE_LENGTH];
|
||||
va_list params;
|
||||
va_start(params, pMsg);
|
||||
V_vsnprintf(szBuffer, sizeof(szBuffer), pMsg, params);
|
||||
va_end(params);
|
||||
LoggingSystem_LogDirect(LOG_GENERAL, LS_ERROR, szBuffer);
|
||||
}
|
||||
|
||||
// @TODO: these callstack spew functions are currently disabled in the new logging system. Need to add support for these if desired.
|
||||
|
48
public/tier0/interface.h
Normal file
48
public/tier0/interface.h
Normal file
@ -0,0 +1,48 @@
|
||||
//========= Copyright ? 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if defined( _WIN32 ) && !defined( _X360 )
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
#if !defined COMPILER_MSVC && !defined HMODULE
|
||||
#define HMODULE void *
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Interface creation function
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Load & Unload should be called in exactly one place for each module
|
||||
// The factory for that module should be passed on to dependent components for
|
||||
// proper versioning.
|
||||
//-----------------------------------------------------------------------------
|
||||
PLATFORM_INTERFACE HMODULE Plat_LoadModule( const char *pModuleName );
|
||||
PLATFORM_INTERFACE void Plat_UnloadModule( HMODULE module );
|
||||
|
||||
// Determines if current process is running with any debug modules
|
||||
PLATFORM_INTERFACE bool Plat_RunningWithDebugModules();
|
||||
|
||||
PLATFORM_INTERFACE HMODULE Plat_FindModuleByAddress( void *pAddress );
|
||||
PLATFORM_INTERFACE CreateInterfaceFn Plat_GetModuleInterfaceFactory( HMODULE module, int *pReturnCode = NULL );
|
||||
|
||||
// This is a helper function to load a module, get its factory, and get a specific interface.
|
||||
// You are expected to free all of these things.
|
||||
// Returns false and cleans up if any of the steps fail.
|
||||
PLATFORM_INTERFACE bool Plat_LoadInterface(
|
||||
const char *pModuleName,
|
||||
const char *pInterfaceVersionName,
|
||||
HMODULE *pOutModule,
|
||||
void **pOutInterface );
|
@ -11,6 +11,8 @@
|
||||
|
||||
#ifdef COMPILER_MSVC
|
||||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#if defined( _X360 )
|
||||
@ -1642,16 +1644,6 @@ FORCEINLINE uint64 RotateBitsRight64( uint64 nValue, int nRotateBits )
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined COMPILER_MSVC && !defined HMODULE
|
||||
#define HMODULE void *
|
||||
#endif
|
||||
|
||||
typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
|
||||
PLATFORM_INTERFACE HMODULE Plat_LoadModule( const char *pModuleName );
|
||||
PLATFORM_INTERFACE void Plat_UnloadModule( HMODULE module );
|
||||
PLATFORM_INTERFACE HMODULE Plat_FindModuleByAddress( void *pAddress );
|
||||
PLATFORM_INTERFACE CreateInterfaceFn Plat_GetModuleInterfaceFactory( HMODULE module, int *pReturnCode = NULL );
|
||||
|
||||
#include "tier0/valve_on.h"
|
||||
|
||||
#if defined(TIER0_DLL_EXPORT)
|
||||
|
@ -18,6 +18,10 @@ DECLARE_HANDLE_32BIT( datamanhandle_t );
|
||||
|
||||
#define INVALID_MEMHANDLE (datamanhandle_t::MakeHandle(~0))
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef UnlockResource
|
||||
#endif
|
||||
|
||||
class CDataManagerBase
|
||||
{
|
||||
public:
|
||||
|
@ -1,197 +0,0 @@
|
||||
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
// This header defines the interface convention used in the valve engine.
|
||||
// To make an interface and expose it:
|
||||
// 1. The interface must be ALL pure virtuals, and have no data members.
|
||||
// 2. Define a name for it.
|
||||
// 3. In its implementation file, use EXPOSE_INTERFACE or EXPOSE_SINGLE_INTERFACE.
|
||||
|
||||
// Versioning
|
||||
// There are two versioning cases that are handled by this:
|
||||
// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case,
|
||||
// you need two EXPOSE_INTERFACEs: one to expose your class as the old interface and one to expose it as the new interface.
|
||||
// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface
|
||||
// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and
|
||||
// expose it for the old interface.
|
||||
|
||||
// Static Linking:
|
||||
// Must mimic unique seperate class 'InterfaceReg' constructors per subsystem.
|
||||
// Each subsystem can then import and export interfaces as expected.
|
||||
// This is achieved through unique namespacing 'InterfaceReg' via symbol _SUBSYSTEM.
|
||||
// Static Linking also needs to generate unique symbols per interface so as to
|
||||
// provide a 'stitching' method whereby these interface symbols can be referenced
|
||||
// via the lib's primary module (usually the lib's interface exposure)
|
||||
// therby stitching all of that lib's code/data together for eventual final exe link inclusion.
|
||||
|
||||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef POSIX
|
||||
#include <dlfcn.h> // dlopen,dlclose, et al
|
||||
#include <unistd.h>
|
||||
|
||||
#define GetProcAddress dlsym
|
||||
|
||||
#endif
|
||||
|
||||
// TODO: move interface.cpp into tier0 library.
|
||||
#include "tier0/platform.h"
|
||||
|
||||
// All interfaces derive from this.
|
||||
class IBaseInterface
|
||||
{
|
||||
public:
|
||||
virtual ~IBaseInterface() {}
|
||||
};
|
||||
|
||||
typedef void* (*InstantiateInterfaceFn)();
|
||||
|
||||
// Used internally to register classes.
|
||||
class InterfaceReg
|
||||
{
|
||||
public:
|
||||
InterfaceReg(InstantiateInterfaceFn fn, const char *pName);
|
||||
|
||||
public:
|
||||
InstantiateInterfaceFn m_CreateFn;
|
||||
const char *m_pName;
|
||||
|
||||
InterfaceReg *m_pNext; // For the global list.
|
||||
};
|
||||
|
||||
// Use this to expose an interface that can have multiple instances.
|
||||
// e.g.:
|
||||
// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" )
|
||||
// This will expose a class called CInterfaceImp that implements IInterface (a pure class)
|
||||
// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" )
|
||||
//
|
||||
// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001")
|
||||
// so that each component can use these names/vtables to communicate
|
||||
//
|
||||
// A single class can support multiple interfaces through multiple inheritance
|
||||
//
|
||||
// Use this if you want to write the factory function.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName);
|
||||
#else
|
||||
#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName );
|
||||
#else
|
||||
#define EXPOSE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##_interface() {return static_cast<interfaceName *>( new className );} \
|
||||
static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface with a global variable you've created.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName);
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static void* __Create##className##interfaceName##_interface() {return static_cast<interfaceName *>( &globalVarName );} \
|
||||
static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use this to expose a singleton interface. This creates the global variable for you automatically.
|
||||
#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM)
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
static className __g_##className##_singleton; \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#else
|
||||
#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \
|
||||
namespace _SUBSYSTEM \
|
||||
{ \
|
||||
static className __g_##className##_singleton; \
|
||||
} \
|
||||
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton)
|
||||
#endif
|
||||
|
||||
// load/unload components
|
||||
class CSysModule;
|
||||
|
||||
// interface return status
|
||||
enum
|
||||
{
|
||||
IFACE_OK = 0,
|
||||
IFACE_FAILED
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This function is automatically exported and allows you to access any interfaces exposed with the above macros.
|
||||
// if pReturnCode is set, it will return one of the following values (IFACE_OK, IFACE_FAILED)
|
||||
// extend this for other error conditions/code
|
||||
//-----------------------------------------------------------------------------
|
||||
DLL_EXPORT void* CreateInterface(const char *pName, int *pReturnCode);
|
||||
|
||||
#if defined( _X360 )
|
||||
DLL_EXPORT void *CreateInterfaceThunk( const char *pName, int *pReturnCode );
|
||||
#endif
|
||||
|
||||
// Determines if current process is running with any debug modules
|
||||
extern bool Sys_RunningWithDebugModules();
|
||||
|
||||
// This is a helper function to load a module, get its factory, and get a specific interface.
|
||||
// You are expected to free all of these things.
|
||||
// Returns false and cleans up if any of the steps fail.
|
||||
bool Sys_LoadInterface(
|
||||
const char *pModuleName,
|
||||
const char *pInterfaceVersionName,
|
||||
HMODULE *pOutModule,
|
||||
void **pOutInterface );
|
||||
|
||||
bool Sys_IsDebuggerPresent();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Place this as a singleton at module scope (e.g.) and use it to get the factory from the specified module name.
|
||||
//
|
||||
// When the singleton goes out of scope (.dll unload if at module scope),
|
||||
// then it'll call Sys_UnloadModule on the module so that the refcount is decremented
|
||||
// and the .dll actually can unload from memory.
|
||||
//-----------------------------------------------------------------------------
|
||||
class CDllDemandLoader
|
||||
{
|
||||
public:
|
||||
CDllDemandLoader( char const *pchModuleName );
|
||||
virtual ~CDllDemandLoader();
|
||||
CreateInterfaceFn GetFactory();
|
||||
void Unload();
|
||||
|
||||
private:
|
||||
|
||||
char const *m_pchModuleName;
|
||||
HMODULE m_hModule;
|
||||
bool m_bLoadAttempted;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "appframework/IAppSystem.h"
|
||||
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "vstdlib/vstdlib.h"
|
||||
#include "tier0/basetypes.h"
|
||||
#include "tier0/threadtools.h"
|
||||
#include "tier1/interface.h"
|
||||
|
||||
#define NTAB 32
|
||||
|
||||
|
@ -1,207 +0,0 @@
|
||||
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
#if defined( _WIN32 ) && !defined( _X360 )
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if !defined( DONT_PROTECT_FILEIO_FUNCTIONS )
|
||||
#define DONT_PROTECT_FILEIO_FUNCTIONS // for protected_things.h
|
||||
#endif
|
||||
|
||||
#if defined( PROTECTED_THINGS_ENABLE )
|
||||
#undef PROTECTED_THINGS_ENABLE // from protected_things.h
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "interface.h"
|
||||
#include "basetypes.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "tier1/strtools.h"
|
||||
#include "tier0/icommandline.h"
|
||||
#include "tier0/dbg.h"
|
||||
#include "tier0/threadtools.h"
|
||||
#ifdef _WIN32
|
||||
#include <direct.h> // getcwd
|
||||
#elif defined _LINUX || defined __APPLE__
|
||||
#define _getcwd getcwd
|
||||
#endif
|
||||
#if defined( _X360 )
|
||||
#include "xbox/xbox_win32stubs.h"
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#if !defined COMPILER_MSVC && !defined HMODULE
|
||||
#define HMODULE void *
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// InterfaceReg.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
InterfaceReg *s_pInterfaceRegs = NULL;
|
||||
|
||||
InterfaceReg::InterfaceReg( InstantiateInterfaceFn fn, const char *pName ) :
|
||||
m_pName(pName)
|
||||
{
|
||||
m_CreateFn = fn;
|
||||
m_pNext = s_pInterfaceRegs;
|
||||
s_pInterfaceRegs = this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
// CreateInterface.
|
||||
// This is the primary exported function by a dll, referenced by name via dynamic binding
|
||||
// that exposes an opqaue function pointer to the interface.
|
||||
// ------------------------------------------------------------------------------------ //
|
||||
void* CreateInterface( const char *pName, int *pReturnCode )
|
||||
{
|
||||
InterfaceReg *pCur;
|
||||
|
||||
for (pCur=s_pInterfaceRegs; pCur; pCur=pCur->m_pNext)
|
||||
{
|
||||
if (strcmp(pCur->m_pName, pName) == 0)
|
||||
{
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_OK;
|
||||
}
|
||||
return pCur->m_CreateFn();
|
||||
}
|
||||
}
|
||||
|
||||
if (pReturnCode)
|
||||
{
|
||||
*pReturnCode = IFACE_FAILED;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#if defined _LINUX || defined __APPLE__
|
||||
// Linux doesn't have this function so this emulates its functionality
|
||||
void *GetModuleHandle(const char *name)
|
||||
{
|
||||
void *handle;
|
||||
|
||||
if( name == NULL )
|
||||
{
|
||||
// hmm, how can this be handled under linux....
|
||||
// is it even needed?
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( (handle=dlopen(name, RTLD_NOW))==NULL)
|
||||
{
|
||||
printf("DLOPEN Error:%s\n",dlerror());
|
||||
// couldn't open this file
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// read "man dlopen" for details
|
||||
// in short dlopen() inc a ref count
|
||||
// so dec the ref count by performing the close
|
||||
dlclose(handle);
|
||||
return handle;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined( _WIN32 ) && !defined( _X360 )
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
bool Sys_IsDebuggerPresent()
|
||||
{
|
||||
return Plat_IsInDebugSession();
|
||||
}
|
||||
|
||||
struct ThreadedLoadLibaryContext_t
|
||||
{
|
||||
const char *m_pLibraryName;
|
||||
HMODULE m_hLibrary;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: get the interface for the specified module and version
|
||||
// Input :
|
||||
// Output :
|
||||
//-----------------------------------------------------------------------------
|
||||
bool Sys_LoadInterface(
|
||||
const char *pModuleName,
|
||||
const char *pInterfaceVersionName,
|
||||
HMODULE *pOutModule,
|
||||
void **pOutInterface )
|
||||
{
|
||||
HMODULE pMod = Plat_LoadModule( pModuleName );
|
||||
if ( !pMod )
|
||||
return false;
|
||||
|
||||
CreateInterfaceFn fn = Plat_GetModuleInterfaceFactory( pMod );
|
||||
if ( !fn )
|
||||
{
|
||||
Plat_UnloadModule( pMod );
|
||||
return false;
|
||||
}
|
||||
|
||||
*pOutInterface = fn( pInterfaceVersionName, NULL );
|
||||
if ( !( *pOutInterface ) )
|
||||
{
|
||||
Plat_UnloadModule( pMod );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( pOutModule )
|
||||
*pOutModule = pMod;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Place this as a singleton at module scope (e.g.) and use it to get the factory from the specified module name.
|
||||
//
|
||||
// When the singleton goes out of scope (.dll unload if at module scope),
|
||||
// then it'll call Sys_UnloadModule on the module so that the refcount is decremented
|
||||
// and the .dll actually can unload from memory.
|
||||
//-----------------------------------------------------------------------------
|
||||
CDllDemandLoader::CDllDemandLoader( char const *pchModuleName ) :
|
||||
m_pchModuleName( pchModuleName ),
|
||||
m_hModule( 0 ),
|
||||
m_bLoadAttempted( false )
|
||||
{
|
||||
}
|
||||
|
||||
CDllDemandLoader::~CDllDemandLoader()
|
||||
{
|
||||
Unload();
|
||||
}
|
||||
|
||||
CreateInterfaceFn CDllDemandLoader::GetFactory()
|
||||
{
|
||||
if ( !m_hModule && !m_bLoadAttempted )
|
||||
{
|
||||
m_bLoadAttempted = true;
|
||||
m_hModule = Plat_LoadModule( m_pchModuleName );
|
||||
}
|
||||
|
||||
if ( !m_hModule )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Plat_GetModuleInterfaceFactory( m_hModule );
|
||||
}
|
||||
|
||||
void CDllDemandLoader::Unload()
|
||||
{
|
||||
if ( m_hModule )
|
||||
{
|
||||
Plat_UnloadModule( m_hModule );
|
||||
m_hModule = 0;
|
||||
}
|
||||
}
|
@ -327,7 +327,6 @@
|
||||
<ClCompile Include="datamanager.cpp" />
|
||||
<ClCompile Include="diff.cpp" />
|
||||
<ClCompile Include="generichash.cpp" />
|
||||
<ClCompile Include="interface.cpp" />
|
||||
<ClCompile Include="KeyValues.cpp" />
|
||||
<ClCompile Include="mempool.cpp" />
|
||||
<ClCompile Include="memstack.cpp" />
|
||||
@ -366,7 +365,6 @@
|
||||
<ClInclude Include="..\public\tier1\functors.h" />
|
||||
<ClInclude Include="..\public\tier1\generichash.h" />
|
||||
<ClInclude Include="..\public\tier1\iconvar.h" />
|
||||
<ClInclude Include="..\public\tier1\interface.h" />
|
||||
<ClInclude Include="..\public\tier1\KeyValues.h" />
|
||||
<ClInclude Include="..\public\tier1\lzmaDecoder.h" />
|
||||
<ClInclude Include="..\public\tier1\lzss.h" />
|
||||
|
@ -41,9 +41,6 @@
|
||||
<ClCompile Include="generichash.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="interface.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="KeyValues.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -139,9 +136,6 @@
|
||||
<ClInclude Include="..\public\tier1\iconvar.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\public\tier1\interface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\public\tier1\KeyValues.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "tier0/platform.h"
|
||||
|
||||
#ifdef IS_WINDOWS_PC
|
||||
#include <windows.h> // UUIDCreate
|
||||
#include <Rpc.h> // UUIDCreate
|
||||
#else
|
||||
#include "checksum_crc.h"
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user