Skip to content

Commit

Permalink
Fix e2 soundcore & sound emitter from not playing soundscripts & soun…
Browse files Browse the repository at this point in the history
…ds with sound characters. (#3125)

* fix soundcore

* no longer necessary

* fix sound emitter also

* match all symbols at the beginning

* Update SoundExists to sanitize sound paths

---------

Co-authored-by: thegrb93 <[email protected]>
  • Loading branch information
unknao and thegrb93 committed Sep 6, 2024
1 parent cc56ea8 commit 5c5f3dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
7 changes: 3 additions & 4 deletions lua/entities/gmod_wire_expression2/core/sound.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ local function soundStop(self, index, fade)
timer.Remove( "E2_sound_stop_" .. self.entity:EntIndex() .. "_" .. index )
end

local function soundCreate(self, entity, index, time, path, fade)
path = string.Trim(string.sub(path, 1, 260))
if path:match('["?]') then return end

if not file.Exists("sound/" .. path, "GAME") then return end
local function soundCreate(self, entity, index, time, path, fade)
path = WireLib.SoundExists(path)
if not path then return end
local data = self.data.sound_data
if not isAllowed( self ) then return end

Expand Down
13 changes: 6 additions & 7 deletions lua/entities/gmod_wire_soundemitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ end

function ENT:UpdateSound()
if self.NeedsRefresh or self.sound ~= self.ActiveSample then
if not file.Exists("sound/" .. self.sound, "GAME") then return end

self.NeedsRefresh = nil
local filter = RecipientFilter()
Expand Down Expand Up @@ -167,23 +166,23 @@ end
function ENT:SetSound(soundName)
self:StopSounds()

soundName = string.Trim(string.sub(soundName, 1, 260))
if soundName:match('["?]') then return end
util.PrecacheSound(soundName)
soundName = WireLib.SoundExists(soundName)
if not soundName then return end

util.PrecacheSound(soundName)
self.sound = soundName

self.SoundProperties = sound.GetProperties(self.sound)
self.SoundProperties = sound.GetProperties(soundName)
if self.SoundProperties then
WireLib.TriggerOutput(self, "Duration", SoundDuration(self.sound))
WireLib.TriggerOutput(self, "Duration", SoundDuration(soundName))
WireLib.TriggerOutput(self, "Property Sound", 1)
WireLib.TriggerOutput(self, "Properties", self.SoundProperties)
else
WireLib.TriggerOutput(self, "Property Sound", 0)
WireLib.TriggerOutput(self, "Properties", {})
end

self:SetOverlayText( soundName:gsub("[/\\]+","/") )
self:SetOverlayText(soundName)
end

function ENT:StartSounds()
Expand Down
7 changes: 7 additions & 0 deletions lua/wire/server/wirelib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,13 @@ if not WireLib.PatchedDuplicator then
end
end

function WireLib.SoundExists(path)
path = string.GetNormalizedFilepath(string.gsub(string.sub(path, 1, 260), '["?]', ''))
if istable(sound.GetProperties(path)) or file.Exists("sound/" .. path, "GAME") then
return path
end
end

-- Notify --

local triv_start = WireLib.Net.Trivial.Start
Expand Down

0 comments on commit 5c5f3dd

Please sign in to comment.