Skip to content

Commit

Permalink
Merge branch 's1lentq-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-up committed Sep 7, 2024
2 parents 2115791 + 808b4de commit 50bdd9b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
2 changes: 2 additions & 0 deletions reapi/extra/amxmodx/scripting/include/cssdk_const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
#define EF_FORCEVISIBILITY 2048 // force visibility
#define EF_OWNER_VISIBILITY 4096 // visibility for owner
#define EF_OWNER_NO_VISIBILITY 8192 // no visibility for owner
#define EF_NOSLERP 16384 // no slerp flag for this entity (addtofullpack)
#define EF_FOLLOWKEEPRENDER 32768 // the entity following will not copy the render (like it follows nothing)

/**
* Break Model Defines
Expand Down
5 changes: 4 additions & 1 deletion reapi/extra/amxmodx/scripting/include/reapi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ enum
{
HC_CONTINUE = 0, // Plugin didn't take any action
HC_SUPERCEDE, // Skip real function, use my return value
HC_BREAK // Skip all forwards and real function, use my return value
HC_BREAK, // Skip all forwards and real function, use my return value
// @note Warning: Be very careful, using this type of return will skip calls for all following AMXX plugins

HC_BYPASS // Skip calls for all following AMXX plugins, but call the original function
// @note Warning: In PRE skips all forwards including POST forwards
};

/**
Expand Down
5 changes: 3 additions & 2 deletions reapi/extra/amxmodx/scripting/include/reapi_engine.inc
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,13 @@ native rh_set_pause(const bool:st, const bool:host = true);
/*
* Checks if a specific entity is fully packed in a given frame for a host client.
*
* @param index Client index for whom we are checking the entity.
* @param host Host index for whom we are checking the entity. (Host cannot be a fake client)
* @param entity Entity index to find in the table of entities for the given frame.
* @param frame Frame index where to look. Default is -1, which checks the previous frame.
* @note To check in the current frame, this native should be called at the end of the server frame.
*
* @return Returns true if the entity is fully packed and ready to be sent to all clients in the given frame, otherwise false.
* @return Returns true if the entity is present in the host's outgoing entity table and
* ready to be sent to all clients in the given frame, otherwise false.
*/
native bool:rh_is_entity_fullpacked(const host, const entity, const frame = -1);

Expand Down
38 changes: 23 additions & 15 deletions reapi/src/hook_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
// hookchain return type
enum HookChainState
{
HC_CONTINUE = 0, // plugin didn't take any action
HC_SUPERCEDE, // skip real function, use my return value
HC_BREAK // skip all forwards and real function, use my return value
// @note Warning: Be very careful using this type of return will skip calls for all following AMXX the plugins.
HC_CONTINUE = 0, // Plugin didn't take any action
HC_SUPERCEDE, // Skip real function, use my return value
HC_BREAK, // Skip all forwards and real function, use my return value
// @note Warning: Be very careful using this type of return will skip calls for all following AMXX the plugins

HC_BYPASS // Skip calls for all following AMXX plugins, but call the original function
// @note Warning: In PRE skips all forwards including POST forwards
};

// api types
Expand Down Expand Up @@ -168,15 +171,17 @@ NOINLINE void DLLEXPORT _callVoidForward(hook_t* hook, original_t original, f_ar
if (likely(fwd->GetState() == FSTATE_ENABLED))
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
auto ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
int ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();

if (unlikely(ret == HC_BREAK)) {
if (unlikely(ret == HC_BREAK))
return;
}

if (unlikely(ret > hc_state))
hc_state = ret;

if (unlikely(ret == HC_BYPASS))
break;
}
}

Expand All @@ -187,16 +192,19 @@ NOINLINE void DLLEXPORT _callVoidForward(hook_t* hook, original_t original, f_ar
hook->wasCalled = true;
}

