2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-01 09:35:47 +03:00

Fixes in natives_member.cpp

This commit is contained in:
asmodai 2016-04-07 22:55:47 +03:00
parent 50b5649257
commit c732fbdc07
2 changed files with 29 additions and 29 deletions

View File

@ -47,7 +47,7 @@ void setupArgTypes(AType args_type[])
#define MAX_ARGS 10u #define MAX_ARGS 10u
template<size_t current, typename T, typename ...t_args> template<size_t current = 0, typename T, typename ...t_args>
void setupArgTypes(AType args_type[MAX_ARGS], T arg, t_args... args) void setupArgTypes(AType args_type[MAX_ARGS], T arg, t_args... args)
{ {
args_type[current] = getApiType(arg); args_type[current] = getApiType(arg);
@ -62,7 +62,7 @@ struct hookctx_t
{ {
args_count = min(count, MAX_ARGS); args_count = min(count, MAX_ARGS);
args_ptr = ptr; args_ptr = ptr;
setupArgTypes<0>(this->args_type, args...); setupArgTypes(args_type, args...);
} }
retval_t retVal; retval_t retVal;

View File

@ -17,8 +17,8 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
return 0; return 0;
} }
size_t value = *getAmxAddr(amx, params[arg_value]); cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = *getAmxAddr(amx, params[arg_elem]); size_t element = (params[arg_count] == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;
switch (member->type) switch (member->type)
{ {
@ -28,7 +28,7 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
{ {
// native set_member(_index, any:_member, _value, _elem); // native set_member(_index, any:_member, _value, _elem);
CBaseEntity *pEntity = nullptr; CBaseEntity *pEntity = nullptr;
edict_t *pEdictValue = INDEXENT(value); edict_t *pEdictValue = INDEXENT(*value);
if (pEdictValue != nullptr) { if (pEdictValue != nullptr) {
pEntity = CBaseEntity::Instance(pEdictValue); pEntity = CBaseEntity::Instance(pEdictValue);
@ -39,8 +39,8 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
case MEMBER_EHANDLE: case MEMBER_EHANDLE:
{ {
// native set_member(_index, any:_member, _value, _elem); // native set_member(_index, any:_member, _value, _elem);
EHANDLE ehandle = get_member<EHANDLE>(pEdict, member->offset, element); EHANDLE& ehandle = get_member<EHANDLE>(pEdict, member->offset, element);
edict_t *pEdictValue = INDEXENT(value); edict_t *pEdictValue = INDEXENT(*value);
ehandle.Set(pEdictValue); ehandle.Set(pEdictValue);
return 1; return 1;
} }
@ -49,37 +49,33 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
case MEMBER_EDICT: case MEMBER_EDICT:
{ {
// native set_member(_index, any:_member, _value, _elem); // native set_member(_index, any:_member, _value, _elem);
edict_t *pEdictValue = INDEXENT(value); edict_t *pEdictValue = INDEXENT(*value);
set_member<edict_t *>(pEdict, member->offset, pEdictValue, element); set_member<edict_t *>(pEdict, member->offset, pEdictValue, element);
return 1; return 1;
} }
case MEMBER_VECTOR: case MEMBER_VECTOR:
{ {
// native set_member(_index, any:_member, Float:_value[3], _elem); // native set_member(_index, any:_member, Float:_value[3], _elem);
cell *pSource = g_amxxapi.GetAmxAddr(amx, params[arg_value]); Vector *pSource = (Vector *)getAmxAddr(amx, params[arg_value]);
Vector vecDest; set_member<Vector>(pEdict, member->offset, *pSource, element);
vecDest.x = *(vec_t *)&pSource[0];
vecDest.y = *(vec_t *)&pSource[1];
vecDest.z = *(vec_t *)&pSource[2];
set_member<Vector>(pEdict, member->offset, vecDest, element);
return 1; return 1;
} }
case MEMBER_CHAR_ARRAY: case MEMBER_CHAR_ARRAY:
{ {
// native set_member(_index, any:_member, const source[]); // native set_member(_index, any:_member, const source[]);
int len; size_t len;
char *source = g_amxxapi.GetAmxString(amx, params[arg_value], 0, &len); char *source = getAmxString(value, &len);
char *dest = get_member_direct<char *>(pEdict, member->offset); char *dest = get_member_direct<char *>(pEdict, member->offset);
strcpy(dest, source); strncpy(dest, source, member->max_size - 1);
dest[member->max_size - 1] = '\0';
return 1; return 1;
} }
case MEMBER_CHAR_POINTER: case MEMBER_CHAR_POINTER:
{ {
// native set_member(_index, any:_member, const source[]); // native set_member(_index, any:_member, const source[]);
int len; size_t len;
char *source = g_amxxapi.GetAmxString(amx, params[arg_value], 0, &len); char *source = getAmxString(value, &len);
char *dest = get_member<char *>(pEdict, member->offset); char *&dest = get_member<char *>(pEdict, member->offset);
if (dest != nullptr) { if (dest != nullptr) {
delete [] dest; delete [] dest;
@ -95,38 +91,38 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
case MEMBER_INTEGER: case MEMBER_INTEGER:
{ {
// native set_member(_index, any:_member, any:_value, _elem); // native set_member(_index, any:_member, any:_value, _elem);
set_member<int>(pEdict, member->offset, value, element); set_member<int>(pEdict, member->offset, *value, element);
return 1; return 1;
} }
case MEMBER_SHORT: case MEMBER_SHORT:
{ {
// native set_member(_index, any:_member, _value, _elem); // native set_member(_index, any:_member, _value, _elem);
set_member<short>(pEdict, member->offset, value, element); set_member<short>(pEdict, member->offset, *value, element);
return 1; return 1;
} }
case MEMBER_BYTE: case MEMBER_BYTE:
{ {
// native set_member(_index, any:_member, _value, _elem); // native set_member(_index, any:_member, _value, _elem);
set_member<byte>(pEdict, member->offset, value, element); set_member<byte>(pEdict, member->offset, *value, element);
return 1; return 1;
} }
case MEMBER_BOOL: case MEMBER_BOOL:
{ {
// native set_member(_index, any:_member, bool:_value, _elem); // native set_member(_index, any:_member, bool:_value, _elem);
set_member<bool>(pEdict, member->offset, value != 0, element); set_member<bool>(pEdict, member->offset, *value != 0, element);
return 1; return 1;
} }
case MEMBER_SIGNALS: case MEMBER_SIGNALS:
{ {
// native set_member(_index, any:_member, _value); // native set_member(_index, any:_member, _value);
CUnifiedSignals signal = get_member<CUnifiedSignals>(pEdict, member->offset, element); CUnifiedSignals& signal = get_member<CUnifiedSignals>(pEdict, member->offset, element);
signal.Signal(value); signal.Signal(*value);
return 1; return 1;
} }
case MEMBER_DOUBLE: case MEMBER_DOUBLE:
{ {
// native set_member(_index, any:_member, any:_value, _elem); // native set_member(_index, any:_member, any:_value, _elem);
set_member<double>(pEdict, member->offset, *(float *)&value, element); set_member<double>(pEdict, member->offset, *(float *)value, element);
return 1; return 1;
} }
case MEBMER_REBUYSTRUCT: case MEBMER_REBUYSTRUCT:
@ -240,6 +236,10 @@ static cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
return 1; return 1;
} }
case MEMBER_DOUBLE:
{
return 1;
}
case MEBMER_REBUYSTRUCT: case MEBMER_REBUYSTRUCT:
return -1; return -1;
} }