From ce06b1d3d78021a72ef557b77efd4ff49478e411 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 20 Dec 2024 05:47:18 +0300 Subject: [PATCH] engine: client: allow CL_GetLocalPlayer to return NULL rather than halting whole server --- engine/client/cl_scrn.c | 2 +- engine/client/client.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 139be701..ea6017a9 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -124,7 +124,7 @@ void SCR_DrawPos( void ) if( cls.state != ca_active || !cl_showpos.value || cl.background ) return; - ent = CL_EDICT_NUM( cl.playernum + 1 ); + ent = CL_GetLocalPlayer(); speed = VectorLength( cl.simvel ); Q_snprintf( msg, MAX_SYSPATH, diff --git a/engine/client/client.h b/engine/client/client.h index 476a8828..6b33578c 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -881,10 +881,12 @@ static inline qboolean CL_IsThirdPerson( void ) static inline cl_entity_t *CL_GetLocalPlayer( void ) { - cl_entity_t *player; + cl_entity_t *player = CL_GetEntityByIndex( cl.playernum + 1 ); - player = CL_EDICT_NUM( cl.playernum + 1 ); - Assert( player != NULL ); + // HACKHACK: GoldSrc doesn't do this, but some mods actually check it for null pointer + // this is a lesser evil than changing semantics of HUD_VidInit and call it after entities are allocated + if( !player ) + Con_Printf( S_WARN "%s: client entities are not initialized yet! Returning NULL...\n", __func__ ); return player; }