2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-27 23:25:30 +03:00

Some fixes

This commit is contained in:
s1lent 2019-07-29 22:22:54 +07:00
parent daac725d34
commit 2e4ef61e9e
No known key found for this signature in database
GPG Key ID: 0FE401DC73916B5C
3 changed files with 48 additions and 3 deletions

View File

@ -123,7 +123,14 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params)
if (unlikely(params[arg_type] != retVal.type))
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: trying to set return value with incompatible type.", __FUNCTION__);
AMXX_LogError(amx, AMX_ERR_NATIVE,
"%s: trying to set return value with incompatible type, expected '%s'; got '%s'",
__FUNCTION__,
getATypeStr(retVal.type),
getATypeStr(static_cast<AType>(params[arg_type]))
);
printf("> SetHookChainReturn: called #3\n");
return FALSE;
}
@ -136,6 +143,9 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params)
case ATYPE_FLOAT:
retVal._integer = *srcAddr;
break;
case ATYPE_BOOL:
retVal._integer = (*srcAddr != 0) ? TRUE : FALSE;
break;
case ATYPE_STRING:
{
@ -188,7 +198,13 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params)
if (unlikely(params[arg_type] != retVal.type))
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: trying to get return value with incompatible type.", __FUNCTION__);
AMXX_LogError(amx, AMX_ERR_NATIVE,
"%s: trying to get return value with incompatible type, expected '%s'; got '%s'",
__FUNCTION__,
getATypeStr(retVal.type),
getATypeStr(static_cast<AType>(params[arg_type]))
);
return FALSE;
}
@ -205,6 +221,8 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params)
case ATYPE_INTEGER:
case ATYPE_FLOAT:
return retVal._integer;
case ATYPE_BOOL:
return retVal._integer != 0 ? TRUE : FALSE;
case ATYPE_STRING:
{
if (PARAMS_COUNT != 2)
@ -258,7 +276,13 @@ cell AMX_NATIVE_CALL SetHookChainArg(AMX *amx, cell *params)
AType type = g_hookCtx->args[number].type;
if (unlikely(params[arg_type] != type))
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid argument type provided.", __FUNCTION__);
AMXX_LogError(amx, AMX_ERR_NATIVE,
"%s: invalid argument type provided, expected '%s'; got '%s'",
__FUNCTION__,
getATypeStr(type),
getATypeStr(static_cast<AType>(params[arg_type]))
);
return FALSE;
}

View File

@ -220,3 +220,22 @@ void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType typ
break;
}
}
const char *getATypeStr(AType type)
{
static constexpr const char *s_ATypes[]
{
"ATYPE_INTEGER",
"ATYPE_FLOAT",
"ATYPE_STRING",
"ATYPE_CLASSPTR",
"ATYPE_EDICT",
"ATYPE_EVARS",
"ATYPE_BOOL"
};
if (type >= arraysize(s_ATypes))
return "";
return s_ATypes[type];
}

View File

@ -57,4 +57,6 @@ void GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *vecOrigin, Vector
void GetAttachment(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector *pVecAngles);
void RemoveOrDropItem(CBasePlayer *pPlayer, CBasePlayerItem *pItem, GiveType type);
const char *getATypeStr(AType type);
extern void NORETURN UTIL_SysError(const char *fmt, ...);