extensions/sdktools/vhelpers.cpp
changeset 4169 65eebc76e836
parent 4159 08f0f6c1e452
child 4272 8b39aa02b05b
     1.1 --- a/extensions/sdktools/vhelpers.cpp	Sun Nov 03 09:39:49 2013 -0500
     1.2 +++ b/extensions/sdktools/vhelpers.cpp	Tue Nov 05 20:32:37 2013 -0500
     1.3 @@ -502,6 +502,63 @@
     1.4  }
     1.5  #endif
     1.6  
     1.7 +CEntityFactoryDictionary *GetEntityFactoryDictionary()
     1.8 +{
     1.9 +	static CEntityFactoryDictionary *dict = NULL;
    1.10 +
    1.11 +#if SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_SDK2013
    1.12 +	dict = (CEntityFactoryDictionary *) servertools->GetEntityFactoryDictionary();
    1.13 +#else
    1.14 +	if (dict == NULL)
    1.15 +	{
    1.16 +		void *addr;
    1.17 +		if (g_pGameConf->GetMemSig("EntityFactoryFinder", (void **) &addr) && addr)
    1.18 +		{
    1.19 +			int offset;
    1.20 +			if (!g_pGameConf->GetOffset("EntityFactoryOffset", &offset) || !offset)
    1.21 +			{
    1.22 +				return NULL;
    1.23 +			}
    1.24 +			dict = *reinterpret_cast<CEntityFactoryDictionary **>((intptr_t) addr + offset);
    1.25 +		}
    1.26 +	}
    1.27 +
    1.28 +	if (dict == NULL)
    1.29 +	{
    1.30 +		ICallWrapper *pWrapper = NULL;
    1.31 +
    1.32 +		PassInfo retData;
    1.33 +		retData.flags = PASSFLAG_BYVAL;
    1.34 +		retData.size = sizeof(void *);
    1.35 +		retData.type = PassType_Basic;
    1.36 +
    1.37 +		void *addr;
    1.38 +		if (g_pGameConf->GetMemSig("EntityFactory", &addr) && addr != NULL)
    1.39 +		{
    1.40 +			pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
    1.41 +		}
    1.42 +
    1.43 +		if (pWrapper)
    1.44 +		{
    1.45 +			void *returnData = NULL;
    1.46 +
    1.47 +			pWrapper->Execute(NULL, &returnData);
    1.48 +
    1.49 +			pWrapper->Destroy();
    1.50 +
    1.51 +			if (returnData == NULL)
    1.52 +			{
    1.53 +				return NULL;
    1.54 +			}
    1.55 +
    1.56 +			dict = (CEntityFactoryDictionary *) returnData;
    1.57 +		}
    1.58 +	}
    1.59 +#endif
    1.60 +
    1.61 +	return dict;
    1.62 +}
    1.63 +
    1.64  CON_COMMAND(sm_dump_classes, "Dumps the class list as a text file")
    1.65  {
    1.66  #if SOURCE_ENGINE <= SE_DARKMESSIAH
    1.67 @@ -521,39 +578,10 @@
    1.68  		return;
    1.69  	}
    1.70  
    1.71 -	CEntityFactoryDictionary *dict = NULL;
    1.72 -
    1.73 -#if SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_SDK2013
    1.74 -	dict = (CEntityFactoryDictionary *)servertools->GetEntityFactoryDictionary();
    1.75 -#else
    1.76 -
    1.77 -	ICallWrapper *pWrapper = NULL;
    1.78 -
    1.79 -	if (!pWrapper)
    1.80 -	{
    1.81 -		PassInfo retData;
    1.82 -		retData.flags = PASSFLAG_BYVAL;
    1.83 -		retData.size = sizeof(void *);
    1.84 -		retData.type = PassType_Basic;
    1.85 -
    1.86 -		void *addr;
    1.87 -		if (!g_pGameConf->GetMemSig("EntityFactory", &addr) || addr == NULL)
    1.88 -		{
    1.89 -			META_CONPRINT("Failed to locate function\n");
    1.90 -			return;
    1.91 -		}
    1.92 -
    1.93 -		pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
    1.94 -	}
    1.95 -
    1.96 -	pWrapper->Execute(NULL, &dict);
    1.97 -
    1.98 -	pWrapper->Destroy();
    1.99 -
   1.100 -#endif
   1.101 -
   1.102 +	CEntityFactoryDictionary *dict = GetEntityFactoryDictionary();
   1.103  	if (dict == NULL)
   1.104  	{
   1.105 +		META_CONPRINT("Failed to locate function\n");
   1.106  		return;
   1.107  	}
   1.108  
   1.109 @@ -714,53 +742,7 @@
   1.110  		return;
   1.111  	}
   1.112  
   1.113 -	static CEntityFactoryDictionary *dict = NULL;
   1.114 -	if (dict == NULL)
   1.115 -	{
   1.116 -		void *addr;
   1.117 -		if (g_pGameConf->GetMemSig("EntityFactoryFinder", (void **)&addr) && addr)
   1.118 -		{
   1.119 -			int offset;
   1.120 -			if (!g_pGameConf->GetOffset("EntityFactoryOffset", &offset) || !offset)
   1.121 -			{
   1.122 -				return;
   1.123 -			}
   1.124 -			dict = *reinterpret_cast<CEntityFactoryDictionary **>((intptr_t)addr + offset);
   1.125 -		}
   1.126 -	}
   1.127 -
   1.128 -	if (dict == NULL)
   1.129 -	{
   1.130 -		ICallWrapper *pWrapper = NULL;
   1.131 -
   1.132 -		PassInfo retData;
   1.133 -		retData.flags = PASSFLAG_BYVAL;
   1.134 -		retData.size = sizeof(void *);
   1.135 -		retData.type = PassType_Basic;
   1.136 -
   1.137 -		void *addr;
   1.138 -		if (g_pGameConf->GetMemSig("EntityFactory", &addr) && addr != NULL)
   1.139 -		{
   1.140 -			pWrapper = g_pBinTools->CreateCall(addr, CallConv_Cdecl, &retData, NULL, 0);
   1.141 -		}
   1.142 -
   1.143 -		if (pWrapper)
   1.144 -		{
   1.145 -			void *returnData = NULL;
   1.146 -
   1.147 -			pWrapper->Execute(NULL, &returnData);
   1.148 -
   1.149 -			pWrapper->Destroy();
   1.150 -
   1.151 -			if (returnData == NULL)
   1.152 -			{
   1.153 -				return;
   1.154 -			}
   1.155 -
   1.156 -			dict = ( CEntityFactoryDictionary * )returnData;
   1.157 -		}
   1.158 -	}
   1.159 -
   1.160 +	CEntityFactoryDictionary *dict = GetEntityFactoryDictionary();
   1.161  	if ( dict == NULL )
   1.162  	{
   1.163  		META_CONPRINT("Failed to locate function\n");