for (auto fwd : hook->post)
if (hc_state != HC_BYPASS)
{
if (likely(fwd->GetState() == FSTATE_ENABLED))
for (auto fwd : hook->post)
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
auto ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();

if (unlikely(ret == HC_BREAK))
break;
if (likely(fwd->GetState() == FSTATE_ENABLED))
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
int ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();

if (unlikely(ret == HC_BREAK || ret == HC_BYPASS))
break;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions reapi/src/natives/natives_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define CHECK_INSTANCE_OF(x, y) if (unlikely(dynamic_cast<x *>((x::BaseClass *)y) == nullptr)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity %d ('%s'), is not an instance of the base class '%s'", __FUNCTION__, indexOfEdict(y->pev), STRING(y->pev->classname), #x); return FALSE; }
#define CHECK_REQUIREMENTS(x) if (unlikely(!api_cfg.has##x())) { AMXX_LogError(amx, AMX_ERR_NATIVE, "Native '%s' is not available, %s required.", __FUNCTION__, #x); return FALSE; } if (!g_RehldsMessageManager) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: %s message manager not initialized.", __FUNCTION__, #x); return FALSE; }

#define AMX_ENTITY_VALIDATE(x, y) if (unlikely(x < AMX_NULLENT || x > gpGlobals->maxEntities)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: \"%s\" invalid entity index %i", __FUNCTION__, y, x); return FALSE; }

class CAmxArg
{
public:
Expand Down
4 changes: 4 additions & 0 deletions reapi/src/natives/natives_members.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,13 +939,15 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size
switch (member->type) {
case MEMBER_CLASSPTR:
{
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
CBaseEntity *pEntity = getPrivate<CBaseEntity>(*value);
set_member<CBaseEntity *>(pdata, member->offset, pEntity, element);
return TRUE;
}
case MEMBER_EHANDLE:
{
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
EHANDLE& ehandle = get_member<EHANDLE>(pdata, member->offset, element);
edict_t *pEdictValue = edictByIndexAmx(*value);
Expand All @@ -954,13 +956,15 @@ cell set_member(AMX *amx, void* pdata, const member_t *member, cell* value, size
}
case MEMBER_EDICT:
{
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
edict_t *pEdictValue = edictByIndexAmx(*value);
set_member<edict_t *>(pdata, member->offset, pEdictValue, element);
return TRUE;
}
case MEMBER_EVARS:
{
AMX_ENTITY_VALIDATE(*value, member->name);
// native set_member(_index, any:_member, _value, _elem);
entvars_t *pev = PEV(*value);
set_member<entvars_t *>(pdata, member->offset, pev, element);
Expand Down
24 changes: 16 additions & 8 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3712,33 +3712,41 @@ cell AMX_NATIVE_CALL rh_get_client_connect_time(AMX *amx, cell *params)
}

/*
* Checks if a specific entity is fully packed in a given frame for a host client.
* Checks if a specific entity is present in the host's outgoing entity table for a given frame,
* indicating it has passed the visibility check (AddToFullPack) and is ready for client transmission.
*
* @param index Client index for whom we are checking the entity.
* @param host Host index for whom we are checking the entity. (Host cannot be a fake client)
* @param entity Entity index to find in the table of entities for the given frame.
* @param frame Frame index where to look. Default is -1, which checks the previous frame.
* @note To check in the current frame, this native should be called at the end of the server frame.
*
* @return Returns true if the entity is fully packed and ready to be sent to all clients in the given frame, otherwise false.
* @return Returns true if the entity is present in the host's outgoing entity table and
* ready to be sent to all clients in the given frame, otherwise false.
*
* native bool:rh_is_entity_fullpacked(const host, const entity, const frame = -1);
*/
cell AMX_NATIVE_CALL rh_is_entity_fullpacked(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_entity, arg_frame };
enum args_e { arg_count, arg_host, arg_entity, arg_frame };

const int SV_UPDATE_BACKUP = (gpGlobals->maxClients == 1) ? SINGLEPLAYER_BACKUP : MULTIPLAYER_BACKUP;
const int SV_UPDATE_MASK = (SV_UPDATE_BACKUP - 1);

CHECK_ISPLAYER(arg_index);
CHECK_ISPLAYER(arg_host);

client_t *pClient = clientOfIndex(params[arg_index]);
CHECK_CLIENT_CONNECTED(pClient, arg_index);
client_t *pHost = clientOfIndex(params[arg_host]);
CHECK_CLIENT_CONNECTED(pHost, arg_host);

if (pHost->fakeclient)
{
AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Entity checking for fake client (#%d) is invalid. Fake clients do not process entity updates.", __FUNCTION__, params[arg_host]);
return FALSE;
}

int iEntity = params[arg_entity];
int iFrame = params[arg_frame];

client_frame_t *frame = &pClient->frames[(pClient->netchan.outgoing_sequence + iFrame) & SV_UPDATE_MASK];
client_frame_t *frame = &pHost->frames[(pHost->netchan.outgoing_sequence + iFrame) & SV_UPDATE_MASK];
packet_entities_t *fullpack = &frame->entities;

for (int i = 0; i < fullpack->num_entities; i++)
Expand Down
16 changes: 15 additions & 1 deletion reapi/src/reapi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,20 @@ void GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector
if (iBone < 0 || iBone >= pstudiohdr->numbones)
return; // invalid bone

float flFrame = pEdict->v.frame;
float flAnimTime = pEdict->v.animtime;

// force to update frame
StudioFrameAdvanceEnt(pstudiohdr, pEdict);

pEntity->pev->angles.x = -pEntity->pev->angles.x;
GET_BONE_POSITION(pEdict, iBone, vecOrigin, vecAngles);
pEntity->pev->angles.x = -pEntity->pev->angles.x;

// restore the original state for the entity
pEdict->v.frame = flFrame;
pEdict->v.animtime = flAnimTime;

// ReGameDLL already have fixes angles for non-players entities
if (!g_ReGameApi && !pEntity->IsPlayer()) {
FixupAngles(pEdict, vecOrigin);
Expand Down Expand Up @@ -204,11 +211,18 @@ void GetAttachment(CBaseEntity *pEntity, int iAttachment, Vector *pVecOrigin, Ve
if (iAttachment < 0 || iAttachment >= pstudiohdr->numattachments)
return; // invalid attachment

float flFrame = pEdict->v.frame;
float flAnimTime = pEdict->v.animtime;

// force to update frame
StudioFrameAdvanceEnt(pstudiohdr, pEdict);

GET_ATTACHMENT(pEdict, iAttachment, vecOrigin, vecAngles);

// restore the original state for the entity
pEdict->v.frame = flFrame;
pEdict->v.animtime = flAnimTime;

// ReGameDLL already have fixes angles for non-players entities
if (!g_ReGameApi && !pEntity->IsPlayer()) {
FixupAngles(pEdict, vecOrigin);
Expand Down Expand Up @@ -281,7 +295,7 @@ bool GetSequenceInfo2(CBaseEntity *pEntity, int *piFlags, float *pflFrameRate, f
*pflFrameRate = 256.0f;
*pflGroundSpeed = 0.0f;
}
else
else
{
*pflFrameRate = pseqdesc->fps * 256.0f / (pseqdesc->numframes - 1);
*pflGroundSpeed = Q_sqrt(pseqdesc->linearmovement[0] * pseqdesc->linearmovement[0] + pseqdesc->linearmovement[1] * pseqdesc->linearmovement[1] + pseqdesc->linearmovement[2] * pseqdesc->linearmovement[2]);
Expand Down

0 comments on commit 50bdd9b

Please sign in to comment.