metamod/dllapi.cpp
branchB-work
changeset 217 43ad553832f6
parent 209 812e3285c758
child 223 fa27b9403af3
     1.1 --- a/metamod/dllapi.cpp	Sat Apr 08 18:26:13 2006 +0000
     1.2 +++ b/metamod/dllapi.cpp	Sat Apr 08 19:29:39 2006 +0000
     1.3 @@ -340,7 +340,7 @@
     1.4  
     1.5  // From SDK dlls/cbase.cpp:
     1.6  // "(wd)" indicates my comments on the functions
     1.7 -DLL_FUNCTIONS gFunctionTable = 
     1.8 +static DLL_FUNCTIONS sFunctionTable = 
     1.9  {
    1.10  	mm_GameDLLInit,				//! pfnGameInit()				Initialize the game (one-time call after loading of game .dll)
    1.11  	mm_DispatchSpawn,				//! pfnSpawn()
    1.12 @@ -404,7 +404,7 @@
    1.13  	mm_AllowLagCompensation,		//! pfnAllowLagCompensation()	(wd) SDK2
    1.14  };
    1.15  
    1.16 -DLL_FUNCTIONS *pHookedDllFunctions = &gFunctionTable;
    1.17 +DLL_FUNCTIONS *pHookedDllFunctions = &sFunctionTable;
    1.18  
    1.19  // It's not clear what the difference is between GetAPI and GetAPI2; they
    1.20  // both appear to return the exact same function table.  
    1.21 @@ -433,13 +433,37 @@
    1.22  		META_ERROR("GetEntityAPI version mismatch; requested=%d ours=%d", interfaceVersion, INTERFACE_VERSION);
    1.23  		return(FALSE);
    1.24  	}
    1.25 -	memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
    1.26 +
    1.27 +//+TBR
    1.28 +#ifdef MM_DEBUG	
    1.29 +	META_LOG( "==DEBUG==> [GetEntityAPI] Setting up engine's DLL_FUNCTIONS struct @%p, version %u.", 
    1.30 +				pFunctionTable, interfaceVersion);
    1.31 +	META_LOG( "==DEBUG==> [GetEntityAPI] Our version is %u. Our current table size is %u, %u entries.", 
    1.32 +				INTERFACE_VERSION,  sizeof(DLL_FUNCTIONS),
    1.33 +				sizeof(DLL_FUNCTIONS) / sizeof(void(*)()));
    1.34 +#endif
    1.35 +//-TBR
    1.36 +	
    1.37 +	memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
    1.38 +
    1.39 +//+TBR
    1.40 +#ifdef MM_DEBUG
    1.41 +	if ( g_engfuncs.pfnIsDedicatedServer() ) {
    1.42 +		META_LOG( "==DEBUG==> [GetEntityAPI] Engine says this is a dedicated server.\n" );
    1.43 +	} 
    1.44 +	else {
    1.45 +		META_LOG( "==DEBUG==> [GetEntityAPI] Engine says this is a listenserver.\n" );
    1.46 +	}
    1.47 +#endif
    1.48 +//-TBR
    1.49 +
    1.50  	return(TRUE);
    1.51  }
    1.52  
    1.53  C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersion)
    1.54  {
    1.55  	META_DEBUG(3, ("called: GetEntityAPI2; version=%d", *interfaceVersion));
    1.56 +
    1.57  	if(!pFunctionTable) {
    1.58  		META_ERROR("GetEntityAPI2 called with null pFunctionTable");
    1.59  		return(FALSE);
    1.60 @@ -450,7 +474,30 @@
    1.61  		*interfaceVersion = INTERFACE_VERSION;
    1.62  		return(FALSE);
    1.63  	}
    1.64 -	memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));
    1.65 +
    1.66 +//+TBR
    1.67 +#ifdef MM_DEBUG
    1.68 +	META_LOG( "==DEBUG==> [GetEntityAPI2] Setting up engine's DLL_FUNCTIONS struct @%p, version %u.", 
    1.69 +				pFunctionTable, *interfaceVersion);
    1.70 +	META_LOG( "==DEBUG==> [GetEntityAPI2] Our version is %u. Our current table size is %u, %u entries.", 
    1.71 +				INTERFACE_VERSION,  sizeof(DLL_FUNCTIONS),
    1.72 +				sizeof(DLL_FUNCTIONS) / sizeof(void(*)()) );
    1.73 +#endif
    1.74 +//-TBR
    1.75 +	
    1.76 +	memcpy(pFunctionTable, &sFunctionTable, sizeof(DLL_FUNCTIONS));
    1.77 +
    1.78 +//+TBR
    1.79 +#ifdef MM_DEBUG
    1.80 +	if ( g_engfuncs.pfnIsDedicatedServer() ) {
    1.81 +		META_LOG( "==DEBUG==> [GetEntityAPI2] Engine says this is a dedicated server.\n" );
    1.82 +	} 
    1.83 +	else {
    1.84 +		META_LOG( "==DEBUG==> [GetEntityAPI2] Engine says this is a listenserver.\n" );
    1.85 +	}
    1.86 +#endif
    1.87 +//-TBR
    1.88 +
    1.89  	return(TRUE);
    1.90  }
    1.91  
    1.92 @@ -466,20 +513,20 @@
    1.93  //
    1.94  // Interestingly, it appears to be called by the engine _before_ GetAPI.
    1.95  
    1.96 -static NEW_DLL_FUNCTIONS gNewFunctionTable = 
    1.97 -{
    1.98 -	mm_OnFreeEntPrivateData,		//! pfnOnFreeEntPrivateData()	Called right before the object's memory is freed.  Calls its destructor.
    1.99 -	mm_GameShutdown,				//! pfnGameShutdown()
   1.100 -	mm_ShouldCollide,				//! pfnShouldCollide()
   1.101 +static meta_new_dll_functions_t sNewFunctionTable (
   1.102 +	&mm_OnFreeEntPrivateData,		//! pfnOnFreeEntPrivateData()	Called right before the object's memory is freed.  Calls its destructor.
   1.103 +	&mm_GameShutdown,				//! pfnGameShutdown()
   1.104 +	&mm_ShouldCollide,				//! pfnShouldCollide()
   1.105  	// Added 2005-08-11 (no SDK update)
   1.106 -	mm_CvarValue,					//! pfnCvarValue()      (fz) Obsolete!  Use mm_CvarValue2 instead
   1.107 +	&mm_CvarValue,					//! pfnCvarValue()      (fz) Obsolete!  Use mm_CvarValue2 instead
   1.108  	// Added 2005-11-22 (no SDK update)
   1.109 -	mm_CvarValue2,					//! pfnCvarValue2()     (fz) When pfnQueryClientCvarValue2() completes it will call
   1.110 +	&mm_CvarValue2					//! pfnCvarValue2()     (fz) When pfnQueryClientCvarValue2() completes it will call
   1.111  									//!                     pfnCvarValue2() with the request ID supplied earlier, the name of
   1.112  									//!                     the cvar requested and the value of that cvar.
   1.113 -};
   1.114 +);
   1.115  
   1.116 -NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &gNewFunctionTable;
   1.117 +
   1.118 +NEW_DLL_FUNCTIONS *pHookedNewDllFunctions = &sNewFunctionTable;
   1.119  
   1.120  C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion) 
   1.121  {
   1.122 @@ -502,17 +549,29 @@
   1.123  		*interfaceVersion = NEW_DLL_FUNCTIONS_VERSION;
   1.124  		return(FALSE);
   1.125  	}
   1.126 -	
   1.127 -	// Detect old engines
   1.128 -	if (!IS_VALID_PTR((void *)g_engfuncs.pfnQueryClientCvarValue2))
   1.129 -	{
   1.130 -		if (!IS_VALID_PTR((void *)g_engfuncs.pfnQueryClientCvarValue))
   1.131 -			memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS) - sizeof(FN_CVARVALUE) - sizeof(FN_CVARVALUE2));
   1.132 -		else
   1.133 -			memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS) - sizeof(FN_CVARVALUE2));
   1.134 -	} else {
   1.135 -        memcpy(pNewFunctionTable, &gNewFunctionTable, sizeof(NEW_DLL_FUNCTIONS));
   1.136 +//+TBR
   1.137 +#ifdef MM_DEBUG
   1.138 +	META_LOG( "==DEBUG==> [GetNewDLLFunctions] Setting up engine's NEW_DLL_FUNCTIONS struct @%p, version %u.",
   1.139 +				pNewFunctionTable, *interfaceVersion);
   1.140 +	META_LOG( "==DEBUG==> [GetNewDLLFunctions] Our version is %u. Our current table size is %u, %u entries.",
   1.141 +				NEW_DLL_FUNCTIONS_VERSION,  sizeof(NEW_DLL_FUNCTIONS),
   1.142 +				sizeof(NEW_DLL_FUNCTIONS) / sizeof(void(*)()) );
   1.143 +#endif
   1.144 +//-TBR
   1.145 +
   1.146 +	sNewFunctionTable.copy_to(pNewFunctionTable);
   1.147 +
   1.148 +//+TBR
   1.149 +#ifdef MM_DEBUG
   1.150 +	if ( g_engfuncs.pfnIsDedicatedServer() ) {
   1.151 +		META_LOG( "==DEBUG==> [GetNewDLLFunctions] Engine says this is a dedicated server.\n" );
   1.152 +	} 
   1.153 +	else {
   1.154 +		META_LOG( "==DEBUG==> [GetNewDLLFunctions] Engine says this is a listenserver.\n" );
   1.155  	}
   1.156 +#endif
   1.157 +//-TBR
   1.158  
   1.159  	return(TRUE);
   1.160  }
   1.161 +