Add natives for Vector params. Add include file with new updated natives. Moved handle check into function.
This commit is contained in:
		
							parent
							
								
									6e40653db6
								
							
						
					
					
						commit
						caccb5a0ff
					
				
							
								
								
									
										263
									
								
								natives.cpp
									
									
									
									
									
								
							
							
						
						
									
										263
									
								
								natives.cpp
									
									
									
									
									
								
							| @ -16,6 +16,22 @@ CBaseEntity *UTIL_GetCBaseEntity(int num) | |||||||
| 	return pUnk->GetBaseEntity(); | 	return pUnk->GetBaseEntity(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool GetHandleIfValidOrError(HandleType_t type, void **object, IPluginContext *pContext, cell_t param) | ||||||
|  | { | ||||||
|  | 	if(param == BAD_HANDLE) | ||||||
|  | 	{ | ||||||
|  | 		return pContext->ThrowNativeError("Invalid Handle %i", BAD_HANDLE) != 0; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	HandleError err; | ||||||
|  | 	HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); | ||||||
|  | 
 | ||||||
|  | 	if((err = handlesys->ReadHandle(param, g_HookSetupHandle, &sec, object)) != HandleError_None) | ||||||
|  | 	{ | ||||||
|  | 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", param, err) != 0; | ||||||
|  | 	} | ||||||
|  | 	return true; | ||||||
|  | } | ||||||
| //native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback);
 | //native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback);
 | ||||||
| cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params) | cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params) | ||||||
| { | { | ||||||
| @ -37,35 +53,32 @@ cell_t Native_CreateHook(IPluginContext *pContext, const cell_t *params) | |||||||
| 	return hndl; | 	return hndl; | ||||||
| } | } | ||||||
| //native bool:DHookAddParam(Handle:setup, HookParamType:type); OLD
 | //native bool:DHookAddParam(Handle:setup, HookParamType:type); OLD
 | ||||||
| //native bool:DHookAddParam(Handle:setup, HookParamType:type, size=-1, flag=-1);
 | //native DHookAddParam(Handle:setup, HookParamType:type, size=-1, DHookPassFlag:flag=DHookPass_ByVal);
 | ||||||
| cell_t Native_AddParam(IPluginContext *pContext, const cell_t *params) | cell_t Native_AddParam(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()); |  | ||||||
| 	HookSetup *setup; | 	HookSetup *setup; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookSetupHandle, &sec, (void **)&setup)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 	ParamInfo info; |  | ||||||
| 
 | 
 | ||||||
| 	//Add support for setting this
 | 	ParamInfo info; | ||||||
| 	info.flag = PASSFLAG_BYVAL; |  | ||||||
| 
 | 
 | ||||||
| 	info.type = (HookParamType)params[2]; | 	info.type = (HookParamType)params[2]; | ||||||
| 
 | 
 | ||||||
| 	if(params[0] == 3 && params[3] != -1) | 	if(params[0] >= 3 && params[3] != -1) | ||||||
| 	{ | 	{ | ||||||
| 		info.size = params[3]; | 		info.size = params[3]; | ||||||
|  | 
 | ||||||
|  | 		if(params[0] >= 4) | ||||||
|  | 		{ | ||||||
|  | 			info.flag = params[4]; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | 		info.flag = PASSFLAG_BYVAL; | ||||||
| 		info.size = GetParamTypeSize(info.type); | 		info.size = GetParamTypeSize(info.type); | ||||||
| 	} | 	} | ||||||
| 	info.pass_type = GetParamTypePassType(info.type); | 	info.pass_type = GetParamTypePassType(info.type); | ||||||
| @ -73,21 +86,16 @@ cell_t Native_AddParam(IPluginContext *pContext, const cell_t *params) | |||||||
| 
 | 
 | ||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
|  | // native DHookEntity(Handle:setup, bool:post, entity, DHookRemovalCB:removalcb);
 | ||||||
| cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params) | cell_t Native_HookEntity(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()); |  | ||||||
| 	HookSetup *setup; | 	HookSetup *setup; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookSetupHandle, &sec, (void **)&setup)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	if(setup->hookType != HookType_Entity) | 	if(setup->hookType != HookType_Entity) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Hook is not an entity hook"); | 		return pContext->ThrowNativeError("Hook is not an entity hook"); | ||||||
| @ -124,19 +132,13 @@ cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params) | |||||||
| // native DHookGamerules(Handle:setup, bool:post, DHookRemovalCB:removalcb);
 | // native DHookGamerules(Handle:setup, bool:post, DHookRemovalCB:removalcb);
 | ||||||
| cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params) | cell_t Native_HookGamerules(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()); |  | ||||||
| 	HookSetup *setup; | 	HookSetup *setup; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookSetupHandle, &sec, (void **)&setup)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	if(setup->hookType != HookType_GameRules) | 	if(setup->hookType != HookType_GameRules) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Hook is not a gamerules hook"); | 		return pContext->ThrowNativeError("Hook is not a gamerules hook"); | ||||||
| @ -175,19 +177,13 @@ cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params) | |||||||
| // DHookRaw(Handle:setup, bool:post, Address:addr, DHookRemovalCB:removalcb);
 | // DHookRaw(Handle:setup, bool:post, Address:addr, DHookRemovalCB:removalcb);
 | ||||||
| cell_t Native_HookRaw(IPluginContext *pContext, const cell_t *params) | cell_t Native_HookRaw(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()); |  | ||||||
| 	HookSetup *setup; | 	HookSetup *setup; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookSetupHandle, &sec, (void **)&setup)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookSetupHandle, (void **)&setup, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
| 	if(setup->hookType != HookType_Raw) | 	if(setup->hookType != HookType_Raw) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Hook is not a gamerules hook"); | 		return pContext->ThrowNativeError("Hook is not a gamerules hook"); | ||||||
| @ -241,17 +237,11 @@ cell_t Native_RemoveHookID(IPluginContext *pContext, const cell_t *params) | |||||||
| // native any:DHookGetParam(Handle:hParams, num);
 | // native any:DHookGetParam(Handle:hParams, num);
 | ||||||
