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.
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};
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;
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");
// LordHavoc: support for endframe
EndFrameQC = ED_FindFunction ("EndFrame");
-};
+}
/*
=================
{
ddef_t *def;
int i;
-
+
for (i=0 ; i<progs->numfielddefs ; i++)
{
def = &pr_fielddefs[i];
}
-/*
-eval_t *GetEdictFieldValue(edict_t *ed, char *field)
-{
- ddef_t *def = NULL;
- int i;
- static int rep = 0;
-
- for (i=0 ; i<GEFV_CACHESIZE ; i++)
- {
- if (!strcmp(field, gefvCache[i].field))
- {
- def = gefvCache[i].pcache;
- goto Done;
- }
- }
-
- def = ED_FindField (field);
-
- if (strlen(field) < MAX_FIELD_LEN)
- {
- gefvCache[rep].pcache = def;
- strcpy (gefvCache[rep].field, field);
- rep ^= 1;
- }
-
-Done:
- if (!def)
- return NULL;
-
- return (eval_t *)((char *)&ed->v + def->ofs*4);
-}
-*/
-
/*
============
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[1024]; // LordHavoc: enlarged a bit (was 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)
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;
*/
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)
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");
sprintf (line, "bad type %i", type);
break;
}
-
+
return line;
}
val = (void *)&pr_globals[ofs];
def = ED_GlobalAtOfs(ofs);
if (!def)
- sprintf (line,"%i(\?\?\?)", ofs); // LordHavoc: escaping the ?s so it is not a trigraph
+ sprintf (line,"%i(?)", ofs);
else
{
s = PR_ValueString (def->type, val);
def = ED_GlobalAtOfs(ofs);
if (!def)
- sprintf (line,"%i(\?\?\?)", ofs); // LordHavoc: escaping the ?s so it is not a trigraph
+ sprintf (line,"%i(?)", ofs);
else
sprintf (line,"%i(%s)", ofs, pr_strings + def->s_name);
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<type_size[type] ; j++)
if (v[j])
break;
Qprintf (f, "}\n");
return;
}
-
+
for (i=1 ; i<progs->numfielddefs ; 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
break;
if (j == type_size[type])
continue;
-
+
Qprintf (f,"\"%s\" ",name);
- Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+ Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
}
Qprintf (f, "}\n");
void ED_PrintEdicts (void)
{
int i;
-
+
Con_Printf ("%i entities\n", sv.num_edicts);
for (i=0 ; i<sv.num_edicts ; i++)
ED_PrintNum (i);
void ED_PrintEdict_f (void)
{
int i;
-
+
i = atoi (Cmd_Argv(1));
if (i >= sv.num_edicts)
{
strcpy (keyname, com_token);
- // parse value
+ // parse value
data = COM_Parse (data);
if (!data)
Host_Error ("ED_ParseEntity: EOF without closing brace");
{
char *new, *new_p;
int i,l;
-
+
l = strlen(string) + 1;
- new = Hunk_AllocName (l, "edict string");
+ new = Mem_Alloc(edictstring_mempool, l);
new_p = new;
for (i=0 ; i< l ; i++)
w = v = v+1;
}
break;
-
+
case ev_entity:
*(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s)));
break;
}
*(func_t *)d = func - pr_functions;
break;
-
+
default:
break;
}
// 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);
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)
{
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");
edict_t *ent;
int inhibit;
dfunction_t *func;
-
+
ent = NULL;
inhibit = 0;
pr_global_struct->time = sv.time;
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))
{
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);
{ev_entity, "nodrawtoclient"},
{ev_entity, "exteriormodeltoclient"},
{ev_entity, "drawonlytoclient"},
- {ev_vector, "colormod"},
{ev_float, "ping"},
{ev_vector, "movement"},
{ev_float, "pmodel"},
int i;
dstatement_t *st;
ddef_t *infielddefs;
+ void *temp;
// flush the non-C variable lookup cache
for (i=0 ; i<GEFV_CACHESIZE ; i++)
gefvCache[i].field[0] = 0;
- progs = (dprograms_t *)COM_LoadHunkFile ("progs.dat", false);
- if (!progs)
+ Mem_EmptyPool(progs_mempool);
+ Mem_EmptyPool(edictstring_mempool);
+
+ temp = COM_LoadFile ("progs.dat", false);
+ if (!temp)
Host_Error ("PR_LoadProgs: couldn't load progs.dat");
+
+ progs = (dprograms_t *)Mem_Alloc(progs_mempool, com_filesize);
+
+ memcpy(progs, temp, com_filesize);
+ Mem_Free(temp);
+
Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
- pr_crc = CRC_Block((byte *)progs, com_filesize);
+ pr_crc = CRC_Block((qbyte *)progs, com_filesize);
// byte swap the header
for (i=0 ; i<sizeof(*progs)/4 ; i++)
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_globaldefs = (ddef_t *)((qbyte *)progs + progs->ofs_globaldefs);
// we need to expand the fielddefs list to include all the engine fields,
// so allocate a new place for it
- infielddefs = (ddef_t *)((byte *)progs + progs->ofs_fielddefs);
- pr_fielddefs = Hunk_AllocName((progs->numfielddefs + DPFIELDS) * sizeof(ddef_t), "progs fields\n");
+ infielddefs = (ddef_t *)((qbyte *)progs + progs->ofs_fielddefs);
+ pr_fielddefs = Mem_Alloc(progs_mempool, (progs->numfielddefs + DPFIELDS) * sizeof(ddef_t));
- pr_statements = (dstatement_t *)((byte *)progs + progs->ofs_statements);
+ pr_statements = (dstatement_t *)((qbyte *)progs + progs->ofs_statements);
// moved edict_size calculation down below field adding code
- pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals);
+ pr_global_struct = (globalvars_t *)((qbyte *)progs + progs->ofs_globals);
pr_globals = (float *)pr_global_struct;
// byte swap the lumps
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
Host_Error ("EDICT_NUM: bad number %i", n);
return NULL;
}
-/*
-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);
-}
-*/
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;
+}
+