From 1b7f5af7bcb1d59cc8682d3bbfdef92e7b380c99 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Mon, 10 Aug 2026 04:04:13 +0300 Subject: [PATCH 1/4] Some fixes about max volume clamping --- .../gmod_wire_expression2/core/sound.lua | 22 ++----------------- lua/entities/gmod_wire_soundemitter.lua | 3 ++- lua/wire/server/wirelib.lua | 16 +++++++++++--- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index 25072b5d8c..4eb44751f2 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -7,7 +7,6 @@ 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_max_level = GetConVar( "wire_sound_max_level" ) --------------------------------------------------------------- -- Helper functions @@ -239,15 +238,7 @@ e2function void soundLevel( index, level ) -- We need to set the level while the sound is stopped sound:Stop() - - 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 - level = max_level - end - - sound:SetSoundLevel(level) + sound:SetSoundLevel(WireLib.ClampSoundLevel(level)) sound:Play() end e2function void soundLevel( string index, level ) = e2function void soundLevel( index, level ) @@ -304,19 +295,10 @@ local function EmitSound(e2, ent, path, level, pitch, volume) if not IsValid(ent) then return e2:throw("Invalid entity!", nil) end 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_max_level:GetInt() - - -- 0 = play sound throughout the map - if max_level ~= -1 and (level == 0 or level > max_level) then - level = max_level - end - end - path = WireLib.SoundExists(path) if not path then return end - ent:EmitSound(path, level, pitch, volume) + ent:EmitSound(path, WireLib.ClampSoundLevel(level), pitch, volume) end __e2setcost(20) diff --git a/lua/entities/gmod_wire_soundemitter.lua b/lua/entities/gmod_wire_soundemitter.lua index 916fe2b77a..0602460ff5 100644 --- a/lua/entities/gmod_wire_soundemitter.lua +++ b/lua/entities/gmod_wire_soundemitter.lua @@ -157,9 +157,10 @@ function ENT:UpdateSound() if self.Active then self:StartSounds() end end + self.SoundObj:ChangePitch(math.Clamp(self.Pitch, 0, 255), 0) self.SoundObj:ChangeVolume(math.Clamp(self.Volume / 100, 0, 1), 0) - self.SoundObj:SetSoundLevel(math.Clamp(self.Level, 55, 165)) + self.SoundObj:SetSoundLevel(WireLib.ClampSoundLevel(self.Level)) end function ENT:SetSound(soundName) diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index cdf2cdd5f5..594828ca73 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1582,7 +1582,17 @@ 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_sound_max_level", "180", FCVAR_ARCHIVE, "The maximum sounds volume (-1 disable)") +local maxSoundLevel = CreateConVar("wire_sound_max_level", "255", FCVAR_ARCHIVE, "The maximum sounds volume (0 to disable)") + +function WireLib.ClampSoundLevel(level) + local max_level = maxSoundLevel:GetInt() + + if max_level > 0 then + return level <= 0 and max_level or math.min(level, max_level) + else + return level + end +end function WireLib.SoundExists(path, ply) -- Limit length and remove invalid chars @@ -1598,14 +1608,14 @@ function WireLib.SoundExists(path, ply) -- Disallow too loud sounds local max_level = maxSoundLevel:GetInt() - if max_level ~= -1 then + if max_level > 0 then local sound_data = sound.GetProperties(checkpath) if sound_data then local sound_level = sound_data.level -- 0 = play sound throughout the map - if sound_level <= 0 then + if sound_level <= 0 or sound_level > max_level then local sounds = sound_data.sound path = istable(sounds) and sounds[math.random(#sounds)] or sounds end From ca9dc6736684f178547faafded2ef22ce5ac48ec Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Mon, 10 Aug 2026 04:09:13 +0300 Subject: [PATCH 2/4] More useful comment --- lua/wire/server/wirelib.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 594828ca73..4f78cbe00e 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1614,7 +1614,7 @@ function WireLib.SoundExists(path, ply) if sound_data then local sound_level = sound_data.level - -- 0 = play sound throughout the map + -- We can't clamp soundlevel of soundscript, take it's sound directly if sound_level <= 0 or sound_level > max_level then local sounds = sound_data.sound path = istable(sounds) and sounds[math.random(#sounds)] or sounds From 66681e39c2e250fa56bbef02b50ca93a7e7ce55c Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Mon, 10 Aug 2026 04:18:56 +0300 Subject: [PATCH 3/4] Clamp convars --- lua/wire/server/wirelib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index 4f78cbe00e..6485daeb63 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1581,8 +1581,8 @@ if not WireLib.PatchedDuplicator then 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_sound_max_level", "255", FCVAR_ARCHIVE, "The maximum sounds volume (0 to disable)") +local maxUniqueSounds = CreateConVar("wire_sounds_unique_max", "200", FCVAR_ARCHIVE, "The maximum number of sound paths a player is allowed to cache", 0) +local maxSoundLevel = CreateConVar("wire_sound_max_level", "255", FCVAR_ARCHIVE, "The maximum sounds volume (0 to disable)", 0, 255) function WireLib.ClampSoundLevel(level) local max_level = maxSoundLevel:GetInt() From 66f77d3b7cdab0860fde90714c51d684ca902b55 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Mon, 10 Aug 2026 04:27:54 +0300 Subject: [PATCH 4/4] Fix nil error --- lua/entities/gmod_wire_expression2/core/sound.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/sound.lua b/lua/entities/gmod_wire_expression2/core/sound.lua index 4eb44751f2..11978257cb 100644 --- a/lua/entities/gmod_wire_expression2/core/sound.lua +++ b/lua/entities/gmod_wire_expression2/core/sound.lua @@ -298,7 +298,7 @@ local function EmitSound(e2, ent, path, level, pitch, volume) path = WireLib.SoundExists(path) if not path then return end - ent:EmitSound(path, WireLib.ClampSoundLevel(level), pitch, volume) + ent:EmitSound(path, WireLib.ClampSoundLevel(level or SNDLVL_75dB), pitch, volume) end __e2setcost(20)