Add option to disable disabling sound streaming.

This commit is contained in:
Ottermandias 2022-01-28 12:36:19 +01:00
parent ac2f2cf3b9
commit e18fcafc51
4 changed files with 584 additions and 533 deletions

View file

@ -20,6 +20,7 @@ namespace Penumbra
public bool DisableFileSystemNotifications { get; set; }
public bool DisableSoundStreaming { get; set; } = true;
public bool EnableHttpApi { get; set; }
public bool EnablePlayerWatch { get; set; } = false;
public int WaitFrames { get; set; } = 30;

View file

@ -12,15 +12,15 @@ using Penumbra.Mod;
using Penumbra.Structs;
using Penumbra.Util;
namespace Penumbra.Mods
namespace Penumbra.Mods;
// The ModCollectionCache contains all required temporary data to use a collection.
// It will only be setup if a collection gets activated in any way.
public class ModCollectionCache
{
// The ModCollectionCache contains all required temporary data to use a collection.
// It will only be setup if a collection gets activated in any way.
public class ModCollectionCache
{
// Shared caches to avoid allocations.
private static readonly BitArray FileSeen = new( 256 );
private static readonly Dictionary< GamePath, Mod.Mod > RegisteredFiles = new( 256 );
private static readonly BitArray FileSeen = new(256);
private static readonly Dictionary< GamePath, Mod.Mod > RegisteredFiles = new(256);
public readonly Dictionary< string, Mod.Mod > AvailableMods = new();
@ -77,8 +77,10 @@ namespace Penumbra.Mods
AddMetaFiles();
Checksums.Clear();
foreach( var file in ResolvedFiles )
{
Checksums.Add( file.Value.Crc64 );
}
}
private void SetChangedItems()
{
@ -131,8 +133,27 @@ namespace Penumbra.Mods
AddRemainingFiles( mod );
}
private bool FilterFile( GamePath gamePath )
{
// If audio streaming is not disabled, replacing .scd files crashes the game,
// so only add those files if it is disabled.
if( !Penumbra.Config.DisableSoundStreaming
&& gamePath.ToString().EndsWith( ".scd", StringComparison.InvariantCultureIgnoreCase ) )
{
return true;
}
return false;
}
private void AddFile( Mod.Mod mod, GamePath gamePath, FullPath file )
{
if( FilterFile( gamePath ) )
{
return;
}
if( !RegisteredFiles.TryGetValue( gamePath, out var oldMod ) )
{
RegisteredFiles.Add( gamePath, mod );
@ -165,8 +186,8 @@ namespace Penumbra.Mods
{
foreach( var (file, paths) in option.OptionFiles )
{
var fullPath = new FullPath(mod.Data.BasePath, file);
var idx = mod.Data.Resources.ModFiles.IndexOf( f => f.Equals(fullPath) );
var fullPath = new FullPath( mod.Data.BasePath, file );
var idx = mod.Data.Resources.ModFiles.IndexOf( f => f.Equals( fullPath ) );
if( idx < 0 )
{
AddMissingFile( fullPath );
@ -259,19 +280,19 @@ namespace Penumbra.Mods
private void AddSwaps( Mod.Mod mod )
{
foreach( var swap in mod.Data.Meta.FileSwaps )
foreach( var (key, value) in mod.Data.Meta.FileSwaps.Where( kvp => !FilterFile( kvp.Key ) ) )
{
if( !RegisteredFiles.TryGetValue( swap.Key, out var oldMod ) )
if( !RegisteredFiles.TryGetValue( key, out var oldMod ) )
{
RegisteredFiles.Add( swap.Key, mod );
SwappedFiles.Add( swap.Key, swap.Value );
RegisteredFiles.Add( key, mod );
SwappedFiles.Add( key, value );
}
else
{
mod.Cache.AddConflict( oldMod, swap.Key );
mod.Cache.AddConflict( oldMod, key );
if( !ReferenceEquals( mod, oldMod ) && mod.Settings.Priority == oldMod.Settings.Priority )
{
oldMod.Cache.AddConflict( mod, swap.Key );
oldMod.Cache.AddConflict( mod, key );
}
}
}
@ -371,5 +392,4 @@ namespace Penumbra.Mods
public string? ResolveSwappedOrReplacementPath( GamePath gameResourcePath )
=> GetCandidateForGameFile( gameResourcePath )?.FullName.Replace( '\\', '/' ) ?? GetSwappedFilePath( gameResourcePath ) ?? null;
}
}

View file

@ -14,10 +14,10 @@ using Penumbra.PlayerWatch;
using Penumbra.UI;
using Penumbra.Util;
namespace Penumbra
namespace Penumbra;
public class Penumbra : IDalamudPlugin
{
public class Penumbra : IDalamudPlugin
{
public string Name { get; } = "Penumbra";
public string PluginDebugTitleStr { get; } = "Penumbra - Debug Build";
@ -44,7 +44,10 @@ namespace Penumbra
Config = Configuration.Load();
MusicManager = new MusicManager();
if( Config.DisableSoundStreaming )
{
MusicManager.DisableStreaming();
}
var gameUtils = Service< ResidentResources >.Set();
PlayerWatcher = PlayerWatchFactory.Create( Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects );
@ -253,5 +256,4 @@ namespace Penumbra
SettingsInterface.FlipVisibility();
}
}
}

View file

@ -194,6 +194,33 @@ public partial class SettingsInterface
"Instead of keeping the mod-selector in the Installed Mods tab a fixed width, this will let it scale with the total size of the Penumbra window." );
}
private void DrawDisableSoundStreamingBox()
{
var tmp = Penumbra.Config.DisableSoundStreaming;
if( ImGui.Checkbox( "Disable Audio Streaming", ref tmp ) && tmp != Penumbra.Config.DisableSoundStreaming )
{
Penumbra.Config.DisableSoundStreaming = tmp;
_configChanged = true;
if( tmp )
{
_base._penumbra.MusicManager.DisableStreaming();
}
else
{
_base._penumbra.MusicManager.EnableStreaming();
}
_base.ReloadMods();
}
ImGui.SameLine();
ImGuiComponents.HelpMarker(
"Disable streaming in the games audio engine.\n"
+ "If you do not disable streaming, you can not replace sound files in the game (*.scd files), they will be ignored by Penumbra.\n\n"
+ "Only touch this if you experience sound problems.\n"
+ "If you toggle this, make sure no modified or to-be-modified sound file is currently playing or was recently playing, else you might crash." );
}
private void DrawLogLoadedFilesBox()
{
ImGui.Checkbox( "Log Loaded Files", ref _base._penumbra.ResourceLoader.LogAllFiles );
@ -306,6 +333,7 @@ public partial class SettingsInterface
private void DrawAdvancedSettings()
{
DrawTempFolder();
DrawDisableSoundStreamingBox();
DrawLogLoadedFilesBox();
DrawDisableNotificationsBox();
DrawEnableHttpApiBox();