diff --git a/Randomiser/Resources/Modules/General/FixAudiTT.lua b/Randomiser/Resources/Modules/General/FixAudiTT.lua index 26f4b05..4e9df46 100644 --- a/Randomiser/Resources/Modules/General/FixAudiTT.lua +++ b/Randomiser/Resources/Modules/General/FixAudiTT.lua @@ -22,4 +22,22 @@ FixAudiTT:AddP3DHandler("art/cars/tt.p3d", function(Path, P3DFile) return true end) +FixAudiTT:AddSPTHandler("sound/scripts/car_tune.spt", function(Path, SPT) + local changed = false + + for carSoundParameters in SPT:GetClasses("carSoundParameters") do + for method, index in carSoundParameters:GetMethods(true) do + local name = method.Name + if name == "SetEngineClipName" or name == "SetEngineIdleClipName" then + if method.Parameters[1] == "tt" then + method.Parameters[1] = "apu_car" + changed = true + end + end + end + end + + return changed +end) + return FixAudiTT \ No newline at end of file diff --git a/Randomiser/Resources/Modules/General/FixCartune.lua b/Randomiser/Resources/Modules/General/FixCartune.lua index 59e6d3e..cb254cf 100644 --- a/Randomiser/Resources/Modules/General/FixCartune.lua +++ b/Randomiser/Resources/Modules/General/FixCartune.lua @@ -1,18 +1,55 @@ local table_remove = table.remove -local FixCartune = Module("Fix Cartune", nil, 1) +local FixCartune = Module("Fix Cartune", nil, 2) +local LoadedSounds = {} + +FixCartune:AddSPTHandler("*.spt", function(Path, SPT) + for daSoundResourceData in SPT:GetClasses("daSoundResourceData") do + LoadedSounds[daSoundResourceData.Name] = true + end + + return false +end) + +local DefaultEngine = "snake_car" +local DefaultDamagedEngine = "fire" +local DefaultHorn = "horn" +local RemoveIfNotLoaded = { + ["SetRoadSkidClipName"] = true, + ["SetDirtSkidClipName"] = true, + ["SetBackupClipName"] = true, + ["SetCarDoorOpenClipName"] = true, + ["SetCarDoorCloseClipName"] = true, + ["SetOverlayClipName"] = true, +} FixCartune:AddSPTHandler("sound/scripts/car_tune.spt", function(Path, SPT) for carSoundParameters in SPT:GetClasses("carSoundParameters") do for method, index in carSoundParameters:GetMethods(true) do local name = method.Name - if name == "SetEngineClipName" or name == "SetEngineIdleClipName" then - if method.Parameters[1] == "tt" then - method.Parameters[1] = "apu_car" + if name == "SetEngineClipName" then + if not LoadedSounds[method.Parameters[1]] then + print(string.format("Replacing not-loaded engine sound \"%s\" with \"%s\".", method.Parameters[1], DefaultEngine)) + method.Parameters[1] = DefaultEngine + end + elseif name == "SetEngineIdleClipName" then + if not LoadedSounds[method.Parameters[1]] then + print(string.format("Replacing not-loaded idle engine sound \"%s\" with \"%s\".", method.Parameters[1], DefaultEngine)) + method.Parameters[1] = DefaultEngine + end + elseif name == "SetDamagedEngineClipName" then + if not LoadedSounds[method.Parameters[1]] then + print(string.format("Replacing not-loaded damaged engine sound \"%s\" with \"%s\".", method.Parameters[1], DefaultDamagedEngineEngine)) + method.Parameters[1] = DefaultDamagedEngine + end + elseif name == "SetHornClipName" then + if not LoadedSounds[method.Parameters[1]] then + print(string.format("Replacing not-loaded horn sound \"%s\" with \"%s\".", method.Parameters[1], DefaultHorn)) + method.Parameters[1] = DefaultHorn end - elseif name == "SetOverlayClipName" then - local clipName = method.Parameters[1] - if clipName == "" or clipName == "generator" then + elseif RemoveIfNotLoaded[name] then + if not LoadedSounds[method.Parameters[1]] then + print(string.format("Removing not-loaded sound \"%s\".", method.Parameters[1])) carSoundParameters:RemoveMethod(index) end end