summaryrefslogtreecommitdiffhomepage
path: root/src/ent.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2022-05-03 04:20:27 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2022-05-03 16:55:46 +0100
commit6d0db0d5bee0201b732149616a691827367cfb35 (patch)
tree842936f4ec6cb8e27ce10682de77728a4ea93bf9 /src/ent.c
parent19d96b65e1a840407a7280ab1f99d48d62932620 (diff)
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.
Diffstat (limited to 'src/ent.c')
-rw-r--r--src/ent.c34
1 files changed, 22 insertions, 12 deletions
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