clear trace globals after CSQC execution, to prevent possible triggerbots working...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2009 20:15:53 +0000 (20:15 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2009 20:15:53 +0000 (20:15 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9228 d7cf8633-e32d-0410-b094-e92efae38249

csprogs.c
prvm_cmds.c
prvm_cmds.h

index ae4151e..56b23ce 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -12,7 +12,9 @@
 
 #define CSQC_RETURNVAL prog->globals.generic[OFS_RETURN]
 #define CSQC_BEGIN             csqc_tmpprog=prog;prog=0;PRVM_SetProg(PRVM_CLIENTPROG);
-#define CSQC_END               prog=csqc_tmpprog;
+#define CSQC_END               VM_ClearTraceGlobals(); prog=csqc_tmpprog;
+// TODO check if the clearing of trace globals takes too much CPU. If it does,
+// perform it before console command processing instead.
 
 static prvm_prog_t *csqc_tmpprog;
 
index 510f5e7..d875d03 100644 (file)
@@ -5044,6 +5044,38 @@ void VM_SetTraceGlobals(const trace_t *trace)
                val->string = trace->hittexture ? PRVM_SetTempString(trace->hittexture->name) : 0;
 }
 
+void VM_ClearTraceGlobals(void)
+{
+       // clean up all trace globals when leaving the VM (anti-triggerbot safeguard)
+       prvm_eval_t *val;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_allsolid)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_startsolid)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_fraction)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_inwater)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_inopen)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_endpos)))
+               VectorClear(val->vector);
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_plane_normal)))
+               VectorClear(val->vector);
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_plane_dist)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_ent)))
+               val->edict = PRVM_EDICT_TO_PROG(prog->edicts);
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_dpstartcontents)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_dphitcontents)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_dphitq3surfaceflags)))
+               val->_float = 0;
+       if ((val = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.trace_dphittexturename)))
+               val->string = 0;
+}
+
 //=============
 
 void VM_Cmd_Init(void)
index a7826ea..6c549c2 100644 (file)
@@ -422,6 +422,7 @@ void VM_strireplace (void);
 void VM_crc16(void);
 
 void VM_SetTraceGlobals(const trace_t *trace);
+void VM_ClearTraceGlobals(void);
 
 void VM_Cmd_Init(void);
 void VM_Cmd_Reset(void);