From 4d3ff34d2fb419e08dc75b727668b6789ddfb33c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:15:00 +0300 Subject: [PATCH 1/5] Actually fix music sounds abuse --- .../gmod_wire_expression2/core/sound.lua | 17 ++++++++---- lua/wire/server/wirelib.lua | 27 +++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index 8b1b24f6d2..816e6c0aa7 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -7,9 +7,7 @@ E2Lib.RegisterExtension("sound", true, "Allows E2s to play sounds.", "Sounds can local wire_expression2_maxsounds = CreateConVar( "wire_expression2_maxsounds", 16, {FCVAR_ARCHIVE} ) local wire_expression2_sound_burst_max = CreateConVar( "wire_expression2_sound_burst_max", 8, {FCVAR_ARCHIVE} ) local wire_expression2_sound_burst_rate = CreateConVar( "wire_expression2_sound_burst_rate", 0.1, {FCVAR_ARCHIVE} ) - --- _level_max: Sets the maximum soundLevel we can set on a sound. 140 is maximum to begin with, a more non-obnoxious level is maybe around 110. -local wire_expression2_sound_level_max = CreateConVar( "wire_expression2_sound_level_max", 110, {FCVAR_ARCHIVE} ) +local wire_sound_level_max = GetConVar( "wire_max_sound_level" ) --------------------------------------------------------------- -- Helper functions @@ -238,9 +236,18 @@ e2function void soundDSP( string index, dsp ) = e2function void soundDSP( index, e2function void soundLevel( index, level ) local sound = getSound( self, index ) if not sound then return end + -- We need to set the level while the sound is stopped sound:Stop() - sound:SetSoundLevel( math.Clamp( level, 0, wire_expression2_sound_level_max:GetInt() ) ) + + local max_level = wire_sound_level_max:GetInt() + + -- 0 = play sound throughout the map + if max_level ~= -1 and (level == 0 or level > max_level) then + level = max_level + end + + sound:SetSoundLevel(level) sound:Play() end e2function void soundLevel( string index, level ) = e2function void soundLevel( index, level ) @@ -298,7 +305,7 @@ local function EmitSound(e2, ent, path, level, pitch, volume) if not isOwner(e2, ent) then return e2:throw("You do not own this entity!", nil) end if level then - local max_level = wire_expression2_sound_level_max:GetInt() + local max_level = wire_sound_level_max:GetInt() -- 0 = play sound throughout the map if max_level ~= -1 and (level == 0 or level > max_level) then diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 739c8939a3..3fdb11f5b1 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1582,6 +1582,7 @@ end local uniqueSoundsTbl = setmetatable({}, {__index=function(t,k) local r={[1]=0} t[k]=r return r end}) local maxUniqueSounds = CreateConVar("wire_sounds_unique_max", "200", FCVAR_ARCHIVE, "The maximum number of sound paths a player is allowed to cache") +local maxSoundLevel = CreateConVar("wire_max_sound_level", "180", FCVAR_ARCHIVE, "The maximum sounds volume (-1 disable)") function WireLib.SoundExists(path, ply) -- Limit length and remove invalid chars @@ -1589,19 +1590,41 @@ function WireLib.SoundExists(path, ply) -- Extract sound flags. See https://developer.valvesoftware.com/wiki/Soundscripts#Sound_characters local flags, checkpath = string.match(path, "^([^%w_/%.]*)(.*)") + if #flags > 2 or string.match(flags, "[^#@<>%^%)}]") then path = checkpath end + -- Disallow too loud sounds + local max_level = maxSoundLevel:GetInt() + + if max_level ~= -1 then + local sound_data = sound.GetProperties(checkpath) + + if sound_data then + local sound_level = sound_data.level + + if sound_level > max_level then + return + elseif sound_level <= 0 then + return + end + end + end + if ply then -- A player can only use a certain number of unique sound paths local playerSounds = uniqueSoundsTbl[ply:SteamID()] + if not playerSounds[checkpath] then - if playerSounds[1] >= maxUniqueSounds:GetInt() then return end + if playerSounds[1] >= maxUniqueSounds:GetInt() then + return + end + playerSounds[checkpath] = true playerSounds[1] = playerSounds[1] + 1 end - elseif not (istable(sound.GetProperties(checkpath)) or file.Exists("sound/" .. checkpath, "GAME")) then + elseif not sound.GetProperties(checkpath) or not file.Exists("sound/" .. checkpath, "GAME") then return end From 7f9e350a098427060a4e95f3bca835b763271a14 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:21:37 +0300 Subject: [PATCH 2/5] Fixes/cleanups --- lua/entities/gmod_wire_expression2/core/sound.lua | 6 +++--- lua/wire/server/wirelib.lua | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index 816e6c0aa7..25072b5d8c 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -7,7 +7,7 @@ E2Lib.RegisterExtension("sound", true, "Allows E2s to play sounds.", "Sounds can local wire_expression2_maxsounds = CreateConVar( "wire_expression2_maxsounds", 16, {FCVAR_ARCHIVE} ) local wire_expression2_sound_burst_max = CreateConVar( "wire_expression2_sound_burst_max", 8, {FCVAR_ARCHIVE} ) local wire_expression2_sound_burst_rate = CreateConVar( "wire_expression2_sound_burst_rate", 0.1, {FCVAR_ARCHIVE} ) -local wire_sound_level_max = GetConVar( "wire_max_sound_level" ) +local wire_sound_max_level = GetConVar( "wire_sound_max_level" ) --------------------------------------------------------------- -- Helper functions @@ -240,7 +240,7 @@ e2function void soundLevel( index, level ) -- We need to set the level while the sound is stopped sound:Stop() - local max_level = wire_sound_level_max:GetInt() + local max_level = wire_sound_max_level:GetInt() -- 0 = play sound throughout the map if max_level ~= -1 and (level == 0 or level > max_level) then @@ -305,7 +305,7 @@ local function EmitSound(e2, ent, path, level, pitch, volume) if not isOwner(e2, ent) then return e2:throw("You do not own this entity!", nil) end if level then - local max_level = wire_sound_level_max:GetInt() + local max_level = wire_sound_max_level:GetInt() -- 0 = play sound throughout the map if max_level ~= -1 and (level == 0 or level > max_level) then diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 3fdb11f5b1..edcfb7de4d 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1582,7 +1582,7 @@ end local uniqueSoundsTbl = setmetatable({}, {__index=function(t,k) local r={[1]=0} t[k]=r return r end}) local maxUniqueSounds = CreateConVar("wire_sounds_unique_max", "200", FCVAR_ARCHIVE, "The maximum number of sound paths a player is allowed to cache") -local maxSoundLevel = CreateConVar("wire_max_sound_level", "180", FCVAR_ARCHIVE, "The maximum sounds volume (-1 disable)") +local maxSoundLevel = CreateConVar("wire_sound_max_level", "180", FCVAR_ARCHIVE, "The maximum sounds volume (-1 disable)") function WireLib.SoundExists(path, ply) -- Limit length and remove invalid chars @@ -1604,9 +1604,7 @@ function WireLib.SoundExists(path, ply) if sound_data then local sound_level = sound_data.level - if sound_level > max_level then - return - elseif sound_level <= 0 then + if sound_level > max_level or sound_level <= 0 then return end end @@ -1624,7 +1622,7 @@ function WireLib.SoundExists(path, ply) playerSounds[checkpath] = true playerSounds[1] = playerSounds[1] + 1 end - elseif not sound.GetProperties(checkpath) or not file.Exists("sound/" .. checkpath, "GAME") then + elseif not sound.GetProperties(checkpath) and not file.Exists("sound/" .. checkpath, "GAME") then return end From 35b579f36d2deea836e8cff20cae2bae4f96cd95 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:32:53 +0300 Subject: [PATCH 3/5] Replace the default sound with a more pleasant one --- lua/entities/gmod_wire_soundemitter.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_soundemitter.lua b/lua/entities/gmod_wire_soundemitter.lua index b04ab77fcd..916fe2b77a 100644 --- a/lua/entities/gmod_wire_soundemitter.lua +++ b/lua/entities/gmod_wire_soundemitter.lua @@ -32,7 +32,7 @@ function ENT:Initialize() self.Volume = 100 self.Level = 80 self.Pitch = 100 - self.sound = self.Samples[1] + self.sound = "synth/brown_noise.wav" -- self.sound is a string, self.SoundObj is a CSoundPatch self.NeedsRefresh = true From 3272382ff8c23f612e32d6eefde858fa8f90aa65 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:36:16 +0300 Subject: [PATCH 4/5] Just use default sound --- lua/wire/server/wirelib.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index edcfb7de4d..f22dda54db 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1604,8 +1604,9 @@ function WireLib.SoundExists(path, ply) if sound_data then local sound_level = sound_data.level - if sound_level > max_level or sound_level <= 0 then - return + if sound_level <= 0 then + local sounds = sound_data.sound + path = istable(sounds) and sounds[math.random(#sounds)] or sounds end end end From bc421e8c4ee53afdb4169b900c8654e953e0f89f Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Sun, 9 Aug 2026 03:41:14 +0300 Subject: [PATCH 5/5] Add comment --- lua/wire/server/wirelib.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index f22dda54db..cdf2cdd5f5 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1604,6 +1604,7 @@ function WireLib.SoundExists(path, ply) if sound_data then local sound_level = sound_data.level + -- 0 = play sound throughout the map if sound_level <= 0 then local sounds = sound_data.sound path = istable(sounds) and sounds[math.random(#sounds)] or sounds