| cell_t Native_GetParam(IPluginContext *pContext, const cell_t *params) | cell_t Native_GetParam(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; | 	HookParamsStruct *paramStruct; | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(params[2] < 0 || params[2] > paramStruct->dg->params.Count()) | 	if(params[2] < 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
| @ -292,17 +282,11 @@ cell_t Native_GetParam(IPluginContext *pContext, const cell_t *params) | |||||||
| // native DHookSetParam(Handle:hParams, param, any:value)
 | // native DHookSetParam(Handle:hParams, param, any:value)
 | ||||||
| cell_t Native_SetParam(IPluginContext *pContext, const cell_t *params) | cell_t Native_SetParam(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; | 	HookParamsStruct *paramStruct; | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
| @ -355,18 +339,11 @@ cell_t Native_SetParam(IPluginContext *pContext, const cell_t *params) | |||||||
| // native any:DHookGetReturn(Handle:hReturn);
 | // native any:DHookGetReturn(Handle:hReturn);
 | ||||||
| cell_t Native_GetReturn(IPluginContext *pContext, const cell_t *params) | cell_t Native_GetReturn(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()); |  | ||||||
| 	HookReturnStruct *returnStruct; | 	HookReturnStruct *returnStruct; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookReturnHandle, &sec, (void **)&returnStruct)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookReturnHandle, (void **)&returnStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	switch(returnStruct->type) | 	switch(returnStruct->type) | ||||||
| @ -389,18 +366,11 @@ cell_t Native_GetReturn(IPluginContext *pContext, const cell_t *params) | |||||||
| // native DHookSetReturn(Handle:hReturn, any:value)
 | // native DHookSetReturn(Handle:hReturn, any:value)
 | ||||||
| cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params) | cell_t Native_SetReturn(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()); |  | ||||||
| 	HookReturnStruct *returnStruct; | 	HookReturnStruct *returnStruct; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookReturnHandle, &sec, (void **)&returnStruct)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookReturnHandle, (void **)&returnStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	switch(returnStruct->type) | 	switch(returnStruct->type) | ||||||
| @ -440,25 +410,82 @@ cell_t Native_SetReturn(IPluginContext *pContext, const cell_t *params) | |||||||
| 	returnStruct->isChanged = true; | 	returnStruct->isChanged = true; | ||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
| /*cell_t Native_GetParamVector(IPluginContext *pContext, const cell_t *params);
 | // native DHookGetParamVector(Handle:hParams, num, Float:vec[3])
 | ||||||
| cell_t Native_GetReturnVector(IPluginContext *pContext, const cell_t *params); | cell_t Native_GetParamVector(IPluginContext *pContext, const cell_t *params) | ||||||
| cell_t Native_SetReturnVector(IPluginContext *pContext, const cell_t *params); | { | ||||||
| cell_t Native_SetParamVector(IPluginContext *pContext, const cell_t *params);*/ | 	HookParamsStruct *paramStruct; | ||||||
|  | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
|  | 	{ | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	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; | ||||||
|  | 
 | ||||||
|  | 	switch(paramStruct->dg->params.Element(index).type) | ||||||
|  | 	{ | ||||||
|  | 		case HookParamType_VectorPtr: | ||||||
|  | 		{ | ||||||
|  | 			cell_t *buffer; | ||||||
|  | 			pContext->LocalToPhysAddr(params[3], &buffer); | ||||||
|  | 			buffer[0] = sp_ftoc(((Vector *)paramStruct->orgParams[index])->x); | ||||||
|  | 			buffer[1] = sp_ftoc(((Vector *)paramStruct->orgParams[index])->y); | ||||||
|  | 			buffer[2] = sp_ftoc(((Vector *)paramStruct->orgParams[index])->z); | ||||||
|  | 			return 1; | ||||||
|  | 		}	 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return pContext->ThrowNativeError("Invalid param type to get. Param is not a vector."); | ||||||
|  | } | ||||||
|  | // native DHookSetParamVector(Handle:hParams, num, Float:vec[3])
 | ||||||
|  | cell_t Native_SetParamVector(IPluginContext *pContext, const cell_t *params) | ||||||
|  | { | ||||||
|  | 	HookParamsStruct *paramStruct; | ||||||
|  | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
|  | 	{ | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	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; | ||||||
|  | 
 | ||||||
|  | 	switch(paramStruct->dg->params.Element(index).type) | ||||||
|  | 	{ | ||||||
|  | 		case HookParamType_VectorPtr: | ||||||
|  | 		{ | ||||||
|  | 			if(paramStruct->newParams[index] != NULL) | ||||||
|  | 				delete (Vector *)paramStruct->newParams[index]; | ||||||
|  | 
 | ||||||
|  | 			cell_t *buffer; | ||||||
|  | 			pContext->LocalToPhysAddr(params[3], &buffer); | ||||||
|  | 
 | ||||||
|  | 			paramStruct->newParams[index] = new Vector(sp_ctof(buffer[0]), sp_ctof(buffer[1]), sp_ctof(buffer[2])); | ||||||
|  | 			return 1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return pContext->ThrowNativeError("Invalid param type to set. Param is not a vector."); | ||||||
|  | } | ||||||
|  | /*cell_t Native_GetReturnVector(IPluginContext *pContext, const cell_t *params);
 | ||||||
|  | cell_t Native_SetReturnVector(IPluginContext *pContext, const cell_t *params);*/ | ||||||
| 
 | 
 | ||||||
| // native DHookGetParamString(Handle:hParams, num, String:buffer[], size)
 | // native DHookGetParamString(Handle:hParams, num, String:buffer[], size)
 | ||||||
| cell_t Native_GetParamString(IPluginContext *pContext, const cell_t *params) | cell_t Native_GetParamString(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; | 	HookParamsStruct *paramStruct; | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
| @ -479,20 +506,14 @@ cell_t Native_GetParamString(IPluginContext *pContext, const cell_t *params) | |||||||
| 
 | 
 | ||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
|  | // native DHookGetReturnString(Handle:hReturn, String:buffer[], size)
 | ||||||
| cell_t Native_GetReturnString(IPluginContext *pContext, const cell_t *params) | cell_t Native_GetReturnString(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()); |  | ||||||
| 	HookReturnStruct *returnStruct; | 	HookReturnStruct *returnStruct; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookReturnHandle, &sec, (void **)&returnStruct)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookReturnHandle, (void **)&returnStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	switch(returnStruct->type) | 	switch(returnStruct->type) | ||||||
| @ -510,20 +531,15 @@ cell_t Native_GetReturnString(IPluginContext *pContext, const cell_t *params) | |||||||
| 			return pContext->ThrowNativeError("Invalid param type to get. Param is not a string."); | 			return pContext->ThrowNativeError("Invalid param type to get. Param is not a string."); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | //native DHookSetReturnString(Handle:hReturn, String:value[])
 | ||||||
| cell_t Native_SetReturnString(IPluginContext *pContext, const cell_t *params) | cell_t Native_SetReturnString(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()); |  | ||||||
| 	HookReturnStruct *returnStruct; | 	HookReturnStruct *returnStruct; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookReturnHandle, &sec, (void **)&returnStruct)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookReturnHandle, (void **)&returnStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	char *value; | 	char *value; | ||||||
| @ -552,17 +568,11 @@ cell_t Native_SetReturnString(IPluginContext *pContext, const cell_t *params) | |||||||
| //native DHookSetParamString(Handle:hParams, num, String:value[])
 | //native DHookSetParamString(Handle:hParams, num, String:value[])
 | ||||||
| cell_t Native_SetParamString(IPluginContext *pContext, const cell_t *params) | cell_t Native_SetParamString(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; | 	HookParamsStruct *paramStruct; | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | 
 | ||||||
|  | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
| @ -610,18 +620,11 @@ cell_t Native_RemoveEntityListener(IPluginContext *pContext, const cell_t *param | |||||||
| //native bool:DHookIsNullParam(Handle:hParams, num);
 | //native bool:DHookIsNullParam(Handle:hParams, num);
 | ||||||
| cell_t Native_IsNullParam(IPluginContext *pContext, const cell_t *params) | 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; | 	HookParamsStruct *paramStruct; | ||||||
| 
 | 
 | ||||||
| 	if((err = handlesys->ReadHandle(params[1], g_HookParamsHandle, &sec, (void **)¶mStruct)) != HandleError_None) | 	if(!GetHandleIfValidOrError(g_HookParamsHandle, (void **)¶mStruct, pContext, params[1])) | ||||||
| 	{ | 	{ | ||||||
| 		return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err); | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | 	if(params[2] <= 0 || params[2] > paramStruct->dg->params.Count()) | ||||||
| @ -652,10 +655,10 @@ sp_nativeinfo_t g_Natives[] = | |||||||
| 	{"DHookGetReturn",						Native_GetReturn}, | 	{"DHookGetReturn",						Native_GetReturn}, | ||||||
| 	{"DHookSetReturn",						Native_SetReturn}, | 	{"DHookSetReturn",						Native_SetReturn}, | ||||||
| 	{"DHookSetParam",						Native_SetParam}, | 	{"DHookSetParam",						Native_SetParam}, | ||||||
| 	/*{"DHookGetParamVector",					Native_GetParamVector},
 | 	{"DHookGetParamVector",					Native_GetParamVector}, | ||||||
| 	{"DHookGetReturnVector",				Native_GetReturnVector}, | 	/*{"DHookGetReturnVector",				Native_GetReturnVector},
 | ||||||
| 	{"DHookSetReturnVector",				Native_SetReturnVector}, | 	{"DHookSetReturnVector",				Native_SetReturnVector},*/ | ||||||
| 	{"DHookSetParamVector",					Native_SetParamVector},*/ | 	{"DHookSetParamVector",					Native_SetParamVector}, | ||||||
| 	{"DHookGetParamString",					Native_GetParamString}, | 	{"DHookGetParamString",					Native_GetParamString}, | ||||||
| 	{"DHookGetReturnString",				Native_GetReturnString}, | 	{"DHookGetReturnString",				Native_GetReturnString}, | ||||||
| 	{"DHookSetReturnString",				Native_SetReturnString}, | 	{"DHookSetReturnString",				Native_SetReturnString}, | ||||||
|  | |||||||
							
								
								
									
										451
									
								
								sourcemod/scripting/include/dhooks.inc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										451
									
								
								sourcemod/scripting/include/dhooks.inc
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,451 @@ | |||||||
|  | #if defined _dhooks_included
 | ||||||
|  | #endinput
 | ||||||
|  | #endif
 | ||||||
|  | #define _dhooks_included
 | ||||||
|  | enum ObjectValueType | ||||||
|  | { | ||||||
|  | 	ObjectValueType_Int = 0, | ||||||
|  | 	ObjectValueType_Bool, | ||||||
|  | 	ObjectValueType_Ehandle, | ||||||
|  | 	ObjectValueType_Float, | ||||||
|  | 	ObjectValueType_CBaseEntityPtr, | ||||||
|  | 	ObjectValueType_IntPtr, | ||||||
|  | 	ObjectValueType_BoolPtr, | ||||||
|  | 	ObjectValueType_EhandlePtr, | ||||||
|  | 	ObjectValueType_FloatPtr, | ||||||
|  | 	ObjectValueType_Vector, | ||||||
|  | 	ObjectValueType_VectorPtr | ||||||
|  | }; | ||||||
|  | enum ListenType | ||||||
|  | { | ||||||
|  | 	ListenType_Created, | ||||||
|  | 	ListenType_Deleted | ||||||
|  | }; | ||||||
|  | enum ReturnType | ||||||
|  | { | ||||||
|  | 	ReturnType_Unknown, | ||||||
|  | 	ReturnType_Void, | ||||||
|  | 	ReturnType_Int, | ||||||
|  | 	ReturnType_Bool, | ||||||
|  | 	ReturnType_Float, | ||||||
|  | 	ReturnType_String, //Note this is a string_t
 | ||||||
|  | 	ReturnType_StringPtr, //Note this is a string_t *
 | ||||||
|  | 	ReturnType_CharPtr, | ||||||
|  | 	ReturnType_Vector, | ||||||
|  | 	ReturnType_VectorPtr, | ||||||
|  | 	ReturnType_CBaseEntity, | ||||||
|  | 	ReturnType_Edict | ||||||
|  | }; | ||||||
|  | enum HookParamType | ||||||
|  | { | ||||||
|  | 	HookParamType_Unknown, | ||||||
|  | 	HookParamType_Int, | ||||||
|  | 	HookParamType_Bool, | ||||||
|  | 	HookParamType_Float, | ||||||
|  | 	HookParamType_String, //Note this is a string_t
 | ||||||
|  | 	HookParamType_StringPtr, //Note this is a string_t *
 | ||||||
|  | 	HookParamType_CharPtr, | ||||||
|  | 	HookParamType_VectorPtr, | ||||||
|  | 	HookParamType_CBaseEntity, | ||||||
|  | 	HookParamType_ObjectPtr, | ||||||
|  | 	HookParamType_Edict, | ||||||
|  | 	HookParamType_Object | ||||||
|  | }; | ||||||
|  | enum ThisPointerType | ||||||
|  | { | ||||||
|  | 	ThisPointer_Ignore, | ||||||
|  | 	ThisPointer_CBaseEntity, | ||||||
|  | 	ThisPointer_Address | ||||||
|  | }; | ||||||
|  | enum HookType | ||||||
|  | { | ||||||
|  | 	HookType_Entity, | ||||||
|  | 	HookType_GameRules, | ||||||
|  | 	HookType_Raw | ||||||
|  | }; | ||||||
|  | enum MRESReturn | ||||||
|  | { | ||||||
|  | 	MRES_ChangedHandled = -2,	// Use changed values and return MRES_Handled
 | ||||||
|  | 	MRES_ChangedOverride,		// Use changed values and return MRES_Override
 | ||||||
|  | 	MRES_Ignored,				// plugin didn't take any action
 | ||||||
|  | 	MRES_Handled,				// plugin did something, but real function should still be called
 | ||||||
|  | 	MRES_Override,				// call real function, but use my return value
 | ||||||
|  | 	MRES_Supercede				// skip real function; use my return value
 | ||||||
|  | }; | ||||||
|  | enum DHookPassFlag | ||||||
|  | { | ||||||
|  | 	DHookPass_ByVal = (1<<0), | ||||||
|  | 	DHookPass_ByRef = (1<<1) | ||||||
|  | }; | ||||||
|  | funcenum ListenCB | ||||||
|  | { | ||||||
|  | 	//Deleted
 | ||||||
|  | 	public (entity), | ||||||
|  | 	//Created
 | ||||||
|  | 	public (entity, const String:classname[]) | ||||||
|  | } | ||||||
|  | funcenum DHookRemovalCB | ||||||
|  | { | ||||||
|  | 	public (hookid) | ||||||
|  | }; | ||||||
|  | funcenum DHookCallback | ||||||
|  | { | ||||||
|  | 	//Function Example: void Ham::Test() with this pointer ignore
 | ||||||
|  | 	MRESReturn:public(), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: void Ham::Test() with this pointer passed
 | ||||||
|  | 	MRESReturn:public(this), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: void Ham::Test(int cake) with this pointer ignore
 | ||||||
|  | 	MRESReturn:public(Handle:hParams), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: void Ham::Test(int cake) with this pointer passed
 | ||||||
|  | 	MRESReturn:public(this, Handle:hParams), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test() with this pointer ignore
 | ||||||
|  | 	MRESReturn:public(Handle:hReturn), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test() with this pointer passed
 | ||||||
|  | 	MRESReturn:public(this, Handle:hReturn), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test(int cake) with this pointer ignore
 | ||||||
|  | 	MRESReturn:public(Handle:hReturn, Handle:hParams), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test(int cake) with this pointer passed
 | ||||||
|  | 	MRESReturn:public(this, Handle:hReturn, Handle:hParams), | ||||||
|  | 	 | ||||||
|  | 	//Address NOW
 | ||||||
|  | 	 | ||||||
|  | 	//Function Example: void Ham::Test() with this pointer passed
 | ||||||
|  | 	MRESReturn:public(Address:this), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: void Ham::Test(int cake) with this pointer passed
 | ||||||
|  | 	MRESReturn:public(Address:this, Handle:hParams), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test() with this pointer passed
 | ||||||
|  | 	MRESReturn:public(Address:this, Handle:hReturn), | ||||||
|  | 	 | ||||||
|  | 	//Function Example: int Ham::Test(int cake) with this pointer passed
 | ||||||
|  | 	MRESReturn:public(Address:this, Handle:hReturn, Handle:hParams) | ||||||
|  | 	 | ||||||
|  | }; | ||||||
|  | /* Adds an entity listener hook | ||||||
|  |  * | ||||||
|  |  * @param type			Type of listener to add | ||||||
|  |  * @param callback		Callback to use | ||||||
|  |  * | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookAddEntityListener(ListenType:type, ListenCB:callback); | ||||||
|  | 
 | ||||||
|  | /* Removes an entity listener hook | ||||||
|  |  * | ||||||
|  |  * @param type			Type of listener to remove | ||||||
|  |  * @param callback		Callback this listener was using | ||||||
|  |  * | ||||||
|  |  * @return True if one was removed false otherwise. | ||||||
|  | */ | ||||||
|  | native bool:DHookRemoveEntityListener(ListenType:type, ListenCB:callback); | ||||||
|  | 
 | ||||||
|  | /* Creates a hook | ||||||
|  |  * | ||||||
|  |  * @param offset		vtable offset for function to hook | ||||||
|  |  * @param hooktype		Type of hook | ||||||
|  |  * @param returntype	Type type of return | ||||||
|  |  * @param thistype		Type of this pointer or ignore (ignore can be used if not needed) | ||||||
|  |  * @param callback		Callback function
 | ||||||
|  |  *  | ||||||
|  |  * @return Returns setup handle for the hook or INVALID_HANDLE. | ||||||
|  | */ | ||||||
|  | native Handle:DHookCreate(offset, HookType:hooktype, ReturnType:returntype, ThisPointerType:thistype, DHookCallback:callback); | ||||||
|  | 
 | ||||||
|  | /* Adds param to a hook setup | ||||||
|  |  * | ||||||
|  |  * @param setup			Setup handle to add the param to. | ||||||
|  |  * @param type			Param type | ||||||
|  |  * @param size			Used for Objects (not Object ptr) to define the size of the object. | ||||||
|  |  * @param flag			Used to change the pass type. | ||||||
|  |  *  | ||||||
|  |  * @error	Invalid setup handle or too many params added (request upping the max in thread) | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookAddParam(Handle:setup, HookParamType:type, size=-1, DHookPassFlag:flag=DHookPass_ByVal); | ||||||
|  | //native DHookAddParam(Handle:setup, HookParamType:type);
 | ||||||
|  | 
 | ||||||
|  | /* Hook entity | ||||||
|  |  *  | ||||||
|  |  * @param setup			Setup handle to use to add the hook. | ||||||
|  |  * @param post			True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!) | ||||||
|  |  * @param entity		Entity index to hook on. | ||||||
|  |  * @param removalcb		Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid setup handle, invalid entity or invalid hook type. | ||||||
|  |  * @return -1 on fail a hookid on success | ||||||
|  | */ | ||||||
|  | native DHookEntity(Handle:setup, bool:post, entity, DHookRemovalCB:removalcb=DHookRemovalCB:-1); | ||||||
|  | 
 | ||||||
|  | /* Hook gamerules | ||||||
|  |  *  | ||||||
|  |  * @param setup			Setup handle to use to add the hook. | ||||||
|  |  * @param post			True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!) | ||||||
|  |  * @param removalcb		Callback for when the hook is removed (Game rules hooks are auto-removed on map end and will call this callback) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid setup handle, failing to get gamerules pointer or invalid hook type. | ||||||
|  |  * @return -1 on fail a hookid on success | ||||||
|  | */ | ||||||
|  | native DHookGamerules(Handle:setup, bool:post, DHookRemovalCB:removalcb=DHookRemovalCB:-1); | ||||||
|  | 
 | ||||||
|  | /* Hook a raw pointer | ||||||
|  |  *  | ||||||
|  |  * @param setup			Setup handle to use to add the hook. | ||||||
|  |  * @param post			True to make the hook a post hook. (If you need to change the retunr value or need the return value use a post hook! If you need to change params and return use a pre and post hook!) | ||||||
|  |  * @param addr			This pointer address. | ||||||
|  |  * @param removalcb		Callback for when the hook is removed (Entity hooks are auto-removed on entity destroyed and will call this callback) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid setup handle, invalid address or invalid hook type. | ||||||
|  |  * @return -1 on fail a hookid on success | ||||||
|  | */ | ||||||
|  | native DHookRaw(Handle:setup, bool:post, Address:addr, DHookRemovalCB:removalcb=DHookRemovalCB:-1); | ||||||
|  | 
 | ||||||
|  | /* Remove hook by hook id | ||||||
|  |  *  | ||||||
|  |  * @param hookid		Hook id to remove | ||||||
|  |  *  | ||||||
|  |  * @return true on success false otherwise | ||||||
|  |  * @note This will not fire the removal callback! | ||||||
|  | */ | ||||||
|  | native bool:DHookRemoveHookID(hookid); | ||||||
|  | 
 | ||||||
|  | /* Get param value (Only use for: int, entity, bool or float param types) | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @return value if num greater than 0. If 0 returns paramcount. | ||||||
|  | */ | ||||||
|  | native any:DHookGetParam(Handle:hParams, num); | ||||||
|  | 
 | ||||||
|  | /* Get vector param value | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1.) | ||||||
|  |  * @param vec			Vector buffer to store result. | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookGetParamVector(Handle:hParams, num, Float:vec[3]); | ||||||
|  | 
 | ||||||
|  | /* Get string param value | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1.) | ||||||
|  |  * @param buffer		String buffer to store result | ||||||
|  |  * @param size			Buffer size | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @return value if num greater than 0. | ||||||
|  | */ | ||||||
|  | native DHookGetParamString(Handle:hParams, num, String:buffer[], size); | ||||||
|  | 
 | ||||||
|  | /* Set param value (Only use for: int, entity, bool or float param types) | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @params num			Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.) | ||||||
|  |  * @param value			Value to set it as (only pass int, bool, float or entity index) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetParam(Handle:hParams, num, any:value); | ||||||
|  | 
 | ||||||
|  | /* Set vector param value | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @params num			Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.) | ||||||
|  |  * @param vec			Value to set vector as. | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetParamVector(Handle:hParams, num, Float:vec[3]); | ||||||
|  | 
 | ||||||
|  | /* Set string param value | ||||||
|  |  *  | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @params num			Param number to set (Example if the function has 2 params and you need to set the value of the first param num would be 1.) | ||||||
|  |  * @param value			Value to set string as. | ||||||
|  |  *  | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetParamString(Handle:hParams, num, String:value[]); | ||||||
|  | 
 | ||||||
|  | /* Get return value (Only use for: int, entity, bool or float return types) | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @return Returns default value if prehook returns actual value if post hook. | ||||||
|  | */ | ||||||
|  | native any:DHookGetReturn(Handle:hReturn); | ||||||
|  | 
 | ||||||
|  | /* Get return vector value | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  * @param vec			Vector buffer to store result in. (In pre hooks will be default value (0.0,0.0,0.0)) | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookGetReturnVector(Handle:hReturn, Float:vec[3]); | ||||||
|  | 
 | ||||||
|  | /* Get return string value | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  * @param buffer		String buffer to store result in. (In pre hooks will be default value "") | ||||||
|  |  * @param size			String buffer size | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookGetReturnString(Handle:hReturn, String:buffer[], size); | ||||||
|  | 
 | ||||||
|  | /* Set return value (Only use for: int, entity, bool or float return types) | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  * @param value			Value to set return as | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetReturn(Handle:hReturn, any:value); | ||||||
|  | 
 | ||||||
|  | /* Set return vector value | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  * @param vec			Value to set return vector as | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetReturnVector(Handle:hReturn, Float:vec[3]); | ||||||
|  | 
 | ||||||
|  | /* Set return string value | ||||||
|  |  *  | ||||||
|  |  * @param hReturn		Handle to return structure | ||||||
|  |  * @param value			Value to set return string as | ||||||
|  |  *  | ||||||
|  |  * @error Invalid Handle, invalid type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetReturnString(Handle:hReturn, String:value[]); | ||||||
|  | 
 | ||||||
|  | /* Gets an objects variable value | ||||||
|  |  * | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored) | ||||||
|  |  * @param offset		Offset within the object to the var to get. | ||||||
|  |  * @param type			Type of var it is | ||||||
|  |  * | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type. | ||||||
|  |  * @return Value of the objects var. If EHANDLE type or entity returns entity index. | ||||||
|  | */ | ||||||
|  | native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type); | ||||||
|  | 
 | ||||||
|  | /* Sets an objects variable value | ||||||
|  |  * | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to set. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored) | ||||||
|  |  * @param offset		Offset within the object to the var to set. | ||||||
|  |  * @param type			Type of var it is | ||||||
|  |  * @param value			The value to set the var to. | ||||||
|  |  * | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type, any:value); | ||||||
|  | 
 | ||||||
|  | /* Gets an objects vector variable value | ||||||
|  |  * | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to get. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored) | ||||||
|  |  * @param offset		Offset within the object to the var to get. | ||||||
|  |  * @param type			Type of var it is | ||||||
|  |  * @param buffer		Buffer to store the result vector | ||||||
|  |  * | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type. | ||||||
|  |  * @return Value of the objects var. | ||||||
|  | */ | ||||||
|  | native DHookGetParamObjectPtrVarVector(Handle:hParams, num, offset, ObjectValueType:type, Float:buffer[3]); | ||||||
|  | 
 | ||||||
|  | /* Sets an objects vector variable value | ||||||
|  |  * | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to set. (Example if the function has 2 params and you need the value of the first param num would be 1. 0 Will return the number of params stored) | ||||||
|  |  * @param offset		Offset within the object to the var to set. | ||||||
|  |  * @param type			Type of var it is | ||||||
|  |  * @param value			The value to set the vector var to. | ||||||
|  |  * | ||||||
|  |  * @error Invalid handle. Invalid param number. Invalid param type. Invalid Object type. | ||||||
|  |  * @noreturn | ||||||
|  | */ | ||||||
|  | native DHookSetParamObjectPtrVarVector(Handle:hParams, num, offset, ObjectValueType:type, Float:value[3]); | ||||||
|  | 
 | ||||||
|  | /* Checks if a pointer param is null | ||||||
|  |  * | ||||||
|  |  * @param hParams		Handle to params structure | ||||||
|  |  * @param num			Param number to check. | ||||||
|  |  * | ||||||
|  |  * @error Non pointer param | ||||||
|  |  * @return True if null false otherwise. | ||||||
|  | */ | ||||||
|  | native bool:DHookIsNullParam(Handle:hParams, num); | ||||||
|  | 
 | ||||||
|  | public Extension:__ext_dhooks = | ||||||
|  | { | ||||||
|  | 	name = "dhooks", | ||||||
|  | 	file = "dhooks.ext", | ||||||
|  | #if defined AUTOLOAD_EXTENSIONS
 | ||||||
|  | 	autoload = 1, | ||||||
|  | #else
 | ||||||
|  | 	autoload = 0, | ||||||
|  | #endif
 | ||||||
|  | #if defined REQUIRE_EXTENSIONS
 | ||||||
|  | 	required = 1, | ||||||
|  | #else
 | ||||||
|  | 	required = 0, | ||||||
|  | #endif
 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | #if !defined REQUIRE_EXTENSIONS
 | ||||||
|  | public __ext_dhooks_SetNTVOptional() | ||||||
|  | { | ||||||
|  | 	MarkNativeAsOptional("DHookAddEntityListener"); | ||||||
|  | 	MarkNativeAsOptional("DHookRemoveEntityListener"); | ||||||
|  | 	MarkNativeAsOptional("DHookCreate"); | ||||||
|  | 	MarkNativeAsOptional("DHookAddParam"); | ||||||
|  | 	MarkNativeAsOptional("DHookEntity"); | ||||||
|  | 	MarkNativeAsOptional("DHookGamerules"); | ||||||
|  | 	MarkNativeAsOptional("DHookRaw"); | ||||||
|  | 	MarkNativeAsOptional("DHookRemoveHookID"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetParam"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetParamVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetParamString"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetParam"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetParamVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetParamString"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetReturn"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetReturnVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetReturnString"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetReturn"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetReturnVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetReturnString"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetParamObjectPtrVar"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetParamObjectPtrVar"); | ||||||
|  | 	MarkNativeAsOptional("DHookGetParamObjectPtrVarVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookSetParamObjectPtrVarVector"); | ||||||
|  | 	MarkNativeAsOptional("DHookIsNullParam"); | ||||||
|  | } | ||||||
|  | #endif
 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user