Skip to content

Headshots can be heard further away: new Sound setting in game - #1352

Open
ccoventry wants to merge 2 commits into
devfrom
feat/headshot-sound-far
Open

ccoventry wants to merge 2 commits into
devfrom
feat/headshot-sound-far

Conversation

@ccoventry

Copy link
Copy Markdown
Owner

Release note: New: "Hear headshots further away" (ds_sound_headshot_far 1): a headshot's sound carries twice as far, without changing any sound file.

What

  • goldsrc-hooks/src/headshot_sound.rs: ds_sound_headshot_far (default 0). While on, player/helmet_hit.wav plays with half its attenuation (0.8 -> 0.4), so it fades out at 2500 units instead of 1250. Every other sound is untouched.
  • fire_sounds' EV_PlaySound hook asks it for the attenuation. The per-sound cost is one byte compare of the name the hook already reads; no lock.
  • In-game Settings tab row (Sound), Commands.txt, Settings.res and console_commands_data.js regenerated, docs/dodstudio_commands.md, goldsrc-hooks/README.md, console_prefix.rs's list of names with no old dodstudio_ one. ds_debug_status counts the headshot sounds and how far away the last one was.

How the sound arrives

Not from the server, so ds_debug_log_server_sounds never shows it. DoD's client.dll plays it from the events/effects/bodydamage.sc handler (client.dll+0xb790): EV_PlaySound(args->entindex, args->origin, CHAN_STATIC, "player/helmet_hit.wav", RandomFloat(0.92, 1.0), 0.8, 0, 100) when bparam1 is 0. (helmet.sc, the helmet flying off, plays no sound.) client.dll is byte-identical across installs and the hook sits on the event API table, so there is no per-build table; tested on both builds.

A temporary log line in the hook (removed before this PR) showed every headshot sound going through the hook, with the event's entity being the player hit in 11 of 11 headshot kills checked against the analyzer's kill list.

Decisions

  • On/off, not a number. Halving the attenuation is the "carries further" step: past 1250 units ATTN_NORM is silent, and half of the 26 headshot kills in ktps8w9-stealth_gskill_rr2_h1 are over 1000 units from the killer. 0 (ATTN_NONE) would play every headshot at full volume across the map. Volume can't go past 1.0 in the engine.
  • The name covers headshots in general: helmet_hit.wav is the only headshot sound DoD plays.
  • What a POV viewer hears: headshots on other players (the recorder's own kills included) carry further. The recorder's own head hits come from the view entity, which the engine plays at full level in both ears, unplaced, so they are unchanged (measured below).

Test done

In game, PRE and POST, ktps8w9-stealth_gskill_rr2_h1 (POV), -addons with the user's own dod_addon helmet_hit.wav, HLAE mirv_movie_sound 1 takes at the same moments with the setting at 0 and 1, levels found with a matched filter against helmet_hit.wav (0 dB = the file at full volume). Evidence and takes: D:\dodstudio-tests\helmet-hit-far\ (measurements.txt).

viewdemo distance PRE 0 PRE 1 POST 0 POST 1
12:11:80 1507 u silent -6.8 dB silent -6.9 dB
12:27:80 2280 u silent - silent -18.7 dB
14:25:40 570 u -3.0 dB -1.0 dB -3.2 dB -1.1 dB
14:37:47 1249 u silent -2.5 dB silent -2.6 dB
14:53:47 299 u -3.2 dB -2.3 dB -3.5 dB -2.5 dB
14:35:81 recorder's own head hit +0.6 dB - +0.3 dB +0.7 dB

(The game varies each hit's volume by 0.7 dB. The near ear at 570 u reaches full scale with the user's boosted file, so that row gains a little less than the +3 dB the formula gives.)

  • cargo test -p goldsrc-hooks --target i686-pc-windows-msvc (1223 pass), cargo test -p native console_prefix, rustfmt and clippy -D warnings on 1.98.1.
  • Not run: npm run test:unit (only the generated data file changed on the JS side).

Test DLL: local\test-helmet-far\dodstudio_goldsrc_hooks.dll.

🤖 Generated with Claude Code

The headshot sound (player/helmet_hit.wav) comes from DoD's client, the
events/effects/bodydamage.sc handler calling EV_PlaySound on the hit
player at ATTN_NORM. The fire_sounds hook now halves that attenuation
while the setting is on, so it fades out at 2500 units instead of 1250.
No .wav file or demo is touched; default off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… hint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccoventry

Copy link
Copy Markdown
Owner Author

Combined in-game test of #1350, #1351 and #1352

Built from dev f628957 with all three branches merged locally. They merge with no conflicts. DLL: local\test-combined\. Recorded at 2560×1440 with the user's dicewsod25.cfg on the Brain account, as an HLAE 300 fps batch capture.

Evidence is in D:\dodstudio-tests\combined-1350-1352\.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant