core/HalfLife2.cpp
changeset 1847 5336a438763f
parent 1690 7cc4f79a0416
child 1848 6214ae913a8a
     1.1 --- a/core/HalfLife2.cpp	Sun Jan 13 02:08:40 2008 +0000
     1.2 +++ b/core/HalfLife2.cpp	Sun Jan 13 08:10:25 2008 +0000
     1.3 @@ -70,7 +70,6 @@
     1.4  	for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++)
     1.5  	{
     1.6  		pInfo = (*iter);
     1.7 -		sm_trie_destroy(pInfo->lookup);
     1.8  		delete pInfo;
     1.9  	}
    1.10  
    1.11 @@ -115,6 +114,8 @@
    1.12  	m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
    1.13  	m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
    1.14  	g_ShareSys.AddInterface(NULL, this);
    1.15 +
    1.16 +	FindInSendTable("CTFPlayer", "m_nDisguiseClass");
    1.17  }
    1.18  
    1.19  #if !defined METAMOD_PLAPI_VERSION
    1.20 @@ -129,7 +130,10 @@
    1.21  	return engine->GetChangeAccessor( (const edict_t *)this );
    1.22  }
    1.23  
    1.24 -SendProp *UTIL_FindInSendTable(SendTable *pTable, const char *name)
    1.25 +bool UTIL_FindInSendTable(SendTable *pTable, 
    1.26 +						  const char *name,
    1.27 +						  sm_sendprop_info_t *info,
    1.28 +						  unsigned int offset)
    1.29  {
    1.30  	const char *pname;
    1.31  	int props = pTable->GetNumProps();
    1.32 @@ -141,13 +145,19 @@
    1.33  		pname = prop->GetName();
    1.34  		if (pname && strcmp(name, pname) == 0)
    1.35  		{
    1.36 -			return prop;
    1.37 +			info->prop = prop;
    1.38 +			info->actual_offset = offset + info->prop->GetOffset();
    1.39 +			return true;
    1.40  		}
    1.41  		if (prop->GetDataTable())
    1.42  		{
    1.43 -			if ((prop=UTIL_FindInSendTable(prop->GetDataTable(), name)) != NULL)
    1.44 +			if (UTIL_FindInSendTable(prop->GetDataTable(), 
    1.45 +				name,
    1.46 +				info,
    1.47 +				offset + prop->GetOffset())
    1.48 +				)
    1.49  			{
    1.50 -				return prop;
    1.51 +				return true;
    1.52  			}
    1.53  		}
    1.54  	}
    1.55 @@ -187,6 +197,7 @@
    1.56  ServerClass *CHalfLife2::FindServerClass(const char *classname)
    1.57  {
    1.58  	DataTableInfo *pInfo = _FindServerClass(classname);
    1.59 +
    1.60  	if (!pInfo)
    1.61  	{
    1.62  		return NULL;
    1.63 @@ -207,7 +218,6 @@
    1.64  			if (strcmp(classname, sc->GetName()) == 0)
    1.65  			{
    1.66  				pInfo = new DataTableInfo;
    1.67 -				pInfo->lookup = sm_trie_create();
    1.68  				pInfo->sc = sc;
    1.69  				sm_trie_insert(m_pClasses, classname, pInfo);
    1.70  				m_Tables.push_back(pInfo);
    1.71 @@ -224,25 +234,46 @@
    1.72  	return pInfo;
    1.73  }
    1.74  
    1.75 +bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info)
    1.76 +{
    1.77 +	DataTableInfo *pInfo;
    1.78 +	sm_sendprop_info_t *prop;
    1.79 +
    1.80 +	if ((pInfo = _FindServerClass(classname)) == NULL)
    1.81 +	{
    1.82 +		return false;
    1.83 +	}
    1.84 +
    1.85 +	if ((prop = pInfo->lookup.retrieve(offset)) == NULL)
    1.86 +	{
    1.87 +		sm_sendprop_info_t temp_info;
    1.88 +
    1.89 +		if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0))
    1.90 +		{
    1.91 +			return false;
    1.92 +		}
    1.93 +
    1.94 +		pInfo->lookup.insert(offset, temp_info);
    1.95 +		*info = temp_info;
    1.96 +	}
    1.97 +	else
    1.98 +	{
    1.99 +		*info = *prop;
   1.100 +	}
   1.101 +	
   1.102 +	return true;
   1.103 +}
   1.104 +
   1.105  SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
   1.106  {
   1.107 -	DataTableInfo *pInfo = _FindServerClass(classname);
   1.108 +	sm_sendprop_info_t info;
   1.109  
   1.110 -	if (!pInfo)
   1.111 +	if (!FindSendPropInfo(classname, offset, &info))
   1.112  	{
   1.113  		return NULL;
   1.114  	}
   1.115  
   1.116 -	SendProp *pProp = NULL;
   1.117 -	if (!sm_trie_retrieve(pInfo->lookup, offset, (void **)&pProp))
   1.118 -	{
   1.119 -		if ((pProp = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset)) != NULL)
   1.120 -		{
   1.121 -			sm_trie_insert(pInfo->lookup, offset, pProp);
   1.122 -		}
   1.123 -	}
   1.124 -
   1.125 -	return pProp;
   1.126 +	return info.prop;
   1.127  }
   1.128  
   1.129  typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset)
   1.130 @@ -272,7 +303,9 @@
   1.131  		if (offset)
   1.132  		{
   1.133  			pEdict->StateChanged(offset);
   1.134 -		} else {
   1.135 +		}
   1.136 +		else
   1.137 +		{
   1.138  			pEdict->StateChanged();
   1.139  		}
   1.140  	}