Improve logical entity support in SDKHooks natives (bug 6069, r=asherkin).
This commit is contained in:
		
							parent
							
								
									9215ddcf8a
								
							
						
					
					
						commit
						451c90b932
					
				| @ -528,7 +528,7 @@ HookReturn SDKHooks::Hook(int entity, SDKHookType type, IPluginFunction *callbac | |||||||
| 	if(!g_HookTypes[type].supported) | 	if(!g_HookTypes[type].supported) | ||||||
| 		return HookRet_NotSupported; | 		return HookRet_NotSupported; | ||||||
| 
 | 
 | ||||||
| 	CBaseEntity *pEnt = UTIL_GetCBaseEntity(entity); | 	CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(entity); | ||||||
| 	if(!pEnt) | 	if(!pEnt) | ||||||
| 		return HookRet_InvalidEntity; | 		return HookRet_InvalidEntity; | ||||||
| 	if(type < 0 || type >= SDKHook_MAXHOOKS) | 	if(type < 0 || type >= SDKHook_MAXHOOKS) | ||||||
|  | |||||||
| @ -58,14 +58,15 @@ cell_t Native_Hook(IPluginContext *pContext, const cell_t *params) | |||||||
| 			break; | 			break; | ||||||
| 		case HookRet_BadEntForHookType: | 		case HookRet_BadEntForHookType: | ||||||
| 		{ | 		{ | ||||||
| 			const char * pClassname = gamehelpers->GetEntityClassname(PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[1]))); | 			CBaseEntity *pEnt = gamehelpers->ReferenceToEntity(params[1]); | ||||||
| 			if (!pClassname) | 			const char *pClassname = pEnt ? gamehelpers->GetEntityClassname(pEnt) : NULL; | ||||||
| 			{ | 			if (!pClassname) | ||||||
| 				pContext->ThrowNativeError("Hook type not valid for this type of entity (%i).", entity); | 			{ | ||||||
| 			} | 				pContext->ThrowNativeError("Hook type not valid for this type of entity (%i).", entity); | ||||||
| 			else | 			} | ||||||
| 			{ | 			else | ||||||
| 				pContext->ThrowNativeError("Hook type not valid for this type of entity (%s)", pClassname); | 			{ | ||||||
|  | 				pContext->ThrowNativeError("Hook type not valid for this type of entity (%i/%s)", entity, pClassname); | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			break; | 			break; | ||||||
| @ -108,18 +109,18 @@ cell_t Native_TakeDamage(IPluginContext *pContext, const cell_t *params) | |||||||
| #if !defined SH_DECL_MANUALEXTERN1 | #if !defined SH_DECL_MANUALEXTERN1 | ||||||
| 	pContext->ThrowNativeError("SDKHooks_TakeDamage is not supported on this engine."); | 	pContext->ThrowNativeError("SDKHooks_TakeDamage is not supported on this engine."); | ||||||
| #else | #else | ||||||
| 	CBaseEntity *pVictim = UTIL_GetCBaseEntity(params[1]); | 	CBaseEntity *pVictim = gamehelpers->ReferenceToEntity(params[1]); | ||||||
| 	if (!pVictim) | 	if (!pVictim) | ||||||
| 		return pContext->ThrowNativeError("Invalid entity index %d for victim", params[1]); | 		return pContext->ThrowNativeError("Invalid entity index %d for victim", params[1]); | ||||||
| 	 | 	 | ||||||
| 	CBaseEntity *pInflictor = UTIL_GetCBaseEntity(params[2]); | 	CBaseEntity *pInflictor = gamehelpers->ReferenceToEntity(params[2]); | ||||||
| 	if (!pInflictor) | 	if (!pInflictor) | ||||||
| 		return pContext->ThrowNativeError("Invalid entity index %d for inflictor", params[2]); | 		return pContext->ThrowNativeError("Invalid entity index %d for inflictor", params[2]); | ||||||
| 
 | 
 | ||||||
| 	CBaseEntity *pAttacker; | 	CBaseEntity *pAttacker; | ||||||
| 	if (params[3] != -1) | 	if (params[3] != -1) | ||||||
| 	{ | 	{ | ||||||
| 		pAttacker = UTIL_GetCBaseEntity(params[3]); | 		pAttacker = gamehelpers->ReferenceToEntity(params[3]); | ||||||
| 		if (!pAttacker) | 		if (!pAttacker) | ||||||
| 		{ | 		{ | ||||||
| 			return pContext->ThrowNativeError("Invalid entity index %d for attackerr", params[3]); | 			return pContext->ThrowNativeError("Invalid entity index %d for attackerr", params[3]); | ||||||
| @ -136,7 +137,7 @@ cell_t Native_TakeDamage(IPluginContext *pContext, const cell_t *params) | |||||||
| 	CBaseEntity *pWeapon; | 	CBaseEntity *pWeapon; | ||||||
| 	if (params[6] != -1) | 	if (params[6] != -1) | ||||||
| 	{ | 	{ | ||||||
| 		pWeapon = UTIL_GetCBaseEntity(params[6]); | 		pWeapon = gamehelpers->ReferenceToEntity(params[6]); | ||||||
| 		if (!pWeapon) | 		if (!pWeapon) | ||||||
| 		{ | 		{ | ||||||
| 			return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[6]); | 			return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[6]); | ||||||
| @ -192,11 +193,15 @@ cell_t Native_DropWeapon(IPluginContext *pContext, const cell_t *params) | |||||||
| #if !defined SH_DECL_MANUALEXTERN1 | #if !defined SH_DECL_MANUALEXTERN1 | ||||||
| 	pContext->ThrowNativeError("SDKHooks_DropWeapon is not supported on this engine."); | 	pContext->ThrowNativeError("SDKHooks_DropWeapon is not supported on this engine."); | ||||||
| #else | #else | ||||||
| 	CBaseEntity *pPlayer = UTIL_GetCBaseEntity(params[1], true); | 	CBaseEntity *pPlayer = gamehelpers->ReferenceToEntity(params[1]); | ||||||
| 	if (!pPlayer) | 	if (!pPlayer) | ||||||
| 		return pContext->ThrowNativeError("Invalid client index %d", params[1]); | 		return pContext->ThrowNativeError("Invalid client index %d", params[1]); | ||||||
|  | 
 | ||||||
|  | 	IGamePlayer *pGamePlayer = playerhelpers->GetGamePlayer(gamehelpers->ReferenceToIndex(params[1])); | ||||||
|  | 	if (!pGamePlayer || !pGamePlayer->IsInGame()) | ||||||
|  | 		return pContext->ThrowNativeError("Client index %d not in game", params[1]); | ||||||
| 	 | 	 | ||||||
| 	CBaseEntity *pWeapon = UTIL_GetCBaseEntity(params[2]); | 	CBaseEntity *pWeapon = gamehelpers->ReferenceToEntity(params[2]); | ||||||
| 	if (!pWeapon) | 	if (!pWeapon) | ||||||
| 		return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[2]); | 		return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[2]); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -34,36 +34,6 @@ | |||||||
| #include "extension.h" | #include "extension.h" | ||||||
| #include "util.h" | #include "util.h" | ||||||
| 
 | 
 | ||||||
| CBaseEntity *UTIL_GetCBaseEntity(int num, bool onlyPlayers) |  | ||||||
| { |  | ||||||
| 	edict_t *pEdict = PEntityOfEntIndex(num); |  | ||||||
| 	if (!pEdict || pEdict->IsFree()) |  | ||||||
| 	{ |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (num > 0 && num <= playerhelpers->GetMaxClients()) |  | ||||||
| 	{ |  | ||||||
| 		IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(pEdict); |  | ||||||
| 		if (!pPlayer || !pPlayer->IsConnected()) |  | ||||||
| 		{ |  | ||||||
| 			return NULL; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	else if (onlyPlayers) |  | ||||||
| 	{ |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	IServerUnknown *pUnk; |  | ||||||
| 	if ((pUnk=pEdict->GetUnknown()) == NULL) |  | ||||||
| 	{ |  | ||||||
| 		return NULL; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	return pUnk->GetBaseEntity(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| bool UTIL_ContainsDataTable(SendTable *pTable, const char *name) | bool UTIL_ContainsDataTable(SendTable *pTable, const char *name) | ||||||
| { | { | ||||||
| 	const char *pname = pTable->GetName(); | 	const char *pname = pTable->GetName(); | ||||||
|  | |||||||
| @ -34,7 +34,6 @@ | |||||||
| 
 | 
 | ||||||
| #include <compat_wrappers.h> | #include <compat_wrappers.h> | ||||||
| 
 | 
 | ||||||
| CBaseEntity *UTIL_GetCBaseEntity(int num, bool onlyPlayers=false); |  | ||||||
| bool UTIL_ContainsDataTable(SendTable *pTable, const char *name); | bool UTIL_ContainsDataTable(SendTable *pTable, const char *name); | ||||||
| 
 | 
 | ||||||
| #endif  //_INCLUDE_TF2TOOLS_UTIL_H_
 | #endif  //_INCLUDE_TF2TOOLS_UTIL_H_
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user