diff --git a/extension.cpp b/extension.cpp index e62dff0..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: @@ -229,6 +261,8 @@ CDetour *g_pDetour_SwingOrStab = NULL; int g_SH_SkipTwoEntitiesShouldHitEntity = 0; int g_SH_SimpleShouldHitEntity = 0; +int g_iMaxPlayers = 0; + uintptr_t g_CTraceFilterNoNPCsOrPlayer = 0; CTraceFilterSkipTwoEntities *g_CTraceFilterSkipTwoEntities = NULL; CTraceFilterSimple *g_CTraceFilterSimple = NULL; @@ -322,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) { @@ -334,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); } @@ -384,7 +439,7 @@ bool ShouldHitEntity(IHandleEntity *pHandleEntity, int contentsMask) int iTeam = 0; - if(index > SM_MAXPLAYERS && g_pPhysboxToClientMap && index < 2048) + if(index > g_iMaxPlayers && g_pPhysboxToClientMap && index < 2048) { index = g_pPhysboxToClientMap[index]; } @@ -393,7 +448,7 @@ bool ShouldHitEntity(IHandleEntity *pHandleEntity, int contentsMask) { iTeam = -index; } - else if(index < 1 || index > SM_MAXPLAYERS) + else if(index < 1 || index > g_iMaxPlayers) { RETURN_META_VALUE(MRES_IGNORED, true); } @@ -505,6 +560,8 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) { srand((unsigned int)time(NULL)); + g_iMaxPlayers = playerhelpers->GetMaxClients(); + char conf_error[255] = ""; if(!gameconfs->LoadGameConfigFile("CSSFixes", &g_pGameConf, conf_error, sizeof(conf_error))) {