From b003ca9abf1bd24bf5edc3587e3931c39809202e Mon Sep 17 00:00:00 2001 From: TimePath Date: Thu, 3 Dec 2015 18:05:00 +1100 Subject: [PATCH] Globalsound: assert source is a player --- qcsrc/common/effects/qc/globalsound.qc | 5 +++-- qcsrc/common/effects/qc/globalsound.qh | 12 +++++------ qcsrc/common/monsters/sv_monsters.qc | 2 +- .../mutators/mutator/dodging/dodging.qc | 2 +- qcsrc/common/physics.qc | 4 ++-- qcsrc/lib/log.qh | 21 +++++++++---------- qcsrc/server/cl_client.qc | 15 ++++++------- qcsrc/server/cl_player.qc | 14 ++++++------- qcsrc/server/command/cmd.qc | 4 ++-- qcsrc/server/playerdemo.qc | 4 ++-- qcsrc/server/sv_main.qc | 6 +++--- 11 files changed, 43 insertions(+), 46 deletions(-) diff --git a/qcsrc/common/effects/qc/globalsound.qc b/qcsrc/common/effects/qc/globalsound.qc index c474f3b7e..4f942ef0c 100644 --- a/qcsrc/common/effects/qc/globalsound.qc +++ b/qcsrc/common/effects/qc/globalsound.qc @@ -20,6 +20,7 @@ */ void globalsound(int channel, entity from, entity gs, float r, int chan, float vol, float atten) { + assert(IS_PLAYER(from)); if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; WriteHeader(channel, globalsound); WriteByte(channel, gs.m_id); @@ -42,6 +43,7 @@ */ void playersound(int channel, entity from, entity ps, float r, int chan, float vol, float atten) { + assert(IS_PLAYER(from)); if (channel == MSG_ONE && !IS_REAL_CLIENT(msg_entity)) return; WriteHeader(channel, playersound); WriteByte(channel, ps.m_id); @@ -294,9 +296,8 @@ #ifdef SVQC - void _GlobalSound(entity gs, entity ps, string sample, int chan, int voicetype, bool fake) + void _GlobalSound(entity this, entity gs, entity ps, string sample, int chan, int voicetype, bool fake) { - SELFPARAM(); if (gs == NULL && ps == NULL && sample == "") return; float r = random(); if (sample != "") sample = GlobalSound_sample(sample, r); diff --git a/qcsrc/common/effects/qc/globalsound.qh b/qcsrc/common/effects/qc/globalsound.qh index 4b86da5c8..892d3d078 100644 --- a/qcsrc/common/effects/qc/globalsound.qh +++ b/qcsrc/common/effects/qc/globalsound.qh @@ -121,11 +121,11 @@ void PrecachePlayerSounds(string f); #ifdef SVQC - void _GlobalSound(entity gs, entity ps, string sample, float chan, float voicetype, bool fake); - #define GlobalSound(def, chan, voicetype) _GlobalSound(def, NULL, string_null, chan, voicetype, false) - #define GlobalSound_string(def, chan, voicetype) _GlobalSound(NULL, NULL, def, chan, voicetype, false) - #define PlayerSound(def, chan, voicetype) _GlobalSound(NULL, def, string_null, chan, voicetype, false) - #define VoiceMessage(def, msg) \ + void _GlobalSound(entity this, entity gs, entity ps, string sample, float chan, float voicetype, bool fake); + #define GlobalSound(this, def, chan, voicetype) _GlobalSound(this, def, NULL, string_null, chan, voicetype, false) + #define GlobalSound_string(this, def, chan, voicetype) _GlobalSound(this, NULL, NULL, def, chan, voicetype, false) + #define PlayerSound(thise, def, chan, voicetype) _GlobalSound(this, NULL, def, string_null, chan, voicetype, false) + #define VoiceMessage(this, def, msg) \ do \ { \ entity VM = def; \ @@ -136,7 +136,7 @@ void PrecachePlayerSounds(string f); if (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) fake = true; \ else if (flood > 0) fake = false; \ else break; \ - _GlobalSound(NULL, VM, string_null, CH_VOICE, voicetype, fake); \ + _GlobalSound(this, NULL, VM, string_null, CH_VOICE, voicetype, fake); \ } \ while (0) diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 45fc34927..e949e3a0d 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -346,7 +346,7 @@ void Monster_Sound(.string samplefield, float sound_delay, float delaytoo, float if(delaytoo) if(time < self.msound_delay) return; // too early - GlobalSound_string(self.(samplefield), chan, VOICETYPE_PLAYERSOUND); + GlobalSound_string(self, self.(samplefield), chan, VOICETYPE_PLAYERSOUND); self.msound_delay = time + sound_delay; } diff --git a/qcsrc/common/mutators/mutator/dodging/dodging.qc b/qcsrc/common/mutators/mutator/dodging/dodging.qc index b25de6125..3521ca77f 100644 --- a/qcsrc/common/mutators/mutator/dodging/dodging.qc +++ b/qcsrc/common/mutators/mutator/dodging/dodging.qc @@ -226,7 +226,7 @@ void PM_dodging(entity this) #ifdef SVQC if (autocvar_sv_dodging_sound) - PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); + PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); animdecide_setaction(this, ANIMACTION_JUMP, true); #endif diff --git a/qcsrc/common/physics.qc b/qcsrc/common/physics.qc index 7a22ae1e5..2fd3dbaa7 100644 --- a/qcsrc/common/physics.qc +++ b/qcsrc/common/physics.qc @@ -520,7 +520,7 @@ bool PlayerJump(entity this) animdecide_setaction(this, ANIMACTION_JUMP, true); if (autocvar_g_jump_grunt) - WITH(entity, self, this, PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND)); + PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND); #endif return true; } @@ -754,7 +754,7 @@ void PM_check_hitground(entity this) tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this); if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) return; entity fall = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) ? GS_FALL_METAL : GS_FALL; - WITH(entity, self, this, GlobalSound(fall, CH_PLAYER, VOICETYPE_PLAYERSOUND)); + GlobalSound(this, fall, CH_PLAYER, VOICETYPE_PLAYERSOUND); #endif } diff --git a/qcsrc/lib/log.qh b/qcsrc/lib/log.qh index 3e512a180..2a35e8e9a 100644 --- a/qcsrc/lib/log.qh +++ b/qcsrc/lib/log.qh @@ -12,13 +12,21 @@ } \ while (0) -#define assert(expr, ...) \ +#define assert(expr, ...) _assert(LOG_WARNING, expr, __VA_ARGS__) +#define ASSERT(expr, ...) _assert(LOG_FATAL, expr, __VA_ARGS__) +#define _assert(f, expr, then) \ do \ { \ - if (!(expr)) LOG_WARNINGF(__VA_ARGS__); \ + if (!(expr)) \ + { \ + f("assertion failed: `" #expr "`\n"); \ + then; \ + } \ } \ while (0) +#define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)]; + #define _LOG(f, level, s) f("[::"level "] ["__FILE__ ":%s:%.0f] %s", __FUNC__, __LINE__, s) #define LOG_FATAL(...) _LOG_FATAL(strcat("", __VA_ARGS__)) @@ -84,13 +92,4 @@ noref bool autocvar_prvm_backtraceforwarnings; } \ while (0) -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) LOG_FATAL("assertion failed: " #expr "\n"); \ - } \ - while (0) - -#define ASSERT_LESS(name, var, const) noref int name[(const - var + 1)]; - #endif diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index e1b34a9bb..f68cff0a4 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -2498,21 +2498,18 @@ void PlayerPreThink () { self.teamkill_soundtime = 0; - setself(self.teamkill_soundsource); - entity oldpusher = self.pusher; - self.pusher = this; - - PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY); - - self.pusher = oldpusher; - setself(this); + entity e = self.teamkill_soundsource; + entity oldpusher = e.pusher; + e.pusher = this; + PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY); + e.pusher = oldpusher; } if(self.taunt_soundtime) if(time > self.taunt_soundtime) { self.taunt_soundtime = 0; - PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT); + PlayerSound(self, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT); } target_voicescript_next(self); diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 22ef4bdff..1b0e46038 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -430,15 +430,15 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two { if(deathtype == DEATH_FALL.m_id) - PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND); else if(self.health > 75) // TODO make a "gentle" version? - PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND); else if(self.health > 50) - PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND); else if(self.health > 25) - PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND); else - PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND); } } } @@ -514,9 +514,9 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtyp if(sound_allowed(MSG_BROADCAST, attacker)) { if(deathtype == DEATH_DROWN.m_id) - PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND); else - PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND); } // get rid of kill indicator diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index 6cac1c4f0..573b9417f 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -607,8 +607,8 @@ void ClientCommand_voice(float request, float argc, string command) sprint(this, sprintf("Invalid voice. Use one of: %s\n", allvoicesamples)); return; } - if (argc >= 3) VoiceMessage(e, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2))); - else VoiceMessage(e, ""); + if (argc >= 3) VoiceMessage(this, e, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2))); + else VoiceMessage(this, e, ""); return; } diff --git a/qcsrc/server/playerdemo.qc b/qcsrc/server/playerdemo.qc index f3e03424b..5ca2c1ca9 100644 --- a/qcsrc/server/playerdemo.qc +++ b/qcsrc/server/playerdemo.qc @@ -146,9 +146,9 @@ float playerdemo_read(entity this) PLAYERDEMO_FIELDS(playerdemo_read_) { time = this.playerdemo_time; - WITH(entity, this, this, PlayerPreThink()); + WITH(entity, self, this, PlayerPreThink()); // not running physics though... this is just so we can run weapon stuff - WITH(entity, this, this, PlayerPostThink()); + WITH(entity, self, this, PlayerPostThink()); } this.playerdemo_time = stof(fgets(this.playerdemo_fh)); if(this.playerdemo_time == 0) diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index a7dfb9677..dd6ad7260 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -54,7 +54,7 @@ void CreatureFrame () if (self.waterlevel != WATERLEVEL_SUBMERGED) { if(self.air_finished < time) - PlayerSound(playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND); + PlayerSound(self, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND); self.air_finished = time + autocvar_g_balance_contents_drowndelay; self.dmg = 2; } @@ -161,9 +161,9 @@ void CreatureFrame () if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) { if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) - GlobalSound(GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(self, GS_STEP_METAL, CH_PLAYER, VOICETYPE_PLAYERSOUND); else - GlobalSound(GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND); + GlobalSound(self, GS_STEP, CH_PLAYER, VOICETYPE_PLAYERSOUND); } } } -- 2.39.2