From 6d0db0d5bee0201b732149616a691827367cfb35 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 3 May 2022 04:20:27 +0100 Subject: Add entity property finding and L4D warp testing This was a lot more code than expected, but it might be finally close to time to release the next beta... We'll see if any more rabbit holes present themselves to jump into, though. --- src/ent.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/ent.c') diff --git a/src/ent.c b/src/ent.c index b621e0b..2e47208 100644 --- a/src/ent.c +++ b/src/ent.c @@ -21,29 +21,39 @@ #include "gamedata.h" #include "gametype.h" #include "intdefs.h" +#include "mem.h" #include "vcall.h" DECL_VFUNC_DYN(void *, PEntityOfEntIndex, int) +static struct edict **edicts = 0; -void *ent_get(int idx) { - // TODO(compat): Based on previous attempts at this, for L4D2, we need - // factory_server("PlayerInfoManager002")->GetGlobalVars()->edicts - // (offset 22 or so). Then get edicts from that. For now, we only need this - // for Portal FOV stuff, so just doing this eiface stuff. +void *ent_getedict(int idx) { + if (edicts) { + // globalvars->edicts seems to be null when disconnected + if (!*edicts) return 0; + return mem_offset(*edicts, sz_edict * idx); + } + else { + return VCALL(engserver, PEntityOfEntIndex, idx); + } +} - struct edict *e = VCALL(engserver, PEntityOfEntIndex, idx); +void *ent_get(int idx) { + struct edict *e = ent_getedict(idx); if (!e) return 0; return e->ent_unknown; } bool ent_init(void) { - if (!has_vtidx_PEntityOfEntIndex) { - con_warn("ent: missing gamedata entries for this engine\n"); - return false; + // for PEntityOfEntIndex we don't really have to do any more init, we + // can just call the function later. + if (has_vtidx_PEntityOfEntIndex) return true; + if (globalvars && has_off_edicts) { + edicts = mem_offset(globalvars, off_edicts); + return true; } - // for PEntityOfEntIndex we don't really have to do any more init, we can - // just call the function later. - return true; + con_warn("ent: not implemented for this engine\n"); + return false; } // vi: sw=4 ts=4 noet tw=80 cc=80 -- cgit v1.2.3