Add files via upload
This commit is contained in:
@@ -81,6 +81,47 @@ local function Count(t)
|
||||
return n
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Sound-CVar snapshot / restore.
|
||||
--
|
||||
-- Every CVar this addon writes to (MasterSoundEffects, EnableMusic,
|
||||
-- MasterVolume, ...) is snapshotted into SavedVariables the FIRST time
|
||||
-- we change it in a session, and restored on PLAYER_LOGOUT.
|
||||
--
|
||||
-- Why SavedVariables and not just an in-memory table:
|
||||
-- KillAllSounds() sets MasterSoundEffects="0" and re-enables it ~50ms
|
||||
-- later from the ticker. If the player /reloads, logs out, or the
|
||||
-- client crashes inside that window, "0" is what WoW persists to
|
||||
-- Config.wtf and every sound effect is muted on the next login with
|
||||
-- no obvious cause. Persisting the pre-mute value lets us recover
|
||||
-- on the very next VARIABLES_LOADED even after a hard crash.
|
||||
-----------------------------------------------------------------------
|
||||
local function SnapshotCVar(name)
|
||||
if type(RelationshipsJukeboxDB) ~= "table" then RelationshipsJukeboxDB = {} end
|
||||
if type(RelationshipsJukeboxDB.savedCVars) ~= "table" then
|
||||
RelationshipsJukeboxDB.savedCVars = {}
|
||||
end
|
||||
if RelationshipsJukeboxDB.savedCVars[name] ~= nil then
|
||||
return -- already snapshotted this session (or from a previous crashed session)
|
||||
end
|
||||
local cv = GetCVar or function() return nil end
|
||||
local ok, val = pcall(cv, name)
|
||||
if ok and val ~= nil then
|
||||
RelationshipsJukeboxDB.savedCVars[name] = tostring(val)
|
||||
end
|
||||
end
|
||||
|
||||
local function RestoreSavedCVars()
|
||||
if type(RelationshipsJukeboxDB) ~= "table" then return end
|
||||
local saved = RelationshipsJukeboxDB.savedCVars
|
||||
if type(saved) ~= "table" then return end
|
||||
local sc = SetCVar or function() end
|
||||
for name, value in pairs(saved) do
|
||||
pcall(sc, name, value)
|
||||
end
|
||||
RelationshipsJukeboxDB.savedCVars = nil
|
||||
end
|
||||
|
||||
local function Trim(s)
|
||||
if not s then return "" end
|
||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||
@@ -366,6 +407,10 @@ end
|
||||
|
||||
local function KillAllSounds(afterReenableCallback)
|
||||
local sc = SetCVar or function() end
|
||||
-- Snapshot MasterSoundEffects BEFORE muting, so if the player /reloads
|
||||
-- or crashes before the ticker re-enables it, we can restore it on
|
||||
-- the next login instead of leaving Config.wtf with SFX muted.
|
||||
SnapshotCVar("MasterSoundEffects")
|
||||
-- Kill ALL currently playing sounds by disabling the master sound CVar.
|
||||
pcall(sc, "MasterSoundEffects", "0")
|
||||
-- Also stop any PlayMusic track as a fallback.
|
||||
@@ -1352,9 +1397,12 @@ local function CreateUI()
|
||||
slider:SetScript("OnValueChanged", function()
|
||||
local pct = this:GetValue()
|
||||
local sc = SetCVar or function() end
|
||||
-- Snapshot MasterVolume once so we can restore the player's
|
||||
-- original master output level on logout.
|
||||
SnapshotCVar("MasterVolume")
|
||||
-- MasterVolume is 0..1, slider is 0..100
|
||||
pcall(sc, "MasterVolume", string.format("%.2f", pct / 100))
|
||||
-- Persist to SavedVariables
|
||||
-- Persist slider position (not applied at login — see VARIABLES_LOADED)
|
||||
RelationshipsJukeboxDB.volume = pct
|
||||
end)
|
||||
end)
|
||||
@@ -1438,6 +1486,7 @@ local function CreateUI()
|
||||
-- Reset volume slider to default (100%)
|
||||
do
|
||||
local sc = SetCVar or function() end
|
||||
SnapshotCVar("MasterVolume")
|
||||
pcall(sc, "MasterVolume", "1.0")
|
||||
RelationshipsJukeboxDB.volume = 100
|
||||
if RJ.volumeSlider then
|
||||
@@ -1911,16 +1960,18 @@ logoutHandler:SetScript("OnEvent", function()
|
||||
RJ.pausedElapsed = nil
|
||||
RJ.currentDuration = 0
|
||||
end
|
||||
-- Always restore the player's original EnableMusic on logout,
|
||||
-- even if no track was playing.
|
||||
if RJ._originalEnableMusic then
|
||||
local sc = SetCVar or function() end
|
||||
pcall(sc, "EnableMusic", RJ._originalEnableMusic)
|
||||
RJ._originalEnableMusic = nil
|
||||
end
|
||||
-- Suppress any remaining pending state
|
||||
-- Suppress the pending MasterSoundEffects re-enable — we're about to
|
||||
-- restore it explicitly from the snapshot below, and the ticker will
|
||||
-- not fire again this session.
|
||||
RJ._pendingReenableAt = nil
|
||||
RJ._pendingReenableCallback = nil
|
||||
-- Clear legacy in-memory copy (superseded by SavedVariables snapshot).
|
||||
RJ._originalEnableMusic = nil
|
||||
-- Restore every sound CVar the addon ever changed this session
|
||||
-- (EnableMusic, MasterSoundEffects, MasterVolume, ...) back to the
|
||||
-- value the player had before the addon loaded, and clear the
|
||||
-- snapshot so the next login starts clean.
|
||||
RestoreSavedCVars()
|
||||
end)
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
@@ -2085,21 +2136,32 @@ loader:SetScript("OnEvent", function()
|
||||
|
||||
EnsureDB()
|
||||
|
||||
-- CRASH-RECOVERY: if a previous session ended (logout, /reload, or crash)
|
||||
-- without our PLAYER_LOGOUT handler firing — for example inside the ~50ms
|
||||
-- window where KillAllSounds() has MasterSoundEffects="0" — restore the
|
||||
-- pre-mute values from SavedVariables FIRST, before we do anything else.
|
||||
-- This guarantees the player logs in with their real sound settings even
|
||||
-- after a hard crash mid-mute.
|
||||
RestoreSavedCVars()
|
||||
|
||||
-- Save the player's original EnableMusic value and disable game engine
|
||||
-- music so it does not overlap with jukebox playback. This is restored
|
||||
-- on logout or when the Reset button is pressed.
|
||||
-- music so it does not overlap with jukebox playback. Restored on
|
||||
-- PLAYER_LOGOUT via RestoreSavedCVars() (and on Reset).
|
||||
--
|
||||
-- IMPORTANT: We deliberately do NOT touch MasterVolume here. MasterVolume
|
||||
-- is the global master output CVar and controls ALL game audio (SFX,
|
||||
-- ambience, jukebox, everything). A previous version applied the saved
|
||||
-- jukebox slider value to MasterVolume at login, which muted every game
|
||||
-- sound whenever the slider had been dragged down. The only thing that
|
||||
-- should be silenced when this addon loads is the in-game music ("the
|
||||
-- music box"), which is what EnableMusic="0" does.
|
||||
do
|
||||
local cv = GetCVar or function() return "1" end
|
||||
local sc = SetCVar or function() end
|
||||
SnapshotCVar("EnableMusic")
|
||||
local ok, val = pcall(cv, "EnableMusic")
|
||||
RJ._originalEnableMusic = (ok and val) or "1"
|
||||
pcall(sc, "EnableMusic", "0")
|
||||
-- Apply saved MasterVolume (master output volume). If the
|
||||
-- player has never set it, the CVar default (1.0) remains.
|
||||
if RelationshipsJukeboxDB.volume then
|
||||
pcall(sc, "MasterVolume",
|
||||
string.format("%.2f", RelationshipsJukeboxDB.volume / 100))
|
||||
end
|
||||
end
|
||||
|
||||
imported, updated = MergeAutoPlaylist()
|
||||
|
||||
Reference in New Issue
Block a user