mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-06 18:08:36 +00:00
Remove duplicate code, move it to a separate function
This commit is contained in:
parent
5da5325a10
commit
f9d175c75e
@ -1086,6 +1086,46 @@ cell_t Native_RemoveEntityListener(IPluginContext *pContext, const cell_t *param
|
|||||||
return pContext->ThrowNativeError("Failed to get g_pEntityListener");
|
return pContext->ThrowNativeError("Failed to get g_pEntityListener");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* GetObjectAddrOrThis(HookParamsStruct* paramStruct, IPluginContext* pContext, const cell_t* params)
|
||||||
|
{
|
||||||
|
if (params[2] != 0)
|
||||||
|
{
|
||||||
|
const auto& paramsVec = paramStruct->dg->params;
|
||||||
|
|
||||||
|
if (params[2] < 0 || params[2] > static_cast<int>(paramsVec.size()))
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramsVec.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = params[2] - 1;
|
||||||
|
const auto& param = paramsVec.at(index);
|
||||||
|
|
||||||
|
if (param.type != HookParamType_ObjectPtr && param.type != HookParamType_Object)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Invalid object value type %i", param.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t offset = GetParamOffset(paramStruct, index);
|
||||||
|
return GetObjectAddr(param.type, param.flags, paramStruct->orgParams, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& dgInfo = paramStruct->dg;
|
||||||
|
|
||||||
|
if (dgInfo->thisFuncCallConv != CallConv_THISCALL)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dgInfo->thisType != ThisPointer_Address
|
||||||
|
&& dgInfo->thisType != ThisPointer_CBaseEntity
|
||||||
|
&& !(dgInfo->thisType == ThisPointer_Ignore && dgInfo->hookType == HookType_GameRules))
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_SHPtr->GetIfacePtr();
|
||||||
|
}
|
||||||
|
|
||||||
//native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type);
|
//native any:DHookGetParamObjectPtrVar(Handle:hParams, num, offset, ObjectValueType:type);
|
||||||
cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params)
|
cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
@ -1096,39 +1136,7 @@ cell_t Native_GetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = NULL;
|
void* addr = GetObjectAddrOrThis(paramStruct, pContext, params);
|
||||||
|
|
||||||
if(params[2] != 0)
|
|
||||||
{
|
|
||||||
if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size())
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = params[2] - 1;
|
|
||||||
|
|
||||||
if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset = GetParamOffset(paramStruct, index);
|
|
||||||
addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules))
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = g_SHPtr->GetIfacePtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch((ObjectValueType)params[4])
|
switch((ObjectValueType)params[4])
|
||||||
{
|
{
|
||||||
@ -1186,39 +1194,7 @@ cell_t Native_SetParamObjectPtrVar(IPluginContext *pContext, const cell_t *param
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = NULL;
|
void* addr = GetObjectAddrOrThis(paramStruct, pContext, params);
|
||||||
|
|
||||||
if(params[2] != 0)
|
|
||||||
{
|
|
||||||
if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size())
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = params[2] - 1;
|
|
||||||
|
|
||||||
if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset = GetParamOffset(paramStruct, index);
|
|
||||||
addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules))
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = g_SHPtr->GetIfacePtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch((ObjectValueType)params[4])
|
switch((ObjectValueType)params[4])
|
||||||
{
|
{
|
||||||
@ -1290,39 +1266,7 @@ cell_t Native_GetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = NULL;
|
void* addr = GetObjectAddrOrThis(paramStruct, pContext, params);
|
||||||
|
|
||||||
if(params[2] != 0)
|
|
||||||
{
|
|
||||||
if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size())
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = params[2] - 1;
|
|
||||||
|
|
||||||
if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset = GetParamOffset(paramStruct, index);
|
|
||||||
addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules))
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = g_SHPtr->GetIfacePtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
cell_t *buffer;
|
cell_t *buffer;
|
||||||
pContext->LocalToPhysAddr(params[5], &buffer);
|
pContext->LocalToPhysAddr(params[5], &buffer);
|
||||||
@ -1363,39 +1307,7 @@ cell_t Native_SetParamObjectPtrVarVector(IPluginContext *pContext, const cell_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = NULL;
|
void* addr = GetObjectAddrOrThis(paramStruct, pContext, params);
|
||||||
|
|
||||||
if(params[2] != 0)
|
|
||||||
{
|
|
||||||
if(params[2] < 0 || params[2] > (int)paramStruct->dg->params.size())
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = params[2] - 1;
|
|
||||||
|
|
||||||
if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset = GetParamOffset(paramStruct, index);
|
|
||||||
addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules))
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = g_SHPtr->GetIfacePtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
cell_t *buffer;
|
cell_t *buffer;
|
||||||
pContext->LocalToPhysAddr(params[5], &buffer);
|
pContext->LocalToPhysAddr(params[5], &buffer);
|
||||||
@ -1435,39 +1347,7 @@ cell_t Native_GetParamObjectPtrString(IPluginContext *pContext, const cell_t *pa
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *addr = NULL;
|
void* addr = GetObjectAddrOrThis(paramStruct, pContext, params);
|
||||||
|
|
||||||
if(params[2] != 0)
|
|
||||||
{
|
|
||||||
if(params[2] <= 0 || params[2] > (int)paramStruct->dg->params.size())
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid param number %i max params is %i", params[2], paramStruct->dg->params.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = params[2] - 1;
|
|
||||||
|
|
||||||
if(paramStruct->dg->params.at(index).type != HookParamType_ObjectPtr && paramStruct->dg->params.at(index).type != HookParamType_Object)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Invalid object value type %i", paramStruct->dg->params.at(index).type);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t offset = GetParamOffset(paramStruct, index);
|
|
||||||
addr = GetObjectAddr(paramStruct->dg->params.at(index).type, paramStruct->dg->params.at(index).flags, paramStruct->orgParams, offset);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(paramStruct->dg->thisFuncCallConv != CallConv_THISCALL)
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is only available in member functions, specify the calling convention type 'thiscall'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(paramStruct->dg->thisType != ThisPointer_Address && paramStruct->dg->thisType != ThisPointer_CBaseEntity && !(paramStruct->dg->thisType == ThisPointer_Ignore && paramStruct->dg->hookType == HookType_GameRules))
|
|
||||||
{
|
|
||||||
return pContext->ThrowNativeError("Parameter 'this' is not specified as an address, it is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = g_SHPtr->GetIfacePtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch((ObjectValueType)params[4])
|
switch((ObjectValueType)params[4])
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user