Skip to content

Commit

Permalink
Merge branch 's1lentq:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aleeperezz16 authored Dec 24, 2023
2 parents 0ef9d10 + f155588 commit 8e2bcd4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6355,7 +6355,7 @@ enum CCSEntity_Members
* Get params: get_member(index, member);
* Set params: set_member(index, member, value);
*/
m_ucDmgPenetrationLevel = BEGIN_MEMBER_REGION(csplayerweapon),
m_ucDmgPenetrationLevel = BEGIN_MEMBER_REGION(csentity),

/*
* Description: Cached inflictor passed inside TakeDamage to retrieve in Killed
Expand Down
18 changes: 9 additions & 9 deletions reapi/src/hook_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void SV_DropClient(IRehldsHook_SV_DropClient *chain, IGameClient *cl, bool crash
{
auto original = [chain](int _cl, bool _crash, const char *_fmt)
{
chain->callNext(g_RehldsSvs->GetClient(_cl - 1), _crash, _fmt);
chain->callNext(clientByIndex(_cl), _crash, _fmt);
};

callVoidForward(RH_SV_DropClient, original, cl->GetId() + 1, crash, fmt);
Expand Down Expand Up @@ -50,7 +50,7 @@ void SV_WriteFullClientUpdate_AMXX(SV_WriteFullClientUpdate_t *data, IGameClient
{
auto original = [data](int _client, size_t _buffer, int _receiver)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_client - 1), (char *)_buffer, data->m_args.maxlen, data->m_args.message, g_RehldsSvs->GetClient(_receiver - 1));
data->m_chain->callNext(clientByIndex(_client), (char *)_buffer, data->m_args.maxlen, data->m_args.message, clientByIndex(_receiver));
};

callVoidForward(RH_SV_WriteFullClientUpdate, original, client->GetId() + 1, buffer, receiver ? receiver->GetId() + 1 : AMX_NULLENT);
Expand Down Expand Up @@ -87,7 +87,7 @@ void ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* cl)
{
auto original = [chain](int client)
{
chain->callNext(g_RehldsSvs->GetClient(client - 1));
chain->callNext(clientByIndex(client));
};

callVoidForward(RH_ClientConnected, original, cl->GetId() + 1);
Expand All @@ -107,7 +107,7 @@ void SV_EmitPings_AMXX(SV_EmitPings_t* data, IGameClient* cl)
{
auto original = [data](int _cl)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args.message);
data->m_chain->callNext(clientByIndex(_cl), data->m_args.message);
};

callVoidForward(RH_SV_EmitPings, original, cl->GetId() + 1);
Expand Down Expand Up @@ -236,10 +236,10 @@ void ExecuteServerStringCmd(IRehldsHook_ExecuteServerStringCmd* chain, const cha
{
auto original = [chain](const char* _cmdName, cmd_source_t _cmdSrc, int client)
{
chain->callNext(_cmdName, _cmdSrc, _cmdSrc == src_client ? g_RehldsSvs->GetClient(client) - 1 : 0);
chain->callNext(_cmdName, _cmdSrc, _cmdSrc == src_client ? clientByIndex(client) : nullptr);
};

callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : 0);
callVoidForward(RH_ExecuteServerStringCmd, original, cmdName, cmdSrc, cmdSrc == src_client ? cl->GetId() + 1 : AMX_NULLENT);
}

/*
Expand Down Expand Up @@ -1734,7 +1734,7 @@ void FileConsistencyProcess_AMXX(FileConsistencyProcess_t *data, IGameClient *cl
int hashCopy = responseHash;
auto original = [data, hashCopy](int _cl, const char *_filename, const char *_cmd, ResourceType_e _type, uint32 _hash, bool _isBreak)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args, _type, hashCopy);
data->m_chain->callNext(clientByIndex(_cl), data->m_args, _type, hashCopy);
};

if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {
Expand All @@ -1754,7 +1754,7 @@ void FileConsistencyFinal(IRecheckerHook_FileConsistencyFinal *chain, IGameClien
{
auto original = [chain](int _cl)
{
chain->callNext(g_RehldsSvs->GetClient(_cl - 1));
chain->callNext(clientByIndex(_cl));
};

callVoidForward(RC_FileConsistencyFinal, original, cl->GetId() + 1);
Expand All @@ -1765,7 +1765,7 @@ void CmdExec_AMXX(CmdExec_t *data, IGameClient *cl, const char *filename, char *
int hashCopy = responseHash;
auto original = [data, hashCopy](int _cl, const char *_filename, char *_cmd, uint32 _responseHash)
{
data->m_chain->callNext(g_RehldsSvs->GetClient(_cl - 1), data->m_args, _cmd, hashCopy);
data->m_chain->callNext(clientByIndex(_cl), data->m_args, _cmd, hashCopy);
};

if (g_RecheckerFuncs->GetResource()->GetPrevHash() == responseHash) {
Expand Down
35 changes: 35 additions & 0 deletions reapi/src/member_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ struct member_t
const char *name;
MType type;
bool (*pfnIsRefsToClass)(void *pEntity);

inline static const char *getTypeString(MType memberType)
{
switch (memberType)
{
case MEMBER_FLOAT: return "Float";
case MEMBER_DOUBLE: return "Double";
case MEMBER_ENTITY: return "Entity";
case MEMBER_CLASSPTR: return "ClassPtr";
case MEMBER_EHANDLE: return "EHANDLE";
case MEMBER_EVARS: return "entvars";
case MEMBER_EDICT: return "edict";
case MEMBER_VECTOR: return "Vector";
case MEMBER_STRING: return "String";
case MEMBER_QSTRING: return "QStirng";
case MEMBER_INTEGER: return "Integer";
case MEMBER_SHORT: return "Short";
case MEMBER_BYTE: return "Byte";
case MEMBER_BOOL: return "Bool";
case MEMBER_SIGNALS: return "Signals";
case MEBMER_REBUYSTRUCT: return "RebuyStruct";
case MEMBER_PMTRACE: return "pmtrace";
case MEBMER_USERCMD: return "usercmd";
case MEMBER_TRACERESULT: return "TraceResult";
default:
{
static char string[16];
Q_snprintf(string, sizeof(string), "%d", memberType);
return string;
}
}

return ""; // shut up compiler
}

};

inline bool member_t::isTypeReturnable() const
Expand Down
59 changes: 36 additions & 23 deletions reapi/src/natives/natives_members.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cell AMX_NATIVE_CALL set_member(AMX *amx, cell *params)
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;

return set_member(
amx,
get_pdata_custom(getPrivate<CBaseEntity>(pEdict), params[arg_member]),
member,
value,
Expand Down Expand Up @@ -99,7 +100,7 @@ cell AMX_NATIVE_CALL get_member(AMX *amx, cell *params)
break;
}

return get_member(
return get_member(amx,
get_pdata_custom(getPrivate<CBaseEntity>(pEdict), params[arg_member]),
member,
dest,
Expand Down Expand Up @@ -145,6 +146,7 @@ cell AMX_NATIVE_CALL set_member_s(AMX *amx, cell *params)
}

return set_member(
amx,
pEntity,
member,
value,
Expand Down Expand Up @@ -225,6 +227,7 @@ cell AMX_NATIVE_CALL get_member_s(AMX *amx, cell *params)
}

return get_member(
amx,
pEntity,
member,
dest,
Expand Down Expand Up @@ -257,7 +260,7 @@ cell AMX_NATIVE_CALL set_member_game(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;

return set_member(g_pGameRules, member, value, element);
return set_member(amx, g_pGameRules, member, value, element);
}

/*
Expand Down Expand Up @@ -308,7 +311,7 @@ cell AMX_NATIVE_CALL get_member_game(AMX *amx, cell *params)
length = 0;
}

return get_member(g_pGameRules, member, dest, element, length);
return get_member(amx, g_pGameRules, member, dest, element, length);
}

/*
Expand Down Expand Up @@ -337,7 +340,7 @@ cell AMX_NATIVE_CALL set_entvar(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_elem]) : 0;

return set_member(&pEdict->v, member, value, element);
return set_member(amx, &pEdict->v, member, value, element);
}

/*
Expand Down Expand Up @@ -399,7 +402,7 @@ cell AMX_NATIVE_CALL get_entvar(AMX *amx, cell *params)
length = 0;
}

return get_member(&pEdict->v, member, dest, element, length);
return get_member(amx, &pEdict->v, member, dest, element, length);
}

/*
Expand All @@ -424,7 +427,7 @@ cell AMX_NATIVE_CALL set_pmove(AMX *amx, cell *params)
cell* value = getAmxAddr(amx, params[arg_value]);
size_t element = (PARAMS_COUNT == 3) ? *getAmxAddr(amx, params[arg_elem]) : 0;

return set_member(g_pMove, member, value, element);
return set_member(amx, g_pMove, member, value, element);
}

/*
Expand Down Expand Up @@ -492,7 +495,7 @@ cell AMX_NATIVE_CALL get_pmove(AMX *amx, cell *params)
length = 0;
}

return get_member(g_pMove, member, dest, element, length);
return get_member(amx, g_pMove, member, dest, element, length);
}

/*
Expand All @@ -515,7 +518,7 @@ cell AMX_NATIVE_CALL set_movevar(AMX *amx, cell *params)
}

cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(g_pMove->movevars, member, value, 0);
return set_member(amx, g_pMove->movevars, member, value, 0);
}

/*
Expand Down Expand Up @@ -552,7 +555,7 @@ cell AMX_NATIVE_CALL get_movevar(AMX *amx, cell *params)
length = 0;
}

return get_member(g_pMove->movevars, member, dest, element, length);
return get_member(amx, g_pMove->movevars, member, dest, element, length);
}

/*
Expand All @@ -573,7 +576,7 @@ cell AMX_NATIVE_CALL set_ucmd(AMX *amx, cell *params)

cell* cmd = (cell *)params[arg_cmd];
cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(cmd, member, value, 0);
return set_member(amx, cmd, member, value, 0);
}

/*
Expand Down Expand Up @@ -605,7 +608,7 @@ cell AMX_NATIVE_CALL get_ucmd(AMX *amx, cell *params)
}

cell* cmd = (cell *)params[arg_cmd];
return get_member(cmd, member, dest, element);
return get_member(amx, cmd, member, dest, element);
}

/*
Expand All @@ -629,7 +632,7 @@ cell AMX_NATIVE_CALL set_pmtrace(AMX *amx, cell *params)

cell* tr = (cell *)params[arg_tr];
cell* value = getAmxAddr(amx, params[arg_value]);
return set_member(tr, member, value, 0);
return set_member(amx, tr, member, value, 0);
}

/*
Expand Down Expand Up @@ -664,7 +667,7 @@ cell AMX_NATIVE_CALL get_pmtrace(AMX *amx, cell *params)
}

cell* tr = (cell *)params[arg_tr];
return get_member(tr, member, dest, element);
return get_member(amx, tr, member, dest, element);
}

/*
Expand Down Expand Up @@ -782,7 +785,7 @@ cell AMX_NATIVE_CALL set_rebuy(AMX *amx, cell *params)
return FALSE;
}

return set_member(handle, member, &params[arg_value], 0);
return set_member(amx, handle, member, &params[arg_value], 0);
}

/*
Expand Down Expand Up @@ -810,7 +813,7 @@ cell AMX_NATIVE_CALL get_rebuy(AMX *amx, cell *params)
return FALSE;
}

return get_member(handle, member, nullptr, 0);
return get_member(amx, handle, member, nullptr, 0);
}

AMX_NATIVE_INFO EngineVars_Natives[] =
Expand Down Expand Up @@ -862,7 +865,7 @@ void RegisterNatives_Members()
g_amxxapi.AddNatives(EngineVars_Natives);
}

cell set_member(void* pdata, const member_t *member, cell* value, size_t element)
cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size_t element)
{
if (!pdata) {
return FALSE;
Expand Down Expand Up @@ -892,6 +895,13 @@ cell set_member(void* pdata, const member_t *member, cell* value, size_t element
set_member<edict_t *>(pdata, member->offset, pEdictValue, element);
return TRUE;
}
case MEMBER_EVARS:
{
// native set_member(_index, any:_member, _value, _elem);
entvars_t *pev = PEV(*value);
set_member<entvars_t *>(pdata, member->offset, pev, element);
return TRUE;
}
case MEMBER_VECTOR:
{
// native set_member(_index, any:_member, Float:_value[3], _elem);
Expand Down Expand Up @@ -975,21 +985,19 @@ cell set_member(void* pdata, const member_t *member, cell* value, size_t element
set_member<TraceResult>(pdata, member->offset, *(TraceResult *)value, element);
return TRUE;
}

case MEMBER_ENTITY:
case MEMBER_EVARS:
case MEBMER_REBUYSTRUCT:
case MEMBER_PMTRACE:
case MEBMER_USERCMD:
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: member type %s (%s) is not supported", __FUNCTION__, member_t::getTypeString(member->type), member->name);
return FALSE;

default: break;
}

return FALSE;
}

cell get_member(void* pdata, const member_t *member, cell* dest, size_t element, size_t length)
cell get_member(AMX *amx, void* pdata, const member_t *member, cell* dest, size_t element, size_t length)
{
if (!pdata) {
return 0;
Expand All @@ -1016,6 +1024,12 @@ cell get_member(void* pdata, const member_t *member, cell* dest, size_t element,
edict_t *pEntity = get_member<edict_t *>(pdata, member->offset, element);
return pEntity ? indexOfEdict(pEntity) : AMX_NULLENT;
}
case MEMBER_EVARS:
{
// native any:get_member(_index, any:_member, element);
entvars_t *pev = get_member<entvars_t *>(pdata, member->offset, element);
return pev ? indexOfEdict(pev) : AMX_NULLENT;
}
case MEMBER_VECTOR:
{
// native any:get_member(_index, any:_member, any:output[], element);
Expand Down Expand Up @@ -1100,10 +1114,9 @@ cell get_member(void* pdata, const member_t *member, cell* dest, size_t element,
pSignals[_State] = signal.GetState();
return 1;
}

case MEMBER_ENTITY:
case MEMBER_EVARS:
return 0;
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: member type %s (%s) is not supported", __FUNCTION__, member_t::getTypeString(member->type), member->name);
return FALSE;
case MEMBER_TRACERESULT:
return (cell)get_member_direct<TraceResult>(pdata, member->offset, element);
case MEBMER_REBUYSTRUCT:
Expand Down
4 changes: 2 additions & 2 deletions reapi/src/natives/natives_members.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
void RegisterNatives_Members();

void *get_pdata_custom(CBaseEntity *pEntity, cell member);
cell set_member(void* pdata, const member_t *member, cell* value, size_t element);
cell get_member(void* pdata, const member_t *member, cell* dest, size_t element, size_t length = 0);
cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size_t element);
cell get_member(AMX *amx, void* pdata, const member_t *member, cell* dest, size_t element, size_t length = 0);

bool isTypeReturnable(MType type);
Loading

0 comments on commit 8e2bcd4

Please sign in to comment.