From a257317f58ecbbd1a03d7a9c4c045924988d5a77 Mon Sep 17 00:00:00 2001 From: 8dcc <8dcc.git@gmail.com> Date: Sun, 23 Jul 2023 22:22:36 +0200 Subject: [PATCH] Add get_entity to util.c With checks to make sure entity is correct Remove is_alive check from valid_client Fixes 41e6b012d9e34712e2080ff11a9c9a56cfcbbc13 --- src/include/util.h | 1 + src/util.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/include/util.h b/src/include/util.h index 656227a..31fae2e 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -21,6 +21,7 @@ typedef struct { /*----------------------------------------------------------------------------*/ +cl_entity_t* get_entity(int ent_idx); bool is_alive(cl_entity_t* ent); bool valid_client(cl_entity_t* ent); char* get_name(int ent_idx); diff --git a/src/util.c b/src/util.c index 7f7ace8..1d7a371 100644 --- a/src/util.c +++ b/src/util.c @@ -7,12 +7,24 @@ #include #include +cl_entity_t* get_entity(int ent_idx) { + if (ent_idx < 0 || ent_idx > 32) + return NULL; + + cl_entity_t* ent = i_engine->GetEntityByIndex(ent_idx); + + if (ent->curstate.messagenum < localplayer->curstate.messagenum) + return NULL; + + return ent; +} + bool is_alive(cl_entity_t* ent) { return ent && ent->curstate.movetype != 6 && ent->curstate.movetype != 0; } bool valid_client(cl_entity_t* ent) { - return is_alive(ent) && ent->index != localplayer->index; + return ent && ent->index != localplayer->index; } char* get_name(int ent_idx) {