diff --git a/extension.cpp b/extension.cpp index 7c32bf0..1eb283e 100644 --- a/extension.cpp +++ b/extension.cpp @@ -76,6 +76,38 @@ bool UTIL_ContainsDataTable(SendTable *pTable, const char *name) return false; } +void UTIL_StringToVector( float *pVector, const char *pString ) +{ + char *pstr, *pfront, tempString[128]; + int j; + + Q_strncpy( tempString, pString, sizeof(tempString) ); + pstr = pfront = tempString; + + for ( j = 0; j < 3; j++ ) // lifted from pr_edict.c + { + pVector[j] = atof( pfront ); + + // skip any leading whitespace + while ( *pstr && *pstr <= ' ' ) + pstr++; + + // skip to next whitespace + while ( *pstr && *pstr > ' ' ) + pstr++; + + if (!*pstr) + break; + + pstr++; + pfront = pstr; + } + for ( j++; j < 3; j++ ) + { + pVector[j] = 0; + } +} + class CTraceFilterSimple : public CTraceFilter { public: @@ -324,10 +356,13 @@ DETOUR_DECL_STATIC2(DETOUR_CreateEntityByName, CBaseEntity*, const char*, classN DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char *, szValue) { + CBaseEntity *pEntity = (CBaseEntity *)this; + // Fix crash bug in engine if(strcasecmp(szKeyName, "angle") == 0) + { szKeyName = "angles"; - + } else if(strcasecmp(szKeyName, "classname") == 0 && strcasecmp(szValue, "info_player_terrorist") == 0) { @@ -336,13 +371,31 @@ DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char * } else if(strcasecmp(szKeyName, "teamnum") == 0 || strcasecmp(szKeyName, "teamnum") == 0 ) { - CBaseEntity *pEntity = (CBaseEntity *)this; const char *pClassname = gamehelpers->GetEntityClassname(pEntity); // All buyzones should be CT buyzones if(pClassname && strcasecmp(pClassname, "func_buyzone") == 0) szValue = "3"; } + else if(strcasecmp(szKeyName, "absvelocity") == 0) + { + static int m_AbsVelocity_offset = 0; + + if (!m_AbsVelocity_offset) + { + datamap_t *pDataMap = gamehelpers->GetDataMap(pEntity); + sm_datatable_info_t info; + + gamehelpers->FindDataMapInfo(pDataMap, "m_vecAbsVelocity", &info); + m_AbsVelocity_offset = info.actual_offset; + } + + float tmp[3]; + UTIL_StringToVector(tmp, szValue); + + Vector *vecAbsVelocity = (Vector*)((uint8_t*)pEntity + m_AbsVelocity_offset); + vecAbsVelocity->Init(tmp[0], tmp[1], tmp[2]); + } return DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue); }