Add client-side world sound replacement functions - #5330
Conversation
Added CClientWorldSoundManager for managing world sounds and integrated it into the game logic.
Added ValidateSound function to check audio validity and handle errors.
Implement client-side world sound management with sound replacement functionality.
|
This isn't actually replacing the sounds, and in my opinion these functions shouldn't be named that way. You're not replacing the actual sound in the audio banks; you're muting the original sounds and playing your own instead. This will mean that, for example, engine sounds won't be modulated based on the vehicle's gear and will instead remain at a constant sound. |
But naming it engineReplaceWorldSound is completely consistent with MTA. Ex, engineReplaceModel doesn't alter the original DFF file inside gta3.img either; it suppresses the original entity and substitutes it in runtime memory. in GTA SA, true bank patching at runtime is unstable and doesn't support custom external formats easily. Anyway, let me think of a better approach and update the files. |
Added DecodeToPcm function to handle PCM decoding from sound files.
Added new members for native sound replacement handling.
|
@FileEX , |
|
Could you record a video showing the engine sound being replaced and reacting to how the vehicle is being driven? |
Sure, i will record a quick video demonstrating the replaced engine sound, then share it here, give me some time |
The engine pitch and sound modulate smoothly with the rpm, speed, and gear shifts, sorry for the short video; GitHub doesn't allow video/image uploads over 10MB 2026-09-07.02-48-01.mp4 |
|
Example: replaceWorldSound("ak1.wav", 5, 31, 5, 25)
replaceWorldSound("ak2.wav", 5, 32, 5, 25)
replaceWorldSound("ak3.wav", 5, 33, 5, 25)2026-09-07.03-05-16.mp4 |
This sound really weird... |
Removed functions related to world sound management from CLuaEngineDefs.cpp.
Removed unused includes for CClientWorldSoundManager and CResourceManager.
|
Can u replace vehicle horn sounds with this? Got a video/audio demo? :D |
xD 2026-09-07.20-45-33.mp4 |
|
lmao I meant a realistic horn sound that sounds as good as the originals |
|
Wouldn't it be more efficient to replace audio chunks in internal data bunks? Your solution basically acts like a replacement for playSound3D (which is inefficient and will not produce native behavior) |
It already does that; index-specific replacements patch the PCM buffer inside the game's loaded sound bank ( |
Added uiGroup and uiIndex to sound structure for better management.
|
@Fernando-A-Rocha here's exactly what u wanted to see regarding the vehicle horn; and @FileEX here are the engine sounds just as u wanted to hear them. the only thing is i don't have the ideal audio files yet; i just found a few decent ones to test with for now. also, using the function properly requires someone who knowns the function's group and index numbers 2026-09-07.23-16-14.mp4 |
If you're replacing a sound in the sound bank, you don't need |
np, just let me know exactly what u would like me to do and i will handle it. list all ur suggestions/required changes |
|
Generally, it should work so that the specified sound in the given audio bank is actually replaced, but the game still plays it normally, modifies its pitch, frequency, etc., without cancelling It's the same as with |
It should be doing this now. i also added a new function, |
Summary
Adds four new client-side functions that let resources replace GTA world sounds (weapon shots, bullet impacts, explosions, vehicle, environment sounds and etc..) directly, without the usual workarounds:
Example:
Behavior highlights:
minDistance/maxDistanceoverrides per call).audio sfxCVar) andmute_sfx_when_minimized, matching the original sound exactly.replaceWorldSoundvalidates the audio file and the distance arguments at call time; unreadable/corrupt files and inverted distances returnfalseand log a script-debugging warning.isWorldSoundReplacedqueries the current state.Video (Make sure to unmute the video):
2026-09-06.21-36-01.mp4
Motivation
Currently, replacing an internal GTA world sound (e.g. a weapon shot) requires disabling the original with
setWorldSoundEnabled, cancellingonClientWorldSound, and manually re-playing a new sound viaplaySound3Dwith tracked positions. That loses the original sound's position and distance behavior, is tedious to write, and is error-prone.This PR lets a resource replace any world sound with a single call, keeping GTA's original trigger, position and distance semantics.
Closes #4908.
Test plan
minDistance/maxDistance).audio sfxto 0 and minimize the game; the replacement must go silent, same as the original.falseand log a warning.Checklist