From: havoc Date: Mon, 25 May 2020 04:10:27 +0000 (+0000) Subject: Refactored VM_SV_AddStat to allow overrides of all stats (0..255) in a more consisten... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=997067cbe42c7d9342762b52eafab1b8f7f5b2ab;p=xonotic%2Fdarkplaces.git Refactored VM_SV_AddStat to allow overrides of all stats (0..255) in a more consistent way, added warnings if overriding engine stats. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12566 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/quakedef.h b/quakedef.h index 4e483f93..8b9ea4d8 100644 --- a/quakedef.h +++ b/quakedef.h @@ -235,6 +235,8 @@ extern char engineversion[128]; //#define STAT_TIME 17 ///< FTE //#define STAT_VIEW2 20 ///< FTE #define STAT_VIEWZOOM 21 ///< DP +#define MIN_VM_STAT 32 ///< stat range available to VM_SV_AddStat +#define MAX_VM_STAT 220 ///< stat range available to VM_SV_AddStat #define STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR 220 ///< DP #define STAT_MOVEVARS_AIRCONTROL_PENALTY 221 ///< DP #define STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW 222 ///< DP diff --git a/svvm_cmds.c b/svvm_cmds.c index b98563fc..fbfe70ad 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -1626,19 +1626,18 @@ static void VM_SV_getlight(prvm_prog_t *prog) typedef struct { - unsigned char type; // 1/2/8 or other value if isn't used + unsigned char type; // 1/2/8 or 0 to indicate unused int fieldoffset; }customstat_t; -static customstat_t *vm_customstats = NULL; //[515]: it starts from 0, not 32 +static customstat_t vm_customstats[MAX_CL_STATS]; // matches the regular stat numbers, but only MIN_VM_STAT to MAX_VM_STAT range is used if things are working properly (can register stats from MAX_VM_STAT to MAX_CL_STATS but will warn) static int vm_customstats_last; void VM_CustomStats_Clear (void) { if(vm_customstats) { - Z_Free(vm_customstats); - vm_customstats = NULL; + memset(vm_customstats, 0, sizeof(vm_customstats)); vm_customstats_last = -1; } } @@ -1653,10 +1652,7 @@ void VM_SV_UpdateCustomStats (client_t *client, prvm_edict_t *ent, sizebuf_t *ms float f; } u; - if(!vm_customstats) - return; - - for(i=0; i= (MAX_CL_STATS-32)) + + if (i >= MAX_CL_STATS) { - VM_Warning(prog, "PF_SV_AddStat: index >= MAX_CL_STATS\n"); + VM_Warning(prog, "PF_SV_AddStat: index (%i) >= MAX_CL_STATS (%i), not supported by protocol, and AddStat beyond MAX_VM_STAT conflicts with engine MOVEVARS\n", i, MAX_CL_STATS, MAX_VM_STAT); return; } - if(i > (MAX_CL_STATS-32-4) && type == 1) + + if (i > (MAX_CL_STATS - 4) && type == 1) { - VM_Warning(prog, "PF_SV_AddStat: index > (MAX_CL_STATS-4) with string\n"); + VM_Warning(prog, "PF_SV_AddStat: index (%i) > (MAX_CL_STATS-4) with string type won't fit in the protocol, and AddStat beyond MAX_VM_STAT conflicts with engine MOVEVARS\n", i, MAX_CL_STATS); return; } + + // these are hazardous to override but sort of allowed if one wants to be adventurous... and enjoys warnings. + if (i < MIN_VM_STAT) + VM_Warning(prog, "PF_SV_AddStat: index (%i) < MIN_VM_STAT (%i) may conflict with engine stats - allowed, but this may break things\n", i, MIN_VM_STAT); + else if (i >= MAX_VM_STAT) + VM_Warning(prog, "PF_SV_AddStat: index (%i) >= MAX_VM_STAT (%i) conflicts with engine stats - allowed, but this may break slowmo and stuff\n", i, MAX_VM_STAT); + else if (i > (MAX_VM_STAT - 4) && type == 1) + VM_Warning(prog, "PF_SV_AddStat: index (%i) >= MAX_VM_STAT (%i) - 4 with string type won't fit within MAX_VM_STAT, thus conflicting with engine stats - allowed, but this may break slowmo and stuff\n", i, MAX_VM_STAT); + vm_customstats[i].type = type; vm_customstats[i].fieldoffset = off; if(vm_customstats_last < i)