]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
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 ae4151ef08ffa040b2e612f4c49e8bb00a1797b9..56b23ce7c86c3a9d635808e073425f4ec3e2cd0e 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 510f5e7efa709086d5185bee6a726cbfad848689..d875d0347963103cbcddec60c5e800b363a6311c 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 a7826eace608dc5a83f01bb25046808370ea7055..6c549c2d995abd9cf06359082a33e1e262c91c08 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);