Hi,
so been trying to get into SM extensions so far everything i made worked. Now i wanted to create a simple GetWeaponShootPosition native which takes a client and returns a float array. I got that setup but it seems im doing something wrong because it crashes right away. Looking through the source sdk 2013 code the function Weapon_ShootPosition seem to return a vector. So im not sure how i would handle the vector correctly as pointer or normal variable because the function itself doesn't return a vector pointer.
PHP Code:
cell_t Native_GetWeaponShootPosition(IPluginContext *pContext, const cell_t *params)
{
static ICallWrapper *pWrapper = NULL;
if(!pWrapper)
{
REGISTER_NATIVE_ADDR("CBasePlayer::Weapon_ShootPosition",
PassInfo pass[1]; \
PassInfo ret;\
pass[0].flags = PASSFLAG_BYVAL; \
pass[0].size = sizeof(CBaseEntity *); \
pass[0].type = PassType_Basic; \
ret.flags = PASSFLAG_BYVAL;\
ret.size = sizeof(Vector);\
ret.type = PassType_Basic;\
pWrapper = g_pBinTools->CreateCall(addr, CallConv_ThisCall, &ret, pass, 1));
}
CBaseEntity *pEntity;
if(!(pEntity = GetCBaseEntity(params[1], true)))
{
return pContext->ThrowNativeError("Client index %d is invalid",params[1]);
}
cell_t *pPos;
pContext->LocalToPhysAddr(params[2], &pPos);
unsigned char vstk[sizeof(CBaseEntity *)];
unsigned char *vptr = vstk;
*(CBaseEntity **)vptr = pEntity;
vptr +=sizeof(CBaseEntity *);
Vector pos;
pWrapper->Execute(vstk, &pos);
pPos[0] = sp_ftoc(pos.x);
pPos[1] = sp_ftoc(pos.y);
pPos[2] = sp_ftoc(pos.z);
return 1;
}