X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=pr_edict.c;h=23a05d1f95b6864c63d289f4733a753b2788d903;hb=929f9a6fe217e9c8ca40a68a5229b08400233946;hp=7f2bcf08d4bcfa420f55c893392d7e94ef503de6;hpb=2275e4d0cab079f4a0849ba55b8f92023d6f3eab;p=xonotic%2Fdarkplaces.git diff --git a/pr_edict.c b/pr_edict.c index 7f2bcf08..23a05d1f 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -32,38 +32,42 @@ float *pr_globals; // same as pr_global_struct int pr_edict_size; // in bytes int pr_edictareasize; // LordHavoc: in bytes -unsigned short pr_crc; +unsigned short pr_crc; + +mempool_t *progs_mempool; +mempool_t *edictstring_mempool; int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4}; ddef_t *ED_FieldAtOfs (int ofs); qboolean ED_ParseEpair (void *base, ddef_t *key, char *s); -cvar_t nomonsters = {"nomonsters", "0"}; -cvar_t gamecfg = {"gamecfg", "0"}; -cvar_t scratch1 = {"scratch1", "0"}; -cvar_t scratch2 = {"scratch2", "0"}; -cvar_t scratch3 = {"scratch3", "0"}; -cvar_t scratch4 = {"scratch4", "0"}; -cvar_t savedgamecfg = {"savedgamecfg", "0", true}; -cvar_t saved1 = {"saved1", "0", true}; -cvar_t saved2 = {"saved2", "0", true}; -cvar_t saved3 = {"saved3", "0", true}; -cvar_t saved4 = {"saved4", "0", true}; -cvar_t decors = {"decors", "0"}; -cvar_t nehx00 = {"nehx00", "0"};cvar_t nehx01 = {"nehx01", "0"}; -cvar_t nehx02 = {"nehx02", "0"};cvar_t nehx03 = {"nehx03", "0"}; -cvar_t nehx04 = {"nehx04", "0"};cvar_t nehx05 = {"nehx05", "0"}; -cvar_t nehx06 = {"nehx06", "0"};cvar_t nehx07 = {"nehx07", "0"}; -cvar_t nehx08 = {"nehx08", "0"};cvar_t nehx09 = {"nehx09", "0"}; -cvar_t nehx10 = {"nehx10", "0"};cvar_t nehx11 = {"nehx11", "0"}; -cvar_t nehx12 = {"nehx12", "0"};cvar_t nehx13 = {"nehx13", "0"}; -cvar_t nehx14 = {"nehx14", "0"};cvar_t nehx15 = {"nehx15", "0"}; -cvar_t nehx16 = {"nehx16", "0"};cvar_t nehx17 = {"nehx17", "0"}; -cvar_t nehx18 = {"nehx18", "0"};cvar_t nehx19 = {"nehx19", "0"}; -cvar_t cutscene = {"cutscene", "1"}; +cvar_t pr_checkextension = {0, "pr_checkextension", "1"}; +cvar_t nomonsters = {0, "nomonsters", "0"}; +cvar_t gamecfg = {0, "gamecfg", "0"}; +cvar_t scratch1 = {0, "scratch1", "0"}; +cvar_t scratch2 = {0,"scratch2", "0"}; +cvar_t scratch3 = {0, "scratch3", "0"}; +cvar_t scratch4 = {0, "scratch4", "0"}; +cvar_t savedgamecfg = {CVAR_SAVE, "savedgamecfg", "0"}; +cvar_t saved1 = {CVAR_SAVE, "saved1", "0"}; +cvar_t saved2 = {CVAR_SAVE, "saved2", "0"}; +cvar_t saved3 = {CVAR_SAVE, "saved3", "0"}; +cvar_t saved4 = {CVAR_SAVE, "saved4", "0"}; +cvar_t decors = {0, "decors", "0"}; +cvar_t nehx00 = {0, "nehx00", "0"};cvar_t nehx01 = {0, "nehx01", "0"}; +cvar_t nehx02 = {0, "nehx02", "0"};cvar_t nehx03 = {0, "nehx03", "0"}; +cvar_t nehx04 = {0, "nehx04", "0"};cvar_t nehx05 = {0, "nehx05", "0"}; +cvar_t nehx06 = {0, "nehx06", "0"};cvar_t nehx07 = {0, "nehx07", "0"}; +cvar_t nehx08 = {0, "nehx08", "0"};cvar_t nehx09 = {0, "nehx09", "0"}; +cvar_t nehx10 = {0, "nehx10", "0"};cvar_t nehx11 = {0, "nehx11", "0"}; +cvar_t nehx12 = {0, "nehx12", "0"};cvar_t nehx13 = {0, "nehx13", "0"}; +cvar_t nehx14 = {0, "nehx14", "0"};cvar_t nehx15 = {0, "nehx15", "0"}; +cvar_t nehx16 = {0, "nehx16", "0"};cvar_t nehx17 = {0, "nehx17", "0"}; +cvar_t nehx18 = {0, "nehx18", "0"};cvar_t nehx19 = {0, "nehx19", "0"}; +cvar_t cutscene = {0, "cutscene", "1"}; // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others)) -cvar_t pr_boundscheck = {"pr_boundscheck", "1"}; +cvar_t pr_boundscheck = {0, "pr_boundscheck", "1"}; #define MAX_FIELD_LEN 64 #define GEFV_CACHESIZE 2 @@ -106,11 +110,13 @@ int eval_idealpitch; int eval_pitch_speed; int eval_viewmodelforclient; int eval_nodrawtoclient; +int eval_exteriormodeltoclient; int eval_drawonlytoclient; -int eval_colormod; int eval_ping; int eval_movement; int eval_pmodel; +int eval_punchvector; +int eval_viewzoom; dfunction_t *SV_PlayerPhysicsQC; dfunction_t *EndFrameQC; @@ -124,7 +130,7 @@ int FindFieldOffset(char *field) return d->ofs*4; } -void FindEdictFieldOffsets() +void FindEdictFieldOffsets(void) { eval_gravity = FindFieldOffset("gravity"); eval_button3 = FindFieldOffset("button3"); @@ -153,11 +159,13 @@ void FindEdictFieldOffsets() eval_pitch_speed = FindFieldOffset("pitch_speed"); eval_viewmodelforclient = FindFieldOffset("viewmodelforclient"); eval_nodrawtoclient = FindFieldOffset("nodrawtoclient"); + eval_exteriormodeltoclient = FindFieldOffset("exteriormodeltoclient"); eval_drawonlytoclient = FindFieldOffset("drawonlytoclient"); - eval_colormod = FindFieldOffset("colormod"); eval_ping = FindFieldOffset("ping"); eval_movement = FindFieldOffset("movement"); eval_pmodel = FindFieldOffset("pmodel"); + eval_punchvector = FindFieldOffset("punchvector"); + eval_viewzoom = FindFieldOffset("viewzoom"); // LordHavoc: allowing QuakeC to override the player movement code SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics"); @@ -235,8 +243,8 @@ void ED_Free (edict_t *ed) ed->v.colormap = 0; ed->v.skin = 0; ed->v.frame = 0; - VectorCopy (vec3_origin, ed->v.origin); - VectorCopy (vec3_origin, ed->v.angles); + VectorClear(ed->v.origin); + VectorClear(ed->v.angles); ed->v.nextthink = -1; ed->v.solid = 0; @@ -292,7 +300,7 @@ ddef_t *ED_FindField (char *name) { ddef_t *def; int i; - + for (i=0 ; inumfielddefs ; i++) { def = &pr_fielddefs[i]; @@ -302,7 +310,6 @@ ddef_t *ED_FindField (char *name) return NULL; } - /* ============ ED_FindGlobal @@ -383,12 +390,14 @@ PR_ValueString Returns a string describing *data in a type specific manner ============= */ +int NoCrash_NUM_FOR_EDICT(edict_t *e); char *PR_ValueString (etype_t type, eval_t *val) { - static char line[256]; - ddef_t *def; - dfunction_t *f; - + static char line[1024]; // LordHavoc: enlarged a bit (was 256) + ddef_t *def; + dfunction_t *f; + int n; + type &= ~DEF_SAVEGLOBAL; switch (type) @@ -396,8 +405,12 @@ char *PR_ValueString (etype_t type, eval_t *val) case ev_string: sprintf (line, "%s", pr_strings + val->string); break; - case ev_entity: - sprintf (line, "entity %i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)) ); + case ev_entity: + n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); + if (n < 0 || n >= MAX_EDICTS) + sprintf (line, "entity %i (invalid!)", n); + else + sprintf (line, "entity %i", n); break; case ev_function: f = pr_functions + val->function; @@ -411,10 +424,12 @@ char *PR_ValueString (etype_t type, eval_t *val) sprintf (line, "void"); break; case ev_float: - sprintf (line, "%5.1f", val->_float); + // LordHavoc: changed from %5.1f to %10.4f + sprintf (line, "%10.4f", val->_float); break; case ev_vector: - sprintf (line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]); + // LordHavoc: changed from %5.1f to %10.4f + sprintf (line, "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); break; case ev_pointer: sprintf (line, "pointer"); @@ -437,10 +452,12 @@ Easier to parse than PR_ValueString */ char *PR_UglyValueString (etype_t type, eval_t *val) { - static char line[256]; - ddef_t *def; - dfunction_t *f; - + static char line[4096]; + int i; + char *s; + ddef_t *def; + dfunction_t *f; + type &= ~DEF_SAVEGLOBAL; switch (type) @@ -448,7 +465,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) case ev_string: sprintf (line, "%s", pr_strings + val->string); break; - case ev_entity: + case ev_entity: sprintf (line, "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); break; case ev_function: @@ -457,7 +474,28 @@ char *PR_UglyValueString (etype_t type, eval_t *val) break; case ev_field: def = ED_FieldAtOfs ( val->_int ); - sprintf (line, "%s", pr_strings + def->s_name); + // LordHavoc: parse the string a bit to turn special characters + // (like newline, specifically) into escape codes, + // this fixes saving games from various mods + //sprintf (line, "%s", pr_strings + def->s_name); + s = pr_strings + def->s_name; + for (i = 0;i < 4095 && *s;) + { + if (*s == '\n') + { + line[i++] = '\\'; + line[i++] = 'n'; + } + else if (*s == '\r') + { + line[i++] = '\\'; + line[i++] = 'r'; + } + else + line[i] = *s; + s++; + } + line[i++] = 0; break; case ev_void: sprintf (line, "void"); @@ -472,7 +510,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) sprintf (line, "bad type %i", type); break; } - + return line; } @@ -491,22 +529,22 @@ char *PR_GlobalString (int ofs) ddef_t *def; void *val; static char line[128]; - + val = (void *)&pr_globals[ofs]; def = ED_GlobalAtOfs(ofs); if (!def) - sprintf (line,"%i(???)", ofs); + sprintf (line,"%i(\?\?\?)", ofs); // LordHavoc: escaping the ?s so it is not a trigraph else { s = PR_ValueString (def->type, val); sprintf (line,"%i(%s)%s", ofs, pr_strings + def->s_name, s); } - + i = strlen(line); for ( ; i<20 ; i++) strcat (line," "); strcat (line," "); - + return line; } @@ -515,18 +553,18 @@ char *PR_GlobalStringNoContents (int ofs) int i; ddef_t *def; static char line[128]; - + def = ED_GlobalAtOfs(ofs); if (!def) - sprintf (line,"%i(???)", ofs); + sprintf (line,"%i(\?\?\?)", ofs); // LordHavoc: escaping the ?s so it is not a trigraph else sprintf (line,"%i(%s)", ofs, pr_strings + def->s_name); - + i = strlen(line); for ( ; i<20 ; i++) strcat (line," "); strcat (line," "); - + return line; } @@ -538,7 +576,8 @@ ED_Print For debugging ============= */ -// LordHavoc: optimized this to print out much more quickly +// LordHavoc: optimized this to print out much more quickly (tempstring) +// LordHavoc: changed to print out every 4096 characters (incase there are a lot of fields to print) void ED_Print (edict_t *ed) { int l; @@ -547,7 +586,7 @@ void ED_Print (edict_t *ed) int i, j; char *name; int type; - char tempstring[8192]; // temporary string buffer + char tempstring[8192], tempstring2[260]; // temporary string buffers if (ed->free) { @@ -563,27 +602,48 @@ void ED_Print (edict_t *ed) name = pr_strings + d->s_name; if (name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars - + v = (int *)((char *)&ed->v + d->ofs*4); // if the value is still all 0, skip the field type = d->type & ~DEF_SAVEGLOBAL; - + for (j=0 ; j 256) + { + strncpy(tempstring2, name, 256); + tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; + tempstring2[259] = 0; + name = tempstring2; + } strcat(tempstring, name); - l = strlen (name); - while (l++ < 15) + for (l = strlen(name);l < 14;l++) strcat(tempstring, " "); + strcat(tempstring, " "); - strcat(tempstring, PR_ValueString(d->type, (eval_t *)v)); + name = PR_ValueString(d->type, (eval_t *)v); + if (strlen(name) > 256) + { + strncpy(tempstring2, name, 256); + tempstring2[256] = tempstring2[257] = tempstring2[258] = '.'; + tempstring2[259] = 0; + name = tempstring2; + } + strcat(tempstring, name); strcat(tempstring, "\n"); + if (strlen(tempstring) >= 4096) + { + Con_Printf("%s", tempstring); + tempstring[0] = 0; + } } - Con_Printf(tempstring); + if (tempstring[0]) + Con_Printf("%s", tempstring); } /* @@ -593,7 +653,7 @@ ED_Write For savegames ============= */ -void ED_Write (FILE *f, edict_t *ed) +void ED_Write (QFile *f, edict_t *ed) { ddef_t *d; int *v; @@ -601,21 +661,21 @@ void ED_Write (FILE *f, edict_t *ed) char *name; int type; - fprintf (f, "{\n"); + Qprintf (f, "{\n"); if (ed->free) { - fprintf (f, "}\n"); + Qprintf (f, "}\n"); return; } - + for (i=1 ; inumfielddefs ; i++) { d = &pr_fielddefs[i]; name = pr_strings + d->s_name; if (name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars - + v = (int *)((char *)&ed->v + d->ofs*4); // if the value is still all 0, skip the field @@ -625,12 +685,12 @@ void ED_Write (FILE *f, edict_t *ed) break; if (j == type_size[type]) continue; - - fprintf (f,"\"%s\" ",name); - fprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v)); + + Qprintf (f,"\"%s\" ",name); + Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v)); } - fprintf (f, "}\n"); + Qprintf (f, "}\n"); } void ED_PrintNum (int ent) @@ -648,7 +708,7 @@ For debugging, prints all the entities in the current server void ED_PrintEdicts (void) { int i; - + Con_Printf ("%i entities\n", sv.num_edicts); for (i=0 ; i= sv.num_edicts) { @@ -724,14 +784,14 @@ FIXME: need to tag constants, doesn't really work ED_WriteGlobals ============= */ -void ED_WriteGlobals (FILE *f) +void ED_WriteGlobals (QFile *f) { ddef_t *def; int i; char *name; int type; - fprintf (f,"{\n"); + Qprintf (f,"{\n"); for (i=0 ; inumglobaldefs ; i++) { def = &pr_globaldefs[i]; @@ -740,16 +800,14 @@ void ED_WriteGlobals (FILE *f) continue; type &= ~DEF_SAVEGLOBAL; - if (type != ev_string - && type != ev_float - && type != ev_entity) + if (type != ev_string && type != ev_float && type != ev_entity) continue; name = pr_strings + def->s_name; - fprintf (f,"\"%s\" ", name); - fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); + Qprintf (f,"\"%s\" ", name); + Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); } - fprintf (f,"}\n"); + Qprintf (f,"}\n"); } /* @@ -773,7 +831,7 @@ void ED_ParseGlobals (char *data) strcpy (keyname, com_token); - // parse value + // parse value data = COM_Parse (data); if (!data) Host_Error ("ED_ParseEntity: EOF without closing brace"); @@ -805,9 +863,9 @@ char *ED_NewString (char *string) { char *new, *new_p; int i,l; - + l = strlen(string) + 1; - new = Hunk_Alloc (l); + new = Mem_Alloc(edictstring_mempool, l); new_p = new; for (i=0 ; i< l ; i++) @@ -823,7 +881,7 @@ char *ED_NewString (char *string) else *new_p++ = string[i]; } - + return new; } @@ -844,9 +902,9 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, char *s) char *v, *w; void *d; dfunction_t *func; - + d = (void *)((int *)base + key->ofs); - + switch (key->type & ~DEF_SAVEGLOBAL) { case ev_string: @@ -870,7 +928,7 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, char *s) w = v = v+1; } break; - + case ev_entity: *(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s))); break; @@ -896,7 +954,7 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, char *s) } *(func_t *)d = func - pr_functions; break; - + default: break; } @@ -928,27 +986,27 @@ char *ED_ParseEdict (char *data, edict_t *ent) // go through all the dictionary pairs while (1) - { + { // parse key data = COM_Parse (data); if (com_token[0] == '}') break; if (!data) Host_Error ("ED_ParseEntity: EOF without closing brace"); - -// anglehack is to allow QuakeEd to write single scalar angles -// and allow them to be turned into vectors. (FIXME...) -if (!strcmp(com_token, "angle")) -{ - strcpy (com_token, "angles"); - anglehack = true; -} -else - anglehack = false; -// FIXME: change light to _light to get rid of this hack -if (!strcmp(com_token, "light")) - strcpy (com_token, "light_lev"); // hack for single light def + // anglehack is to allow QuakeEd to write single scalar angles + // and allow them to be turned into vectors. (FIXME...) + if (!strcmp(com_token, "angle")) + { + strcpy (com_token, "angles"); + anglehack = true; + } + else + anglehack = false; + + // FIXME: change light to _light to get rid of this hack + if (!strcmp(com_token, "light")) + strcpy (com_token, "light_lev"); // hack for single light def strcpy (keyname, com_token); @@ -960,7 +1018,7 @@ if (!strcmp(com_token, "light")) n--; } - // parse value + // parse value data = COM_Parse (data); if (!data) Host_Error ("ED_ParseEntity: EOF without closing brace"); @@ -968,13 +1026,13 @@ if (!strcmp(com_token, "light")) if (com_token[0] == '}') Host_Error ("ED_ParseEntity: closing brace without data"); - init = true; + init = true; // keynames with a leading underscore are used for utility comments, // and are immediately discarded by quake if (keyname[0] == '_') continue; - + key = ED_FindField (keyname); if (!key) { @@ -982,12 +1040,12 @@ if (!strcmp(com_token, "light")) continue; } -if (anglehack) -{ -char temp[32]; -strcpy (temp, com_token); -sprintf (com_token, "0 %s 0", temp); -} + if (anglehack) + { + char temp[32]; + strcpy (temp, com_token); + sprintf (com_token, "0 %s 0", temp); + } if (!ED_ParseEpair ((void *)&ent->v, key, com_token)) Host_Error ("ED_ParseEdict: parse error"); @@ -1020,7 +1078,7 @@ void ED_LoadFromFile (char *data) edict_t *ent; int inhibit; dfunction_t *func; - + ent = NULL; inhibit = 0; pr_global_struct->time = sv.time; @@ -1042,7 +1100,7 @@ void ED_LoadFromFile (char *data) data = ED_ParseEdict (data, ent); // remove things from different skill levels or deathmatch - if (deathmatch.value) + if (deathmatch.integer) { if (((int)ent->v.spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) { @@ -1076,7 +1134,7 @@ void ED_LoadFromFile (char *data) if (!func) { - if (developer.value) // don't confuse non-developers with errors + if (developer.integer) // don't confuse non-developers with errors { Con_Printf ("No spawn function for:\n"); ED_Print (ent); @@ -1086,13 +1144,59 @@ void ED_LoadFromFile (char *data) } pr_global_struct->self = EDICT_TO_PROG(ent); - PR_ExecuteProgram (func - pr_functions); - } + PR_ExecuteProgram (func - pr_functions, ""); + } Con_DPrintf ("%i entities inhibited\n", inhibit); } +typedef struct dpfield_s +{ + int type; + char *string; +} +dpfield_t; + +#define DPFIELDS (sizeof(dpfields) / sizeof(dpfield_t)) + +dpfield_t dpfields[] = +{ + {ev_float, "gravity"}, + {ev_float, "button3"}, + {ev_float, "button4"}, + {ev_float, "button5"}, + {ev_float, "button6"}, + {ev_float, "button7"}, + {ev_float, "button8"}, + {ev_float, "glow_size"}, + {ev_float, "glow_trail"}, + {ev_float, "glow_color"}, + {ev_float, "items2"}, + {ev_float, "scale"}, + {ev_float, "alpha"}, + {ev_float, "renderamt"}, + {ev_float, "rendermode"}, + {ev_float, "fullbright"}, + {ev_float, "ammo_shells1"}, + {ev_float, "ammo_nails1"}, + {ev_float, "ammo_lava_nails"}, + {ev_float, "ammo_rockets1"}, + {ev_float, "ammo_multi_rockets"}, + {ev_float, "ammo_cells1"}, + {ev_float, "ammo_plasma"}, + {ev_float, "idealpitch"}, + {ev_float, "pitch_speed"}, + {ev_entity, "viewmodelforclient"}, + {ev_entity, "nodrawtoclient"}, + {ev_entity, "exteriormodeltoclient"}, + {ev_entity, "drawonlytoclient"}, + {ev_float, "ping"}, + {ev_vector, "movement"}, + {ev_float, "pmodel"}, + {ev_vector, "punchvector"} +}; + /* =============== PR_LoadProgs @@ -1100,41 +1204,55 @@ PR_LoadProgs */ void PR_LoadProgs (void) { - int i; + int i; dstatement_t *st; + ddef_t *infielddefs; + void *temp; // flush the non-C variable lookup cache for (i=0 ; iversion != PROG_VERSION) Host_Error ("progs.dat has wrong version number (%i should be %i)", progs->version, PROG_VERSION); if (progs->crc != PROGHEADER_CRC) Host_Error ("progs.dat system vars have been modified, progdefs.h is out of date"); - pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions); + pr_functions = (dfunction_t *)((qbyte *)progs + progs->ofs_functions); pr_strings = (char *)progs + progs->ofs_strings; - pr_globaldefs = (ddef_t *)((byte *)progs + progs->ofs_globaldefs); - pr_fielddefs = (ddef_t *)((byte *)progs + progs->ofs_fielddefs); - pr_statements = (dstatement_t *)((byte *)progs + progs->ofs_statements); + pr_globaldefs = (ddef_t *)((qbyte *)progs + progs->ofs_globaldefs); - pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals); - pr_globals = (float *)pr_global_struct; - - pr_edict_size = progs->entityfields * 4 + sizeof (edict_t) - sizeof(entvars_t); + // we need to expand the fielddefs list to include all the engine fields, + // so allocate a new place for it + infielddefs = (ddef_t *)((qbyte *)progs + progs->ofs_fielddefs); + pr_fielddefs = Mem_Alloc(progs_mempool, (progs->numfielddefs + DPFIELDS) * sizeof(ddef_t)); - pr_edictareasize = pr_edict_size * MAX_EDICTS; + pr_statements = (dstatement_t *)((qbyte *)progs + progs->ofs_statements); + + // moved edict_size calculation down below field adding code + + pr_global_struct = (globalvars_t *)((qbyte *)progs + progs->ofs_globals); + pr_globals = (float *)pr_global_struct; // byte swap the lumps for (i=0 ; inumstatements ; i++) @@ -1153,7 +1271,7 @@ void PR_LoadProgs (void) pr_functions[i].s_file = LittleLong (pr_functions[i].s_file); pr_functions[i].numparms = LittleLong (pr_functions[i].numparms); pr_functions[i].locals = LittleLong (pr_functions[i].locals); - } + } for (i=0 ; inumglobaldefs ; i++) { @@ -1162,18 +1280,37 @@ void PR_LoadProgs (void) pr_globaldefs[i].s_name = LittleLong (pr_globaldefs[i].s_name); } - for (i=0 ; inumfielddefs ; i++) + // copy the progs fields to the new fields list + for (i = 0;i < progs->numfielddefs;i++) { - pr_fielddefs[i].type = LittleShort (pr_fielddefs[i].type); + pr_fielddefs[i].type = LittleShort (infielddefs[i].type); if (pr_fielddefs[i].type & DEF_SAVEGLOBAL) Host_Error ("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL"); - pr_fielddefs[i].ofs = LittleShort (pr_fielddefs[i].ofs); - pr_fielddefs[i].s_name = LittleLong (pr_fielddefs[i].s_name); + pr_fielddefs[i].ofs = LittleShort (infielddefs[i].ofs); + pr_fielddefs[i].s_name = LittleLong (infielddefs[i].s_name); + } + + // append the darkplaces fields + for (i = 0;i < DPFIELDS;i++) + { + pr_fielddefs[progs->numfielddefs].type = dpfields[i].type; + pr_fielddefs[progs->numfielddefs].ofs = progs->entityfields; + pr_fielddefs[progs->numfielddefs].s_name = dpfields[i].string - pr_strings; + if (pr_fielddefs[progs->numfielddefs].type == ev_vector) + progs->entityfields += 3; + else + progs->entityfields++; + progs->numfielddefs++; } for (i=0 ; inumglobals ; i++) ((int *)pr_globals)[i] = LittleLong (((int *)pr_globals)[i]); + // moved edict_size calculation down here, below field adding code + pr_edict_size = progs->entityfields * 4 + sizeof (edict_t) - sizeof(entvars_t); + + pr_edictareasize = pr_edict_size * MAX_EDICTS; + // LordHavoc: bounds check anything static for (i = 0,st = pr_statements;i < progs->numstatements;i++,st++) { @@ -1277,6 +1414,32 @@ void PR_LoadProgs (void) } +void PR_Fields_f (void) +{ + int i; + if (!sv.active) + { + Con_Printf("no progs loaded\n"); + return; + } + for (i = 0;i < progs->numfielddefs;i++) + Con_Printf("%s\n", (pr_strings + pr_fielddefs[i].s_name)); + Con_Printf("%i entity fields, totalling %i bytes per edict, %i edicts, %i bytes total spent on edict fields\n", progs->entityfields, progs->entityfields * 4, MAX_EDICTS, progs->entityfields * 4 * MAX_EDICTS); +} + +void PR_Globals_f (void) +{ + int i; + if (!sv.active) + { + Con_Printf("no progs loaded\n"); + return; + } + for (i = 0;i < progs->numglobaldefs;i++) + Con_Printf("%s\n", (pr_strings + pr_globaldefs[i].s_name)); + Con_Printf("%i global variables, totalling %i bytes\n", progs->numglobals, progs->numglobals * 4); +} + /* =============== PR_Init @@ -1288,6 +1451,9 @@ void PR_Init (void) Cmd_AddCommand ("edicts", ED_PrintEdicts); Cmd_AddCommand ("edictcount", ED_Count); Cmd_AddCommand ("profile", PR_Profile_f); + Cmd_AddCommand ("pr_fields", PR_Fields_f); + Cmd_AddCommand ("pr_globals", PR_Globals_f); + Cvar_RegisterVariable (&pr_checkextension); Cvar_RegisterVariable (&nomonsters); Cvar_RegisterVariable (&gamecfg); Cvar_RegisterVariable (&scratch1); @@ -1302,7 +1468,7 @@ void PR_Init (void) // LordHavoc: for DarkPlaces, this overrides the number of decors (shell casings, gibs, etc) Cvar_RegisterVariable (&decors); // LordHavoc: Nehahra uses these to pass data around cutscene demos - if (nehahra) + if (gamemode == GAME_NEHAHRA) { Cvar_RegisterVariable (&nehx00);Cvar_RegisterVariable (&nehx01); Cvar_RegisterVariable (&nehx02);Cvar_RegisterVariable (&nehx03); @@ -1318,6 +1484,9 @@ void PR_Init (void) Cvar_RegisterVariable (&cutscene); // for Nehahra but useful to other mods as well // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others)) Cvar_RegisterVariable (&pr_boundscheck); + + progs_mempool = Mem_AllocPool("progs.dat"); + edictstring_mempool = Mem_AllocPool("edict strings"); } // LordHavoc: turned EDICT_NUM into a #define for speed reasons @@ -1331,18 +1500,27 @@ edict_t *EDICT_NUM(int n) { if (n < 0 || n >= sv.max_edicts) Sys_Error ("EDICT_NUM: bad number %i", n); - return (edict_t *)((byte *)sv.edicts+ (n)*pr_edict_size); + return (edict_t *)((qbyte *)sv.edicts+ (n)*pr_edict_size); } */ int NUM_FOR_EDICT(edict_t *e) { int b; - - b = (byte *)e - (byte *)sv.edicts; + + b = (qbyte *)e - (qbyte *)sv.edicts; b = b / pr_edict_size; - + if (b < 0 || b >= sv.num_edicts) Host_Error ("NUM_FOR_EDICT: bad pointer"); return b; } + +int NoCrash_NUM_FOR_EDICT(edict_t *e) +{ + int b; + + b = (qbyte *)e - (qbyte *)sv.edicts; + b = b / pr_edict_size; + return b; +}