ref: 8a4ebe3fc930049a7ad7699443a44412d7a16a6a
parent: 51431bdefa5aaf9c99dd5524df93dd81c8a18368
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Dec 28 13:19:14 EST 2023
PF_find: workarounds for a bit of insanity
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -943,18 +943,24 @@
// entity (entity start, .string field, string match) find = #5;
static void
-PF_Find(pr_t *pr)
+PF_find(pr_t *pr)
{
int e;
int f;
char *s, *t;
edict_t *ed;
+ ddef_t *def;
e = G_EDICTNUM(pr, OFS_PARM0);
f = G_INT(pr, OFS_PARM1);
s = G_STRING(pr, OFS_PARM2);
if (!s)
- PR_RunError (pr, "PF_Find: bad search string");
+ PR_RunError(pr, "PF_find: bad search string");
+ if((def = ED_FieldAtOfs(pr, f)) == nil)
+ PR_RunError(pr, "PF_find: invalid field offset %d", f);
+ // FIXME(sigrid): apparently this is common
+ //if(def->type != ev_string)
+ // Con_DPrintf("PF_find: not a string field: %s", PR_Str(pr, def->s_name));
for (e++ ; e < pr->num_edicts ; e++)
{
@@ -962,10 +968,9 @@
if (ed->free)
continue;
t = E_STRING(pr, ed, f);
- if (!t)
- continue;
- if (!strcmp(t, s))
- {
+ if (t == nil)
+ t = "";
+ if(!strcmp(t, s)){
RETURN_EDICT(pr, ed);
return;
}
@@ -1830,7 +1835,7 @@
PF_Remove, // void(entity e) remove = #15;
PF_traceline, // float(vector v1, vector v2, float tryents) traceline = #16;
PF_checkclient, // entity() clientlist = #17;
-PF_Find, // entity(entity start, .string fld, string match) find = #18;
+PF_find, // entity(entity start, .string fld, string match) find = #18;
PF_precache_sound, // void(string s) precache_sound = #19;
PF_precache_model, // void(string s) precache_model = #20;
PF_stuffcmd, // void(entity client, string s)stuffcmd = #21;
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -11,7 +11,6 @@
[ev_pointer] = sizeof(void *)/4,
};
-ddef_t *ED_FieldAtOfs (pr_t *pr, int ofs);
bool ED_ParseEpair (pr_t *pr, void *base, ddef_t *key, char *s);
void PR_InitSV(pr_t *pr);
--- a/progs.h
+++ b/progs.h
@@ -144,6 +144,7 @@
#pragma varargck argpos PR_RunError 2
void PR_RunError (pr_t *pr, char *error, ...);
+ddef_t *ED_FieldAtOfs (pr_t *pr, int ofs);
void ED_PrintEdicts(void);
void ED_PrintNum(pr_t *pr, int ent);