Add more natives!
This commit is contained in:
		
							parent
							
								
									cf6d35365e
								
							
						
					
					
						commit
						50b7eb0def
					
				| @ -71,3 +71,32 @@ void DHooksEntityListener::OnEntityDestroyed(CBaseEntity *pEntity) | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | bool DHooksEntityListener::AddPluginEntityListener(ListenType type, IPluginFunction *callback) | ||||||
|  | { | ||||||
|  | 	for(int i = g_EntityListeners.Count() -1; i >= 0; i--) | ||||||
|  | 	{ | ||||||
|  | 		EntityListener listerner = g_EntityListeners.Element(i); | ||||||
|  | 		if(listerner.callback == callback && listerner.type == type) | ||||||
|  | 		{ | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	EntityListener listener; | ||||||
|  | 	listener.callback = callback; | ||||||
|  | 	listener.type = type; | ||||||
|  | 	g_EntityListeners.AddToTail(listener); | ||||||
|  | 	return true; | ||||||
|  | } | ||||||
|  | bool DHooksEntityListener::RemovePluginEntityListener(ListenType type, IPluginFunction *callback) | ||||||
|  | { | ||||||
|  | 	for(int i = g_EntityListeners.Count() -1; i >= 0; i--) | ||||||
|  | 	{ | ||||||
|  | 		EntityListener listerner = g_EntityListeners.Element(i); | ||||||
|  | 		if(listerner.callback == callback && listerner.type == type) | ||||||
|  | 		{ | ||||||
|  | 			g_EntityListeners.Remove(i); | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return false; | ||||||
|  | } | ||||||
|  | |||||||
							
								
								
									
										17
									
								
								listeners.h
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								listeners.h
									
									
									
									
									
								
							| @ -1,9 +1,15 @@ | |||||||
| #ifndef _INCLUDE_FORWARDS_H_ | #ifndef _INCLUDE_LISTENERS_H_ | ||||||
| #define _INCLUDE_FORWARDS_H_ | #define _INCLUDE_LISTENERS_H_ | ||||||
| 
 | 
 | ||||||
| #include "extension.h" | #include "extension.h" | ||||||
| #include "vhook.h" | #include "vhook.h" | ||||||
| 
 | 
 | ||||||
|  | enum ListenType | ||||||
|  | { | ||||||
|  | 	ListenType_Created, | ||||||
|  | 	ListenType_Deleted | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| class DHooksEntityListener : public ISMEntityListener | class DHooksEntityListener : public ISMEntityListener | ||||||
| { | { | ||||||
| public: | public: | ||||||
| @ -11,13 +17,10 @@ public: | |||||||
| 	virtual void OnEntityDestroyed(CBaseEntity *pEntity); | 	virtual void OnEntityDestroyed(CBaseEntity *pEntity); | ||||||
| 	void CleanupListeners(IPluginContext *func); | 	void CleanupListeners(IPluginContext *func); | ||||||
| 	virtual void LevelShutdown(); | 	virtual void LevelShutdown(); | ||||||
|  | 	bool AddPluginEntityListener(ListenType type, IPluginFunction *callback); | ||||||
|  | 	bool RemovePluginEntityListener(ListenType type, IPluginFunction *callback); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| enum ListenType |  | ||||||
| { |  | ||||||
| 	ListenType_Created, |  | ||||||
| 	ListenType_Deleted |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| struct EntityListener | struct EntityListener | ||||||
| { | { | ||||||
|  | |||||||
							
								
								
									
										61
									
								
								natives.cpp
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								natives.cpp
									
									
									
									
									
								
							| @ -520,6 +520,59 @@ cell_t Native_SetParamString(IPluginContext *pContext, const cell_t *params) | |||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | //native DHookAddEntityListener(ListenType:type, ListenCB:callback);
 | ||||||
|  | cell_t Native_AddEntityListener(IPluginContext *pContext, const cell_t *params) | ||||||
|  | { | ||||||
|  | 	if(g_pEntityListener) | ||||||
|  | 	{ | ||||||
|  | 		return g_pEntityListener->AddPluginEntityListener((ListenType)params[1], pContext->GetFunctionById(params[2]));; | ||||||
|  | 	} | ||||||
|  | 	return pContext->ThrowNativeError("Failed to get g_pEntityListener"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //native bool:DHookRemoveEntityListener(ListenType:type, ListenCB:callback);
 | ||||||
|  | cell_t Native_RemoveEntityListener(IPluginContext *pContext, const cell_t *params) | ||||||
|  | { | ||||||
|  | 	if(g_pEntityListener) | ||||||
|  | 	{ | ||||||
|  | 		return g_pEntityListener->RemovePluginEntityListener((ListenType)params[1], pContext->GetFunctionById(params[2]));; | ||||||
|  | 	} | ||||||
|  | 	return pContext->ThrowNativeError("Failed to get g_pEntityListener"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //native bool:DHookIsNullParam(Handle:hParams, num);
 | ||||||
|  | cell_t Native_IsNullParam(IPluginContext *pContext, const cell_t *params) | ||||||
|  | { | ||||||
|  | 	if(params[1] == BAD_HANDLE) | ||||||
|  | 	{ | ||||||
|  | 		return pContext->ThrowNativeError("Invalid Handle %i", BAD_HANDLE); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	HandleError err; | ||||||
|  | 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); | ||||||
|  | 	HookParamsStruct *paramStruct; | ||||||
|  | 
 | ||||||
|  | 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | ||||||
|  | 	{ | ||||||
|  | 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
|  | 	{ | ||||||
|  | 		return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.Count()); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	int index = params[2] - 1; | ||||||
|  | 
 | ||||||
|  | 	HookParamType type = paramStruct->dg->params.Element(index).type; | ||||||
|  | 
 | ||||||
|  | 	//Check that the type is ptr
 | ||||||
|  | 	if(type == HookParamType_StringPtr || type == HookParamType_CharPtr || type == HookParamType_VectorPtr || type == HookParamType_CBaseEntity || type == HookParamType_ObjectPtr || type == HookParamType_Edict || type == HookParamType_Unknown) | ||||||
|  | 		return (paramStruct->orgParams[index] == NULL); | ||||||
|  | 	else | ||||||
|  | 		return pContext->ThrowNativeError("Param is not a pointer!"); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| sp_nativeinfo_t g_Natives[] =  | sp_nativeinfo_t g_Natives[] =  | ||||||
| { | { | ||||||
| 	{"DHookCreate",							Native_CreateHook}, | 	{"DHookCreate",							Native_CreateHook}, | ||||||
| @ -540,12 +593,12 @@ sp_nativeinfo_t g_Natives[] = | |||||||
| 	//{"DHookGetReturnString",				Native_GetReturnString},
 | 	//{"DHookGetReturnString",				Native_GetReturnString},
 | ||||||
| 	//{"DHookSetReturnString",				Native_SetReturnString},
 | 	//{"DHookSetReturnString",				Native_SetReturnString},
 | ||||||
| 	{"DHookSetParamString",					Native_SetParamString}, | 	{"DHookSetParamString",					Native_SetParamString}, | ||||||
| 	/*{"DHookAddEntityListener",			Native_AddEntityListener},
 | 	{"DHookAddEntityListener",				Native_AddEntityListener}, | ||||||
| 	{"DHookRemoveEntityListener",			Native_RemoveEntityListener}, | 	{"DHookRemoveEntityListener",			Native_RemoveEntityListener}, | ||||||
| 	{"DHookGetParamObjectPtrVar",			Native_GetParamObjectPtrVar}, | 	/*{"DHookGetParamObjectPtrVar",			Native_GetParamObjectPtrVar},
 | ||||||
| 	{"DHookSetParamObjectPtrVar",			Native_SetParamObjectPtrVar}, | 	{"DHookSetParamObjectPtrVar",			Native_SetParamObjectPtrVar}, | ||||||
| 	{"DHookGetParamObjectPtrVarVector",		Native_GetParamObjectPtrVarVector}, | 	{"DHookGetParamObjectPtrVarVector",		Native_GetParamObjectPtrVarVector}, | ||||||
| 	{"DHookSetParamObjectPtrVarVector",		Native_SetParamObjectPtrVarVector}, | 	{"DHookSetParamObjectPtrVarVector",		Native_SetParamObjectPtrVarVector},*/ | ||||||
| 	{"DHookIsNullParam",					Native_IsNullParam},*/ | 	{"DHookIsNullParam",					Native_IsNullParam}, | ||||||
| 	{NULL,							NULL} | 	{NULL,							NULL} | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -3,6 +3,9 @@ | |||||||
| 
 | 
 | ||||||
| #include "extension.h" | #include "extension.h" | ||||||
| #include "vhook.h" | #include "vhook.h" | ||||||
|  | #include "listeners.h" | ||||||
|  | 
 | ||||||
|  | extern DHooksEntityListener *g_pEntityListener; | ||||||
| extern ISDKTools *g_pSDKTools; | extern ISDKTools *g_pSDKTools; | ||||||
| extern HandleType_t g_HookSetupHandle; | extern HandleType_t g_HookSetupHandle; | ||||||
| extern HandleType_t g_HookParamsHandle; | extern HandleType_t g_HookParamsHandle; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user