X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=prvm_edict.c;h=a751a15ecfc7e5b50c57244ffd49822b5adecba9;hp=65ba909d70ced719053e2a4eb504ecd96c4bd43c;hb=c3ea7019c9ce6dd91e6f40a027a45cd27da17385;hpb=abc955133d73f40d03447e0243b80e96740c86c9 diff --git a/prvm_edict.c b/prvm_edict.c index 65ba909d..a751a15e 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -31,10 +31,6 @@ int prvm_type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(v ddef_t *PRVM_ED_FieldAtOfs(int ofs); qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qboolean parsebackslash); -// LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others)) -#ifdef PRVM_BOUNDSCHECK_CVAR -cvar_t prvm_boundscheck = {0, "prvm_boundscheck", "1", "enables detection of out of bounds memory access in the QuakeC code being run (in other words, prevents really exceedingly bad QuakeC code from doing nasty things to your computer)"}; -#endif // LordHavoc: prints every opcode as it executes - warning: this is significant spew cvar_t prvm_traceqc = {0, "prvm_traceqc", "0", "prints every QuakeC statement as it is executed (only for really thorough debugging!)"}; // LordHavoc: counts usage of each QuakeC statement @@ -44,6 +40,12 @@ cvar_t prvm_leaktest = {0, "prvm_leaktest", "0", "try to detect memory leaks in cvar_t prvm_leaktest_ignore_classnames = {0, "prvm_leaktest_ignore_classnames", "", "classnames of entities to NOT leak check because they are found by find(world, classname, ...) but are actually spawned by QC code (NOT map entities)"}; cvar_t prvm_errordump = {0, "prvm_errordump", "0", "write a savegame on crash to crash-server.dmp"}; +qboolean prvm_runawaycheck = true; + +// LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others)) +// enables detection of out of bounds memory access in the QuakeC code being run (in other words, prevents really exceedingly bad QuakeC code from doing nasty things to your computer) +qboolean prvm_boundscheck = true; + extern sizebuf_t vm_tempstringsbuf; //============================================================================ @@ -507,6 +509,11 @@ char *PRVM_UglyValueString (etype_t type, prvm_eval_t *val) line[i++] = '\\'; line[i++] = '\\'; } + else if (*s == '"') + { + line[i++] = '\\'; + line[i++] = '"'; + } else line[i++] = *s; s++; @@ -686,6 +693,7 @@ PRVM_ED_Write For savegames ============= */ +extern cvar_t developer_entityparsing; void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed) { ddef_t *d; @@ -706,6 +714,10 @@ void PRVM_ED_Write (qfile_t *f, prvm_edict_t *ed) { d = &prog->fielddefs[i]; name = PRVM_GetString(d->s_name); + + if(developer_entityparsing.integer) + Con_Printf("PRVM_ED_Write: at entity %d field %s\n", PRVM_NUM_FOR_EDICT(ed), name); + if (name[strlen(name)-2] == '_') continue; // skip _x, _y, _z vars @@ -884,6 +896,10 @@ void PRVM_ED_WriteGlobals (qfile_t *f) continue; name = PRVM_GetString(def->s_name); + + if(developer_entityparsing.integer) + Con_Printf("PRVM_ED_WriteGlobals: at global %s\n", name); + FS_Printf(f,"\"%s\" ", name); FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString((etype_t)type, (prvm_eval_t *)&prog->globals.generic[def->ofs])); } @@ -908,12 +924,18 @@ void PRVM_ED_ParseGlobals (const char *data) if (com_token[0] == '}') break; + if (developer_entityparsing.integer) + Con_Printf("Key: \"%s\"", com_token); + strlcpy (keyname, com_token, sizeof(keyname)); // parse value if (!COM_ParseToken_Simple(&data, false, true)) PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace"); + if (developer_entityparsing.integer) + Con_Printf(" \"%s\"\n", com_token); + if (com_token[0] == '}') PRVM_ERROR ("PRVM_ED_ParseGlobals: closing brace without data"); @@ -975,7 +997,7 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool break; case ev_float: - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; val->_float = atof(s); break; @@ -983,12 +1005,12 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool case ev_vector: for (i = 0;i < 3;i++) { - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; if (!*s) break; val->vector[i] = atof(s); - while (*s > ' ') + while (!ISWHITESPACE(*s)) s++; if (!*s) break; @@ -996,7 +1018,7 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s, qbool break; case ev_entity: - while (*s && *s <= ' ') + while (*s && ISWHITESPACE(*s)) s++; i = atoi(s); if (i >= prog->limit_edicts) @@ -1150,7 +1172,6 @@ ed should be a properly initialized empty edict. Used for initial level load and for savegames. ==================== */ -extern cvar_t developer_entityparsing; const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent) { ddef_t *key; @@ -1302,9 +1323,17 @@ void PRVM_ED_LoadFromFile (const char *data) continue; } + if (prog->funcoffsets.SV_OnEntityPreSpawnFunction) + { + // self = ent + PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict = PRVM_EDICT_TO_PROG(ent); + PRVM_ExecuteProgram (prog->funcoffsets.SV_OnEntityPreSpawnFunction, "QC function SV_OnEntityPreSpawnFunction is missing"); + } + // // immediately call spawn function, but only if there is a self global and a classname // + if(!ent->priv.required->free) if(prog->globaloffsets.self >= 0 && prog->fieldoffsets.classname >= 0) { string_t handle = PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.classname)->string; @@ -1340,7 +1369,7 @@ void PRVM_ED_LoadFromFile (const char *data) PRVM_ED_Print(ent, NULL); } PRVM_ED_Free (ent); - continue; + continue; // not included in "inhibited" count } } else @@ -1351,6 +1380,14 @@ void PRVM_ED_LoadFromFile (const char *data) } } + if(!ent->priv.required->free) + if (prog->funcoffsets.SV_OnEntityPostSpawnFunction) + { + // self = ent + PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict = PRVM_EDICT_TO_PROG(ent); + PRVM_ExecuteProgram (prog->funcoffsets.SV_OnEntityPostSpawnFunction, "QC function SV_OnEntityPostSpawnFunction is missing"); + } + spawned++; if (ent->priv.required->free) died++; @@ -1420,6 +1457,7 @@ void PRVM_FindOffsets(void) prog->fieldoffsets.frame1time = PRVM_ED_FindFieldOffset("frame1time"); prog->fieldoffsets.frame2 = PRVM_ED_FindFieldOffset("frame2"); prog->fieldoffsets.frame2time = PRVM_ED_FindFieldOffset("frame2time"); + prog->fieldoffsets.shadertime = PRVM_ED_FindFieldOffset("shadertime"); prog->fieldoffsets.fullbright = PRVM_ED_FindFieldOffset("fullbright"); prog->fieldoffsets.glow_color = PRVM_ED_FindFieldOffset("glow_color"); prog->fieldoffsets.glow_size = PRVM_ED_FindFieldOffset("glow_size"); @@ -1480,8 +1518,12 @@ void PRVM_FindOffsets(void) prog->funcoffsets.SV_ParseClientCommand = PRVM_ED_FindFunctionOffset("SV_ParseClientCommand"); prog->funcoffsets.SV_PlayerPhysics = PRVM_ED_FindFunctionOffset("SV_PlayerPhysics"); prog->funcoffsets.SV_OnEntityNoSpawnFunction = PRVM_ED_FindFunctionOffset("SV_OnEntityNoSpawnFunction"); + prog->funcoffsets.SV_OnEntityPreSpawnFunction = PRVM_ED_FindFunctionOffset("SV_OnEntityPreSpawnFunction"); + prog->funcoffsets.SV_OnEntityPostSpawnFunction = PRVM_ED_FindFunctionOffset("SV_OnEntityPostSpawnFunction"); prog->funcoffsets.GameCommand = PRVM_ED_FindFunctionOffset("GameCommand"); prog->funcoffsets.SV_Shutdown = PRVM_ED_FindFunctionOffset("SV_Shutdown"); + prog->funcoffsets.URI_Get_Callback = PRVM_ED_FindFunctionOffset("URI_Get_Callback"); + prog->funcoffsets.SV_PausedTic = PRVM_ED_FindFunctionOffset("SV_PausedTic"); prog->globaloffsets.SV_InitCmd = PRVM_ED_FindGlobalOffset("SV_InitCmd"); prog->globaloffsets.self = PRVM_ED_FindGlobalOffset("self"); prog->globaloffsets.time = PRVM_ED_FindGlobalOffset("time"); @@ -1498,6 +1540,7 @@ void PRVM_FindOffsets(void) prog->globaloffsets.trace_plane_normal = PRVM_ED_FindGlobalOffset("trace_plane_normal"); prog->globaloffsets.trace_plane_dist = PRVM_ED_FindGlobalOffset("trace_plane_dist"); prog->globaloffsets.trace_ent = PRVM_ED_FindGlobalOffset("trace_ent"); + prog->globaloffsets.trace_networkentity = PRVM_ED_FindGlobalOffset("trace_networkentity"); prog->globaloffsets.trace_dphitcontents = PRVM_ED_FindGlobalOffset("trace_dphitcontents"); prog->globaloffsets.trace_dphitq3surfaceflags = PRVM_ED_FindGlobalOffset("trace_dphitq3surfaceflags"); prog->globaloffsets.trace_dphittexturename = PRVM_ED_FindGlobalOffset("trace_dphittexturename"); @@ -1512,6 +1555,15 @@ void PRVM_FindOffsets(void) prog->globaloffsets.drawfont = PRVM_ED_FindGlobalOffset("drawfont"); prog->globaloffsets.require_spawnfunc_prefix = PRVM_ED_FindGlobalOffset("require_spawnfunc_prefix"); prog->globaloffsets.worldstatus = PRVM_ED_FindGlobalOffset("worldstatus"); + prog->globaloffsets.servertime = PRVM_ED_FindGlobalOffset("servertime"); + prog->globaloffsets.serverprevtime = PRVM_ED_FindGlobalOffset("serverprevtime"); + prog->globaloffsets.serverdeltatime = PRVM_ED_FindGlobalOffset("serverdeltatime"); + prog->globaloffsets.gettaginfo_name = PRVM_ED_FindGlobalOffset("gettaginfo_name"); + prog->globaloffsets.gettaginfo_parent = PRVM_ED_FindGlobalOffset("gettaginfo_parent"); + prog->globaloffsets.gettaginfo_offset = PRVM_ED_FindGlobalOffset("gettaginfo_offset"); + prog->globaloffsets.gettaginfo_forward = PRVM_ED_FindGlobalOffset("gettaginfo_forward"); + prog->globaloffsets.gettaginfo_right = PRVM_ED_FindGlobalOffset("gettaginfo_right"); + prog->globaloffsets.gettaginfo_up = PRVM_ED_FindGlobalOffset("gettaginfo_up"); // menu qc only uses some functions, nothing else prog->funcoffsets.m_draw = PRVM_ED_FindFunctionOffset("m_draw"); @@ -2092,10 +2144,10 @@ void PRVM_Init (void) Cmd_AddCommand ("cl_cmd", PRVM_GameCommand_Client_f, "calls the client QC function GameCommand with the supplied string as argument"); Cmd_AddCommand ("menu_cmd", PRVM_GameCommand_Menu_f, "calls the menu QC function GameCommand with the supplied string as argument"); Cmd_AddCommand ("sv_cmd", PRVM_GameCommand_Server_f, "calls the server QC function GameCommand with the supplied string as argument"); - // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others)) -#ifdef PRVM_BOUNDSCHECK_CVAR - Cvar_RegisterVariable (&prvm_boundscheck); -#endif + + // COMMANDLINEOPTION: PRVM: -noboundscheck disables the bounds checks (security hole if CSQC is in use!) + prvm_boundscheck = !COM_CheckParm("-noboundscheck"); + Cvar_RegisterVariable (&prvm_traceqc); Cvar_RegisterVariable (&prvm_statementprofiling); Cvar_RegisterVariable (&prvm_backtraceforwarnings); @@ -2103,6 +2155,9 @@ void PRVM_Init (void) Cvar_RegisterVariable (&prvm_leaktest_ignore_classnames); Cvar_RegisterVariable (&prvm_errordump); + // COMMANDLINEOPTION: PRVM: -norunaway disables the runaway loop check (it might be impossible to exit DarkPlaces if used!) + prvm_runawaycheck = !COM_CheckParm("-norunaway"); + //VM_Cmd_Init(); } @@ -2345,7 +2400,7 @@ int PRVM_SetTempString(const char *s) { if (developer.integer >= 100) Con_Printf("PRVM_SetTempString: enlarging tempstrings buffer (%iKB -> %iKB)\n", old.maxsize/1024, vm_tempstringsbuf.maxsize/1024); - vm_tempstringsbuf.data = Mem_Alloc(sv_mempool, vm_tempstringsbuf.maxsize); + vm_tempstringsbuf.data = (unsigned char *) Mem_Alloc(sv_mempool, vm_tempstringsbuf.maxsize); if (old.cursize) memcpy(vm_tempstringsbuf.data, old.data, old.cursize); if (old.data) @@ -2639,7 +2694,7 @@ void PRVM_LeakTest() for (i = 0; i < (int)Mem_ExpandableArray_IndexRange(&prog->stringbuffersarray); ++i) { - prvm_stringbuffer_t *stringbuffer = Mem_ExpandableArray_RecordAtIndex(&prog->stringbuffersarray, i); + prvm_stringbuffer_t *stringbuffer = (prvm_stringbuffer_t*) Mem_ExpandableArray_RecordAtIndex(&prog->stringbuffersarray, i); if(stringbuffer) if(stringbuffer->origin) {