]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_edict.c
make DP compile with C++ again
[xonotic/darkplaces.git] / prvm_edict.c
index d8499c4368c98e6028a5e7525b45912b230e8264..82314f8a8f9bc217e7ffece1401a0d0017b99b2a 100644 (file)
@@ -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;
 
 //============================================================================
@@ -1321,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;
@@ -1359,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
@@ -1370,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++;
@@ -1499,6 +1517,8 @@ 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");
@@ -1518,6 +1538,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");
@@ -2112,10 +2133,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);
@@ -2123,6 +2144,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();
 }
 
@@ -2365,7 +2389,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)
@@ -2659,7 +2683,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)
                {