diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 28f8b96..263ac40 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -47,7 +47,7 @@ void setupArgTypes(AType args_type[]) #define MAX_ARGS 10u -template +template void setupArgTypes(AType args_type[MAX_ARGS], T arg, t_args... args) { args_type[current] = getApiType(arg); @@ -62,7 +62,7 @@ struct hookctx_t { args_count = min(count, MAX_ARGS); args_ptr = ptr; - setupArgTypes<0>(this->args_type, args...); + setupArgTypes(args_type, args...); } retval_t retVal; diff --git a/reapi/src/natives_member.cpp b/reapi/src/natives_member.cpp index f75a984..5052530 100644 --- a/reapi/src/natives_member.cpp +++ b/reapi/src/natives_member.cpp @@ -17,8 +17,8 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) return 0; } - size_t value = *getAmxAddr(amx, params[arg_value]); - size_t element = *getAmxAddr(amx, params[arg_elem]); + cell* value = getAmxAddr(amx, params[arg_value]); + size_t element = (params[arg_count] == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0; 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); CBaseEntity *pEntity = nullptr; - edict_t *pEdictValue = INDEXENT(value); + edict_t *pEdictValue = INDEXENT(*value); if (pEdictValue != nullptr) { pEntity = CBaseEntity::Instance(pEdictValue); @@ -39,8 +39,8 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) case MEMBER_EHANDLE: { // native set_member(_index, any:_member, _value, _elem); - EHANDLE ehandle = get_member(pEdict, member->offset, element); - edict_t *pEdictValue = INDEXENT(value); + EHANDLE& ehandle = get_member(pEdict, member->offset, element); + edict_t *pEdictValue = INDEXENT(*value); ehandle.Set(pEdictValue); return 1; } @@ -49,37 +49,33 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) case MEMBER_EDICT: { // native set_member(_index, any:_member, _value, _elem); - edict_t *pEdictValue = INDEXENT(value); + edict_t *pEdictValue = INDEXENT(*value); set_member(pEdict, member->offset, pEdictValue, element); return 1; } case MEMBER_VECTOR: { // native set_member(_index, any:_member, Float:_value[3], _elem); - cell *pSource = g_amxxapi.GetAmxAddr(amx, params[arg_value]); - Vector vecDest; - vecDest.x = *(vec_t *)&pSource[0]; - vecDest.y = *(vec_t *)&pSource[1]; - vecDest.z = *(vec_t *)&pSource[2]; - - set_member(pEdict, member->offset, vecDest, element); + Vector *pSource = (Vector *)getAmxAddr(amx, params[arg_value]); + set_member(pEdict, member->offset, *pSource, element); return 1; } case MEMBER_CHAR_ARRAY: { // native set_member(_index, any:_member, const source[]); - int len; - char *source = g_amxxapi.GetAmxString(amx, params[arg_value], 0, &len); + size_t len; + char *source = getAmxString(value, &len); char *dest = get_member_direct(pEdict, member->offset); - strcpy(dest, source); + strncpy(dest, source, member->max_size - 1); + dest[member->max_size - 1] = '\0'; return 1; } case MEMBER_CHAR_POINTER: { // native set_member(_index, any:_member, const source[]); - int len; - char *source = g_amxxapi.GetAmxString(amx, params[arg_value], 0, &len); - char *dest = get_member(pEdict, member->offset); + size_t len; + char *source = getAmxString(value, &len); + char *&dest = get_member(pEdict, member->offset); if (dest != nullptr) { delete [] dest; @@ -95,38 +91,38 @@ static cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params) case MEMBER_INTEGER: { // native set_member(_index, any:_member, any:_value, _elem); - set_member(pEdict, member->offset, value, element); + set_member(pEdict, member->offset, *value, element); return 1; } case MEMBER_SHORT: { // native set_member(_index, any:_member, _value, _elem); - set_member(pEdict, member->offset, value, element); + set_member(pEdict, member->offset, *value, element); return 1; } case MEMBER_BYTE: { // native set_member(_index, any:_member, _value, _elem); - set_member(pEdict, member->offset, value, element); + set_member(pEdict, member->offset, *value, element); return 1; } case MEMBER_BOOL: { // native set_member(_index, any:_member, bool:_value, _elem); - set_member(pEdict, member->offset, value != 0, element); + set_member(pEdict, member->offset, *value != 0, element); return 1; } case MEMBER_SIGNALS: { // native set_member(_index, any:_member, _value); - CUnifiedSignals signal = get_member(pEdict, member->offset, element); - signal.Signal(value); + CUnifiedSignals& signal = get_member(pEdict, member->offset, element); + signal.Signal(*value); return 1; } case MEMBER_DOUBLE: { // native set_member(_index, any:_member, any:_value, _elem); - set_member(pEdict, member->offset, *(float *)&value, element); + set_member(pEdict, member->offset, *(float *)value, element); return 1; } case MEBMER_REBUYSTRUCT: @@ -234,12 +230,16 @@ static cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params) CUnifiedSignals signal = get_member(pEdict, member->offset); cell *pSignal = g_amxxapi.GetAmxAddr(amx, params[3]); cell *pState = g_amxxapi.GetAmxAddr(amx, params[4]); - + *pSignal = signal.GetSignal(); *pState = signal.GetState(); return 1; } + case MEMBER_DOUBLE: + { + return 1; + } case MEBMER_REBUYSTRUCT: return -1; }